dolibarr 21.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) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2017 Olivier Geffroy <jeff@jeffinfo.com>
6 * Copyright (C) 2018-2020 Frédéric France <frederic.france@netlogic.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
34// Load translation files required by the page
35$langs->loadLangs(array('compta', 'bills', 'donation', 'salaries'));
36
37$date_startday = GETPOSTINT('date_startday');
38$date_startmonth = GETPOSTINT('date_startmonth');
39$date_startyear = GETPOSTINT('date_startyear');
40$date_endday = GETPOSTINT('date_endday');
41$date_endmonth = GETPOSTINT('date_endmonth');
42$date_endyear = GETPOSTINT('date_endyear');
43
44$nbofyear = 4;
45
46// Date range
47$year = GETPOSTINT('year');
48if (empty($year)) {
49 $year_current = (int) dol_print_date(dol_now(), "%Y");
50 $month_current = (int) dol_print_date(dol_now(), "%m");
51 $year_start = $year_current - ($nbofyear - 1);
52} else {
53 $year_current = $year;
54 $month_current = (int) dol_print_date(dol_now(), "%m");
55 $year_start = $year - $nbofyear + (getDolGlobalInt('SOCIETE_FISCAL_MONTH_START') > 1 ? 0 : 1);
56}
57$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
58$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
59
60// We define date_start and date_end
61if (empty($date_start) || empty($date_end)) { // We define date_start and date_end
62 $q = GETPOSTINT("q");
63 if (empty($q)) {
64 // We define date_start and date_end
65 $year_end = $year_start + $nbofyear - (getDolGlobalInt('SOCIETE_FISCAL_MONTH_START') > 1 ? 0 : 1);
66 $month_start = GETPOSTISSET("month") ? GETPOSTINT("month") : getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1);
67 if (!GETPOST('month')) { // If month not forced
68 if (!$year && $month_start > $month_current) {
69 $year_start--;
70 $year_end--;
71 }
72 $month_end = $month_start - 1;
73 if ($month_end < 1) {
74 $month_end = 12;
75 }
76 } else {
77 $month_end = $month_start;
78 }
79 $date_start = dol_get_first_day($year_start, $month_start, false);
80 $date_end = dol_get_last_day($year_end, $month_end, false);
81 }
82 if ($q == 1) {
83 $date_start = dol_get_first_day($year_start, 1, false);
84 $date_end = dol_get_last_day($year_start, 3, false);
85 }
86 if ($q == 2) {
87 $date_start = dol_get_first_day($year_start, 4, false);
88 $date_end = dol_get_last_day($year_start, 6, false);
89 }
90 if ($q == 3) {
91 $date_start = dol_get_first_day($year_start, 7, false);
92 $date_end = dol_get_last_day($year_start, 9, false);
93 }
94 if ($q == 4) {
95 $date_start = dol_get_first_day($year_start, 10, false);
96 $date_end = dol_get_last_day($year_start, 12, false);
97 }
98}
99
100$userid = GETPOSTINT('userid');
101$socid = GETPOSTINT('socid');
102
103$tmps = dol_getdate($date_start);
104$month_start = $tmps['mon'];
105$year_start = $tmps['year'];
106$tmpe = dol_getdate($date_end);
107$month_end = $tmpe['mon'];
108$year_end = $tmpe['year'];
109$nbofyear = ($year_end - $year_start) + 1;
110
111// Define modecompta ('CREANCES-DETTES' or 'RECETTES-DEPENSES' or 'BOOKKEEPING')
112$modecompta = getDolGlobalString('ACCOUNTING_MODE');
113if (isModEnabled('accounting')) {
114 $modecompta = 'BOOKKEEPING';
115}
116if (GETPOST("modecompta", 'alpha')) {
117 $modecompta = GETPOST("modecompta", 'alpha');
118}
119
120// Security check
121if ($user->socid > 0) {
122 $socid = $user->socid;
123}
124if (isModEnabled('comptabilite')) {
125 $result = restrictedArea($user, 'compta', '', '', 'resultat');
126}
127if (isModEnabled('accounting')) {
128 $result = restrictedArea($user, 'accounting', '', '', 'comptarapport');
129}
130
131
132
133
134/*
135 * View
136 */
137
138$param = '';
139if ($date_startday && $date_startmonth && $date_startyear) {
140 $param .= '&date_startday='.$date_startday.'&date_startmonth='.$date_startmonth.'&date_startyear='.$date_startyear;
141}
142if ($date_endday && $date_endmonth && $date_endyear) {
143 $param .= '&date_endday='.$date_endday.'&date_endmonth='.$date_endmonth.'&date_endyear='.$date_endyear;
144}
145
146llxHeader();
147
148$form = new Form($db);
149
150$exportlink = '';
151$namelink = '';
152$builddate = dol_now();
153
154// Affiche en-tete du rapport
155if ($modecompta == "CREANCES-DETTES") {
156 $name = $langs->trans("Turnover");
157 $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>" : "");
158 $description = $langs->trans("RulesCADue");
159 if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) {
160 $description .= $langs->trans("DepositsAreNotIncluded");
161 } else {
162 $description .= $langs->trans("DepositsAreIncluded");
163 }
164 //$exportlink=$langs->trans("NotYetAvailable");
165} elseif ($modecompta == "RECETTES-DEPENSES") {
166 $name = $langs->trans("TurnoverCollected");
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("RulesCAIn");
169 $description .= $langs->trans("DepositsAreIncluded");
170 //$exportlink=$langs->trans("NotYetAvailable");
171} elseif ($modecompta == "BOOKKEEPING") {
172 $name = $langs->trans("Turnover");
173 $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>" : "");
174 $description = $langs->trans("RulesSalesTurnoverOfIncomeAccounts");
175 //$exportlink=$langs->trans("NotYetAvailable");
176}
177$period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0, 0, '', '', '', '', 1, '', '', 'tzserver');
178$period .= ' - ';
179$period .= $form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0, 0, '', '', '', '', 1, '', '', 'tzserver');
180
181$moreparam = array();
182if (!empty($modecompta)) {
183 $moreparam['modecompta'] = $modecompta;
184}
185
186// Define $calcmode line
187$calcmode = '';
188if ($modecompta == "RECETTES-DEPENSES" || $modecompta == "BOOKKEEPINGCOLLECTED") {
189 /*if (isModEnabled('accounting')) {
190 $calcmode .= '<input type="radio" name="modecompta" id="modecompta3" value="BOOKKEEPINGCOLLECTED"'.($modecompta == 'BOOKKEEPINGCOLLECTED' ? ' checked="checked"' : '').'><label for="modecompta3"> '.$langs->trans("CalcModeBookkeeping").'</label>';
191 $calcmode .= '<br>';
192 }*/
193 $calcmode .= '<input type="radio" name="modecompta" id="modecompta2" value="RECETTES-DEPENSES"'.($modecompta == 'RECETTES-DEPENSES' ? ' checked="checked"' : '').'><label for="modecompta2"> '.$langs->trans("CalcModePayment");
194 if (isModEnabled('accounting')) {
195 $calcmode .= ' <span class="opacitymedium hideonsmartphone">('.$langs->trans("CalcModeNoBookKeeping").')</span>';
196 }
197 $calcmode .= '</label>';
198} else {
199 if (isModEnabled('accounting')) {
200 $calcmode .= '<input type="radio" name="modecompta" id="modecompta3" value="BOOKKEEPING"'.($modecompta == 'BOOKKEEPING' ? ' checked="checked"' : '').'><label for="modecompta3"> '.$langs->trans("CalcModeBookkeeping").'</label>';
201 $calcmode .= ' <span class="opacitymedium hideonsmartphone">('.$langs->trans("DataMustHaveBeenTransferredInAccounting").')</span>';
202 $calcmode .= '<br>';
203 }
204 $calcmode .= '<input type="radio" name="modecompta" id="modecompta2" value="CREANCES-DETTES"'.($modecompta == 'CREANCES-DETTES' ? ' checked="checked"' : '').'><label for="modecompta2"> '.$langs->trans("CalcModeDebt");
205 if (isModEnabled('accounting')) {
206 $calcmode .= ' <span class="opacitymedium hideonsmartphone">('.$langs->trans("CalcModeNoBookKeeping").')</span>';
207 }
208 $calcmode .= '</label>';
209}
210
211report_header($name, $namelink, $period, $periodlink, $description, $builddate, $exportlink, $moreparam, $calcmode);
212
213if (isModEnabled('accounting')) {
214 if ($modecompta != 'BOOKKEEPING') {
215 print info_admin($langs->trans("WarningReportNotReliable"), 0, 0, 1);
216 } else {
217 // Test if there is at least one line in bookkeeping
218 $pcgverid = getDolGlobalInt('CHARTOFACCOUNTS');
219 $pcgvercode = dol_getIdFromCode($db, $pcgverid, 'accounting_system', 'rowid', 'pcg_version');
220 if (empty($pcgvercode)) {
221 $pcgvercode = $pcgverid;
222 }
223
224 $sql = "SELECT b.rowid ";
225 $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as b,";
226 $sql .= " ".MAIN_DB_PREFIX."accounting_account as aa";
227 $sql .= " WHERE b.entity = ".$conf->entity; // In module double party accounting, we never share entities
228 $sql .= " AND b.numero_compte = aa.account_number";
229 $sql .= " AND aa.entity = ".$conf->entity;
230 $sql .= " AND aa.fk_pcg_version = '".$db->escape($pcgvercode)."'";
231 $sql .= $db->plimit(1);
232
233 $resql = $db->query($sql);
234 $nb = $db->num_rows($resql);
235 if ($nb == 0) {
236 $langs->load("errors");
237 print info_admin($langs->trans("WarningNoDataTransferedInAccountancyYet"), 0, 0, 1);
238 }
239 }
240}
241
242
243if ($modecompta == 'CREANCES-DETTES') {
244 $sql = "SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total_ht) as amount, sum(f.total_ttc) as amount_ttc";
245 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
246 $sql .= " WHERE f.fk_statut in (1,2)";
247 if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) {
248 $sql .= " AND f.type IN (0,1,2,5)";
249 } else {
250 $sql .= " AND f.type IN (0,1,2,3,5)";
251 }
252 $sql .= " AND f.entity IN (".getEntity('invoice').")";
253 if ($socid) {
254 $sql .= " AND f.fk_soc = ".((int) $socid);
255 }
256} elseif ($modecompta == "RECETTES-DEPENSES") {
257 /*
258 * Liste des paiements (les anciens paiements ne sont pas vus par cette requete car, sur les
259 * vieilles versions, ils n'etaient pas lies via paiement_facture. On les ajoute plus loin)
260 */
261 $sql = "SELECT date_format(p.datep, '%Y-%m') as dm, sum(pf.amount) as amount_ttc";
262 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
263 $sql .= ", ".MAIN_DB_PREFIX."paiement_facture as pf";
264 $sql .= ", ".MAIN_DB_PREFIX."paiement as p";
265 $sql .= " WHERE p.rowid = pf.fk_paiement";
266 $sql .= " AND pf.fk_facture = f.rowid";
267 $sql .= " AND f.entity IN (".getEntity('invoice').")";
268 if ($socid) {
269 $sql .= " AND f.fk_soc = ".((int) $socid);
270 }
271} elseif ($modecompta == "BOOKKEEPING") {
272 $pcgverid = getDolGlobalInt('CHARTOFACCOUNTS');
273 $pcgvercode = dol_getIdFromCode($db, $pcgverid, 'accounting_system', 'rowid', 'pcg_version');
274 if (empty($pcgvercode)) {
275 $pcgvercode = $pcgverid;
276 }
277
278 $sql = "SELECT date_format(b.doc_date, '%Y-%m') as dm, sum(b.credit - b.debit) as amount_ttc";
279 $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as b,";
280 $sql .= " ".MAIN_DB_PREFIX."accounting_account as aa";
281 $sql .= " WHERE b.entity = ".$conf->entity; // In module double party accounting, we never share entities
282 $sql .= " AND b.numero_compte = aa.account_number";
283 $sql .= " AND b.doc_type = 'customer_invoice'";
284 $sql .= " AND aa.entity = ".$conf->entity;
285 $sql .= " AND aa.fk_pcg_version = '".$db->escape($pcgvercode)."'";
286 $sql .= " AND aa.pcg_type = 'INCOME'"; // TODO Be able to use a custom group
287}
288$sql .= " GROUP BY dm";
289$sql .= " ORDER BY dm";
290// TODO Add a filter on $date_start and $date_end to reduce quantity on data
291//print $sql;
292
293$minyearmonth = $maxyearmonth = 0;
294
295$cumulative = array();
296$cumulative_ht = array();
297$total_ht = array();
298$total = array();
299
300$result = $db->query($sql);
301if ($result) {
302 $num = $db->num_rows($result);
303 $i = 0;
304 while ($i < $num) {
305 $obj = $db->fetch_object($result);
306 $cumulative_ht[$obj->dm] = empty($obj->amount) ? 0 : $obj->amount;
307 $cumulative[$obj->dm] = empty($obj->amount_ttc) ? 0 : $obj->amount_ttc;
308 if ($obj->amount_ttc) {
309 $minyearmonth = ($minyearmonth ? min($minyearmonth, $obj->dm) : $obj->dm);
310 $maxyearmonth = max($maxyearmonth, $obj->dm);
311 }
312 $i++;
313 }
314 $db->free($result);
315} else {
316 dol_print_error($db);
317}
318
319// On ajoute les paiements anciennes version, non lies par paiement_facture (very old versions)
320if ($modecompta == 'RECETTES-DEPENSES') {
321 $sql = "SELECT date_format(p.datep,'%Y-%m') as dm, sum(p.amount) as amount_ttc";
322 $sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
323 $sql .= ", ".MAIN_DB_PREFIX."bank_account as ba";
324 $sql .= ", ".MAIN_DB_PREFIX."paiement as p";
325 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement";
326 $sql .= " WHERE pf.rowid IS NULL";
327 $sql .= " AND p.fk_bank = b.rowid";
328 $sql .= " AND b.fk_account = ba.rowid";
329 $sql .= " AND ba.entity IN (".getEntity('bank_account').")";
330 $sql .= " GROUP BY dm";
331 $sql .= " ORDER BY dm";
332
333 $result = $db->query($sql);
334 if ($result) {
335 $num = $db->num_rows($result);
336 $i = 0;
337 while ($i < $num) {
338 $obj = $db->fetch_object($result);
339 if (empty($cumulative[$obj->dm])) {
340 $cumulative[$obj->dm] = $obj->amount_ttc;
341 } else {
342 $cumulative[$obj->dm] += $obj->amount_ttc;
343 }
344 if ($obj->amount_ttc) {
345 $minyearmonth = ($minyearmonth ? min($minyearmonth, $obj->dm) : $obj->dm);
346 $maxyearmonth = max($maxyearmonth, $obj->dm);
347 }
348 $i++;
349 }
350 } else {
351 dol_print_error($db);
352 }
353}
354
355$moreforfilter = '';
356
357print '<div class="div-table-responsive">';
358print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
359
360print '<tr class="liste_titre"><td>&nbsp;</td>';
361
362for ($annee = $year_start; $annee <= $year_end; $annee++) {
363 if ($modecompta == 'CREANCES-DETTES') {
364 print '<td align="center" width="10%" colspan="3">';
365 } else {
366 print '<td align="center" width="10%" colspan="2" class="borderrightlight">';
367 }
368 if ($modecompta != 'BOOKKEEPING') {
369 print '<a href="casoc.php?year='.$annee.($modecompta ? '&modecompta='.$modecompta : '').'">';
370 }
371 print $annee;
372 if (getDolGlobalInt('SOCIETE_FISCAL_MONTH_START') > 1) {
373 print '-'.($annee + 1);
374 }
375 if ($modecompta != 'BOOKKEEPING') {
376 print '</a>';
377 }
378 print '</td>';
379 if ($annee != $year_end) {
380 print '<td width="15">&nbsp;</td>';
381 }
382}
383print '</tr>';
384
385print '<tr class="liste_titre"><td class="liste_titre">'.$langs->trans("Month").'</td>';
386for ($annee = $year_start; $annee <= $year_end; $annee++) {
387 if ($modecompta == 'CREANCES-DETTES') {
388 print '<td class="liste_titre right">'.$langs->trans("AmountHT").'</td>';
389 }
390 print '<td class="liste_titre right">';
391 if ($modecompta == "BOOKKEEPING") {
392 print $langs->trans("Amount");
393 } else {
394 print $langs->trans("AmountTTC");
395 }
396 print '</td>';
397 print '<td class="liste_titre right borderrightlight">'.$langs->trans("Delta").'</td>';
398 if ($annee != $year_end) {
399 print '<td class="liste_titre" width="15">&nbsp;</td>';
400 }
401}
402print '</tr>';
403
404$now_show_delta = 0;
405$minyear = substr($minyearmonth, 0, 4);
406$maxyear = substr($maxyearmonth, 0, 4);
407$nowyear = dol_print_date(dol_now('gmt'), "%Y", 'gmt');
408$nowyearmonth = dol_print_date(dol_now(), "%Y%m");
409$maxyearmonth = max($maxyearmonth, $nowyearmonth);
410$now = dol_now();
411$casenow = dol_print_date($now, "%Y-%m");
412
413// Loop on each month
414$nb_mois_decalage = GETPOSTISSET('date_startmonth') ? (GETPOSTINT('date_startmonth') - 1) : (!getDolGlobalInt('SOCIETE_FISCAL_MONTH_START') ? 0 : (getDolGlobalInt('SOCIETE_FISCAL_MONTH_START') - 1));
415for ($mois = 1 + $nb_mois_decalage; $mois <= 12 + $nb_mois_decalage; $mois++) {
416 $mois_modulo = $mois; // ajout
417 if ($mois > 12) {
418 $mois_modulo = $mois - 12;
419 } // ajout
420
421 if ($year_start == $year_end) {
422 // If we show only one year or one month, we do not show month before the selected month
423 if ($mois < $date_startmonth && $year_start <= $date_startyear) {
424 continue;
425 }
426 // If we show only one year or one month, we do not show month after the selected month
427 if ($mois > $date_endmonth && $year_end >= $date_endyear) {
428 break;
429 }
430 }
431
432 print '<tr class="oddeven">';
433
434 // Month
435 print "<td>".dol_print_date(dol_mktime(12, 0, 0, $mois_modulo, 1, 2000), "%B")."</td>";
436
437 for ($annee = $year_start - 1; $annee <= $year_end; $annee++) { // We start one year before to have data to be able to make delta
438 $annee_decalage = $annee;
439 if ($mois > 12) {
440 $annee_decalage = $annee + 1;
441 }
442 $case = dol_print_date(dol_mktime(1, 1, 1, $mois_modulo, 1, $annee_decalage), "%Y-%m");
443 $caseprev = dol_print_date(dol_mktime(1, 1, 1, $mois_modulo, 1, $annee_decalage - 1), "%Y-%m");
444
445 if ($annee >= $year_start) { // We ignore $annee < $year_start, we loop on it to be able to make delta, nothing is output.
446 if ($modecompta == 'CREANCES-DETTES') {
447 // Value turnover of month w/o VAT
448 print '<td class="right">';
449 if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) {
450 if (!empty($cumulative_ht[$case])) {
451 $now_show_delta = 1; // On a trouve le premier mois de la premiere annee generant du chiffre.
452 print '<a href="casoc.php?year='.$annee_decalage.'&month='.$mois_modulo.($modecompta ? '&modecompta='.$modecompta : '').'">'.price($cumulative_ht[$case], 1).'</a>';
453 } else {
454 if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) {
455 print '0';
456 } else {
457 print '&nbsp;';
458 }
459 }
460 }
461 print "</td>";
462 }
463
464 // Value turnover of month
465 print '<td class="right">';
466 if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) {
467 if (!empty($cumulative[$case])) {
468 $now_show_delta = 1; // On a trouve le premier mois de la premiere annee generant du chiffre.
469 if ($modecompta != 'BOOKKEEPING') {
470 print '<a href="casoc.php?year='.$annee_decalage.'&month='.$mois_modulo.($modecompta ? '&modecompta='.$modecompta : '').'">';
471 }
472 print price($cumulative[$case], 1);
473 if ($modecompta != 'BOOKKEEPING') {
474 print '</a>';
475 }
476 } else {
477 if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) {
478 print '0';
479 } else {
480 print '&nbsp;';
481 }
482 }
483 }
484 print "</td>";
485
486 // Percentage of month
487 print '<td class="borderrightlight right"><span class="opacitymedium">';
488 //var_dump($annee.' '.$year_end.' '.$mois.' '.$month_end);
489 if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) {
490 if ($annee_decalage > $minyear && $case <= $casenow) {
491 if (!empty($cumulative[$caseprev]) && !empty($cumulative[$case])) {
492 $percent = (round(($cumulative[$case] - $cumulative[$caseprev]) / $cumulative[$caseprev], 4) * 100);
493 //print "X $cumulative[$case] - $cumulative[$caseprev] - $cumulative[$caseprev] - $percent X";
494 print($percent >= 0 ? "+$percent" : "$percent").'%';
495 }
496 if (!empty($cumulative[$caseprev]) && empty($cumulative[$case])) {
497 print '-100%';
498 }
499 if (empty($cumulative[$caseprev]) && !empty($cumulative[$case])) {
500 //print '<td class="right">+Inf%</td>';
501 print '-';
502 }
503 if (isset($cumulative[$caseprev]) && empty($cumulative[$caseprev]) && empty($cumulative[$case])) {
504 print '+0%';
505 }
506 if (!isset($cumulative[$caseprev]) && empty($cumulative[$case])) {
507 print '-';
508 }
509 } else {
510 if ($minyearmonth <= $case && $case <= $maxyearmonth) {
511 print '-';
512 } else {
513 print '&nbsp;';
514 }
515 }
516 }
517 print '</span></td>';
518
519 if ($annee_decalage < $year_end || ($annee_decalage == $year_end && $mois > 12 && $annee < $year_end)) {
520 print '<td width="15">&nbsp;</td>';
521 }
522 }
523
524 if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) {
525 if (empty($total_ht[$annee])) {
526 $total_ht[$annee] = (empty($cumulative_ht[$case]) ? 0 : $cumulative_ht[$case]);
527 } else {
528 $total_ht[$annee] += (empty($cumulative_ht[$case]) ? 0 : $cumulative_ht[$case]);
529 }
530 if (empty($total[$annee])) {
531 $total[$annee] = empty($cumulative[$case]) ? 0 : $cumulative[$case];
532 } else {
533 $total[$annee] += empty($cumulative[$case]) ? 0 : $cumulative[$case];
534 }
535 }
536 }
537
538 print '</tr>';
539}
540
541/*
542 for ($mois = 1 ; $mois < 13 ; $mois++)
543 {
544
545 print '<tr class="oddeven">';
546
547 print "<td>".dol_print_date(dol_mktime(12,0,0,$mois,1,2000),"%B")."</td>";
548 for ($annee = $year_start ; $annee <= $year_end ; $annee++)
549 {
550 $casenow = dol_print_date(dol_now(),"%Y-%m");
551 $case = dol_print_date(dol_mktime(1,1,1,$mois,1,$annee),"%Y-%m");
552 $caseprev = dol_print_date(dol_mktime(1,1,1,$mois,1,$annee-1),"%Y-%m");
553
554 // Valeur CA du mois
555 print '<td class="right">';
556 if ($cumulative[$case])
557 {
558 $now_show_delta=1; // On a trouve le premier mois de la premiere annee generant du chiffre.
559 print '<a href="casoc.php?year='.$annee.'&month='.$mois.'">'.price($cumulative[$case],1).'</a>';
560 }
561 else
562 {
563 if ($minyearmonth < $case && $case <= max($maxyearmonth,$nowyearmonth)) { print '0'; }
564 else { print '&nbsp;'; }
565 }
566 print "</td>";
567
568 // Pourcentage du mois
569 if ($annee > $minyear && $case <= $casenow) {
570 if ($cumulative[$caseprev] && $cumulative[$case])
571 {
572 $percent=(round(($cumulative[$case]-$cumulative[$caseprev])/$cumulative[$caseprev],4)*100);
573 //print "X $cumulative[$case] - $cumulative[$caseprev] - $cumulative[$caseprev] - $percent X";
574 print '<td class="right">'.($percent>=0?"+$percent":"$percent").'%</td>';
575
576 }
577 if ($cumulative[$caseprev] && ! $cumulative[$case])
578 {
579 print '<td class="right">-100%</td>';
580 }
581 if (! $cumulative[$caseprev] && $cumulative[$case])
582 {
583 print '<td class="right">+Inf%</td>';
584 }
585 if (! $cumulative[$caseprev] && ! $cumulative[$case])
586 {
587 print '<td class="right">+0%</td>';
588 }
589 }
590 else
591 {
592 print '<td class="right">';
593 if ($minyearmonth <= $case && $case <= $maxyearmonth) { print '-'; }
594 else { print '&nbsp;'; }
595 print '</td>';
596 }
597
598 $total[$annee]+=$cumulative[$case];
599 if ($annee != $year_end) print '<td width="15">&nbsp;</td>';
600 }
601
602 print '</tr>';
603 }
604 */
605
606// Show total
607print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td>';
608for ($annee = $year_start; $annee <= $year_end; $annee++) {
609 if ($modecompta == 'CREANCES-DETTES') {
610 // Montant total HT
611 if ($total_ht[$annee] || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) {
612 print '<td class="nowrap right">';
613 print(empty($total_ht[$annee]) ? '0' : price($total_ht[$annee]));
614 print "</td>";
615 } else {
616 print '<td>&nbsp;</td>';
617 }
618 }
619
620 // Total amount
621 if (!empty($total[$annee]) || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) {
622 print '<td class="nowrap right">';
623 print(empty($total[$annee]) ? '0' : price($total[$annee]));
624 print "</td>";
625 } else {
626 print '<td>&nbsp;</td>';
627 }
628
629 // Pourcentage total
630 if ($annee > $minyear && $annee <= max($nowyear, $maxyear)) {
631 if (!empty($total[$annee - 1]) && !empty($total[$annee])) {
632 $percent = (round(($total[$annee] - $total[$annee - 1]) / $total[$annee - 1], 4) * 100);
633 print '<td class="nowrap borderrightlight right">';
634 print($percent >= 0 ? "+$percent" : "$percent").'%';
635 print '</td>';
636 }
637 if (!empty($total[$annee - 1]) && empty($total[$annee])) {
638 print '<td class="borderrightlight right">-100%</td>';
639 }
640 if (empty($total[$annee - 1]) && !empty($total[$annee])) {
641 print '<td class="borderrightlight right">+'.$langs->trans('Inf').'%</td>';
642 }
643 if (empty($total[$annee - 1]) && empty($total[$annee])) {
644 print '<td class="borderrightlight right">+0%</td>';
645 }
646 } else {
647 print '<td class="borderrightlight right">';
648 if (!empty($total[$annee]) || ($minyear <= $annee && $annee <= max($nowyear, $maxyear))) {
649 print '-';
650 } else {
651 print '&nbsp;';
652 }
653 print '</td>';
654 }
655
656 if ($annee != $year_end) {
657 print '<td width="15">&nbsp;</td>';
658 }
659}
660print "</tr>\n";
661print "</table>";
662print '</div>';
663
664
665/*
666 * En mode recettes/depenses, on complete avec les montants factures non regles
667 * et les propales signees mais pas facturees. En effet, en recettes-depenses,
668 * on comptabilise lorsque le montant est sur le compte donc il est interessant
669 * d'avoir une vision de ce qui va arriver.
670 */
671
672/*
673 Je commente toute cette partie car les chiffres affichees sont faux - Eldy.
674 En attendant correction.
675
676 if ($modecompta != 'CREANCES-DETTES')
677 {
678
679 print '<br><table width="100%" class="noborder">';
680
681 // Unpaid invoices
682 // There is a bug here. We need to use the remaining to pay and not the total of unpaid invoices!
683
684 $sql = "SELECT f.ref, f.rowid, s.nom, s.rowid as socid, f.total_ttc, sum(pf.amount) as am";
685 $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";
686 $sql .= " WHERE s.rowid = f.fk_soc AND f.paye = 0 AND f.fk_statut = 1";
687 if ($socid)
688 {
689 $sql .= " AND f.fk_soc = $socid";
690 }
691 $sql .= " GROUP BY f.ref,f.rowid,s.nom, s.rowid, f.total_ttc";
692
693 $resql=$db->query($sql);
694 if ($resql)
695 {
696 $num = $db->num_rows($resql);
697 $i = 0;
698
699 if ($num)
700 {
701 $total_ttc_Rac = $totalam_Rac = $total_Rac = 0;
702 while ($i < $num)
703 {
704 $obj = $db->fetch_object($resql);
705 $total_ttc_Rac += $obj->total_ttc;
706 $totalam_Rac += $obj->am;
707 $i++;
708 }
709
710 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>";
711 }
712 $db->free($resql);
713 }
714 else
715 {
716 dol_print_error($db);
717 }
718 */
719
720/*
721 *
722 * Propales signees, et non facturees
723 *
724 */
725
726/*
727 Je commente toute cette partie car les chiffres affichees sont faux - Eldy.
728 En attendant correction.
729
730 $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
731 FROM ".MAIN_DB_PREFIX."commande AS p, ".MAIN_DB_PREFIX."societe AS s
732 LEFT JOIN ".MAIN_DB_PREFIX."co_fa AS co_fa ON co_fa.fk_commande = p.rowid
733 LEFT JOIN ".MAIN_DB_PREFIX."facture AS f ON co_fa.fk_facture = f.rowid
734 WHERE p.fk_soc = s.rowid
735 AND p.fk_statut >=1
736 AND p.facture =0";
737 if ($socid)
738 {
739 $sql .= " AND f.fk_soc = ".((int) $socid);
740 }
741 $sql .= " GROUP BY p.rowid";
742
743 $resql=$db->query($sql);
744 if ($resql)
745 {
746 $num = $db->num_rows($resql);
747 $i = 0;
748
749 if ($num)
750 {
751 $total_pr = 0;
752 while ($i < $num)
753 {
754 $obj = $db->fetch_object($resql);
755 $total_pr += $obj->total_ttc-$obj->tot_fttc;
756 $i++;
757 }
758
759 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>";
760 }
761 $db->free($resql);
762 }
763 else
764 {
765 dol_print_error($db);
766 }
767 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>";
768 }
769 print "</table>";
770
771 */
772
773// End of page
774llxFooter();
775$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:70
Class to manage generation of HTML components Only common components must be here.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition date.lib.php:595
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition date.lib.php:614
llxFooter()
Footer empty.
Definition document.php:107
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='')
Return an id or code from a code or id.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
img_previous($titlealt='default', $moreatt='')
Show previous logo.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_next($titlealt='default', $moreatt='')
Show next logo.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
report_header($reportname, $notused, $period, $periodlink, $description, $builddate, $exportlink='', $moreparam=array(), $calcmode='', $varlink='')
Show header of a report.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.