27 require
'../../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
30 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
31 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formaccounting.class.php';
32 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountancycategory.class.php';
35 $langs->loadLangs(array(
'compta',
'bills',
'donation',
'salaries',
'accountancy'));
40 $action =
GETPOST(
'action',
'aZ09');
41 $cat_id =
GETPOST(
'account_category');
44 $rowid =
GETPOST(
'rowid',
'int');
45 $cancel =
GETPOST(
'cancel',
'alpha');
46 $showaccountdetail =
GETPOST(
'showaccountdetail',
'aZ09') ?
GETPOST(
'showaccountdetail',
'aZ09') :
'no';
49 $date_startmonth =
GETPOST(
'date_startmonth',
'int');
50 $date_startday =
GETPOST(
'date_startday',
'int');
51 $date_startyear =
GETPOST(
'date_startyear',
'int');
52 $date_endmonth =
GETPOST(
'date_endmonth',
'int');
53 $date_endday =
GETPOST(
'date_endday',
'int');
54 $date_endyear =
GETPOST(
'date_endyear',
'int');
61 $year_current = strftime(
"%Y",
dol_now());
62 $month_current = strftime(
"%m",
dol_now());
63 $year_start = $year_current - ($nbofyear - 1);
65 $year_current = $year;
66 $month_current = strftime(
"%m",
dol_now());
67 $year_start = $year - ($nbofyear - 1);
69 $date_start =
dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
70 $date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
73 if (empty($date_start) || empty($date_end)) {
77 $year_end = $year_start + ($nbofyear - 1);
78 $month_start =
GETPOST(
"month",
'int') ?
GETPOST(
"month",
'int') : ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1);
79 $date_startmonth = $month_start;
81 if (!
GETPOST(
"year") && $month_start > $month_current) {
85 $month_end = $month_start - 1;
92 $month_end = $month_start;
115 if (($date_start <
dol_time_plus_duree($date_end, -1,
'y')) || ($date_start > $date_end)) {
121 $start_year = $tmps[
'year'];
122 $start_month = $tmps[
'mon'];
124 $year_end = $tmpe[
'year'];
125 $month_end = $tmpe[
'mon'];
126 $nbofyear = ($year_end - $start_year) + 1;
139 $modecompta = $conf->global->ACCOUNTING_MODE;
141 $modecompta =
'BOOKKEEPING';
144 $modecompta =
GETPOST(
"modecompta",
'alpha');
150 $socid =
GETPOST(
'socid',
'int');
151 if ($user->socid > 0) {
152 $socid = $user->socid;
158 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
167 $langs->trans(
"MonthShort01"),
168 $langs->trans(
"MonthShort02"),
169 $langs->trans(
"MonthShort03"),
170 $langs->trans(
"MonthShort04"),
171 $langs->trans(
"MonthShort05"),
172 $langs->trans(
"MonthShort06"),
173 $langs->trans(
"MonthShort07"),
174 $langs->trans(
"MonthShort08"),
175 $langs->trans(
"MonthShort09"),
176 $langs->trans(
"MonthShort10"),
177 $langs->trans(
"MonthShort11"),
178 $langs->trans(
"MonthShort12"),
181 llxheader(
'', $langs->trans(
'ReportInOut'));
186 $textprevyear =
'<a href="'.$_SERVER[
"PHP_SELF"].
'?year='.($start_year - 1).
'">'.
img_previous().
'</a>';
187 $textnextyear =
' <a href="'.$_SERVER[
"PHP_SELF"].
'?year='.($start_year + 1).
'">'.
img_next().
'</a>';
192 if ($modecompta ==
"CREANCES-DETTES") {
193 $name = $langs->trans(
"AnnualByAccountDueDebtMode");
194 $calcmode = $langs->trans(
"CalcModeDebt");
195 $calcmode .=
'<br>('.$langs->trans(
"SeeReportInInputOutputMode",
'<a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$start_year.(GETPOST(
"month") > 0 ?
'&month='.GETPOST(
"month") :
'').
'&modecompta=RECETTES-DEPENSES">',
'</a>').
')';
197 $calcmode .=
'<br>('.$langs->trans(
"SeeReportInBookkeepingMode",
'<a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$start_year.
'&modecompta=BOOKKEEPING">',
'</a>').
')';
199 $period =
$form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.
$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
201 $description = $langs->trans(
"RulesResultDue");
202 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
203 $description .= $langs->trans(
"DepositsAreNotIncluded");
205 $description .= $langs->trans(
"DepositsAreIncluded");
207 if (!empty($conf->global->FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS)) {
208 $description .= $langs->trans(
"SupplierDepositsAreNotIncluded");
212 } elseif ($modecompta ==
"RECETTES-DEPENSES") {
213 $name = $langs->trans(
"AnnualByAccountInputOutputMode");
214 $calcmode = $langs->trans(
"CalcModeEngagement");
215 $calcmode .=
'<br>('.$langs->trans(
"SeeReportInDueDebtMode",
'<a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$year.(GETPOST(
"month") > 0 ?
'&month='.GETPOST(
"month") :
'').
'&modecompta=CREANCES-DETTES">',
'</a>').
')';
217 $calcmode .=
'<br>('.$langs->trans(
"SeeReportInBookkeepingMode",
'<a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$year.
'&modecompta=BOOKKEEPING">',
'</a>').
')';
219 $period =
$form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.
$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
221 $description = $langs->trans(
"RulesResultInOut");
224 } elseif ($modecompta ==
"BOOKKEEPING") {
225 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByPersonalizedAccountGroups");
226 $calcmode = $langs->trans(
"CalcModeBookkeeping");
229 $period =
$form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.
$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
230 $arraylist = array(
'no'=>$langs->trans(
"No"),
'yes'=>$langs->trans(
"AccountWithNonZeroValues"),
'all'=>$langs->trans(
"All"));
231 $period .=
' '.$langs->trans(
"DetailByAccount").
' '.
$form->selectarray(
'showaccountdetail', $arraylist, $showaccountdetail, 0);
232 $periodlink = $textprevyear.$textnextyear;
234 $description = $langs->trans(
"RulesResultBookkeepingPersonalized");
235 $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")).
')';
239 report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, array(
'modecompta'=>$modecompta,
'action' =>
''), $calcmode);
242 if (
isModEnabled(
'accounting') && $modecompta !=
'BOOKKEEPING') {
243 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0, 1);
249 print
'<div class="div-table-responsive">';
250 print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
252 print
'<tr class="liste_titre">';
253 print
'<th class="liste_titre">'.$langs->trans(
"AccountingCategory").
'</th>';
254 print
'<th class="liste_titre"></th>';
255 print
'<th class="liste_titre right">'.$langs->trans(
"PreviousPeriod").
'</th>';
256 print
'<th class="liste_titre right">'.$langs->trans(
"SelectedPeriod").
'</th>';
257 foreach ($months as $k => $v) {
258 if (($k + 1) >= $date_startmonth) {
259 print
'<th class="liste_titre right width50">'.$langs->trans(
'MonthShort'.sprintf(
"%02s", ($k + 1))).
'</th>';
262 foreach ($months as $k => $v) {
263 if (($k + 1) < $date_startmonth) {
264 print
'<th class="liste_titre right width50">'.$langs->trans(
'MonthShort'.sprintf(
"%02s", ($k + 1))).
'</th>';
269 if ($modecompta ==
'CREANCES-DETTES') {
272 } elseif ($modecompta ==
"RECETTES-DEPENSES") {
275 } elseif ($modecompta ==
"BOOKKEEPING") {
277 $cats = $AccCat->getCats();
278 $unactive_cats = $AccCat->getCats(-1, 0);
307 $totPerAccount = array();
308 if (!is_array($cats) && $cats < 0) {
310 } elseif (is_array($cats) && count($cats) > 0) {
311 foreach ($cats as $cat) {
313 if (!empty($cat[
'category_type'])) {
317 $formula = $cat[
'formula'];
319 print
'<tr class="liste_total">';
322 print
'<td class="liste_total width200">';
331 foreach ($unactive_cats as $un_cat) {
332 $vars[$un_cat[
'code']] = 0;
336 foreach ($sommes as $code => $det) {
337 if (is_null($det[
'NP'])) {
340 $vars[$code] = $det[
'NP'];
343 $result = strtr($formula, $vars);
353 print
'<td class="liste_total right"><span class="amount">'.price($r).
'</span></td>';
356 $code = $cat[
'code'];
357 $sommes[$code][
'NP'] += $r;
360 if (is_array($sommes) && !empty($sommes)) {
361 foreach ($sommes as $code => $det) {
362 $vars[$code] = $det[
'N'];
366 $result = strtr($formula, $vars);
374 print
'<td class="liste_total right"><span class="amount">'.price($r).
'</span></td>';
375 $sommes[$code][
'N'] += $r;
378 foreach ($months as $k => $v) {
379 if (($k + 1) >= $date_startmonth) {
380 foreach ($sommes as $code => $det) {
381 $vars[$code] = $det[
'M'][$k];
383 $result = strtr($formula, $vars);
391 print
'<td class="liste_total right"><span class="amount">'.price($r).
'</span></td>';
392 $sommes[$code][
'M'][$k] += $r;
395 foreach ($months as $k => $v) {
396 if (($k + 1) < $date_startmonth) {
397 foreach ($sommes as $code => $det) {
398 $vars[$code] = $det[
'M'][$k];
400 $result = strtr($formula, $vars);
408 print
'<td class="liste_total right"><span class="amount">'.price($r).
'</span></td>';
409 $sommes[$code][
'M'][$k] += $r;
418 $code = $cat[
'code'];
423 $totCat[
'M'] = array();
424 foreach ($months as $k => $v) {
425 $totCat[
'M'][$k] = 0;
429 $cpts = $AccCat->getCptsCat($cat[
'rowid']);
431 if (empty($cpts)) $cpts[] = array();
434 $arrayofaccountforfilter = array();
435 foreach ($cpts as $i => $cpt) {
436 if (!empty($cpt[
'account_number'])) {
437 $arrayofaccountforfilter[] = $cpt[
'account_number'];
442 if (!empty($arrayofaccountforfilter)) {
443 $return = $AccCat->getSumDebitCredit($arrayofaccountforfilter, $date_start_previous, $date_end_previous, $cat[
'dc'] ? $cat[
'dc'] : 0);
449 foreach ($cpts as $i => $cpt) {
450 $resultNP = empty($AccCat->sdcperaccount[$cpt[
'account_number']]) ? 0 : $AccCat->sdcperaccount[$cpt[
'account_number']];
452 $totCat[
'NP'] += $resultNP;
453 $sommes[$code][
'NP'] += $resultNP;
454 $totPerAccount[$cpt[
'account_number']][
'NP'] = $resultNP;
461 foreach ($cpts as $i => $cpt) {
467 foreach ($months as $k => $v) {
468 $monthtoprocess = $k + 1;
469 $yeartoprocess = $start_year;
470 if (($k + 1) < $start_month) {
475 $return = $AccCat->getSumDebitCredit($cpt[
'account_number'], $date_start, $date_end, $cat[
'dc'] ? $cat[
'dc'] : 0,
'nofilter', $monthtoprocess, $yeartoprocess);
480 $resultM = $AccCat->sdc;
482 $totCat[
'M'][$k] += $resultM;
483 $sommes[$code][
'M'][$k] += $resultM;
484 $totPerAccount[$cpt[
'account_number']][
'M'][$k] = $resultM;
486 $resultN += $resultM;
489 $totCat[
'N'] += $resultN;
490 $sommes[$code][
'N'] += $resultN;
491 $totPerAccount[$cpt[
'account_number']][
'N'] = $resultN;
500 print
'<td class="width200">';
507 if (count($cpts) > 0 && !empty($cpts[0])) {
509 foreach ($cpts as $cpt) {
526 print
' - <span class="warning">'.$langs->trans(
"GroupIsEmptyCheckSetup").
'</span>';
530 print
'<td class="right"><span class="amount">'.price($totCat[
'NP']).
'</span></td>';
531 print
'<td class="right"><span class="amount">'.price($totCat[
'N']).
'</span></td>';
534 foreach ($totCat[
'M'] as $k => $v) {
535 if (($k + 1) >= $date_startmonth) {
536 print
'<td class="right nowraponall"><span class="amount">'.price($v).
'</span></td>';
539 foreach ($totCat[
'M'] as $k => $v) {
540 if (($k + 1) < $date_startmonth) {
541 print
'<td class="right nowraponall"><span class="amount">'.price($v).
'</span></td>';
548 if ($showaccountdetail !=
'no') {
549 foreach ($cpts as $i => $cpt) {
550 $resultNP = $totPerAccount[$cpt[
'account_number']][
'NP'];
551 $resultN = $totPerAccount[$cpt[
'account_number']][
'N'];
553 if ($showaccountdetail ==
'all' || $resultN != 0) {
556 print
'<td class="tdoverflowmax200">';
557 print
' '.length_accountg($cpt[
'account_number']);
559 print $cpt[
'account_label'];
561 print
'<td class="right"><span class="amount">'.price($resultNP).
'</span></td>';
562 print
'<td class="right"><span class="amount">'.price($resultN).
'</span></td>';
565 foreach ($months as $k => $v) {
566 if (($k + 1) >= $date_startmonth) {
567 $resultM = $totPerAccount[$cpt[
'account_number']][
'M'][$k];
568 print
'<td class="right"><span class="amount">'.price($resultM).
'</span></td>';
571 foreach ($months as $k => $v) {
572 if (($k + 1) < $date_startmonth) {
573 $resultM = $totPerAccount[$cpt[
'account_number']][
'M'][$k];
574 print
'<td class="right"><span class="amount">'.price($resultM).
'</span></td>';