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