dolibarr 21.0.0-beta
clientfourn.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2002-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2012 Cédric Salvador <csalvador@gpcsolutions.fr>
6 * Copyright (C) 2012-2014 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
7 * Copyright (C) 2014-2106 Ferran Marcet <fmarcet@2byte.es>
8 * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
9 * Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
10 * Copyright (C) 2018-2024 Frédéric France <frederic.france@free.fr>
11 * Copyright (C) 2020 Maxime DEMAREST <maxime@indelog.fr>
12 * Copyright (C) 2021 Alexandre Spangaro <aspangaro@open-dsi.fr>
13 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 3 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program. If not, see <https://www.gnu.org/licenses/>.
27 */
28
35// Load Dolibarr environment
36require '../../main.inc.php';
37require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
38require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
39require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
40require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
41require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php';
42require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
43require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
44require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountancycategory.class.php';
45require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
46
56// Load translation files required by the page
57$langs->loadLangs(array('compta', 'bills', 'donation', 'salaries', 'accountancy', 'loan'));
58
59$date_startmonth = GETPOSTINT('date_startmonth');
60$date_startday = GETPOSTINT('date_startday');
61$date_startyear = GETPOSTINT('date_startyear');
62$date_endmonth = GETPOSTINT('date_endmonth');
63$date_endday = GETPOSTINT('date_endday');
64$date_endyear = GETPOSTINT('date_endyear');
65$showaccountdetail = GETPOST('showaccountdetail', 'aZ09') ? GETPOST('showaccountdetail', 'aZ09') : 'yes';
66
67$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
68$sortfield = GETPOST('sortfield', 'aZ09comma');
69$sortorder = GETPOST('sortorder', 'aZ09comma');
70$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
71if (empty($page) || $page == -1) {
72 $page = 0;
73} // If $page is not defined, or '' or -1
74$offset = $limit * $page;
75$pageprev = $page - 1;
76$pagenext = $page + 1;
77//if (! $sortfield) $sortfield='s.nom, s.rowid';
78if (!$sortorder) {
79 $sortorder = 'ASC';
80}
81
82// Date range
83$year = GETPOSTINT('year'); // this is used for navigation previous/next. It is the last year to show in filter
84if (empty($year)) {
85 $year_current = dol_print_date(dol_now(), "%Y");
86 $month_current = dol_print_date(dol_now(), "%m");
87 $year_start = $year_current;
88} else {
89 $year_current = $year;
90 $month_current = dol_print_date(dol_now(), "%m");
91 $year_start = $year;
92}
93$date_start = dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
94$date_end = dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
95
96// We define date_start and date_end
97if (empty($date_start) || empty($date_end)) { // We define date_start and date_end
98 $q = GETPOST("q") ? GETPOSTINT("q") : 0;
99 if ($q == 0) {
100 // We define date_start and date_end
101 $year_end = $year_start;
102 $month_start = GETPOST("month") ? GETPOSTINT("month") : getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1);
103 $month_end = "";
104 if (!GETPOST('month')) {
105 if (!$year && $month_start > $month_current) {
106 $year_start--;
107 $year_end--;
108 }
109 if (getDolGlobalInt('SOCIETE_FISCAL_MONTH_START') > 1) {
110 $month_end = $month_start - 1;
111 $year_end = $year_start + 1;
112 }
113 if ($month_end < 1) {
114 $month_end = 12;
115 }
116 } else {
117 $month_end = $month_start;
118 }
119 $date_start = dol_get_first_day($year_start, $month_start, false);
120 $date_end = dol_get_last_day($year_end, $month_end, false);
121 }
122 if ($q == 1) {
123 $date_start = dol_get_first_day($year_start, 1, false);
124 $date_end = dol_get_last_day($year_start, 3, false);
125 }
126 if ($q == 2) {
127 $date_start = dol_get_first_day($year_start, 4, false);
128 $date_end = dol_get_last_day($year_start, 6, false);
129 }
130 if ($q == 3) {
131 $date_start = dol_get_first_day($year_start, 7, false);
132 $date_end = dol_get_last_day($year_start, 9, false);
133 }
134 if ($q == 4) {
135 $date_start = dol_get_first_day($year_start, 10, false);
136 $date_end = dol_get_last_day($year_start, 12, false);
137 }
138}
139
140// $date_start and $date_end are defined. We force $year_start and $nbofyear
141$tmps = dol_getdate($date_start);
142$year_start = $tmps['year'];
143$tmpe = dol_getdate($date_end);
144$year_end = $tmpe['year'];
145$nbofyear = ($year_end - $year_start) + 1;
146//var_dump("year_start=".$year_start." year_end=".$year_end." nbofyear=".$nbofyear." date_start=".dol_print_date($date_start, 'dayhour')." date_end=".dol_print_date($date_end, 'dayhour'));
147
148// Define modecompta ('CREANCES-DETTES' or 'RECETTES-DEPENSES' or 'BOOKKEEPING')
149$modecompta = getDolGlobalString('ACCOUNTING_MODE');
150if (isModEnabled('accounting')) {
151 $modecompta = 'BOOKKEEPING';
152}
153if (GETPOST("modecompta", 'alpha')) {
154 $modecompta = GETPOST("modecompta", 'alpha');
155}
156
157$AccCat = new AccountancyCategory($db);
158
159// Security check
160$socid = GETPOSTINT('socid');
161if ($user->socid > 0) {
162 $socid = $user->socid;
163}
164
165// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
166$hookmanager->initHooks(['customersupplierreportlist']);
167
168if (isModEnabled('comptabilite')) {
169 $result = restrictedArea($user, 'compta', '', '', 'resultat');
170}
171if (isModEnabled('accounting')) {
172 $result = restrictedArea($user, 'accounting', '', '', 'comptarapport');
173}
174
175/*
176 * View
177 */
178
179llxHeader();
180
181$form = new Form($db);
182
183$periodlink = '';
184$exportlink = '';
185
186$total_ht = 0;
187$total_ttc = 0;
188
189$builddate = '';
190$name = '';
191$period = '';
192
193// Affiche en-tete de rapport
194if ($modecompta == "CREANCES-DETTES") {
195 $name = $langs->trans("ReportInOut").', '.$langs->trans("ByPredefinedAccountGroups");
196 $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
197 $periodlink = ($year_start ? "<a href='".$_SERVER["PHP_SELF"]."?year=".($tmps['year'] - 1)."&modecompta=".$modecompta."'>".img_previous()."</a> <a href='".$_SERVER["PHP_SELF"]."?year=".($tmps['year'] + 1)."&modecompta=".$modecompta."'>".img_next()."</a>" : "");
198 $description = $langs->trans("RulesResultDue");
199 if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) {
200 $description .= $langs->trans("DepositsAreNotIncluded");
201 } else {
202 $description .= $langs->trans("DepositsAreIncluded");
203 }
204 if (getDolGlobalString('FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS')) {
205 $description .= $langs->trans("SupplierDepositsAreNotIncluded");
206 }
207 $builddate = dol_now();
208 //$exportlink=$langs->trans("NotYetAvailable");
209} elseif ($modecompta == "RECETTES-DEPENSES") {
210 $name = $langs->trans("ReportInOut").', '.$langs->trans("ByPredefinedAccountGroups");
211 $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
212 $periodlink = ($year_start ? "<a href='".$_SERVER["PHP_SELF"]."?year=".($tmps['year'] - 1)."&modecompta=".$modecompta."'>".img_previous()."</a> <a href='".$_SERVER["PHP_SELF"]."?year=".($tmps['year'] + 1)."&modecompta=".$modecompta."'>".img_next()."</a>" : "");
213 $description = $langs->trans("RulesResultInOut");
214 $builddate = dol_now();
215 //$exportlink=$langs->trans("NotYetAvailable");
216} elseif ($modecompta == "BOOKKEEPING") {
217 $name = $langs->trans("ReportInOut").', '.$langs->trans("ByPredefinedAccountGroups");
218 $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
219 $arraylist = array('no' => $langs->trans("CustomerCode"), 'yes' => $langs->trans("AccountWithNonZeroValues"), 'all' => $langs->trans("All"));
220 $period .= ' &nbsp; &nbsp; <span class="opacitymedium">'.$langs->trans("DetailBy").'</span> '.$form->selectarray('showaccountdetail', $arraylist, $showaccountdetail, 0);
221 $periodlink = ($year_start ? "<a href='".$_SERVER["PHP_SELF"]."?year=".($tmps['year'] - 1)."&modecompta=".$modecompta."&showaccountdetail=".$showaccountdetail."'>".img_previous()."</a> <a href='".$_SERVER["PHP_SELF"]."?year=".($tmps['year'] + 1)."&modecompta=".$modecompta."&showaccountdetail=".$showaccountdetail."'>".img_next()."</a>" : "");
222 $description = $langs->trans("RulesResultBookkeepingPredefined");
223 $description .= ' ('.$langs->trans("SeePageForSetup", DOL_URL_ROOT.'/accountancy/admin/account.php?mainmenu=accountancy&leftmenu=accountancy_admin', $langs->transnoentitiesnoconv("Accountancy").' / '.$langs->transnoentitiesnoconv("Setup").' / '.$langs->transnoentitiesnoconv("Chartofaccounts")).')';
224 $builddate = dol_now();
225 //$exportlink=$langs->trans("NotYetAvailable");
226}
227
228// Define $calcmode line
229$calcmode = '';
230if (isModEnabled('accounting')) {
231 $calcmode .= '<input type="radio" name="modecompta" id="modecompta3" value="BOOKKEEPING"'.($modecompta == 'BOOKKEEPING' ? ' checked="checked"' : '').'><label for="modecompta3"> '.$langs->trans("CalcModeBookkeeping").'</label>';
232 $calcmode .= '<br>';
233}
234$calcmode .= '<input type="radio" name="modecompta" id="modecompta1" value="RECETTES-DEPENSES"'.($modecompta == 'RECETTES-DEPENSES' ? ' checked="checked"' : '').'><label for="modecompta1"> '.$langs->trans("CalcModePayment");
235if (isModEnabled('accounting')) {
236 $calcmode .= ' <span class="opacitymedium hideonsmartphone">('.$langs->trans("CalcModeNoBookKeeping").')</span>';
237}
238$calcmode .= '</label>';
239$calcmode .= '<br><input type="radio" name="modecompta" id="modecompta2" value="CREANCES-DETTES"'.($modecompta == 'CREANCES-DETTES' ? ' checked="checked"' : '').'><label for="modecompta2"> '.$langs->trans("CalcModeDebt");
240if (isModEnabled('accounting')) {
241 $calcmode .= ' <span class="opacitymedium hideonsmartphone">('.$langs->trans("CalcModeNoBookKeeping").')</span>';
242}
243$calcmode .= '</label>';
244
245
246report_header($name, '', $period, $periodlink, $description, $builddate, $exportlink, array('modecompta' => $modecompta, 'showaccountdetail' => $showaccountdetail), $calcmode);
247
248if (isModEnabled('accounting') && $modecompta != 'BOOKKEEPING') {
249 print info_admin($langs->trans("WarningReportNotReliable"), 0, 0, '1');
250}
251
252// Show report array
253$param = '&modecompta='.urlencode($modecompta).'&showaccountdetail='.urlencode($showaccountdetail);
254if ($date_startday) {
255 $param .= '&date_startday='.$date_startday;
256}
257if ($date_startmonth) {
258 $param .= '&date_startmonth='.$date_startmonth;
259}
260if ($date_startyear) {
261 $param .= '&date_startyear='.$date_startyear;
262}
263if ($date_endday) {
264 $param .= '&date_endday='.$date_endday;
265}
266if ($date_endmonth) {
267 $param .= '&date_endmonth='.$date_endmonth;
268}
269if ($date_endyear) {
270 $param .= '&date_endyear='.$date_endyear;
271}
272
273print '<table class="liste noborder centpercent">';
274print '<tr class="liste_titre">';
275
276if ($modecompta == 'BOOKKEEPING') {
277 print_liste_field_titre("PredefinedGroups", $_SERVER["PHP_SELF"], 'f.thirdparty_code,f.rowid', '', $param, '', $sortfield, $sortorder, '');
278} else {
279 print_liste_field_titre("", $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, '');
280}
282if ($modecompta == 'BOOKKEEPING') {
283 print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], 'amount', '', $param, 'class="right"', $sortfield, $sortorder);
284} else {
285 if ($modecompta == 'CREANCES-DETTES') {
286 print_liste_field_titre("AmountHT", $_SERVER["PHP_SELF"], 'amount_ht', '', $param, 'class="right"', $sortfield, $sortorder);
287 } else {
288 print_liste_field_titre(''); // Make 4 columns in total whatever $modecompta is
289 }
290 print_liste_field_titre("AmountTTC", $_SERVER["PHP_SELF"], 'amount_ttc', '', $param, 'class="right"', $sortfield, $sortorder);
291}
292print "</tr>\n";
293
294
295$total_ht_outcome = $total_ttc_outcome = $total_ht_income = $total_ttc_income = 0;
296
297
298if ($modecompta == 'BOOKKEEPING') {
299 $predefinedgroupwhere = "(";
300 $predefinedgroupwhere .= " (pcg_type = 'EXPENSE')";
301 $predefinedgroupwhere .= " OR ";
302 $predefinedgroupwhere .= " (pcg_type = 'INCOME')";
303 $predefinedgroupwhere .= ")";
304
305 $charofaccountstring = getDolGlobalInt('CHARTOFACCOUNTS');
306 $charofaccountstring = dol_getIdFromCode($db, getDolGlobalString('CHARTOFACCOUNTS'), 'accounting_system', 'rowid', 'pcg_version');
307
308 $sql = "SELECT -1 as socid, aa.pcg_type, SUM(f.credit - f.debit) as amount";
309 if ($showaccountdetail == 'no') {
310 $sql .= ", f.thirdparty_code as name";
311 }
312 $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as f";
313 $sql .= ", ".MAIN_DB_PREFIX."accounting_account as aa";
314 $sql .= " WHERE f.numero_compte = aa.account_number";
315 $sql .= " AND ".$predefinedgroupwhere;
316 $sql .= " AND fk_pcg_version = '".$db->escape($charofaccountstring)."'";
317 $sql .= " AND f.entity = ".$conf->entity;
318 if (!empty($date_start) && !empty($date_end)) {
319 $sql .= " AND f.doc_date >= '".$db->idate($date_start)."' AND f.doc_date <= '".$db->idate($date_end)."'";
320 }
321 $sql .= " GROUP BY pcg_type";
322 if ($showaccountdetail == 'no') {
323 $sql .= ", name, socid"; // group by "accounting group" (INCOME/EXPENSE), then "customer".
324 }
325 $sql .= $db->order($sortfield, $sortorder);
326
327 $oldpcgtype = '';
328
329 dol_syslog("get bookkeeping entries", LOG_DEBUG);
330 $result = $db->query($sql);
331 if ($result) {
332 $num = $db->num_rows($result);
333 $i = 0;
334 if ($num > 0) {
335 while ($i < $num) {
336 $objp = $db->fetch_object($result);
337
338 if ($showaccountdetail == 'no') {
339 if ($objp->pcg_type != $oldpcgtype) {
340 print '<tr class="trforbreak"><td colspan="3" class="tdforbreak">'.dol_escape_htmltag($objp->pcg_type).'</td></tr>';
341 $oldpcgtype = $objp->pcg_type;
342 }
343 }
344
345 if ($showaccountdetail == 'no') {
346 print '<tr class="oddeven">';
347 print '<td></td>';
348 print '<td>';
349 print dol_escape_htmltag($objp->pcg_type);
350 print($objp->name ? ' ('.dol_escape_htmltag($objp->name).')' : ' ('.$langs->trans("Unknown").')');
351 print "</td>\n";
352 print '<td class="right nowraponall"><span class="amount">'.price($objp->amount)."</span></td>\n";
353 print "</tr>\n";
354 } else {
355 print '<tr class="oddeven trforbreak">';
356 print '<td colspan="2" class="tdforbreak">';
357 print dol_escape_htmltag($objp->pcg_type);
358 print "</td>\n";
359 print '<td class="right nowraponall tdforbreak"><span class="amount">'.price($objp->amount)."</span></td>\n";
360 print "</tr>\n";
361 }
362
363 $total_ht += (isset($objp->amount) ? $objp->amount : 0);
364 $total_ttc += (isset($objp->amount) ? $objp->amount : 0);
365
366 if ($objp->pcg_type == 'INCOME') {
367 $total_ht_income += (isset($objp->amount) ? $objp->amount : 0);
368 $total_ttc_income += (isset($objp->amount) ? $objp->amount : 0);
369 }
370 if ($objp->pcg_type == 'EXPENSE') {
371 $total_ht_outcome -= (isset($objp->amount) ? $objp->amount : 0);
372 $total_ttc_outcome -= (isset($objp->amount) ? $objp->amount : 0);
373 }
374
375 // Loop on detail of all accounts
376 // This make 14 calls for each detail of account (NP, N and month m)
377 if ($showaccountdetail != 'no') {
378 $tmppredefinedgroupwhere = "pcg_type = '".$db->escape($objp->pcg_type)."'";
379 $tmppredefinedgroupwhere .= " AND fk_pcg_version = '".$db->escape($charofaccountstring)."'";
380 //$tmppredefinedgroupwhere .= " AND thirdparty_code = '".$db->escape($objp->name)."'";
381
382 // Get cpts of category/group
383 $cpts = $AccCat->getCptsCat(0, $tmppredefinedgroupwhere);
384
385 foreach ($cpts as $j => $cpt) {
386 $return = $AccCat->getSumDebitCredit($cpt['account_number'], $date_start, $date_end, (empty($cpt['dc']) ? 0 : $cpt['dc']));
387 if ($return < 0) {
388 setEventMessages(null, $AccCat->errors, 'errors');
389 $resultN = 0;
390 } else {
391 $resultN = $AccCat->sdc;
392 }
393
394
395 if ($showaccountdetail == 'all' || $resultN != 0) {
396 print '<tr>';
397 print '<td></td>';
398 print '<td class="tdoverflowmax200"> &nbsp; &nbsp; '.length_accountg($cpt['account_number']).' - '.$cpt['account_label'].'</td>';
399 print '<td class="right nowraponall"><span class="amount">'.price($resultN).'</span></td>';
400 print "</tr>\n";
401 }
402 }
403 }
404
405 $i++;
406 }
407 } else {
408 print '<tr><td colspan="3" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
409 }
410 } else {
411 dol_print_error($db);
412 }
413} else {
414 /*
415 * Customer invoices
416 */
417 print '<tr class="trforbreak"><td colspan="4">'.$langs->trans("CustomersInvoices").'</td></tr>';
418
419 if ($modecompta == 'CREANCES-DETTES') {
420 $sql = "SELECT s.nom as name, s.rowid as socid, sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc";
421 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
422 $sql .= ", ".MAIN_DB_PREFIX."facture as f";
423 $sql .= " WHERE f.fk_soc = s.rowid";
424 $sql .= " AND f.fk_statut IN (1,2)";
425 if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) {
426 $sql .= " AND f.type IN (0,1,2,5)";
427 } else {
428 $sql .= " AND f.type IN (0,1,2,3,5)";
429 }
430 if (!empty($date_start) && !empty($date_end)) {
431 $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
432 }
433 } elseif ($modecompta == 'RECETTES-DEPENSES') {
434 /*
435 * List of payments (old payments are not seen by this query because, on older versions, they were not linked via payment_invoice.
436 * old versions, they were not linked via payment_invoice. They are added later)
437 */
438 $sql = "SELECT s.nom as name, s.rowid as socid, sum(pf.amount) as amount_ttc";
439 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
440 $sql .= ", ".MAIN_DB_PREFIX."facture as f";
441 $sql .= ", ".MAIN_DB_PREFIX."paiement_facture as pf";
442 $sql .= ", ".MAIN_DB_PREFIX."paiement as p";
443 $sql .= " WHERE p.rowid = pf.fk_paiement";
444 $sql .= " AND pf.fk_facture = f.rowid";
445 $sql .= " AND f.fk_soc = s.rowid";
446 if (!empty($date_start) && !empty($date_end)) {
447 $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
448 }
449 }
450 $sql .= " AND f.entity IN (".getEntity('invoice').")";
451 if ($socid) {
452 $sql .= " AND f.fk_soc = ".((int) $socid);
453 }
454 $sql .= " GROUP BY name, socid";
455 $sql .= $db->order($sortfield, $sortorder);
456
457 dol_syslog("get customer invoices", LOG_DEBUG);
458 $result = $db->query($sql);
459 if ($result) {
460 $num = $db->num_rows($result);
461 $i = 0;
462 while ($i < $num) {
463 $objp = $db->fetch_object($result);
464
465 print '<tr class="oddeven">';
466 print '<td>&nbsp;</td>';
467 print "<td>".$langs->trans("Bills").' <a href="'.DOL_URL_ROOT.'/compta/facture/list.php?socid='.$objp->socid.'">'.$objp->name."</td>\n";
468
469 print '<td class="right">';
470 if ($modecompta == 'CREANCES-DETTES') {
471 print '<span class="amount">'.price($objp->amount_ht)."</span>";
472 }
473 print "</td>\n";
474 print '<td class="right"><span class="amount">'.price($objp->amount_ttc)."</span></td>\n";
475
476 $total_ht += (isset($objp->amount_ht) ? $objp->amount_ht : 0);
477 $total_ttc += $objp->amount_ttc;
478 print "</tr>\n";
479 $i++;
480 }
481 $db->free($result);
482 } else {
483 dol_print_error($db);
484 }
485
486 // We add the old customer payments, not linked by payment_invoice
487 if ($modecompta == 'RECETTES-DEPENSES') {
488 $sql = "SELECT 'Autres' as name, '0' as idp, sum(p.amount) as amount_ttc";
489 $sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
490 $sql .= ", ".MAIN_DB_PREFIX."bank_account as ba";
491 $sql .= ", ".MAIN_DB_PREFIX."paiement as p";
492 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement";
493 $sql .= " WHERE pf.rowid IS NULL";
494 $sql .= " AND p.fk_bank = b.rowid";
495 $sql .= " AND b.fk_account = ba.rowid";
496 $sql .= " AND ba.entity IN (".getEntity('bank_account').")";
497 if (!empty($date_start) && !empty($date_end)) {
498 $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
499 }
500 $sql .= " GROUP BY name, idp";
501 $sql .= " ORDER BY name";
502
503 dol_syslog("get old customer payments not linked to invoices", LOG_DEBUG);
504 $result = $db->query($sql);
505 if ($result) {
506 $num = $db->num_rows($result);
507 $i = 0;
508 if ($num) {
509 while ($i < $num) {
510 $objp = $db->fetch_object($result);
511
512
513 print '<tr class="oddeven">';
514 print '<td>&nbsp;</td>';
515 print "<td>".$langs->trans("Bills")." ".$langs->trans("Other")." (".$langs->trans("PaymentsNotLinkedToInvoice").")\n";
516
517 print '<td class="right">';
518 if ($modecompta == 'CREANCES-DETTES') {
519 print '<span class="amount">'.price($objp->amount_ht)."</span></td>\n";
520 }
521 print '</td>';
522 print '<td class="right"><span class="amount">'.price($objp->amount_ttc)."</span></td>\n";
523
524 $total_ht += (isset($objp->amount_ht) ? $objp->amount_ht : 0);
525 $total_ttc += $objp->amount_ttc;
526
527 print "</tr>\n";
528 $i++;
529 }
530 }
531 $db->free($result);
532 } else {
533 dol_print_error($db);
534 }
535 }
536
537 if ($total_ttc == 0) {
538 print '<tr class="oddeven">';
539 print '<td>&nbsp;</td>';
540 print '<td colspan="3"><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
541 print '</tr>';
542 }
543
544 $total_ht_income += $total_ht;
545 $total_ttc_income += $total_ttc;
546
547 print '<tr class="liste_total">';
548 print '<td></td>';
549 print '<td></td>';
550 print '<td class="right">';
551 if ($modecompta == 'CREANCES-DETTES') {
552 print price($total_ht);
553 }
554 print '</td>';
555 print '<td class="right">'.price($total_ttc).'</td>';
556 print '</tr>';
557
558 /*
559 * Donations
560 */
561
562 if (isModEnabled('don')) {
563 print '<tr class="trforbreak"><td colspan="4">'.$langs->trans("Donations").'</td></tr>';
564
565 if ($modecompta == 'CREANCES-DETTES' || $modecompta == 'RECETTES-DEPENSES') {
566 if ($modecompta == 'CREANCES-DETTES') {
567 $sql = "SELECT p.societe as name, p.firstname, p.lastname, date_format(p.datedon,'%Y-%m') as dm, sum(p.amount) as amount";
568 $sql .= " FROM ".MAIN_DB_PREFIX."don as p";
569 $sql .= " WHERE p.entity IN (".getEntity('donation').")";
570 $sql .= " AND fk_statut in (1,2)";
571 } else {
572 $sql = "SELECT p.societe as nom, p.firstname, p.lastname, date_format(p.datedon,'%Y-%m') as dm, sum(p.amount) as amount";
573 $sql .= " FROM ".MAIN_DB_PREFIX."don as p";
574 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."payment_donation as pe ON pe.fk_donation = p.rowid";
575 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON pe.fk_typepayment = c.id";
576 $sql .= " WHERE p.entity IN (".getEntity('donation').")";
577 $sql .= " AND fk_statut >= 2";
578 }
579 if (!empty($date_start) && !empty($date_end)) {
580 $sql .= " AND p.datedon >= '".$db->idate($date_start)."' AND p.datedon <= '".$db->idate($date_end)."'";
581 }
582 }
583 $sql .= " GROUP BY p.societe, p.firstname, p.lastname, dm";
584 $newsortfield = $sortfield;
585 if ($newsortfield == 's.nom, s.rowid') {
586 $newsortfield = 'p.societe, p.firstname, p.lastname, dm';
587 }
588 if ($newsortfield == 'amount_ht') {
589 $newsortfield = 'amount';
590 }
591 if ($newsortfield == 'amount_ttc') {
592 $newsortfield = 'amount';
593 }
594 $sql .= $db->order($newsortfield, $sortorder);
595
596 dol_syslog("get dunning");
597 $result = $db->query($sql);
598 $subtotal_ht = 0;
599 $subtotal_ttc = 0;
600 if ($result) {
601 $num = $db->num_rows($result);
602 $i = 0;
603 if ($num) {
604 while ($i < $num) {
605 $obj = $db->fetch_object($result);
606
607 $total_ht += $obj->amount;
608 $total_ttc += $obj->amount;
609 $subtotal_ht += $obj->amount;
610 $subtotal_ttc += $obj->amount;
611
612 print '<tr class="oddeven">';
613 print '<td>&nbsp;</td>';
614
615 print "<td>".$langs->trans("Donation")." <a href=\"".DOL_URL_ROOT."/don/list.php?search_company=".$obj->name."&search_name=".$obj->firstname." ".$obj->lastname."\">".$obj->name." ".$obj->firstname." ".$obj->lastname."</a></td>\n";
616
617 print '<td class="right">';
618 if ($modecompta == 'CREANCES-DETTES') {
619 print '<span class="amount">'.price($obj->amount).'</span>';
620 }
621 print '</td>';
622 print '<td class="right"><span class="amount">'.price($obj->amount).'</span></td>';
623 print '</tr>';
624 $i++;
625 }
626 } else {
627 print '<tr class="oddeven"><td>&nbsp;</td>';
628 print '<td colspan="3"><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
629 print '</tr>';
630 }
631 } else {
632 dol_print_error($db);
633 }
634
635 $total_ht_income += $subtotal_ht;
636 $total_ttc_income += $subtotal_ttc;
637
638 print '<tr class="liste_total">';
639 print '<td></td>';
640 print '<td></td>';
641 print '<td class="right">';
642 if ($modecompta == 'CREANCES-DETTES') {
643 print price($subtotal_ht);
644 }
645 print '</td>';
646 print '<td class="right">'.price($subtotal_ttc).'</td>';
647 print '</tr>';
648 }
649
650 /*
651 * Suppliers invoices
652 */
653 if ($modecompta == 'CREANCES-DETTES') {
654 $sql = "SELECT s.nom as name, s.rowid as socid, sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc";
655 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
656 $sql .= ", ".MAIN_DB_PREFIX."facture_fourn as f";
657 $sql .= " WHERE f.fk_soc = s.rowid";
658 $sql .= " AND f.fk_statut IN (1,2)";
659 if (getDolGlobalString('FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS')) {
660 $sql .= " AND f.type IN (0,1,2)";
661 } else {
662 $sql .= " AND f.type IN (0,1,2,3)";
663 }
664 if (!empty($date_start) && !empty($date_end)) {
665 $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
666 }
667 } elseif ($modecompta == 'RECETTES-DEPENSES') {
668 $sql = "SELECT s.nom as name, s.rowid as socid, sum(pf.amount) as amount_ttc";
669 $sql .= " FROM ".MAIN_DB_PREFIX."paiementfourn as p";
670 $sql .= ", ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf";
671 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture_fourn as f";
672 $sql .= " ON pf.fk_facturefourn = f.rowid";
673 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s";
674 $sql .= " ON f.fk_soc = s.rowid";
675 $sql .= " WHERE p.rowid = pf.fk_paiementfourn ";
676 if (!empty($date_start) && !empty($date_end)) {
677 $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
678 }
679 }
680
681 $sql .= " AND f.entity = ".((int) $conf->entity);
682 if ($socid) {
683 $sql .= " AND f.fk_soc = ".((int) $socid);
684 }
685 $sql .= " GROUP BY name, socid";
686 $sql .= $db->order($sortfield, $sortorder);
687
688 print '<tr class="trforbreak"><td colspan="4">'.$langs->trans("SuppliersInvoices").'</td></tr>';
689
690 $subtotal_ht = 0;
691 $subtotal_ttc = 0;
692 dol_syslog("get suppliers invoices", LOG_DEBUG);
693 $result = $db->query($sql);
694 if ($result) {
695 $num = $db->num_rows($result);
696 $i = 0;
697 if ($num > 0) {
698 while ($i < $num) {
699 $objp = $db->fetch_object($result);
700
701 print '<tr class="oddeven">';
702 print '<td>&nbsp;</td>';
703 print "<td>".$langs->trans("Bills").' <a href="'.DOL_URL_ROOT."/fourn/facture/list.php?socid=".$objp->socid.'">'.$objp->name.'</a></td>'."\n";
704
705 print '<td class="right">';
706 if ($modecompta == 'CREANCES-DETTES') {
707 print '<span class="amount">'.price(-$objp->amount_ht)."</span>";
708 }
709 print "</td>\n";
710 print '<td class="right"><span class="amount">'.price(-$objp->amount_ttc)."</span></td>\n";
711
712 $total_ht -= (isset($objp->amount_ht) ? $objp->amount_ht : 0);
713 $total_ttc -= $objp->amount_ttc;
714 $subtotal_ht += (isset($objp->amount_ht) ? $objp->amount_ht : 0);
715 $subtotal_ttc += $objp->amount_ttc;
716
717 print "</tr>\n";
718 $i++;
719 }
720 } else {
721 print '<tr class="oddeven">';
722 print '<td>&nbsp;</td>';
723 print '<td colspan="3"><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
724 print '</tr>';
725 }
726
727 $db->free($result);
728 } else {
729 dol_print_error($db);
730 }
731
732 $total_ht_outcome += $subtotal_ht;
733 $total_ttc_outcome += $subtotal_ttc;
734
735 print '<tr class="liste_total">';
736 print '<td></td>';
737 print '<td></td>';
738 print '<td class="right">';
739 if ($modecompta == 'CREANCES-DETTES') {
740 print price(-$subtotal_ht);
741 }
742 print '</td>';
743 print '<td class="right">'.price(-$subtotal_ttc).'</td>';
744 print '</tr>';
745
746
747 /*
748 * Social / Fiscal contributions who are not deductible
749 */
750
751 print '<tr class="trforbreak"><td colspan="4">'.$langs->trans("SocialContributionsNondeductibles").'</td></tr>';
752
753 if ($modecompta == 'CREANCES-DETTES') {
754 $sql = "SELECT c.id, c.libelle as label, c.accountancy_code, sum(cs.amount) as amount";
755 $sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c";
756 $sql .= ", ".MAIN_DB_PREFIX."chargesociales as cs";
757 $sql .= " WHERE cs.fk_type = c.id";
758 $sql .= " AND c.deductible = 0";
759 if (!empty($date_start) && !empty($date_end)) {
760 $sql .= " AND cs.date_ech >= '".$db->idate($date_start)."' AND cs.date_ech <= '".$db->idate($date_end)."'";
761 }
762 } elseif ($modecompta == 'RECETTES-DEPENSES') {
763 $sql = "SELECT c.id, c.libelle as label, c.accountancy_code, sum(p.amount) as amount";
764 $sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c";
765 $sql .= ", ".MAIN_DB_PREFIX."chargesociales as cs";
766 $sql .= ", ".MAIN_DB_PREFIX."paiementcharge as p";
767 $sql .= " WHERE p.fk_charge = cs.rowid";
768 $sql .= " AND cs.fk_type = c.id";
769 $sql .= " AND c.deductible = 0";
770 if (!empty($date_start) && !empty($date_end)) {
771 $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
772 }
773 }
774 $sql .= " AND cs.entity = ".$conf->entity;
775 $sql .= " GROUP BY c.libelle, c.id, c.accountancy_code";
776 $newsortfield = $sortfield;
777 if ($newsortfield == 's.nom, s.rowid') {
778 $newsortfield = 'c.libelle, c.id';
779 }
780 if ($newsortfield == 'amount_ht') {
781 $newsortfield = 'amount';
782 }
783 if ($newsortfield == 'amount_ttc') {
784 $newsortfield = 'amount';
785 }
786
787 $sql .= $db->order($newsortfield, $sortorder);
788
789 dol_syslog("get social contributions deductible=0", LOG_DEBUG);
790 $result = $db->query($sql);
791 $subtotal_ht = 0;
792 $subtotal_ttc = 0;
793 if ($result) {
794 $num = $db->num_rows($result);
795 $i = 0;
796 if ($num) {
797 while ($i < $num) {
798 $obj = $db->fetch_object($result);
799
800 $total_ht -= $obj->amount;
801 $total_ttc -= $obj->amount;
802 $subtotal_ht += $obj->amount;
803 $subtotal_ttc += $obj->amount;
804
805 $titletoshow = '';
806 if ($obj->accountancy_code) {
807 $titletoshow = $langs->trans("AccountingCode").': '.$obj->accountancy_code;
808 $tmpaccountingaccount = new AccountingAccount($db);
809 $tmpaccountingaccount->fetch(0, $obj->accountancy_code, 1);
810 $titletoshow .= ' - '.$langs->trans("AccountingCategory").': '.$tmpaccountingaccount->pcg_type;
811 }
812
813 print '<tr class="oddeven">';
814 print '<td>&nbsp;</td>';
815 print '<td'.($obj->accountancy_code ? ' title="'.dol_escape_htmltag($titletoshow).'"' : '').'>'.dol_escape_htmltag($obj->label).'</td>';
816 print '<td class="right">';
817 if ($modecompta == 'CREANCES-DETTES') {
818 print '<span class="amount">'.price(-$obj->amount).'</span>';
819 }
820 print '</td>';
821 print '<td class="right"><span class="amount">'.price(-$obj->amount).'</span></td>';
822 print '</tr>';
823 $i++;
824 }
825 } else {
826 print '<tr class="oddeven">';
827 print '<td>&nbsp;</td>';
828 print '<td colspan="3"><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
829 print '</tr>';
830 }
831 } else {
832 dol_print_error($db);
833 }
834
835 $total_ht_outcome += $subtotal_ht;
836 $total_ttc_outcome += $subtotal_ttc;
837
838 print '<tr class="liste_total">';
839 print '<td></td>';
840 print '<td></td>';
841 print '<td class="right">';
842 if ($modecompta == 'CREANCES-DETTES') {
843 print price(-$subtotal_ht);
844 }
845 print '</td>';
846 print '<td class="right">'.price(-$subtotal_ttc).'</td>';
847 print '</tr>';
848
849
850 /*
851 * Social / Fiscal contributions who are deductible
852 */
853
854 print '<tr class="trforbreak"><td colspan="4">'.$langs->trans("SocialContributionsDeductibles").'</td></tr>';
855
856 if ($modecompta == 'CREANCES-DETTES') {
857 $sql = "SELECT c.id, c.libelle as label, c.accountancy_code, sum(cs.amount) as amount";
858 $sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c";
859 $sql .= ", ".MAIN_DB_PREFIX."chargesociales as cs";
860 $sql .= " WHERE cs.fk_type = c.id";
861 $sql .= " AND c.deductible = 1";
862 if (!empty($date_start) && !empty($date_end)) {
863 $sql .= " AND cs.date_ech >= '".$db->idate($date_start)."' AND cs.date_ech <= '".$db->idate($date_end)."'";
864 }
865 $sql .= " AND cs.entity = ".$conf->entity;
866 } elseif ($modecompta == 'RECETTES-DEPENSES') {
867 $sql = "SELECT c.id, c.libelle as label, c.accountancy_code, sum(p.amount) as amount";
868 $sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c";
869 $sql .= ", ".MAIN_DB_PREFIX."chargesociales as cs";
870 $sql .= ", ".MAIN_DB_PREFIX."paiementcharge as p";
871 $sql .= " WHERE p.fk_charge = cs.rowid";
872 $sql .= " AND cs.fk_type = c.id";
873 $sql .= " AND c.deductible = 1";
874 if (!empty($date_start) && !empty($date_end)) {
875 $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
876 }
877 $sql .= " AND cs.entity = ".$conf->entity;
878 }
879 $sql .= " GROUP BY c.libelle, c.id, c.accountancy_code";
880 $newsortfield = $sortfield;
881 if ($newsortfield == 's.nom, s.rowid') {
882 $newsortfield = 'c.libelle, c.id';
883 }
884 if ($newsortfield == 'amount_ht') {
885 $newsortfield = 'amount';
886 }
887 if ($newsortfield == 'amount_ttc') {
888 $newsortfield = 'amount';
889 }
890 $sql .= $db->order($newsortfield, $sortorder);
891
892 dol_syslog("get social contributions deductible=1", LOG_DEBUG);
893 $result = $db->query($sql);
894 $subtotal_ht = 0;
895 $subtotal_ttc = 0;
896 if ($result) {
897 $num = $db->num_rows($result);
898 $i = 0;
899 if ($num) {
900 while ($i < $num) {
901 $obj = $db->fetch_object($result);
902
903 $total_ht -= $obj->amount;
904 $total_ttc -= $obj->amount;
905 $subtotal_ht += $obj->amount;
906 $subtotal_ttc += $obj->amount;
907
908 $titletoshow = '';
909 if ($obj->accountancy_code) {
910 $titletoshow = $langs->trans("AccountingCode").': '.$obj->accountancy_code;
911 $tmpaccountingaccount = new AccountingAccount($db);
912 $tmpaccountingaccount->fetch(0, $obj->accountancy_code, 1);
913 $titletoshow .= ' - '.$langs->trans("AccountingCategory").': '.$tmpaccountingaccount->pcg_type;
914 }
915
916 print '<tr class="oddeven">';
917 print '<td>&nbsp;</td>';
918 print '<td'.($obj->accountancy_code ? ' title="'.dol_escape_htmltag($titletoshow).'"' : '').'>'.dol_escape_htmltag($obj->label).'</td>';
919 print '<td class="right">';
920 if ($modecompta == 'CREANCES-DETTES') {
921 print '<span class="amount">'.price(-$obj->amount).'</span>';
922 }
923 print '</td>';
924 print '<td class="right"><span class="amount">'.price(-$obj->amount).'</span></td>';
925 print '</tr>';
926 $i++;
927 }
928 } else {
929 print '<tr class="oddeven">';
930 print '<td>&nbsp;</td>';
931 print '<td colspan="3"><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
932 print '</tr>';
933 }
934 } else {
935 dol_print_error($db);
936 }
937
938 $total_ht_outcome += $subtotal_ht;
939 $total_ttc_outcome += $subtotal_ttc;
940
941 print '<tr class="liste_total">';
942 print '<td></td>';
943 print '<td></td>';
944 print '<td class="right">';
945 if ($modecompta == 'CREANCES-DETTES') {
946 print price(-$subtotal_ht);
947 }
948 print '</td>';
949 print '<td class="right">'.price(-$subtotal_ttc).'</td>';
950 print '</tr>';
951
952
953 /*
954 * Salaries
955 */
956
957 if (isModEnabled('salaries')) {
958 print '<tr class="trforbreak"><td colspan="4">'.$langs->trans("Salaries").'</td></tr>';
959
960 if ($modecompta == 'CREANCES-DETTES' || $modecompta == 'RECETTES-DEPENSES') {
961 if ($modecompta == 'CREANCES-DETTES') {
962 $column = 's.dateep'; // We use the date of end of period of salary
963
964 $sql = "SELECT u.rowid, u.firstname, u.lastname, s.fk_user as fk_user, s.label as label, date_format($column,'%Y-%m') as dm, sum(s.amount) as amount";
965 $sql .= " FROM ".MAIN_DB_PREFIX."salary as s";
966 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."user as u ON u.rowid = s.fk_user";
967 $sql .= " WHERE s.entity IN (".getEntity('salary').")";
968 if (!empty($date_start) && !empty($date_end)) {
969 $sql .= " AND $column >= '".$db->idate($date_start)."' AND $column <= '".$db->idate($date_end)."'";
970 }
971 $sql .= " GROUP BY u.rowid, u.firstname, u.lastname, s.fk_user, s.label, dm";
972 } else {
973 $column = 'p.datep';
974
975 $sql = "SELECT u.rowid, u.firstname, u.lastname, s.fk_user as fk_user, p.label as label, date_format($column,'%Y-%m') as dm, sum(p.amount) as amount";
976 $sql .= " FROM ".MAIN_DB_PREFIX."payment_salary as p";
977 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."salary as s ON s.rowid = p.fk_salary";
978 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."user as u ON u.rowid = s.fk_user";
979 $sql .= " WHERE p.entity IN (".getEntity('payment_salary').")";
980 if (!empty($date_start) && !empty($date_end)) {
981 $sql .= " AND $column >= '".$db->idate($date_start)."' AND $column <= '".$db->idate($date_end)."'";
982 }
983 $sql .= " GROUP BY u.rowid, u.firstname, u.lastname, s.fk_user, p.label, dm";
984 }
985
986 $newsortfield = $sortfield;
987 if ($newsortfield == 's.nom, s.rowid') {
988 $newsortfield = 'u.firstname, u.lastname';
989 }
990 if ($newsortfield == 'amount_ht') {
991 $newsortfield = 'amount';
992 }
993 if ($newsortfield == 'amount_ttc') {
994 $newsortfield = 'amount';
995 }
996 $sql .= $db->order($newsortfield, $sortorder);
997 }
998
999 dol_syslog("get salaries");
1000 $result = $db->query($sql);
1001 $subtotal_ht = 0;
1002 $subtotal_ttc = 0;
1003 if ($result) {
1004 $num = $db->num_rows($result);
1005 $i = 0;
1006 if ($num) {
1007 while ($i < $num) {
1008 $obj = $db->fetch_object($result);
1009
1010 $total_ht -= $obj->amount;
1011 $total_ttc -= $obj->amount;
1012 $subtotal_ht += $obj->amount;
1013 $subtotal_ttc += $obj->amount;
1014
1015 print '<tr class="oddeven"><td>&nbsp;</td>';
1016
1017 $userstatic = new User($db);
1018 $userstatic->fetch($obj->fk_user);
1019
1020 print "<td>".$langs->trans("Salary")." <a href=\"".DOL_URL_ROOT."/salaries/list.php?search_user=".urlencode($userstatic->getFullName($langs))."\">".$obj->firstname." ".$obj->lastname."</a></td>\n";
1021 print '<td class="right">';
1022 if ($modecompta == 'CREANCES-DETTES') {
1023 print '<span class="amount">'.price(-$obj->amount).'</span>';
1024 }
1025 print '</td>';
1026 print '<td class="right"><span class="amount">'.price(-$obj->amount).'</span></td>';
1027 print '</tr>';
1028 $i++;
1029 }
1030 } else {
1031 print '<tr class="oddeven">';
1032 print '<td>&nbsp;</td>';
1033 print '<td colspan="3"><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
1034 print '</tr>';
1035 }
1036 } else {
1037 dol_print_error($db);
1038 }
1039
1040 $total_ht_outcome += $subtotal_ht;
1041 $total_ttc_outcome += $subtotal_ttc;
1042
1043 print '<tr class="liste_total">';
1044 print '<td></td>';
1045 print '<td></td>';
1046 print '<td class="right">';
1047 if ($modecompta == 'CREANCES-DETTES') {
1048 print price(-$subtotal_ht);
1049 }
1050 print '</td>';
1051 print '<td class="right">'.price(-$subtotal_ttc).'</td>';
1052 print '</tr>';
1053 }
1054
1055
1056 /*
1057 * Expense report
1058 */
1059
1060 if (isModEnabled('expensereport')) {
1061 if ($modecompta == 'CREANCES-DETTES' || $modecompta == 'RECETTES-DEPENSES') {
1062 $langs->load('trips');
1063 if ($modecompta == 'CREANCES-DETTES') {
1064 $sql = "SELECT p.rowid, p.ref, u.rowid as userid, u.firstname, u.lastname, date_format(date_valid,'%Y-%m') as dm, p.total_ht as amount_ht, p.total_ttc as amount_ttc";
1065 $sql .= " FROM ".MAIN_DB_PREFIX."expensereport as p";
1066 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."user as u ON u.rowid=p.fk_user_author";
1067 $sql .= " WHERE p.entity IN (".getEntity('expensereport').")";
1068 $sql .= " AND p.fk_statut>=5";
1069
1070 $column = 'p.date_valid';
1071 } else {
1072 $sql = "SELECT p.rowid, p.ref, u.rowid as userid, u.firstname, u.lastname, date_format(pe.datep,'%Y-%m') as dm, sum(pe.amount) as amount_ht, sum(pe.amount) as amount_ttc";
1073 $sql .= " FROM ".MAIN_DB_PREFIX."expensereport as p";
1074 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."user as u ON u.rowid=p.fk_user_author";
1075 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."payment_expensereport as pe ON pe.fk_expensereport = p.rowid";
1076 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON pe.fk_typepayment = c.id";
1077 $sql .= " WHERE p.entity IN (".getEntity('expensereport').")";
1078 $sql .= " AND p.fk_statut>=5";
1079
1080 $column = 'pe.datep';
1081 }
1082
1083 if (!empty($date_start) && !empty($date_end)) {
1084 $sql .= " AND $column >= '".$db->idate($date_start)."' AND $column <= '".$db->idate($date_end)."'";
1085 }
1086
1087 if ($modecompta == 'CREANCES-DETTES') {
1088 //No need of GROUP BY
1089 } else {
1090 $sql .= " GROUP BY u.rowid, p.rowid, p.ref, u.firstname, u.lastname, dm";
1091 }
1092 $newsortfield = $sortfield;
1093 if ($newsortfield == 's.nom, s.rowid') {
1094 $newsortfield = 'p.ref';
1095 }
1096 $sql .= $db->order($newsortfield, $sortorder);
1097 }
1098
1099 print '<tr class="trforbreak"><td colspan="4">'.$langs->trans("ExpenseReport").'</td></tr>';
1100
1101 dol_syslog("get expense report outcome");
1102 $result = $db->query($sql);
1103 $subtotal_ht = 0;
1104 $subtotal_ttc = 0;
1105 if ($result) {
1106 $num = $db->num_rows($result);
1107 if ($num) {
1108 while ($obj = $db->fetch_object($result)) {
1109 $total_ht -= $obj->amount_ht;
1110 $total_ttc -= $obj->amount_ttc;
1111 $subtotal_ht += $obj->amount_ht;
1112 $subtotal_ttc += $obj->amount_ttc;
1113
1114 print '<tr class="oddeven">';
1115 print '<td>&nbsp;</td>';
1116 print "<td>".$langs->trans("ExpenseReport")." <a href=\"".DOL_URL_ROOT."/expensereport/list.php?search_user=".$obj->userid."\">".$obj->firstname." ".$obj->lastname."</a></td>\n";
1117 print '<td class="right">';
1118 if ($modecompta == 'CREANCES-DETTES') {
1119 print '<span class="amount">'.price(-$obj->amount_ht).'</span>';
1120 }
1121 print '</td>';
1122 print '<td class="right"><span class="amount">'.price(-$obj->amount_ttc).'</span></td>';
1123 print '</tr>';
1124 }
1125 } else {
1126 print '<tr class="oddeven">';
1127 print '<td>&nbsp;</td>';
1128 print '<td colspan="3"><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
1129 print '</tr>';
1130 }
1131 } else {
1132 dol_print_error($db);
1133 }
1134
1135 $total_ht_outcome += $subtotal_ht;
1136 $total_ttc_outcome += $subtotal_ttc;
1137
1138 print '<tr class="liste_total">';
1139 print '<td></td>';
1140 print '<td></td>';
1141 print '<td class="right">';
1142 if ($modecompta == 'CREANCES-DETTES') {
1143 print price(-$subtotal_ht);
1144 }
1145 print '</td>';
1146 print '<td class="right">'.price(-$subtotal_ttc).'</td>';
1147 print '</tr>';
1148 }
1149
1150
1151 /*
1152 * Various Payments
1153 */
1154 //$conf->global->ACCOUNTING_REPORTS_INCLUDE_VARPAY = 1;
1155
1156 if (getDolGlobalString('ACCOUNTING_REPORTS_INCLUDE_VARPAY') && isModEnabled("bank") && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES")) {
1157 $subtotal_ht = 0;
1158 $subtotal_ttc = 0;
1159
1160 print '<tr class="trforbreak"><td colspan="4">'.$langs->trans("VariousPayment").'</td></tr>';
1161
1162 // Debit
1163 $sql = "SELECT SUM(p.amount) AS amount FROM ".MAIN_DB_PREFIX."payment_various as p";
1164 $sql .= ' WHERE 1 = 1';
1165 if (!empty($date_start) && !empty($date_end)) {
1166 $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
1167 }
1168 $sql .= ' GROUP BY p.sens';
1169 $sql .= ' ORDER BY p.sens';
1170
1171 dol_syslog('get various payments', LOG_DEBUG);
1172 $result = $db->query($sql);
1173 if ($result) {
1174 // Debit (payment of suppliers for example)
1175 $obj = $db->fetch_object($result);
1176 if (isset($obj->amount)) {
1177 $subtotal_ht += -$obj->amount;
1178 $subtotal_ttc += -$obj->amount;
1179
1180 $total_ht_outcome += $obj->amount;
1181 $total_ttc_outcome += $obj->amount;
1182 }
1183 print '<tr class="oddeven">';
1184 print '<td>&nbsp;</td>';
1185 print "<td>".$langs->trans("AccountingDebit")."</td>\n";
1186 print '<td class="right">';
1187 if ($modecompta == 'CREANCES-DETTES') {
1188 print '<span class="amount">'.price(-$obj->amount).'</span>';
1189 }
1190 print '</td>';
1191 print '<td class="right"><span class="amount">'.price(-$obj->amount)."</span></td>\n";
1192 print "</tr>\n";
1193
1194 // Credit (payment received from customer for example)
1195 $obj = $db->fetch_object($result);
1196 if (isset($obj->amount)) {
1197 $subtotal_ht += $obj->amount;
1198 $subtotal_ttc += $obj->amount;
1199
1200 $total_ht_income += $obj->amount;
1201 $total_ttc_income += $obj->amount;
1202 }
1203 print '<tr class="oddeven"><td>&nbsp;</td>';
1204 print "<td>".$langs->trans("AccountingCredit")."</td>\n";
1205 print '<td class="right">';
1206 if ($modecompta == 'CREANCES-DETTES') {
1207 print '<span class="amount">'.price($obj->amount).'</span>';
1208 }
1209 print '</td>';
1210 print '<td class="right"><span class="amount">'.price($obj->amount)."</span></td>\n";
1211 print "</tr>\n";
1212
1213 // Total
1214 $total_ht += $subtotal_ht;
1215 $total_ttc += $subtotal_ttc;
1216 print '<tr class="liste_total">';
1217 print '<td></td>';
1218 print '<td></td>';
1219 print '<td class="right">';
1220 if ($modecompta == 'CREANCES-DETTES') {
1221 print price($subtotal_ht);
1222 }
1223 print '</td>';
1224 print '<td class="right">'.price($subtotal_ttc).'</td>';
1225 print '</tr>';
1226 } else {
1227 dol_print_error($db);
1228 }
1229 }
1230
1231 /*
1232 * Payment Loan
1233 */
1234
1235 if (getDolGlobalString('ACCOUNTING_REPORTS_INCLUDE_LOAN') && isModEnabled('don') && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES")) {
1236 $subtotal_ht = 0;
1237 $subtotal_ttc = 0;
1238
1239 print '<tr class="trforbreak"><td colspan="4">'.$langs->trans("PaymentLoan").'</td></tr>';
1240
1241 $sql = 'SELECT l.rowid as id, l.label AS label, SUM(p.amount_capital + p.amount_insurance + p.amount_interest) as amount FROM '.MAIN_DB_PREFIX.'payment_loan as p';
1242 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'loan AS l ON l.rowid = p.fk_loan';
1243 $sql .= ' WHERE 1 = 1';
1244 if (!empty($date_start) && !empty($date_end)) {
1245 $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
1246 }
1247 $sql .= ' GROUP BY p.fk_loan';
1248 $sql .= ' ORDER BY p.fk_loan';
1249
1250 dol_syslog('get loan payments', LOG_DEBUG);
1251 $result = $db->query($sql);
1252 if ($result) {
1253 require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php';
1254 $loan_static = new Loan($db);
1255 while ($obj = $db->fetch_object($result)) {
1256 $loan_static->id = $obj->id;
1257 $loan_static->ref = $obj->id;
1258 $loan_static->label = $obj->label;
1259 print '<tr class="oddeven"><td>&nbsp;</td>';
1260 print "<td>".$loan_static->getNomUrl(1).' - '.$obj->label."</td>\n";
1261 if ($modecompta == 'CREANCES-DETTES') {
1262 print '<td class="right"><span class="amount">'.price(-$obj->amount).'</span></td>';
1263 }
1264 print '<td class="right"><span class="amount">'.price(-$obj->amount)."</span></td>\n";
1265 print "</tr>\n";
1266 $subtotal_ht -= $obj->amount;
1267 $subtotal_ttc -= $obj->amount;
1268 }
1269 $total_ht += $subtotal_ht;
1270 $total_ttc += $subtotal_ttc;
1271
1272 $total_ht_income += $subtotal_ht;
1273 $total_ttc_income += $subtotal_ttc;
1274
1275 print '<tr class="liste_total">';
1276 print '<td></td>';
1277 print '<td></td>';
1278 print '<td class="right">';
1279 if ($modecompta == 'CREANCES-DETTES') {
1280 print price($subtotal_ht);
1281 }
1282 print '</td>';
1283 print '<td class="right">'.price($subtotal_ttc).'</td>';
1284 print '</tr>';
1285 } else {
1286 dol_print_error($db);
1287 }
1288 }
1289
1290 /*
1291 * VAT
1292 */
1293
1294 print '<tr class="trforbreak"><td colspan="4">'.$langs->trans("VAT").'</td></tr>';
1295 $subtotal_ht = 0;
1296 $subtotal_ttc = 0;
1297
1298 if (isModEnabled('tax') && ($modecompta == 'CREANCES-DETTES' || $modecompta == 'RECETTES-DEPENSES')) {
1299 if ($modecompta == 'CREANCES-DETTES') {
1300 // VAT to pay
1301 $amount = 0;
1302 $sql = "SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total_tva) as amount";
1303 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
1304 $sql .= " WHERE f.fk_statut IN (1,2)";
1305 if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) {
1306 $sql .= " AND f.type IN (0,1,2,5)";
1307 } else {
1308 $sql .= " AND f.type IN (0,1,2,3,5)";
1309 }
1310 if (!empty($date_start) && !empty($date_end)) {
1311 $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
1312 }
1313 $sql .= " AND f.entity IN (".getEntity('invoice').")";
1314 $sql .= " GROUP BY dm";
1315 $newsortfield = $sortfield;
1316 if ($newsortfield == 's.nom, s.rowid') {
1317 $newsortfield = 'dm';
1318 }
1319 if ($newsortfield == 'amount_ht') {
1320 $newsortfield = 'amount';
1321 }
1322 if ($newsortfield == 'amount_ttc') {
1323 $newsortfield = 'amount';
1324 }
1325 $sql .= $db->order($newsortfield, $sortorder);
1326
1327 dol_syslog("get vat to pay", LOG_DEBUG);
1328 $result = $db->query($sql);
1329 if ($result) {
1330 $num = $db->num_rows($result);
1331 $i = 0;
1332 if ($num) {
1333 while ($i < $num) {
1334 $obj = $db->fetch_object($result);
1335
1336 $amount -= $obj->amount;
1337 //$total_ht -= $obj->amount;
1338 $total_ttc -= $obj->amount;
1339 //$subtotal_ht -= $obj->amount;
1340 $subtotal_ttc -= $obj->amount;
1341 $i++;
1342 }
1343 }
1344 } else {
1345 dol_print_error($db);
1346 }
1347
1348 $total_ht_outcome -= 0;
1349 $total_ttc_outcome -= $amount;
1350
1351 print '<tr class="oddeven">';
1352 print '<td>&nbsp;</td>';
1353 print "<td>".$langs->trans("VATToPay")."</td>\n";
1354 print '<td class="right">&nbsp;</td>'."\n";
1355 print '<td class="right"><span class="amount">'.price($amount)."</span></td>\n";
1356 print "</tr>\n";
1357
1358 // VAT to retrieve
1359 $amount = 0;
1360 $sql = "SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total_tva) as amount";
1361 $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
1362 $sql .= " WHERE f.fk_statut IN (1,2)";
1363 if (getDolGlobalString('FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS')) {
1364 $sql .= " AND f.type IN (0,1,2)";
1365 } else {
1366 $sql .= " AND f.type IN (0,1,2,3)";
1367 }
1368 if (!empty($date_start) && !empty($date_end)) {
1369 $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
1370 }
1371 $sql .= " AND f.entity = ".$conf->entity;
1372 $sql .= " GROUP BY dm";
1373 $newsortfield = $sortfield;
1374 if ($newsortfield == 's.nom, s.rowid') {
1375 $newsortfield = 'dm';
1376 }
1377 if ($newsortfield == 'amount_ht') {
1378 $newsortfield = 'amount';
1379 }
1380 if ($newsortfield == 'amount_ttc') {
1381 $newsortfield = 'amount';
1382 }
1383 $sql .= $db->order($newsortfield, $sortorder);
1384
1385 dol_syslog("get vat received back", LOG_DEBUG);
1386 $result = $db->query($sql);
1387 if ($result) {
1388 $num = $db->num_rows($result);
1389 $i = 0;
1390 if ($num) {
1391 while ($i < $num) {
1392 $obj = $db->fetch_object($result);
1393
1394 $amount += $obj->amount;
1395 //$total_ht += $obj->amount;
1396 $total_ttc += $obj->amount;
1397 //$subtotal_ht += $obj->amount;
1398 $subtotal_ttc += $obj->amount;
1399
1400 $i++;
1401 }
1402 }
1403 } else {
1404 dol_print_error($db);
1405 }
1406
1407 $total_ht_income += 0;
1408 $total_ttc_income += $amount;
1409
1410 print '<tr class="oddeven">';
1411 print '<td>&nbsp;</td>';
1412 print '<td>'.$langs->trans("VATToCollect")."</td>\n";
1413 print '<td class="right">&nbsp;</td>'."\n";
1414 print '<td class="right"><span class="amount">'.price($amount)."</span></td>\n";
1415 print "</tr>\n";
1416 } else {
1417 // VAT really already paid
1418 $amount = 0;
1419 $sql = "SELECT date_format(t.datev,'%Y-%m') as dm, sum(t.amount) as amount";
1420 $sql .= " FROM ".MAIN_DB_PREFIX."tva as t";
1421 $sql .= " WHERE amount > 0";
1422 if (!empty($date_start) && !empty($date_end)) {
1423 $sql .= " AND t.datev >= '".$db->idate($date_start)."' AND t.datev <= '".$db->idate($date_end)."'";
1424 }
1425 $sql .= " AND t.entity = ".$conf->entity;
1426 $sql .= " GROUP BY dm";
1427 $newsortfield = $sortfield;
1428 if ($newsortfield == 's.nom, s.rowid') {
1429 $newsortfield = 'dm';
1430 }
1431 if ($newsortfield == 'amount_ht') {
1432 $newsortfield = 'amount';
1433 }
1434 if ($newsortfield == 'amount_ttc') {
1435 $newsortfield = 'amount';
1436 }
1437 $sql .= $db->order($newsortfield, $sortorder);
1438
1439 dol_syslog("get vat really paid", LOG_DEBUG);
1440 $result = $db->query($sql);
1441 if ($result) {
1442 $num = $db->num_rows($result);
1443 $i = 0;
1444 if ($num) {
1445 while ($i < $num) {
1446 $obj = $db->fetch_object($result);
1447
1448 $amount -= $obj->amount;
1449 $total_ht -= $obj->amount;
1450 $total_ttc -= $obj->amount;
1451 $subtotal_ht -= $obj->amount;
1452 $subtotal_ttc -= $obj->amount;
1453
1454 $i++;
1455 }
1456 }
1457 $db->free($result);
1458 } else {
1459 dol_print_error($db);
1460 }
1461
1462 $total_ht_outcome -= 0;
1463 $total_ttc_outcome -= $amount;
1464
1465 print '<tr class="oddeven">';
1466 print '<td>&nbsp;</td>';
1467 print "<td>".$langs->trans("VATPaid")."</td>\n";
1468 print '<td <class="right"></td>'."\n";
1469 print '<td class="right"><span class="amount">'.price($amount)."</span></td>\n";
1470 print "</tr>\n";
1471
1472 // VAT really received
1473 $amount = 0;
1474 $sql = "SELECT date_format(t.datev,'%Y-%m') as dm, sum(t.amount) as amount";
1475 $sql .= " FROM ".MAIN_DB_PREFIX."tva as t";
1476 $sql .= " WHERE amount < 0";
1477 if (!empty($date_start) && !empty($date_end)) {
1478 $sql .= " AND t.datev >= '".$db->idate($date_start)."' AND t.datev <= '".$db->idate($date_end)."'";
1479 }
1480 $sql .= " AND t.entity = ".$conf->entity;
1481 $sql .= " GROUP BY dm";
1482 $newsortfield = $sortfield;
1483 if ($newsortfield == 's.nom, s.rowid') {
1484 $newsortfield = 'dm';
1485 }
1486 if ($newsortfield == 'amount_ht') {
1487 $newsortfield = 'amount';
1488 }
1489 if ($newsortfield == 'amount_ttc') {
1490 $newsortfield = 'amount';
1491 }
1492 $sql .= $db->order($newsortfield, $sortorder);
1493
1494 dol_syslog("get vat really received back", LOG_DEBUG);
1495 $result = $db->query($sql);
1496 if ($result) {
1497 $num = $db->num_rows($result);
1498 $i = 0;
1499 if ($num) {
1500 while ($i < $num) {
1501 $obj = $db->fetch_object($result);
1502
1503 $amount += -$obj->amount;
1504 $total_ht += -$obj->amount;
1505 $total_ttc += -$obj->amount;
1506 $subtotal_ht += -$obj->amount;
1507 $subtotal_ttc += -$obj->amount;
1508
1509 $i++;
1510 }
1511 }
1512 $db->free($result);
1513 } else {
1514 dol_print_error($db);
1515 }
1516
1517 $total_ht_income += 0;
1518 $total_ttc_income += $amount;
1519
1520 print '<tr class="oddeven">';
1521 print '<td>&nbsp;</td>';
1522 print "<td>".$langs->trans("VATCollected")."</td>\n";
1523 print '<td class="right"></td>'."\n";
1524 print '<td class="right"><span class="amount">'.price($amount)."</span></td>\n";
1525 print "</tr>\n";
1526 }
1527 }
1528
1529 if ($mysoc->tva_assuj != '0') { // Assujetti
1530 print '<tr class="liste_total">';
1531 print '<td></td>';
1532 print '<td></td>';
1533 print '<td class="right">&nbsp;</td>';
1534 print '<td class="right">'.price(price2num($subtotal_ttc, 'MT')).'</td>';
1535 print '</tr>';
1536 }
1537}
1538
1539$action = "balanceclient";
1540$object = array(&$total_ht, &$total_ttc);
1541$parameters["mode"] = $modecompta;
1542$parameters["date_start"] = $date_start;
1543$parameters["date_end"] = $date_end;
1544// Initialize a technical object to manage hooks of expenses. Note that conf->hooks_modules contains array array
1545$hookmanager->initHooks(array('externalbalance'));
1546$reshook = $hookmanager->executeHooks('addBalanceLine', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
1547print $hookmanager->resPrint;
1548
1549
1550
1551// Total
1552print '<tr>';
1553print '<td colspan="'.($modecompta == 'BOOKKEEPING' ? 3 : 4).'">&nbsp;</td>';
1554print '</tr>';
1555
1556print '<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans("Income").'</td>';
1557if ($modecompta == 'CREANCES-DETTES') {
1558 print '<td class="liste_total right nowraponall">'.price(price2num($total_ht_income, 'MT')).'</td>';
1559} elseif ($modecompta == 'RECETTES-DEPENSES') {
1560 print '<td></td>';
1561}
1562print '<td class="liste_total right nowraponall">'.price(price2num($total_ttc_income, 'MT')).'</td>';
1563print '</tr>';
1564print '<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans("Outcome").'</td>';
1565if ($modecompta == 'CREANCES-DETTES') {
1566 print '<td class="liste_total right nowraponall">'.price(price2num(-$total_ht_outcome, 'MT')).'</td>';
1567} elseif ($modecompta == 'RECETTES-DEPENSES') {
1568 print '<td></td>';
1569}
1570print '<td class="liste_total right nowraponall">'.price(price2num(-$total_ttc_outcome, 'MT')).'</td>';
1571print '</tr>';
1572print '<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans("Profit").'</td>';
1573if ($modecompta == 'CREANCES-DETTES') {
1574 print '<td class="liste_total right nowraponall">'.price(price2num($total_ht, 'MT')).'</td>';
1575} elseif ($modecompta == 'RECETTES-DEPENSES') {
1576 print '<td></td>';
1577}
1578print '<td class="liste_total right nowraponall">'.price(price2num($total_ttc, 'MT')).'</td>';
1579print '</tr>';
1580
1581print "</table>";
1582print '<br>';
1583
1584// End of page
1585llxFooter();
1586$db->close();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:71
Class to manage categories of an accounting account.
Class to manage accounting accounts.
Class to manage generation of HTML components Only common components must be here.
Loan.
Class to manage Dolibarr users.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition date.lib.php:600
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition date.lib.php:619
llxFooter()
Footer empty.
Definition document.php:107
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='')
Return an id or code from a code or id.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
img_previous($titlealt='default', $moreatt='')
Show previous logo.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_next($titlealt='default', $moreatt='')
Show next logo.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
report_header($reportname, $notused, $period, $periodlink, $description, $builddate, $exportlink='', $moreparam=array(), $calcmode='', $varlink='')
Show header of a report.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.