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';
36 $langs->loadLangs(array(
'compta',
'bills',
'donation',
'salaries',
'accountancy'));
41 $action =
GETPOST(
'action',
'aZ09');
42 $cat_id =
GETPOST(
'account_category');
45 $rowid =
GETPOST(
'rowid',
'int');
46 $cancel =
GETPOST(
'cancel',
'alpha');
47 $showaccountdetail =
GETPOST(
'showaccountdetail',
'aZ09') ?
GETPOST(
'showaccountdetail',
'aZ09') :
'no';
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');
67 $year_start = $year_current - ($nbofyear - 1);
69 $year_current = $year;
71 $year_start = $year - ($nbofyear - 1);
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);
77 if (empty($date_start) || empty($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;
85 if (!$year && $month_start > $month_current) {
89 $month_end = $month_start - 1;
96 $month_end = $month_start;
119 if (($date_start <
dol_time_plus_duree($date_end, -1,
'y')) || ($date_start > $date_end)) {
125 $start_year = $tmps[
'year'];
126 $start_month = $tmps[
'mon'];
128 $year_end = $tmpe[
'year'];
129 $month_end = $tmpe[
'mon'];
130 $nbofyear = ($year_end - $start_year) + 1;
143 $modecompta = $conf->global->ACCOUNTING_MODE;
145 $modecompta =
'BOOKKEEPING';
147 if (
GETPOST(
"modecompta",
'alpha')) {
148 $modecompta =
GETPOST(
"modecompta",
'alpha');
154 $socid =
GETPOST(
'socid',
'int');
155 if ($user->socid > 0) {
156 $socid = $user->socid;
162 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
164 $hookmanager->initHooks([
'resultreportlist']);
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"),
185 llxheader(
'', $langs->trans(
'ReportInOut'));
190 $textprevyear =
'<a href="'.$_SERVER[
"PHP_SELF"].
'?year='.($start_year - 1).
'&showaccountdetail='.urlencode($showaccountdetail).
'">'.
img_previous().
'</a>';
191 $textnextyear =
' <a href="'.$_SERVER[
"PHP_SELF"].
'?year='.($start_year + 1).
'&showaccountdetail='.urlencode($showaccountdetail).
'">'.
img_next().
'</a>';
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>').
')';
201 $calcmode .=
'<br>('.$langs->trans(
"SeeReportInBookkeepingMode",
'<a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$start_year.
'&modecompta=BOOKKEEPING">',
'</a>').
')';
203 $period =
$form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.
$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
205 $description = $langs->trans(
"RulesResultDue");
206 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
207 $description .= $langs->trans(
"DepositsAreNotIncluded");
209 $description .= $langs->trans(
"DepositsAreIncluded");
211 if (!empty($conf->global->FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS)) {
212 $description .= $langs->trans(
"SupplierDepositsAreNotIncluded");
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>').
')';
221 $calcmode .=
'<br>('.$langs->trans(
"SeeReportInBookkeepingMode",
'<a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$year.
'&modecompta=BOOKKEEPING">',
'</a>').
')';
223 $period =
$form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.
$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
225 $description = $langs->trans(
"RulesResultInOut");
228 } elseif ($modecompta ==
"BOOKKEEPING") {
229 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByPersonalizedAccountGroups");
230 $calcmode = $langs->trans(
"CalcModeBookkeeping");
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 .=
' <span class="opacitymedium">'.$langs->trans(
"DetailBy").
'</span> '.
$form->selectarray(
'showaccountdetail', $arraylist, $showaccountdetail, 0);
236 $periodlink = $textprevyear.$textnextyear;
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")).
')';
243 report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, array(
'modecompta'=>$modecompta,
'action' =>
''), $calcmode);
246 if (
isModEnabled(
'accounting') && $modecompta !=
'BOOKKEEPING') {
247 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0, 1);
253 print
'<div class="div-table-responsive">';
254 print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
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>';
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>';
273 if ($modecompta ==
'CREANCES-DETTES') {
276 } elseif ($modecompta ==
"RECETTES-DEPENSES") {
279 } elseif ($modecompta ==
"BOOKKEEPING") {
281 $cats = $AccCat->getCats();
282 $unactive_cats = $AccCat->getCats(-1, 0);
311 $totPerAccount = array();
312 if (!is_array($cats) && $cats < 0) {
314 } elseif (is_array($cats) && count($cats) > 0) {
316 foreach ($cats as $cat) {
317 if (!empty($cat[
'category_type'])) {
321 $formula = $cat[
'formula'];
323 print
'<tr class="liste_total">';
326 print
'<td class="liste_total tdoverflowmax100" title="'.dol_escape_htmltag($cat[
'code']).
'">';
328 print
'</td><td class="tdoverflowmax250 borderright" title="'.dol_escape_htmltag($cat[
'label']).
'">';
335 foreach ($unactive_cats as $un_cat) {
336 $vars[$un_cat[
'code']] = 0;
340 foreach ($sommes as $code => $det) {
341 $vars[$code] = empty($det[
'NP']) ? 0 : $det[
'NP'];
344 $result = strtr($formula, $vars);
345 $result = str_replace(
'--',
'+', $result);
347 if (preg_match(
'/[a-z]/i', $result)) {
348 $r =
'Error bad formula: '.$result;
350 print
'<td class="liste_total right"><span class="amount" title="'.dol_escape_htmltag($r).
'">'.$rshort.
'</span></td>';
359 print
'<td class="liste_total right"><span class="amount">'.price($r).
'</span></td>';
363 $code = $cat[
'code'];
364 if (empty($sommes[$code][
'NP'])) {
365 $sommes[$code][
'NP'] = $r;
367 $sommes[$code][
'NP'] += $r;
371 if (is_array($sommes) && !empty($sommes)) {
372 foreach ($sommes as $code => $det) {
373 $vars[$code] = empty($det[
'N']) ? 0 : $det[
'N'];
377 $result = strtr($formula, $vars);
378 $result = str_replace(
'--',
'+', $result);
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;
390 $sommes[$code][
'N'] += $r;
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];
399 $result = strtr($formula, $vars);
400 $result = str_replace(
'--',
'+', $result);
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;
412 $sommes[$code][
'M'][$k] += $r;
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];
422 $result = strtr($formula, $vars);
423 $result = str_replace(
'--',
'+', $result);
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;
435 $sommes[$code][
'M'][$k] += $r;
444 $code = $cat[
'code'];
449 $totCat[
'M'] = array();
450 foreach ($months as $k => $v) {
451 $totCat[
'M'][$k] = 0;
455 $cpts = $AccCat->getCptsCat($cat[
'rowid']);
461 $arrayofaccountforfilter = array();
462 foreach ($cpts as $i => $cpt) {
463 if (isset($cpt[
'account_number'])) {
464 $arrayofaccountforfilter[] = $cpt[
'account_number'];
469 if (!empty($arrayofaccountforfilter)) {
470 $return = $AccCat->getSumDebitCredit($arrayofaccountforfilter, $date_start_previous, $date_end_previous, empty($cat[
'dc']) ? 0 : $cat[
'dc']);
475 foreach ($cpts as $i => $cpt) {
476 $resultNP = empty($AccCat->sdcperaccount[$cpt[
'account_number']]) ? 0 : $AccCat->sdcperaccount[$cpt[
'account_number']];
478 if (empty($totCat[
'NP'])) {
479 $totCat[
'NP'] = $resultNP;
481 $totCat[
'NP'] += $resultNP;
483 if (empty($sommes[$code][
'NP'])) {
484 $sommes[$code][
'NP'] = $resultNP;
486 $sommes[$code][
'NP'] += $resultNP;
488 $totPerAccount[$cpt[
'account_number']][
'NP'] = $resultNP;
495 foreach ($cpts as $i => $cpt) {
501 foreach ($months as $k => $v) {
502 $monthtoprocess = $k + 1;
503 $yeartoprocess = $start_year;
504 if (($k + 1) < $start_month) {
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);
515 $resultM = $AccCat->sdc;
520 if (empty($totCat[
'M'][$k])) {
521 $totCat[
'M'][$k] = $resultM;
523 $totCat[
'M'][$k] += $resultM;
525 if (empty($sommes[$code][
'M'][$k])) {
526 $sommes[$code][
'M'][$k] = $resultM;
528 $sommes[$code][
'M'][$k] += $resultM;
530 if (isset($cpt[
'account_number'])) {
531 $totPerAccount[$cpt[
'account_number']][
'M'][$k] = $resultM;
534 $resultN += $resultM;
537 if (empty($totCat)) {
538 $totCat[
'N'] = $resultN;
540 $totCat[
'N'] += $resultN;
542 if (empty($sommes[$code][
'N'])) {
543 $sommes[$code][
'N'] = $resultN;
545 $sommes[$code][
'N'] += $resultN;
547 if (isset($cpt[
'account_number'])) {
548 $totPerAccount[$cpt[
'account_number']][
'N'] = $resultN;
555 print
'<tr'.($showaccountdetail !=
'no' ?
' class="trforbreak"' :
'').
'>';
558 print
'<td class="tdoverflowmax100" title="'.dol_escape_htmltag($cat[
'code']).
'">';
564 if (count($cpts) > 0 && !empty($cpts[0])) {
566 foreach ($cpts as $cpt) {
568 $labeltoshow .=
'...)';
572 $labeltoshow .=
', ';
574 $labeltoshow .=
' (';
583 $labeltoshow .=
' - <span class="warning">'.$langs->trans(
"GroupIsEmptyCheckSetup").
'</span>';
585 print
'<td class="tdoverflowmax250 borderright" title="'.dol_escape_htmltag(
dol_string_nohtmltag($labeltoshow)).
'">';
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>';
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>';
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>';
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'];
617 if ($showaccountdetail ==
'all' || $resultN != 0) {
621 if (isset($cpt[
'account_number'])) {
622 $labeldetail =
' '.length_accountg($cpt[
'account_number']).
' - '.$cpt[
'account_label'];
627 print
'<td class="tdoverflowmax250 borderright" title="'.dol_escape_htmltag($labeldetail).
'">';
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>';
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];
641 print
'<td class="right"><span class="amount">'.price($resultM).
'</span></td>';
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];
651 print
'<td class="right"><span class="amount">'.price($resultM).
'</span></td>';