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