dolibarr 24.0.2
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-2026 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$description = '';
193
194// Affiche en-tete de rapport
195if ($modecompta == "CREANCES-DETTES") {
196 $name = $langs->trans("ReportInOut").', '.$langs->trans("ByPredefinedAccountGroups");
197 $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
198 $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>" : "");
199 $description = $langs->trans("RulesResultDue");
200 if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) {
201 $description .= $langs->trans("DepositsAreNotIncluded");
202 } else {
203 $description .= $langs->trans("DepositsAreIncluded");
204 }
205 if (getDolGlobalString('FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS')) {
206 $description .= $langs->trans("SupplierDepositsAreNotIncluded");
207 }
208 $builddate = dol_now();
209 //$exportlink=$langs->trans("NotYetAvailable");
210} elseif ($modecompta == "RECETTES-DEPENSES") {
211 $name = $langs->trans("ReportInOut").', '.$langs->trans("ByPredefinedAccountGroups");
212 $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
213 $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>" : "");
214 $description = $langs->trans("RulesResultInOut");
215 $builddate = dol_now();
216 //$exportlink=$langs->trans("NotYetAvailable");
217} elseif ($modecompta == "BOOKKEEPING") {
218 $name = $langs->trans("ReportInOut").', '.$langs->trans("ByPredefinedAccountGroups");
219 $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
220 $arraylist = array('no' => $langs->trans("CustomerCode"), 'yes' => $langs->trans("AccountWithNonZeroValues"), 'all' => $langs->trans("All"));
221 $period .= ' &nbsp; &nbsp; <span class="opacitymedium">'.$langs->trans("DetailBy").'</span> '.$form->selectarray('showaccountdetail', $arraylist, $showaccountdetail, 0);
222 $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>" : "");
223 $description = $langs->trans("RulesResultBookkeepingPredefined");
224 $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")).')';
225 $builddate = dol_now();
226 //$exportlink=$langs->trans("NotYetAvailable");
227}
228
229// Define $calcmode line
230$calcmode = '';
231if (isModEnabled('accounting')) {
232 $calcmode .= '<input type="radio" name="modecompta" id="modecompta3" value="BOOKKEEPING"'.($modecompta == 'BOOKKEEPING' ? ' checked="checked"' : '').'><label for="modecompta3"> '.$langs->trans("CalcModeBookkeeping").'</label>';
233 $calcmode .= '<br>';
234}
235$calcmode .= '<input type="radio" name="modecompta" id="modecompta1" value="RECETTES-DEPENSES"'.($modecompta == 'RECETTES-DEPENSES' ? ' checked="checked"' : '').'><label for="modecompta1"> '.$langs->trans("CalcModePayment");
236if (isModEnabled('accounting')) {
237 $calcmode .= ' <span class="opacitymedium hideonsmartphone">('.$langs->trans("CalcModeNoBookKeeping").')</span>';
238}
239$calcmode .= '</label>';
240$calcmode .= '<br><input type="radio" name="modecompta" id="modecompta2" value="CREANCES-DETTES"'.($modecompta == 'CREANCES-DETTES' ? ' checked="checked"' : '').'><label for="modecompta2"> '.$langs->trans("CalcModeDebt");
241if (isModEnabled('accounting')) {
242 $calcmode .= ' <span class="opacitymedium hideonsmartphone">('.$langs->trans("CalcModeNoBookKeeping").')</span>';
243}
244$calcmode .= '</label>';
245
246
247report_header($name, '', $period, $periodlink, $description, $builddate, $exportlink, array('modecompta' => $modecompta, 'showaccountdetail' => $showaccountdetail), $calcmode);
248
249if (isModEnabled('accounting') && $modecompta != 'BOOKKEEPING') {
250 print info_admin($langs->trans("WarningReportNotReliable"), 0, 0, '1');
251}
252
253// Show report array
254$param = '&modecompta='.urlencode($modecompta).'&showaccountdetail='.urlencode($showaccountdetail);
255if ($date_startday) {
256 $param .= '&date_startday='.$date_startday;
257}
258if ($date_startmonth) {
259 $param .= '&date_startmonth='.$date_startmonth;
260}
261if ($date_startyear) {
262 $param .= '&date_startyear='.$date_startyear;
263}
264if ($date_endday) {
265 $param .= '&date_endday='.$date_endday;
266}
267if ($date_endmonth) {
268 $param .= '&date_endmonth='.$date_endmonth;
269}
270if ($date_endyear) {
271 $param .= '&date_endyear='.$date_endyear;
272}
273
274print '<table class="liste noborder centpercent">';
275print '<tr class="liste_titre">';
276
277if ($modecompta == 'BOOKKEEPING') {
278 print_liste_field_titre("PredefinedGroups", $_SERVER["PHP_SELF"], 'f.thirdparty_code,f.rowid', '', $param, '', $sortfield, $sortorder, '');
279} else {
280 print_liste_field_titre("", $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, '');
281}
283if ($modecompta == 'BOOKKEEPING') {
284 print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], 'amount', '', $param, 'class="right"', $sortfield, $sortorder);
285} else {
286 if ($modecompta == 'CREANCES-DETTES') {
287 print_liste_field_titre("AmountHT", $_SERVER["PHP_SELF"], 'amount_ht', '', $param, 'class="right"', $sortfield, $sortorder);
288 } else {
289 print_liste_field_titre(''); // Make 4 columns in total whatever $modecompta is
290 }
291 print_liste_field_titre("AmountTTC", $_SERVER["PHP_SELF"], 'amount_ttc', '', $param, 'class="right"', $sortfield, $sortorder);
292}
293print "</tr>\n";
294
295
296$total_ht_outcome = $total_ttc_outcome = $total_ht_income = $total_ttc_income = 0;
297
298
299if ($modecompta == 'BOOKKEEPING') {
300 $sanitizedpredefinedgroupwhere = "(";
301 // Some shipped charts of accounts (e.g. US-BASE) split income and expense
302 // accounts across more than one pcg_type value (COGS, OTHER_REVENUE,
303 // OTHER_EXPENSES), unlike FR/GB-style charts which only use INCOME/EXPENSE.
304 // Include those here so this report does not silently omit them.
305 $sanitizedpredefinedgroupwhere .= " (pcg_type IN ('EXPENSE', 'COGS', 'OTHER_EXPENSES'))";
306 $sanitizedpredefinedgroupwhere .= " OR ";
307 $sanitizedpredefinedgroupwhere .= " (pcg_type IN ('INCOME', 'OTHER_REVENUE'))";
308 $sanitizedpredefinedgroupwhere .= ")";
309
310 $charofaccountstring = getDolGlobalInt('CHARTOFACCOUNTS');
311 $charofaccountstring = dol_getIdFromCode($db, getDolGlobalString('CHARTOFACCOUNTS'), 'accounting_system', 'rowid', 'pcg_version');
312
313 $sql = "SELECT -1 as socid, aa.pcg_type, SUM(f.credit - f.debit) as amount";
314 if ($showaccountdetail == 'no') {
315 $sql .= ", f.thirdparty_code as name";
316 }
317 $sql .= " FROM ".$db->prefix()."accounting_bookkeeping as f";
318 $sql .= " INNER JOIN ".$db->prefix()."accounting_account as aa";
319 $sql .= " ON aa.account_number = f.numero_compte";
320 $sql .= " AND aa.entity = f.entity"; // Security prevents duplicate.
321 $sql .= " WHERE 1=1";
322 $sql .= " AND ".$sanitizedpredefinedgroupwhere;
323 $sql .= " AND aa.fk_pcg_version = '".$db->escape($charofaccountstring)."'";
324 $sql .= " AND f.entity = ".((int) $conf->entity);
325 if (!empty($date_start) && !empty($date_end)) {
326 $sql .= " AND f.doc_date >= '".$db->idate($date_start)."'";
327 $sql .= " AND f.doc_date <= '".$db->idate($date_end)."'";
328 }
329 $sql .= " GROUP BY aa.pcg_type";
330 if ($showaccountdetail == 'no') {
331 $sql .= ", name, socid"; // group by "accounting group" (INCOME/EXPENSE), then "customer".
332 }
333 $sql .= $db->order($sortfield, $sortorder);
334
335 $oldpcgtype = '';
336
337 dol_syslog("get bookkeeping entries", LOG_DEBUG);
338 $result = $db->query($sql);
339 if ($result) {
340 $num = $db->num_rows($result);
341 $i = 0;
342 if ($num > 0) {
343 while ($i < $num) {
344 $objp = $db->fetch_object($result);
345
346 if ($showaccountdetail == 'no') {
347 if ($objp->pcg_type != $oldpcgtype) {
348 print '<tr class="trforbreak"><td colspan="3" class="tdforbreak">'.dol_escape_htmltag($objp->pcg_type).'</td></tr>';
349 $oldpcgtype = $objp->pcg_type;
350 }
351 }
352
353 if ($showaccountdetail == 'no') {
354 print '<tr class="oddeven">';
355 print '<td></td>';
356 print '<td>';
357 print dol_escape_htmltag($objp->pcg_type);
358 print($objp->name ? ' ('.dol_escape_htmltag($objp->name).')' : ' ('.$langs->trans("Unknown").')');
359 print "</td>\n";
360 print '<td class="right nowraponall"><span class="amount">'.price($objp->amount)."</span></td>\n";
361 print "</tr>\n";
362 } else {
363 print '<tr class="oddeven trforbreak">';
364 print '<td colspan="2" class="tdforbreak">';
365 print dol_escape_htmltag($objp->pcg_type);
366 print "</td>\n";
367 print '<td class="right nowraponall tdforbreak"><span class="amount">'.price($objp->amount)."</span></td>\n";
368 print "</tr>\n";
369 }
370
371 $total_ht += (isset($objp->amount) ? $objp->amount : 0);
372 $total_ttc += (isset($objp->amount) ? $objp->amount : 0);
373
374 if (in_array($objp->pcg_type, array('INCOME', 'OTHER_REVENUE'))) {
375 $total_ht_income += (isset($objp->amount) ? $objp->amount : 0);
376 $total_ttc_income += (isset($objp->amount) ? $objp->amount : 0);
377 }
378 if (in_array($objp->pcg_type, array('EXPENSE', 'COGS', 'OTHER_EXPENSES'))) {
379 $total_ht_outcome -= (isset($objp->amount) ? $objp->amount : 0);
380 $total_ttc_outcome -= (isset($objp->amount) ? $objp->amount : 0);
381 }
382
383 // Loop on detail of all accounts
384 // This make 14 calls for each detail of account (NP, N and month m)
385 if ($showaccountdetail != 'no') {
386 $tmppredefinedgroupwhere = "pcg_type = '".$db->escape($objp->pcg_type)."'";
387 $tmppredefinedgroupwhere .= " AND fk_pcg_version = '".$db->escape($charofaccountstring)."'";
388 //$tmppredefinedgroupwhere .= " AND thirdparty_code = '".$db->escape($objp->name)."'";
389
390 // Get cpts of category/group
391 $cpts = $AccCat->getCptsCat(0, $tmppredefinedgroupwhere);
392
393 foreach ($cpts as $j => $cpt) {
394 $return = $AccCat->getSumDebitCredit($cpt['account_number'], $date_start, $date_end, (empty($cpt['dc']) ? 0 : $cpt['dc']));
395 if ($return < 0) {
396 setEventMessages(null, $AccCat->errors, 'errors');
397 $resultN = 0;
398 } else {
399 $resultN = $AccCat->sdc;
400 }
401
402
403 if ($showaccountdetail == 'all' || $resultN != 0) {
404 print '<tr>';
405 print '<td></td>';
406 print '<td class="tdoverflowmax200"> &nbsp; &nbsp; '.length_accountg($cpt['account_number']).' - '.$cpt['account_label'].'</td>';
407 print '<td class="right nowraponall"><span class="amount">'.price($resultN).'</span></td>';
408 print "</tr>\n";
409 }
410 }
411 }
412
413 $i++;
414 }
415 } else {
416 print '<tr><td colspan="3" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
417 }
418 } else {
420 }
421} else {
422 /*
423 * Customer invoices
424 */
425 print '<tr class="trforbreak"><td colspan="4">'.$langs->trans("CustomersInvoices").'</td></tr>';
426
427 if ($modecompta == 'CREANCES-DETTES') {
428 $sql = "SELECT s.nom as name, s.rowid as socid, sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc";
429 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
430 $sql .= ", ".MAIN_DB_PREFIX."facture as f";
431 $sql .= " WHERE f.fk_soc = s.rowid";
432 $sql .= " AND f.fk_statut IN (1,2)";
433 if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) {
434 $sql .= " AND f.type IN (0,1,2,5)";
435 } else {
436 $sql .= " AND f.type IN (0,1,2,3,5)";
437 }
438 if (!empty($date_start) && !empty($date_end)) {
439 $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
440 }
441 } elseif ($modecompta == 'RECETTES-DEPENSES') {
442 /*
443 * List of payments (old payments are not seen by this query because, on older versions, they were not linked via payment_invoice.
444 * old versions, they were not linked via payment_invoice. They are added later)
445 */
446 $sql = "SELECT s.nom as name, s.rowid as socid, sum(pf.amount) as amount_ttc";
447 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
448 $sql .= ", ".MAIN_DB_PREFIX."facture as f";
449 $sql .= ", ".MAIN_DB_PREFIX."paiement_facture as pf";
450 $sql .= ", ".MAIN_DB_PREFIX."paiement as p";
451 $sql .= " WHERE p.rowid = pf.fk_paiement";
452 $sql .= " AND pf.fk_facture = f.rowid";
453 $sql .= " AND f.fk_soc = s.rowid";
454 if (!empty($date_start) && !empty($date_end)) {
455 $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
456 }
457 } else {
458 $sql = '';
459 }
460 $sql .= " AND f.entity IN (".getEntity('invoice').")";
461 if ($socid) {
462 $sql .= " AND f.fk_soc = ".((int) $socid);
463 }
464 $sql .= " GROUP BY name, socid";
465 $sql .= $db->order($sortfield, $sortorder);
466
467 dol_syslog("get customer invoices", LOG_DEBUG);
468 $result = $db->query($sql);
469 if ($result) {
470 $num = $db->num_rows($result);
471 $i = 0;
472 while ($i < $num) {
473 $objp = $db->fetch_object($result);
474
475 print '<tr class="oddeven">';
476 print '<td>&nbsp;</td>';
477 print "<td>".$langs->trans("Bills").' <a href="'.DOL_URL_ROOT.'/compta/facture/list.php?socid='.$objp->socid.'">'.$objp->name."</td>\n";
478
479 print '<td class="right">';
480 if ($modecompta == 'CREANCES-DETTES') {
481 print '<span class="amount">'.price($objp->amount_ht)."</span>";
482 }
483 print "</td>\n";
484 print '<td class="right"><span class="amount">'.price($objp->amount_ttc)."</span></td>\n";
485
486 $total_ht += (isset($objp->amount_ht) ? $objp->amount_ht : 0);
487 $total_ttc += $objp->amount_ttc;
488 print "</tr>\n";
489 $i++;
490 }
491 $db->free($result);
492 } else {
494 }
495
496 // We add the old customer payments, not linked by payment_invoice
497 if ($modecompta == 'RECETTES-DEPENSES') {
498 $sql = "SELECT 'Autres' as name, '0' as idp, sum(p.amount) as amount_ttc";
499 $sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
500 $sql .= ", ".MAIN_DB_PREFIX."bank_account as ba";
501 $sql .= ", ".MAIN_DB_PREFIX."paiement as p";
502 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement";
503 $sql .= " WHERE pf.rowid IS NULL";
504 $sql .= " AND p.fk_bank = b.rowid";
505 $sql .= " AND b.fk_account = ba.rowid";
506 $sql .= " AND ba.entity IN (".getEntity('bank_account').")";
507 if (!empty($date_start) && !empty($date_end)) {
508 $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
509 }
510 $sql .= " GROUP BY name, idp";
511 $sql .= " ORDER BY name";
512
513 dol_syslog("get old customer payments not linked to invoices", LOG_DEBUG);
514 $result = $db->query($sql);
515 if ($result) {
516 $num = $db->num_rows($result);
517 $i = 0;
518 if ($num) {
519 while ($i < $num) {
520 $objp = $db->fetch_object($result);
521
522
523 print '<tr class="oddeven">';
524 print '<td>&nbsp;</td>';
525 print "<td>".$langs->trans("Bills")." ".$langs->trans("Other")." (".$langs->trans("PaymentsNotLinkedToInvoice").")\n";
526
527 print '<td class="right">';
528 if ($modecompta == 'CREANCES-DETTES') {
529 print '<span class="amount">'.price($objp->amount_ht)."</span></td>\n";
530 }
531 print '</td>';
532 print '<td class="right"><span class="amount">'.price($objp->amount_ttc)."</span></td>\n";
533
534 $total_ht += (isset($objp->amount_ht) ? $objp->amount_ht : 0);
535 $total_ttc += $objp->amount_ttc;
536
537 print "</tr>\n";
538 $i++;
539 }
540 }
541 $db->free($result);
542 } else {
544 }
545 }
546
547 if ($total_ttc == 0) {
548 print '<tr class="oddeven">';
549 print '<td>&nbsp;</td>';
550 print '<td colspan="3"><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
551 print '</tr>';
552 }
553
554 $total_ht_income += $total_ht;
555 $total_ttc_income += $total_ttc;
556
557 print '<tr class="liste_total">';
558 print '<td></td>';
559 print '<td></td>';
560 print '<td class="right">';
561 if ($modecompta == 'CREANCES-DETTES') {
562 print price($total_ht);
563 }
564 print '</td>';
565 print '<td class="right">'.price($total_ttc).'</td>';
566 print '</tr>';
567
568 /*
569 * Donations
570 */
571
572 if (isModEnabled('don')) {
573 print '<tr class="trforbreak"><td colspan="4">'.$langs->trans("Donations").'</td></tr>';
574
575 if ($modecompta == 'CREANCES-DETTES' || $modecompta == 'RECETTES-DEPENSES') {
576 if ($modecompta == 'CREANCES-DETTES') {
577 $sql = "SELECT p.societe as name, p.firstname, p.lastname, date_format(p.datedon,'%Y-%m') as dm, sum(p.amount) as amount";
578 $sql .= " FROM ".MAIN_DB_PREFIX."don as p";
579 $sql .= " WHERE p.entity IN (".getEntity('donation').")";
580 $sql .= " AND fk_statut in (1,2)";
581 } else {
582 $sql = "SELECT p.societe as nom, p.firstname, p.lastname, date_format(p.datedon,'%Y-%m') as dm, sum(pe.amount) as amount";
583 $sql .= " FROM ".MAIN_DB_PREFIX."don as p";
584 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."payment_donation as pe ON pe.fk_donation = p.rowid";
585 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON pe.fk_typepayment = c.id";
586 $sql .= " WHERE p.entity IN (".getEntity('donation').")";
587 $sql .= " AND fk_statut >= 2";
588 }
589 if (!empty($date_start) && !empty($date_end)) {
590 $sql .= " AND p.datedon >= '".$db->idate($date_start)."' AND p.datedon <= '".$db->idate($date_end)."'";
591 }
592 }
593 $sql .= " GROUP BY p.societe, p.firstname, p.lastname, dm";
594 $sqlNewSortField = $sortfield; // @phan-suppress-current-line SqlInjection
595 if ($sqlNewSortField == 's.nom, s.rowid') {
596 $sqlNewSortField = 'p.societe, p.firstname, p.lastname, dm';
597 }
598 if ($sqlNewSortField == 'amount_ht') {
599 $sqlNewSortField = 'amount';
600 }
601 if ($sqlNewSortField == 'amount_ttc') {
602 $sqlNewSortField = 'amount';
603 }
604 $sql .= $db->order($sqlNewSortField, $sortorder);
605
606 dol_syslog("get dunning");
607 $result = $db->query($sql);
608 $subtotal_ht = 0;
609 $subtotal_ttc = 0;
610 if ($result) {
611 $num = $db->num_rows($result);
612 $i = 0;
613 if ($num) {
614 while ($i < $num) {
615 $obj = $db->fetch_object($result);
616
617 $total_ht += $obj->amount;
618 $total_ttc += $obj->amount;
619 $subtotal_ht += $obj->amount;
620 $subtotal_ttc += $obj->amount;
621
622 print '<tr class="oddeven">';
623 print '<td>&nbsp;</td>';
624
625 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";
626
627 print '<td class="right">';
628 if ($modecompta == 'CREANCES-DETTES') {
629 print '<span class="amount">'.price($obj->amount).'</span>';
630 }
631 print '</td>';
632 print '<td class="right"><span class="amount">'.price($obj->amount).'</span></td>';
633 print '</tr>';
634 $i++;
635 }
636 } else {
637 print '<tr class="oddeven"><td>&nbsp;</td>';
638 print '<td colspan="3"><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
639 print '</tr>';
640 }
641 } else {
643 }
644
645 $total_ht_income += $subtotal_ht;
646 $total_ttc_income += $subtotal_ttc;
647
648 print '<tr class="liste_total">';
649 print '<td></td>';
650 print '<td></td>';
651 print '<td class="right">';
652 if ($modecompta == 'CREANCES-DETTES') {
653 print price($subtotal_ht);
654 }
655 print '</td>';
656 print '<td class="right">'.price($subtotal_ttc).'</td>';
657 print '</tr>';
658 }
659
660 /*
661 * Suppliers invoices
662 */
663 if ($modecompta == 'CREANCES-DETTES') {
664 $sql = "SELECT s.nom as name, s.rowid as socid, sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc";
665 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
666 $sql .= ", ".MAIN_DB_PREFIX."facture_fourn as f";
667 $sql .= " WHERE f.fk_soc = s.rowid";
668 $sql .= " AND f.fk_statut IN (1,2)";
669 if (getDolGlobalString('FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS')) {
670 $sql .= " AND f.type IN (0,1,2)";
671 } else {
672 $sql .= " AND f.type IN (0,1,2,3)";
673 }
674 if (!empty($date_start) && !empty($date_end)) {
675 $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
676 }
677 } elseif ($modecompta == 'RECETTES-DEPENSES') {
678 $sql = "SELECT s.nom as name, s.rowid as socid, sum(pf.amount) as amount_ttc";
679 $sql .= " FROM ".MAIN_DB_PREFIX."paiementfourn as p";
680 $sql .= ", ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf";
681 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture_fourn as f";
682 $sql .= " ON pf.fk_facturefourn = f.rowid";
683 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s";
684 $sql .= " ON f.fk_soc = s.rowid";
685 $sql .= " WHERE p.rowid = pf.fk_paiementfourn ";
686 if (!empty($date_start) && !empty($date_end)) {
687 $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
688 }
689 }
690
691 $sql .= " AND f.entity = ".((int) $conf->entity);
692 if ($socid) {
693 $sql .= " AND f.fk_soc = ".((int) $socid);
694 }
695 $sql .= " GROUP BY name, socid";
696 $sql .= $db->order($sortfield, $sortorder);
697
698 print '<tr class="trforbreak"><td colspan="4">'.$langs->trans("SuppliersInvoices").'</td></tr>';
699
700 $subtotal_ht = 0;
701 $subtotal_ttc = 0;
702 dol_syslog("get suppliers invoices", LOG_DEBUG);
703 $result = $db->query($sql);
704 if ($result) {
705 $num = $db->num_rows($result);
706 $i = 0;
707 if ($num > 0) {
708 while ($i < $num) {
709 $objp = $db->fetch_object($result);
710
711 print '<tr class="oddeven">';
712 print '<td>&nbsp;</td>';
713 print "<td>".$langs->trans("Bills").' <a href="'.DOL_URL_ROOT."/fourn/facture/list.php?socid=".$objp->socid.'">'.$objp->name.'</a></td>'."\n";
714
715 print '<td class="right">';
716 if ($modecompta == 'CREANCES-DETTES') {
717 print '<span class="amount">'.price(-$objp->amount_ht)."</span>";
718 }
719 print "</td>\n";
720 print '<td class="right"><span class="amount">'.price(-$objp->amount_ttc)."</span></td>\n";
721
722 $total_ht -= (isset($objp->amount_ht) ? $objp->amount_ht : 0);
723 $total_ttc -= $objp->amount_ttc;
724 $subtotal_ht += (isset($objp->amount_ht) ? $objp->amount_ht : 0);
725 $subtotal_ttc += $objp->amount_ttc;
726
727 print "</tr>\n";
728 $i++;
729 }
730 } else {
731 print '<tr class="oddeven">';
732 print '<td>&nbsp;</td>';
733 print '<td colspan="3"><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
734 print '</tr>';
735 }
736
737 $db->free($result);
738 } else {
740 }
741
742 $total_ht_outcome += $subtotal_ht;
743 $total_ttc_outcome += $subtotal_ttc;
744
745 print '<tr class="liste_total">';
746 print '<td></td>';
747 print '<td></td>';
748 print '<td class="right">';
749 if ($modecompta == 'CREANCES-DETTES') {
750 print price(-$subtotal_ht);
751 }
752 print '</td>';
753 print '<td class="right">'.price(-$subtotal_ttc).'</td>';
754 print '</tr>';
755
756
757 /*
758 * Social / Fiscal contributions who are not deductible
759 */
760
761 print '<tr class="trforbreak"><td colspan="4">'.$langs->trans("SocialContributionsNondeductibles").'</td></tr>';
762
763 if ($modecompta == 'CREANCES-DETTES') {
764 $sql = "SELECT c.id, c.libelle as label, c.accountancy_code, sum(cs.amount) as amount";
765 $sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c";
766 $sql .= ", ".MAIN_DB_PREFIX."chargesociales as cs";
767 $sql .= " WHERE cs.fk_type = c.id";
768 $sql .= " AND c.deductible = 0";
769 if (!empty($date_start) && !empty($date_end)) {
770 $sql .= " AND cs.date_ech >= '".$db->idate($date_start)."' AND cs.date_ech <= '".$db->idate($date_end)."'";
771 }
772 } elseif ($modecompta == 'RECETTES-DEPENSES') {
773 $sql = "SELECT c.id, c.libelle as label, c.accountancy_code, sum(p.amount) as amount";
774 $sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c";
775 $sql .= ", ".MAIN_DB_PREFIX."chargesociales as cs";
776 $sql .= ", ".MAIN_DB_PREFIX."paiementcharge as p";
777 $sql .= " WHERE p.fk_charge = cs.rowid";
778 $sql .= " AND cs.fk_type = c.id";
779 $sql .= " AND c.deductible = 0";
780 if (!empty($date_start) && !empty($date_end)) {
781 $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
782 }
783 }
784 $sql .= " AND cs.entity = ".((int) $conf->entity);
785 $sql .= " GROUP BY c.libelle, c.id, c.accountancy_code";
786 $sqlNewSortField = $sortfield; // @phan-suppress-current-line SqlInjection
787 if ($sqlNewSortField == 's.nom, s.rowid') {
788 $sqlNewSortField = 'c.libelle, c.id';
789 }
790 if ($sqlNewSortField == 'amount_ht') {
791 $sqlNewSortField = 'amount';
792 }
793 if ($sqlNewSortField == 'amount_ttc') {
794 $sqlNewSortField = 'amount';
795 }
796
797 $sql .= $db->order($sqlNewSortField, $sortorder);
798
799 dol_syslog("get social contributions deductible=0", LOG_DEBUG);
800 $result = $db->query($sql);
801 $subtotal_ht = 0;
802 $subtotal_ttc = 0;
803 if ($result) {
804 $num = $db->num_rows($result);
805 $i = 0;
806 if ($num) {
807 while ($i < $num) {
808 $obj = $db->fetch_object($result);
809
810 $total_ht -= $obj->amount;
811 $total_ttc -= $obj->amount;
812 $subtotal_ht += $obj->amount;
813 $subtotal_ttc += $obj->amount;
814
815 $titletoshow = '';
816 if ($obj->accountancy_code) {
817 $titletoshow = $langs->trans("AccountingCode").': '.$obj->accountancy_code;
818 $tmpaccountingaccount = new AccountingAccount($db);
819 $tmpaccountingaccount->fetch(0, $obj->accountancy_code, 1);
820 $titletoshow .= ' - '.$langs->trans("AccountingCategory").': '.$tmpaccountingaccount->pcg_type;
821 }
822
823 print '<tr class="oddeven">';
824 print '<td>&nbsp;</td>';
825 print '<td'.($obj->accountancy_code ? ' title="'.dol_escape_htmltag($titletoshow).'"' : '').'>'.dol_escape_htmltag($obj->label).'</td>';
826 print '<td class="right">';
827 if ($modecompta == 'CREANCES-DETTES') {
828 print '<span class="amount">'.price(-$obj->amount).'</span>';
829 }
830 print '</td>';
831 print '<td class="right"><span class="amount">'.price(-$obj->amount).'</span></td>';
832 print '</tr>';
833 $i++;
834 }
835 } else {
836 print '<tr class="oddeven">';
837 print '<td>&nbsp;</td>';
838 print '<td colspan="3"><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
839 print '</tr>';
840 }
841 } else {
843 }
844
845 $total_ht_outcome += $subtotal_ht;
846 $total_ttc_outcome += $subtotal_ttc;
847
848 print '<tr class="liste_total">';
849 print '<td></td>';
850 print '<td></td>';
851 print '<td class="right">';
852 if ($modecompta == 'CREANCES-DETTES') {
853 print price(-$subtotal_ht);
854 }
855 print '</td>';
856 print '<td class="right">'.price(-$subtotal_ttc).'</td>';
857 print '</tr>';
858
859
860 /*
861 * Social / Fiscal contributions who are deductible
862 */
863
864 print '<tr class="trforbreak"><td colspan="4">'.$langs->trans("SocialContributionsDeductibles").'</td></tr>';
865
866 if ($modecompta == 'CREANCES-DETTES') {
867 $sql = "SELECT c.id, c.libelle as label, c.accountancy_code, sum(cs.amount) as amount";
868 $sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c";
869 $sql .= ", ".MAIN_DB_PREFIX."chargesociales as cs";
870 $sql .= " WHERE cs.fk_type = c.id";
871 $sql .= " AND c.deductible = 1";
872 if (!empty($date_start) && !empty($date_end)) {
873 $sql .= " AND cs.date_ech >= '".$db->idate($date_start)."' AND cs.date_ech <= '".$db->idate($date_end)."'";
874 }
875 $sql .= " AND cs.entity = ".((int) $conf->entity);
876 } elseif ($modecompta == 'RECETTES-DEPENSES') {
877 $sql = "SELECT c.id, c.libelle as label, c.accountancy_code, sum(p.amount) as amount";
878 $sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c";
879 $sql .= ", ".MAIN_DB_PREFIX."chargesociales as cs";
880 $sql .= ", ".MAIN_DB_PREFIX."paiementcharge as p";
881 $sql .= " WHERE p.fk_charge = cs.rowid";
882 $sql .= " AND cs.fk_type = c.id";
883 $sql .= " AND c.deductible = 1";
884 if (!empty($date_start) && !empty($date_end)) {
885 $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
886 }
887 $sql .= " AND cs.entity = ".((int) $conf->entity);
888 }
889 $sql .= " GROUP BY c.libelle, c.id, c.accountancy_code";
890 $sqlNewSortField = $sortfield; // @phan-suppress-current-line SqlInjection
891 if ($sqlNewSortField == 's.nom, s.rowid') {
892 $sqlNewSortField = 'c.libelle, c.id';
893 }
894 if ($sqlNewSortField == 'amount_ht') {
895 $sqlNewSortField = 'amount';
896 }
897 if ($sqlNewSortField == 'amount_ttc') {
898 $sqlNewSortField = 'amount';
899 }
900 $sql .= $db->order($sqlNewSortField, $sortorder);
901
902 dol_syslog("get social contributions deductible=1", LOG_DEBUG);
903 $result = $db->query($sql);
904 $subtotal_ht = 0;
905 $subtotal_ttc = 0;
906 if ($result) {
907 $num = $db->num_rows($result);
908 $i = 0;
909 if ($num) {
910 while ($i < $num) {
911 $obj = $db->fetch_object($result);
912
913 $total_ht -= $obj->amount;
914 $total_ttc -= $obj->amount;
915 $subtotal_ht += $obj->amount;
916 $subtotal_ttc += $obj->amount;
917
918 $titletoshow = '';
919 if ($obj->accountancy_code) {
920 $titletoshow = $langs->trans("AccountingCode").': '.$obj->accountancy_code;
921 $tmpaccountingaccount = new AccountingAccount($db);
922 $tmpaccountingaccount->fetch(0, $obj->accountancy_code, 1);
923 $titletoshow .= ' - '.$langs->trans("AccountingCategory").': '.$tmpaccountingaccount->pcg_type;
924 }
925
926 print '<tr class="oddeven">';
927 print '<td>&nbsp;</td>';
928 print '<td'.($obj->accountancy_code ? ' title="'.dol_escape_htmltag($titletoshow).'"' : '').'>'.dol_escape_htmltag($obj->label).'</td>';
929 print '<td class="right">';
930 if ($modecompta == 'CREANCES-DETTES') {
931 print '<span class="amount">'.price(-$obj->amount).'</span>';
932 }
933 print '</td>';
934 print '<td class="right"><span class="amount">'.price(-$obj->amount).'</span></td>';
935 print '</tr>';
936 $i++;
937 }
938 } else {
939 print '<tr class="oddeven">';
940 print '<td>&nbsp;</td>';
941 print '<td colspan="3"><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
942 print '</tr>';
943 }
944 } else {
946 }
947
948 $total_ht_outcome += $subtotal_ht;
949 $total_ttc_outcome += $subtotal_ttc;
950
951 print '<tr class="liste_total">';
952 print '<td></td>';
953 print '<td></td>';
954 print '<td class="right">';
955 if ($modecompta == 'CREANCES-DETTES') {
956 print price(-$subtotal_ht);
957 }
958 print '</td>';
959 print '<td class="right">'.price(-$subtotal_ttc).'</td>';
960 print '</tr>';
961
962
963 /*
964 * Salaries
965 */
966
967 if (isModEnabled('salaries')) {
968 print '<tr class="trforbreak"><td colspan="4">'.$langs->trans("Salaries").'</td></tr>';
969
970 if ($modecompta == 'CREANCES-DETTES' || $modecompta == 'RECETTES-DEPENSES') {
971 if ($modecompta == 'CREANCES-DETTES') {
972 $column = 's.dateep'; // We use the date of end of period of salary
973
974 $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";
975 $sql .= " FROM ".MAIN_DB_PREFIX."salary as s";
976 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."user as u ON u.rowid = s.fk_user";
977 $sql .= " WHERE s.entity IN (".getEntity('salary').")";
978 if (!empty($date_start) && !empty($date_end)) {
979 $sql .= " AND $column >= '".$db->idate($date_start)."' AND $column <= '".$db->idate($date_end)."'";
980 }
981 $sql .= " GROUP BY u.rowid, u.firstname, u.lastname, s.fk_user, s.label, dm";
982 } else {
983 $column = 'p.datep';
984
985 $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";
986 $sql .= " FROM ".MAIN_DB_PREFIX."payment_salary as p";
987 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."salary as s ON s.rowid = p.fk_salary";
988 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."user as u ON u.rowid = s.fk_user";
989 $sql .= " WHERE p.entity IN (".getEntity('payment_salary').")";
990 if (!empty($date_start) && !empty($date_end)) {
991 $sql .= " AND $column >= '".$db->idate($date_start)."' AND $column <= '".$db->idate($date_end)."'";
992 }
993 $sql .= " GROUP BY u.rowid, u.firstname, u.lastname, s.fk_user, p.label, dm";
994 }
995
996 $sqlNewSortField = $sortfield; // @phan-suppress-current-line SqlInjection
997 if ($sqlNewSortField == 's.nom, s.rowid') {
998 $sqlNewSortField = 'u.firstname, u.lastname';
999 }
1000 if ($sqlNewSortField == 'amount_ht') {
1001 $sqlNewSortField = 'amount';
1002 }
1003 if ($sqlNewSortField == 'amount_ttc') {
1004 $sqlNewSortField = 'amount';
1005 }
1006 $sql .= $db->order($sqlNewSortField, $sortorder);
1007 }
1008
1009 dol_syslog("get salaries");
1010 $result = $db->query($sql);
1011 $subtotal_ht = 0;
1012 $subtotal_ttc = 0;
1013 if ($result) {
1014 $num = $db->num_rows($result);
1015 $i = 0;
1016 if ($num) {
1017 while ($i < $num) {
1018 $obj = $db->fetch_object($result);
1019
1020 $total_ht -= $obj->amount;
1021 $total_ttc -= $obj->amount;
1022 $subtotal_ht += $obj->amount;
1023 $subtotal_ttc += $obj->amount;
1024
1025 print '<tr class="oddeven"><td>&nbsp;</td>';
1026
1027 $userstatic = new User($db);
1028 $userstatic->fetch($obj->fk_user);
1029
1030 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";
1031 print '<td class="right">';
1032 if ($modecompta == 'CREANCES-DETTES') {
1033 print '<span class="amount">'.price(-$obj->amount).'</span>';
1034 }
1035 print '</td>';
1036 print '<td class="right"><span class="amount">'.price(-$obj->amount).'</span></td>';
1037 print '</tr>';
1038 $i++;
1039 }
1040 } else {
1041 print '<tr class="oddeven">';
1042 print '<td>&nbsp;</td>';
1043 print '<td colspan="3"><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
1044 print '</tr>';
1045 }
1046 } else {
1048 }
1049
1050 $total_ht_outcome += $subtotal_ht;
1051 $total_ttc_outcome += $subtotal_ttc;
1052
1053 print '<tr class="liste_total">';
1054 print '<td></td>';
1055 print '<td></td>';
1056 print '<td class="right">';
1057 if ($modecompta == 'CREANCES-DETTES') {
1058 print price(-$subtotal_ht);
1059 }
1060 print '</td>';
1061 print '<td class="right">'.price(-$subtotal_ttc).'</td>';
1062 print '</tr>';
1063 }
1064
1065
1066 /*
1067 * Expense report
1068 */
1069
1070 if (isModEnabled('expensereport')) {
1071 if ($modecompta == 'CREANCES-DETTES' || $modecompta == 'RECETTES-DEPENSES') {
1072 $langs->load('trips');
1073 if ($modecompta == 'CREANCES-DETTES') {
1074 $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";
1075 $sql .= " FROM ".MAIN_DB_PREFIX."expensereport as p";
1076 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."user as u ON u.rowid=p.fk_user_author";
1077 $sql .= " WHERE p.entity IN (".getEntity('expensereport').")";
1078 $sql .= " AND p.fk_statut>=5";
1079
1080 $column = 'p.date_valid';
1081 } else {
1082 $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";
1083 $sql .= " FROM ".MAIN_DB_PREFIX."expensereport as p";
1084 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."user as u ON u.rowid=p.fk_user_author";
1085 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."payment_expensereport as pe ON pe.fk_expensereport = p.rowid";
1086 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON pe.fk_typepayment = c.id";
1087 $sql .= " WHERE p.entity IN (".getEntity('expensereport').")";
1088 $sql .= " AND p.fk_statut>=5";
1089
1090 $column = 'pe.datep';
1091 }
1092
1093 if (!empty($date_start) && !empty($date_end)) {
1094 $sql .= " AND $column >= '".$db->idate($date_start)."' AND $column <= '".$db->idate($date_end)."'";
1095 }
1096
1097 if ($modecompta == 'CREANCES-DETTES') {
1098 //No need of GROUP BY
1099 } else {
1100 $sql .= " GROUP BY u.rowid, p.rowid, p.ref, u.firstname, u.lastname, dm";
1101 }
1102 $sqlNewSortField = $sortfield; // @phan-suppress-current-line SqlInjection
1103 if ($sqlNewSortField == 's.nom, s.rowid') {
1104 $sqlNewSortField = 'p.ref';
1105 }
1106 $sql .= $db->order($sqlNewSortField, $sortorder);
1107 }
1108
1109 print '<tr class="trforbreak"><td colspan="4">'.$langs->trans("ExpenseReport").'</td></tr>';
1110
1111 dol_syslog("get expense report outcome");
1112 $result = $db->query($sql);
1113 $subtotal_ht = 0;
1114 $subtotal_ttc = 0;
1115 if ($result) {
1116 $num = $db->num_rows($result);
1117 if ($num) {
1118 while ($obj = $db->fetch_object($result)) {
1119 $total_ht -= $obj->amount_ht;
1120 $total_ttc -= $obj->amount_ttc;
1121 $subtotal_ht += $obj->amount_ht;
1122 $subtotal_ttc += $obj->amount_ttc;
1123
1124 print '<tr class="oddeven">';
1125 print '<td>&nbsp;</td>';
1126 print "<td>".$langs->trans("ExpenseReport")." <a href=\"".DOL_URL_ROOT."/expensereport/list.php?search_user=".$obj->userid."\">".$obj->firstname." ".$obj->lastname."</a></td>\n";
1127 print '<td class="right">';
1128 if ($modecompta == 'CREANCES-DETTES') {
1129 print '<span class="amount">'.price(-$obj->amount_ht).'</span>';
1130 }
1131 print '</td>';
1132 print '<td class="right"><span class="amount">'.price(-$obj->amount_ttc).'</span></td>';
1133 print '</tr>';
1134 }
1135 } else {
1136 print '<tr class="oddeven">';
1137 print '<td>&nbsp;</td>';
1138 print '<td colspan="3"><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
1139 print '</tr>';
1140 }
1141 } else {
1143 }
1144
1145 $total_ht_outcome += $subtotal_ht;
1146 $total_ttc_outcome += $subtotal_ttc;
1147
1148 print '<tr class="liste_total">';
1149 print '<td></td>';
1150 print '<td></td>';
1151 print '<td class="right">';
1152 if ($modecompta == 'CREANCES-DETTES') {
1153 print price(-$subtotal_ht);
1154 }
1155 print '</td>';
1156 print '<td class="right">'.price(-$subtotal_ttc).'</td>';
1157 print '</tr>';
1158 }
1159
1160
1161 /*
1162 * Various Payments
1163 */
1164 //$conf->global->ACCOUNTING_REPORTS_INCLUDE_VARPAY = 1;
1165
1166 if (getDolGlobalString('ACCOUNTING_REPORTS_INCLUDE_VARPAY') && isModEnabled("bank") && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES")) {
1167 $subtotal_ht = 0;
1168 $subtotal_ttc = 0;
1169
1170 print '<tr class="trforbreak"><td colspan="4">'.$langs->trans("VariousPayment").'</td></tr>';
1171
1172 // Debit
1173 $sql = "SELECT SUM(p.amount) AS amount FROM ".MAIN_DB_PREFIX."payment_various as p";
1174 $sql .= ' WHERE 1 = 1';
1175 if (!empty($date_start) && !empty($date_end)) {
1176 $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
1177 }
1178 $sql .= ' GROUP BY p.sens';
1179 $sql .= ' ORDER BY p.sens';
1180
1181 dol_syslog('get various payments', LOG_DEBUG);
1182 $result = $db->query($sql);
1183 if ($result) {
1184 // Debit (payment of suppliers for example)
1185 $obj = $db->fetch_object($result);
1186 if (isset($obj->amount)) {
1187 $subtotal_ht += -$obj->amount;
1188 $subtotal_ttc += -$obj->amount;
1189
1190 $total_ht_outcome += $obj->amount;
1191 $total_ttc_outcome += $obj->amount;
1192 }
1193 $debit_amount = isset($obj->amount) ? $obj->amount : 0;
1194 print '<tr class="oddeven">';
1195 print '<td>&nbsp;</td>';
1196 print "<td>".$langs->trans("AccountingDebit")."</td>\n";
1197 print '<td class="right">';
1198 if ($modecompta == 'CREANCES-DETTES') {
1199 print '<span class="amount">'.price(-$debit_amount).'</span>';
1200 }
1201 print '</td>';
1202 print '<td class="right"><span class="amount">'.price(-$debit_amount)."</span></td>\n";
1203 print "</tr>\n";
1204
1205 // Credit (payment received from customer for example)
1206 $obj = $db->fetch_object($result);
1207 if (isset($obj->amount)) {
1208 $subtotal_ht += $obj->amount;
1209 $subtotal_ttc += $obj->amount;
1210
1211 $total_ht_income += $obj->amount;
1212 $total_ttc_income += $obj->amount;
1213 }
1214 $credit_amount = isset($obj->amount) ? $obj->amount : 0;
1215 print '<tr class="oddeven"><td>&nbsp;</td>';
1216 print "<td>".$langs->trans("AccountingCredit")."</td>\n";
1217 print '<td class="right">';
1218 if ($modecompta == 'CREANCES-DETTES') {
1219 print '<span class="amount">'.price($credit_amount).'</span>';
1220 }
1221 print '</td>';
1222 print '<td class="right"><span class="amount">'.price($credit_amount)."</span></td>\n";
1223 print "</tr>\n";
1224
1225 // Total
1226 $total_ht += $subtotal_ht;
1227 $total_ttc += $subtotal_ttc;
1228 print '<tr class="liste_total">';
1229 print '<td></td>';
1230 print '<td></td>';
1231 print '<td class="right">';
1232 if ($modecompta == 'CREANCES-DETTES') {
1233 print price($subtotal_ht);
1234 }
1235 print '</td>';
1236 print '<td class="right">'.price($subtotal_ttc).'</td>';
1237 print '</tr>';
1238 } else {
1240 }
1241 }
1242
1243 /*
1244 * Payment Loan
1245 */
1246
1247 if (getDolGlobalString('ACCOUNTING_REPORTS_INCLUDE_LOAN') && isModEnabled('don') && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES")) {
1248 $subtotal_ht = 0;
1249 $subtotal_ttc = 0;
1250
1251 print '<tr class="trforbreak"><td colspan="4">'.$langs->trans("PaymentLoan").'</td></tr>';
1252
1253 $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';
1254 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'loan AS l ON l.rowid = p.fk_loan';
1255 $sql .= ' WHERE 1 = 1';
1256 if (!empty($date_start) && !empty($date_end)) {
1257 $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
1258 }
1259 $sql .= ' GROUP BY p.fk_loan';
1260 $sql .= ' ORDER BY p.fk_loan';
1261
1262 dol_syslog('get loan payments', LOG_DEBUG);
1263 $result = $db->query($sql);
1264 if ($result) {
1265 require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php';
1266 $loan_static = new Loan($db);
1267 while ($obj = $db->fetch_object($result)) {
1268 $loan_static->id = $obj->id;
1269 $loan_static->ref = $obj->id;
1270 $loan_static->label = $obj->label;
1271 print '<tr class="oddeven"><td>&nbsp;</td>';
1272 print "<td>".$loan_static->getNomUrl(1).' - '.$obj->label."</td>\n";
1273 if ($modecompta == 'CREANCES-DETTES') {
1274 print '<td class="right"><span class="amount">'.price(-$obj->amount).'</span></td>';
1275 }
1276 print '<td class="right"><span class="amount">'.price(-$obj->amount)."</span></td>\n";
1277 print "</tr>\n";
1278 $subtotal_ht -= $obj->amount;
1279 $subtotal_ttc -= $obj->amount;
1280 }
1281 $total_ht += $subtotal_ht;
1282 $total_ttc += $subtotal_ttc;
1283
1284 $total_ht_income += $subtotal_ht;
1285 $total_ttc_income += $subtotal_ttc;
1286
1287 print '<tr class="liste_total">';
1288 print '<td></td>';
1289 print '<td></td>';
1290 print '<td class="right">';
1291 if ($modecompta == 'CREANCES-DETTES') {
1292 print price($subtotal_ht);
1293 }
1294 print '</td>';
1295 print '<td class="right">'.price($subtotal_ttc).'</td>';
1296 print '</tr>';
1297 } else {
1299 }
1300 }
1301
1302 /*
1303 * VAT
1304 */
1305
1306 print '<tr class="trforbreak"><td colspan="4">'.$langs->trans("VAT").'</td></tr>';
1307 $subtotal_ht = 0;
1308 $subtotal_ttc = 0;
1309
1310 if (isModEnabled('tax') && ($modecompta == 'CREANCES-DETTES' || $modecompta == 'RECETTES-DEPENSES')) {
1311 if ($modecompta == 'CREANCES-DETTES') {
1312 // VAT to pay
1313 $amount = 0;
1314 $sql = "SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total_tva) as amount";
1315 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
1316 $sql .= " WHERE f.fk_statut IN (1,2)";
1317 if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) {
1318 $sql .= " AND f.type IN (0,1,2,5)";
1319 } else {
1320 $sql .= " AND f.type IN (0,1,2,3,5)";
1321 }
1322 if (!empty($date_start) && !empty($date_end)) {
1323 $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
1324 }
1325 $sql .= " AND f.entity IN (".getEntity('invoice').")";
1326 $sql .= " GROUP BY dm";
1327 $sqlNewSortField = $sortfield; // @phan-suppress-current-line SqlInjection
1328 if ($sqlNewSortField == 's.nom, s.rowid') {
1329 $sqlNewSortField = 'dm';
1330 }
1331 if ($sqlNewSortField == 'amount_ht') {
1332 $sqlNewSortField = 'amount';
1333 }
1334 if ($sqlNewSortField == 'amount_ttc') {
1335 $sqlNewSortField = 'amount';
1336 }
1337 $sql .= $db->order($sqlNewSortField, $sortorder);
1338
1339 dol_syslog("get vat to pay", LOG_DEBUG);
1340 $result = $db->query($sql);
1341 if ($result) {
1342 $num = $db->num_rows($result);
1343 $i = 0;
1344 if ($num) {
1345 while ($i < $num) {
1346 $obj = $db->fetch_object($result);
1347
1348 $amount -= $obj->amount;
1349 //$total_ht -= $obj->amount;
1350 $total_ttc -= $obj->amount;
1351 //$subtotal_ht -= $obj->amount;
1352 $subtotal_ttc -= $obj->amount;
1353 $i++;
1354 }
1355 }
1356 } else {
1358 }
1359
1360 $total_ht_outcome -= 0;
1361 $total_ttc_outcome -= $amount;
1362
1363 print '<tr class="oddeven">';
1364 print '<td>&nbsp;</td>';
1365 print "<td>".$langs->trans("VATToPay")."</td>\n";
1366 print '<td class="right">&nbsp;</td>'."\n";
1367 print '<td class="right"><span class="amount">'.price($amount)."</span></td>\n";
1368 print "</tr>\n";
1369
1370 // VAT to retrieve
1371 $amount = 0;
1372 $sql = "SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total_tva) as amount";
1373 $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
1374 $sql .= " WHERE f.fk_statut IN (1,2)";
1375 if (getDolGlobalString('FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS')) {
1376 $sql .= " AND f.type IN (0,1,2)";
1377 } else {
1378 $sql .= " AND f.type IN (0,1,2,3)";
1379 }
1380 if (!empty($date_start) && !empty($date_end)) {
1381 $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
1382 }
1383 $sql .= " AND f.entity = ".((int) $conf->entity);
1384 $sql .= " GROUP BY dm";
1385 $sqlNewSortField = $sortfield; // @phan-suppress-current-line SqlInjection
1386 if ($sqlNewSortField == 's.nom, s.rowid') {
1387 $sqlNewSortField = 'dm';
1388 }
1389 if ($sqlNewSortField == 'amount_ht') {
1390 $sqlNewSortField = 'amount';
1391 }
1392 if ($sqlNewSortField == 'amount_ttc') {
1393 $sqlNewSortField = 'amount';
1394 }
1395 $sql .= $db->order($sqlNewSortField, $sortorder);
1396
1397 dol_syslog("get vat received back", LOG_DEBUG);
1398 $result = $db->query($sql);
1399 if ($result) {
1400 $num = $db->num_rows($result);
1401 $i = 0;
1402 if ($num) {
1403 while ($i < $num) {
1404 $obj = $db->fetch_object($result);
1405
1406 $amount += $obj->amount;
1407 //$total_ht += $obj->amount;
1408 $total_ttc += $obj->amount;
1409 //$subtotal_ht += $obj->amount;
1410 $subtotal_ttc += $obj->amount;
1411
1412 $i++;
1413 }
1414 }
1415 } else {
1417 }
1418
1419 $total_ht_income += 0;
1420 $total_ttc_income += $amount;
1421
1422 print '<tr class="oddeven">';
1423 print '<td>&nbsp;</td>';
1424 print '<td>'.$langs->trans("VATToCollect")."</td>\n";
1425 print '<td class="right">&nbsp;</td>'."\n";
1426 print '<td class="right"><span class="amount">'.price($amount)."</span></td>\n";
1427 print "</tr>\n";
1428 } else {
1429 // VAT really already paid
1430 $amount = 0;
1431 $sql = "SELECT date_format(t.datev,'%Y-%m') as dm, sum(t.amount) as amount";
1432 $sql .= " FROM ".MAIN_DB_PREFIX."tva as t";
1433 $sql .= " WHERE amount > 0";
1434 if (!empty($date_start) && !empty($date_end)) {
1435 $sql .= " AND t.datev >= '".$db->idate($date_start)."' AND t.datev <= '".$db->idate($date_end)."'";
1436 }
1437 $sql .= " AND t.entity = ".((int) $conf->entity);
1438 $sql .= " GROUP BY dm";
1439 $sqlNewSortField = $sortfield; // @phan-suppress-current-line SqlInjection
1440 if ($sqlNewSortField == 's.nom, s.rowid') {
1441 $sqlNewSortField = 'dm';
1442 }
1443 if ($sqlNewSortField == 'amount_ht') {
1444 $sqlNewSortField = 'amount';
1445 }
1446 if ($sqlNewSortField == 'amount_ttc') {
1447 $sqlNewSortField = 'amount';
1448 }
1449 $sql .= $db->order($sqlNewSortField, $sortorder);
1450
1451 dol_syslog("get vat really paid", LOG_DEBUG);
1452 $result = $db->query($sql);
1453 if ($result) {
1454 $num = $db->num_rows($result);
1455 $i = 0;
1456 if ($num) {
1457 while ($i < $num) {
1458 $obj = $db->fetch_object($result);
1459
1460 $amount -= $obj->amount;
1461 $total_ht -= $obj->amount;
1462 $total_ttc -= $obj->amount;
1463 $subtotal_ht -= $obj->amount;
1464 $subtotal_ttc -= $obj->amount;
1465
1466 $i++;
1467 }
1468 }
1469 $db->free($result);
1470 } else {
1472 }
1473
1474 $total_ht_outcome -= 0;
1475 $total_ttc_outcome -= $amount;
1476
1477 print '<tr class="oddeven">';
1478 print '<td>&nbsp;</td>';
1479 print "<td>".$langs->trans("VATPaid")."</td>\n";
1480 print '<td <class="right"></td>'."\n";
1481 print '<td class="right"><span class="amount">'.price($amount)."</span></td>\n";
1482 print "</tr>\n";
1483
1484 // VAT really received
1485 $amount = 0;
1486 $sql = "SELECT date_format(t.datev,'%Y-%m') as dm, sum(t.amount) as amount";
1487 $sql .= " FROM ".MAIN_DB_PREFIX."tva as t";
1488 $sql .= " WHERE amount < 0";
1489 if (!empty($date_start) && !empty($date_end)) {
1490 $sql .= " AND t.datev >= '".$db->idate($date_start)."' AND t.datev <= '".$db->idate($date_end)."'";
1491 }
1492 $sql .= " AND t.entity = ".((int) $conf->entity);
1493 $sql .= " GROUP BY dm";
1494 $sqlNewSortField = $sortfield; // @phan-suppress-current-line SqlInjection
1495 if ($sqlNewSortField == 's.nom, s.rowid') {
1496 $sqlNewSortField = 'dm';
1497 }
1498 if ($sqlNewSortField == 'amount_ht') {
1499 $sqlNewSortField = 'amount';
1500 }
1501 if ($sqlNewSortField == 'amount_ttc') {
1502 $sqlNewSortField = 'amount';
1503 }
1504 $sql .= $db->order($sqlNewSortField, $sortorder);
1505
1506 dol_syslog("get vat really received back", LOG_DEBUG);
1507 $result = $db->query($sql);
1508 if ($result) {
1509 $num = $db->num_rows($result);
1510 $i = 0;
1511 if ($num) {
1512 while ($i < $num) {
1513 $obj = $db->fetch_object($result);
1514
1515 $amount += -$obj->amount;
1516 $total_ht += -$obj->amount;
1517 $total_ttc += -$obj->amount;
1518 $subtotal_ht += -$obj->amount;
1519 $subtotal_ttc += -$obj->amount;
1520
1521 $i++;
1522 }
1523 }
1524 $db->free($result);
1525 } else {
1527 }
1528
1529 $total_ht_income += 0;
1530 $total_ttc_income += $amount;
1531
1532 print '<tr class="oddeven">';
1533 print '<td>&nbsp;</td>';
1534 print "<td>".$langs->trans("VATCollected")."</td>\n";
1535 print '<td class="right"></td>'."\n";
1536 print '<td class="right"><span class="amount">'.price($amount)."</span></td>\n";
1537 print "</tr>\n";
1538 }
1539 }
1540
1541 if ($mysoc->tva_assuj != '0') { // Assujetti
1542 print '<tr class="liste_total">';
1543 print '<td></td>';
1544 print '<td></td>';
1545 print '<td class="right">&nbsp;</td>';
1546 print '<td class="right">'.price(price2num($subtotal_ttc, 'MT')).'</td>';
1547 print '</tr>';
1548 }
1549}
1550
1551$action = "balanceclient";
1552$object = array(&$total_ht, &$total_ttc);
1553$parameters = array();
1554$parameters["mode"] = $modecompta;
1555$parameters["date_start"] = $date_start;
1556$parameters["date_end"] = $date_end;
1557// Initialize a technical object to manage hooks of expenses. Note that conf->hooks_modules contains array array
1558$hookmanager->initHooks(array('externalbalance'));
1559$reshook = $hookmanager->executeHooks('addBalanceLine', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
1560print $hookmanager->resPrint;
1561
1562
1563
1564// Total
1565print '<tr>';
1566print '<td colspan="'.($modecompta == 'BOOKKEEPING' ? 3 : 4).'">&nbsp;</td>';
1567print '</tr>';
1568
1569print '<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans("Income").'</td>';
1570if ($modecompta == 'CREANCES-DETTES') {
1571 print '<td class="liste_total right nowraponall">'.price(price2num($total_ht_income, 'MT')).'</td>';
1572} elseif ($modecompta == 'RECETTES-DEPENSES') {
1573 print '<td></td>';
1574}
1575print '<td class="liste_total right nowraponall">'.price(price2num($total_ttc_income, 'MT')).'</td>';
1576print '</tr>';
1577print '<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans("Outcome").'</td>';
1578if ($modecompta == 'CREANCES-DETTES') {
1579 print '<td class="liste_total right nowraponall">'.price(price2num(-$total_ht_outcome, 'MT')).'</td>';
1580} elseif ($modecompta == 'RECETTES-DEPENSES') {
1581 print '<td></td>';
1582}
1583print '<td class="liste_total right nowraponall">'.price(price2num(-$total_ttc_outcome, 'MT')).'</td>';
1584print '</tr>';
1585print '<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans("Profit").'</td>';
1586if ($modecompta == 'CREANCES-DETTES') {
1587 print '<td class="liste_total right nowraponall">'.price(price2num($total_ht, 'MT')).'</td>';
1588} elseif ($modecompta == 'RECETTES-DEPENSES') {
1589 print '<td></td>';
1590}
1591print '<td class="liste_total right nowraponall">'.price(price2num($total_ttc, 'MT')).'</td>';
1592print '</tr>';
1593
1594print "</table>";
1595print '<br>';
1596
1597// End of page
1598llxFooter();
1599$db->close();
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
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:73
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.
global $mysoc
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition date.lib.php:620
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition date.lib.php:639
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
$date_start
Variables from include:
dol_now($mode='gmt')
Return date for now.
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...
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='', $useCache=true)
Return an id or code from a code or id.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
img_previous($titlealt='default', $moreatt='')
Show previous logo.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
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.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='', $textonpictotooltip='', $cssfordropdown='info_admin')
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...
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, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.