Nb of sql requests divided by 2 from report per personalized categories
This commit is contained in:
parent
8de51ede18
commit
987303a6ca
@ -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.='<br>('.$langs->trans("SeeReportInInputOutputMode",'<a href="'.$_SERVER["PHP_SELF"].'?year_start='.$year_start.'&modecompta=RECETTES-DEPENSES">','</a>').')';
|
||||
$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 '<th class="liste_titre"></th>';
|
||||
print '<th class="liste_titre" align="right">'.$langs->trans("PreviousYear").'</th>';
|
||||
print '<th class="liste_titre" align="right">'.$langs->trans("SelectedPeriod").'</th>';
|
||||
foreach($months as $k => $v){
|
||||
print '<th class="liste_titre" align="right">'.$langs->trans($v).'</th>';
|
||||
print '<th class="liste_titre width50" align="right" >'.$langs->trans($v).'</th>';
|
||||
}
|
||||
print '</tr>';
|
||||
|
||||
@ -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 "<tr>";
|
||||
|
||||
// Year NP
|
||||
//print '<td colspan="2"><font color="blue">' . $cat['label'] . '</font></td>';
|
||||
print '<td colspan="2">' . $cat['label'] . '</td>';
|
||||
|
||||
@ -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 '<td align="right"><font color="blue">' . price($r) . '</font></td>';
|
||||
$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 '<td align="right"><font color="blue">' . price($r) . '</font></td>';
|
||||
$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 '<td align="right"><font color="blue">' . price($r) . '</font></td>';
|
||||
$sommes[$code]['M'][$k] += $r;
|
||||
}
|
||||
@ -306,7 +318,7 @@ else if ($modecompta=="BOOKKEEPING")
|
||||
|
||||
print "</tr>\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 '<td align="right">' . price($totCat['NP']) . '</td>';
|
||||
print '<td align="right">' . price($totCat['N']) . '</td>';
|
||||
|
||||
@ -398,55 +418,28 @@ else if ($modecompta=="BOOKKEEPING")
|
||||
}
|
||||
print "</tr>\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 '<tr>';
|
||||
print '<td> ' . length_accountg($cpt['account_number']) . '</td>';
|
||||
print '<td>' . $cpt['name_cpt'] . '</td>';
|
||||
print '<td align="right">' . price($resultNP) . '</td>';
|
||||
print '<td align="right">' . price($resultN) . '</td>';
|
||||
}
|
||||
|
||||
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 '<td align="right">' . price($resultM) . '</td>';
|
||||
}
|
||||
}
|
||||
|
||||
if ($simple_report == 'yes') {
|
||||
print "</tr>\n";
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user