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