dolibarr  17.0.4
index.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2017 Olivier Geffroy <jeff@jeffinfo.com>
6  * Copyright (C) 2018-2020 Frédéric France <frederic.france@netlogic.fr>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
27 // Load Dolibarr environment
28 require '../../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
31 
32 // Load translation files required by the page
33 $langs->loadLangs(array('compta', 'bills', 'donation', 'salaries'));
34 
35 $date_startday = GETPOST('date_startday', 'int');
36 $date_startmonth = GETPOST('date_startmonth', 'int');
37 $date_startyear = GETPOST('date_startyear', 'int');
38 $date_endday = GETPOST('date_endday', 'int');
39 $date_endmonth = GETPOST('date_endmonth', 'int');
40 $date_endyear = GETPOST('date_endyear', 'int');
41 
42 $nbofyear = 4;
43 
44 // Date range
45 $year = GETPOST('year', 'int');
46 if (empty($year)) {
47  $year_current = dol_print_date(dol_now(), "%Y");
48  $month_current = dol_print_date(dol_now(), "%m");
49  $year_start = $year_current - ($nbofyear - 1);
50 } else {
51  $year_current = $year;
52  $month_current = dol_print_date(dol_now(), "%m");
53  $year_start = $year - ($nbofyear - 1);
54 }
55 $date_start = dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear, 'tzserver');
56 $date_end = dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear, 'tzserver');
57 
58 // We define date_start and date_end
59 if (empty($date_start) || empty($date_end)) { // We define date_start and date_end
60  $q = GETPOST("q") ? GETPOST("q") : 0;
61  if ($q == 0) {
62  // We define date_start and date_end
63  $year_end = $year_start + ($nbofyear - 1);
64  $month_start = GETPOSTISSET("month") ? GETPOST("month", 'int') : ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1);
65  if (!GETPOST('month')) {
66  if (!GETPOST("year") && $month_start > $month_current) {
67  $year_start--;
68  $year_end--;
69  }
70  $month_end = $month_start - 1;
71  if ($month_end < 1) {
72  $month_end = 12;
73  } else {
74  $year_end++;
75  }
76  } else {
77  $month_end = $month_start;
78  }
79  $date_start = dol_get_first_day($year_start, $month_start, false);
80  $date_end = dol_get_last_day($year_end, $month_end, false);
81  }
82  if ($q == 1) {
83  $date_start = dol_get_first_day($year_start, 1, false);
84  $date_end = dol_get_last_day($year_start, 3, false);
85  }
86  if ($q == 2) {
87  $date_start = dol_get_first_day($year_start, 4, false);
88  $date_end = dol_get_last_day($year_start, 6, false);
89  }
90  if ($q == 3) {
91  $date_start = dol_get_first_day($year_start, 7, false);
92  $date_end = dol_get_last_day($year_start, 9, false);
93  }
94  if ($q == 4) {
95  $date_start = dol_get_first_day($year_start, 10, false);
96  $date_end = dol_get_last_day($year_start, 12, false);
97  }
98 }
99 
100 $userid = GETPOST('userid', 'int');
101 $socid = GETPOST('socid', 'int');
102 
103 $tmps = dol_getdate($date_start);
104 $mothn_start = $tmps['mon'];
105 $year_start = $tmps['year'];
106 $tmpe = dol_getdate($date_end);
107 $month_end = $tmpe['mon'];
108 $year_end = $tmpe['year'];
109 $nbofyear = ($year_end - $year_start) + 1;
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")) {
117  $modecompta = GETPOST("modecompta", 'alpha');
118 }
119 
120 // Security check
121 if ($user->socid > 0) {
122  $socid = $user->socid;
123 }
124 if (isModEnabled('comptabilite')) {
125  $result = restrictedArea($user, 'compta', '', '', 'resultat');
126 }
127 if (isModEnabled('accounting')) {
128  $result = restrictedArea($user, 'accounting', '', '', 'comptarapport');
129 }
130 
131 
132 
133 
134 /*
135  * View
136  */
137 
138 $param = '';
139 if ($date_startday && $date_startmonth && $date_startyear) {
140  $param .= '&date_startday='.$date_startday.'&date_startmonth='.$date_startmonth.'&date_startyear='.$date_startyear;
141 }
142 if ($date_endday && $date_endmonth && $date_endyear) {
143  $param .= '&date_endday='.$date_endday.'&date_endmonth='.$date_endmonth.'&date_endyear='.$date_endyear;
144 }
145 
146 llxHeader();
147 
148 $form = new Form($db);
149 
150 $exportlink="";
151 $namelink="";
152 // Affiche en-tete du rapport
153 if ($modecompta == "CREANCES-DETTES") {
154  $name = $langs->trans("Turnover");
155  $calcmode = $langs->trans("CalcModeDebt");
156  //$calcmode.='<br>('.$langs->trans("SeeReportInInputOutputMode",'<a href="'.$_SERVER["PHP_SELF"].'?year_start='.$year_start.'&modecompta=RECETTES-DEPENSES">','</a>').')';
157  if (isModEnabled('accounting')) {
158  $calcmode .= '<br>('.$langs->trans("SeeReportInBookkeepingMode", '{link1}', '{link2}').')';
159  $calcmode = str_replace('{link1}', '<a class="bold" href="'.$_SERVER["PHP_SELF"].'?'.($param ? $param : 'year_start='.$year_start).'&modecompta=BOOKKEEPING">', $calcmode);
160  $calcmode = str_replace('{link2}', '</a>', $calcmode);
161  }
162  $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>" : "");
163  $description = $langs->trans("RulesCADue");
164  if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
165  $description .= $langs->trans("DepositsAreNotIncluded");
166  } else {
167  $description .= $langs->trans("DepositsAreIncluded");
168  }
169  $builddate = dol_now();
170  //$exportlink=$langs->trans("NotYetAvailable");
171 } elseif ($modecompta == "RECETTES-DEPENSES") {
172  $name = $langs->trans("TurnoverCollected");
173  $calcmode = $langs->trans("CalcModeEngagement");
174  //$calcmode .= '<br>('.$langs->trans("SeeReportInDueDebtMode",'<a href="'.$_SERVER["PHP_SELF"].'?year_start='.$year_start.'&modecompta=CREANCES-DETTES">','</a>').')';
175  //if (isModEnabled('accounting')) {
176  //$calcmode.='<br>('.$langs->trans("SeeReportInBookkeepingMode",'<a href="'.$_SERVER["PHP_SELF"].'?year_start='.$year_start.'&modecompta=BOOKKEEPINGCOLLECTED">','</a>').')';
177  //}
178  $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>" : "");
179  $description = $langs->trans("RulesCAIn");
180  $description .= $langs->trans("DepositsAreIncluded");
181  $builddate = dol_now();
182  //$exportlink=$langs->trans("NotYetAvailable");
183 } elseif ($modecompta == "BOOKKEEPING") {
184  $name = $langs->trans("Turnover");
185  $calcmode = $langs->trans("CalcModeBookkeeping");
186  $calcmode .= '<br>('.$langs->trans("SeeReportInDueDebtMode", '{link1}', '{link2}').')';
187  $calcmode = str_replace('{link1}', '<a class="bold" href="'.$_SERVER["PHP_SELF"].'?'.($param ? $param : 'year_start='.$year_start).'&modecompta=CREANCES-DETTES">', $calcmode);
188  $calcmode = str_replace('{link2}', '</a>', $calcmode);
189  //$calcmode.='<br>('.$langs->trans("SeeReportInInputOutputMode",'<a href="'.$_SERVER["PHP_SELF"].'?year_start='.$year_start.'&modecompta=RECETTES-DEPENSES">','</a>').')';
190  $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>" : "");
191  $description = $langs->trans("RulesSalesTurnoverOfIncomeAccounts");
192  $builddate = dol_now();
193  //$exportlink=$langs->trans("NotYetAvailable");
194 }
195 $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0, 0, '', '', '', '', 1, '', '', 'tzserver');
196 $period .= ' - ';
197 $period .= $form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0, 0, '', '', '', '', 1, '', '', 'tzserver');
198 
199 $moreparam = array();
200 if (!empty($modecompta)) {
201  $moreparam['modecompta'] = $modecompta;
202 }
203 report_header($name, $namelink, $period, $periodlink, $description, $builddate, $exportlink, $moreparam, $calcmode);
204 
205 if (isModEnabled('accounting') && $modecompta != 'BOOKKEEPING') {
206  print info_admin($langs->trans("WarningReportNotReliable"), 0, 0, 1);
207 }
208 
209 
210 if ($modecompta == 'CREANCES-DETTES') {
211  $sql = "SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total_ht) as amount, sum(f.total_ttc) as amount_ttc";
212  $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
213  $sql .= " WHERE f.fk_statut in (1,2)";
214  if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
215  $sql .= " AND f.type IN (0,1,2,5)";
216  } else {
217  $sql .= " AND f.type IN (0,1,2,3,5)";
218  }
219  $sql .= " AND f.entity IN (".getEntity('invoice').")";
220  if ($socid) {
221  $sql .= " AND f.fk_soc = ".((int) $socid);
222  }
223 } elseif ($modecompta == "RECETTES-DEPENSES") {
224  /*
225  * Liste des paiements (les anciens paiements ne sont pas vus par cette requete car, sur les
226  * vieilles versions, ils n'etaient pas lies via paiement_facture. On les ajoute plus loin)
227  */
228  $sql = "SELECT date_format(p.datep, '%Y-%m') as dm, sum(pf.amount) as amount_ttc";
229  $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
230  $sql .= ", ".MAIN_DB_PREFIX."paiement_facture as pf";
231  $sql .= ", ".MAIN_DB_PREFIX."paiement as p";
232  $sql .= " WHERE p.rowid = pf.fk_paiement";
233  $sql .= " AND pf.fk_facture = f.rowid";
234  $sql .= " AND f.entity IN (".getEntity('invoice').")";
235  if ($socid) {
236  $sql .= " AND f.fk_soc = ".((int) $socid);
237  }
238 } elseif ($modecompta == "BOOKKEEPING") {
239  $pcgverid = $conf->global->CHARTOFACCOUNTS;
240  $pcgvercode = dol_getIdFromCode($db, $pcgverid, 'accounting_system', 'rowid', 'pcg_version');
241  if (empty($pcgvercode)) {
242  $pcgvercode = $pcgverid;
243  }
244 
245  $sql = "SELECT date_format(b.doc_date, '%Y-%m') as dm, sum(b.credit - b.debit) as amount_ttc";
246  $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as b,";
247  $sql .= " ".MAIN_DB_PREFIX."accounting_account as aa";
248  $sql .= " WHERE b.entity = ".$conf->entity; // In module double party accounting, we never share entities
249  $sql .= " AND b.numero_compte = aa.account_number";
250  $sql .= " AND b.doc_type = 'customer_invoice'";
251  $sql .= " AND aa.entity = ".$conf->entity;
252  $sql .= " AND aa.fk_pcg_version = '".$db->escape($pcgvercode)."'";
253  $sql .= " AND aa.pcg_type = 'INCOME'"; // TODO Be able to use a custom group
254 }
255 $sql .= " GROUP BY dm";
256 $sql .= " ORDER BY dm";
257 // TODO Add a filter on $date_start and $date_end to reduce quantity on data
258 //print $sql;
259 
260 $minyearmonth = $maxyearmonth = 0;
261 
262 $cum = array();
263 $cum_ht = array();
264 $total_ht = array();
265 $total = array();
266 
267 $result = $db->query($sql);
268 if ($result) {
269  $num = $db->num_rows($result);
270  $i = 0;
271  while ($i < $num) {
272  $obj = $db->fetch_object($result);
273  $cum_ht[$obj->dm] = empty($obj->amount) ? 0 : $obj->amount;
274  $cum[$obj->dm] = empty($obj->amount_ttc) ? 0 : $obj->amount_ttc;
275  if ($obj->amount_ttc) {
276  $minyearmonth = ($minyearmonth ? min($minyearmonth, $obj->dm) : $obj->dm);
277  $maxyearmonth = max($maxyearmonth, $obj->dm);
278  }
279  $i++;
280  }
281  $db->free($result);
282 } else {
283  dol_print_error($db);
284 }
285 
286 // On ajoute les paiements anciennes version, non lies par paiement_facture (very old versions)
287 if ($modecompta == 'RECETTES-DEPENSES') {
288  $sql = "SELECT date_format(p.datep,'%Y-%m') as dm, sum(p.amount) as amount_ttc";
289  $sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
290  $sql .= ", ".MAIN_DB_PREFIX."bank_account as ba";
291  $sql .= ", ".MAIN_DB_PREFIX."paiement as p";
292  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement";
293  $sql .= " WHERE pf.rowid IS NULL";
294  $sql .= " AND p.fk_bank = b.rowid";
295  $sql .= " AND b.fk_account = ba.rowid";
296  $sql .= " AND ba.entity IN (".getEntity('bank_account').")";
297  $sql .= " GROUP BY dm";
298  $sql .= " ORDER BY dm";
299 
300  $result = $db->query($sql);
301  if ($result) {
302  $num = $db->num_rows($result);
303  $i = 0;
304  while ($i < $num) {
305  $obj = $db->fetch_object($result);
306  if (empty($cum[$obj->dm])) {
307  $cum[$obj->dm] = $obj->amount_ttc;
308  } else {
309  $cum[$obj->dm] += $obj->amount_ttc;
310  }
311  if ($obj->amount_ttc) {
312  $minyearmonth = ($minyearmonth ?min($minyearmonth, $obj->dm) : $obj->dm);
313  $maxyearmonth = max($maxyearmonth, $obj->dm);
314  }
315  $i++;
316  }
317  } else {
318  dol_print_error($db);
319  }
320 }
321 
322 $moreforfilter = '';
323 
324 print '<div class="div-table-responsive">';
325 print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
326 
327 print '<tr class="liste_titre"><td>&nbsp;</td>';
328 
329 for ($annee = $year_start; $annee <= $year_end; $annee++) {
330  if ($modecompta == 'CREANCES-DETTES') {
331  print '<td align="center" width="10%" colspan="3">';
332  } else {
333  print '<td align="center" width="10%" colspan="2" class="borderrightlight">';
334  }
335  if ($modecompta != 'BOOKKEEPING') {
336  print '<a href="casoc.php?year='.$annee.'">';
337  }
338  print $annee;
339  if ($conf->global->SOCIETE_FISCAL_MONTH_START > 1) {
340  print '-'.($annee + 1);
341  }
342  if ($modecompta != 'BOOKKEEPING') {
343  print '</a>';
344  }
345  print '</td>';
346  if ($annee != $year_end) {
347  print '<td width="15">&nbsp;</td>';
348  }
349 }
350 print '</tr>';
351 
352 print '<tr class="liste_titre"><td class="liste_titre">'.$langs->trans("Month").'</td>';
353 for ($annee = $year_start; $annee <= $year_end; $annee++) {
354  if ($modecompta == 'CREANCES-DETTES') {
355  print '<td class="liste_titre right">'.$langs->trans("AmountHT").'</td>';
356  }
357  print '<td class="liste_titre right">';
358  if ($modecompta == "BOOKKEEPING") {
359  print $langs->trans("Amount");
360  } else {
361  print $langs->trans("AmountTTC");
362  }
363  print '</td>';
364  print '<td class="liste_titre right borderrightlight">'.$langs->trans("Delta").'</td>';
365  if ($annee != $year_end) {
366  print '<td class="liste_titre" width="15">&nbsp;</td>';
367  }
368 }
369 print '</tr>';
370 
371 $now_show_delta = 0;
372 $minyear = substr($minyearmonth, 0, 4);
373 $maxyear = substr($maxyearmonth, 0, 4);
374 $nowyear = dol_print_date(dol_now('gmt'), "%Y", 'gmt');
375 $nowyearmonth = strftime("%Y-%m", dol_now());
376 $maxyearmonth = max($maxyearmonth, $nowyearmonth);
377 $now = dol_now();
378 $casenow = dol_print_date($now, "%Y-%m");
379 
380 // Loop on each month
381 $nb_mois_decalage = GETPOSTISSET('date_startmonth') ? (GETPOST('date_startmonth', 'int') - 1) : (empty($conf->global->SOCIETE_FISCAL_MONTH_START) ? 0 : ($conf->global->SOCIETE_FISCAL_MONTH_START - 1));
382 for ($mois = 1 + $nb_mois_decalage; $mois <= 12 + $nb_mois_decalage; $mois++) {
383  $mois_modulo = $mois; // ajout
384  if ($mois > 12) {
385  $mois_modulo = $mois - 12;
386  } // ajout
387 
388  if ($year_start == $year_end) {
389  // If we show only one year or one month, we do not show month before the selected month
390  if ($mois < $date_startmonth && $year_start <= $date_startyear) {
391  continue;
392  }
393  // If we show only one year or one month, we do not show month after the selected month
394  if ($mois > $date_endmonth && $year_end >= $date_endyear) {
395  break;
396  }
397  }
398 
399  print '<tr class="oddeven">';
400 
401  // Month
402  print "<td>".dol_print_date(dol_mktime(12, 0, 0, $mois_modulo, 1, 2000), "%B")."</td>";
403 
404  for ($annee = $year_start - 1; $annee <= $year_end; $annee++) { // We start one year before to have data to be able to make delta
405  $annee_decalage = $annee;
406  if ($mois > 12) {
407  $annee_decalage = $annee + 1;
408  }
409  $case = dol_print_date(dol_mktime(1, 1, 1, $mois_modulo, 1, $annee_decalage), "%Y-%m");
410  $caseprev = dol_print_date(dol_mktime(1, 1, 1, $mois_modulo, 1, $annee_decalage - 1), "%Y-%m");
411 
412  if ($annee >= $year_start) { // We ignore $annee < $year_start, we loop on it to be able to make delta, nothing is output.
413  if ($modecompta == 'CREANCES-DETTES') {
414  // Value turnover of month w/o VAT
415  print '<td class="right">';
416  if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) {
417  if ($cum_ht[$case]) {
418  $now_show_delta = 1; // On a trouve le premier mois de la premiere annee generant du chiffre.
419  print '<a href="casoc.php?year='.$annee_decalage.'&month='.$mois_modulo.($modecompta ? '&modecompta='.$modecompta : '').'">'.price($cum_ht[$case], 1).'</a>';
420  } else {
421  if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) {
422  print '0';
423  } else {
424  print '&nbsp;';
425  }
426  }
427  }
428  print "</td>";
429  }
430 
431  // Value turnover of month
432  print '<td class="right">';
433  if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) {
434  if (!empty($cum[$case])) {
435  $now_show_delta = 1; // On a trouve le premier mois de la premiere annee generant du chiffre.
436  if ($modecompta != 'BOOKKEEPING') {
437  print '<a href="casoc.php?year='.$annee_decalage.'&month='.$mois_modulo.($modecompta ? '&modecompta='.$modecompta : '').'">';
438  }
439  print price($cum[$case], 1);
440  if ($modecompta != 'BOOKKEEPING') {
441  print '</a>';
442  }
443  } else {
444  if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) {
445  print '0';
446  } else {
447  print '&nbsp;';
448  }
449  }
450  }
451  print "</td>";
452 
453  // Percentage of month
454  print '<td class="borderrightlight right"><span class="opacitymedium">';
455  //var_dump($annee.' '.$year_end.' '.$mois.' '.$month_end);
456  if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) {
457  if ($annee_decalage > $minyear && $case <= $casenow) {
458  if (!empty($cum[$caseprev]) && !empty($cum[$case])) {
459  $percent = (round(($cum[$case] - $cum[$caseprev]) / $cum[$caseprev], 4) * 100);
460  //print "X $cum[$case] - $cum[$caseprev] - $cum[$caseprev] - $percent X";
461  print ($percent >= 0 ? "+$percent" : "$percent").'%';
462  }
463  if (!empty($cum[$caseprev]) && empty($cum[$case])) {
464  print '-100%';
465  }
466  if (empty($cum[$caseprev]) && !empty($cum[$case])) {
467  //print '<td class="right">+Inf%</td>';
468  print '-';
469  }
470  if (isset($cum[$caseprev]) && empty($cum[$caseprev]) && empty($cum[$case])) {
471  print '+0%';
472  }
473  if (!isset($cum[$caseprev]) && empty($cum[$case])) {
474  print '-';
475  }
476  } else {
477  if ($minyearmonth <= $case && $case <= $maxyearmonth) {
478  print '-';
479  } else {
480  print '&nbsp;';
481  }
482  }
483  }
484  print '</span></td>';
485 
486  if ($annee_decalage < $year_end || ($annee_decalage == $year_end && $mois > 12 && $annee < $year_end)) {
487  print '<td width="15">&nbsp;</td>';
488  }
489  }
490 
491  if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) {
492  if (empty($total_ht[$annee])) {
493  $total_ht[$annee] = (empty($cum_ht[$case]) ? 0 : $cum_ht[$case]);
494  } else {
495  $total_ht[$annee] += (empty($cum_ht[$case]) ? 0 : $cum_ht[$case]);
496  }
497  if (empty($total[$annee])) {
498  $total[$annee] = empty($cum[$case]) ? 0 : $cum[$case];
499  } else {
500  $total[$annee] += empty($cum[$case]) ? 0 : $cum[$case];
501  }
502  }
503  }
504 
505  print '</tr>';
506 }
507 
508 /*
509  for ($mois = 1 ; $mois < 13 ; $mois++)
510  {
511 
512  print '<tr class="oddeven">';
513 
514  print "<td>".dol_print_date(dol_mktime(12,0,0,$mois,1,2000),"%B")."</td>";
515  for ($annee = $year_start ; $annee <= $year_end ; $annee++)
516  {
517  $casenow = dol_print_date(dol_now(),"%Y-%m");
518  $case = dol_print_date(dol_mktime(1,1,1,$mois,1,$annee),"%Y-%m");
519  $caseprev = dol_print_date(dol_mktime(1,1,1,$mois,1,$annee-1),"%Y-%m");
520 
521  // Valeur CA du mois
522  print '<td class="right">';
523  if ($cum[$case])
524  {
525  $now_show_delta=1; // On a trouve le premier mois de la premiere annee generant du chiffre.
526  print '<a href="casoc.php?year='.$annee.'&month='.$mois.'">'.price($cum[$case],1).'</a>';
527  }
528  else
529  {
530  if ($minyearmonth < $case && $case <= max($maxyearmonth,$nowyearmonth)) { print '0'; }
531  else { print '&nbsp;'; }
532  }
533  print "</td>";
534 
535  // Pourcentage du mois
536  if ($annee > $minyear && $case <= $casenow) {
537  if ($cum[$caseprev] && $cum[$case])
538  {
539  $percent=(round(($cum[$case]-$cum[$caseprev])/$cum[$caseprev],4)*100);
540  //print "X $cum[$case] - $cum[$caseprev] - $cum[$caseprev] - $percent X";
541  print '<td class="right">'.($percent>=0?"+$percent":"$percent").'%</td>';
542 
543  }
544  if ($cum[$caseprev] && ! $cum[$case])
545  {
546  print '<td class="right">-100%</td>';
547  }
548  if (! $cum[$caseprev] && $cum[$case])
549  {
550  print '<td class="right">+Inf%</td>';
551  }
552  if (! $cum[$caseprev] && ! $cum[$case])
553  {
554  print '<td class="right">+0%</td>';
555  }
556  }
557  else
558  {
559  print '<td class="right">';
560  if ($minyearmonth <= $case && $case <= $maxyearmonth) { print '-'; }
561  else { print '&nbsp;'; }
562  print '</td>';
563  }
564 
565  $total[$annee]+=$cum[$case];
566  if ($annee != $year_end) print '<td width="15">&nbsp;</td>';
567  }
568 
569  print '</tr>';
570  }
571  */
572 
573 // Show total
574 print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td>';
575 for ($annee = $year_start; $annee <= $year_end; $annee++) {
576  if ($modecompta == 'CREANCES-DETTES') {
577  // Montant total HT
578  if ($total_ht[$annee] || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) {
579  print '<td class="nowrap right">';
580  print (empty($total_ht[$annee]) ? '0' : price($total_ht[$annee]));
581  print "</td>";
582  } else {
583  print '<td>&nbsp;</td>';
584  }
585  }
586 
587  // Total amount
588  if (!empty($total[$annee]) || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) {
589  print '<td class="nowrap right">';
590  print (empty($total[$annee]) ? '0' : price($total[$annee]));
591  print "</td>";
592  } else {
593  print '<td>&nbsp;</td>';
594  }
595 
596  // Pourcentage total
597  if ($annee > $minyear && $annee <= max($nowyear, $maxyear)) {
598  if (!empty($total[$annee - 1]) && !empty($total[$annee])) {
599  $percent = (round(($total[$annee] - $total[$annee - 1]) / $total[$annee - 1], 4) * 100);
600  print '<td class="nowrap borderrightlight right">';
601  print ($percent >= 0 ? "+$percent" : "$percent").'%';
602  print '</td>';
603  }
604  if (!empty($total[$annee - 1]) && empty($total[$annee])) {
605  print '<td class="borderrightlight right">-100%</td>';
606  }
607  if (empty($total[$annee - 1]) && !empty($total[$annee])) {
608  print '<td class="borderrightlight right">+'.$langs->trans('Inf').'%</td>';
609  }
610  if (empty($total[$annee - 1]) && empty($total[$annee])) {
611  print '<td class="borderrightlight right">+0%</td>';
612  }
613  } else {
614  print '<td class="borderrightlight right">';
615  if (!empty($total[$annee]) || ($minyear <= $annee && $annee <= max($nowyear, $maxyear))) {
616  print '-';
617  } else {
618  print '&nbsp;';
619  }
620  print '</td>';
621  }
622 
623  if ($annee != $year_end) {
624  print '<td width="15">&nbsp;</td>';
625  }
626 }
627 print "</tr>\n";
628 print "</table>";
629 print '</div>';
630 
631 
632 /*
633  * En mode recettes/depenses, on complete avec les montants factures non regles
634  * et les propales signees mais pas facturees. En effet, en recettes-depenses,
635  * on comptabilise lorsque le montant est sur le compte donc il est interessant
636  * d'avoir une vision de ce qui va arriver.
637  */
638 
639 /*
640  Je commente toute cette partie car les chiffres affichees sont faux - Eldy.
641  En attendant correction.
642 
643  if ($modecompta != 'CREANCES-DETTES')
644  {
645 
646  print '<br><table width="100%" class="noborder">';
647 
648  // Factures non reglees
649  // Y a bug ici. Il faut prendre le reste a payer et non le total des factures non reglees !
650 
651  $sql = "SELECT f.ref, f.rowid, s.nom, s.rowid as socid, f.total_ttc, sum(pf.amount) as am";
652  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f left join ".MAIN_DB_PREFIX."paiement_facture as pf on f.rowid=pf.fk_facture";
653  $sql .= " WHERE s.rowid = f.fk_soc AND f.paye = 0 AND f.fk_statut = 1";
654  if ($socid)
655  {
656  $sql .= " AND f.fk_soc = $socid";
657  }
658  $sql .= " GROUP BY f.ref,f.rowid,s.nom, s.rowid, f.total_ttc";
659 
660  $resql=$db->query($sql);
661  if ($resql)
662  {
663  $num = $db->num_rows($resql);
664  $i = 0;
665 
666  if ($num)
667  {
668  $total_ttc_Rac = $totalam_Rac = $total_Rac = 0;
669  while ($i < $num)
670  {
671  $obj = $db->fetch_object($resql);
672  $total_ttc_Rac += $obj->total_ttc;
673  $totalam_Rac += $obj->am;
674  $i++;
675  }
676 
677  print "<tr class="oddeven"><td class=\"right\" colspan=\"5\"><i>Facture a encaisser : </i></td><td class=\"right\"><i>".price($total_ttc_Rac)."</i></td><td colspan=\"5\"><-- bug ici car n'exclut pas le deja r?gl? des factures partiellement r?gl?es</td></tr>";
678  }
679  $db->free($resql);
680  }
681  else
682  {
683  dol_print_error($db);
684  }
685  */
686 
687 /*
688  *
689  * Propales signees, et non facturees
690  *
691  */
692 
693 /*
694  Je commente toute cette partie car les chiffres affichees sont faux - Eldy.
695  En attendant correction.
696 
697  $sql = "SELECT sum(f.total_ht) as tot_fht,sum(f.total_ttc) as tot_fttc, p.rowid, p.ref, s.nom, s.rowid as socid, p.total_ht, p.total_ttc
698  FROM ".MAIN_DB_PREFIX."commande AS p, ".MAIN_DB_PREFIX."societe AS s
699  LEFT JOIN ".MAIN_DB_PREFIX."co_fa AS co_fa ON co_fa.fk_commande = p.rowid
700  LEFT JOIN ".MAIN_DB_PREFIX."facture AS f ON co_fa.fk_facture = f.rowid
701  WHERE p.fk_soc = s.rowid
702  AND p.fk_statut >=1
703  AND p.facture =0";
704  if ($socid)
705  {
706  $sql .= " AND f.fk_soc = ".((int) $socid);
707  }
708  $sql .= " GROUP BY p.rowid";
709 
710  $resql=$db->query($sql);
711  if ($resql)
712  {
713  $num = $db->num_rows($resql);
714  $i = 0;
715 
716  if ($num)
717  {
718  $total_pr = 0;
719  while ($i < $num)
720  {
721  $obj = $db->fetch_object($resql);
722  $total_pr += $obj->total_ttc-$obj->tot_fttc;
723  $i++;
724  }
725 
726  print "<tr class="oddeven"><td class=\"right\" colspan=\"5\"><i>Signe et non facture:</i></td><td class=\"right\"><i>".price($total_pr)."</i></td><td colspan=\"5\"><-- bug ici, ca devrait exclure le deja facture</td></tr>";
727  }
728  $db->free($resql);
729  }
730  else
731  {
732  dol_print_error($db);
733  }
734  print "<tr class="oddeven"><td class=\"right\" colspan=\"5\"><i>Total CA previsionnel : </i></td><td class=\"right\"><i>".price($total_CA)."</i></td><td colspan=\"3\"><-- bug ici car bug sur les 2 precedents</td></tr>";
735  }
736  print "</table>";
737 
738  */
739 
740 // End of page
741 llxFooter();
742 $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...
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.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
isModEnabled($module)
Is Dolibarr module enabled.
dol_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.