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');
63 $month_current = strftime(
"%m",
dol_now());
64 $year_start = $year_current - ($nbofyear - 1);
66 $year_current = $year;
67 $month_current = strftime(
"%m",
dol_now());
68 $year_start = $year - ($nbofyear - 1);
70 $date_start =
dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
71 $date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
74 if (empty($date_start) || empty($date_end)) {
78 $year_end = $year_start + ($nbofyear - 1);
79 $month_start =
GETPOST(
"month",
'int') ?
GETPOST(
"month",
'int') : ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1);
80 $date_startmonth = $month_start;
82 if (!
GETPOST(
"year") && $month_start > $month_current) {
86 $month_end = $month_start - 1;
93 $month_end = $month_start;
116 if (($date_start <
dol_time_plus_duree($date_end, -1,
'y')) || ($date_start > $date_end)) {
122 $start_year = $tmps[
'year'];
123 $start_month = $tmps[
'mon'];
125 $year_end = $tmpe[
'year'];
126 $month_end = $tmpe[
'mon'];
127 $nbofyear = ($year_end - $start_year) + 1;
140 $modecompta = $conf->global->ACCOUNTING_MODE;
142 $modecompta =
'BOOKKEEPING';
145 $modecompta =
GETPOST(
"modecompta",
'alpha');
151 $socid =
GETPOST(
'socid',
'int');
152 if ($user->socid > 0) {
153 $socid = $user->socid;
159 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
168 $langs->trans(
"MonthShort01"),
169 $langs->trans(
"MonthShort02"),
170 $langs->trans(
"MonthShort03"),
171 $langs->trans(
"MonthShort04"),
172 $langs->trans(
"MonthShort05"),
173 $langs->trans(
"MonthShort06"),
174 $langs->trans(
"MonthShort07"),
175 $langs->trans(
"MonthShort08"),
176 $langs->trans(
"MonthShort09"),
177 $langs->trans(
"MonthShort10"),
178 $langs->trans(
"MonthShort11"),
179 $langs->trans(
"MonthShort12"),
182 llxheader(
'', $langs->trans(
'ReportInOut'));
187 $textprevyear =
'<a href="'.$_SERVER[
"PHP_SELF"].
'?year='.($start_year - 1).
'&showaccountdetail='.urlencode($showaccountdetail).
'">'.
img_previous().
'</a>';
188 $textnextyear =
' <a href="'.$_SERVER[
"PHP_SELF"].
'?year='.($start_year + 1).
'&showaccountdetail='.urlencode($showaccountdetail).
'">'.
img_next().
'</a>';
193 if ($modecompta ==
"CREANCES-DETTES") {
194 $name = $langs->trans(
"AnnualByAccountDueDebtMode");
195 $calcmode = $langs->trans(
"CalcModeDebt");
196 $calcmode .=
'<br>('.$langs->trans(
"SeeReportInInputOutputMode",
'<a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$start_year.(GETPOST(
"month") > 0 ?
'&month='.GETPOST(
"month") :
'').
'&modecompta=RECETTES-DEPENSES">',
'</a>').
')';
198 $calcmode .=
'<br>('.$langs->trans(
"SeeReportInBookkeepingMode",
'<a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$start_year.
'&modecompta=BOOKKEEPING">',
'</a>').
')';
200 $period =
$form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.
$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
202 $description = $langs->trans(
"RulesResultDue");
203 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
204 $description .= $langs->trans(
"DepositsAreNotIncluded");
206 $description .= $langs->trans(
"DepositsAreIncluded");
208 if (!empty($conf->global->FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS)) {
209 $description .= $langs->trans(
"SupplierDepositsAreNotIncluded");
213 } elseif ($modecompta ==
"RECETTES-DEPENSES") {
214 $name = $langs->trans(
"AnnualByAccountInputOutputMode");
215 $calcmode = $langs->trans(
"CalcModeEngagement");
216 $calcmode .=
'<br>('.$langs->trans(
"SeeReportInDueDebtMode",
'<a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$year.(GETPOST(
"month") > 0 ?
'&month='.GETPOST(
"month") :
'').
'&modecompta=CREANCES-DETTES">',
'</a>').
')';
218 $calcmode .=
'<br>('.$langs->trans(
"SeeReportInBookkeepingMode",
'<a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$year.
'&modecompta=BOOKKEEPING">',
'</a>').
')';
220 $period =
$form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.
$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
222 $description = $langs->trans(
"RulesResultInOut");
225 } elseif ($modecompta ==
"BOOKKEEPING") {
226 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByPersonalizedAccountGroups");
227 $calcmode = $langs->trans(
"CalcModeBookkeeping");
230 $period =
$form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.
$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
231 $arraylist = array(
'no'=>$langs->trans(
"No"),
'yes'=>$langs->trans(
"AccountWithNonZeroValues"),
'all'=>$langs->trans(
"All"));
232 $period .=
' '.$langs->trans(
"DetailByAccount").
' '.
$form->selectarray(
'showaccountdetail', $arraylist, $showaccountdetail, 0);
233 $periodlink = $textprevyear.$textnextyear;
235 $description = $langs->trans(
"RulesResultBookkeepingPersonalized");
236 $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 report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, array(
'modecompta'=>$modecompta,
'action' =>
''), $calcmode);
243 if (
isModEnabled(
'accounting') && $modecompta !=
'BOOKKEEPING') {
244 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0, 1);
250 print
'<div class="div-table-responsive">';
251 print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
253 print
'<tr class="liste_titre">';
254 print
'<th class="liste_titre">'.$langs->trans(
"AccountingCategory").
'</th>';
255 print
'<th class="liste_titre"></th>';
256 print
'<th class="liste_titre right">'.$langs->trans(
"PreviousPeriod").
'</th>';
257 print
'<th class="liste_titre right">'.$langs->trans(
"SelectedPeriod").
'</th>';
258 foreach ($months as $k => $v) {
259 if (($k + 1) >= $date_startmonth) {
260 print
'<th class="liste_titre right width50">'.$langs->trans(
'MonthShort'.sprintf(
"%02s", ($k + 1))).
'</th>';
263 foreach ($months as $k => $v) {
264 if (($k + 1) < $date_startmonth) {
265 print
'<th class="liste_titre right width50">'.$langs->trans(
'MonthShort'.sprintf(
"%02s", ($k + 1))).
'</th>';
270 if ($modecompta ==
'CREANCES-DETTES') {
273 } elseif ($modecompta ==
"RECETTES-DEPENSES") {
276 } elseif ($modecompta ==
"BOOKKEEPING") {
278 $cats = $AccCat->getCats();
279 $unactive_cats = $AccCat->getCats(-1, 0);
308 $totPerAccount = array();
309 if (!is_array($cats) && $cats < 0) {
311 } elseif (is_array($cats) && count($cats) > 0) {
313 foreach ($cats as $cat) {
314 if (!empty($cat[
'category_type'])) {
318 $formula = $cat[
'formula'];
320 print
'<tr class="liste_total">';
323 print
'<td class="liste_total tdoverflowmax100" title="'.dol_escape_htmltag($cat[
'code']).
'">';
325 print
'</td><td class="tdoverflowmax250 borderright" title="'.dol_escape_htmltag($cat[
'label']).
'">';
332 foreach ($unactive_cats as $un_cat) {
333 $vars[$un_cat[
'code']] = 0;
337 foreach ($sommes as $code => $det) {
338 $vars[$code] = $det[
'NP'];
341 $result = strtr($formula, $vars);
342 $result = str_replace(
'--',
'+', $result);
344 if (preg_match(
'/[a-z]/i', $result)) {
345 $r =
'Error bad formula: '.$result;
347 print
'<td class="liste_total right"><span class="amount" title="'.dol_escape_htmltag($r).
'">'.$rshort.
'</span></td>';
353 print
'<td class="liste_total right"><span class="amount">'.price($r).
'</span></td>';
357 $code = $cat[
'code'];
358 $sommes[$code][
'NP'] += $r;
361 if (is_array($sommes) && !empty($sommes)) {
362 foreach ($sommes as $code => $det) {
363 $vars[$code] = $det[
'N'];
367 $result = strtr($formula, $vars);
368 $result = str_replace(
'--',
'+', $result);
373 print
'<td class="liste_total right borderright"><span class="amount">'.price($r).
'</span></td>';
374 $sommes[$code][
'N'] += $r;
377 foreach ($months as $k => $v) {
378 if (($k + 1) >= $date_startmonth) {
379 foreach ($sommes as $code => $det) {
380 $vars[$code] = $det[
'M'][$k];
382 $result = strtr($formula, $vars);
383 $result = str_replace(
'--',
'+', $result);
388 print
'<td class="liste_total right"><span class="amount">'.price($r).
'</span></td>';
389 $sommes[$code][
'M'][$k] += $r;
393 foreach ($months as $k => $v) {
394 if (($k + 1) < $date_startmonth) {
395 foreach ($sommes as $code => $det) {
396 $vars[$code] = $det[
'M'][$k];
398 $result = strtr($formula, $vars);
399 $result = str_replace(
'--',
'+', $result);
404 print
'<td class="liste_total right"><span class="amount">'.price($r).
'</span></td>';
405 $sommes[$code][
'M'][$k] += $r;
413 $code = $cat[
'code'];
418 $totCat[
'M'] = array();
419 foreach ($months as $k => $v) {
420 $totCat[
'M'][$k] = 0;
424 $cpts = $AccCat->getCptsCat($cat[
'rowid']);
430 $arrayofaccountforfilter = array();
431 foreach ($cpts as $i => $cpt) {
432 if (!is_null($cpt[
'account_number'])) {
433 $arrayofaccountforfilter[] = $cpt[
'account_number'];
438 if (!empty($arrayofaccountforfilter)) {
439 $return = $AccCat->getSumDebitCredit($arrayofaccountforfilter, $date_start_previous, $date_end_previous, $cat[
'dc'] ? $cat[
'dc'] : 0);
444 foreach ($cpts as $i => $cpt) {
445 $resultNP = empty($AccCat->sdcperaccount[$cpt[
'account_number']]) ? 0 : $AccCat->sdcperaccount[$cpt[
'account_number']];
447 $totCat[
'NP'] += $resultNP;
448 $sommes[$code][
'NP'] += $resultNP;
449 $totPerAccount[$cpt[
'account_number']][
'NP'] = $resultNP;
456 foreach ($cpts as $i => $cpt) {
462 foreach ($months as $k => $v) {
463 $monthtoprocess = $k + 1;
464 $yeartoprocess = $start_year;
465 if (($k + 1) < $start_month) {
470 $return = $AccCat->getSumDebitCredit($cpt[
'account_number'], $date_start, $date_end, $cat[
'dc'] ? $cat[
'dc'] : 0,
'nofilter', $monthtoprocess, $yeartoprocess);
475 $resultM = $AccCat->sdc;
477 $totCat[
'M'][$k] += $resultM;
478 $sommes[$code][
'M'][$k] += $resultM;
479 $totPerAccount[$cpt[
'account_number']][
'M'][$k] = $resultM;
481 $resultN += $resultM;
484 $totCat[
'N'] += $resultN;
485 $sommes[$code][
'N'] += $resultN;
486 $totPerAccount[$cpt[
'account_number']][
'N'] = $resultN;
492 print
'<tr'.($showaccountdetail !=
'no' ?
' class="trforbreak"' :
'').
'>';
495 print
'<td class="tdoverflowmax100" title="'.dol_escape_htmltag($cat[
'code']).
'">';
501 if (count($cpts) > 0 && !empty($cpts[0])) {
503 foreach ($cpts as $cpt) {
505 $labeltoshow .=
'...)';
509 $labeltoshow .=
', ';
511 $labeltoshow .=
' (';
520 $labeltoshow .=
' - <span class="warning">'.$langs->trans(
"GroupIsEmptyCheckSetup").
'</span>';
522 print
'<td class="tdoverflowmax250 borderright" title="'.dol_escape_htmltag(
dol_string_nohtmltag($labeltoshow)).
'">';
526 print
'<td class="right"><span class="amount">'.price($totCat[
'NP']).
'</span></td>';
527 print
'<td class="right borderright"><span class="amount">'.price($totCat[
'N']).
'</span></td>';
530 foreach ($totCat[
'M'] as $k => $v) {
531 if (($k + 1) >= $date_startmonth) {
532 print
'<td class="right nowraponall"><span class="amount">'.price($v).
'</span></td>';
535 foreach ($totCat[
'M'] as $k => $v) {
536 if (($k + 1) < $date_startmonth) {
537 print
'<td class="right nowraponall"><span class="amount">'.price($v).
'</span></td>';
544 if ($showaccountdetail !=
'no') {
545 foreach ($cpts as $i => $cpt) {
546 $resultNP = $totPerAccount[$cpt[
'account_number']][
'NP'];
547 $resultN = $totPerAccount[$cpt[
'account_number']][
'N'];
549 if ($showaccountdetail ==
'all' || $resultN != 0) {
552 print
'<td class="tdoverflowmax250 borderright">';
553 print
' '.length_accountg($cpt[
'account_number']);
555 print $cpt[
'account_label'];
557 print
'<td class="right"><span class="amount">'.price($resultNP).
'</span></td>';
558 print
'<td class="right borderright"><span class="amount">'.price($resultN).
'</span></td>';
561 foreach ($months as $k => $v) {
562 if (($k + 1) >= $date_startmonth) {
563 $resultM = $totPerAccount[$cpt[
'account_number']][
'M'][$k];
564 print
'<td class="right"><span class="amount">'.price($resultM).
'</span></td>';
567 foreach ($months as $k => $v) {
568 if (($k + 1) < $date_startmonth) {
569 $resultM = $totPerAccount[$cpt[
'account_number']][
'M'][$k];
570 print
'<td class="right"><span class="amount">'.price($resultM).
'</span></td>';
Class to manage categories of an accounting account.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
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 informations (by default a local PHP server timestamp) Re...
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
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.
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.
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.