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");
209 } elseif ($modecompta ==
"RECETTES-DEPENSES") {
210 $name = $langs->trans(
"AnnualByAccountInputOutputMode");
211 $calcmode = $langs->trans(
"CalcModeEngagement");
212 $calcmode .=
'<br>('.$langs->trans(
"SeeReportInDueDebtMode",
'<a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$year.(GETPOST(
"month") > 0 ?
'&month='.GETPOST(
"month") :
'').
'&modecompta=CREANCES-DETTES">',
'</a>').
')';
214 $calcmode .=
'<br>('.$langs->trans(
"SeeReportInBookkeepingMode",
'<a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$year.
'&modecompta=BOOKKEEPING">',
'</a>').
')';
216 $period =
$form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.
$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
218 $description = $langs->trans(
"RulesResultInOut");
221 } elseif ($modecompta ==
"BOOKKEEPING") {
222 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByPersonalizedAccountGroups");
223 $calcmode = $langs->trans(
"CalcModeBookkeeping");
226 $period =
$form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.
$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
227 $arraylist = array(
'no'=>$langs->trans(
"No"),
'yes'=>$langs->trans(
"AccountWithNonZeroValues"),
'all'=>$langs->trans(
"All"));
228 $period .=
' '.$langs->trans(
"DetailByAccount").
' '.
$form->selectarray(
'showaccountdetail', $arraylist, $showaccountdetail, 0);
229 $periodlink = $textprevyear.$textnextyear;
231 $description = $langs->trans(
"RulesResultBookkeepingPersonalized");
232 $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")).
')';
238 report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, array(
'modecompta'=>$modecompta,
'action' =>
''), $calcmode);
241 if (
isModEnabled(
'accounting') && $modecompta !=
'BOOKKEEPING') {
242 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0, 1);
248 print
'<div class="div-table-responsive">';
249 print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
251 print
'<tr class="liste_titre">';
252 print
'<th class="liste_titre">'.$langs->trans(
"AccountingCategory").
'</th>';
253 print
'<th class="liste_titre"></th>';
254 print
'<th class="liste_titre right">'.$langs->trans(
"PreviousPeriod").
'</th>';
255 print
'<th class="liste_titre right">'.$langs->trans(
"SelectedPeriod").
'</th>';
256 foreach ($months as $k => $v) {
257 if (($k + 1) >= $date_startmonth) {
258 print
'<th class="liste_titre right width50">'.$langs->trans(
'MonthShort'.sprintf(
"%02s", ($k + 1))).
'</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>';
268 if ($modecompta ==
'CREANCES-DETTES') {
271 } elseif ($modecompta ==
"RECETTES-DEPENSES") {
274 } elseif ($modecompta ==
"BOOKKEEPING") {
276 $cats = $AccCat->getCats();
277 $unactive_cats = $AccCat->getCats(-1, 0);
306 $totPerAccount = array();
307 if (!is_array($cats) && $cats < 0) {
309 } elseif (is_array($cats) && count($cats) > 0) {
310 foreach ($cats as $cat) {
312 if (!empty($cat[
'category_type'])) {
316 $formula = $cat[
'formula'];
318 print
'<tr class="liste_total">';
321 print
'<td class="liste_total width200">';
330 foreach ($unactive_cats as $un_cat) {
331 $vars[$un_cat[
'code']] = 0;
335 foreach ($sommes as $code => $det) {
336 $vars[$code] = $det[
'NP'];
339 $result = strtr($formula, $vars);
346 print
'<td class="liste_total right"><span class="amount">'.price($r).
'</span></td>';
349 $code = $cat[
'code'];
350 $sommes[$code][
'NP'] += $r;
353 if (is_array($sommes) && !empty($sommes)) {
354 foreach ($sommes as $code => $det) {
355 $vars[$code] = $det[
'N'];
359 $result = strtr($formula, $vars);
364 print
'<td class="liste_total right"><span class="amount">'.price($r).
'</span></td>';
365 $sommes[$code][
'N'] += $r;
368 foreach ($months as $k => $v) {
369 if (($k + 1) >= $date_startmonth) {
370 foreach ($sommes as $code => $det) {
371 $vars[$code] = $det[
'M'][$k];
373 $result = strtr($formula, $vars);
378 print
'<td class="liste_total right"><span class="amount">'.price($r).
'</span></td>';
379 $sommes[$code][
'M'][$k] += $r;
382 foreach ($months as $k => $v) {
383 if (($k + 1) < $date_startmonth) {
384 foreach ($sommes as $code => $det) {
385 $vars[$code] = $det[
'M'][$k];
387 $result = strtr($formula, $vars);
392 print
'<td class="liste_total right"><span class="amount">'.price($r).
'</span></td>';
393 $sommes[$code][
'M'][$k] += $r;
402 $code = $cat[
'code'];
407 $totCat[
'M'] = array();
408 foreach ($months as $k => $v) {
409 $totCat[
'M'][$k] = 0;
413 $cpts = $AccCat->getCptsCat($cat[
'rowid']);
415 if (empty($cpts)) $cpts[] = array();
418 $arrayofaccountforfilter = array();
419 foreach ($cpts as $i => $cpt) {
420 $arrayofaccountforfilter[] = $cpt[
'account_number'];
424 if (!empty($arrayofaccountforfilter)) {
425 $return = $AccCat->getSumDebitCredit($arrayofaccountforfilter, $date_start_previous, $date_end_previous, $cat[
'dc'] ? $cat[
'dc'] : 0);
431 foreach ($cpts as $i => $cpt) {
432 $resultNP = empty($AccCat->sdcperaccount[$cpt[
'account_number']]) ? 0 : $AccCat->sdcperaccount[$cpt[
'account_number']];
434 $totCat[
'NP'] += $resultNP;
435 $sommes[$code][
'NP'] += $resultNP;
436 $totPerAccount[$cpt[
'account_number']][
'NP'] = $resultNP;
443 foreach ($cpts as $i => $cpt) {
449 foreach ($months as $k => $v) {
450 $monthtoprocess = $k + 1;
451 $yeartoprocess = $start_year;
452 if (($k + 1) < $start_month) {
457 $return = $AccCat->getSumDebitCredit($cpt[
'account_number'], $date_start, $date_end, $cat[
'dc'] ? $cat[
'dc'] : 0,
'nofilter', $monthtoprocess, $yeartoprocess);
462 $resultM = $AccCat->sdc;
464 $totCat[
'M'][$k] += $resultM;
465 $sommes[$code][
'M'][$k] += $resultM;
466 $totPerAccount[$cpt[
'account_number']][
'M'][$k] = $resultM;
468 $resultN += $resultM;
471 $totCat[
'N'] += $resultN;
472 $sommes[$code][
'N'] += $resultN;
473 $totPerAccount[$cpt[
'account_number']][
'N'] = $resultN;
482 print
'<td class="width200">';
489 if (count($cpts) > 0 && !empty($cpts[0])) {
491 foreach ($cpts as $cpt) {
508 print
' - <span class="warning">'.$langs->trans(
"GroupIsEmptyCheckSetup").
'</span>';
512 print
'<td class="right"><span class="amount">'.price($totCat[
'NP']).
'</span></td>';
513 print
'<td class="right"><span class="amount">'.price($totCat[
'N']).
'</span></td>';
516 foreach ($totCat[
'M'] as $k => $v) {
517 if (($k + 1) >= $date_startmonth) {
518 print
'<td class="right nowraponall"><span class="amount">'.price($v).
'</span></td>';
521 foreach ($totCat[
'M'] as $k => $v) {
522 if (($k + 1) < $date_startmonth) {
523 print
'<td class="right nowraponall"><span class="amount">'.price($v).
'</span></td>';
530 if ($showaccountdetail !=
'no') {
531 foreach ($cpts as $i => $cpt) {
532 $resultNP = $totPerAccount[$cpt[
'account_number']][
'NP'];
533 $resultN = $totPerAccount[$cpt[
'account_number']][
'N'];
535 if ($showaccountdetail ==
'all' || $resultN != 0) {
538 print
'<td class="tdoverflowmax200">';
539 print
' '.length_accountg($cpt[
'account_number']);
541 print $cpt[
'account_label'];
543 print
'<td class="right"><span class="amount">'.price($resultNP).
'</span></td>';
544 print
'<td class="right"><span class="amount">'.price($resultN).
'</span></td>';
547 foreach ($months as $k => $v) {
548 if (($k + 1) >= $date_startmonth) {
549 $resultM = $totPerAccount[$cpt[
'account_number']][
'M'][$k];
550 print
'<td class="right"><span class="amount">'.price($resultM).
'</span></td>';
553 foreach ($months as $k => $v) {
554 if (($k + 1) < $date_startmonth) {
555 $resultM = $totPerAccount[$cpt[
'account_number']][
'M'][$k];
556 print
'<td class="right"><span class="amount">'.price($resultM).
'</span></td>';
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
if($cancel &&!$id) if($action== 'add'&&!$cancel) if($action== 'delete') if($id) $form
Actions.
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_now($mode= 'auto')
Return date for now.
report_header($reportname, $notused, $period, $periodlink, $description, $builddate, $exportlink= '', $moreparam=array(), $calcmode= '', $varlink= '')
Show header of a report.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
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_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Class to manage categories of an accounting account.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
dol_eval($s, $returnvalue=0, $hideerrors=1, $onlysimplestring= '1')
Replace eval function to add more security.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin= '1', $morecss= 'hideonsmartphone', $textfordropdown= '')
Show information for admin users or standard users.
dol_getdate($timestamp, $fast=false, $forcetimezone= '')
Return an array with locale date info.
restrictedArea($user, $features, $objectid=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.
img_next($titlealt= 'default', $moreatt= '')
Show next logo.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
img_previous($titlealt= 'default', $moreatt= '')
Show previous logo.
isModEnabled($module)
Is Dolibarr module enabled.