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