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