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