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