dolibarr 21.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-2024 Frédéric France <frederic.france@free.fr>
7 * Copyright (C) 2024 Benjamin B. <b.crozon@trebisol.com>
8 * Copyright (C) 2024 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';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
32require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
33
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$name = '';
163
164// Affiche en-tete du rapport
165if ($modecompta == "CREANCES-DETTES") {
166 $name = $langs->trans("Turnover");
167 $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>" : "");
168 $description = $langs->trans("RulesCADue");
169 if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) {
170 $description .= $langs->trans("DepositsAreNotIncluded");
171 } else {
172 $description .= $langs->trans("DepositsAreIncluded");
173 }
174 //$exportlink=$langs->trans("NotYetAvailable");
175} elseif ($modecompta == "RECETTES-DEPENSES") {
176 $name = $langs->trans("TurnoverCollected");
177 $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>" : "");
178 $description = $langs->trans("RulesCAIn");
179 $description .= $langs->trans("DepositsAreIncluded");
180 //$exportlink=$langs->trans("NotYetAvailable");
181} elseif ($modecompta == "BOOKKEEPING") {
182 $name = $langs->trans("Turnover");
183 $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>" : "");
184 $description = $langs->trans("RulesSalesTurnoverOfIncomeAccounts");
185 //$exportlink=$langs->trans("NotYetAvailable");
186}
187$period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0, 0, '', '', '', '', 1, '', '', 'tzserver');
188$period .= ' - ';
189$period .= $form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0, 0, '', '', '', '', 1, '', '', 'tzserver');
190
191$moreparam = array();
192if (!empty($modecompta)) {
193 $moreparam['modecompta'] = $modecompta;
194}
195
196// Define $calcmode line
197$calcmode = '';
198if ($modecompta == "RECETTES-DEPENSES" || $modecompta == "BOOKKEEPINGCOLLECTED") {
199 /*if (isModEnabled('accounting')) {
200 $calcmode .= '<input type="radio" name="modecompta" id="modecompta3" value="BOOKKEEPINGCOLLECTED"'.($modecompta == 'BOOKKEEPINGCOLLECTED' ? ' checked="checked"' : '').'><label for="modecompta3"> '.$langs->trans("CalcModeBookkeeping").'</label>';
201 $calcmode .= '<br>';
202 }*/
203 $calcmode .= '<input type="radio" name="modecompta" id="modecompta2" value="RECETTES-DEPENSES"'.($modecompta == 'RECETTES-DEPENSES' ? ' checked="checked"' : '').'><label for="modecompta2"> '.$langs->trans("CalcModePayment");
204 if (isModEnabled('accounting')) {
205 $calcmode .= ' <span class="opacitymedium hideonsmartphone">('.$langs->trans("CalcModeNoBookKeeping").')</span>';
206 }
207 $calcmode .= '</label>';
208} else {
209 if (isModEnabled('accounting')) {
210 $calcmode .= '<input type="radio" name="modecompta" id="modecompta3" value="BOOKKEEPING"'.($modecompta == 'BOOKKEEPING' ? ' checked="checked"' : '').'><label for="modecompta3"> '.$langs->trans("CalcModeBookkeeping").'</label>';
211 $calcmode .= ' <span class="opacitymedium hideonsmartphone">('.$langs->trans("DataMustHaveBeenTransferredInAccounting").')</span>';
212 $calcmode .= '<br>';
213 }
214 $calcmode .= '<input type="radio" name="modecompta" id="modecompta2" value="CREANCES-DETTES"'.($modecompta == 'CREANCES-DETTES' ? ' checked="checked"' : '').'><label for="modecompta2"> '.$langs->trans("CalcModeDebt");
215 if (isModEnabled('accounting')) {
216 $calcmode .= ' <span class="opacitymedium hideonsmartphone">('.$langs->trans("CalcModeNoBookKeeping").')</span>';
217 }
218 $calcmode .= '</label>';
219}
220
221report_header($name, $namelink, $period, $periodlink, $description, $builddate, $exportlink, $moreparam, $calcmode);
222
223if (isModEnabled('accounting')) {
224 if ($modecompta != 'BOOKKEEPING') {
225 print info_admin($langs->trans("WarningReportNotReliable"), 0, 0, '1');
226 } else {
227 // Test if there is at least one line in bookkeeping
228 $pcgverid = getDolGlobalInt('CHARTOFACCOUNTS');
229 $pcgvercode = dol_getIdFromCode($db, $pcgverid, 'accounting_system', 'rowid', 'pcg_version');
230 if (empty($pcgvercode)) {
231 $pcgvercode = $pcgverid;
232 }
233
234 $sql = "SELECT b.rowid ";
235 $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as b,";
236 $sql .= " ".MAIN_DB_PREFIX."accounting_account as aa";
237 $sql .= " WHERE b.entity = ".$conf->entity; // In module double party accounting, we never share entities
238 $sql .= " AND b.numero_compte = aa.account_number";
239 $sql .= " AND aa.entity = ".$conf->entity;
240 $sql .= " AND aa.fk_pcg_version = '".$db->escape($pcgvercode)."'";
241 $sql .= $db->plimit(1);
242
243 $resql = $db->query($sql);
244 $nb = $db->num_rows($resql);
245 if ($nb == 0) {
246 $langs->load("errors");
247 print info_admin($langs->trans("WarningNoDataTransferedInAccountancyYet"), 0, 0, '1');
248 }
249 }
250}
251
252
253if ($modecompta == 'CREANCES-DETTES') {
254 $sql = "SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total_ht) as amount, sum(f.total_ttc) as amount_ttc";
255 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
256 $sql .= " WHERE f.fk_statut in (1,2)";
257 if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) {
258 $sql .= " AND f.type IN (0,1,2,5)";
259 } else {
260 $sql .= " AND f.type IN (0,1,2,3,5)";
261 }
262 $sql .= " AND f.entity IN (".getEntity('invoice').")";
263 if ($socid) {
264 $sql .= " AND f.fk_soc = ".((int) $socid);
265 }
266} elseif ($modecompta == "RECETTES-DEPENSES") {
267 /*
268 * Liste des paiements (les anciens paiements ne sont pas vus par cette requete car, sur les
269 * vieilles versions, ils n'etaient pas lies via paiement_facture. On les ajoute plus loin)
270 */
271 $sql = "SELECT date_format(p.datep, '%Y-%m') as dm, sum(pf.amount) as amount_ttc";
272 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
273 $sql .= ", ".MAIN_DB_PREFIX."paiement_facture as pf";
274 $sql .= ", ".MAIN_DB_PREFIX."paiement as p";
275 $sql .= " WHERE p.rowid = pf.fk_paiement";
276 $sql .= " AND pf.fk_facture = f.rowid";
277 $sql .= " AND f.entity IN (".getEntity('invoice').")";
278 if ($socid) {
279 $sql .= " AND f.fk_soc = ".((int) $socid);
280 }
281} elseif ($modecompta == "BOOKKEEPING") {
282 $pcgverid = getDolGlobalInt('CHARTOFACCOUNTS');
283 $pcgvercode = dol_getIdFromCode($db, $pcgverid, 'accounting_system', 'rowid', 'pcg_version');
284 if (empty($pcgvercode)) {
285 $pcgvercode = $pcgverid;
286 }
287
288 $sql = "SELECT date_format(b.doc_date, '%Y-%m') as dm, sum(b.credit - b.debit) as amount_ttc";
289 $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as b,";
290 $sql .= " ".MAIN_DB_PREFIX."accounting_account as aa";
291 $sql .= " WHERE b.entity = ".$conf->entity; // In module double party accounting, we never share entities
292 $sql .= " AND b.numero_compte = aa.account_number";
293 $sql .= " AND b.doc_type = 'customer_invoice'";
294 $sql .= " AND aa.entity = ".$conf->entity;
295 $sql .= " AND aa.fk_pcg_version = '".$db->escape($pcgvercode)."'";
296 $sql .= " AND aa.pcg_type = 'INCOME'"; // TODO Be able to use a custom group
297}
298$sql .= " GROUP BY dm";
299$sql .= " ORDER BY dm";
300// TODO Add a filter on $date_start and $date_end to reduce quantity on data
301//print $sql;
302
303$minyearmonth = $maxyearmonth = 0;
304
305$cumulative = array();
306$cumulative_ht = array();
307$total_ht = array();
308$total = array();
309
310$result = $db->query($sql);
311if ($result) {
312 $num = $db->num_rows($result);
313 $i = 0;
314 while ($i < $num) {
315 $obj = $db->fetch_object($result);
316 $cumulative_ht[$obj->dm] = empty($obj->amount) ? 0 : $obj->amount;
317 $cumulative[$obj->dm] = empty($obj->amount_ttc) ? 0 : $obj->amount_ttc;
318 if ($obj->amount_ttc) {
319 $minyearmonth = ($minyearmonth ? min($minyearmonth, $obj->dm) : $obj->dm);
320 $maxyearmonth = max($maxyearmonth, $obj->dm);
321 }
322 $i++;
323 }
324 $db->free($result);
325} else {
326 dol_print_error($db);
327}
328
329// On ajoute les paiements anciennes version, non lies par paiement_facture (very old versions)
330if ($modecompta == 'RECETTES-DEPENSES') {
331 $sql = "SELECT date_format(p.datep,'%Y-%m') as dm, sum(p.amount) as amount_ttc";
332 $sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
333 $sql .= ", ".MAIN_DB_PREFIX."bank_account as ba";
334 $sql .= ", ".MAIN_DB_PREFIX."paiement as p";
335 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement";
336 $sql .= " WHERE pf.rowid IS NULL";
337 $sql .= " AND p.fk_bank = b.rowid";
338 $sql .= " AND b.fk_account = ba.rowid";
339 $sql .= " AND ba.entity IN (".getEntity('bank_account').")";
340 $sql .= " GROUP BY dm";
341 $sql .= " ORDER BY dm";
342
343 $result = $db->query($sql);
344 if ($result) {
345 $num = $db->num_rows($result);
346 $i = 0;
347 while ($i < $num) {
348 $obj = $db->fetch_object($result);
349 if (empty($cumulative[$obj->dm])) {
350 $cumulative[$obj->dm] = $obj->amount_ttc;
351 } else {
352 $cumulative[$obj->dm] += $obj->amount_ttc;
353 }
354 if ($obj->amount_ttc) {
355 $minyearmonth = ($minyearmonth ? min($minyearmonth, $obj->dm) : $obj->dm);
356 $maxyearmonth = max($maxyearmonth, $obj->dm);
357 }
358 $i++;
359 }
360 } else {
361 dol_print_error($db);
362 }
363}
364
365$moreforfilter = '';
366
367print '<div class="div-table-responsive">';
368print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
369
370print '<tr class="liste_titre"><td>&nbsp;</td>';
371
372for ($annee = $year_start; $annee <= $year_end; $annee++) {
373 if ($modecompta == 'CREANCES-DETTES') {
374 print '<td align="center" width="10%" colspan="3">';
375 } else {
376 print '<td align="center" width="10%" colspan="2" class="borderrightlight">';
377 }
378 if ($modecompta != 'BOOKKEEPING') {
379 print '<a href="casoc.php?year='.$annee.($modecompta ? '&modecompta='.$modecompta : '').'">';
380 }
381 print $annee;
382 if (getDolGlobalInt('SOCIETE_FISCAL_MONTH_START') > 1) {
383 print '-'.($annee + 1);
384 }
385 if ($modecompta != 'BOOKKEEPING') {
386 print '</a>';
387 }
388 print '</td>';
389 if ($annee != $year_end) {
390 print '<td width="15">&nbsp;</td>';
391 }
392}
393print '</tr>';
394
395print '<tr class="liste_titre"><td class="liste_titre">'.$langs->trans("Month").'</td>';
396for ($annee = $year_start; $annee <= $year_end; $annee++) {
397 if ($modecompta == 'CREANCES-DETTES') {
398 print '<td class="liste_titre right">'.$langs->trans("AmountHT").'</td>';
399 }
400 print '<td class="liste_titre right">';
401 if ($modecompta == "BOOKKEEPING") {
402 print $langs->trans("Amount");
403 } else {
404 print $langs->trans("AmountTTC");
405 }
406 print '</td>';
407 print '<td class="liste_titre right borderrightlight">'.$langs->trans("Delta").'</td>';
408 if ($annee != $year_end) {
409 print '<td class="liste_titre" width="15">&nbsp;</td>';
410 }
411}
412print '</tr>';
413
414$now_show_delta = 0;
415$minyear = substr($minyearmonth, 0, 4);
416$maxyear = substr($maxyearmonth, 0, 4);
417$nowyear = dol_print_date(dol_now('gmt'), "%Y", 'gmt');
418$nowyearmonth = dol_print_date(dol_now(), "%Y%m");
419$maxyearmonth = max($maxyearmonth, $nowyearmonth);
420$now = dol_now();
421$casenow = dol_print_date($now, "%Y-%m");
422
423// Loop on each month
424$nb_mois_decalage = GETPOSTISSET('date_startmonth') ? (GETPOSTINT('date_startmonth') - 1) : (!getDolGlobalInt('SOCIETE_FISCAL_MONTH_START') ? 0 : (getDolGlobalInt('SOCIETE_FISCAL_MONTH_START') - 1));
425for ($mois = 1 + $nb_mois_decalage; $mois <= 12 + $nb_mois_decalage; $mois++) {
426 $mois_modulo = $mois; // ajout
427 if ($mois > 12) {
428 $mois_modulo = $mois - 12;
429 } // ajout
430
431 if ($year_start == $year_end) {
432 // If we show only one year or one month, we do not show month before the selected month
433 if ($mois < $date_startmonth && $year_start <= $date_startyear) {
434 continue;
435 }
436 // If we show only one year or one month, we do not show month after the selected month
437 if ($mois > $date_endmonth && $year_end >= $date_endyear) {
438 break;
439 }
440 }
441
442 print '<tr class="oddeven">';
443
444 // Month
445 print "<td>".dol_print_date(dol_mktime(12, 0, 0, $mois_modulo, 1, 2000), "%B")."</td>";
446
447 for ($annee = $year_start - 1; $annee <= $year_end; $annee++) { // We start one year before to have data to be able to make delta
448 $annee_decalage = $annee;
449 if ($mois > 12) {
450 $annee_decalage = $annee + 1;
451 }
452 $case = dol_print_date(dol_mktime(1, 1, 1, $mois_modulo, 1, $annee_decalage), "%Y-%m");
453 $caseprev = dol_print_date(dol_mktime(1, 1, 1, $mois_modulo, 1, $annee_decalage - 1), "%Y-%m");
454
455 if ($annee >= $year_start) { // We ignore $annee < $year_start, we loop on it to be able to make delta, nothing is output.
456 if ($modecompta == 'CREANCES-DETTES') {
457 // Value turnover of month w/o VAT
458 print '<td class="right">';
459 if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) {
460 if (!empty($cumulative_ht[$case])) {
461 $now_show_delta = 1; // On a trouve le premier mois de la premiere annee generant du chiffre.
462 print '<a href="casoc.php?year='.$annee_decalage.'&month='.$mois_modulo.($modecompta ? '&modecompta='.$modecompta : '').'">'.price($cumulative_ht[$case], 1).'</a>';
463 } else {
464 if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) {
465 print '0';
466 } else {
467 print '&nbsp;';
468 }
469 }
470 }
471 print "</td>";
472 }
473
474 // Value turnover of month
475 print '<td class="right">';
476 if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) {
477 if (!empty($cumulative[$case])) {
478 $now_show_delta = 1; // On a trouve le premier mois de la premiere annee generant du chiffre.
479 if ($modecompta != 'BOOKKEEPING') {
480 print '<a href="casoc.php?year='.$annee_decalage.'&month='.$mois_modulo.($modecompta ? '&modecompta='.$modecompta : '').'">';
481 }
482 print price($cumulative[$case], 1);
483 if ($modecompta != 'BOOKKEEPING') {
484 print '</a>';
485 }
486 } else {
487 if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) {
488 print '0';
489 } else {
490 print '&nbsp;';
491 }
492 }
493 }
494 print "</td>";
495
496 // Percentage of month
497 print '<td class="borderrightlight right"><span class="opacitymedium">';
498 //var_dump($annee.' '.$year_end.' '.$mois.' '.$month_end);
499 if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) {
500 if ($annee_decalage > $minyear && $case <= $casenow) {
501 if ($modecompta=='CREANCES-DETTES') {
502 $cumulative_previous_year = (!empty($cumulative_ht[$caseprev])?$cumulative_ht[$caseprev]:0);
503 $cumulative_year = (!empty($cumulative_ht[$case])?$cumulative_ht[$case]:0);
504 $isset_cumulative_previous_year = isset($cumulative_ht[$caseprev]);
505 } else {
506 $cumulative_previous_year = (!empty($cumulative[$caseprev])?$cumulative[$caseprev]:0);
507 $cumulative_year = (!empty($cumulative[$case])?$cumulative[$case]:0);
508 $isset_cumulative_previous_year = isset($cumulative_ht[$caseprev]);
509 }
510 if (!empty($cumulative_previous_year) && !empty($cumulative_year)) {
511 $percent = (round(($cumulative_year - $cumulative_previous_year) / $cumulative_previous_year, 4) * 100);
512 //print "X $cumulative_year - $cumulative_previous_year - $cumulative_previous_year - $percent X";
513 print($percent >= 0 ? "+$percent" : "$percent").'%';
514 }
515 if (!empty($cumulative_previous_year) && empty($cumulative_year)) {
516 print '-100%';
517 }
518 if (empty($cumulative_previous_year) && !empty($cumulative_year)) {
519 //print '<td class="right">+Inf%</td>';
520 print '-';
521 }
522 if ($isset_cumulative_previous_year && empty($cumulative_previous_year) && empty($cumulative_year)) {
523 print '+0%';
524 }
525 if (!$isset_cumulative_previous_year && empty($cumulative_year)) {
526 print '-';
527 }
528 } else {
529 if ($minyearmonth <= $case && $case <= $maxyearmonth) {
530 print '-';
531 } else {
532 print '&nbsp;';
533 }
534 }
535 }
536 print '</span></td>';
537
538 if ($annee_decalage < $year_end || ($annee_decalage == $year_end && $mois > 12 && $annee < $year_end)) {
539 print '<td width="15">&nbsp;</td>';
540 }
541 }
542
543 if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) {
544 if (empty($total_ht[$annee])) {
545 $total_ht[$annee] = (empty($cumulative_ht[$case]) ? 0 : $cumulative_ht[$case]);
546 } else {
547 $total_ht[$annee] += (empty($cumulative_ht[$case]) ? 0 : $cumulative_ht[$case]);
548 }
549 if (empty($total[$annee])) {
550 $total[$annee] = empty($cumulative[$case]) ? 0 : $cumulative[$case];
551 } else {
552 $total[$annee] += empty($cumulative[$case]) ? 0 : $cumulative[$case];
553 }
554 }
555 }
556
557 print '</tr>';
558}
559
560/*
561 for ($mois = 1 ; $mois < 13 ; $mois++)
562 {
563
564 print '<tr class="oddeven">';
565
566 print "<td>".dol_print_date(dol_mktime(12,0,0,$mois,1,2000),"%B")."</td>";
567 for ($annee = $year_start ; $annee <= $year_end ; $annee++)
568 {
569 $casenow = dol_print_date(dol_now(),"%Y-%m");
570 $case = dol_print_date(dol_mktime(1,1,1,$mois,1,$annee),"%Y-%m");
571 $caseprev = dol_print_date(dol_mktime(1,1,1,$mois,1,$annee-1),"%Y-%m");
572
573 // Valeur CA du mois
574 print '<td class="right">';
575 if ($cumulative[$case])
576 {
577 $now_show_delta=1; // On a trouve le premier mois de la premiere annee generant du chiffre.
578 print '<a href="casoc.php?year='.$annee.'&month='.$mois.'">'.price($cumulative[$case],1).'</a>';
579 }
580 else
581 {
582 if ($minyearmonth < $case && $case <= max($maxyearmonth,$nowyearmonth)) { print '0'; }
583 else { print '&nbsp;'; }
584 }
585 print "</td>";
586
587 // Pourcentage du mois
588 if ($annee > $minyear && $case <= $casenow) {
589 if ($cumulative[$caseprev] && $cumulative[$case])
590 {
591 $percent=(round(($cumulative[$case]-$cumulative[$caseprev])/$cumulative[$caseprev],4)*100);
592 //print "X $cumulative[$case] - $cumulative[$caseprev] - $cumulative[$caseprev] - $percent X";
593 print '<td class="right">'.($percent>=0?"+$percent":"$percent").'%</td>';
594
595 }
596 if ($cumulative[$caseprev] && ! $cumulative[$case])
597 {
598 print '<td class="right">-100%</td>';
599 }
600 if (! $cumulative[$caseprev] && $cumulative[$case])
601 {
602 print '<td class="right">+Inf%</td>';
603 }
604 if (! $cumulative[$caseprev] && ! $cumulative[$case])
605 {
606 print '<td class="right">+0%</td>';
607 }
608 }
609 else
610 {
611 print '<td class="right">';
612 if ($minyearmonth <= $case && $case <= $maxyearmonth) { print '-'; }
613 else { print '&nbsp;'; }
614 print '</td>';
615 }
616
617 $total[$annee]+=$cumulative[$case];
618 if ($annee != $year_end) print '<td width="15">&nbsp;</td>';
619 }
620
621 print '</tr>';
622 }
623 */
624
625// Show total
626print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td>';
627for ($annee = $year_start; $annee <= $year_end; $annee++) {
628 if ($modecompta == 'CREANCES-DETTES') {
629 // Montant total HT
630 if (isset($total_ht[$annee]) || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) {
631 print '<td class="nowrap right">';
632 print(empty($total_ht[$annee]) ? '0' : price($total_ht[$annee]));
633 print "</td>";
634 } else {
635 print '<td>&nbsp;</td>';
636 }
637 }
638
639 // Total amount
640 if (!empty($total[$annee]) || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) {
641 print '<td class="nowrap right">';
642 print(empty($total[$annee]) ? '0' : price($total[$annee]));
643 print "</td>";
644 } else {
645 print '<td>&nbsp;</td>';
646 }
647
648 // Pourcentage total
649 if ($annee > $minyear && $annee <= max($nowyear, $maxyear)) {
650 if ($modecompta == 'CREANCES-DETTES') {
651 $total_previous_year = (!empty($total_ht[$annee - 1])?$total_ht[$annee - 1]:0);
652 $total_year = (!empty($total_ht[$annee])?$total_ht[$annee]:0);
653 } else {
654 $total_previous_year = (!empty($total[$annee - 1])?$total[$annee - 1]:0);
655 $total_year = (!empty($total[$annee])?$total[$annee]:0);
656 }
657 if (!empty($total_previous_year) && !empty($total_year)) {
658 $percent = (round(($total_year - $total_previous_year) / $total_previous_year, 4) * 100);
659 print '<td class="nowrap borderrightlight right">';
660 print($percent >= 0 ? "+$percent" : "$percent").'%';
661 print '</td>';
662 }
663 if (!empty($total_previous_year) && empty($total_year)) {
664 print '<td class="borderrightlight right">-100%</td>';
665 }
666 if (empty($total_previous_year) && !empty($total_year)) {
667 print '<td class="borderrightlight right">+'.$langs->trans('Inf').'%</td>';
668 }
669 if (empty($total_previous_year) && empty($total_year)) {
670 print '<td class="borderrightlight right">+0%</td>';
671 }
672 } else {
673 print '<td class="borderrightlight right">';
674 if (!empty($total[$annee]) || ($minyear <= $annee && $annee <= max($nowyear, $maxyear))) {
675 print '-';
676 } else {
677 print '&nbsp;';
678 }
679 print '</td>';
680 }
681
682 if ($annee != $year_end) {
683 print '<td width="15">&nbsp;</td>';
684 }
685}
686print "</tr>\n";
687print "</table>";
688print '</div>';
689
690
691/*
692 * En mode recettes/depenses, on complete avec les montants factures non regles
693 * et les propales signees mais pas facturees. En effet, en recettes-depenses,
694 * on comptabilise lorsque le montant est sur le compte donc il est interessant
695 * d'avoir une vision de ce qui va arriver.
696 */
697
698/*
699 Je commente toute cette partie car les chiffres affichees sont faux - Eldy.
700 En attendant correction.
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>Facture a encaisser : </i></td><td class=\"right\"><i>".price($total_ttc_Rac)."</i></td><td colspan=\"5\"><-- bug ici car n'exclut pas le deja r?gl? des factures partiellement r?gl?es</td></tr>";
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 Je commente toute cette partie car les chiffres affichees sont faux - Eldy.
754 En attendant correction.
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:87
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
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.