29require
'../../main.inc.php';
30require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
31require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
32require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
33require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formaccounting.class.php';
34require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountancycategory.class.php';
35require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountancyreport.class.php';
47$langs->loadLangs(array(
'compta',
'bills',
'donation',
'salaries',
'accountancy'));
54$action =
GETPOST(
'action',
'aZ09');
55$cat_id =
GETPOST(
'account_category');
59$cancel =
GETPOST(
'cancel',
'alpha');
60$showaccountdetail =
GETPOST(
'showaccountdetail',
'aZ09') ?
GETPOST(
'showaccountdetail',
'aZ09') :
'no';
63$date_startmonth =
GETPOSTINT(
'date_startmonth');
80 $year_start = $year_current - ($nbofyear - 1);
82 $year_current = $year;
84 $year_start = $year - ($nbofyear - 1);
86$date_start =
dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
87$date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
90if (empty($date_start) || empty($date_end)) {
94 $year_end = $year_start + ($nbofyear - 1);
96 $date_startmonth = $month_start;
98 if (!$year && $month_start > $month_current) {
102 $month_end = $month_start - 1;
103 if ($month_end < 1) {
109 $month_end = $month_start;
138$start_year = $tmps[
'year'];
139$start_month = $tmps[
'mon'];
141$year_end = $tmpe[
'year'];
142$month_end = $tmpe[
'mon'];
143$nbofyear = ($year_end - $start_year) + 1;
145$date_startmonth = $start_month;
146$date_endmonth = $month_end;
160if (isModEnabled(
'accounting')) {
161 $modecompta =
'BOOKKEEPING';
163if (
GETPOST(
"modecompta",
'alpha')) {
164 $modecompta =
GETPOST(
"modecompta",
'alpha');
171if ($user->socid > 0) {
172 $socid = $user->socid;
174$hookmanager->initHooks([
'resultreportlist']);
175if (isModEnabled(
'comptabilite')) {
178if (isModEnabled(
'accounting')) {
179 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
187 $langs->trans(
"MonthShort01"),
188 $langs->trans(
"MonthShort02"),
189 $langs->trans(
"MonthShort03"),
190 $langs->trans(
"MonthShort04"),
191 $langs->trans(
"MonthShort05"),
192 $langs->trans(
"MonthShort06"),
193 $langs->trans(
"MonthShort07"),
194 $langs->trans(
"MonthShort08"),
195 $langs->trans(
"MonthShort09"),
196 $langs->trans(
"MonthShort10"),
197 $langs->trans(
"MonthShort11"),
198 $langs->trans(
"MonthShort12"),
201llxHeader(
'', $langs->trans(
'ReportInOut'));
208$form =
new Form($db);
210$textprevyear =
'<a href="'.$_SERVER[
"PHP_SELF"].
'?year='.($start_year - 1).
'&showaccountdetail='.urlencode($showaccountdetail).
'">'.
img_previous().
'</a>';
211$textnextyear =
' <a href="'.$_SERVER[
"PHP_SELF"].
'?year='.($start_year + 1).
'&showaccountdetail='.urlencode($showaccountdetail).
'">'.
img_next().
'</a>';
215if ($modecompta ==
"CREANCES-DETTES") {
216 $name = $langs->trans(
"AnnualByAccountDueDebtMode");
217 $calcmode = $langs->trans(
"CalcModeDebt");
218 $calcmode .=
'<br>('.$langs->trans(
"SeeReportInInputOutputMode",
'<a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$start_year.(GETPOST(
"month") > 0 ?
'&month='.GETPOST(
"month") :
'').
'&modecompta=RECETTES-DEPENSES">',
'</a>').
')';
219 if (isModEnabled(
'accounting')) {
220 $calcmode .=
'<br>('.$langs->trans(
"SeeReportInBookkeepingMode",
'<a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$start_year.
'&modecompta=BOOKKEEPING">',
'</a>').
')';
222 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
224 $description = $langs->trans(
"RulesResultDue");
226 $description .= $langs->trans(
"DepositsAreNotIncluded");
228 $description .= $langs->trans(
"DepositsAreIncluded");
231 $description .= $langs->trans(
"SupplierDepositsAreNotIncluded");
235} elseif ($modecompta ==
"RECETTES-DEPENSES") {
236 $name = $langs->trans(
"AnnualByAccountInputOutputMode");
237 $calcmode = $langs->trans(
"CalcModePayment");
238 $calcmode .=
'<br>('.$langs->trans(
"SeeReportInDueDebtMode",
'<a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$year.(GETPOST(
"month") > 0 ?
'&month='.GETPOST(
"month") :
'').
'&modecompta=CREANCES-DETTES">',
'</a>').
')';
239 if (isModEnabled(
'accounting')) {
240 $calcmode .=
'<br>('.$langs->trans(
"SeeReportInBookkeepingMode",
'<a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$year.
'&modecompta=BOOKKEEPING">',
'</a>').
')';
242 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
244 $description = $langs->trans(
"RulesResultInOut");
247} elseif ($modecompta ==
"BOOKKEEPING") {
249 $accountingreportstatic->fetch($id_report);
251 $reportLabel = $accountingreportstatic->label;
253 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByPersonalizedAccountGroups").
' '.$reportLabel;
254 $calcmode = $langs->trans(
"CalcModeBookkeeping");
257 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
258 $arraylist = array(
'no' => $langs->trans(
"None"),
'yes' => $langs->trans(
"AccountWithNonZeroValues"),
'all' => $langs->trans(
"All"));
259 $period .=
' <span class="opacitymedium">'.$langs->trans(
"DetailBy").
'</span> '.$form->selectarray(
'showaccountdetail', $arraylist, $showaccountdetail, 0);
260 $periodlink = $textprevyear.$textnextyear;
262 $description = $langs->trans(
"RulesResultBookkeepingPersonalized");
263 $description .=
' ('.$langs->trans(
"SeePageForSetup", DOL_URL_ROOT.
'/accountancy/admin/categories_list.php?search_country_id='.$mysoc->country_id.
'&mainmenu=accountancy&leftmenu=accountancy_admin', $langs->transnoentitiesnoconv(
"Accountancy").
' / '.$langs->transnoentitiesnoconv(
"Setup").
' / '.$langs->transnoentitiesnoconv(
"AccountingCategory")).
')';
267report_header($name,
'', $period, $periodlink ??
'', $description, $builddate, $exportlink ??
'', array(
'modecompta' => $modecompta,
'action' =>
''), $calcmode);
270if (isModEnabled(
'accounting') && $modecompta !=
'BOOKKEEPING') {
271 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0,
'1');
277print
'<div class="div-table-responsive">';
278print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
280print
'<tr class="liste_titre">';
281print
'<th class="liste_titre">'.$langs->trans(
"AccountingCategory").
'</th>';
282print
'<th class="liste_titre"></th>';
283print
'<th class="liste_titre right">'.$langs->trans(
"PreviousPeriod").
'</th>';
284print
'<th class="liste_titre right">'.$langs->trans(
"SelectedPeriod").
'</th>';
285foreach ($months as $k => $v) {
286 if (($k + 1) >= $date_startmonth && (($date_startmonth <= $date_endmonth && ($k + 1) <= $date_endmonth) || ($date_startmonth > $date_endmonth))) {
287 print
'<th class="liste_titre right width50">'.$langs->trans(
'MonthShort'.sprintf(
"%02d", ($k + 1))).
'</th>';
290if ($date_startmonth > $date_endmonth) {
291 foreach ($months as $k => $v) {
292 if (($k + 1) < $date_startmonth && ($k + 1) <= $date_endmonth) {
293 print
'<th class="liste_titre right width50">'.$langs->trans(
'MonthShort'.sprintf(
"%02d", ($k + 1))).
'</th>';
299if ($modecompta ==
'CREANCES-DETTES') {
302} elseif ($modecompta ==
"RECETTES-DEPENSES") {
305} elseif ($modecompta ==
"BOOKKEEPING") {
307 $cats = $AccCat->getCats(-1, 1, $id_report);
308 $unactive_cats = $AccCat->getCats(-1, 0, $id_report);
337 $totPerAccount = array();
338 if (!is_array($cats) && $cats < 0) {
340 } elseif (is_array($cats) && count($cats) > 0) {
342 foreach ($cats as $cat) {
343 if (!empty($cat[
'category_type'])) {
347 $formula = $cat[
'formula'];
349 print
'<tr class="liste_total">';
352 print
'<td class="liste_total tdoverflowmax100" title="'.dol_escape_htmltag($cat[
'code']).
'">';
354 print
'</td><td class="tdoverflowmax250 borderright" title="'.dol_escape_htmltag($cat[
'label']).
'">';
361 foreach ($unactive_cats as $un_cat) {
362 $vars[$un_cat[
'code']] = 0;
366 foreach ($sommes as $code => $det) {
367 $vars[$code] = empty($det[
'NP']) ? 0 : $det[
'NP'];
370 $result = strtr($formula, $vars);
371 $result = str_replace(
'--',
'+', $result);
373 if (preg_match(
'/[a-z]/i', $result)) {
374 $r =
'Error bad formula: '.$result;
376 print
'<td class="liste_total right"><span class="amount" title="'.dol_escape_htmltag($r).
'">'.$rshort.
'</span></td>';
380 $r = (float)
dol_eval($result, 1, 1,
'1');
383 print
'<td class="liste_total right"><span class="amount">'.price($r, 0,
'', 1, 0, 0).
'</span></td>';
385 print
'<td class="liste_total right"><span class="amount">'.price($r).
'</span></td>';
389 if (!isset($sommes[$code])) {
390 $sommes[$code] = array();
393 $code = $cat[
'code'];
394 if (empty($sommes[$code][
'NP'])) {
395 $sommes[$code][
'NP'] = $r;
397 $sommes[$code][
'NP'] += $r;
401 if (is_array($sommes) && !empty($sommes)) {
402 foreach ($sommes as $code => $det) {
403 $vars[$code] = empty($det[
'N']) ? 0 : $det[
'N'];
407 $result = strtr($formula, $vars);
408 $result = str_replace(
'--',
'+', $result);
411 $r = (float)
dol_eval($result, 1, 1,
'1');
414 print
'<td class="liste_total right borderright"><span class="amount">'.price($r, 0,
'', 1, 0, 0).
'</span></td>';
416 print
'<td class="liste_total right borderright"><span class="amount">'.price($r).
'</span></td>';
418 if (empty($sommes[$code][
'N'])) {
419 $sommes[$code][
'N'] = $r;
421 $sommes[$code][
'N'] += $r;
425 foreach ($months as $k => $v) {
426 if (($k + 1) >= $date_startmonth && (($date_startmonth <= $date_endmonth && ($k + 1) <= $date_endmonth) || ($date_startmonth > $date_endmonth))) {
427 foreach ($sommes as $code => $det) {
428 $vars[$code] = empty($det[
'M'][$k]) ? 0 : $det[
'M'][$k];
430 $result = strtr($formula, $vars);
431 $result = str_replace(
'--',
'+', $result);
434 $r = (float)
dol_eval($result, 1, 1,
'1');
438 print
'<td class="liste_total right"><span class="amount">'.price($r, 0,
'', 1, 0, 0).
'</span></td>';
440 print
'<td class="liste_total right"><span class="amount">'.price($r).
'</span></td>';
442 if (empty($sommes[$code][
'M'][$k])) {
443 $sommes[$code][
'M'][$k] = $r;
445 $sommes[$code][
'M'][$k] += $r;
450 if ($date_startmonth > $date_endmonth) {
451 foreach ($months as $k => $v) {
452 if (($k + 1) < $date_startmonth && ($k + 1) <= $date_endmonth) {
453 foreach ($sommes as $code => $det) {
454 $vars[$code] = empty($det[
'M'][$k]) ? 0 : $det[
'M'][$k];
456 $result = strtr($formula, $vars);
457 $result = str_replace(
'--',
'+', $result);
460 $r = (float)
dol_eval($result, 1, 1,
'1');
463 print
'<td class="liste_total right"><span class="amount">'.price($r, 0,
'', 1, 0, 0).
'</span></td>';
465 print
'<td class="liste_total right"><span class="amount">'.price($r).
'</span></td>';
467 if (empty($sommes[$code][
'M'][$k])) {
468 $sommes[$code][
'M'][$k] = $r;
470 $sommes[$code][
'M'][$k] += $r;
480 $code = $cat[
'code'];
485 $totCat[
'M'] = array();
486 foreach ($months as $k => $v) {
487 $totCat[
'M'][$k] = 0;
489 if (!isset($sommes[$code])) {
490 $sommes[$code] = array();
494 $cpts = $AccCat->getCptsCat($cat[
'rowid']);
500 $arrayofaccountforfilter = array();
501 foreach ($cpts as $i => $cpt) {
502 if (isset($cpt[
'account_number'])) {
503 $arrayofaccountforfilter[] = $cpt[
'account_number'];
508 if (!empty($arrayofaccountforfilter)) {
509 $return = $AccCat->getSumDebitCredit($arrayofaccountforfilter, $date_start_previous, $date_end_previous, empty($cat[
'dc']) ? 0 : $cat[
'dc']);
514 foreach ($cpts as $i => $cpt) {
515 $resultNP = empty($AccCat->sdcperaccount[$cpt[
'account_number']]) ? 0 : $AccCat->sdcperaccount[$cpt[
'account_number']];
517 if (empty($totCat[
'NP'])) {
518 $totCat[
'NP'] = $resultNP;
520 $totCat[
'NP'] += $resultNP;
522 if (empty($sommes[$code][
'NP'])) {
523 $sommes[$code][
'NP'] = $resultNP;
525 $sommes[$code][
'NP'] += $resultNP;
527 $totPerAccount[$cpt[
'account_number']][
'NP'] = $resultNP;
534 foreach ($cpts as $i => $cpt) {
540 foreach ($months as $k => $v) {
541 $monthtoprocess = $k + 1;
542 $yeartoprocess = $start_year;
543 if (($k + 1) < $start_month) {
548 if (isset($cpt[
'account_number'])) {
549 $return = $AccCat->getSumDebitCredit($cpt[
'account_number'], $date_start, $date_end, empty($cat[
'dc']) ? 0 : $cat[
'dc'],
'nofilter', $monthtoprocess, $yeartoprocess);
554 $resultM = $AccCat->sdc;
559 if (empty($totCat[
'M'][$k])) {
560 $totCat[
'M'][$k] = $resultM;
562 $totCat[
'M'][$k] += $resultM;
564 if (empty($sommes[$code][
'M'][$k])) {
565 $sommes[$code][
'M'][$k] = $resultM;
567 $sommes[$code][
'M'][$k] += $resultM;
569 if (isset($cpt[
'account_number'])) {
570 $totPerAccount[$cpt[
'account_number']][
'M'][$k] = $resultM;
573 $resultN += $resultM;
576 if (empty($totCat)) {
577 $totCat[
'N'] = $resultN;
579 $totCat[
'N'] += $resultN;
581 if (empty($sommes[$code][
'N'])) {
582 $sommes[$code][
'N'] = $resultN;
584 $sommes[$code][
'N'] += $resultN;
586 if (isset($cpt[
'account_number'])) {
587 $totPerAccount[$cpt[
'account_number']][
'N'] = $resultN;
594 print
'<tr'.($showaccountdetail !=
'no' ?
' class="trforbreak"' :
'').
'>';
597 print
'<td class="tdoverflowmax100" title="'.dol_escape_htmltag($cat[
'code']).
'">';
603 if (count($cpts) > 0 && !empty($cpts[0])) {
605 foreach ($cpts as $cpt) {
607 $labeltoshow .=
'...)';
611 $labeltoshow .=
', ';
613 $labeltoshow .=
' (';
622 $labeltoshow .=
' - <span class="warning">'.$langs->trans(
"GroupIsEmptyCheckSetup").
'</span>';
624 print
'<td class="tdoverflowmax250 borderright" title="'.dol_escape_htmltag(
dol_string_nohtmltag($labeltoshow)).
'">';
629 print
'<td class="right"><span class="amount">'.price($totCat[
'NP'], 0,
'', 1, 0, 0).
'</span></td>';
630 print
'<td class="right borderright"><span class="amount">'.price($totCat[
'N'], 0,
'', 1, 0, 0).
'</span></td>';
632 print
'<td class="right"><span class="amount">'.price($totCat[
'NP']).
'</span></td>';
633 print
'<td class="right borderright"><span class="amount">'.price($totCat[
'N']).
'</span></td>';
637 foreach ($totCat[
'M'] as $k => $v) {
638 if (($k + 1) >= $date_startmonth && (($date_startmonth <= $date_endmonth && ($k + 1) <= $date_endmonth) || ($date_startmonth > $date_endmonth))) {
640 print
'<td class="right nowraponall"><span class="amount">'.price($v, 0,
'', 1, 0, 0).
'</span></td>';
642 print
'<td class="right nowraponall"><span class="amount">'.price($v).
'</span></td>';
646 if ($date_startmonth > $date_endmonth) {
647 foreach ($totCat[
'M'] as $k => $v) {
648 if (($k + 1) < $date_startmonth && ($k + 1) <= $date_endmonth) {
650 print
'<td class="right nowraponall"><span class="amount">'.price($v, 0,
'', 1, 0, 0).
'</span></td>';
652 print
'<td class="right nowraponall"><span class="amount">'.price($v).
'</span></td>';
661 if ($showaccountdetail !=
'no') {
662 foreach ($cpts as $i => $cpt) {
663 if (isset($cpt[
'account_number'])) {
664 $resultNP = $totPerAccount[$cpt[
'account_number']][
'NP'];
665 $resultN = $totPerAccount[$cpt[
'account_number']][
'N'];
671 if ($showaccountdetail ==
'all' || $resultN != 0) {
675 if (isset($cpt[
'account_number'])) {
676 $labeldetail =
' '.length_accountg($cpt[
'account_number']).
' - '.$cpt[
'account_label'];
681 print
'<td class="tdoverflowmax250 borderright" title="'.dol_escape_htmltag($labeldetail).
'">';
685 print
'<td class="right"><span class="amount">'.price($resultNP, 0,
'', 1, 0, 0).
'</span></td>';
686 print
'<td class="right borderright"><span class="amount">'.price($resultN, 0,
'', 1, 0, 0).
'</span></td>';
688 print
'<td class="right"><span class="amount">'.price($resultNP).
'</span></td>';
689 print
'<td class="right borderright"><span class="amount">'.price($resultN).
'</span></td>';
693 foreach ($months as $k => $v) {
694 if (($k + 1) >= $date_startmonth && (($date_startmonth <= $date_endmonth && ($k + 1) <= $date_endmonth) || ($date_startmonth > $date_endmonth))) {
695 if (isset($cpt[
'account_number'])) {
696 $resultM = $totPerAccount[$cpt[
'account_number']][
'M'][$k];
700 print
'<td class="right"><span class="amount">'.price($resultM).
'</span></td>';
703 if ($date_startmonth > $date_endmonth) {
704 foreach ($months as $k => $v) {
705 if (($k + 1) < $date_startmonth && ($k + 1) <= $date_endmonth) {
706 if (isset($cpt[
'account_number'])) {
707 $resultM = empty($totPerAccount[$cpt[
'account_number']][
'M'][$k]) ? 0 : $totPerAccount[$cpt[
'account_number']][
'M'][$k];
711 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.
Class to manage reports for accounting categories.
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.