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');
62 $year_current = strftime(
"%Y",
dol_now());
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))
80 $year_end = $year_start + ($nbofyear - 1);
81 $month_start =
GETPOST(
"month",
'int') ?
GETPOST(
"month",
'int') : ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1);
82 $date_startmonth = $month_start;
85 if (!
GETPOST(
"year") && $month_start > $month_current)
90 $month_end = $month_start - 1;
91 if ($month_end < 1) $month_end = 12;
93 }
else $month_end = $month_start;
109 $start_year = $tmps[
'year'];
110 $start_month = $tmps[
'mon'];
112 $year_end = $tmpe[
'year'];
113 $month_end = $tmpe[
'mon'];
114 $nbofyear = ($year_end - $start_year) + 1;
127 $modecompta = $conf->global->ACCOUNTING_MODE;
128 if (!empty($conf->accounting->enabled)) $modecompta =
'BOOKKEEPING';
129 if (
GETPOST(
"modecompta")) $modecompta =
GETPOST(
"modecompta",
'alpha');
132 if ($user->socid > 0)
134 if (!$user->rights->accounting->comptarapport->lire)
145 $langs->trans(
"MonthShort01"),
146 $langs->trans(
"MonthShort02"),
147 $langs->trans(
"MonthShort03"),
148 $langs->trans(
"MonthShort04"),
149 $langs->trans(
"MonthShort05"),
150 $langs->trans(
"MonthShort06"),
151 $langs->trans(
"MonthShort07"),
152 $langs->trans(
"MonthShort08"),
153 $langs->trans(
"MonthShort09"),
154 $langs->trans(
"MonthShort10"),
155 $langs->trans(
"MonthShort11"),
156 $langs->trans(
"MonthShort12"),
159 llxheader(
'', $langs->trans(
'ReportInOut'));
162 $form =
new Form($db);
164 $textprevyear =
'<a href="'.$_SERVER[
"PHP_SELF"].
'?year='.($start_year - 1).
'">'.
img_previous().
'</a>';
165 $textnextyear =
' <a href="'.$_SERVER[
"PHP_SELF"].
'?year='.($start_year + 1).
'">'.
img_next().
'</a>';
170 if ($modecompta ==
"CREANCES-DETTES")
172 $name = $langs->trans(
"AnnualByAccountDueDebtMode");
173 $calcmode = $langs->trans(
"CalcModeDebt");
174 $calcmode .=
'<br>('.$langs->trans(
"SeeReportInInputOutputMode",
'<a href="'.
$_SERVER[
"PHP_SELF"].
'?year='.$start_year.(GETPOST(
"month") > 0 ?
'&month='.GETPOST(
"month") :
'').
'&modecompta=RECETTES-DEPENSES">',
'</a>').
')';
175 if (!empty($conf->accounting->enabled)) $calcmode .=
'<br>('.$langs->trans(
"SeeReportInBookkeepingMode",
'<a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$start_year.
'&modecompta=BOOKKEEPING">',
'</a>').
')';
176 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
178 $description = $langs->trans(
"RulesResultDue");
179 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $description .= $langs->trans(
"DepositsAreNotIncluded");
180 else $description .= $langs->trans(
"DepositsAreIncluded");
183 } elseif ($modecompta ==
"RECETTES-DEPENSES") {
184 $name = $langs->trans(
"AnnualByAccountInputOutputMode");
185 $calcmode = $langs->trans(
"CalcModeEngagement");
186 $calcmode .=
'<br>('.$langs->trans(
"SeeReportInDueDebtMode",
'<a href="'.
$_SERVER[
"PHP_SELF"].
'?year='.$year.(GETPOST(
"month") > 0 ?
'&month='.GETPOST(
"month") :
'').
'&modecompta=CREANCES-DETTES">',
'</a>').
')';
187 if (!empty($conf->accounting->enabled)) $calcmode .=
'<br>('.$langs->trans(
"SeeReportInBookkeepingMode",
'<a href="'.$_SERVER[
"PHP_SELF"].
'?year='.$year.
'&modecompta=BOOKKEEPING">',
'</a>').
')';
188 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
190 $description = $langs->trans(
"RulesResultInOut");
193 } elseif ($modecompta ==
"BOOKKEEPING")
195 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByPersonalizedAccountGroups");
196 $calcmode = $langs->trans(
"CalcModeBookkeeping");
199 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
200 $arraylist = array(
'no'=>$langs->trans(
"No"),
'yes'=>$langs->trans(
"AccountWithNonZeroValues"),
'all'=>$langs->trans(
"All"));
201 $period .=
' '.$langs->trans(
"DetailByAccount").
' '.$form->selectarray(
'showaccountdetail', $arraylist, $showaccountdetail, 0);
202 $periodlink = $textprevyear.$textnextyear;
204 $description = $langs->trans(
"RulesResultBookkeepingPersonalized").
205 $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")).
')';
211 report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, array(
'modecompta'=>$modecompta,
'action' =>
''), $calcmode);
214 if (!empty($conf->accounting->enabled) && $modecompta !=
'BOOKKEEPING')
222 print '<div class="div-table-responsive">';
223 print '<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
225 print '<tr class="liste_titre">';
226 print
'<th class="liste_titre">'.$langs->trans(
"AccountingCategory").
'</th>';
227 print
'<th class="liste_titre"></th>';
228 print
'<th class="liste_titre right">'.$langs->trans(
"PreviousPeriod").
'</th>';
229 print
'<th class="liste_titre right">'.$langs->trans(
"SelectedPeriod").
'</th>';
230 foreach ($months as $k => $v) {
231 if (($k + 1) >= $date_startmonth)
233 print
'<th class="liste_titre right width50">'.$langs->trans(
'MonthShort'.sprintf(
"%02s", ($k + 1))).
'</th>';
236 foreach ($months as $k => $v) {
237 if (($k + 1) < $date_startmonth)
239 print
'<th class="liste_titre right width50">'.$langs->trans(
'MonthShort'.sprintf(
"%02s", ($k + 1))).
'</th>';
244 if ($modecompta ==
'CREANCES-DETTES')
248 } elseif ($modecompta ==
"RECETTES-DEPENSES")
252 } elseif ($modecompta ==
"BOOKKEEPING")
255 $cats = $AccCat->getCats();
284 $totPerAccount = array();
285 if (!is_array($cats) && $cats < 0) {
287 } elseif (is_array($cats) && count($cats) > 0) {
288 foreach ($cats as $cat) {
290 if (!empty($cat[
'category_type'])) {
294 $formula = $cat[
'formula'];
296 print
'<tr class="liste_total">';
299 print
'<td class="liste_total width200">';
308 foreach ($sommes as $code => $det) {
309 $vars[$code] = $det[
'NP'];
312 $result = strtr($formula, $vars);
319 print
'<td class="liste_total right">'.price($r).
'</td>';
322 $code = $cat[
'code'];
323 $sommes[$code][
'NP'] += $r;
326 if (is_array($sommes) && !empty($sommes)) {
327 foreach ($sommes as $code => $det) {
328 $vars[$code] = $det[
'N'];
332 $result = strtr($formula, $vars);
337 print
'<td class="liste_total right">'.price($r).
'</td>';
338 $sommes[$code][
'N'] += $r;
341 foreach ($months as $k => $v) {
342 if (($k + 1) >= $date_startmonth) {
343 foreach ($sommes as $code => $det) {
344 $vars[$code] = $det[
'M'][$k];
346 $result = strtr($formula, $vars);
351 print
'<td class="liste_total right">'.price($r).
'</td>';
352 $sommes[$code][
'M'][$k] += $r;
355 foreach ($months as $k => $v) {
356 if (($k + 1) < $date_startmonth) {
357 foreach ($sommes as $code => $det) {
358 $vars[$code] = $det[
'M'][$k];
360 $result = strtr($formula, $vars);
365 print
'<td class="liste_total right">'.price($r).
'</td>';
366 $sommes[$code][
'M'][$k] += $r;
375 $code = $cat[
'code'];
380 $totCat[
'M'] = array();
381 foreach ($months as $k => $v) {
382 $totCat[
'M'][$k] = 0;
386 $cpts = $AccCat->getCptsCat($cat[
'rowid']);
388 $arrayofaccountforfilter = array();
389 foreach ($cpts as $i => $cpt)
391 $arrayofaccountforfilter[] = $cpt[
'account_number'];
395 if (!empty($arrayofaccountforfilter)) {
396 $return = $AccCat->getSumDebitCredit($arrayofaccountforfilter, $date_start_previous, $date_end_previous, $cat[
'dc'] ? $cat[
'dc'] : 0);
402 foreach ($cpts as $i => $cpt)
404 $resultNP = empty($AccCat->sdcperaccount[$cpt[
'account_number']]) ? 0 : $AccCat->sdcperaccount[$cpt[
'account_number']];
406 $totCat[
'NP'] += $resultNP;
407 $sommes[$code][
'NP'] += $resultNP;
408 $totPerAccount[$cpt[
'account_number']][
'NP'] = $resultNP;
415 foreach ($cpts as $i => $cpt)
422 foreach ($months as $k => $v) {
423 $monthtoprocess = $k + 1;
424 $yeartoprocess = $start_year;
425 if (($k + 1) < $start_month)
429 $return = $AccCat->getSumDebitCredit($cpt[
'account_number'], $date_start, $date_end, $cat[
'dc'] ? $cat[
'dc'] : 0,
'nofilter', $monthtoprocess, $yeartoprocess);
434 $resultM = $AccCat->sdc;
436 $totCat[
'M'][$k] += $resultM;
437 $sommes[$code][
'M'][$k] += $resultM;
438 $totPerAccount[$cpt[
'account_number']][
'M'][$k] = $resultM;
440 $resultN += $resultM;
443 $totCat[
'N'] += $resultN;
444 $sommes[$code][
'N'] += $resultN;
445 $totPerAccount[$cpt[
'account_number']][
'N'] = $resultN;
454 print
'<td class="width200">';
461 if (count($cpts) > 0)
464 foreach ($cpts as $cpt) {
472 print $cpt[
'account_number'];
478 print
' - <span class="warning">'.$langs->trans(
"GroupIsEmptyCheckSetup").
'</span>';
482 print
'<td class="right">'.price($totCat[
'NP']).
'</td>';
483 print
'<td class="right">'.price($totCat[
'N']).
'</td>';
486 foreach ($totCat[
'M'] as $k => $v) {
487 if (($k + 1) >= $date_startmonth)
488 print
'<td class="right">'.price($v).
'</td>';
490 foreach ($totCat[
'M'] as $k => $v) {
491 if (($k + 1) < $date_startmonth)
492 print
'<td class="right">'.price($v).
'</td>';
498 if ($showaccountdetail !=
'no') {
499 foreach ($cpts as $i => $cpt) {
500 $resultNP = $totPerAccount[$cpt[
'account_number']][
'NP'];
501 $resultN = $totPerAccount[$cpt[
'account_number']][
'N'];
503 if ($showaccountdetail ==
'all' || $resultN != 0) {
506 print
'<td class="tdoverflowmax200">';
507 print
' '.length_accountg($cpt[
'account_number']);
509 print $cpt[
'account_label'];
511 print
'<td class="right">'.price($resultNP).
'</td>';
512 print
'<td class="right">'.price($resultN).
'</td>';
515 foreach ($months as $k => $v) {
516 if (($k + 1) >= $date_startmonth) {
517 $resultM = $totPerAccount[$cpt[
'account_number']][
'M'][$k];
518 print
'<td class="right">'.price($resultM).
'</td>';
521 foreach ($months as $k => $v) {
522 if (($k + 1) < $date_startmonth) {
523 $resultM = $totPerAccount[$cpt[
'account_number']][
'M'][$k];
524 print
'<td class="right">'.price($resultM).
'</td>';
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_eval($s, $returnvalue=0, $hideerrors=1)
Replace eval function to add more security.
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.
Class to manage categories of an accounting account.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
dol_getdate($timestamp, $fast=false, $forcetimezone= '')
Return an array with locale date info.
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
print $_SERVER["PHP_SELF"]
Edit parameters.
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.
print
Draft customers invoices.
img_previous($titlealt= 'default', $moreatt= '')
Show previous logo.
dol_time_plus_duree($time, $duration_value, $duration_unit)
Add a delay to a date.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin= '1', $morecss= '', $textfordropdown= '')
Show information for admin users or standard users.