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';
37$langs->loadLangs(array(
'compta',
'bills',
'donation',
'salaries',
'accountancy'));
42$action =
GETPOST(
'action',
'aZ09');
43$cat_id =
GETPOST(
'account_category');
47$cancel =
GETPOST(
'cancel',
'alpha');
48$showaccountdetail =
GETPOST(
'showaccountdetail',
'aZ09') ?
GETPOST(
'showaccountdetail',
'aZ09') :
'no';
51$date_startmonth =
GETPOSTINT(
'date_startmonth');
68 $year_start = $year_current - ($nbofyear - 1);
70 $year_current = $year;
72 $year_start = $year - ($nbofyear - 1);
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);
78if (empty($date_start) || empty($date_end)) {
82 $year_end = $year_start + ($nbofyear - 1);
84 $date_startmonth = $month_start;
86 if (!$year && $month_start > $month_current) {
90 $month_end = $month_start - 1;
97 $month_end = $month_start;
126$start_year = $tmps[
'year'];
127$start_month = $tmps[
'mon'];
129$year_end = $tmpe[
'year'];
130$month_end = $tmpe[
'mon'];
131$nbofyear = ($year_end - $start_year) + 1;
133$date_startmonth = $start_month;
134$date_endmonth = $month_end;
148if (isModEnabled(
'accounting')) {
149 $modecompta =
'BOOKKEEPING';
151if (
GETPOST(
"modecompta",
'alpha')) {
152 $modecompta =
GETPOST(
"modecompta",
'alpha');
159if ($user->socid > 0) {
160 $socid = $user->socid;
162$hookmanager->initHooks([
'resultreportlist']);
163if (isModEnabled(
'comptabilite')) {
166if (isModEnabled(
'accounting')) {
167 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
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"),
189llxHeader(
'', $langs->trans(
'ReportInOut'));
191$form =
new Form($db);
193$textprevyear =
'<a href="'.$_SERVER[
"PHP_SELF"].
'?year='.($start_year - 1).
'&showaccountdetail='.urlencode($showaccountdetail).
'">'.
img_previous().
'</a>';
194$textnextyear =
' <a href="'.$_SERVER[
"PHP_SELF"].
'?year='.($start_year + 1).
'&showaccountdetail='.urlencode($showaccountdetail).
'">'.
img_next().
'</a>';
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>').
')';
206 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
208 $description = $langs->trans(
"RulesResultDue");
210 $description .= $langs->trans(
"DepositsAreNotIncluded");
212 $description .= $langs->trans(
"DepositsAreIncluded");
215 $description .= $langs->trans(
"SupplierDepositsAreNotIncluded");
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>').
')';
226 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
228 $description = $langs->trans(
"RulesResultInOut");
231} elseif ($modecompta ==
"BOOKKEEPING") {
232 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByPersonalizedAccountGroups");
233 $calcmode = $langs->trans(
"CalcModeBookkeeping");
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 .=
' <span class="opacitymedium">'.$langs->trans(
"DetailBy").
'</span> '.$form->selectarray(
'showaccountdetail', $arraylist, $showaccountdetail, 0);
239 $periodlink = $textprevyear.$textnextyear;
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")).
')';
246report_header($name,
'', $period, $periodlink ??
'', $description, $builddate, $exportlink ??
'', array(
'modecompta' => $modecompta,
'action' =>
''), $calcmode);
249if (isModEnabled(
'accounting') && $modecompta !=
'BOOKKEEPING') {
250 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0,
'1');
256print
'<div class="div-table-responsive">';
257print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
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>';
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>';
278if ($modecompta ==
'CREANCES-DETTES') {
281} elseif ($modecompta ==
"RECETTES-DEPENSES") {
284} elseif ($modecompta ==
"BOOKKEEPING") {
286 $cats = $AccCat->getCats();
287 $unactive_cats = $AccCat->getCats(-1, 0);
316 $totPerAccount = array();
317 if (!is_array($cats) && $cats < 0) {
319 } elseif (is_array($cats) && count($cats) > 0) {
321 foreach ($cats as $cat) {
322 if (!empty($cat[
'category_type'])) {
326 $formula = $cat[
'formula'];
328 print
'<tr class="liste_total">';
331 print
'<td class="liste_total tdoverflowmax100" title="'.dol_escape_htmltag($cat[
'code']).
'">';
333 print
'</td><td class="tdoverflowmax250 borderright" title="'.dol_escape_htmltag($cat[
'label']).
'">';
340 foreach ($unactive_cats as $un_cat) {
341 $vars[$un_cat[
'code']] = 0;
345 foreach ($sommes as $code => $det) {
346 $vars[$code] = empty($det[
'NP']) ? 0 : $det[
'NP'];
349 $result = strtr($formula, $vars);
350 $result = str_replace(
'--',
'+', $result);
352 if (preg_match(
'/[a-z]/i', $result)) {
353 $r =
'Error bad formula: '.$result;
355 print
'<td class="liste_total right"><span class="amount" title="'.dol_escape_htmltag($r).
'">'.$rshort.
'</span></td>';
359 $r = (float)
dol_eval($result, 1, 1,
'1');
362 print
'<td class="liste_total right"><span class="amount">'.price($r, 0,
'', 1, 0, 0).
'</span></td>';
364 print
'<td class="liste_total right"><span class="amount">'.price($r).
'</span></td>';
368 if (!isset($sommes[$code])) {
369 $sommes[$code] = array();
372 $code = $cat[
'code'];
373 if (empty($sommes[$code][
'NP'])) {
374 $sommes[$code][
'NP'] = $r;
376 $sommes[$code][
'NP'] += $r;
380 if (is_array($sommes) && !empty($sommes)) {
381 foreach ($sommes as $code => $det) {
382 $vars[$code] = empty($det[
'N']) ? 0 : $det[
'N'];
386 $result = strtr($formula, $vars);
387 $result = str_replace(
'--',
'+', $result);
390 $r = (float)
dol_eval($result, 1, 1,
'1');
393 print
'<td class="liste_total right borderright"><span class="amount">'.price($r, 0,
'', 1, 0, 0).
'</span></td>';
395 print
'<td class="liste_total right borderright"><span class="amount">'.price($r).
'</span></td>';
397 if (empty($sommes[$code][
'N'])) {
398 $sommes[$code][
'N'] = $r;
400 $sommes[$code][
'N'] += $r;
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];
409 $result = strtr($formula, $vars);
410 $result = str_replace(
'--',
'+', $result);
413 $r = (float)
dol_eval($result, 1, 1,
'1');
417 print
'<td class="liste_total right"><span class="amount">'.price($r, 0,
'', 1, 0, 0).
'</span></td>';
419 print
'<td class="liste_total right"><span class="amount">'.price($r).
'</span></td>';
421 if (empty($sommes[$code][
'M'][$k])) {
422 $sommes[$code][
'M'][$k] = $r;
424 $sommes[$code][
'M'][$k] += $r;
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];
435 $result = strtr($formula, $vars);
436 $result = str_replace(
'--',
'+', $result);
439 $r = (float)
dol_eval($result, 1, 1,
'1');
442 print
'<td class="liste_total right"><span class="amount">'.price($r, 0,
'', 1, 0, 0).
'</span></td>';
444 print
'<td class="liste_total right"><span class="amount">'.price($r).
'</span></td>';
446 if (empty($sommes[$code][
'M'][$k])) {
447 $sommes[$code][
'M'][$k] = $r;
449 $sommes[$code][
'M'][$k] += $r;
459 $code = $cat[
'code'];
464 $totCat[
'M'] = array();
465 foreach ($months as $k => $v) {
466 $totCat[
'M'][$k] = 0;
468 if (!isset($sommes[$code])) {
469 $sommes[$code] = array();
473 $cpts = $AccCat->getCptsCat($cat[
'rowid']);
479 $arrayofaccountforfilter = array();
480 foreach ($cpts as $i => $cpt) {
481 if (isset($cpt[
'account_number'])) {
482 $arrayofaccountforfilter[] = $cpt[
'account_number'];
487 if (!empty($arrayofaccountforfilter)) {
488 $return = $AccCat->getSumDebitCredit($arrayofaccountforfilter, $date_start_previous, $date_end_previous, empty($cat[
'dc']) ? 0 : $cat[
'dc']);
493 foreach ($cpts as $i => $cpt) {
494 $resultNP = empty($AccCat->sdcperaccount[$cpt[
'account_number']]) ? 0 : $AccCat->sdcperaccount[$cpt[
'account_number']];
496 if (empty($totCat[
'NP'])) {
497 $totCat[
'NP'] = $resultNP;
499 $totCat[
'NP'] += $resultNP;
501 if (empty($sommes[$code][
'NP'])) {
502 $sommes[$code][
'NP'] = $resultNP;
504 $sommes[$code][
'NP'] += $resultNP;
506 $totPerAccount[$cpt[
'account_number']][
'NP'] = $resultNP;
513 foreach ($cpts as $i => $cpt) {
519 foreach ($months as $k => $v) {
520 $monthtoprocess = $k + 1;
521 $yeartoprocess = $start_year;
522 if (($k + 1) < $start_month) {
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);
533 $resultM = $AccCat->sdc;
538 if (empty($totCat[
'M'][$k])) {
539 $totCat[
'M'][$k] = $resultM;
541 $totCat[
'M'][$k] += $resultM;
543 if (empty($sommes[$code][
'M'][$k])) {
544 $sommes[$code][
'M'][$k] = $resultM;
546 $sommes[$code][
'M'][$k] += $resultM;
548 if (isset($cpt[
'account_number'])) {
549 $totPerAccount[$cpt[
'account_number']][
'M'][$k] = $resultM;
552 $resultN += $resultM;
555 if (empty($totCat)) {
556 $totCat[
'N'] = $resultN;
558 $totCat[
'N'] += $resultN;
560 if (empty($sommes[$code][
'N'])) {
561 $sommes[$code][
'N'] = $resultN;
563 $sommes[$code][
'N'] += $resultN;
565 if (isset($cpt[
'account_number'])) {
566 $totPerAccount[$cpt[
'account_number']][
'N'] = $resultN;
573 print
'<tr'.($showaccountdetail !=
'no' ?
' class="trforbreak"' :
'').
'>';
576 print
'<td class="tdoverflowmax100" title="'.dol_escape_htmltag($cat[
'code']).
'">';
582 if (count($cpts) > 0 && !empty($cpts[0])) {
584 foreach ($cpts as $cpt) {
586 $labeltoshow .=
'...)';
590 $labeltoshow .=
', ';
592 $labeltoshow .=
' (';
601 $labeltoshow .=
' - <span class="warning">'.$langs->trans(
"GroupIsEmptyCheckSetup").
'</span>';
603 print
'<td class="tdoverflowmax250 borderright" title="'.dol_escape_htmltag(
dol_string_nohtmltag($labeltoshow)).
'">';
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>';
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>';
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))) {
619 print
'<td class="right nowraponall"><span class="amount">'.price($v, 0,
'', 1, 0, 0).
'</span></td>';
621 print
'<td class="right nowraponall"><span class="amount">'.price($v).
'</span></td>';
625 if ($date_startmonth > $date_endmonth) {
626 foreach ($totCat[
'M'] as $k => $v) {
627 if (($k + 1) < $date_startmonth && ($k + 1) <= $date_endmonth) {
629 print
'<td class="right nowraponall"><span class="amount">'.price($v, 0,
'', 1, 0, 0).
'</span></td>';
631 print
'<td class="right nowraponall"><span class="amount">'.price($v).
'</span></td>';
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'];
650 if ($showaccountdetail ==
'all' || $resultN != 0) {
654 if (isset($cpt[
'account_number'])) {
655 $labeldetail =
' '.length_accountg($cpt[
'account_number']).
' - '.$cpt[
'account_label'];
660 print
'<td class="tdoverflowmax250 borderright" title="'.dol_escape_htmltag($labeldetail).
'">';
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>';
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>';
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];
679 print
'<td class="right"><span class="amount">'.price($resultM).
'</span></td>';
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];
690 print
'<td class="right"><span class="amount">'.price($resultM).
'</span></td>';
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.
Class to manage categories of an accounting account.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
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.