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