28require 
'../../main.inc.php';
 
   29require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
 
   30require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
 
   31require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
 
   32require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formaccounting.class.php';
 
   33require_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);
 
   77if (empty($date_start) || empty($date_end)) { 
 
   81    $year_end = $year_start + ($nbofyear - 1);
 
   83    $date_startmonth = $month_start;
 
   85      if (!$year && $month_start > $month_current) {
 
   89      $month_end = $month_start - 1;
 
   96      $month_end = $month_start;
 
  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;
 
  144if (isModEnabled(
'accounting')) {
 
  145  $modecompta = 
'BOOKKEEPING';
 
  147if (
GETPOST(
"modecompta", 
'alpha')) {
 
  148  $modecompta = 
GETPOST(
"modecompta", 
'alpha');
 
  154$socid = 
GETPOST(
'socid', 
'int');
 
  155if ($user->socid > 0) {
 
  156  $socid = $user->socid;
 
  158if (isModEnabled(
'comptabilite')) {
 
  161if (isModEnabled(
'accounting')) {
 
  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"),
 
  185llxheader(
'', $langs->trans(
'ReportInOut'));
 
  188$form = 
new Form($db);
 
  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>';
 
  196if ($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>').
')';
 
  200  if (isModEnabled(
'accounting')) {
 
  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");
 
  207    $description .= $langs->trans(
"DepositsAreNotIncluded");
 
  209    $description .= $langs->trans(
"DepositsAreIncluded");
 
  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>').
')';
 
  220  if (isModEnabled(
'accounting')) {
 
  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")).
')';
 
  243report_header($name, 
'', $period, $periodlink ?? 
'', $description, $builddate, $exportlink ?? 
'', array(
'modecompta'=>$modecompta, 
'action' => 
''), $calcmode);
 
  246if (isModEnabled(
'accounting') && $modecompta != 
'BOOKKEEPING') {
 
  247  print 
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0, 1);
 
  253print 
'<div class="div-table-responsive">';
 
  254print 
'<table class="tagtable liste'.($moreforfilter ? 
" listwithfilterbefore" : 
"").
'">'.
"\n";
 
  256print 
'<tr class="liste_titre">';
 
  257print 
'<th class="liste_titre">'.$langs->trans(
"AccountingCategory").
'</th>';
 
  258print 
'<th class="liste_titre"></th>';
 
  259print 
'<th class="liste_titre right">'.$langs->trans(
"PreviousPeriod").
'</th>';
 
  260print 
'<th class="liste_titre right">'.$langs->trans(
"SelectedPeriod").
'</th>';
 
  261foreach ($months as $k => $v) {
 
  262  if (($k + 1) >= $date_startmonth && $k < $date_endmonth) {
 
  263    print 
'<th class="liste_titre right width50">'.$langs->trans(
'MonthShort'.sprintf(
"%02s", ($k + 1))).
'</th>';
 
  266foreach ($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>';
 
  273if ($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 && $k < $date_endmonth) {
 
  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) {
 
  508            if (($yeartoprocess == $start_year && ($k + 1) >= $date_startmonth && $k < $date_endmonth) ||
 
  509              ($yeartoprocess == $start_year + 1 && ($k + 1) < $date_startmonth)
 
  512              if (isset($cpt[
'account_number'])) {
 
  513                $return = $AccCat->getSumDebitCredit($cpt[
'account_number'], $date_start, $date_end, empty($cat[
'dc']) ? 0 : $cat[
'dc'], 
'nofilter', $monthtoprocess, $yeartoprocess);
 
  518                  $resultM = $AccCat->sdc;
 
  523              if (empty($totCat[
'M'][$k])) {
 
  524                $totCat[
'M'][$k] = $resultM;
 
  526                $totCat[
'M'][$k] += $resultM;
 
  528              if (empty($sommes[$code][
'M'][$k])) {
 
  529                $sommes[$code][
'M'][$k] = $resultM;
 
  531                $sommes[$code][
'M'][$k] += $resultM;
 
  533              if (isset($cpt[
'account_number'])) {
 
  534                $totPerAccount[$cpt[
'account_number']][
'M'][$k] = $resultM;
 
  537              $resultN += $resultM;
 
  541          if (empty($totCat)) {
 
  542            $totCat[
'N'] = $resultN;
 
  544            $totCat[
'N'] += $resultN;
 
  546          if (empty($sommes[$code][
'N'])) {
 
  547            $sommes[$code][
'N'] = $resultN;
 
  549            $sommes[$code][
'N'] += $resultN;
 
  551          if (isset($cpt[
'account_number'])) {
 
  552            $totPerAccount[$cpt[
'account_number']][
'N'] = $resultN;
 
  559        print 
'<tr'.($showaccountdetail != 
'no' ? 
' class="trforbreak"' : 
'').
'>';
 
  562        print 
'<td class="tdoverflowmax100" title="'.dol_escape_htmltag($cat[
'code']).
'">';
 
  568        if (count($cpts) > 0 && !empty($cpts[0])) {    
 
  570          foreach ($cpts as $cpt) {
 
  572              $labeltoshow .= 
'...)';
 
  576              $labeltoshow .= 
', ';
 
  578              $labeltoshow .= 
' (';
 
  587          $labeltoshow .= 
' - <span class="warning">'.$langs->trans(
"GroupIsEmptyCheckSetup").
'</span>';
 
  589        print 
'<td class="tdoverflowmax250 borderright" title="'.dol_escape_htmltag(
dol_string_nohtmltag($labeltoshow)).
'">';
 
  593        print 
'<td class="right"><span class="amount">'.price($totCat[
'NP']).
'</span></td>';
 
  594        print 
'<td class="right borderright"><span class="amount">'.price($totCat[
'N']).
'</span></td>';
 
  597        foreach ($totCat[
'M'] as $k => $v) {
 
  598          if (($k + 1) >= $date_startmonth && $k < $date_endmonth) {
 
  599            print 
'<td class="right nowraponall"><span class="amount">'.price($v).
'</span></td>';
 
  602        foreach ($totCat[
'M'] as $k => $v) {
 
  603          if (($k + 1) < $date_startmonth) {
 
  604            print 
'<td class="right nowraponall"><span class="amount">'.price($v).
'</span></td>';
 
  611        if ($showaccountdetail != 
'no') {
 
  612          foreach ($cpts as $i => $cpt) {
 
  613            if (isset($cpt[
'account_number'])) {
 
  614              $resultNP = $totPerAccount[$cpt[
'account_number']][
'NP'];
 
  615              $resultN = $totPerAccount[$cpt[
'account_number']][
'N'];
 
  621            if ($showaccountdetail == 
'all' || $resultN != 0) {
 
  625              if (isset($cpt[
'account_number'])) {
 
  626                $labeldetail = 
'     '.length_accountg($cpt[
'account_number']).
' - '.$cpt[
'account_label'];
 
  631              print 
'<td class="tdoverflowmax250 borderright" title="'.dol_escape_htmltag($labeldetail).
'">';
 
  634              print 
'<td class="right"><span class="amount">'.price($resultNP).
'</span></td>';
 
  635              print 
'<td class="right borderright"><span class="amount">'.price($resultN).
'</span></td>';
 
  638              foreach ($months as $k => $v) {
 
  639                if (($k + 1) >= $date_startmonth && $k < $date_endmonth) {
 
  640                  if (isset($cpt[
'account_number'])) {
 
  641                    $resultM = $totPerAccount[$cpt[
'account_number']][
'M'][$k];
 
  645                  print 
'<td class="right"><span class="amount">'.price($resultM).
'</span></td>';
 
  648              foreach ($months as $k => $v) {
 
  649                if (($k + 1) < $date_startmonth) {
 
  650                  if (isset($cpt[
'account_number'])) {
 
  651                    $resultM = empty($totPerAccount[$cpt[
'account_number']][
'M'][$k]) ? 0 : $totPerAccount[$cpt[
'account_number']][
'M'][$k];
 
  655                  print 
'<td class="right"><span class="amount">'.price($resultM).
'</span></td>';
 
Class to manage categories of an accounting account.
 
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_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
 
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.
 
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
 
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.
 
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
 
img_next($titlealt='default', $moreatt='')
Show next logo.
 
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
 
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
 
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
 
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.