diff --git a/htdocs/compta/resultat/result.php b/htdocs/compta/resultat/result.php index aa714cf042f..fb78c6b8485 100644 --- a/htdocs/compta/resultat/result.php +++ b/htdocs/compta/resultat/result.php @@ -39,16 +39,16 @@ $cat_id = GETPOST('account_category'); $selectcpt = GETPOST('cpt_bk'); $id = GETPOST('id', 'int'); $rowid = GETPOST('rowid', 'int'); -$cancel = GETPOST('cancel'); -$simple_report = GETPOST('simple_report'); +$cancel = GETPOST('cancel','alpha'); +$showaccountdetail = GETPOST('showaccountdetail','aZ09'); -$date_startmonth=GETPOST('date_startmonth'); -$date_startday=GETPOST('date_startday'); -$date_startyear=GETPOST('date_startyear'); -$date_endmonth=GETPOST('date_endmonth'); -$date_endday=GETPOST('date_endday'); -$date_endyear=GETPOST('date_endyear'); +$date_startmonth=GETPOST('date_startmonth','int'); +$date_startday=GETPOST('date_startday','int'); +$date_startyear=GETPOST('date_startyear','int'); +$date_endmonth=GETPOST('date_endmonth','int'); +$date_endday=GETPOST('date_endday','int'); +$date_endyear=GETPOST('date_endyear','int'); $nbofyear=1; @@ -181,10 +181,11 @@ else if ($modecompta=="BOOKKEEPING") //$calcmode.='
('.$langs->trans("SeeReportInInputOutputMode",'','').')'; $nomlink = ''; $period=$form->select_date($date_start,'date_start',0,0,0,'',1,0,1).' - '.$form->select_date($date_end,'date_end',0,0,0,'',1,0,1); - $period.='     '.$langs->trans("DetailByAccount").' '. $form->selectyesno('simple_report',$simple_report,0); + $period.='     '.$langs->trans("DetailByAccount").' '. $form->selectyesno('showaccountdetail',$showaccountdetail,0); $periodlink = $textprevyear . " " . $langs->trans("Year") . " " . $start_year . " " . $textnextyear ; $exportlink = ''; - $description=$langs->trans("RulesResultBookkeepingPersonalized", $langs->transnoentitiesnoconv("Accountancy").' / '.$langs->transnoentitiesnoconv("Setup").' / '.$langs->trans("AccountingCategory")); + $description=$langs->trans("RulesResultBookkeepingPersonalized"). + $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->trans("AccountingCategory")).')'; //if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $description.= $langs->trans("DepositsAreNotIncluded"); //else $description.= $langs->trans("DepositsAreIncluded"); $builddate = time(); @@ -224,7 +225,7 @@ print ''; print ''.$langs->trans("PreviousYear").''; print ''.$langs->trans("SelectedPeriod").''; foreach($months as $k => $v){ - print ''.$langs->trans($v).''; + print ''.$langs->trans($v).''; } print ''; @@ -240,9 +241,6 @@ else if ($modecompta=="RECETTES-DEPENSES") } else if ($modecompta=="BOOKKEEPING") { - // TODO - //if (! empty($date_start) && ! empty($date_end)) - // $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'"; //All categories $cats = $AccCat->getCats(); @@ -250,14 +248,19 @@ else if ($modecompta=="BOOKKEEPING") $j=1; $sommes = array(); + $totPerAccount = array(); foreach ($cats as $cat) // Loop on each group { if (!empty($cat['category_type'])) // category calculed { + // When we enter here, $sommes was filled by group of accounts + $formula = $cat['formula']; print ""; + + // Year NP //print '' . $cat['label'] . ''; print '' . $cat['label'] . ''; @@ -271,11 +274,15 @@ else if ($modecompta=="BOOKKEEPING") $result = strtr($formula, $vars); - - $r = $AccCat->calculate($result); + //var_dump($result); + //$r = $AccCat->calculate($result); + $r = dol_eval($result, 1); + //var_dump($r); print '' . price($r) . ''; - $code = $cat['code']; // code categorie de calcule + + // Year N + $code = $cat['code']; // code of categorie ('VTE', 'MAR', ...) $sommes[$code]['NP'] += $r; // Current fiscal year (N) @@ -287,18 +294,23 @@ else if ($modecompta=="BOOKKEEPING") $result = strtr($formula, $vars); - $r = $AccCat->calculate($result); + //$r = $AccCat->calculate($result); + $r = dol_eval($result, 1); print '' . price($r) . ''; $sommes[$code]['N'] += $r; // Detail by month - foreach($months as $k => $v){ + foreach($months as $k => $v) + { foreach($sommes as $code => $det){ $vars[$code] = $det['M'][$k]; } $result = strtr($formula, $vars); - $r = $AccCat->calculate($result); + + //$r = $AccCat->calculate($result); + $r = dol_eval($result, 1); + print '' . price($r) . ''; $sommes[$code]['M'][$k] += $r; } @@ -306,7 +318,7 @@ else if ($modecompta=="BOOKKEEPING") print "\n"; - + //var_dump($sommes); } else // normal category { @@ -352,7 +364,8 @@ else if ($modecompta=="BOOKKEEPING") $code = $cat['code']; - // Column N Previous and N + // Set value into column NPrevious, N and each month M ($totCat) + // This make 14 calls for each detail of account (NP, N and month m) foreach($cpts as $i => $cpt) { // N-1 @@ -376,6 +389,10 @@ else if ($modecompta=="BOOKKEEPING") $totCat['NP'] += $resultNP; $totCat['N'] += $resultN; + $sommes[$code]['NP'] += $resultNP; + $sommes[$code]['N'] += $resultN; + $totPerAccount[$cpt['account_number']]['NP'] = $resultNP; + $totPerAccount[$cpt['account_number']]['N'] = $resultN; foreach($months as $k => $v) { @@ -387,9 +404,12 @@ else if ($modecompta=="BOOKKEEPING") $resultM=$AccCat->sdc; } $totCat['M'][$k] += $resultM; + $sommes[$code]['M'][$k] += $resultM; + $totPerAccount[$cpt['account_number']]['M'][$k] = $resultM; } } + // Now output columns for row $code ('VTE', 'MAR', ...) print '' . price($totCat['NP']) . ''; print '' . price($totCat['N']) . ''; @@ -398,55 +418,28 @@ else if ($modecompta=="BOOKKEEPING") } print "\n"; - // - foreach($cpts as $i => $cpt) + // Loop on detail of all accounts + // This make 14 calls for each detail of account (NP, N and month m) + if ($showaccountdetail == 'yes') { - // N-1 - $return = $AccCat->getResult($cpt['account_number'], 0, $date_start_previous, $date_end_previous, $cpt['dc']); + foreach($cpts as $i => $cpt) + { + $resultNP=$totPerAccount[$cpt['account_number']]['NP']; + $resultN=$totPerAccount[$cpt['account_number']]['N']; - if ($return < 0) { - setEventMessages(null, $AccCat->errors, 'errors'); - $resultNP=0; - } else { - $resultNP=$AccCat->sdc; - } - - //N - $return = $AccCat->getResult($cpt['account_number'], 0, $date_start, $date_end, $cpt['dc']); - if ($return < 0) { - setEventMessages(null, $AccCat->errors, 'errors'); - $resultN=0; - } else { - $resultN=$AccCat->sdc; - } - - $sommes[$code]['NP'] += $resultNP; - $sommes[$code]['N'] += $resultN; - - if ($simple_report == 'yes') { print ''; print '     ' . length_accountg($cpt['account_number']) . ''; print '' . $cpt['name_cpt'] . ''; print '' . price($resultNP) . ''; print '' . price($resultN) . ''; - } - foreach($months as $k => $v) - { - $return = $AccCat->getResult($cpt['account_number'], $k+1, $date_start, $date_end, $cpt['dc']); - if ($return < 0) { - setEventMessages(null, $AccCat->errors, 'errors'); - $resultM=0; - } else { - $resultM=$AccCat->sdc; - } - $sommes[$code]['M'][$k] += $resultM; - if ($simple_report == 'yes') { + // Make one call for each month + foreach($months as $k => $v) + { + $resultM=$totPerAccount[$cpt['account_number']]['M'][$k]; print '' . price($resultM) . ''; } - } - if ($simple_report == 'yes') { print "\n"; } }