dolibarr  13.0.2
index.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2014-2016 Ferran Marcet <fmarcet@2byte.es>
6  * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
7  * Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
8  * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
9  * Copyright (C) 2020 Maxime DEMAREST <maxime@indelog.fr>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program. If not, see <https://www.gnu.org/licenses/>.
23  */
24 
31 require '../../main.inc.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
34 
35 // Load translation files required by the page
36 $langs->loadLangs(array('compta', 'bills', 'donation', 'salaries'));
37 
38 $date_startmonth = GETPOST('date_startmonth', 'int');
39 $date_startday = GETPOST('date_startday', 'int');
40 $date_startyear = GETPOST('date_startyear', 'int');
41 $date_endmonth = GETPOST('date_endmonth', 'int');
42 $date_endday = GETPOST('date_endday', 'int');
43 $date_endyear = GETPOST('date_endyear', 'int');
44 
45 $nbofyear = 4;
46 
47 // Date range
48 $year = GETPOST('year', 'int');
49 if (empty($year))
50 {
51  $year_current = strftime("%Y", dol_now());
52  $month_current = strftime("%m", dol_now());
53  $year_start = $year_current - ($nbofyear - 1);
54 } else {
55  $year_current = $year;
56  $month_current = strftime("%m", dol_now());
57  $year_start = $year - ($nbofyear - 1);
58 }
59 $date_start = dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
60 $date_end = dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
61 
62 // We define date_start and date_end
63 if (empty($date_start) || empty($date_end)) // We define date_start and date_end
64 {
65  $q = GETPOST("q") ?GETPOST("q") : 0;
66  if ($q == 0)
67  {
68  // We define date_start and date_end
69  $year_end = $year_start + ($nbofyear - 1);
70  $month_start = GETPOST("month") ?GETPOST("month") : ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1);
71  if (!GETPOST('month'))
72  {
73  if (!GETPOST("year") && $month_start > $month_current)
74  {
75  $year_start--;
76  $year_end--;
77  }
78  $month_end = $month_start - 1;
79  if ($month_end < 1) $month_end = 12;
80  else $year_end++;
81  } else $month_end = $month_start;
82  $date_start = dol_get_first_day($year_start, $month_start, false); $date_end = dol_get_last_day($year_end, $month_end, false);
83  }
84  if ($q == 1) { $date_start = dol_get_first_day($year_start, 1, false); $date_end = dol_get_last_day($year_start, 3, false); }
85  if ($q == 2) { $date_start = dol_get_first_day($year_start, 4, false); $date_end = dol_get_last_day($year_start, 6, false); }
86  if ($q == 3) { $date_start = dol_get_first_day($year_start, 7, false); $date_end = dol_get_last_day($year_start, 9, false); }
87  if ($q == 4) { $date_start = dol_get_first_day($year_start, 10, false); $date_end = dol_get_last_day($year_start, 12, false); }
88 }
89 
90 // $date_start and $date_end are defined. We force $year_start and $nbofyear
91 $tmps = dol_getdate($date_start);
92 $year_start = $tmps['year'];
93 $tmpe = dol_getdate($date_end);
94 $year_end = $tmpe['year'];
95 $nbofyear = ($year_end - $year_start) + 1;
96 //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'));
97 
98 
99 // Security check
100 $socid = GETPOST('socid', 'int');
101 if ($user->socid > 0) $socid = $user->socid;
102 if (!empty($conf->comptabilite->enabled)) $result = restrictedArea($user, 'compta', '', '', 'resultat');
103 if (!empty($conf->accounting->enabled)) $result = restrictedArea($user, 'accounting', '', '', 'comptarapport');
104 
105 // Define modecompta ('CREANCES-DETTES' or 'RECETTES-DEPENSES' or 'BOOKKEEPING')
106 $modecompta = $conf->global->ACCOUNTING_MODE;
107 if (!empty($conf->accounting->enabled)) $modecompta = 'BOOKKEEPING';
108 if (GETPOST("modecompta", 'alpha')) $modecompta = GETPOST("modecompta", 'alpha');
109 
110 
111 /*
112  * View
113  */
114 
115 llxHeader();
116 
117 $form = new Form($db);
118 
119 $exportlink = '';
120 
121 // Affiche en-tete du rapport
122 if ($modecompta == 'CREANCES-DETTES')
123 {
124  $name = $langs->trans("ReportInOut").', '.$langs->trans("ByYear");
125  $calcmode = $langs->trans("CalcModeDebt");
126  $calcmode .= '<br>('.$langs->trans("SeeReportInInputOutputMode", '{s1}', '{s2}').')';
127  $calcmode = str_replace(array('{s1}', '{s2}'), array('<a href="'.$_SERVER["PHP_SELF"].'?year_start='.$year_start.'&modecompta=RECETTES-DEPENSES">', '</a>'), $calcmode);
128  if (!empty($conf->accounting->enabled)) {
129  $calcmode .= '<br>('.$langs->trans("SeeReportInBookkeepingMode", '{s1}', '{s2}').')';
130  $calcmode = str_replace(array('{s1}', '{s2}'), array('<a href="'.$_SERVER["PHP_SELF"].'?year_start='.$year_start.'&modecompta=BOOKKEEPING">', '</a>'), $calcmode);
131  }
132  $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
133  $periodlink = ($year_start ? "<a href='".$_SERVER["PHP_SELF"]."?year=".($year_start + $nbofyear - 2)."&modecompta=".$modecompta."'>".img_previous()."</a> <a href='".$_SERVER["PHP_SELF"]."?year=".($year_start + $nbofyear)."&modecompta=".$modecompta."'>".img_next()."</a>" : "");
134  $description = $langs->trans("RulesAmountWithTaxIncluded");
135  $description .= '<br>'.$langs->trans("RulesResultDue");
136  if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $description .= "<br>".$langs->trans("DepositsAreNotIncluded");
137  else $description .= "<br>".$langs->trans("DepositsAreIncluded");
138  $builddate = dol_now();
139  //$exportlink=$langs->trans("NotYetAvailable");
140 } elseif ($modecompta == "RECETTES-DEPENSES") {
141  $name = $langs->trans("ReportInOut").', '.$langs->trans("ByYear");
142  $calcmode = $langs->trans("CalcModeEngagement");
143  $calcmode .= '<br>('.$langs->trans("SeeReportInDueDebtMode", '{s1}', '{s2}').')';
144  $calcmode = str_replace(array('{s1}', '{s2}'), array('<a href="'.$_SERVER["PHP_SELF"].'?year_start='.$year_start.'&modecompta=CREANCES-DETTES">', '</a>'), $calcmode);
145  if (!empty($conf->accounting->enabled)) {
146  $calcmode .= '<br>('.$langs->trans("SeeReportInBookkeepingMode", '{s1}', '{s2}').')';
147  $calcmode = str_replace(array('{s1}', '{s2}'), array('<a href="'.$_SERVER["PHP_SELF"].'?year_start='.$year_start.'&modecompta=BOOKKEEPING">', '</a>'), $calcmode);
148  }
149  $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
150  $periodlink = ($year_start ? "<a href='".$_SERVER["PHP_SELF"]."?year=".($year_start + $nbofyear - 2)."&modecompta=".$modecompta."'>".img_previous()."</a> <a href='".$_SERVER["PHP_SELF"]."?year=".($year_start + $nbofyear)."&modecompta=".$modecompta."'>".img_next()."</a>" : "");
151  $description = $langs->trans("RulesAmountWithTaxIncluded");
152  $description .= '<br>'.$langs->trans("RulesResultInOut");
153  $builddate = dol_now();
154  //$exportlink=$langs->trans("NotYetAvailable");
155 } elseif ($modecompta == "BOOKKEEPING")
156 {
157  $name = $langs->trans("ReportInOut").', '.$langs->trans("ByYear");
158  $calcmode = $langs->trans("CalcModeBookkeeping");
159  $calcmode .= '<br>('.$langs->trans("SeeReportInInputOutputMode", '{s1}', '{s2}').')';
160  $calcmode = str_replace(array('{s1}', '{s2}'), array('<a href="'.$_SERVER["PHP_SELF"].'?year_start='.$year_start.'&modecompta=RECETTES-DEPENSES">', '</a>'), $calcmode);
161  $calcmode .= '<br>('.$langs->trans("SeeReportInDueDebtMode", '{s1}', '{s2}').')';
162  $calcmode = str_replace(array('{s1}', '{s2}'), array('<a href="'.$_SERVER["PHP_SELF"].'?year_start='.$year_start.'&modecompta=CREANCES-DETTES">', '</a>'), $calcmode);
163  $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
164  $periodlink = ($year_start ? "<a href='".$_SERVER["PHP_SELF"]."?year=".($year_start + $nbofyear - 2)."&modecompta=".$modecompta."'>".img_previous()."</a> <a href='".$_SERVER["PHP_SELF"]."?year=".($year_start + $nbofyear)."&modecompta=".$modecompta."'>".img_next()."</a>" : "");
165  $description = $langs->trans("RulesAmountOnInOutBookkeepingRecord");
166  $description .= ' ('.$langs->trans("SeePageForSetup", DOL_URL_ROOT.'/accountancy/admin/account.php?mainmenu=accountancy&leftmenu=accountancy_admin', $langs->transnoentitiesnoconv("Accountancy").' / '.$langs->transnoentitiesnoconv("Setup").' / '.$langs->trans("Chartofaccounts")).')';
167  $builddate = dol_now();
168  //$exportlink=$langs->trans("NotYetAvailable");
169 }
170 
171 $hselected = 'report';
172 
173 report_header($name, '', $period, $periodlink, $description, $builddate, $exportlink, array('modecompta'=>$modecompta), $calcmode);
174 
175 if (!empty($conf->accounting->enabled) && $modecompta != 'BOOKKEEPING')
176 {
177  print info_admin($langs->trans("WarningReportNotReliable"), 0, 0, 1);
178 }
179 
180 
181 
182 /*
183  * Factures clients
184  */
185 
186 $subtotal_ht = 0;
187 $subtotal_ttc = 0;
188 if (!empty($conf->facture->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES"))
189 {
190  if ($modecompta == 'CREANCES-DETTES')
191  {
192  $sql = "SELECT sum(f.total) as amount_ht, sum(f.total_ttc) as amount_ttc, date_format(f.datef,'%Y-%m') as dm";
193  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
194  $sql .= ", ".MAIN_DB_PREFIX."facture as f";
195  $sql .= " WHERE f.fk_soc = s.rowid";
196  $sql .= " AND f.fk_statut IN (1,2)";
197  if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql .= " AND f.type IN (0,1,2,5)";
198  else $sql .= " AND f.type IN (0,1,2,3,5)";
199  if (!empty($date_start) && !empty($date_end))
200  $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
201  } elseif ($modecompta == "RECETTES-DEPENSES")
202  {
203  /*
204  * Liste des paiements (les anciens paiements ne sont pas vus par cette requete car, sur les
205  * vieilles versions, ils n'etaient pas lies via paiement_facture. On les ajoute plus loin)
206  */
207  $sql = "SELECT sum(pf.amount) as amount_ttc, date_format(p.datep,'%Y-%m') as dm";
208  $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
209  $sql .= ", ".MAIN_DB_PREFIX."paiement_facture as pf";
210  $sql .= ", ".MAIN_DB_PREFIX."paiement as p";
211  $sql .= " WHERE p.rowid = pf.fk_paiement";
212  $sql .= " AND pf.fk_facture = f.rowid";
213  if (!empty($date_start) && !empty($date_end))
214  $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
215  }
216 
217  $sql .= " AND f.entity IN (".getEntity('invoice').")";
218  if ($socid) $sql .= " AND f.fk_soc = $socid";
219  $sql .= " GROUP BY dm";
220  $sql .= " ORDER BY dm";
221 
222  //print $sql;
223  dol_syslog("get customers invoices", LOG_DEBUG);
224  $result = $db->query($sql);
225  if ($result)
226  {
227  $num = $db->num_rows($result);
228  $i = 0;
229  while ($i < $num)
230  {
231  $row = $db->fetch_object($result);
232  $encaiss[$row->dm] = (isset($row->amount_ht) ? $row->amount_ht : 0);
233  $encaiss_ttc[$row->dm] = $row->amount_ttc;
234  $i++;
235  }
236  $db->free($result);
237  } else {
238  dol_print_error($db);
239  }
240 } elseif ($modecompta == "BOOKKEEPING")
241 {
242  // Nothing from this table
243 }
244 
245 if (!empty($conf->facture->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES"))
246 {
247  // On ajoute les paiements clients anciennes version, non lies par paiement_facture
248  if ($modecompta != 'CREANCES-DETTES')
249  {
250  $sql = "SELECT sum(p.amount) as amount_ttc, date_format(p.datep,'%Y-%m') as dm";
251  $sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
252  $sql .= ", ".MAIN_DB_PREFIX."bank_account as ba";
253  $sql .= ", ".MAIN_DB_PREFIX."paiement as p";
254  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement";
255  $sql .= " WHERE pf.rowid IS NULL";
256  $sql .= " AND p.fk_bank = b.rowid";
257  $sql .= " AND b.fk_account = ba.rowid";
258  $sql .= " AND ba.entity IN (".getEntity('bank_account').")";
259  if (!empty($date_start) && !empty($date_end))
260  $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
261  $sql .= " GROUP BY dm";
262  $sql .= " ORDER BY dm";
263 
264  dol_syslog("get old customers payments not linked to invoices", LOG_DEBUG);
265  $result = $db->query($sql);
266  if ($result) {
267  $num = $db->num_rows($result);
268  $i = 0;
269  while ($i < $num)
270  {
271  $row = $db->fetch_object($result);
272 
273  if (!isset($encaiss[$row->dm])) $encaiss[$row->dm] = 0;
274  $encaiss[$row->dm] += (isset($row->amount_ht) ? $row->amount_ht : 0);
275 
276  if (!isset($encaiss_ttc[$row->dm])) $encaiss_ttc[$row->dm] = 0;
277  $encaiss_ttc[$row->dm] += $row->amount_ttc;
278 
279  $i++;
280  }
281  } else {
282  dol_print_error($db);
283  }
284  } elseif ($modecompta == "RECETTES-DEPENSES")
285  {
286  // Nothing from this table
287  }
288 } elseif ($modecompta == "BOOKKEEPING")
289 {
290  // Nothing from this table
291 }
292 
293 
294 /*
295  * Frais, factures fournisseurs.
296  */
297 $subtotal_ht = 0;
298 $subtotal_ttc = 0;
299 
300 if (!empty($conf->facture->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES"))
301 {
302  if ($modecompta == 'CREANCES-DETTES')
303  {
304  $sql = "SELECT sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc, date_format(f.datef,'%Y-%m') as dm";
305  $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
306  $sql .= " WHERE f.fk_statut IN (1,2)";
307  if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql .= " AND f.type IN (0,1,2)";
308  else $sql .= " AND f.type IN (0,1,2,3)";
309  if (!empty($date_start) && !empty($date_end))
310  $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
311  } elseif ($modecompta == "RECETTES-DEPENSES")
312  {
313  $sql = "SELECT sum(pf.amount) as amount_ttc, date_format(p.datep,'%Y-%m') as dm";
314  $sql .= " FROM ".MAIN_DB_PREFIX."paiementfourn as p";
315  $sql .= ", ".MAIN_DB_PREFIX."facture_fourn as f";
316  $sql .= ", ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf";
317  $sql .= " WHERE f.rowid = pf.fk_facturefourn";
318  $sql .= " AND p.rowid = pf.fk_paiementfourn";
319  if (!empty($date_start) && !empty($date_end))
320  $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
321  }
322 
323  $sql .= " AND f.entity = ".$conf->entity;
324  if ($socid) $sql .= " AND f.fk_soc = ".$socid;
325  $sql .= " GROUP BY dm";
326 
327  dol_syslog("get suppliers invoices", LOG_DEBUG);
328  $result = $db->query($sql);
329  if ($result)
330  {
331  $num = $db->num_rows($result);
332  $i = 0;
333  while ($i < $num)
334  {
335  $row = $db->fetch_object($result);
336 
337  if (!isset($decaiss[$row->dm])) $decaiss[$row->dm] = 0;
338  $decaiss[$row->dm] = (isset($row->amount_ht) ? $row->amount_ht : 0);
339 
340  if (!isset($decaiss_ttc[$row->dm])) $decaiss_ttc[$row->dm] = 0;
341  $decaiss_ttc[$row->dm] = $row->amount_ttc;
342 
343  $i++;
344  }
345  $db->free($result);
346  } else {
347  dol_print_error($db);
348  }
349 } elseif ($modecompta == "BOOKKEEPING")
350 {
351  // Nothing from this table
352 }
353 
354 
355 
356 /*
357  * TVA
358  */
359 
360 $subtotal_ht = 0;
361 $subtotal_ttc = 0;
362 if (!empty($conf->tax->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES"))
363 {
364  if ($modecompta == 'CREANCES-DETTES')
365  {
366  // TVA collected to pay
367  $sql = "SELECT sum(f.tva) as amount, date_format(f.datef,'%Y-%m') as dm";
368  $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
369  $sql .= " WHERE f.fk_statut IN (1,2)";
370  if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql .= " AND f.type IN (0,1,2,5)";
371  else $sql .= " AND f.type IN (0,1,2,3,5)";
372  $sql .= " AND f.entity IN (".getEntity('invoice').")";
373  if (!empty($date_start) && !empty($date_end))
374  $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
375  $sql .= " GROUP BY dm";
376 
377  dol_syslog("get vat to pay", LOG_DEBUG);
378  $result = $db->query($sql);
379  if ($result) {
380  $num = $db->num_rows($result);
381  $i = 0;
382  if ($num) {
383  while ($i < $num) {
384  $obj = $db->fetch_object($result);
385 
386  if (!isset($decaiss[$obj->dm])) $decaiss[$obj->dm] = 0;
387  $decaiss[$obj->dm] += $obj->amount;
388 
389  if (!isset($decaiss_ttc[$obj->dm])) $decaiss_ttc[$obj->dm] = 0;
390  $decaiss_ttc[$obj->dm] += $obj->amount;
391 
392  $i++;
393  }
394  }
395  } else {
396  dol_print_error($db);
397  }
398  // TVA paid to get
399  $sql = "SELECT sum(f.total_tva) as amount, date_format(f.datef,'%Y-%m') as dm";
400  $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
401  $sql .= " WHERE f.fk_statut IN (1,2)";
402  if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql .= " AND f.type IN (0,1,2)";
403  else $sql .= " AND f.type IN (0,1,2,3)";
404  $sql .= " AND f.entity = ".$conf->entity;
405  if (!empty($date_start) && !empty($date_end))
406  $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
407  $sql .= " GROUP BY dm";
408 
409  dol_syslog("get vat to receive back", LOG_DEBUG);
410  $result = $db->query($sql);
411  if ($result) {
412  $num = $db->num_rows($result);
413  $i = 0;
414  if ($num) {
415  while ($i < $num) {
416  $obj = $db->fetch_object($result);
417 
418  if (!isset($encaiss[$obj->dm])) $encaiss[$obj->dm] = 0;
419  $encaiss[$obj->dm] += $obj->amount;
420 
421  if (!isset($encaiss_ttc[$obj->dm])) $encaiss_ttc[$obj->dm] = 0;
422  $encaiss_ttc[$obj->dm] += $obj->amount;
423 
424  $i++;
425  }
426  }
427  } else {
428  dol_print_error($db);
429  }
430  } elseif ($modecompta == "RECETTES-DEPENSES")
431  {
432  // TVA really already paid
433  $sql = "SELECT sum(t.amount) as amount, date_format(t.datev,'%Y-%m') as dm";
434  $sql .= " FROM ".MAIN_DB_PREFIX."tva as t";
435  $sql .= " WHERE amount > 0";
436  $sql .= " AND t.entity = ".$conf->entity;
437  if (!empty($date_start) && !empty($date_end))
438  $sql .= " AND t.datev >= '".$db->idate($date_start)."' AND t.datev <= '".$db->idate($date_end)."'";
439  $sql .= " GROUP BY dm";
440 
441  dol_syslog("get vat really paid", LOG_DEBUG);
442  $result = $db->query($sql);
443  if ($result) {
444  $num = $db->num_rows($result);
445  $i = 0;
446  if ($num) {
447  while ($i < $num) {
448  $obj = $db->fetch_object($result);
449 
450  if (!isset($decaiss[$obj->dm])) $decaiss[$obj->dm] = 0;
451  $decaiss[$obj->dm] += $obj->amount;
452 
453  if (!isset($decaiss_ttc[$obj->dm])) $decaiss_ttc[$obj->dm] = 0;
454  $decaiss_ttc[$obj->dm] += $obj->amount;
455 
456  $i++;
457  }
458  }
459  } else {
460  dol_print_error($db);
461  }
462  // TVA retrieved
463  $sql = "SELECT sum(t.amount) as amount, date_format(t.datev,'%Y-%m') as dm";
464  $sql .= " FROM ".MAIN_DB_PREFIX."tva as t";
465  $sql .= " WHERE amount < 0";
466  $sql .= " AND t.entity = ".$conf->entity;
467  if (!empty($date_start) && !empty($date_end))
468  $sql .= " AND t.datev >= '".$db->idate($date_start)."' AND t.datev <= '".$db->idate($date_end)."'";
469  $sql .= " GROUP BY dm";
470 
471  dol_syslog("get vat really received back", LOG_DEBUG);
472  $result = $db->query($sql);
473  if ($result) {
474  $num = $db->num_rows($result);
475  $i = 0;
476  if ($num) {
477  while ($i < $num) {
478  $obj = $db->fetch_object($result);
479 
480  if (!isset($encaiss[$obj->dm])) $encaiss[$obj->dm] = 0;
481  $encaiss[$obj->dm] += -$obj->amount;
482 
483  if (!isset($encaiss_ttc[$obj->dm])) $encaiss_ttc[$obj->dm] = 0;
484  $encaiss_ttc[$obj->dm] += -$obj->amount;
485 
486  $i++;
487  }
488  }
489  } else {
490  dol_print_error($db);
491  }
492  }
493 } elseif ($modecompta == "BOOKKEEPING")
494 {
495  // Nothing from this table
496 }
497 
498 /*
499  * Social contributions
500  */
501 
502 $subtotal_ht = 0;
503 $subtotal_ttc = 0;
504 if (!empty($conf->tax->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES"))
505 {
506  if ($modecompta == 'CREANCES-DETTES')
507  {
508  $sql = "SELECT c.libelle as nom, date_format(cs.date_ech,'%Y-%m') as dm, sum(cs.amount) as amount";
509  $sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c";
510  $sql .= ", ".MAIN_DB_PREFIX."chargesociales as cs";
511  $sql .= " WHERE cs.fk_type = c.id";
512  if (!empty($date_start) && !empty($date_end))
513  $sql .= " AND cs.date_ech >= '".$db->idate($date_start)."' AND cs.date_ech <= '".$db->idate($date_end)."'";
514  } elseif ($modecompta == "RECETTES-DEPENSES")
515  {
516  $sql = "SELECT c.libelle as nom, date_format(p.datep,'%Y-%m') as dm, sum(p.amount) as amount";
517  $sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c";
518  $sql .= ", ".MAIN_DB_PREFIX."chargesociales as cs";
519  $sql .= ", ".MAIN_DB_PREFIX."paiementcharge as p";
520  $sql .= " WHERE p.fk_charge = cs.rowid";
521  $sql .= " AND cs.fk_type = c.id";
522  if (!empty($date_start) && !empty($date_end))
523  $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
524  }
525 
526  $sql .= " AND cs.entity = ".$conf->entity;
527  $sql .= " GROUP BY c.libelle, dm";
528 
529  dol_syslog("get social contributions", LOG_DEBUG);
530  $result = $db->query($sql);
531  if ($result) {
532  $num = $db->num_rows($result);
533  $i = 0;
534  if ($num) {
535  while ($i < $num) {
536  $obj = $db->fetch_object($result);
537 
538  if (!isset($decaiss[$obj->dm])) $decaiss[$obj->dm] = 0;
539  $decaiss[$obj->dm] += $obj->amount;
540 
541  if (!isset($decaiss_ttc[$obj->dm])) $decaiss_ttc[$obj->dm] = 0;
542  $decaiss_ttc[$obj->dm] += $obj->amount;
543 
544  $i++;
545  }
546  }
547  } else {
548  dol_print_error($db);
549  }
550 } elseif ($modecompta == "BOOKKEEPING")
551 {
552  // Nothing from this table
553 }
554 
555 
556 /*
557  * Salaries
558  */
559 
560 if (!empty($conf->salaries->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES"))
561 {
562  if ($modecompta == 'CREANCES-DETTES') $column = 'p.datev';
563  if ($modecompta == "RECETTES-DEPENSES") $column = 'p.datep';
564 
565  $subtotal_ht = 0;
566  $subtotal_ttc = 0;
567  $sql = "SELECT p.label as nom, date_format(".$column.",'%Y-%m') as dm, sum(p.amount) as amount";
568  $sql .= " FROM ".MAIN_DB_PREFIX."payment_salary as p";
569  $sql .= " WHERE p.entity IN (".getEntity('payment_salary').")";
570  if (!empty($date_start) && !empty($date_end))
571  $sql .= " AND ".$column." >= '".$db->idate($date_start)."' AND ".$column." <= '".$db->idate($date_end)."'";
572  $sql .= " GROUP BY p.label, dm";
573 
574  dol_syslog("get social salaries payments");
575  $result = $db->query($sql);
576  if ($result) {
577  $num = $db->num_rows($result);
578  $i = 0;
579  if ($num) {
580  while ($i < $num) {
581  $obj = $db->fetch_object($result);
582 
583  if (!isset($decaiss[$obj->dm]))
584  $decaiss[$obj->dm] = 0;
585  $decaiss[$obj->dm] += $obj->amount;
586 
587  if (!isset($decaiss_ttc[$obj->dm]))
588  $decaiss_ttc[$obj->dm] = 0;
589  $decaiss_ttc[$obj->dm] += $obj->amount;
590 
591  $i++;
592  }
593  }
594  } else {
595  dol_print_error($db);
596  }
597 } elseif ($modecompta == "BOOKKEEPING")
598 {
599  // Nothing from this table
600 }
601 
602 
603 /*
604  * Expense reports
605  */
606 
607 if (!empty($conf->expensereport->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES"))
608 {
609  $langs->load('trips');
610 
611  if ($modecompta == 'CREANCES-DETTES') {
612  $sql = "SELECT date_format(date_valid,'%Y-%m') as dm, sum(p.total_ht) as amount_ht,sum(p.total_ttc) as amount_ttc";
613  $sql .= " FROM ".MAIN_DB_PREFIX."expensereport as p";
614  $sql .= " INNER JOIN ".MAIN_DB_PREFIX."user as u ON u.rowid=p.fk_user_author";
615  $sql .= " WHERE p.entity IN (".getEntity('expensereport').")";
616  $sql .= " AND p.fk_statut>=5";
617 
618  $column = 'p.date_valid';
619  if (!empty($date_start) && !empty($date_end))
620  $sql .= " AND ".$column." >= '".$db->idate($date_start)."' AND ".$column." <= '".$db->idate($date_end)."'";
621  } elseif ($modecompta == 'RECETTES-DEPENSES') {
622  $sql = "SELECT date_format(pe.datep,'%Y-%m') as dm, sum(p.total_ht) as amount_ht,sum(p.total_ttc) as amount_ttc";
623  $sql .= " FROM ".MAIN_DB_PREFIX."expensereport as p";
624  $sql .= " INNER JOIN ".MAIN_DB_PREFIX."user as u ON u.rowid=p.fk_user_author";
625  $sql .= " INNER JOIN ".MAIN_DB_PREFIX."payment_expensereport as pe ON pe.fk_expensereport = p.rowid";
626  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON pe.fk_typepayment = c.id";
627  $sql .= " WHERE p.entity IN (".getEntity('expensereport').")";
628  $sql .= " AND p.fk_statut>=5";
629 
630  $column = 'pe.datep';
631  if (!empty($date_start) && !empty($date_end))
632  $sql .= " AND ".$column." >= '".$db->idate($date_start)."' AND ".$column." <= '".$db->idate($date_end)."'";
633  }
634 
635  $sql .= " GROUP BY dm";
636 
637  dol_syslog("get expense report outcome");
638  $result = $db->query($sql);
639  $subtotal_ht = 0;
640  $subtotal_ttc = 0;
641  if ($result)
642  {
643  $num = $db->num_rows($result);
644  if ($num)
645  {
646  while ($obj = $db->fetch_object($result))
647  {
648  if (!isset($decaiss[$obj->dm])) $decaiss[$obj->dm] = 0;
649  $decaiss[$obj->dm] += $obj->amount_ht;
650 
651  if (!isset($decaiss_ttc[$obj->dm])) $decaiss_ttc[$obj->dm] = 0;
652  $decaiss_ttc[$obj->dm] += $obj->amount_ttc;
653  }
654  }
655  } else {
656  dol_print_error($db);
657  }
658 } elseif ($modecompta == 'BOOKKEEPING') {
659  // Nothing from this table
660 }
661 
662 
663 /*
664  * Donation get dunning payments
665  */
666 
667 if (!empty($conf->don->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES"))
668 {
669  $subtotal_ht = 0;
670  $subtotal_ttc = 0;
671 
672  if ($modecompta == 'CREANCES-DETTES') {
673  $sql = "SELECT p.societe as nom, p.firstname, p.lastname, date_format(p.datedon,'%Y-%m') as dm, sum(p.amount) as amount";
674  $sql .= " FROM ".MAIN_DB_PREFIX."don as p";
675  $sql .= " WHERE p.entity IN (".getEntity('donation').")";
676  $sql .= " AND fk_statut in (1,2)";
677  if (!empty($date_start) && !empty($date_end))
678  $sql .= " AND p.datedon >= '".$db->idate($date_start)."' AND p.datedon <= '".$db->idate($date_end)."'";
679  } elseif ($modecompta == 'RECETTES-DEPENSES') {
680  $sql = "SELECT p.societe as nom, p.firstname, p.lastname, date_format(pe.datep,'%Y-%m') as dm, sum(p.amount) as amount";
681  $sql .= " FROM ".MAIN_DB_PREFIX."don as p";
682  $sql .= " INNER JOIN ".MAIN_DB_PREFIX."payment_donation as pe ON pe.fk_donation = p.rowid";
683  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON pe.fk_typepayment = c.id";
684  $sql .= " WHERE p.entity IN (".getEntity('donation').")";
685  $sql .= " AND fk_statut >= 2";
686  if (!empty($date_start) && !empty($date_end)) {
687  $sql .= " AND pe.datep >= '".$db->idate($date_start)."' AND pe.datep <= '".$db->idate($date_end)."'";
688  }
689  }
690 
691  $sql .= " GROUP BY p.societe, p.firstname, p.lastname, dm";
692 
693  dol_syslog("get donation payments");
694  $result = $db->query($sql);
695  if ($result)
696  {
697  $num = $db->num_rows($result);
698  $i = 0;
699  if ($num)
700  {
701  while ($i < $num)
702  {
703  $obj = $db->fetch_object($result);
704 
705  if (!isset($encaiss[$obj->dm])) $encaiss[$obj->dm] = 0;
706  $encaiss[$obj->dm] += $obj->amount;
707 
708  if (!isset($encaiss_ttc[$obj->dm])) $encaiss_ttc[$obj->dm] = 0;
709  $encaiss_ttc[$obj->dm] += $obj->amount;
710 
711  $i++;
712  }
713  }
714  } else {
715  dol_print_error($db);
716  }
717 } elseif ($modecompta == 'BOOKKEEPING') {
718  // Nothing from this table
719 }
720 
721 /*
722  * Various Payments
723  */
724 
725 if (!empty($conf->global->ACCOUNTING_REPORTS_INCLUDE_VARPAY) && !empty($conf->banque->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES"))
726 {
727  // decaiss
728 
729  $sql = "SELECT date_format(p.datep, '%Y-%m') AS dm, SUM(p.amount) AS amount FROM ".MAIN_DB_PREFIX."payment_various as p";
730  $sql .= ' WHERE p.sens = 0';
731  if (!empty($date_start) && !empty($date_end))
732  $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
733  $sql .= ' GROUP BY dm';
734 
735  dol_syslog("get various payments");
736  $result = $db->query($sql);
737  if ($result)
738  {
739  $num = $db->num_rows($result);
740  $i = 0;
741  if ($num)
742  {
743  while ($i < $num)
744  {
745  $obj = $db->fetch_object($result);
746  if (!isset($decaiss_ttc[$obj->dm])) $decaiss_ttc[$obj->dm] = 0;
747  if (isset($obj->amount)) $decaiss_ttc[$obj->dm] += $obj->amount;
748  $i++;
749  }
750  }
751  } else {
752  dol_print_error($db);
753  }
754 
755  // encaiss
756 
757  $sql = "SELECT date_format(p.datep, '%Y-%m') AS dm, SUM(p.amount) AS amount FROM ".MAIN_DB_PREFIX."payment_various AS p";
758  $sql .= ' WHERE p.sens = 1';
759  if (!empty($date_start) && !empty($date_end))
760  $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
761  $sql .= ' GROUP BY dm';
762 
763  dol_syslog("get various payments");
764  $result = $db->query($sql);
765  if ($result)
766  {
767  $num = $db->num_rows($result);
768  $i = 0;
769  if ($num)
770  {
771  while ($i < $num)
772  {
773  $obj = $db->fetch_object($result);
774  if (!isset($encaiss_ttc[$obj->dm])) $encaiss_ttc[$obj->dm] = 0;
775  if (isset($obj->amount)) $encaiss_ttc[$obj->dm] += $obj->amount;
776  $i++;
777  }
778  }
779  } else {
780  dol_print_error($db);
781  }
782 }
783 // Useless with BOOKKEEPING
784 //elseif ($modecompta == 'BOOKKEEPING') {
785 //}
786 
787 /*
788  * Payement Loan
789  */
790 
791 if (!empty($conf->global->ACCOUNTING_REPORTS_INCLUDE_LOAN) && !empty($conf->loan->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES"))
792 {
793  $sql = "SELECT date_format(p.datep, '%Y-%m') AS dm, SUM(p.amount_capital + p.amount_insurance + p.amount_interest) AS amount FROM ".MAIN_DB_PREFIX."payment_loan AS p";
794  $sql .= ' WHERE 1 = 1';
795  if (!empty($date_start) && !empty($date_end))
796  $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
797  $sql .= ' GROUP BY dm';
798 
799  dol_syslog("get loan payments");
800  $result = $db->query($sql);
801  if ($result)
802  {
803  $num = $db->num_rows($result);
804  $i = 0;
805  if ($num)
806  {
807  while ($i < $num)
808  {
809  $obj = $db->fetch_object($result);
810  if (!isset($decaiss_ttc[$obj->dm])) $decaiss_ttc[$obj->dm] = 0;
811  if (isset($obj->amount)) $decaiss_ttc[$obj->dm] += $obj->amount;
812  $i++;
813  }
814  }
815  } else {
816  dol_print_error($db);
817  }
818 }
819 // Useless with BOOKKEEPING
820 //elseif ($modecompta == 'BOOKKEEPING') {
821 //}
822 
823 
824 /*
825  * Request in mode BOOKKEEPING
826  */
827 
828 if (!empty($conf->accounting->enabled) && ($modecompta == 'BOOKKEEPING'))
829 {
830  $predefinedgroupwhere = "(";
831  $predefinedgroupwhere .= " (aa.pcg_type = 'EXPENSE')";
832  $predefinedgroupwhere .= " OR ";
833  $predefinedgroupwhere .= " (aa.pcg_type = 'INCOME')";
834  $predefinedgroupwhere .= ")";
835 
836  $charofaccountstring = $conf->global->CHARTOFACCOUNTS;
837  $charofaccountstring = dol_getIdFromCode($db, $conf->global->CHARTOFACCOUNTS, 'accounting_system', 'rowid', 'pcg_version');
838 
839  $sql = "SELECT b.doc_ref, b.numero_compte, b.subledger_account, b.subledger_label, aa.pcg_type, date_format(b.doc_date,'%Y-%m') as dm, sum(b.debit) as debit, sum(b.credit) as credit, sum(b.montant) as amount";
840  $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as b, ".MAIN_DB_PREFIX."accounting_account as aa";
841  $sql .= " WHERE b.entity = ".$conf->entity;
842  $sql .= " AND aa.entity = ".$conf->entity;
843  $sql .= " AND b.numero_compte = aa.account_number";
844  $sql .= " AND ".$predefinedgroupwhere;
845  $sql .= " AND fk_pcg_version = '".$db->escape($charofaccountstring)."'";
846  if (!empty($date_start) && !empty($date_end))
847  $sql .= " AND b.doc_date >= '".$db->idate($date_start)."' AND b.doc_date <= '".$db->idate($date_end)."'";
848  $sql .= " GROUP BY b.doc_ref, b.numero_compte, b.subledger_account, b.subledger_label, pcg_type, dm";
849  //print $sql;
850 
851  $subtotal_ht = 0;
852  $subtotal_ttc = 0;
853 
854  dol_syslog("get bookkeeping record");
855  $result = $db->query($sql);
856  if ($result)
857  {
858  $num = $db->num_rows($result);
859  $i = 0;
860  if ($num)
861  {
862  while ($i < $num)
863  {
864  $obj = $db->fetch_object($result);
865 
866  if ($obj->pcg_type == 'INCOME') {
867  if (!isset($encaiss[$obj->dm])) $encaiss[$obj->dm] = 0; // To avoid warning of var not defined
868  $encaiss[$obj->dm] += $obj->credit;
869  $encaiss[$obj->dm] -= $obj->debit;
870  }
871  if ($obj->pcg_type == 'EXPENSE') {
872  if (!isset($decaiss[$obj->dm])) $decaiss[$obj->dm] = 0; // To avoid warning of var not defined
873  $decaiss[$obj->dm] += $obj->debit;
874  $decaiss[$obj->dm] -= $obj->credit;
875  }
876 
877  // ???
878  if (!isset($encaiss_ttc[$obj->dm])) $encaiss_ttc[$obj->dm] = 0;
879  if (!isset($decaiss_ttc[$obj->dm])) $decaiss_ttc[$obj->dm] = 0;
880  $encaiss_ttc[$obj->dm] += 0;
881  $decaiss_ttc[$obj->dm] += 0;
882 
883  $i++;
884  }
885  }
886  } else {
887  dol_print_error($db);
888  }
889 }
890 
891 
892 
893 $action = "balance";
894 $object = array(&$encaiss, &$encaiss_ttc, &$decaiss, &$decaiss_ttc);
895 $parameters["mode"] = $modecompta;
896 // Initialize technical object to manage hooks of expenses. Note that conf->hooks_modules contains array array
897 $hookmanager->initHooks(array('externalbalance'));
898 $reshook = $hookmanager->executeHooks('addReportInfo', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
899 
900 
901 
902 /*
903  * Show result array
904  */
905 
906 $totentrees = array();
907 $totsorties = array();
908 
909 print '<div class="div-table-responsive">';
910 print '<table class="tagtable liste">'."\n";
911 
912 print '<tr class="liste_titre"><td class="liste_titre">&nbsp;</td>';
913 
914 for ($annee = $year_start; $annee <= $year_end; $annee++)
915 {
916  print '<td align="center" colspan="2" class="liste_titre borderrightlight">';
917  print '<a href="clientfourn.php?year='.$annee.'">';
918  print $annee;
919  if ($conf->global->SOCIETE_FISCAL_MONTH_START > 1) print '-'.($annee + 1);
920  print '</a></td>';
921 }
922 print '</tr>';
923 print '<tr class="liste_titre"><td class="liste_titre">'.$langs->trans("Month").'</td>';
924 // Loop on each year to ouput
925 for ($annee = $year_start; $annee <= $year_end; $annee++)
926 {
927  print '<td class="liste_titre" align="center">';
928  $htmlhelp = '';
929  // if ($modecompta == 'RECETTES-DEPENSES') $htmlhelp=$langs->trans("PurchasesPlusVATEarnedAndDue");
930  print $form->textwithpicto($langs->trans("Outcome"), $htmlhelp);
931  print '</td>';
932  print '<td class="liste_titre" align="center" class="borderrightlight">';
933  $htmlhelp = '';
934  // if ($modecompta == 'RECETTES-DEPENSES') $htmlhelp=$langs->trans("SalesPlusVATToRetrieve");
935  print $form->textwithpicto($langs->trans("Income"), $htmlhelp);
936  print '</td>';
937 }
938 print '</tr>';
939 
940 
941 // Loop on each month
942 $nb_mois_decalage = $conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START - 1) : 0;
943 for ($mois = 1 + $nb_mois_decalage; $mois <= 12 + $nb_mois_decalage; $mois++)
944 {
945  $mois_modulo = $mois;
946  if ($mois > 12) {$mois_modulo = $mois - 12; }
947 
948  print '<tr class="oddeven">';
949  print "<td>".dol_print_date(dol_mktime(12, 0, 0, $mois_modulo, 1, $annee), "%B")."</td>";
950  for ($annee = $year_start; $annee <= $year_end; $annee++)
951  {
952  $annee_decalage = $annee;
953  if ($mois > 12) {$annee_decalage = $annee + 1; }
954  $case = strftime("%Y-%m", dol_mktime(12, 0, 0, $mois_modulo, 1, $annee_decalage));
955 
956  print '<td class="right">&nbsp;';
957  if ($modecompta == 'BOOKKEEPING')
958  {
959  if (isset($decaiss[$case]) && $decaiss[$case] != 0)
960  {
961  print '<a href="clientfourn.php?year='.$annee_decalage.'&month='.$mois_modulo.($modecompta ? '&modecompta='.$modecompta : '').'">'.price(price2num($decaiss[$case], 'MT')).'</a>';
962  if (!isset($totsorties[$annee])) $totsorties[$annee] = 0;
963  $totsorties[$annee] += $decaiss[$case];
964  }
965  } else {
966  if (isset($decaiss_ttc[$case]) && $decaiss_ttc[$case] != 0)
967  {
968  print '<a href="clientfourn.php?year='.$annee_decalage.'&month='.$mois_modulo.($modecompta ? '&modecompta='.$modecompta : '').'">'.price(price2num($decaiss_ttc[$case], 'MT')).'</a>';
969  if (!isset($totsorties[$annee])) $totsorties[$annee] = 0;
970  $totsorties[$annee] += $decaiss_ttc[$case];
971  }
972  }
973  print "</td>";
974 
975  print '<td class="borderrightlight nowrap right">&nbsp;';
976  if ($modecompta == 'BOOKKEEPING')
977  {
978  if (isset($encaiss[$case]))
979  {
980  print '<a href="clientfourn.php?year='.$annee_decalage.'&month='.$mois_modulo.($modecompta ? '&modecompta='.$modecompta : '').'">'.price(price2num($encaiss[$case], 'MT')).'</a>';
981  if (!isset($totentrees[$annee])) $totentrees[$annee] = 0;
982  $totentrees[$annee] += $encaiss[$case];
983  }
984  } else {
985  if (isset($encaiss_ttc[$case]))
986  {
987  print '<a href="clientfourn.php?year='.$annee_decalage.'&month='.$mois_modulo.($modecompta ? '&modecompta='.$modecompta : '').'">'.price(price2num($encaiss_ttc[$case], 'MT')).'</a>';
988  if (!isset($totentrees[$annee])) $totentrees[$annee] = 0;
989  $totentrees[$annee] += $encaiss_ttc[$case];
990  }
991  }
992  print "</td>";
993  }
994 
995  print '</tr>';
996 }
997 
998 // Total
999 
1000 $nbcols = 0;
1001 print '<tr class="liste_total impair"><td>';
1002 if ($modecompta == 'BOOKKEEPING') print $langs->trans("Total");
1003 else print $langs->trans("TotalTTC");
1004 print '</td>';
1005 for ($annee = $year_start; $annee <= $year_end; $annee++)
1006 {
1007  $nbcols += 2;
1008  print '<td class="nowrap right">'.(isset($totsorties[$annee]) ?price(price2num($totsorties[$annee], 'MT')) : '&nbsp;').'</td>';
1009  print '<td class="nowrap right" style="border-right: 1px solid #DDD">'.(isset($totentrees[$annee]) ?price(price2num($totentrees[$annee], 'MT')) : '&nbsp;').'</td>';
1010 }
1011 print "</tr>\n";
1012 
1013 // Empty line
1014 print '<tr class="impair"><td>&nbsp;</td>';
1015 print '<td colspan="'.$nbcols.'">&nbsp;</td>';
1016 print "</tr>\n";
1017 
1018 // Balance
1019 
1020 print '<tr class="liste_total"><td>'.$langs->trans("AccountingResult").'</td>';
1021 for ($annee = $year_start; $annee <= $year_end; $annee++)
1022 {
1023  print '<td colspan="2" class="borderrightlight right"> ';
1024  if (isset($totentrees[$annee]) || isset($totsorties[$annee]))
1025  {
1026  $in = (isset($totentrees[$annee]) ?price2num($totentrees[$annee], 'MT') : 0);
1027  $out = (isset($totsorties[$annee]) ?price2num($totsorties[$annee], 'MT') : 0);
1028  print price(price2num($in - $out, 'MT')).'</td>';
1029  // print '<td>&nbsp;</td>';
1030  }
1031 }
1032 print "</tr>\n";
1033 
1034 print "</table>";
1035 print '</div>';
1036 
1037 // End of page
1038 llxFooter();
1039 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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...
dol_now($mode= 'auto')
Return date for now.
report_header($reportname, $notused, $period, $periodlink, $description, $builddate, $exportlink= '', $moreparam=array(), $calcmode= '', $varlink= '')
Show header of a report.
Definition: report.lib.php:41
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition: date.lib.php:481
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...
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to manage generation of HTML components Only common components must be here.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
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.
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
print $_SERVER["PHP_SELF"]
Edit parameters.
img_next($titlealt= 'default', $moreatt= '')
Show next logo.
dol_getIdFromCode($db, $key, $tablename, $fieldkey= 'code', $fieldid= 'id', $entityfilter=0)
Return an id or code from a code or id.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition: date.lib.php:498
print
Draft customers invoices.
Definition: index.php:89
img_previous($titlealt= 'default', $moreatt= '')
Show previous logo.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
llxFooter()
Empty footer.
Definition: wrapper.php:59
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin= '1', $morecss= '', $textfordropdown= '')
Show information for admin users or standard users.