dolibarr 24.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-2026 Frédéric France <frederic.france@free.fr>
7 * Copyright (C) 2024 Benjamin B. <b.crozon@trebisol.com>
8 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
29// Load Dolibarr environment
30require '../../main.inc.php';
39require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
40require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
41
42// Load translation files required by the page
43$langs->loadLangs(array('compta', 'bills', 'donation', 'salaries'));
44
45$date_startday = GETPOSTINT('date_startday');
46$date_startmonth = GETPOSTINT('date_startmonth');
47$date_startyear = GETPOSTINT('date_startyear');
48$date_endday = GETPOSTINT('date_endday');
49$date_endmonth = GETPOSTINT('date_endmonth');
50$date_endyear = GETPOSTINT('date_endyear');
51
52$nbofyear = 4;
53
54// Date range
55$year = GETPOSTINT('year');
56if (empty($year)) {
57 $year_current = (int) dol_print_date(dol_now(), "%Y");
58 $month_current = (int) dol_print_date(dol_now(), "%m");
59 $year_start = $year_current - ($nbofyear - 1);
60} else {
61 $year_current = $year;
62 $month_current = (int) dol_print_date(dol_now(), "%m");
63 $year_start = $year - $nbofyear + (getDolGlobalInt('SOCIETE_FISCAL_MONTH_START') > 1 ? 0 : 1);
64}
65$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
66$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
67
68// We define date_start and date_end
69if (empty($date_start) || empty($date_end)) { // We define date_start and date_end
70 $q = GETPOSTINT("q");
71 if (empty($q)) {
72 // We define date_start and date_end
73 $year_end = $year_start + $nbofyear - (getDolGlobalInt('SOCIETE_FISCAL_MONTH_START') > 1 ? 0 : 1);
74 $month_start = GETPOSTISSET("month") ? GETPOSTINT("month") : getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1);
75 if (!GETPOST('month')) { // If month not forced
76 if (!$year && $month_start > $month_current) {
77 $year_start--;
78 $year_end--;
79 }
80 $month_end = $month_start - 1;
81 if ($month_end < 1) {
82 $month_end = 12;
83 }
84 } else {
85 $month_end = $month_start;
86 }
87 $date_start = dol_get_first_day($year_start, $month_start, false);
88 $date_end = dol_get_last_day($year_end, $month_end, false);
89 }
90 if ($q == 1) {
91 $date_start = dol_get_first_day($year_start, 1, false);
92 $date_end = dol_get_last_day($year_start, 3, false);
93 }
94 if ($q == 2) {
95 $date_start = dol_get_first_day($year_start, 4, false);
96 $date_end = dol_get_last_day($year_start, 6, false);
97 }
98 if ($q == 3) {
99 $date_start = dol_get_first_day($year_start, 7, false);
100 $date_end = dol_get_last_day($year_start, 9, false);
101 }
102 if ($q == 4) {
103 $date_start = dol_get_first_day($year_start, 10, false);
104 $date_end = dol_get_last_day($year_start, 12, false);
105 }
106}
107
108$userid = GETPOSTINT('userid');
109$socid = GETPOSTINT('socid');
110
111$tmps = dol_getdate($date_start);
112$month_start = $tmps['mon'];
113$year_start = $tmps['year'];
114$tmpe = dol_getdate($date_end);
115$month_end = $tmpe['mon'];
116$year_end = $tmpe['year'];
117$nbofyear = ($year_end - $year_start) + 1;
118
119// Define modecompta ('CREANCES-DETTES' or 'RECETTES-DEPENSES' or 'BOOKKEEPING')
120$modecompta = getDolGlobalString('ACCOUNTING_MODE');
121if (isModEnabled('accounting')) {
122 $modecompta = 'BOOKKEEPING';
123}
124if (GETPOST("modecompta", 'alpha')) {
125 $modecompta = GETPOST("modecompta", 'alpha');
126}
127
128// Security check
129if ($user->socid > 0) {
130 $socid = $user->socid;
131}
132if (isModEnabled('comptabilite')) {
133 $result = restrictedArea($user, 'compta', '', '', 'resultat');
134}
135if (isModEnabled('accounting')) {
136 $result = restrictedArea($user, 'accounting', '', '', 'comptarapport');
137}
138
139
140
141
142/*
143 * View
144 */
145
146$param = '';
147if ($date_startday && $date_startmonth && $date_startyear) {
148 $param .= '&date_startday='.$date_startday.'&date_startmonth='.$date_startmonth.'&date_startyear='.$date_startyear;
149}
150if ($date_endday && $date_endmonth && $date_endyear) {
151 $param .= '&date_endday='.$date_endday.'&date_endmonth='.$date_endmonth.'&date_endyear='.$date_endyear;
152}
153
154llxHeader();
155
156$form = new Form($db);
157
158$exportlink = '';
159$namelink = '';
160$builddate = dol_now();
161$periodlink = '';
162$description = '';
163$name = '';
164
165// Display report header
166if ($modecompta == "CREANCES-DETTES") {
167 $name = $langs->trans("Turnover");
168 $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>" : "");
169 $description = $langs->trans("RulesCADue");
170 if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) {
171 $description .= $langs->trans("DepositsAreNotIncluded");
172 } else {
173 $description .= $langs->trans("DepositsAreIncluded");
174 }
175 //$exportlink=$langs->trans("NotYetAvailable");
176} elseif ($modecompta == "RECETTES-DEPENSES") {
177 $name = $langs->trans("TurnoverCollected");
178 $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>" : "");
179 $description = $langs->trans("RulesCAIn");
180 $description .= $langs->trans("DepositsAreIncluded");
181 //$exportlink=$langs->trans("NotYetAvailable");
182} elseif ($modecompta == "BOOKKEEPING") {
183 $name = $langs->trans("Turnover");
184 $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>" : "");
185 $description = $langs->trans("RulesSalesTurnoverOfIncomeAccounts");
186 //$exportlink=$langs->trans("NotYetAvailable");
187}
188$period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0, 0, '', '', '', '', 1, '', '', 'tzserver');
189$period .= ' - ';
190$period .= $form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0, 0, '', '', '', '', 1, '', '', 'tzserver');
191
192$moreparam = array();
193if (!empty($modecompta)) {
194 $moreparam['modecompta'] = $modecompta;
195}
196
197// Define $calcmode line
198$calcmode = '';
199if ($modecompta == "RECETTES-DEPENSES" || $modecompta == "BOOKKEEPINGCOLLECTED") {
200 /*if (isModEnabled('accounting')) {
201 $calcmode .= '<input type="radio" name="modecompta" id="modecompta3" value="BOOKKEEPINGCOLLECTED"'.($modecompta == 'BOOKKEEPINGCOLLECTED' ? ' checked="checked"' : '').'><label for="modecompta3"> '.$langs->trans("CalcModeBookkeeping").'</label>';
202 $calcmode .= '<br>';
203 }*/
204 $calcmode .= '<input type="radio" name="modecompta" id="modecompta2" value="RECETTES-DEPENSES"'.($modecompta == 'RECETTES-DEPENSES' ? ' checked="checked"' : '').'><label for="modecompta2"> '.$langs->trans("CalcModePayment");
205 if (isModEnabled('accounting')) {
206 $calcmode .= ' <span class="opacitymedium hideonsmartphone">('.$langs->trans("CalcModeNoBookKeeping").')</span>';
207 }
208 $calcmode .= '</label>';
209} else {
210 if (isModEnabled('accounting')) {
211 $calcmode .= '<input type="radio" name="modecompta" id="modecompta3" value="BOOKKEEPING"'.($modecompta == 'BOOKKEEPING' ? ' checked="checked"' : '').'><label for="modecompta3"> '.$langs->trans("CalcModeBookkeeping").'</label>';
212 $calcmode .= ' <span class="opacitymedium hideonsmartphone">('.$langs->trans("DataMustHaveBeenTransferredInAccounting").')</span>';
213 $calcmode .= '<br>';
214 }
215 $calcmode .= '<input type="radio" name="modecompta" id="modecompta2" value="CREANCES-DETTES"'.($modecompta == 'CREANCES-DETTES' ? ' checked="checked"' : '').'><label for="modecompta2"> '.$langs->trans("CalcModeDebt");
216 if (isModEnabled('accounting')) {
217 $calcmode .= ' <span class="opacitymedium hideonsmartphone">('.$langs->trans("CalcModeNoBookKeeping").')</span>';
218 }
219 $calcmode .= '</label>';
220}
221
222report_header($name, $namelink, $period, $periodlink, $description, $builddate, $exportlink, $moreparam, $calcmode);
223$sql = '';
224
225if (isModEnabled('accounting')) {
226 if ($modecompta != 'BOOKKEEPING') {
227 print info_admin($langs->trans("WarningReportNotReliable"), 0, 0, '1');
228 } else {
229 // Test if there is at least one line in bookkeeping
230 $pcgverid = getDolGlobalInt('CHARTOFACCOUNTS');
231 $pcgvercode = dol_getIdFromCode($db, $pcgverid, 'accounting_system', 'rowid', 'pcg_version');
232 if (empty($pcgvercode)) {
233 $pcgvercode = $pcgverid;
234 }
235
236 $sql = "SELECT b.rowid ";
237 $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as b,";
238 $sql .= " ".MAIN_DB_PREFIX."accounting_account as aa";
239 $sql .= " WHERE b.entity = ".$conf->entity; // In module double party accounting, we never share entities
240 $sql .= " AND b.numero_compte = aa.account_number";
241 $sql .= " AND aa.entity = ".$conf->entity;
242 $sql .= " AND aa.fk_pcg_version = '".$db->escape($pcgvercode)."'";
243 $sql .= $db->plimit(1);
244
245 $resql = $db->query($sql);
246 $nb = $db->num_rows($resql);
247 if ($nb == 0) {
248 $langs->load("errors");
249 print info_admin($langs->trans("WarningNoDataTransferedInAccountancyYet"), 0, 0, '1');
250 }
251 }
252}
253
254
255if ($modecompta == 'CREANCES-DETTES') {
256 $sql = "SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total_ht) as amount, sum(f.total_ttc) as amount_ttc";
257 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
258 $sql .= " WHERE f.fk_statut in (1,2)";
259 if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) {
260 $sql .= " AND f.type IN (0,1,2,5)";
261 } else {
262 $sql .= " AND f.type IN (0,1,2,3,5)";
263 }
264 $sql .= " AND f.entity IN (".getEntity('invoice').")";
265 if ($socid) {
266 $sql .= " AND f.fk_soc = ".((int) $socid);
267 }
268} elseif ($modecompta == "RECETTES-DEPENSES") {
269 /*
270 * Liste des paiements (les anciens paiements ne sont pas vus par cette requete car, sur les
271 * vieilles versions, ils n'etaient pas lies via paiement_facture. On les ajoute plus loin)
272 */
273 $sql = "SELECT date_format(p.datep, '%Y-%m') as dm, sum(pf.amount) as amount_ttc";
274 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
275 $sql .= ", ".MAIN_DB_PREFIX."paiement_facture as pf";
276 $sql .= ", ".MAIN_DB_PREFIX."paiement as p";
277 $sql .= " WHERE p.rowid = pf.fk_paiement";
278 $sql .= " AND pf.fk_facture = f.rowid";
279 $sql .= " AND f.entity IN (".getEntity('invoice').")";
280 if ($socid) {
281 $sql .= " AND f.fk_soc = ".((int) $socid);
282 }
283} elseif ($modecompta == "BOOKKEEPING") {
284 $pcgverid = getDolGlobalInt('CHARTOFACCOUNTS');
285 $pcgvercode = dol_getIdFromCode($db, $pcgverid, 'accounting_system', 'rowid', 'pcg_version');
286 if (empty($pcgvercode)) {
287 $pcgvercode = $pcgverid;
288 }
289
290 $sql = "SELECT date_format(b.doc_date, '%Y-%m') as dm, sum(b.credit - b.debit) as amount_ttc";
291 $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as b,";
292 $sql .= " ".MAIN_DB_PREFIX."accounting_account as aa";
293 $sql .= " WHERE b.entity = ".$conf->entity; // In module double party accounting, we never share entities
294 $sql .= " AND b.numero_compte = aa.account_number";
295 $sql .= " AND b.doc_type = 'customer_invoice'";
296 $sql .= " AND aa.entity = ".$conf->entity;
297 $sql .= " AND aa.fk_pcg_version = '".$db->escape($pcgvercode)."'";
298 $sql .= " AND aa.pcg_type = 'INCOME'"; // TODO Be able to use a custom group
299}
300$sql .= " GROUP BY dm";
301$sql .= " ORDER BY dm";
302// TODO Add a filter on $date_start and $date_end to reduce quantity on data
303//print $sql;
304
305$minyearmonth = $maxyearmonth = 0;
306
307$cumulative = array();
308$cumulative_ht = array();
309$total_ht = array();
310$total = array();
311
312$result = $db->query($sql);
313if ($result) {
314 $num = $db->num_rows($result);
315 $i = 0;
316 while ($i < $num) {
317 $obj = $db->fetch_object($result);
318 $cumulative_ht[$obj->dm] = empty($obj->amount) ? 0 : $obj->amount;
319 $cumulative[$obj->dm] = empty($obj->amount_ttc) ? 0 : $obj->amount_ttc;
320 if ($obj->amount_ttc) {
321 $minyearmonth = ($minyearmonth ? min($minyearmonth, $obj->dm) : $obj->dm);
322 $maxyearmonth = max($maxyearmonth, $obj->dm);
323 }
324 $i++;
325 }
326 $db->free($result);
327} else {
329}
330
331// On ajoute les paiements anciennes version, non lies par paiement_facture (very old versions)
332if ($modecompta == 'RECETTES-DEPENSES') {
333 $sql = "SELECT date_format(p.datep,'%Y-%m') as dm, sum(p.amount) as amount_ttc";
334 $sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
335 $sql .= ", ".MAIN_DB_PREFIX."bank_account as ba";
336 $sql .= ", ".MAIN_DB_PREFIX."paiement as p";
337 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement";
338 $sql .= " WHERE pf.rowid IS NULL";
339 $sql .= " AND p.fk_bank = b.rowid";
340 $sql .= " AND b.fk_account = ba.rowid";
341 $sql .= " AND ba.entity IN (".getEntity('bank_account').")";
342 $sql .= " GROUP BY dm";
343 $sql .= " ORDER BY dm";
344
345 $result = $db->query($sql);
346 if ($result) {
347 $num = $db->num_rows($result);
348 $i = 0;
349 while ($i < $num) {
350 $obj = $db->fetch_object($result);
351 if (empty($cumulative[$obj->dm])) {
352 $cumulative[$obj->dm] = $obj->amount_ttc;
353 } else {
354 $cumulative[$obj->dm] += $obj->amount_ttc;
355 }
356 if ($obj->amount_ttc) {
357 $minyearmonth = ($minyearmonth ? min($minyearmonth, $obj->dm) : $obj->dm);
358 $maxyearmonth = max($maxyearmonth, $obj->dm);
359 }
360 $i++;
361 }
362 } else {
364 }
365}
366
367$moreforfilter = '';
368
369print '<div class="div-table-responsive">';
370print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
371
372print '<tr class="liste_titre"><td>&nbsp;</td>';
373
374for ($annee = $year_start; $annee <= $year_end; $annee++) {
375 if ($modecompta == 'CREANCES-DETTES') {
376 print '<td align="center" width="10%" colspan="3">';
377 } else {
378 print '<td align="center" width="10%" colspan="2" class="borderrightlight">';
379 }
380 if ($modecompta != 'BOOKKEEPING') {
381 print '<a href="casoc.php?year='.$annee.($modecompta ? '&modecompta='.$modecompta : '').'">';
382 }
383 print $annee;
384 if (getDolGlobalInt('SOCIETE_FISCAL_MONTH_START') > 1) {
385 print '-'.($annee + 1);
386 }
387 if ($modecompta != 'BOOKKEEPING') {
388 print '</a>';
389 }
390 print '</td>';
391 if ($annee != $year_end) {
392 print '<td width="15">&nbsp;</td>';
393 }
394}
395print '</tr>';
396
397print '<tr class="liste_titre"><td class="liste_titre">'.$langs->trans("Month").'</td>';
398for ($annee = $year_start; $annee <= $year_end; $annee++) {
399 if ($modecompta == 'CREANCES-DETTES') {
400 print '<td class="liste_titre right">'.$langs->trans("AmountHT").'</td>';
401 }
402 print '<td class="liste_titre right">';
403 if ($modecompta == "BOOKKEEPING") {
404 print $langs->trans("Amount");
405 } else {
406 print $langs->trans("AmountTTC");
407 }
408 print '</td>';
409 print '<td class="liste_titre right borderrightlight">'.$langs->trans("Delta").'</td>';
410 if ($annee != $year_end) {
411 print '<td class="liste_titre" width="15">&nbsp;</td>';
412 }
413}
414print '</tr>';
415
416$now_show_delta = 0;
417$minyear = substr($minyearmonth, 0, 4);
418$maxyear = substr($maxyearmonth, 0, 4);
419$nowyear = dol_print_date(dol_now('gmt'), "%Y", 'gmt');
420$nowyearmonth = dol_print_date(dol_now(), "%Y%m");
421$maxyearmonth = max($maxyearmonth, $nowyearmonth);
422$now = dol_now();
423$casenow = dol_print_date($now, "%Y-%m");
424
425// Loop on each month
426$nb_mois_decalage = GETPOSTISSET('date_startmonth') ? (GETPOSTINT('date_startmonth') - 1) : (!getDolGlobalInt('SOCIETE_FISCAL_MONTH_START') ? 0 : (getDolGlobalInt('SOCIETE_FISCAL_MONTH_START') - 1));
427for ($mois = 1 + $nb_mois_decalage; $mois <= 12 + $nb_mois_decalage; $mois++) {
428 $mois_modulo = $mois; // ajout
429 if ($mois > 12) {
430 $mois_modulo = $mois - 12;
431 } // ajout
432
433 if ($year_start == $year_end) {
434 // If we show only one year or one month, we do not show month before the selected month
435 if ($mois < $date_startmonth && $year_start <= $date_startyear) {
436 continue;
437 }
438 // If we show only one year or one month, we do not show month after the selected month
439 if ($mois > $date_endmonth && $year_end >= $date_endyear) {
440 break;
441 }
442 }
443
444 print '<tr class="oddeven">';
445
446 // Month
447 print "<td>".dol_print_date(dol_mktime(12, 0, 0, $mois_modulo, 1, 2000), "%B")."</td>";
448
449 for ($annee = $year_start - 1; $annee <= $year_end; $annee++) { // We start one year before to have data to be able to make delta
450 $annee_decalage = $annee;
451 if ($mois > 12) {
452 $annee_decalage = $annee + 1;
453 }
454 $case = dol_print_date(dol_mktime(1, 1, 1, $mois_modulo, 1, $annee_decalage), "%Y-%m");
455 $caseprev = dol_print_date(dol_mktime(1, 1, 1, $mois_modulo, 1, $annee_decalage - 1), "%Y-%m");
456
457 if ($annee >= $year_start) { // We ignore $annee < $year_start, we loop on it to be able to make delta, nothing is output.
458 if ($modecompta == 'CREANCES-DETTES') {
459 // Value turnover of month w/o VAT
460 print '<td class="right">';
461 if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) {
462 if (!empty($cumulative_ht[$case])) {
463 $now_show_delta = 1; // On a trouve le premier mois de la premiere annee generant du chiffre.
464 print '<a href="casoc.php?year='.$annee_decalage.'&month='.$mois_modulo.'&modecompta='.$modecompta.'">'.price($cumulative_ht[$case], 1).'</a>';
465 } else {
466 if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) {
467 print '0';
468 } else {
469 print '&nbsp;';
470 }
471 }
472 }
473 print "</td>";
474 }
475
476 // Value turnover of month
477 print '<td class="right">';
478 if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) {
479 if (!empty($cumulative[$case])) {
480 $now_show_delta = 1; // On a trouve le premier mois de la premiere annee generant du chiffre.
481 if ($modecompta != 'BOOKKEEPING') {
482 print '<a href="casoc.php?year='.$annee_decalage.'&month='.$mois_modulo.($modecompta ? '&modecompta='.$modecompta : '').'">';
483 }
484 print price($cumulative[$case], 1);
485 if ($modecompta != 'BOOKKEEPING') {
486 print '</a>';
487 }
488 } else {
489 if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) {
490 print '0';
491 } else {
492 print '&nbsp;';
493 }
494 }
495 }
496 print "</td>";
497
498 // Percentage of month
499 print '<td class="borderrightlight right"><span class="opacitymedium">';
500 //var_dump($annee.' '.$year_end.' '.$mois.' '.$month_end);
501 if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) {
502 if ($annee_decalage > $minyear && $case <= $casenow) {
503 if ($modecompta == 'CREANCES-DETTES') {
504 $cumulative_previous_year = (!empty($cumulative_ht[$caseprev]) ? $cumulative_ht[$caseprev] : 0);
505 $cumulative_year = (!empty($cumulative_ht[$case]) ? $cumulative_ht[$case] : 0);
506 $isset_cumulative_previous_year = isset($cumulative_ht[$caseprev]);
507 } else {
508 $cumulative_previous_year = (!empty($cumulative[$caseprev]) ? $cumulative[$caseprev] : 0);
509 $cumulative_year = (!empty($cumulative[$case]) ? $cumulative[$case] : 0);
510 $isset_cumulative_previous_year = isset($cumulative_ht[$caseprev]);
511 }
512 if (!empty($cumulative_previous_year) && !empty($cumulative_year)) {
513 $percent = (round(($cumulative_year - $cumulative_previous_year) / $cumulative_previous_year, 4) * 100);
514 //print "X $cumulative_year - $cumulative_previous_year - $cumulative_previous_year - $percent X";
515 print($percent >= 0 ? "+$percent" : "$percent").'%';
516 }
517 if (!empty($cumulative_previous_year) && empty($cumulative_year)) {
518 print '-100%';
519 }
520 if (empty($cumulative_previous_year) && !empty($cumulative_year)) {
521 //print '<td class="right">+Inf%</td>';
522 print '-';
523 }
524 if ($isset_cumulative_previous_year && empty($cumulative_previous_year) && empty($cumulative_year)) {
525 print '+0%';
526 }
527 if (!$isset_cumulative_previous_year && empty($cumulative_year)) {
528 print '-';
529 }
530 } else {
531 if ($minyearmonth <= $case && $case <= $maxyearmonth) {
532 print '-';
533 } else {
534 print '&nbsp;';
535 }
536 }
537 }
538 print '</span></td>';
539
540 if ($annee_decalage < $year_end || ($annee_decalage == $year_end && $mois > 12 && $annee < $year_end)) {
541 print '<td width="15">&nbsp;</td>';
542 }
543 }
544
545 if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) {
546 if (empty($total_ht[$annee])) {
547 $total_ht[$annee] = (empty($cumulative_ht[$case]) ? 0 : $cumulative_ht[$case]);
548 } else {
549 $total_ht[$annee] += (empty($cumulative_ht[$case]) ? 0 : $cumulative_ht[$case]);
550 }
551 if (empty($total[$annee])) {
552 $total[$annee] = empty($cumulative[$case]) ? 0 : $cumulative[$case];
553 } else {
554 $total[$annee] += empty($cumulative[$case]) ? 0 : $cumulative[$case];
555 }
556 }
557 }
558
559 print '</tr>';
560}
561
562/*
563 for ($mois = 1 ; $mois < 13 ; $mois++)
564 {
565
566 print '<tr class="oddeven">';
567
568 print "<td>".dol_print_date(dol_mktime(12,0,0,$mois,1,2000),"%B")."</td>";
569 for ($annee = $year_start ; $annee <= $year_end ; $annee++)
570 {
571 $casenow = dol_print_date(dol_now(),"%Y-%m");
572 $case = dol_print_date(dol_mktime(1,1,1,$mois,1,$annee),"%Y-%m");
573 $caseprev = dol_print_date(dol_mktime(1,1,1,$mois,1,$annee-1),"%Y-%m");
574
575 // Value of CA for the month
576 print '<td class="right">';
577 if ($cumulative[$case])
578 {
579 $now_show_delta=1; // The first month of the initial year to generate turnover has been identified.
580 print '<a href="casoc.php?year='.$annee.'&month='.$mois.'">'.price($cumulative[$case],1).'</a>';
581 }
582 else
583 {
584 if ($minyearmonth < $case && $case <= max($maxyearmonth,$nowyearmonth)) { print '0'; }
585 else { print '&nbsp;'; }
586 }
587 print "</td>";
588
589 // Percentage of the month
590 if ($annee > $minyear && $case <= $casenow) {
591 if ($cumulative[$caseprev] && $cumulative[$case]) {
592 $percent=(round(($cumulative[$case]-$cumulative[$caseprev])/$cumulative[$caseprev],4)*100);
593 //print "X $cumulative[$case] - $cumulative[$caseprev] - $cumulative[$caseprev] - $percent X";
594 print '<td class="right">'.($percent>=0?"+$percent":"$percent").'%</td>';
595
596 }
597 if ($cumulative[$caseprev] && ! $cumulative[$case])
598 {
599 print '<td class="right">-100%</td>';
600 }
601 if (! $cumulative[$caseprev] && $cumulative[$case])
602 {
603 print '<td class="right">+Inf%</td>';
604 }
605 if (! $cumulative[$caseprev] && ! $cumulative[$case])
606 {
607 print '<td class="right">+0%</td>';
608 }
609 }
610 else
611 {
612 print '<td class="right">';
613 if ($minyearmonth <= $case && $case <= $maxyearmonth) { print '-'; }
614 else { print '&nbsp;'; }
615 print '</td>';
616 }
617
618 $total[$annee]+=$cumulative[$case];
619 if ($annee != $year_end) print '<td width="15">&nbsp;</td>';
620 }
621
622 print '</tr>';
623 }
624 */
625
626// Show total
627print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td>';
628for ($annee = $year_start; $annee <= $year_end; $annee++) {
629 if ($modecompta == 'CREANCES-DETTES') {
630 // Montant total HT
631 if (isset($total_ht[$annee]) || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) {
632 print '<td class="nowrap right">';
633 print(empty($total_ht[$annee]) ? '0' : price($total_ht[$annee]));
634 print "</td>";
635 } else {
636 print '<td>&nbsp;</td>';
637 }
638 }
639
640 // Total amount
641 if (!empty($total[$annee]) || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) {
642 print '<td class="nowrap right">';
643 print(empty($total[$annee]) ? '0' : price($total[$annee]));
644 print "</td>";
645 } else {
646 print '<td>&nbsp;</td>';
647 }
648
649 // Percentage total
650 if ($annee > $minyear && $annee <= max($nowyear, $maxyear)) {
651 if ($modecompta == 'CREANCES-DETTES') {
652 $total_previous_year = (!empty($total_ht[$annee - 1]) ? $total_ht[$annee - 1] : 0);
653 $total_year = (!empty($total_ht[$annee]) ? $total_ht[$annee] : 0);
654 } else {
655 $total_previous_year = (!empty($total[$annee - 1]) ? $total[$annee - 1] : 0);
656 $total_year = (!empty($total[$annee]) ? $total[$annee] : 0);
657 }
658 if (!empty($total_previous_year) && !empty($total_year)) {
659 $percent = (round(($total_year - $total_previous_year) / $total_previous_year, 4) * 100);
660 print '<td class="nowrap borderrightlight right">';
661 print($percent >= 0 ? "+$percent" : "$percent").'%';
662 print '</td>';
663 }
664 if (!empty($total_previous_year) && empty($total_year)) {
665 print '<td class="borderrightlight right">-100%</td>';
666 }
667 if (empty($total_previous_year) && !empty($total_year)) {
668 print '<td class="borderrightlight right">+'.$langs->trans('Inf').'%</td>';
669 }
670 if (empty($total_previous_year) && empty($total_year)) {
671 print '<td class="borderrightlight right">+0%</td>';
672 }
673 } else {
674 print '<td class="borderrightlight right">';
675 if (!empty($total[$annee]) || ($minyear <= $annee && $annee <= max($nowyear, $maxyear))) {
676 print '-';
677 } else {
678 print '&nbsp;';
679 }
680 print '</td>';
681 }
682
683 if ($annee != $year_end) {
684 print '<td width="15">&nbsp;</td>';
685 }
686}
687print "</tr>\n";
688print "</table>";
689print '</div>';
690
691
692/*
693 * In cash accounting mode, we include outstanding invoiced amounts and signed proposals
694 * that haven't been invoiced yet. Since cash accounting only records transactions
695 * when funds hit the account, it is useful to have visibility into upcoming cash flow.
696 */
697
698/*
699 Commenting out this entire section because the displayed figures are incorrect - Eldy.
700 Waiting for the fix.
701
702 if ($modecompta != 'CREANCES-DETTES')
703 {
704
705 print '<br><table width="100%" class="noborder">';
706
707 // Unpaid invoices
708 // There is a bug here. We need to use the remaining to pay and not the total of unpaid invoices!
709
710 $sql = "SELECT f.ref, f.rowid, s.nom, s.rowid as socid, f.total_ttc, sum(pf.amount) as am";
711 $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";
712 $sql .= " WHERE s.rowid = f.fk_soc AND f.paye = 0 AND f.fk_statut = 1";
713 if ($socid)
714 {
715 $sql .= " AND f.fk_soc = $socid";
716 }
717 $sql .= " GROUP BY f.ref,f.rowid,s.nom, s.rowid, f.total_ttc";
718
719 $resql=$db->query($sql);
720 if ($resql)
721 {
722 $num = $db->num_rows($resql);
723 $i = 0;
724
725 if ($num)
726 {
727 $total_ttc_Rac = $totalam_Rac = $total_Rac = 0;
728 while ($i < $num)
729 {
730 $obj = $db->fetch_object($resql);
731 $total_ttc_Rac += $obj->total_ttc;
732 $totalam_Rac += $obj->am;
733 $i++;
734 }
735
736 print "<tr class="oddeven"><td class=\"right\" colspan=\"5\"><i>Invoice 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 invoices partiellement réglées</td></tr>";
737 }
738 $db->free($resql);
739 }
740 else
741 {
742 dol_print_error($db);
743 }
744 */
745
746/*
747 *
748 * Propales signees, et non facturees
749 *
750 */
751
752/*
753 Commenting out this entire section because the displayed figures are incorrect - Eldy.
754 Waiting for the fix.
755
756 $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
757 FROM ".MAIN_DB_PREFIX."commande AS p, ".MAIN_DB_PREFIX."societe AS s
758 LEFT JOIN ".MAIN_DB_PREFIX."co_fa AS co_fa ON co_fa.fk_commande = p.rowid
759 LEFT JOIN ".MAIN_DB_PREFIX."facture AS f ON co_fa.fk_facture = f.rowid
760 WHERE p.fk_soc = s.rowid
761 AND p.fk_statut >=1
762 AND p.facture =0";
763 if ($socid)
764 {
765 $sql .= " AND f.fk_soc = ".((int) $socid);
766 }
767 $sql .= " GROUP BY p.rowid";
768
769 $resql=$db->query($sql);
770 if ($resql)
771 {
772 $num = $db->num_rows($resql);
773 $i = 0;
774
775 if ($num)
776 {
777 $total_pr = 0;
778 while ($i < $num)
779 {
780 $obj = $db->fetch_object($resql);
781 $total_pr += $obj->total_ttc-$obj->tot_fttc;
782 $i++;
783 }
784
785 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>";
786 }
787 $db->free($resql);
788 }
789 else
790 {
791 dol_print_error($db);
792 }
793 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>";
794 }
795 print "</table>";
796
797 */
798
799// End of page
800llxFooter();
801$db->close();
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
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:73
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:604
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition date.lib.php:623
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
$date_start
Variables from include:
dol_now($mode='gmt')
Return date for now.
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...
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='', $useCache=true)
Return an id or code from a code or id.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='', $textonpictotooltip='')
Show information in HTML for admin users or standard users.
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
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.
isModEnabled($module)
Is Dolibarr module enabled.
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.