dolibarr  13.0.2
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 require '../../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
30 
31 // Load translation files required by the page
32 $langs->loadLangs(array('compta', 'bills', 'donation', 'salaries'));
33 
34 $date_startday = GETPOST('date_startday', 'int');
35 $date_startmonth = GETPOST('date_startmonth', 'int');
36 $date_startyear = GETPOST('date_startyear', 'int');
37 $date_endday = GETPOST('date_endday', 'int');
38 $date_endmonth = GETPOST('date_endmonth', 'int');
39 $date_endyear = GETPOST('date_endyear', 'int');
40 
41 $nbofyear = 4;
42 
43 // Date range
44 $year = GETPOST('year', 'int');
45 if (empty($year))
46 {
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);
56 $date_end = dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
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 {
61  $q = GETPOST("q") ? GETPOST("q") : 0;
62  if ($q == 0)
63  {
64  // We define date_start and date_end
65  $year_end = $year_start + ($nbofyear - 1);
66  $month_start = GETPOSTISSET("month") ? GETPOST("month", 'int') : ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1);
67  if (!GETPOST('month'))
68  {
69  if (!GETPOST("year") && $month_start > $month_current)
70  {
71  $year_start--;
72  $year_end--;
73  }
74  $month_end = $month_start - 1;
75  if ($month_end < 1) $month_end = 12;
76  } else $month_end = $month_start;
77  $date_start = dol_get_first_day($year_start, $month_start, false); $date_end = dol_get_last_day($year_end, $month_end, false);
78  }
79  if ($q == 1) { $date_start = dol_get_first_day($year_start, 1, false); $date_end = dol_get_last_day($year_start, 3, false); }
80  if ($q == 2) { $date_start = dol_get_first_day($year_start, 4, false); $date_end = dol_get_last_day($year_start, 6, false); }
81  if ($q == 3) { $date_start = dol_get_first_day($year_start, 7, false); $date_end = dol_get_last_day($year_start, 9, false); }
82  if ($q == 4) { $date_start = dol_get_first_day($year_start, 10, false); $date_end = dol_get_last_day($year_start, 12, false); }
83 }
84 
85 $userid = GETPOST('userid', 'int');
86 $socid = GETPOST('socid', 'int');
87 
88 $tmps = dol_getdate($date_start);
89 $mothn_start = $tmps['mon'];
90 $year_start = $tmps['year'];
91 $tmpe = dol_getdate($date_end);
92 $month_end = $tmpe['mon'];
93 $year_end = $tmpe['year'];
94 $nbofyear = ($year_end - $year_start) + 1;
95 
96 // Define modecompta ('CREANCES-DETTES' or 'RECETTES-DEPENSES' or 'BOOKKEEPING')
97 $modecompta = $conf->global->ACCOUNTING_MODE;
98 if (!empty($conf->accounting->enabled)) $modecompta = 'BOOKKEEPING';
99 if (GETPOST("modecompta")) $modecompta = GETPOST("modecompta", 'alpha');
100 
101 // Security check
102 if ($user->socid > 0) $socid = $user->socid;
103 if (!empty($conf->comptabilite->enabled)) $result = restrictedArea($user, 'compta', '', '', 'resultat');
104 if (!empty($conf->accounting->enabled)) $result = restrictedArea($user, 'accounting', '', '', 'comptarapport');
105 
106 
107 
108 
109 /*
110  * View
111  */
112 
113 $param = '';
114 if ($date_startday && $date_startmonth && $date_startyear) $param .= '&date_startday='.$date_startday.'&date_startmonth='.$date_startmonth.'&date_startyear='.$date_startyear;
115 if ($date_endday && $date_endmonth && $date_endyear) $param .= '&date_endday='.$date_endday.'&date_endmonth='.$date_endmonth.'&date_endyear='.$date_endyear;
116 
117 llxHeader();
118 
119 $form = new Form($db);
120 
121 // Affiche en-tete du rapport
122 if ($modecompta == "CREANCES-DETTES")
123 {
124  $name = $langs->trans("Turnover");
125  $calcmode = $langs->trans("CalcModeDebt");
126  //$calcmode.='<br>('.$langs->trans("SeeReportInInputOutputMode",'<a href="'.$_SERVER["PHP_SELF"].'?year_start='.$year_start.'&modecompta=RECETTES-DEPENSES">','</a>').')';
127  $calcmode .= '<br>('.$langs->trans("SeeReportInBookkeepingMode", '{link1}', '{link2}').')';
128  $calcmode = str_replace('{link1}', '<a class="bold" href="'.$_SERVER["PHP_SELF"].'?'.($param ? $param : 'year_start='.$year_start).'&modecompta=BOOKKEEPING">', $calcmode);
129  $calcmode = str_replace('{link2}', '</a>', $calcmode);
130  $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
131  $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>" : "");
132  $description = $langs->trans("RulesCADue");
133  if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $description .= $langs->trans("DepositsAreNotIncluded");
134  else $description .= $langs->trans("DepositsAreIncluded");
135  $builddate = dol_now();
136  //$exportlink=$langs->trans("NotYetAvailable");
137 } elseif ($modecompta == "RECETTES-DEPENSES")
138 {
139  $name = $langs->trans("TurnoverCollected");
140  $calcmode = $langs->trans("CalcModeEngagement");
141  //$calcmode.='<br>('.$langs->trans("SeeReportInDueDebtMode",'<a href="'.$_SERVER["PHP_SELF"].'?year_start='.$year_start.'&modecompta=CREANCES-DETTES">','</a>').')';
142  //$calcmode.='<br>('.$langs->trans("SeeReportInBookkeepingMode",'<a href="'.$_SERVER["PHP_SELF"].'?year_start='.$year_start.'&modecompta=BOOKKEEPINGCOLLECTED">','</a>').')';
143  $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
144  $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>" : "");
145  $description = $langs->trans("RulesCAIn");
146  $description .= $langs->trans("DepositsAreIncluded");
147  $builddate = dol_now();
148  //$exportlink=$langs->trans("NotYetAvailable");
149 } elseif ($modecompta == "BOOKKEEPING")
150 {
151  $name = $langs->trans("Turnover");
152  $calcmode = $langs->trans("CalcModeBookkeeping");
153  $calcmode .= '<br>('.$langs->trans("SeeReportInDueDebtMode", '{link1}', '{link2}').')';
154  $calcmode = str_replace('{link1}', '<a class="bold" href="'.$_SERVER["PHP_SELF"].'?'.($param ? $param : 'year_start='.$year_start).'&modecompta=CREANCES-DETTES">', $calcmode);
155  $calcmode = str_replace('{link2}', '</a>', $calcmode);
156  //$calcmode.='<br>('.$langs->trans("SeeReportInInputOutputMode",'<a href="'.$_SERVER["PHP_SELF"].'?year_start='.$year_start.'&modecompta=RECETTES-DEPENSES">','</a>').')';
157  $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
158  $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>" : "");
159  $description = $langs->trans("RulesCATotalSaleJournal");
160  $builddate = dol_now();
161  //$exportlink=$langs->trans("NotYetAvailable");
162 }
163 
164 $moreparam = array();
165 if (!empty($modecompta)) $moreparam['modecompta'] = $modecompta;
166 report_header($name, $namelink, $period, $periodlink, $description, $builddate, $exportlink, $moreparam, $calcmode);
167 
168 if (!empty($conf->accounting->enabled) && $modecompta != 'BOOKKEEPING')
169 {
170  print info_admin($langs->trans("WarningReportNotReliable"), 0, 0, 1);
171 }
172 
173 
174 if ($modecompta == 'CREANCES-DETTES')
175 {
176  $sql = "SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total) as amount, sum(f.total_ttc) as amount_ttc";
177  $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
178  $sql .= " WHERE f.fk_statut in (1,2)";
179  if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql .= " AND f.type IN (0,1,2,5)";
180  else $sql .= " AND f.type IN (0,1,2,3,5)";
181  $sql .= " AND f.entity IN (".getEntity('invoice').")";
182  if ($socid) $sql .= " AND f.fk_soc = ".$socid;
183 } elseif ($modecompta == "RECETTES-DEPENSES")
184 {
185  /*
186  * Liste des paiements (les anciens paiements ne sont pas vus par cette requete car, sur les
187  * vieilles versions, ils n'etaient pas lies via paiement_facture. On les ajoute plus loin)
188  */
189  $sql = "SELECT date_format(p.datep,'%Y-%m') as dm, sum(pf.amount) as amount_ttc";
190  $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
191  $sql .= ", ".MAIN_DB_PREFIX."paiement_facture as pf";
192  $sql .= ", ".MAIN_DB_PREFIX."paiement as p";
193  $sql .= " WHERE p.rowid = pf.fk_paiement";
194  $sql .= " AND pf.fk_facture = f.rowid";
195  $sql .= " AND f.entity IN (".getEntity('invoice').")";
196  if ($socid) $sql .= " AND f.fk_soc = ".$socid;
197 } elseif ($modecompta == "BOOKKEEPING")
198 {
199  $sql = "SELECT date_format(b.doc_date,'%Y-%m') as dm, sum(b.credit) as amount_ttc";
200  $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as b, ".MAIN_DB_PREFIX."accounting_journal as aj";
201  $sql .= " WHERE b.entity = ".$conf->entity; // In module double party accounting, we never share entities
202  $sql .= " AND aj.entity = ".$conf->entity;
203  $sql .= " AND b.code_journal = aj.code AND aj.nature = 2"; // @todo currently count amount in sale journal, but we need to define a category group for turnover
204 }
205 
206 $sql .= " GROUP BY dm";
207 $sql .= " ORDER BY dm";
208 // TODO Add a filter on $date_start and $date_end to reduce quantity on data
209 //print $sql;
210 
211 $minyearmonth = $maxyearmonth = 0;
212 
213 $result = $db->query($sql);
214 if ($result)
215 {
216  $num = $db->num_rows($result);
217  $i = 0;
218  while ($i < $num)
219  {
220  $obj = $db->fetch_object($result);
221  $cum_ht[$obj->dm] = !empty($obj->amount) ? $obj->amount : 0;
222  $cum[$obj->dm] = $obj->amount_ttc;
223  if ($obj->amount_ttc)
224  {
225  $minyearmonth = ($minyearmonth ? min($minyearmonth, $obj->dm) : $obj->dm);
226  $maxyearmonth = max($maxyearmonth, $obj->dm);
227  }
228  $i++;
229  }
230  $db->free($result);
231 } else {
232  dol_print_error($db);
233 }
234 
235 // On ajoute les paiements anciennes version, non lies par paiement_facture (very old versions)
236 if ($modecompta == 'RECETTES-DEPENSES')
237 {
238  $sql = "SELECT date_format(p.datep,'%Y-%m') as dm, sum(p.amount) as amount_ttc";
239  $sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
240  $sql .= ", ".MAIN_DB_PREFIX."bank_account as ba";
241  $sql .= ", ".MAIN_DB_PREFIX."paiement as p";
242  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement";
243  $sql .= " WHERE pf.rowid IS NULL";
244  $sql .= " AND p.fk_bank = b.rowid";
245  $sql .= " AND b.fk_account = ba.rowid";
246  $sql .= " AND ba.entity IN (".getEntity('bank_account').")";
247  $sql .= " GROUP BY dm";
248  $sql .= " ORDER BY dm";
249 
250  $result = $db->query($sql);
251  if ($result)
252  {
253  $num = $db->num_rows($result);
254  $i = 0;
255  while ($i < $num)
256  {
257  $obj = $db->fetch_object($result);
258  $cum[$obj->dm] += $obj->amount_ttc;
259  if ($obj->amount_ttc)
260  {
261  $minyearmonth = ($minyearmonth ?min($minyearmonth, $obj->dm) : $obj->dm);
262  $maxyearmonth = max($maxyearmonth, $obj->dm);
263  }
264  $i++;
265  }
266  } else {
267  dol_print_error($db);
268  }
269 }
270 
271 $moreforfilter = '';
272 
273 print '<div class="div-table-responsive">';
274 print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
275 
276 print '<tr class="liste_titre"><td>&nbsp;</td>';
277 
278 for ($annee = $year_start; $annee <= $year_end; $annee++)
279 {
280  if ($modecompta == 'CREANCES-DETTES') print '<td align="center" width="10%" colspan="3">';
281  else print '<td align="center" width="10%" colspan="2" class="borderrightlight">';
282  if ($modecompta != 'BOOKKEEPING') print '<a href="casoc.php?year='.$annee.'">';
283  print $annee;
284  if ($conf->global->SOCIETE_FISCAL_MONTH_START > 1) print '-'.($annee + 1);
285  if ($modecompta != 'BOOKKEEPING') print '</a>';
286  print '</td>';
287  if ($annee != $year_end) print '<td width="15">&nbsp;</td>';
288 }
289 print '</tr>';
290 
291 print '<tr class="liste_titre"><td class="liste_titre">'.$langs->trans("Month").'</td>';
292 for ($annee = $year_start; $annee <= $year_end; $annee++)
293 {
294  if ($modecompta == 'CREANCES-DETTES') print '<td class="liste_titre right">'.$langs->trans("AmountHT").'</td>';
295  print '<td class="liste_titre right">'.$langs->trans("AmountTTC").'</td>';
296  print '<td class="liste_titre right borderrightlight">'.$langs->trans("Delta").'</td>';
297  if ($annee != $year_end) print '<td class="liste_titre" width="15">&nbsp;</td>';
298 }
299 print '</tr>';
300 
301 $now_show_delta = 0;
302 $minyear = substr($minyearmonth, 0, 4);
303 $maxyear = substr($maxyearmonth, 0, 4);
304 $nowyear = strftime("%Y", dol_now());
305 $nowyearmonth = strftime("%Y-%m", dol_now());
306 $maxyearmonth = max($maxyearmonth, $nowyearmonth);
307 $now = dol_now();
308 $casenow = dol_print_date($now, "%Y-%m");
309 
310 // Loop on each month
311 $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));
312 for ($mois = 1 + $nb_mois_decalage; $mois <= 12 + $nb_mois_decalage; $mois++)
313 {
314  $mois_modulo = $mois; // ajout
315  if ($mois > 12) {$mois_modulo = $mois - 12; } // ajout
316 
317  if ($year_start == $year_end) {
318  // If we show only one year or one month, we do not show month before the selected month
319  if ($mois < $date_startmonth && $year_start <= $date_startyear) {
320  continue;
321  }
322  // If we show only one year or one month, we do not show month after the selected month
323  if ($mois > $date_endmonth && $year_end >= $date_endyear) {
324  break;
325  }
326  }
327 
328  print '<tr class="oddeven">';
329 
330  // Month
331  print "<td>".dol_print_date(dol_mktime(12, 0, 0, $mois_modulo, 1, 2000), "%B")."</td>";
332 
333  for ($annee = $year_start - 1; $annee <= $year_end; $annee++) // We start one year before to have data to be able to make delta
334  {
335  $annee_decalage = $annee;
336  if ($mois > 12) {$annee_decalage = $annee + 1; }
337  $case = dol_print_date(dol_mktime(1, 1, 1, $mois_modulo, 1, $annee_decalage), "%Y-%m");
338  $caseprev = dol_print_date(dol_mktime(1, 1, 1, $mois_modulo, 1, $annee_decalage - 1), "%Y-%m");
339 
340  if ($annee >= $year_start) // We ignore $annee < $year_start, we loop on it to be able to make delta, nothing is output.
341  {
342  if ($modecompta == 'CREANCES-DETTES') {
343  // Value turnover of month w/o VAT
344  print '<td class="right">';
345  if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) {
346  if ($cum_ht[$case]) {
347  $now_show_delta = 1; // On a trouve le premier mois de la premiere annee generant du chiffre.
348  print '<a href="casoc.php?year='.$annee_decalage.'&month='.$mois_modulo.($modecompta ? '&modecompta='.$modecompta : '').'">'.price($cum_ht[$case], 1).'</a>';
349  } else {
350  if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) { print '0'; } else { print '&nbsp;'; }
351  }
352  }
353  print "</td>";
354  }
355 
356  // Value turnover of month
357  print '<td class="right">';
358  if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) {
359  if ($cum[$case]) {
360  $now_show_delta = 1; // On a trouve le premier mois de la premiere annee generant du chiffre.
361  if ($modecompta != 'BOOKKEEPING') print '<a href="casoc.php?year='.$annee_decalage.'&month='.$mois_modulo.($modecompta ? '&modecompta='.$modecompta : '').'">';
362  print price($cum[$case], 1);
363  if ($modecompta != 'BOOKKEEPING') print '</a>';
364  } else {
365  if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) { print '0'; } else { print '&nbsp;'; }
366  }
367  }
368  print "</td>";
369 
370  // Percentage of month
371  print '<td class="borderrightlight right">';
372  //var_dump($annee.' '.$year_end.' '.$mois.' '.$month_end);
373  if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) {
374  if ($annee_decalage > $minyear && $case <= $casenow)
375  {
376  if ($cum[$caseprev] && $cum[$case])
377  {
378  $percent = (round(($cum[$case] - $cum[$caseprev]) / $cum[$caseprev], 4) * 100);
379  //print "X $cum[$case] - $cum[$caseprev] - $cum[$caseprev] - $percent X";
380  print ($percent >= 0 ? "+$percent" : "$percent").'%';
381  }
382  if ($cum[$caseprev] && !$cum[$case])
383  {
384  print '-100%';
385  }
386  if (!$cum[$caseprev] && $cum[$case])
387  {
388  //print '<td class="right">+Inf%</td>';
389  print '-';
390  }
391  if (isset($cum[$caseprev]) && !$cum[$caseprev] && !$cum[$case])
392  {
393  print '+0%';
394  }
395  if (!isset($cum[$caseprev]) && !$cum[$case])
396  {
397  print '-';
398  }
399  } else {
400  if ($minyearmonth <= $case && $case <= $maxyearmonth) { print '-'; } else { print '&nbsp;'; }
401  }
402  }
403  print '</td>';
404 
405  if ($annee_decalage < $year_end || ($annee_decalage == $year_end && $mois > 12 && $annee < $year_end)) print '<td width="15">&nbsp;</td>';
406  }
407 
408  if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) {
409  $total_ht[$annee] += ((!empty($cum_ht[$case])) ? $cum_ht[$case] : 0);
410  $total[$annee] += $cum[$case];
411  }
412  }
413 
414  print '</tr>';
415 }
416 
417 /*
418  for ($mois = 1 ; $mois < 13 ; $mois++)
419  {
420 
421  print '<tr class="oddeven">';
422 
423  print "<td>".dol_print_date(dol_mktime(12,0,0,$mois,1,2000),"%B")."</td>";
424  for ($annee = $year_start ; $annee <= $year_end ; $annee++)
425  {
426  $casenow = dol_print_date(dol_now(),"%Y-%m");
427  $case = dol_print_date(dol_mktime(1,1,1,$mois,1,$annee),"%Y-%m");
428  $caseprev = dol_print_date(dol_mktime(1,1,1,$mois,1,$annee-1),"%Y-%m");
429 
430  // Valeur CA du mois
431  print '<td class="right">';
432  if ($cum[$case])
433  {
434  $now_show_delta=1; // On a trouve le premier mois de la premiere annee generant du chiffre.
435  print '<a href="casoc.php?year='.$annee.'&month='.$mois.'">'.price($cum[$case],1).'</a>';
436  }
437  else
438  {
439  if ($minyearmonth < $case && $case <= max($maxyearmonth,$nowyearmonth)) { print '0'; }
440  else { print '&nbsp;'; }
441  }
442  print "</td>";
443 
444  // Pourcentage du mois
445  if ($annee > $minyear && $case <= $casenow) {
446  if ($cum[$caseprev] && $cum[$case])
447  {
448  $percent=(round(($cum[$case]-$cum[$caseprev])/$cum[$caseprev],4)*100);
449  //print "X $cum[$case] - $cum[$caseprev] - $cum[$caseprev] - $percent X";
450  print '<td class="right">'.($percent>=0?"+$percent":"$percent").'%</td>';
451 
452  }
453  if ($cum[$caseprev] && ! $cum[$case])
454  {
455  print '<td class="right">-100%</td>';
456  }
457  if (! $cum[$caseprev] && $cum[$case])
458  {
459  print '<td class="right">+Inf%</td>';
460  }
461  if (! $cum[$caseprev] && ! $cum[$case])
462  {
463  print '<td class="right">+0%</td>';
464  }
465  }
466  else
467  {
468  print '<td class="right">';
469  if ($minyearmonth <= $case && $case <= $maxyearmonth) { print '-'; }
470  else { print '&nbsp;'; }
471  print '</td>';
472  }
473 
474  $total[$annee]+=$cum[$case];
475  if ($annee != $year_end) print '<td width="15">&nbsp;</td>';
476  }
477 
478  print '</tr>';
479  }
480  */
481 
482 // Show total
483 print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td>';
484 for ($annee = $year_start; $annee <= $year_end; $annee++)
485 {
486  if ($modecompta == 'CREANCES-DETTES') {
487  // Montant total HT
488  if ($total_ht[$annee] || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) {
489  print '<td class="nowrap right">';
490  print ($total_ht[$annee] ?price($total_ht[$annee]) : "0");
491  print "</td>";
492  } else {
493  print '<td>&nbsp;</td>';
494  }
495  }
496 
497  // Total amount
498  if ($total[$annee] || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) {
499  print '<td class="nowrap right">';
500  print ($total[$annee] ?price($total[$annee]) : "0");
501  print "</td>";
502  } else {
503  print '<td>&nbsp;</td>';
504  }
505 
506  // Pourcentage total
507  if ($annee > $minyear && $annee <= max($nowyear, $maxyear)) {
508  if ($total[$annee - 1] && $total[$annee]) {
509  $percent = (round(($total[$annee] - $total[$annee - 1]) / $total[$annee - 1], 4) * 100);
510  print '<td class="nowrap borderrightlight right">';
511  print ($percent >= 0 ? "+$percent" : "$percent").'%';
512  print '</td>';
513  }
514  if ($total[$annee - 1] && !$total[$annee])
515  {
516  print '<td class="borderrightlight right">-100%</td>';
517  }
518  if (!$total[$annee - 1] && $total[$annee])
519  {
520  print '<td class="borderrightlight right">+'.$langs->trans('Inf').'%</td>';
521  }
522  if (!$total[$annee - 1] && !$total[$annee])
523  {
524  print '<td class="borderrightlight right">+0%</td>';
525  }
526  } else {
527  print '<td class="borderrightlight right">';
528  if ($total[$annee] || ($minyear <= $annee && $annee <= max($nowyear, $maxyear))) { print '-'; } else { print '&nbsp;'; }
529  print '</td>';
530  }
531 
532  if ($annee != $year_end) print '<td width="15">&nbsp;</td>';
533 }
534 print "</tr>\n";
535 print "</table>";
536 print '</div>';
537 
538 
539 /*
540  * En mode recettes/depenses, on complete avec les montants factures non regles
541  * et les propales signees mais pas facturees. En effet, en recettes-depenses,
542  * on comptabilise lorsque le montant est sur le compte donc il est interessant
543  * d'avoir une vision de ce qui va arriver.
544  */
545 
546 /*
547  Je commente toute cette partie car les chiffres affichees sont faux - Eldy.
548  En attendant correction.
549 
550  if ($modecompta != 'CREANCES-DETTES')
551  {
552 
553  print '<br><table width="100%" class="noborder">';
554 
555  // Factures non reglees
556  // Y a bug ici. Il faut prendre le reste a payer et non le total des factures non reglees !
557 
558  $sql = "SELECT f.ref, f.rowid, s.nom, s.rowid as socid, f.total_ttc, sum(pf.amount) as am";
559  $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";
560  $sql .= " WHERE s.rowid = f.fk_soc AND f.paye = 0 AND f.fk_statut = 1";
561  if ($socid)
562  {
563  $sql .= " AND f.fk_soc = $socid";
564  }
565  $sql .= " GROUP BY f.ref,f.rowid,s.nom, s.rowid, f.total_ttc";
566 
567  $resql=$db->query($sql);
568  if ($resql)
569  {
570  $num = $db->num_rows($resql);
571  $i = 0;
572 
573  if ($num)
574  {
575  $total_ttc_Rac = $totalam_Rac = $total_Rac = 0;
576  while ($i < $num)
577  {
578  $obj = $db->fetch_object($resql);
579  $total_ttc_Rac += $obj->total_ttc;
580  $totalam_Rac += $obj->am;
581  $i++;
582  }
583 
584  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>";
585  }
586  $db->free($resql);
587  }
588  else
589  {
590  dol_print_error($db);
591  }
592  */
593 
594 /*
595  *
596  * Propales signees, et non facturees
597  *
598  */
599 
600 /*
601  Je commente toute cette partie car les chiffres affichees sont faux - Eldy.
602  En attendant correction.
603 
604  $sql = "SELECT sum(f.total) 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
605  FROM ".MAIN_DB_PREFIX."commande AS p, ".MAIN_DB_PREFIX."societe AS s
606  LEFT JOIN ".MAIN_DB_PREFIX."co_fa AS co_fa ON co_fa.fk_commande = p.rowid
607  LEFT JOIN ".MAIN_DB_PREFIX."facture AS f ON co_fa.fk_facture = f.rowid
608  WHERE p.fk_soc = s.rowid
609  AND p.fk_statut >=1
610  AND p.facture =0";
611  if ($socid)
612  {
613  $sql .= " AND f.fk_soc = ".$socid;
614  }
615  $sql .= " GROUP BY p.rowid";
616 
617  $resql=$db->query($sql);
618  if ($resql)
619  {
620  $num = $db->num_rows($resql);
621  $i = 0;
622 
623  if ($num)
624  {
625  $total_pr = 0;
626  while ($i < $num)
627  {
628  $obj = $db->fetch_object($resql);
629  $total_pr += $obj->total_ttc-$obj->tot_fttc;
630  $i++;
631  }
632 
633  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>";
634  }
635  $db->free($resql);
636  }
637  else
638  {
639  dol_print_error($db);
640  }
641  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>";
642  }
643  print "</table>";
644 
645  */
646 
647 // End of page
648 llxFooter();
649 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm= 'auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
dol_now($mode= 'auto')
Return date for now.
report_header($reportname, $notused, $period, $periodlink, $description, $builddate, $exportlink= '', $moreparam=array(), $calcmode= '', $varlink= '')
Show header of a report.
Definition: report.lib.php:41
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition: date.lib.php:481
price($amount, $form=0, $outlangs= '', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code= '')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
dol_getdate($timestamp, $fast=false, $forcetimezone= '')
Return an array with locale date info.
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
print $_SERVER["PHP_SELF"]
Edit parameters.
img_next($titlealt= 'default', $moreatt= '')
Show next logo.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition: date.lib.php:498
print
Draft customers invoices.
Definition: index.php:89
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...
llxFooter()
Empty footer.
Definition: wrapper.php:59
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin= '1', $morecss= '', $textfordropdown= '')
Show information for admin users or standard users.