fix missing test on method result

This commit is contained in:
florian HENRY
2019-03-11 21:25:51 +01:00
parent c6a269e4c4
commit 53a76e91b4

View File

@@ -288,262 +288,251 @@ elseif ($modecompta=="BOOKKEEPING")
$j=1; $j=1;
$sommes = array(); $sommes = array();
$totPerAccount = array(); $totPerAccount = array();
if (!is_array($cats) && $cats<0) {
foreach ($cats as $cat) // Loop on each group setEventMessages(null,$AccCat->errors,'errors');
{ } elseif (is_array($cats) && count($cats)>0) {
if (!empty($cat['category_type'])) // category calculed foreach ($cats as $cat) // Loop on each group
{ {
// When we enter here, $sommes was filled by group of accounts if (!empty($cat['category_type'])) // category calculed
{
// When we enter here, $sommes was filled by group of accounts
$formula = $cat['formula']; $formula = $cat['formula'];
print '<tr class="liste_total">'; print '<tr class="liste_total">';
// Year NP // Year NP
print '<td class="liste_total width200">'; print '<td class="liste_total width200">';
print $cat['code']; print $cat['code'];
print '</td><td>'; print '</td><td>';
print $cat['label']; print $cat['label'];
print '</td>'; print '</td>';
$vars = array(); $vars = array();
// Previous Fiscal year (N-1) // Previous Fiscal year (N-1)
foreach($sommes as $code => $det){ foreach ($sommes as $code => $det) {
$vars[$code] = $det['NP']; $vars[$code] = $det['NP'];
}
$result = strtr($formula, $vars);
//var_dump($result);
//$r = $AccCat->calculate($result);
$r = dol_eval($result, 1);
//var_dump($r);
print '<td class="liste_total right">' . price($r) . '</td>';
// Year N
$code = $cat['code']; // code of categorie ('VTE', 'MAR', ...)
$sommes[$code]['NP'] += $r;
// Current fiscal year (N)
if (is_array($sommes) && ! empty($sommes)){
foreach($sommes as $code => $det){
$vars[$code] = $det['N'];
} }
}
$result = strtr($formula, $vars);
//$r = $AccCat->calculate($result); $result = strtr($formula, $vars);
$r = dol_eval($result, 1);
print '<td class="liste_total right">' . price($r) . '</td>'; //var_dump($result);
$sommes[$code]['N'] += $r; //$r = $AccCat->calculate($result);
$r = dol_eval($result, 1);
//var_dump($r);
// Detail by month print '<td class="liste_total right">' . price($r) . '</td>';
foreach($months as $k => $v)
{
if (($k+1) >= $date_startmonth)
{
foreach($sommes as $code => $det){
$vars[$code] = $det['M'][$k];
}
$result = strtr($formula, $vars);
//$r = $AccCat->calculate($result); // Year N
$r = dol_eval($result, 1); $code = $cat['code']; // code of categorie ('VTE', 'MAR', ...)
$sommes[$code]['NP'] += $r;
print '<td class="liste_total right">' . price($r) . '</td>'; // Current fiscal year (N)
$sommes[$code]['M'][$k] += $r; if (is_array($sommes) && !empty($sommes)) {
} foreach ($sommes as $code => $det) {
} $vars[$code] = $det['N'];
foreach($months as $k => $v)
{
if (($k+1) < $date_startmonth)
{
foreach($sommes as $code => $det){
$vars[$code] = $det['M'][$k];
}
$result = strtr($formula, $vars);
//$r = $AccCat->calculate($result);
$r = dol_eval($result, 1);
print '<td class="liste_total right">' . price($r) . '</td>';
$sommes[$code]['M'][$k] += $r;
}
}
print "</tr>\n";
//var_dump($sommes);
}
else // normal category
{
$code = $cat['code']; // Category code we process
$totCat = array();
$totCat['NP'] = 0;
$totCat['N'] = 0;
$totCat['M'] = array();
foreach($months as $k => $v)
{
$totCat['M'][$k] = 0;
}
// Set $cpts with array of accounts in the category/group
$cpts = $AccCat->getCptsCat($cat['rowid']);
$arrayofaccountforfilter=array();
foreach($cpts as $i => $cpt) // Loop on each account.
{
$arrayofaccountforfilter[]=$cpt['account_number'];
}
// N-1
if (! empty($arrayofaccountforfilter))
{
$return = $AccCat->getSumDebitCredit($arrayofaccountforfilter, $date_start_previous, $date_end_previous, $cat['dc']?$cat['dc']:0);
if ($return < 0) {
setEventMessages(null, $AccCat->errors, 'errors');
$resultNP=0;
} else {
foreach($cpts as $i => $cpt) // Loop on each account.
{
$resultNP = empty($AccCat->sdcperaccount[$cpt['account_number']])?0:$AccCat->sdcperaccount[$cpt['account_number']];
$totCat['NP'] += $resultNP;
$sommes[$code]['NP'] += $resultNP;
$totPerAccount[$cpt['account_number']]['NP'] = $resultNP;
} }
} }
}
// Set value into column N and month M ($totCat) $result = strtr($formula, $vars);
// This make 12 calls for each accountancy account (12 monthes M)
foreach($cpts as $i => $cpt) // Loop on each account. //$r = $AccCat->calculate($result);
$r = dol_eval($result, 1);
print '<td class="liste_total right">' . price($r) . '</td>';
$sommes[$code]['N'] += $r;
// Detail by month
foreach ($months as $k => $v) {
if (($k + 1) >= $date_startmonth) {
foreach ($sommes as $code => $det) {
$vars[$code] = $det['M'][$k];
}
$result = strtr($formula, $vars);
//$r = $AccCat->calculate($result);
$r = dol_eval($result, 1);
print '<td class="liste_total right">' . price($r) . '</td>';
$sommes[$code]['M'][$k] += $r;
}
}
foreach ($months as $k => $v) {
if (($k + 1) < $date_startmonth) {
foreach ($sommes as $code => $det) {
$vars[$code] = $det['M'][$k];
}
$result = strtr($formula, $vars);
//$r = $AccCat->calculate($result);
$r = dol_eval($result, 1);
print '<td class="liste_total right">' . price($r) . '</td>';
$sommes[$code]['M'][$k] += $r;
}
}
print "</tr>\n";
//var_dump($sommes);
} else // normal category
{ {
// We make 1 loop for each account because we may want detail per account. $code = $cat['code']; // Category code we process
// @TODO Optimize to ask a 'group by' account and a filter with account in (..., ...) in request
// Each month $totCat = array();
$resultN = 0; $totCat['NP'] = 0;
foreach($months as $k => $v) $totCat['N'] = 0;
$totCat['M'] = array();
foreach ($months as $k => $v) {
$totCat['M'][$k] = 0;
}
// Set $cpts with array of accounts in the category/group
$cpts = $AccCat->getCptsCat($cat['rowid']);
$arrayofaccountforfilter = array();
foreach ($cpts as $i => $cpt) // Loop on each account.
{ {
$monthtoprocess = $k+1; // ($k+1) is month 1, 2, ..., 12 $arrayofaccountforfilter[] = $cpt['account_number'];
$yeartoprocess = $start_year; }
if (($k+1) < $start_month) $yeartoprocess++;
// N-1
if (!empty($arrayofaccountforfilter)) {
$return = $AccCat->getSumDebitCredit($arrayofaccountforfilter, $date_start_previous, $date_end_previous, $cat['dc'] ? $cat['dc'] : 0);
//var_dump($monthtoprocess.'_'.$yeartoprocess);
$return = $AccCat->getSumDebitCredit($cpt['account_number'], $date_start, $date_end, $cat['dc']?$cat['dc']:0, 'nofilter', $monthtoprocess, $yeartoprocess);
if ($return < 0) { if ($return < 0) {
setEventMessages(null, $AccCat->errors, 'errors'); setEventMessages(null, $AccCat->errors, 'errors');
$resultM=0; $resultNP = 0;
} else { } else {
$resultM=$AccCat->sdc; foreach ($cpts as $i => $cpt) // Loop on each account.
} {
$totCat['M'][$k] += $resultM; $resultNP = empty($AccCat->sdcperaccount[$cpt['account_number']]) ? 0 : $AccCat->sdcperaccount[$cpt['account_number']];
$sommes[$code]['M'][$k] += $resultM;
$totPerAccount[$cpt['account_number']]['M'][$k] = $resultM;
$resultN += $resultM; $totCat['NP'] += $resultNP;
$sommes[$code]['NP'] += $resultNP;
$totPerAccount[$cpt['account_number']]['NP'] = $resultNP;
}
}
} }
$totCat['N'] += $resultN; // Set value into column N and month M ($totCat)
$sommes[$code]['N'] += $resultN; // This make 12 calls for each accountancy account (12 monthes M)
$totPerAccount[$cpt['account_number']]['N'] = $resultN; foreach ($cpts as $i => $cpt) // Loop on each account.
}
// Now output columns for row $code ('VTE', 'MAR', ...)
print "<tr>";
// Column group
print '<td class="width200">';
print $cat['code'];
print '</td>';
// Label of group
print '<td>';
print $cat['label'];
if (count($cpts) > 0) // Show example of 5 first accounting accounts
{
$i=0;
foreach($cpts as $cpt)
{ {
if ($i > 5) // We make 1 loop for each account because we may want detail per account.
{ // @TODO Optimize to ask a 'group by' account and a filter with account in (..., ...) in request
print '...)';
break; // Each month
$resultN = 0;
foreach ($months as $k => $v) {
$monthtoprocess = $k + 1; // ($k+1) is month 1, 2, ..., 12
$yeartoprocess = $start_year;
if (($k + 1) < $start_month)
$yeartoprocess++;
//var_dump($monthtoprocess.'_'.$yeartoprocess);
$return = $AccCat->getSumDebitCredit($cpt['account_number'], $date_start, $date_end, $cat['dc'] ? $cat['dc'] : 0, 'nofilter', $monthtoprocess, $yeartoprocess);
if ($return < 0) {
setEventMessages(null, $AccCat->errors, 'errors');
$resultM = 0;
} else {
$resultM = $AccCat->sdc;
}
$totCat['M'][$k] += $resultM;
$sommes[$code]['M'][$k] += $resultM;
$totPerAccount[$cpt['account_number']]['M'][$k] = $resultM;
$resultN += $resultM;
} }
if ($i > 0) print ', ';
else print ' ('; $totCat['N'] += $resultN;
print $cpt['account_number']; $sommes[$code]['N'] += $resultN;
$i++; $totPerAccount[$cpt['account_number']]['N'] = $resultN;
} }
if ($i <= 5) print ')';
}
else
{
print ' - <span class="warning">'.$langs->trans("GroupIsEmptyCheckSetup").'</span>';
}
print '</td>';
print '<td class="right">' . price($totCat['NP']) . '</td>';
print '<td class="right">' . price($totCat['N']) . '</td>';
// Each month // Now output columns for row $code ('VTE', 'MAR', ...)
foreach($totCat['M'] as $k => $v){
if (($k+1) >= $date_startmonth) print '<td class="right">' . price($v) . '</td>';
}
foreach($totCat['M'] as $k => $v){
if (($k+1) < $date_startmonth) print '<td class="right">' . price($v) . '</td>';
}
print "</tr>\n"; print "<tr>";
// Loop on detail of all accounts to output the detail // Column group
if ($showaccountdetail != 'no') print '<td class="width200">';
{ print $cat['code'];
foreach($cpts as $i => $cpt) print '</td>';
// Label of group
print '<td>';
print $cat['label'];
if (count($cpts) > 0) // Show example of 5 first accounting accounts
{ {
$resultNP=$totPerAccount[$cpt['account_number']]['NP']; $i = 0;
$resultN=$totPerAccount[$cpt['account_number']]['N']; foreach ($cpts as $cpt) {
if ($i > 5) {
if ($showaccountdetail == 'all' || $resultN > 0) print '...)';
{ break;
print '<tr>';
print '<td></td>';
print '<td class="tdoverflowmax200">';
print ' &nbsp; &nbsp; ' . length_accountg($cpt['account_number']);
print ' - ';
print $cpt['account_label'];
print '</td>';
print '<td class="right">' . price($resultNP) . '</td>';
print '<td class="right">' . price($resultN) . '</td>';
// Make one call for each month
foreach($months as $k => $v)
{
if (($k+1) >= $date_startmonth)
{
$resultM=$totPerAccount[$cpt['account_number']]['M'][$k];
print '<td class="right">' . price($resultM) . '</td>';
}
} }
foreach($months as $k => $v) if ($i > 0)
{ print ', ';
if (($k+1) < $date_startmonth) else print ' (';
{ print $cpt['account_number'];
$resultM=$totPerAccount[$cpt['account_number']]['M'][$k]; $i++;
print '<td class="right">' . price($resultM) . '</td>'; }
if ($i <= 5)
print ')';
} else {
print ' - <span class="warning">' . $langs->trans("GroupIsEmptyCheckSetup") . '</span>';
}
print '</td>';
print '<td class="right">' . price($totCat['NP']) . '</td>';
print '<td class="right">' . price($totCat['N']) . '</td>';
// Each month
foreach ($totCat['M'] as $k => $v) {
if (($k + 1) >= $date_startmonth)
print '<td class="right">' . price($v) . '</td>';
}
foreach ($totCat['M'] as $k => $v) {
if (($k + 1) < $date_startmonth)
print '<td class="right">' . price($v) . '</td>';
}
print "</tr>\n";
// Loop on detail of all accounts to output the detail
if ($showaccountdetail != 'no') {
foreach ($cpts as $i => $cpt) {
$resultNP = $totPerAccount[$cpt['account_number']]['NP'];
$resultN = $totPerAccount[$cpt['account_number']]['N'];
if ($showaccountdetail == 'all' || $resultN > 0) {
print '<tr>';
print '<td></td>';
print '<td class="tdoverflowmax200">';
print ' &nbsp; &nbsp; ' . length_accountg($cpt['account_number']);
print ' - ';
print $cpt['account_label'];
print '</td>';
print '<td class="right">' . price($resultNP) . '</td>';
print '<td class="right">' . price($resultN) . '</td>';
// Make one call for each month
foreach ($months as $k => $v) {
if (($k + 1) >= $date_startmonth) {
$resultM = $totPerAccount[$cpt['account_number']]['M'][$k];
print '<td class="right">' . price($resultM) . '</td>';
}
} }
foreach ($months as $k => $v) {
if (($k + 1) < $date_startmonth) {
$resultM = $totPerAccount[$cpt['account_number']]['M'][$k];
print '<td class="right">' . price($resultM) . '</td>';
}
}
print "</tr>\n";
} }
print "</tr>\n";
} }
} }
} }