dolibarr 21.0.0-alpha
supplier_turnover.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2020 Maxime Kohlhaas <maxime@atm-consulting.fr>
3 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
24// Load Dolibarr environment
25require '../../main.inc.php';
26require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
27require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
28
29// Load translation files required by the page
30$langs->loadLangs(array('compta', 'bills'));
31
32$date_startday = GETPOSTINT('date_startday');
33$date_startmonth = GETPOSTINT('date_startmonth');
34$date_startyear = GETPOSTINT('date_startyear');
35$date_endday = GETPOSTINT('date_endday');
36$date_endmonth = GETPOSTINT('date_endmonth');
37$date_endyear = GETPOSTINT('date_endyear');
38
39$nbofyear = 4;
40
41// Date range
42$year = GETPOSTINT('year');
43if (empty($year)) {
44 $year_current = (int) dol_print_date(dol_now(), "%Y");
45 $month_current = (int) dol_print_date(dol_now(), "%m");
46 $year_start = $year_current - ($nbofyear - 1);
47} else {
48 $year_current = $year;
49 $month_current = (int) dol_print_date(dol_now(), "%m");
50 $year_start = $year - $nbofyear + (getDolGlobalInt('SOCIETE_FISCAL_MONTH_START') > 1 ? 0 : 1);
51}
52$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
53$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
54
55// We define date_start and date_end
56if (empty($date_start) || empty($date_end)) { // We define date_start and date_end
57 $q = GETPOSTINT("q");
58 if (empty($q)) {
59 // We define date_start and date_end
60 $year_end = $year_start + $nbofyear - (getDolGlobalInt('SOCIETE_FISCAL_MONTH_START') > 1 ? 0 : 1);
61 $month_start = GETPOSTISSET("month") ? GETPOSTINT("month") : getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1);
62 if (!GETPOST('month')) { // If month not forced
63 if (!$year && $month_start > $month_current) {
64 $year_start--;
65 $year_end--;
66 }
67 $month_end = $month_start - 1;
68 if ($month_end < 1) {
69 $month_end = 12;
70 }
71 } else {
72 $month_end = $month_start;
73 }
74 $date_start = dol_get_first_day($year_start, $month_start, false);
75 $date_end = dol_get_last_day($year_end, $month_end, false);
76 }
77 if ($q == 1) {
78 $date_start = dol_get_first_day($year_start, 1, false);
79 $date_end = dol_get_last_day($year_start, 3, false);
80 }
81 if ($q == 2) {
82 $date_start = dol_get_first_day($year_start, 4, false);
83 $date_end = dol_get_last_day($year_start, 6, false);
84 }
85 if ($q == 3) {
86 $date_start = dol_get_first_day($year_start, 7, false);
87 $date_end = dol_get_last_day($year_start, 9, false);
88 }
89 if ($q == 4) {
90 $date_start = dol_get_first_day($year_start, 10, false);
91 $date_end = dol_get_last_day($year_start, 12, false);
92 }
93}
94
95$userid = GETPOSTINT('userid');
96$socid = GETPOSTINT('socid');
97
98$tmps = dol_getdate($date_start);
99$month_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 = getDolGlobalString('ACCOUNTING_MODE');
108if (isModEnabled('accounting')) {
109 $modecompta = 'BOOKKEEPING';
110}
111if (GETPOST("modecompta", 'alpha')) {
112 $modecompta = GETPOST("modecompta", 'alpha');
113}
114
115// Security check
116if ($user->socid > 0) {
117 $socid = $user->socid;
118}
119if (isModEnabled('comptabilite')) {
120 $result = restrictedArea($user, 'compta', '', '', 'resultat');
121}
122if (isModEnabled('accounting')) {
123 $result = restrictedArea($user, 'accounting', '', '', 'comptarapport');
124}
125
126
127/*
128 * View
129 */
130
131llxHeader();
132
133$form = new Form($db);
134
135$exportlink = '';
136$namelink = '';
137$builddate = dol_now();
138
139// TODO Report from bookkeeping not yet available, so we switch on report on business events
140/*if ($modecompta == "BOOKKEEPING") {
141 $modecompta = "CREANCES-DETTES";
142}*/
143if ($modecompta == "BOOKKEEPINGCOLLECTED") {
144 $modecompta = "RECETTES-DEPENSES";
145}
146
147// Affiche en-tete du rapport
148if ($modecompta == "CREANCES-DETTES") {
149 $name = $langs->trans("PurchaseTurnover");
150 $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>" : "");
151 $description = $langs->trans("RulesPurchaseTurnoverDue");
152 //$exportlink=$langs->trans("NotYetAvailable");
153} elseif ($modecompta == "RECETTES-DEPENSES") {
154 $name = $langs->trans("PurchaseTurnoverCollected");
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("RulesPurchaseTurnoverIn");
157 //$exportlink=$langs->trans("NotYetAvailable");
158} elseif ($modecompta == "BOOKKEEPING") {
159 $name = $langs->trans("PurchaseTurnover");
160 $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>" : "");
161 $description = $langs->trans("RulesPurchaseTurnoverOfExpenseAccounts");
162 //$exportlink=$langs->trans("NotYetAvailable");
163} elseif ($modecompta == "BOOKKEEPINGCOLLECTED") {
164 $name = $langs->trans("PurchaseTurnoverCollected");
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("RulesPurchaseTurnoverCollectedOfExpenseAccounts");
167 //$exportlink=$langs->trans("NotYetAvailable");
168}
169
170$period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0, 0, '', '', '', '', 1, '', '', 'tzserver');
171$period .= ' - ';
172$period .= $form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0, 0, '', '', '', '', 1, '', '', 'tzserver');
173
174$moreparam = array();
175if (!empty($modecompta)) {
176 $moreparam['modecompta'] = $modecompta;
177}
178
179// Define $calcmode line
180$calcmode = '';
181if ($modecompta == "RECETTES-DEPENSES" || $modecompta == "BOOKKEEPINGCOLLECTED") {
182 /*if (isModEnabled('accounting')) {
183 $calcmode .= '<input type="radio" name="modecompta" id="modecompta3" value="BOOKKEEPINGCOLLECTED"'.($modecompta == 'BOOKKEEPINGCOLLECTED' ? ' checked="checked"' : '').'><label for="modecompta3"> '.$langs->trans("CalcModeBookkeeping").'</label>';
184 $calcmode .= '<br>';
185 }*/
186 $calcmode .= '<input type="radio" name="modecompta" id="modecompta2" value="RECETTES-DEPENSES"'.($modecompta == 'RECETTES-DEPENSES' ? ' checked="checked"' : '').'><label for="modecompta2"> '.$langs->trans("CalcModePayment");
187 if (isModEnabled('accounting')) {
188 $calcmode .= ' <span class="opacitymedium hideonsmartphone">('.$langs->trans("CalcModeNoBookKeeping").')</span>';
189 }
190 $calcmode .= '</label>';
191} else {
192 if (isModEnabled('accounting')) {
193 $calcmode .= '<input type="radio" name="modecompta" id="modecompta3" value="BOOKKEEPING"'.($modecompta == 'BOOKKEEPING' ? ' checked="checked"' : '').'><label for="modecompta3"> '.$langs->trans("CalcModeBookkeeping").'</label>';
194 $calcmode .= ' <span class="opacitymedium hideonsmartphone">('.$langs->trans("DataMustHaveBeenTransferredInAccounting").')</span>';
195 $calcmode .= '<br>';
196 }
197 $calcmode .= '<input type="radio" name="modecompta" id="modecompta2" value="CREANCES-DETTES"'.($modecompta == 'CREANCES-DETTES' ? ' checked="checked"' : '').'><label for="modecompta2"> '.$langs->trans("CalcModeDebt");
198 if (isModEnabled('accounting')) {
199 $calcmode .= ' <span class="opacitymedium hideonsmartphone">('.$langs->trans("CalcModeNoBookKeeping").')</span>';
200 }
201 $calcmode .= '</label>';
202}
203
204
205report_header($name, $namelink, $period, $periodlink, $description, $builddate, $exportlink, $moreparam, $calcmode);
206
207if (isModEnabled('accounting')) {
208 if ($modecompta != 'BOOKKEEPING') {
209 print info_admin($langs->trans("WarningReportNotReliable"), 0, 0, '1');
210 } else {
211 // Test if there is at least one line in bookkeeping
212 $pcgverid = getDolGlobalInt('CHARTOFACCOUNTS');
213 $pcgvercode = dol_getIdFromCode($db, $pcgverid, 'accounting_system', 'rowid', 'pcg_version');
214 if (empty($pcgvercode)) {
215 $pcgvercode = $pcgverid;
216 }
217
218 $sql = "SELECT b.rowid ";
219 $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as b,";
220 $sql .= " ".MAIN_DB_PREFIX."accounting_account as aa";
221 $sql .= " WHERE b.entity = ".$conf->entity; // In module double party accounting, we never share entities
222 $sql .= " AND b.numero_compte = aa.account_number";
223 $sql .= " AND aa.entity = ".$conf->entity;
224 $sql .= " AND aa.fk_pcg_version = '".$db->escape($pcgvercode)."'";
225 $sql .= $db->plimit(1);
226
227 $resql = $db->query($sql);
228 $nb = $db->num_rows($resql);
229 if ($nb == 0) {
230 $langs->load("errors");
231 print info_admin($langs->trans("WarningNoDataTransferedInAccountancyYet"), 0, 0, '1');
232 }
233 }
234}
235
236
237if ($modecompta == 'CREANCES-DETTES') {
238 $sql = "SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total_ht) as amount, sum(f.total_ttc) as amount_ttc";
239 $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
240 $sql .= " WHERE f.fk_statut in (1,2)";
241 $sql .= " AND f.type IN (0,2)";
242 $sql .= " AND f.entity IN (".getEntity('supplier_invoice').")";
243 if ($socid) {
244 $sql .= " AND f.fk_soc = ".((int) $socid);
245 }
246} elseif ($modecompta == "RECETTES-DEPENSES") {
247 $sql = "SELECT date_format(p.datep,'%Y-%m') as dm, sum(pf.amount) as amount_ttc";
248 $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
249 $sql .= ", ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf";
250 $sql .= ", ".MAIN_DB_PREFIX."paiementfourn as p";
251 $sql .= " WHERE p.rowid = pf.fk_paiementfourn";
252 $sql .= " AND pf.fk_facturefourn = f.rowid";
253 $sql .= " AND f.entity IN (".getEntity('supplier_invoice').")";
254 if ($socid) {
255 $sql .= " AND f.fk_soc = ".((int) $socid);
256 }
257} elseif ($modecompta == "BOOKKEEPING") {
258 $pcgverid = getDolGlobalInt('CHARTOFACCOUNTS');
259 $pcgvercode = dol_getIdFromCode($db, $pcgverid, 'accounting_system', 'rowid', 'pcg_version');
260 if (empty($pcgvercode)) {
261 $pcgvercode = $pcgverid;
262 }
263
264 $sql = "SELECT date_format(b.doc_date, '%Y-%m') as dm, sum(b.debit - b.credit) as amount_ttc";
265 $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as b,";
266 $sql .= " ".MAIN_DB_PREFIX."accounting_account as aa";
267 $sql .= " WHERE b.entity = ".$conf->entity; // In module double party accounting, we never share entities
268 $sql .= " AND b.doc_type = 'supplier_invoice'";
269 $sql .= " AND b.numero_compte = aa.account_number";
270 $sql .= " AND aa.entity = ".$conf->entity;
271 $sql .= " AND aa.fk_pcg_version = '".$db->escape($pcgvercode)."'";
272 $sql .= " AND aa.pcg_type = 'EXPENSE'"; // TODO Be able to use a custom group
273}
274$sql .= " GROUP BY dm";
275$sql .= " ORDER BY dm";
276// TODO Add a filter on $date_start and $date_end to reduce quantity on data
277//print $sql;
278
279$minyearmonth = $maxyearmonth = 0;
280
281$cumulative = array();
282$cumulative_ht = array();
283$total_ht = array();
284$total = array();
285
286$result = $db->query($sql);
287if ($result) {
288 $num = $db->num_rows($result);
289 $i = 0;
290 while ($i < $num) {
291 $obj = $db->fetch_object($result);
292 $cumulative_ht[$obj->dm] = empty($obj->amount) ? 0 : $obj->amount;
293 $cumulative[$obj->dm] = empty($obj->amount_ttc) ? 0 : $obj->amount_ttc;
294 if ($obj->amount_ttc) {
295 $minyearmonth = ($minyearmonth ? min($minyearmonth, $obj->dm) : $obj->dm);
296 $maxyearmonth = max($maxyearmonth, $obj->dm);
297 }
298 $i++;
299 }
300 $db->free($result);
301} else {
302 dol_print_error($db);
303}
304
305$moreforfilter = '';
306
307print '<div class="div-table-responsive">';
308print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
309
310print '<tr class="liste_titre"><td>&nbsp;</td>';
311
312for ($annee = $year_start; $annee <= $year_end; $annee++) {
313 if ($modecompta == 'CREANCES-DETTES') {
314 print '<td align="center" width="10%" colspan="3">';
315 } else {
316 print '<td align="center" width="10%" colspan="2" class="borderrightlight">';
317 }
318 if ($modecompta != 'BOOKKEEPING') {
319 print '<a href="supplier_turnover_by_thirdparty.php?year='.$annee.($modecompta ? '&modecompta='.$modecompta : '').'">';
320 }
321 print $annee;
322 if (getDolGlobalInt('SOCIETE_FISCAL_MONTH_START') > 1) {
323 print '-'.($annee + 1);
324 }
325 if ($modecompta != 'BOOKKEEPING') {
326 print '</a>';
327 }
328 print '</td>';
329 if ($annee != $year_end) {
330 print '<td width="15">&nbsp;</td>';
331 }
332}
333print '</tr>';
334
335print '<tr class="liste_titre"><td class="liste_titre">'.$langs->trans("Month").'</td>';
336for ($annee = $year_start; $annee <= $year_end; $annee++) {
337 if ($modecompta == 'CREANCES-DETTES') {
338 print '<td class="liste_titre right">'.$langs->trans("AmountHT").'</td>';
339 }
340 print '<td class="liste_titre right">';
341 if ($modecompta == "BOOKKEEPING") {
342 print $langs->trans("Amount");
343 } else {
344 print $langs->trans("AmountTTC");
345 }
346 print '</td>';
347 print '<td class="liste_titre right borderrightlight">'.$langs->trans("Delta").'</td>';
348 if ($annee != $year_end) {
349 print '<td class="liste_titre" width="15">&nbsp;</td>';
350 }
351}
352print '</tr>';
353
354$now_show_delta = 0;
355$minyear = substr($minyearmonth, 0, 4);
356$maxyear = substr($maxyearmonth, 0, 4);
357$nowyear = dol_print_date(dol_now('gmt'), "%Y", 'gmt');
358$nowyearmonth = dol_print_date(dol_now(), "%Y-%m");
359$maxyearmonth = max($maxyearmonth, $nowyearmonth);
360$now = dol_now();
361$casenow = dol_print_date($now, "%Y-%m");
362
363// Loop on each month
364$nb_mois_decalage = GETPOSTISSET('date_startmonth') ? (GETPOSTINT('date_startmonth') - 1) : (!getDolGlobalInt('SOCIETE_FISCAL_MONTH_START') ? 0 : (getDolGlobalInt('SOCIETE_FISCAL_MONTH_START') - 1));
365for ($mois = 1 + $nb_mois_decalage; $mois <= 12 + $nb_mois_decalage; $mois++) {
366 $mois_modulo = $mois; // ajout
367 if ($mois > 12) {
368 $mois_modulo = $mois - 12;
369 } // ajout
370
371 if ($year_start == $year_end) {
372 if ($mois > $date_endmonth && $year_end >= $date_endyear) {
373 break;
374 }
375 }
376
377 print '<tr class="oddeven">';
378
379 // Month
380 print "<td>".dol_print_date(dol_mktime(12, 0, 0, $mois_modulo, 1, 2000), "%B")."</td>";
381
382 for ($annee = $year_start - 1; $annee <= $year_end; $annee++) { // We start one year before to have data to be able to make delta
383 $annee_decalage = $annee;
384 if ($mois > 12) {
385 $annee_decalage = $annee + 1;
386 }
387 $case = dol_print_date(dol_mktime(1, 1, 1, $mois_modulo, 1, $annee_decalage), "%Y-%m");
388 $caseprev = dol_print_date(dol_mktime(1, 1, 1, $mois_modulo, 1, $annee_decalage - 1), "%Y-%m");
389
390 if ($annee >= $year_start) { // We ignore $annee < $year_start, we loop on it to be able to make delta, nothing is output.
391 if ($modecompta == 'CREANCES-DETTES') {
392 // Value turnover of month w/o VAT
393 print '<td class="right">';
394 if (!empty($cumulative_ht[$case])) {
395 $now_show_delta = 1; // On a trouve le premier mois de la premiere annee generant du chiffre.
396 print '<a href="supplier_turnover_by_thirdparty.php?year='.$annee_decalage.'&month='.$mois_modulo.($modecompta ? '&modecompta='.$modecompta : '').'">'.price($cumulative_ht[$case], 1).'</a>';
397 } else {
398 if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) {
399 print '0';
400 } else {
401 print '&nbsp;';
402 }
403 }
404 print "</td>";
405 }
406
407 // Value turnover of month
408 print '<td class="right">';
409 if (!empty($cumulative[$case])) {
410 $now_show_delta = 1; // On a trouve le premier mois de la premiere annee generant du chiffre.
411 if ($modecompta != 'BOOKKEEPING') {
412 print '<a href="supplier_turnover_by_thirdparty.php?year='.$annee_decalage.'&month='.$mois_modulo.($modecompta ? '&modecompta='.$modecompta : '').'">';
413 }
414 print price($cumulative[$case], 1);
415 if ($modecompta != 'BOOKKEEPING') {
416 print '</a>';
417 }
418 } else {
419 if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) {
420 print '0';
421 } else {
422 print '&nbsp;';
423 }
424 }
425 print "</td>";
426
427 // Percentage of month
428 if ($annee_decalage > $minyear && $case <= $casenow) {
429 if (!empty($cumulative[$caseprev]) && !empty($cumulative[$case])) {
430 $percent = (round(($cumulative[$case] - $cumulative[$caseprev]) / $cumulative[$caseprev], 4) * 100);
431 //print "X $cumulative[$case] - $cumulative[$caseprev] - $cumulative[$caseprev] - $percent X";
432 print '<td class="borderrightlight right">'.($percent >= 0 ? "+$percent" : "$percent").'%</td>';
433 }
434 if (!empty($cumulative[$caseprev]) && empty($cumulative[$case])) {
435 print '<td class="borderrightlight right">-100%</td>';
436 }
437 if (empty($cumulative[$caseprev]) && !empty($cumulative[$case])) {
438 //print '<td class="right">+Inf%</td>';
439 print '<td class="borderrightlight right">-</td>';
440 }
441 if (isset($cumulative[$caseprev]) && empty($cumulative[$caseprev]) && empty($cumulative[$case])) {
442 print '<td class="borderrightlight right">+0%</td>';
443 }
444 if (!isset($cumulative[$caseprev]) && empty($cumulative[$case])) {
445 print '<td class="borderrightlight right">-</td>';
446 }
447 } else {
448 print '<td class="borderrightlight right">';
449 if ($minyearmonth <= $case && $case <= $maxyearmonth) {
450 print '-';
451 } else {
452 print '&nbsp;';
453 }
454 print '</td>';
455 }
456
457 if ($annee_decalage < $year_end || ($annee_decalage == $year_end && $mois > 12 && $annee < $year_end)) {
458 print '<td width="15">&nbsp;</td>';
459 }
460 }
461
462 if (empty($total_ht[$annee])) {
463 $total_ht[$annee] = ((!empty($cumulative_ht[$case])) ? $cumulative_ht[$case] : 0);
464 } else {
465 $total_ht[$annee] += ((!empty($cumulative_ht[$case])) ? $cumulative_ht[$case] : 0);
466 }
467 if (empty($total[$annee])) {
468 $total[$annee] = (empty($cumulative[$case]) ? 0 : $cumulative[$case]);
469 } else {
470 $total[$annee] += (empty($cumulative[$case]) ? 0 : $cumulative[$case]);
471 }
472 }
473
474 print '</tr>';
475}
476
477// Affiche total
478print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td>';
479for ($annee = $year_start; $annee <= $year_end; $annee++) {
480 if ($modecompta == 'CREANCES-DETTES') {
481 // Montant total HT
482 if ($total_ht[$annee] || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) {
483 print '<td class="nowrap right">';
484 print($total_ht[$annee] ? price($total_ht[$annee]) : "0");
485 print "</td>";
486 } else {
487 print '<td>&nbsp;</td>';
488 }
489 }
490
491 // Montant total
492 if ($total[$annee] || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) {
493 print '<td class="nowrap right">'.($total[$annee] ? price($total[$annee]) : "0")."</td>";
494 } else {
495 print '<td>&nbsp;</td>';
496 }
497
498 // Pourcentage total
499 if ($annee > $minyear && $annee <= max($nowyear, $maxyear)) {
500 if ($total[$annee - 1] && $total[$annee]) {
501 $percent = (round(($total[$annee] - $total[$annee - 1]) / $total[$annee - 1], 4) * 100);
502 print '<td class="nowrap borderrightlight right">';
503 print($percent >= 0 ? "+$percent" : "$percent").'%';
504 print '</td>';
505 }
506 if (!empty($total[$annee - 1]) && empty($total[$annee])) {
507 print '<td class="borderrightlight right">-100%</td>';
508 }
509 if (empty($total[$annee - 1]) && !empty($total[$annee])) {
510 print '<td class="borderrightlight right">+'.$langs->trans('Inf').'%</td>';
511 }
512 if (empty($total[$annee - 1]) && empty($total[$annee])) {
513 print '<td class="borderrightlight right">+0%</td>';
514 }
515 } else {
516 print '<td class="borderrightlight right">';
517 if (!empty($total[$annee]) || ($minyear <= $annee && $annee <= max($nowyear, $maxyear))) {
518 print '-';
519 } else {
520 print '&nbsp;';
521 }
522 print '</td>';
523 }
524
525 if ($annee != $year_end) {
526 print '<td width="15">&nbsp;</td>';
527 }
528}
529print "</tr>\n";
530print "</table>";
531print '</div>';
532
533// End of page
534llxFooter();
535$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:70
Class to manage generation of HTML components Only common components must be here.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition date.lib.php:596
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition date.lib.php:615
llxFooter()
Footer empty.
Definition document.php:107
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.
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.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
report_header($reportname, $notused, $period, $periodlink, $description, $builddate, $exportlink='', $moreparam=array(), $calcmode='', $varlink='')
Show header of a report.
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.