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