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