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