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