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