dolibarr 21.0.0-beta
result.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2016-2017 Jamal Elbaz <jamelbaz@gmail.com>
3 * Copyright (C) 2016-2022 Alexandre Spangaro <aspangaro@open-dsi.fr>
4 * Copyright (C) 2018-2020 Laurent Destailleur <eldy@destailleur.fr>
5 * Copyright (C) 2018-2024 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
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
28// Load Dolibarr environment
29require '../../main.inc.php';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
32require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
33require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
34require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountancycategory.class.php';
35require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountancyreport.class.php';
36
46// Load translation files required by the page
47$langs->loadLangs(array('compta', 'bills', 'donation', 'salaries', 'accountancy'));
48
49$id_report = GETPOSTINT('id_report');
50
51$error = 0;
52
53$mesg = '';
54$action = GETPOST('action', 'aZ09');
55$cat_id = GETPOST('account_category');
56$selectcpt = GETPOST('cpt_bk');
57$id = GETPOSTINT('id');
58$rowid = GETPOSTINT('rowid');
59$cancel = GETPOST('cancel', 'alpha');
60$showaccountdetail = GETPOST('showaccountdetail', 'aZ09') ? GETPOST('showaccountdetail', 'aZ09') : 'no';
61
62
63$date_startmonth = GETPOSTINT('date_startmonth');
64$date_startday = GETPOSTINT('date_startday');
65$date_startyear = GETPOSTINT('date_startyear');
66$date_endmonth = GETPOSTINT('date_endmonth');
67$date_endday = GETPOSTINT('date_endday');
68$date_endyear = GETPOSTINT('date_endyear');
69
70$nbofyear = 1;
71
72// Change this to test different cases of setup
73//$conf->global->SOCIETE_FISCAL_MONTH_START = 7;
74
75// Date range
76$year = GETPOSTINT('year'); // year with current month, is the month of the period we must show
77if (empty($year)) {
78 $year_current = (int) dol_print_date(dol_now('gmt'), "%Y", 'gmt');
79 $month_current = (int) dol_print_date(dol_now(), "%m");
80 $year_start = $year_current - ($nbofyear - 1);
81} else {
82 $year_current = $year;
83 $month_current = (int) dol_print_date(dol_now(), "%m");
84 $year_start = $year - ($nbofyear - 1);
85}
86$date_start = dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
87$date_end = dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
88
89// We define date_start and date_end
90if (empty($date_start) || empty($date_end)) { // We define date_start and date_end
91 $q = GETPOSTINT("q") ? GETPOSTINT("q") : 0;
92 if ($q == 0) {
93 // We define date_start and date_end
94 $year_end = $year_start + ($nbofyear - 1);
95 $month_start = GETPOSTINT("month") ? GETPOSTINT("month") : getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1);
96 $date_startmonth = $month_start;
97 if (!GETPOST('month')) {
98 if (!$year && $month_start > $month_current) {
99 $year_start--;
100 $year_end--;
101 }
102 $month_end = $month_start - 1;
103 if ($month_end < 1) {
104 $month_end = 12;
105 } else {
106 $year_end++;
107 }
108 } else {
109 $month_end = $month_start;
110 }
111 $date_start = dol_get_first_day($year_start, $month_start, false);
112 $date_end = dol_get_last_day($year_end, $month_end, false);
113 }
114 if ($q == 1) {
115 $date_start = dol_get_first_day($year_start, 1, false);
116 $date_end = dol_get_last_day($year_start, 3, false);
117 }
118 if ($q == 2) {
119 $date_start = dol_get_first_day($year_start, 4, false);
120 $date_end = dol_get_last_day($year_start, 6, false);
121 }
122 if ($q == 3) {
123 $date_start = dol_get_first_day($year_start, 7, false);
124 $date_end = dol_get_last_day($year_start, 9, false);
125 }
126 if ($q == 4) {
127 $date_start = dol_get_first_day($year_start, 10, false);
128 $date_end = dol_get_last_day($year_start, 12, false);
129 }
130}
131
132if (($date_start < dol_time_plus_duree($date_end, -1, 'y')) || ($date_start > $date_end)) {
133 $date_end = dol_time_plus_duree($date_start - 1, 1, 'y');
134}
135
136// $date_start and $date_end are defined. We force $start_year and $nbofyear
137$tmps = dol_getdate($date_start);
138$start_year = $tmps['year'];
139$start_month = $tmps['mon'];
140$tmpe = dol_getdate($date_end);
141$year_end = $tmpe['year'];
142$month_end = $tmpe['mon'];
143$nbofyear = ($year_end - $start_year) + 1;
144
145$date_startmonth = $start_month;
146$date_endmonth = $month_end;
147
148$date_start_previous = dol_time_plus_duree($date_start, -1, 'y');
149$date_end_previous = dol_time_plus_duree($date_end, -1, 'y');
150
151//var_dump($date_start." ".$date_end." ".$date_start_previous." ".$date_end_previous." ".$nbofyear);
152
153
154if ($cat_id == 0) {
155 $cat_id = null;
156}
157
158// Define modecompta ('CREANCES-DETTES' or 'RECETTES-DEPENSES' or 'BOOKKEEPING')
159$modecompta = getDolGlobalString('ACCOUNTING_MODE');
160if (isModEnabled('accounting')) {
161 $modecompta = 'BOOKKEEPING';
162}
163if (GETPOST("modecompta", 'alpha')) {
164 $modecompta = GETPOST("modecompta", 'alpha');
165}
166
167$AccCat = new AccountancyCategory($db);
168
169// Security check
170$socid = GETPOSTINT('socid');
171if ($user->socid > 0) {
172 $socid = $user->socid;
173}
174$hookmanager->initHooks(['resultreportlist']);
175if (isModEnabled('comptabilite')) {
176 $result = restrictedArea($user, 'compta', '', '', 'resultat');
177}
178if (isModEnabled('accounting')) {
179 $result = restrictedArea($user, 'accounting', '', '', 'comptarapport');
180}
181
182/*
183 * View
184 */
185
186$months = array(
187 $langs->trans("MonthShort01"),
188 $langs->trans("MonthShort02"),
189 $langs->trans("MonthShort03"),
190 $langs->trans("MonthShort04"),
191 $langs->trans("MonthShort05"),
192 $langs->trans("MonthShort06"),
193 $langs->trans("MonthShort07"),
194 $langs->trans("MonthShort08"),
195 $langs->trans("MonthShort09"),
196 $langs->trans("MonthShort10"),
197 $langs->trans("MonthShort11"),
198 $langs->trans("MonthShort12"),
199);
200
201llxHeader('', $langs->trans('ReportInOut'));
202
203$builddate = 0;
204$name = '';
205$period = '';
206$calcmode = 0;
207
208$form = new Form($db);
209
210$textprevyear = '<a href="'.$_SERVER["PHP_SELF"].'?year='.($start_year - 1).'&showaccountdetail='.urlencode($showaccountdetail).'">'.img_previous().'</a>';
211$textnextyear = ' &nbsp; <a href="'.$_SERVER["PHP_SELF"].'?year='.($start_year + 1).'&showaccountdetail='.urlencode($showaccountdetail).'">'.img_next().'</a>';
212
213
214// Affiche en-tete de rapport
215if ($modecompta == "CREANCES-DETTES") {
216 $name = $langs->trans("AnnualByAccountDueDebtMode");
217 $calcmode = $langs->trans("CalcModeDebt");
218 $calcmode .= '<br>('.$langs->trans("SeeReportInInputOutputMode", '<a href="'.$_SERVER["PHP_SELF"].'?year='.$start_year.(GETPOST("month") > 0 ? '&month='.GETPOST("month") : '').'&modecompta=RECETTES-DEPENSES">', '</a>').')';
219 if (isModEnabled('accounting')) {
220 $calcmode .= '<br>('.$langs->trans("SeeReportInBookkeepingMode", '<a href="'.$_SERVER["PHP_SELF"].'?year='.$start_year.'&modecompta=BOOKKEEPING">', '</a>').')';
221 }
222 $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
223 //$periodlink='<a href="'.$_SERVER["PHP_SELF"].'?year='.($year-1).'&modecompta='.$modecompta.'">'.img_previous().'</a> <a href="'.$_SERVER["PHP_SELF"].'?year='.($year+1).'&modecompta='.$modecompta.'">'.img_next().'</a>';
224 $description = $langs->trans("RulesResultDue");
225 if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) {
226 $description .= $langs->trans("DepositsAreNotIncluded");
227 } else {
228 $description .= $langs->trans("DepositsAreIncluded");
229 }
230 if (getDolGlobalString('FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS')) {
231 $description .= $langs->trans("SupplierDepositsAreNotIncluded");
232 }
233 $builddate = dol_now();
234 //$exportlink=$langs->trans("NotYetAvailable");
235} elseif ($modecompta == "RECETTES-DEPENSES") {
236 $name = $langs->trans("AnnualByAccountInputOutputMode");
237 $calcmode = $langs->trans("CalcModePayment");
238 $calcmode .= '<br>('.$langs->trans("SeeReportInDueDebtMode", '<a href="'.$_SERVER["PHP_SELF"].'?year='.$year.(GETPOST("month") > 0 ? '&month='.GETPOST("month") : '').'&modecompta=CREANCES-DETTES">', '</a>').')';
239 if (isModEnabled('accounting')) {
240 $calcmode .= '<br>('.$langs->trans("SeeReportInBookkeepingMode", '<a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'&modecompta=BOOKKEEPING">', '</a>').')';
241 }
242 $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
243 //$periodlink='<a href="'.$_SERVER["PHP_SELF"].'?year='.($year-1).'&modecompta='.$modecompta.'">'.img_previous().'</a> <a href="'.$_SERVER["PHP_SELF"].'?year='.($year+1).'&modecompta='.$modecompta.'">'.img_next().'</a>';
244 $description = $langs->trans("RulesResultInOut");
245 $builddate = dol_now();
246 //$exportlink=$langs->trans("NotYetAvailable");
247} elseif ($modecompta == "BOOKKEEPING") {
248 $accountingreportstatic = new AccountancyReport($db);
249 $accountingreportstatic->fetch($id_report);
250 $reportLabel = '';
251 $reportLabel = $accountingreportstatic->label;
252
253 $name = $langs->trans("ReportInOut").', '.$langs->trans("ByPersonalizedAccountGroups").' '.$reportLabel;
254 $calcmode = $langs->trans("CalcModeBookkeeping");
255 //$calcmode.='<br>('.$langs->trans("SeeReportInDueDebtMode",'<a href="'.$_SERVER["PHP_SELF"].'?year_start='.$year_start.'&modecompta=CREANCES-DETTES">','</a>').')';
256 //$calcmode.='<br>('.$langs->trans("SeeReportInInputOutputMode",'<a href="'.$_SERVER["PHP_SELF"].'?year_start='.$year_start.'&modecompta=RECETTES-DEPENSES">','</a>').')';
257 $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
258 $arraylist = array('no' => $langs->trans("None"), 'yes' => $langs->trans("AccountWithNonZeroValues"), 'all' => $langs->trans("All"));
259 $period .= ' &nbsp; &nbsp; <span class="opacitymedium">'.$langs->trans("DetailBy").'</span> '.$form->selectarray('showaccountdetail', $arraylist, $showaccountdetail, 0);
260 $periodlink = $textprevyear.$textnextyear;
261 $exportlink = '';
262 $description = $langs->trans("RulesResultBookkeepingPersonalized");
263 $description .= ' ('.$langs->trans("SeePageForSetup", DOL_URL_ROOT.'/accountancy/admin/categories_list.php?search_country_id='.$mysoc->country_id.'&mainmenu=accountancy&leftmenu=accountancy_admin', $langs->transnoentitiesnoconv("Accountancy").' / '.$langs->transnoentitiesnoconv("Setup").' / '.$langs->transnoentitiesnoconv("AccountingCategory")).')';
264 $builddate = dol_now();
265}
266
267report_header($name, '', $period, $periodlink ?? '', $description, $builddate, $exportlink ?? '', array('modecompta' => $modecompta, 'action' => ''), $calcmode);
268
269
270if (isModEnabled('accounting') && $modecompta != 'BOOKKEEPING') {
271 print info_admin($langs->trans("WarningReportNotReliable"), 0, 0, '1');
272}
273
274
275$moreforfilter = '';
276
277print '<div class="div-table-responsive">';
278print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
279
280print '<tr class="liste_titre">';
281print '<th class="liste_titre">'.$langs->trans("AccountingCategory").'</th>';
282print '<th class="liste_titre"></th>';
283print '<th class="liste_titre right">'.$langs->trans("PreviousPeriod").'</th>';
284print '<th class="liste_titre right">'.$langs->trans("SelectedPeriod").'</th>';
285foreach ($months as $k => $v) {
286 if (($k + 1) >= $date_startmonth && (($date_startmonth <= $date_endmonth && ($k + 1) <= $date_endmonth) || ($date_startmonth > $date_endmonth))) {
287 print '<th class="liste_titre right width50">'.$langs->trans('MonthShort'.sprintf("%02d", ($k + 1))).'</th>';
288 }
289}
290if ($date_startmonth > $date_endmonth) {
291 foreach ($months as $k => $v) {
292 if (($k + 1) < $date_startmonth && ($k + 1) <= $date_endmonth) {
293 print '<th class="liste_titre right width50">'.$langs->trans('MonthShort'.sprintf("%02d", ($k + 1))).'</th>';
294 }
295 }
296}
297print '</tr>';
298
299if ($modecompta == 'CREANCES-DETTES') {
300 //if (!empty($date_start) && !empty($date_end))
301 // $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
302} elseif ($modecompta == "RECETTES-DEPENSES") {
303 //if (!empty($date_start) && !empty($date_end))
304 // $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
305} elseif ($modecompta == "BOOKKEEPING") {
306 // Get array of all report groups that are active
307 $cats = $AccCat->getCats(-1, 1, $id_report); // WARNING: Computed groups must be after group they include
308 $unactive_cats = $AccCat->getCats(-1, 0, $id_report);
309
310 /*
311 $sql = 'SELECT DISTINCT t.numero_compte as nb FROM '.MAIN_DB_PREFIX.'accounting_bookkeeping as t, '.MAIN_DB_PREFIX.'accounting_account as aa';
312 $sql.= " WHERE t.numero_compte = aa.account_number AND aa.fk_accounting_category = 0";
313 if (!empty($date_start) && !empty($date_end))
314 $sql.= " AND t.doc_date >= '".$db->idate($date_start)."' AND t.doc_date <= '".$db->idate($date_end)."'";
315 if (!empty($month)) {
316 $sql .= " AND MONTH(t.doc_date) = " . ((int) $month);
317 }
318 $resql = $db->query($sql);
319 if ($resql)
320 {
321 $num_rows = $db->num_rows($resql);
322 if ($num_rows) {
323
324 print '<div class="warning">Warning: There is '.$num_rows.' accounts in your ledger table that are not set into a reporting group</div>';
325 $i = 0;
326 //while ($i < $num) {
327 // $obj = $db->fetch_object($resql);
328 // $i++;
329 //}
330 }
331 }
332 else dol_print_error($db);
333 */
334
335 $j = 1;
336 $sommes = array();
337 $totPerAccount = array();
338 if (!is_array($cats) && $cats < 0) {
339 setEventMessages(null, $AccCat->errors, 'errors');
340 } elseif (is_array($cats) && count($cats) > 0) {
341 // Loop on each custom group of accounts
342 foreach ($cats as $cat) {
343 if (!empty($cat['category_type'])) {
344 // category calculated
345 // When we enter here, $sommes was filled by group of accounts
346
347 $formula = $cat['formula'];
348
349 print '<tr class="liste_total">';
350
351 // Code and Label
352 print '<td class="liste_total tdoverflowmax100" title="'.dol_escape_htmltag($cat['code']).'">';
353 print dol_escape_htmltag($cat['code']);
354 print '</td><td class="tdoverflowmax250 borderright" title="'.dol_escape_htmltag($cat['label']).'">';
355 print dol_escape_htmltag($cat['label']);
356 print '</td>';
357
358 $vars = array();
359
360 // Unactive categories have a total of 0 to be used in the formula.
361 foreach ($unactive_cats as $un_cat) {
362 $vars[$un_cat['code']] = 0;
363 }
364
365 // Previous Fiscal year (N-1)
366 foreach ($sommes as $code => $det) {
367 $vars[$code] = empty($det['NP']) ? 0 : $det['NP'];
368 }
369
370 $result = strtr($formula, $vars);
371 $result = str_replace('--', '+', $result);
372
373 if (preg_match('/[a-z]/i', $result)) {
374 $r = 'Error bad formula: '.$result;
375 $rshort = 'Err';
376 print '<td class="liste_total right"><span class="amount" title="'.dol_escape_htmltag($r).'">'.$rshort.'</span></td>';
377 } else {
378 //var_dump($result);
379 //$r = $AccCat->calculate($result);
380 $r = (float) dol_eval($result, 1, 1, '1');
381
382 if (getDolGlobalInt('ACCOUNTANCY_TRUNC_DECIMAL_ON_BALANCE_REPORT')) {
383 print '<td class="liste_total right"><span class="amount">'.price($r, 0, '', 1, 0, 0).'</span></td>';
384 } else {
385 print '<td class="liste_total right"><span class="amount">'.price($r).'</span></td>';
386 }
387 }
388
389 if (!isset($sommes[$code])) {
390 $sommes[$code] = array();
391 }
392 // Year N
393 $code = $cat['code']; // code of categorie ('VTE', 'MAR', ...)
394 if (empty($sommes[$code]['NP'])) {
395 $sommes[$code]['NP'] = $r;
396 } else {
397 $sommes[$code]['NP'] += $r;
398 }
399
400 // Current fiscal year (N)
401 if (is_array($sommes) && !empty($sommes)) {
402 foreach ($sommes as $code => $det) {
403 $vars[$code] = empty($det['N']) ? 0 : $det['N'];
404 }
405 }
406
407 $result = strtr($formula, $vars);
408 $result = str_replace('--', '+', $result);
409
410 //$r = $AccCat->calculate($result);
411 $r = (float) dol_eval($result, 1, 1, '1');
412
413 if (getDolGlobalInt('ACCOUNTANCY_TRUNC_DECIMAL_ON_BALANCE_REPORT')) {
414 print '<td class="liste_total right borderright"><span class="amount">'.price($r, 0, '', 1, 0, 0).'</span></td>';
415 } else {
416 print '<td class="liste_total right borderright"><span class="amount">'.price($r).'</span></td>';
417 }
418 if (empty($sommes[$code]['N'])) {
419 $sommes[$code]['N'] = $r;
420 } else {
421 $sommes[$code]['N'] += $r;
422 }
423
424 // Detail by month
425 foreach ($months as $k => $v) {
426 if (($k + 1) >= $date_startmonth && (($date_startmonth <= $date_endmonth && ($k + 1) <= $date_endmonth) || ($date_startmonth > $date_endmonth))) {
427 foreach ($sommes as $code => $det) {
428 $vars[$code] = empty($det['M'][$k]) ? 0 : $det['M'][$k];
429 }
430 $result = strtr($formula, $vars);
431 $result = str_replace('--', '+', $result);
432
433 //$r = $AccCat->calculate($result);
434 $r = (float) dol_eval($result, 1, 1, '1');
435
436
437 if (getDolGlobalInt('ACCOUNTANCY_TRUNC_DECIMAL_ON_BALANCE_REPORT')) {
438 print '<td class="liste_total right"><span class="amount">'.price($r, 0, '', 1, 0, 0).'</span></td>';
439 } else {
440 print '<td class="liste_total right"><span class="amount">'.price($r).'</span></td>';
441 }
442 if (empty($sommes[$code]['M'][$k])) {
443 $sommes[$code]['M'][$k] = $r;
444 } else {
445 $sommes[$code]['M'][$k] += $r;
446 }
447 }
448 }
449
450 if ($date_startmonth > $date_endmonth) {
451 foreach ($months as $k => $v) {
452 if (($k + 1) < $date_startmonth && ($k + 1) <= $date_endmonth) {
453 foreach ($sommes as $code => $det) {
454 $vars[$code] = empty($det['M'][$k]) ? 0 : $det['M'][$k];
455 }
456 $result = strtr($formula, $vars);
457 $result = str_replace('--', '+', $result);
458
459 //$r = $AccCat->calculate($result);
460 $r = (float) dol_eval($result, 1, 1, '1');
461
462 if (getDolGlobalInt('ACCOUNTANCY_TRUNC_DECIMAL_ON_BALANCE_REPORT')) {
463 print '<td class="liste_total right"><span class="amount">'.price($r, 0, '', 1, 0, 0).'</span></td>';
464 } else {
465 print '<td class="liste_total right"><span class="amount">'.price($r).'</span></td>';
466 }
467 if (empty($sommes[$code]['M'][$k])) {
468 $sommes[$code]['M'][$k] = $r;
469 } else {
470 $sommes[$code]['M'][$k] += $r;
471 }
472 }
473 }
474 }
475
476 print "</tr>\n";
477
478 //var_dump($sommes);
479 } else { // normal category
480 $code = $cat['code']; // Category code we process
481
482 $totCat = array();
483 $totCat['NP'] = 0;
484 $totCat['N'] = 0;
485 $totCat['M'] = array();
486 foreach ($months as $k => $v) {
487 $totCat['M'][$k] = 0;
488 }
489 if (!isset($sommes[$code])) {
490 $sommes[$code] = array();
491 }
492
493 // Set $cpts with array of accounts in the category/group
494 $cpts = $AccCat->getCptsCat($cat['rowid']);
495 // We should loop over empty $cpts array, else the category _code_ is used in the formula, which leads to wrong result if the code is a number.
496 if (empty($cpts)) {
497 $cpts[] = array();
498 }
499
500 $arrayofaccountforfilter = array();
501 foreach ($cpts as $i => $cpt) { // Loop on each account.
502 if (isset($cpt['account_number'])) {
503 $arrayofaccountforfilter[] = $cpt['account_number'];
504 }
505 }
506
507 // N-1
508 if (!empty($arrayofaccountforfilter)) {
509 $return = $AccCat->getSumDebitCredit($arrayofaccountforfilter, $date_start_previous, $date_end_previous, empty($cat['dc']) ? 0 : $cat['dc']);
510 if ($return < 0) {
511 setEventMessages(null, $AccCat->errors, 'errors');
512 $resultNP = 0;
513 } else {
514 foreach ($cpts as $i => $cpt) { // Loop on each account found
515 $resultNP = empty($AccCat->sdcperaccount[$cpt['account_number']]) ? 0 : $AccCat->sdcperaccount[$cpt['account_number']];
516
517 if (empty($totCat['NP'])) {
518 $totCat['NP'] = $resultNP;
519 } else {
520 $totCat['NP'] += $resultNP;
521 }
522 if (empty($sommes[$code]['NP'])) {
523 $sommes[$code]['NP'] = $resultNP;
524 } else {
525 $sommes[$code]['NP'] += $resultNP;
526 }
527 $totPerAccount[$cpt['account_number']]['NP'] = $resultNP;
528 }
529 }
530 }
531
532 // Set value into column N and month M ($totCat)
533 // This make 12 calls for each accountancy account (12 months M)
534 foreach ($cpts as $i => $cpt) { // Loop on each account.
535 // We make 1 loop for each account because we may want detail per account.
536 // @todo Optimize to ask a 'group by' account and a filter with account in (..., ...) in request
537
538 // Each month
539 $resultN = 0;
540 foreach ($months as $k => $v) {
541 $monthtoprocess = $k + 1; // ($k+1) is month 1, 2, ..., 12
542 $yeartoprocess = $start_year;
543 if (($k + 1) < $start_month) {
544 $yeartoprocess++;
545 }
546
547 //var_dump($monthtoprocess.'_'.$yeartoprocess);
548 if (isset($cpt['account_number'])) {
549 $return = $AccCat->getSumDebitCredit($cpt['account_number'], $date_start, $date_end, empty($cat['dc']) ? 0 : $cat['dc'], 'nofilter', $monthtoprocess, $yeartoprocess);
550 if ($return < 0) {
551 setEventMessages(null, $AccCat->errors, 'errors');
552 $resultM = 0;
553 } else {
554 $resultM = $AccCat->sdc;
555 }
556 } else {
557 $resultM = 0;
558 }
559 if (empty($totCat['M'][$k])) {
560 $totCat['M'][$k] = $resultM;
561 } else {
562 $totCat['M'][$k] += $resultM;
563 }
564 if (empty($sommes[$code]['M'][$k])) {
565 $sommes[$code]['M'][$k] = $resultM;
566 } else {
567 $sommes[$code]['M'][$k] += $resultM;
568 }
569 if (isset($cpt['account_number'])) {
570 $totPerAccount[$cpt['account_number']]['M'][$k] = $resultM;
571 }
572
573 $resultN += $resultM;
574 }
575
576 if (empty($totCat)) {
577 $totCat['N'] = $resultN;
578 } else {
579 $totCat['N'] += $resultN;
580 }
581 if (empty($sommes[$code]['N'])) {
582 $sommes[$code]['N'] = $resultN;
583 } else {
584 $sommes[$code]['N'] += $resultN;
585 }
586 if (isset($cpt['account_number'])) {
587 $totPerAccount[$cpt['account_number']]['N'] = $resultN;
588 }
589 }
590
591
592 // Now output columns for row $code ('VTE', 'MAR', ...)
593
594 print '<tr'.($showaccountdetail != 'no' ? ' class="trforbreak"' : '').'>';
595
596 // Column group
597 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($cat['code']).'">';
598 print dol_escape_htmltag($cat['code']);
599 print '</td>';
600
601 // Label of group
602 $labeltoshow = dol_escape_htmltag($cat['label']);
603 if (count($cpts) > 0 && !empty($cpts[0])) { // Show example of 5 first accounting accounts
604 $i = 0;
605 foreach ($cpts as $cpt) {
606 if ($i > 5) {
607 $labeltoshow .= '...)';
608 break;
609 }
610 if ($i > 0) {
611 $labeltoshow .= ', ';
612 } else {
613 $labeltoshow .= ' (';
614 }
615 $labeltoshow .= dol_escape_htmltag($cpt['account_number']);
616 $i++;
617 }
618 if ($i <= 5) {
619 $labeltoshow .= ')';
620 }
621 } else {
622 $labeltoshow .= ' - <span class="warning">'.$langs->trans("GroupIsEmptyCheckSetup").'</span>';
623 }
624 print '<td class="tdoverflowmax250 borderright" title="'.dol_escape_htmltag(dol_string_nohtmltag($labeltoshow)).'">';
625 print $labeltoshow;
626 print '</td>';
627
628 if (getDolGlobalInt('ACCOUNTANCY_TRUNC_DECIMAL_ON_BALANCE_REPORT')) {
629 print '<td class="right"><span class="amount">'.price($totCat['NP'], 0, '', 1, 0, 0).'</span></td>';
630 print '<td class="right borderright"><span class="amount">'.price($totCat['N'], 0, '', 1, 0, 0).'</span></td>';
631 } else {
632 print '<td class="right"><span class="amount">'.price($totCat['NP']).'</span></td>';
633 print '<td class="right borderright"><span class="amount">'.price($totCat['N']).'</span></td>';
634 }
635
636 // Each month
637 foreach ($totCat['M'] as $k => $v) {
638 if (($k + 1) >= $date_startmonth && (($date_startmonth <= $date_endmonth && ($k + 1) <= $date_endmonth) || ($date_startmonth > $date_endmonth))) {
639 if (getDolGlobalInt('ACCOUNTANCY_TRUNC_DECIMAL_ON_BALANCE_REPORT')) {
640 print '<td class="right nowraponall"><span class="amount">'.price($v, 0, '', 1, 0, 0).'</span></td>';
641 } else {
642 print '<td class="right nowraponall"><span class="amount">'.price($v).'</span></td>';
643 }
644 }
645 }
646 if ($date_startmonth > $date_endmonth) {
647 foreach ($totCat['M'] as $k => $v) {
648 if (($k + 1) < $date_startmonth && ($k + 1) <= $date_endmonth) {
649 if (getDolGlobalInt('ACCOUNTANCY_TRUNC_DECIMAL_ON_BALANCE_REPORT')) {
650 print '<td class="right nowraponall"><span class="amount">'.price($v, 0, '', 1, 0, 0).'</span></td>';
651 } else {
652 print '<td class="right nowraponall"><span class="amount">'.price($v).'</span></td>';
653 }
654 }
655 }
656 }
657
658 print "</tr>\n";
659
660 // Loop on detail of all accounts to output the detail
661 if ($showaccountdetail != 'no') {
662 foreach ($cpts as $i => $cpt) {
663 if (isset($cpt['account_number'])) {
664 $resultNP = $totPerAccount[$cpt['account_number']]['NP'];
665 $resultN = $totPerAccount[$cpt['account_number']]['N'];
666 } else {
667 $resultNP = 0;
668 $resultN = 0;
669 }
670
671 if ($showaccountdetail == 'all' || $resultN != 0) {
672 print '<tr>';
673 print '<td></td>';
674
675 if (isset($cpt['account_number'])) {
676 $labeldetail = ' &nbsp; &nbsp; '.length_accountg($cpt['account_number']).' - '.$cpt['account_label'];
677 } else {
678 $labeldetail = '-';
679 }
680
681 print '<td class="tdoverflowmax250 borderright" title="'.dol_escape_htmltag($labeldetail).'">';
682 print dol_escape_htmltag($labeldetail);
683 print '</td>';
684 if (getDolGlobalInt('ACCOUNTANCY_TRUNC_DECIMAL_ON_BALANCE_REPORT')) {
685 print '<td class="right"><span class="amount">'.price($resultNP, 0, '', 1, 0, 0).'</span></td>';
686 print '<td class="right borderright"><span class="amount">'.price($resultN, 0, '', 1, 0, 0).'</span></td>';
687 } else {
688 print '<td class="right"><span class="amount">'.price($resultNP).'</span></td>';
689 print '<td class="right borderright"><span class="amount">'.price($resultN).'</span></td>';
690 }
691
692 // Make one call for each month
693 foreach ($months as $k => $v) {
694 if (($k + 1) >= $date_startmonth && (($date_startmonth <= $date_endmonth && ($k + 1) <= $date_endmonth) || ($date_startmonth > $date_endmonth))) {
695 if (isset($cpt['account_number'])) {
696 $resultM = $totPerAccount[$cpt['account_number']]['M'][$k];
697 } else {
698 $resultM = 0;
699 }
700 print '<td class="right"><span class="amount">'.price($resultM).'</span></td>';
701 }
702 }
703 if ($date_startmonth > $date_endmonth) {
704 foreach ($months as $k => $v) {
705 if (($k + 1) < $date_startmonth && ($k + 1) <= $date_endmonth) {
706 if (isset($cpt['account_number'])) {
707 $resultM = empty($totPerAccount[$cpt['account_number']]['M'][$k]) ? 0 : $totPerAccount[$cpt['account_number']]['M'][$k];
708 } else {
709 $resultM = 0;
710 }
711 print '<td class="right"><span class="amount">'.price($resultM).'</span></td>';
712 }
713 }
714 }
715 print "</tr>\n";
716 }
717 }
718 }
719 }
720 }
721 }
722}
723
724print "</table>";
725print '</div>';
726
727// End of page
728llxFooter();
729$db->close();
$id
Definition account.php:48
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 categories of an accounting account.
Class to manage reports for accounting categories.
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_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition date.lib.php:125
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...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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.
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.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
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.