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