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