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