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