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 (!empty($cumulative[$caseprev]) && !empty($cumulative[$case])) {
502 $percent = (round(($cumulative[$case] - $cumulative[$caseprev]) / $cumulative[$caseprev], 4) * 100);
503 //print "X $cumulative[$case] - $cumulative[$caseprev] - $cumulative[$caseprev] - $percent X";
504 print($percent >= 0 ? "+$percent" : "$percent").'%';
505 }
506 if (!empty($cumulative[$caseprev]) && empty($cumulative[$case])) {
507 print '-100%';
508 }
509 if (empty($cumulative[$caseprev]) && !empty($cumulative[$case])) {
510 //print '<td class="right">+Inf%</td>';
511 print '-';
512 }
513 if (isset($cumulative[$caseprev]) && empty($cumulative[$caseprev]) && empty($cumulative[$case])) {
514 print '+0%';
515 }
516 if (!isset($cumulative[$caseprev]) && empty($cumulative[$case])) {
517 print '-';
518 }
519 } else {
520 if ($minyearmonth <= $case && $case <= $maxyearmonth) {
521 print '-';
522 } else {
523 print '&nbsp;';
524 }
525 }
526 }
527 print '</span></td>';
528
529 if ($annee_decalage < $year_end || ($annee_decalage == $year_end && $mois > 12 && $annee < $year_end)) {
530 print '<td width="15">&nbsp;</td>';
531 }
532 }
533
534 if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) {
535 if (empty($total_ht[$annee])) {
536 $total_ht[$annee] = (empty($cumulative_ht[$case]) ? 0 : $cumulative_ht[$case]);
537 } else {
538 $total_ht[$annee] += (empty($cumulative_ht[$case]) ? 0 : $cumulative_ht[$case]);
539 }
540 if (empty($total[$annee])) {
541 $total[$annee] = empty($cumulative[$case]) ? 0 : $cumulative[$case];
542 } else {
543 $total[$annee] += empty($cumulative[$case]) ? 0 : $cumulative[$case];
544 }
545 }
546 }
547
548 print '</tr>';
549}
550
551/*
552 for ($mois = 1 ; $mois < 13 ; $mois++)
553 {
554
555 print '<tr class="oddeven">';
556
557 print "<td>".dol_print_date(dol_mktime(12,0,0,$mois,1,2000),"%B")."</td>";
558 for ($annee = $year_start ; $annee <= $year_end ; $annee++)
559 {
560 $casenow = dol_print_date(dol_now(),"%Y-%m");
561 $case = dol_print_date(dol_mktime(1,1,1,$mois,1,$annee),"%Y-%m");
562 $caseprev = dol_print_date(dol_mktime(1,1,1,$mois,1,$annee-1),"%Y-%m");
563
564 // Valeur CA du mois
565 print '<td class="right">';
566 if ($cumulative[$case])
567 {
568 $now_show_delta=1; // On a trouve le premier mois de la premiere annee generant du chiffre.
569 print '<a href="casoc.php?year='.$annee.'&month='.$mois.'">'.price($cumulative[$case],1).'</a>';
570 }
571 else
572 {
573 if ($minyearmonth < $case && $case <= max($maxyearmonth,$nowyearmonth)) { print '0'; }
574 else { print '&nbsp;'; }
575 }
576 print "</td>";
577
578 // Pourcentage du mois
579 if ($annee > $minyear && $case <= $casenow) {
580 if ($cumulative[$caseprev] && $cumulative[$case])
581 {
582 $percent=(round(($cumulative[$case]-$cumulative[$caseprev])/$cumulative[$caseprev],4)*100);
583 //print "X $cumulative[$case] - $cumulative[$caseprev] - $cumulative[$caseprev] - $percent X";
584 print '<td class="right">'.($percent>=0?"+$percent":"$percent").'%</td>';
585
586 }
587 if ($cumulative[$caseprev] && ! $cumulative[$case])
588 {
589 print '<td class="right">-100%</td>';
590 }
591 if (! $cumulative[$caseprev] && $cumulative[$case])
592 {
593 print '<td class="right">+Inf%</td>';
594 }
595 if (! $cumulative[$caseprev] && ! $cumulative[$case])
596 {
597 print '<td class="right">+0%</td>';
598 }
599 }
600 else
601 {
602 print '<td class="right">';
603 if ($minyearmonth <= $case && $case <= $maxyearmonth) { print '-'; }
604 else { print '&nbsp;'; }
605 print '</td>';
606 }
607
608 $total[$annee]+=$cumulative[$case];
609 if ($annee != $year_end) print '<td width="15">&nbsp;</td>';
610 }
611
612 print '</tr>';
613 }
614 */
615
616// Show total
617print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td>';
618for ($annee = $year_start; $annee <= $year_end; $annee++) {
619 if ($modecompta == 'CREANCES-DETTES') {
620 // Montant total HT
621 if ($total_ht[$annee] || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) {
622 print '<td class="nowrap right">';
623 print(empty($total_ht[$annee]) ? '0' : price($total_ht[$annee]));
624 print "</td>";
625 } else {
626 print '<td>&nbsp;</td>';
627 }
628 }
629
630 // Total amount
631 if (!empty($total[$annee]) || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) {
632 print '<td class="nowrap right">';
633 print(empty($total[$annee]) ? '0' : price($total[$annee]));
634 print "</td>";
635 } else {
636 print '<td>&nbsp;</td>';
637 }
638
639 // Pourcentage total
640 if ($annee > $minyear && $annee <= max($nowyear, $maxyear)) {
641 if (!empty($total[$annee - 1]) && !empty($total[$annee])) {
642 $percent = (round(($total[$annee] - $total[$annee - 1]) / $total[$annee - 1], 4) * 100);
643 print '<td class="nowrap borderrightlight right">';
644 print($percent >= 0 ? "+$percent" : "$percent").'%';
645 print '</td>';
646 }
647 if (!empty($total[$annee - 1]) && empty($total[$annee])) {
648 print '<td class="borderrightlight right">-100%</td>';
649 }
650 if (empty($total[$annee - 1]) && !empty($total[$annee])) {
651 print '<td class="borderrightlight right">+'.$langs->trans('Inf').'%</td>';
652 }
653 if (empty($total[$annee - 1]) && empty($total[$annee])) {
654 print '<td class="borderrightlight right">+0%</td>';
655 }
656 } else {
657 print '<td class="borderrightlight right">';
658 if (!empty($total[$annee]) || ($minyear <= $annee && $annee <= max($nowyear, $maxyear))) {
659 print '-';
660 } else {
661 print '&nbsp;';
662 }
663 print '</td>';
664 }
665
666 if ($annee != $year_end) {
667 print '<td width="15">&nbsp;</td>';
668 }
669}
670print "</tr>\n";
671print "</table>";
672print '</div>';
673
674
675/*
676 * En mode recettes/depenses, on complete avec les montants factures non regles
677 * et les propales signees mais pas facturees. En effet, en recettes-depenses,
678 * on comptabilise lorsque le montant est sur le compte donc il est interessant
679 * d'avoir une vision de ce qui va arriver.
680 */
681
682/*
683 Je commente toute cette partie car les chiffres affichees sont faux - Eldy.
684 En attendant correction.
685
686 if ($modecompta != 'CREANCES-DETTES')
687 {
688
689 print '<br><table width="100%" class="noborder">';
690
691 // Unpaid invoices
692 // There is a bug here. We need to use the remaining to pay and not the total of unpaid invoices!
693
694 $sql = "SELECT f.ref, f.rowid, s.nom, s.rowid as socid, f.total_ttc, sum(pf.amount) as am";
695 $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";
696 $sql .= " WHERE s.rowid = f.fk_soc AND f.paye = 0 AND f.fk_statut = 1";
697 if ($socid)
698 {
699 $sql .= " AND f.fk_soc = $socid";
700 }
701 $sql .= " GROUP BY f.ref,f.rowid,s.nom, s.rowid, f.total_ttc";
702
703 $resql=$db->query($sql);
704 if ($resql)
705 {
706 $num = $db->num_rows($resql);
707 $i = 0;
708
709 if ($num)
710 {
711 $total_ttc_Rac = $totalam_Rac = $total_Rac = 0;
712 while ($i < $num)
713 {
714 $obj = $db->fetch_object($resql);
715 $total_ttc_Rac += $obj->total_ttc;
716 $totalam_Rac += $obj->am;
717 $i++;
718 }
719
720 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>";
721 }
722 $db->free($resql);
723 }
724 else
725 {
726 dol_print_error($db);
727 }
728 */
729
730/*
731 *
732 * Propales signees, et non facturees
733 *
734 */
735
736/*
737 Je commente toute cette partie car les chiffres affichees sont faux - Eldy.
738 En attendant correction.
739
740 $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
741 FROM ".MAIN_DB_PREFIX."commande AS p, ".MAIN_DB_PREFIX."societe AS s
742 LEFT JOIN ".MAIN_DB_PREFIX."co_fa AS co_fa ON co_fa.fk_commande = p.rowid
743 LEFT JOIN ".MAIN_DB_PREFIX."facture AS f ON co_fa.fk_facture = f.rowid
744 WHERE p.fk_soc = s.rowid
745 AND p.fk_statut >=1
746 AND p.facture =0";
747 if ($socid)
748 {
749 $sql .= " AND f.fk_soc = ".((int) $socid);
750 }
751 $sql .= " GROUP BY p.rowid";
752
753 $resql=$db->query($sql);
754 if ($resql)
755 {
756 $num = $db->num_rows($resql);
757 $i = 0;
758
759 if ($num)
760 {
761 $total_pr = 0;
762 while ($i < $num)
763 {
764 $obj = $db->fetch_object($resql);
765 $total_pr += $obj->total_ttc-$obj->tot_fttc;
766 $i++;
767 }
768
769 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>";
770 }
771 $db->free($resql);
772 }
773 else
774 {
775 dol_print_error($db);
776 }
777 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>";
778 }
779 print "</table>";
780
781 */
782
783// End of page
784llxFooter();
785$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:71
Class to manage generation of HTML components Only common components must be here.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition date.lib.php:600
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition date.lib.php:619
llxFooter()
Footer empty.
Definition document.php:107
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='')
Return an id or code from a code or id.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
img_previous($titlealt='default', $moreatt='')
Show previous logo.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_next($titlealt='default', $moreatt='')
Show next logo.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
report_header($reportname, $notused, $period, $periodlink, $description, $builddate, $exportlink='', $moreparam=array(), $calcmode='', $varlink='')
Show header of a report.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.