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