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