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