Debug v17 - Fix the report on custom groups, column previous period
This commit is contained in:
parent
f4476b905c
commit
bcd5c207cf
@ -678,6 +678,22 @@ class AccountancyCategory // extends CommonObject
|
|||||||
$this->sdc = 0;
|
$this->sdc = 0;
|
||||||
$this->sdcpermonth = array();
|
$this->sdcpermonth = array();
|
||||||
|
|
||||||
|
if (is_array($cpt)) {
|
||||||
|
$listofaccount = '';
|
||||||
|
foreach ($cpt as $cptcursor) {
|
||||||
|
if (! is_null($cptcursor)) {
|
||||||
|
if ($listofaccount) {
|
||||||
|
$listofaccount .= ",";
|
||||||
|
}
|
||||||
|
$listofaccount .= "'".$cptcursor."'";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (empty($listofaccount)) {
|
||||||
|
// List of account is empty, so we do no try sql request, we can say result is empty.
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$sql = "SELECT SUM(t.debit) as debit, SUM(t.credit) as credit";
|
$sql = "SELECT SUM(t.debit) as debit, SUM(t.credit) as credit";
|
||||||
if (is_array($cpt)) {
|
if (is_array($cpt)) {
|
||||||
$sql .= ", t.numero_compte as accountancy_account";
|
$sql .= ", t.numero_compte as accountancy_account";
|
||||||
@ -686,13 +702,6 @@ class AccountancyCategory // extends CommonObject
|
|||||||
//if (in_array($this->db->type, array('mysql', 'mysqli'))) $sql.=' USE INDEX idx_accounting_bookkeeping_doc_date';
|
//if (in_array($this->db->type, array('mysql', 'mysqli'))) $sql.=' USE INDEX idx_accounting_bookkeeping_doc_date';
|
||||||
$sql .= " WHERE t.entity = ".$conf->entity;
|
$sql .= " WHERE t.entity = ".$conf->entity;
|
||||||
if (is_array($cpt)) {
|
if (is_array($cpt)) {
|
||||||
$listofaccount = '';
|
|
||||||
foreach ($cpt as $cptcursor) {
|
|
||||||
if ($listofaccount) {
|
|
||||||
$listofaccount .= ",";
|
|
||||||
}
|
|
||||||
$listofaccount .= "'".$cptcursor."'";
|
|
||||||
}
|
|
||||||
$sql .= " AND t.numero_compte IN (".$this->db->sanitize($listofaccount, 1).")";
|
$sql .= " AND t.numero_compte IN (".$this->db->sanitize($listofaccount, 1).")";
|
||||||
} else {
|
} else {
|
||||||
$sql .= " AND t.numero_compte = '".$this->db->escape($cpt)."'";
|
$sql .= " AND t.numero_compte = '".$this->db->escape($cpt)."'";
|
||||||
@ -709,22 +718,28 @@ class AccountancyCategory // extends CommonObject
|
|||||||
if (is_array($cpt)) {
|
if (is_array($cpt)) {
|
||||||
$sql .= " GROUP BY t.numero_compte";
|
$sql .= " GROUP BY t.numero_compte";
|
||||||
}
|
}
|
||||||
//print $sql;
|
|
||||||
|
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
if ($resql) {
|
if ($resql) {
|
||||||
$num = $this->db->num_rows($resql);
|
$num = $this->db->num_rows($resql);
|
||||||
if ($num) {
|
if ($num) {
|
||||||
$obj = $this->db->fetch_object($resql);
|
$i = 0;
|
||||||
if ($sens == 1) {
|
while ($i < $num) {
|
||||||
$this->sdc = $obj->debit - $obj->credit;
|
$obj = $this->db->fetch_object($resql);
|
||||||
} else {
|
if ($obj) {
|
||||||
$this->sdc = $obj->credit - $obj->debit;
|
if ($sens == 1) {
|
||||||
}
|
$this->sdc = $obj->debit - $obj->credit;
|
||||||
if (is_array($cpt)) {
|
} else {
|
||||||
$this->sdcperaccount[$obj->accountancy_account] = $this->sdc;
|
$this->sdc = $obj->credit - $obj->debit;
|
||||||
|
}
|
||||||
|
if (is_array($cpt)) {
|
||||||
|
$this->sdcperaccount[$obj->accountancy_account] = $this->sdc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $num;
|
return $num;
|
||||||
} else {
|
} else {
|
||||||
$this->error = "Error ".$this->db->lasterror();
|
$this->error = "Error ".$this->db->lasterror();
|
||||||
|
|||||||
@ -184,8 +184,8 @@ llxheader('', $langs->trans('ReportInOut'));
|
|||||||
$formaccounting = new FormAccounting($db);
|
$formaccounting = new FormAccounting($db);
|
||||||
$form = new Form($db);
|
$form = new Form($db);
|
||||||
|
|
||||||
$textprevyear = '<a href="'.$_SERVER["PHP_SELF"].'?year='.($start_year - 1).'">'.img_previous().'</a>';
|
$textprevyear = '<a href="'.$_SERVER["PHP_SELF"].'?year='.($start_year - 1).'&showaccountdetail='.urlencode($showaccountdetail).'">'.img_previous().'</a>';
|
||||||
$textnextyear = ' <a href="'.$_SERVER["PHP_SELF"].'?year='.($start_year + 1).'">'.img_next().'</a>';
|
$textnextyear = ' <a href="'.$_SERVER["PHP_SELF"].'?year='.($start_year + 1).'&showaccountdetail='.urlencode($showaccountdetail).'">'.img_next().'</a>';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -309,8 +309,8 @@ if ($modecompta == 'CREANCES-DETTES') {
|
|||||||
if (!is_array($cats) && $cats < 0) {
|
if (!is_array($cats) && $cats < 0) {
|
||||||
setEventMessages(null, $AccCat->errors, 'errors');
|
setEventMessages(null, $AccCat->errors, 'errors');
|
||||||
} elseif (is_array($cats) && count($cats) > 0) {
|
} elseif (is_array($cats) && count($cats) > 0) {
|
||||||
|
// Loop on each custom group of accounts
|
||||||
foreach ($cats as $cat) {
|
foreach ($cats as $cat) {
|
||||||
// Loop on each group
|
|
||||||
if (!empty($cat['category_type'])) {
|
if (!empty($cat['category_type'])) {
|
||||||
// category calculed
|
// category calculed
|
||||||
// When we enter here, $sommes was filled by group of accounts
|
// When we enter here, $sommes was filled by group of accounts
|
||||||
@ -319,10 +319,10 @@ if ($modecompta == 'CREANCES-DETTES') {
|
|||||||
|
|
||||||
print '<tr class="liste_total">';
|
print '<tr class="liste_total">';
|
||||||
|
|
||||||
// Year NP
|
// Code and Label
|
||||||
print '<td class="liste_total width200">';
|
print '<td class="liste_total tdoverflowmax100" title="'.dol_escape_htmltag($cat['code']).'">';
|
||||||
print dol_escape_htmltag($cat['code']);
|
print dol_escape_htmltag($cat['code']);
|
||||||
print '</td><td>';
|
print '</td><td class="tdoverflowmax250" title="'.dol_escape_htmltag($cat['label']).'">';
|
||||||
print dol_escape_htmltag($cat['label']);
|
print dol_escape_htmltag($cat['label']);
|
||||||
print '</td>';
|
print '</td>';
|
||||||
|
|
||||||
@ -345,83 +345,71 @@ if ($modecompta == 'CREANCES-DETTES') {
|
|||||||
$r = 'Error bad formula: '.$result;
|
$r = 'Error bad formula: '.$result;
|
||||||
$rshort = 'Err';
|
$rshort = 'Err';
|
||||||
print '<td class="liste_total right"><span class="amount" title="'.dol_escape_htmltag($r).'">'.$rshort.'</span></td>';
|
print '<td class="liste_total right"><span class="amount" title="'.dol_escape_htmltag($r).'">'.$rshort.'</span></td>';
|
||||||
print '<td class="liste_total right"><span class="amount" title="'.dol_escape_htmltag($r).'">'.$rshort.'</span></td>';
|
|
||||||
// Detail by month
|
|
||||||
foreach ($months as $k => $v) {
|
|
||||||
if (($k + 1) >= $date_startmonth) {
|
|
||||||
print '<td class="liste_total right"><span class="amount" title="'.dol_escape_htmltag($r).'">'.$rshort.'</span></td>';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
foreach ($months as $k => $v) {
|
|
||||||
if (($k + 1) < $date_startmonth) {
|
|
||||||
print '<td class="liste_total right"><span class="amount" title="'.dol_escape_htmltag($r).'">'.$rshort.'</span></td>';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
//var_dump($result);
|
//var_dump($result);
|
||||||
//$r = $AccCat->calculate($result);
|
//$r = $AccCat->calculate($result);
|
||||||
$r = dol_eval($result, 1, 1, '1');
|
$r = dol_eval($result, 1, 1, '1');
|
||||||
//var_dump($r);
|
|
||||||
|
|
||||||
print '<td class="liste_total right"><span class="amount">'.price($r).'</span></td>';
|
print '<td class="liste_total right"><span class="amount">'.price($r).'</span></td>';
|
||||||
|
}
|
||||||
|
|
||||||
// Year N
|
// Year N
|
||||||
$code = $cat['code']; // code of categorie ('VTE', 'MAR', ...)
|
$code = $cat['code']; // code of categorie ('VTE', 'MAR', ...)
|
||||||
$sommes[$code]['NP'] += $r;
|
$sommes[$code]['NP'] += $r;
|
||||||
|
|
||||||
// Current fiscal year (N)
|
// Current fiscal year (N)
|
||||||
if (is_array($sommes) && !empty($sommes)) {
|
if (is_array($sommes) && !empty($sommes)) {
|
||||||
|
foreach ($sommes as $code => $det) {
|
||||||
|
$vars[$code] = $det['N'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = strtr($formula, $vars);
|
||||||
|
$result = str_replace('--', '+', $result);
|
||||||
|
|
||||||
|
//$r = $AccCat->calculate($result);
|
||||||
|
$r = dol_eval($result, 1, 1, '1');
|
||||||
|
|
||||||
|
print '<td class="liste_total right"><span class="amount">'.price($r).'</span></td>';
|
||||||
|
$sommes[$code]['N'] += $r;
|
||||||
|
|
||||||
|
// Detail by month
|
||||||
|
foreach ($months as $k => $v) {
|
||||||
|
if (($k + 1) >= $date_startmonth) {
|
||||||
foreach ($sommes as $code => $det) {
|
foreach ($sommes as $code => $det) {
|
||||||
$vars[$code] = $det['N'];
|
$vars[$code] = $det['M'][$k];
|
||||||
}
|
}
|
||||||
|
$result = strtr($formula, $vars);
|
||||||
|
$result = str_replace('--', '+', $result);
|
||||||
|
|
||||||
|
//$r = $AccCat->calculate($result);
|
||||||
|
$r = dol_eval($result, 1, 1, '1');
|
||||||
|
|
||||||
|
print '<td class="liste_total right"><span class="amount">'.price($r).'</span></td>';
|
||||||
|
$sommes[$code]['M'][$k] += $r;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$result = strtr($formula, $vars);
|
foreach ($months as $k => $v) {
|
||||||
|
if (($k + 1) < $date_startmonth) {
|
||||||
//$r = $AccCat->calculate($result);
|
foreach ($sommes as $code => $det) {
|
||||||
$r = dol_eval($result, 1, 1, 1);
|
$vars[$code] = $det['M'][$k];
|
||||||
|
|
||||||
print '<td class="liste_total right"><span class="amount">'.price($r).'</span></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, 1, 1);
|
|
||||||
|
|
||||||
print '<td class="liste_total right"><span class="amount">'.price($r).'</span></td>';
|
|
||||||
$sommes[$code]['M'][$k] += $r;
|
|
||||||
}
|
}
|
||||||
}
|
$result = strtr($formula, $vars);
|
||||||
|
$result = str_replace('--', '+', $result);
|
||||||
|
|
||||||
|
//$r = $AccCat->calculate($result);
|
||||||
|
$r = dol_eval($result, 1, 1, '1');
|
||||||
|
|
||||||
foreach ($months as $k => $v) {
|
print '<td class="liste_total right"><span class="amount">'.price($r).'</span></td>';
|
||||||
if (($k + 1) < $date_startmonth) {
|
$sommes[$code]['M'][$k] += $r;
|
||||||
foreach ($sommes as $code => $det) {
|
|
||||||
$vars[$code] = $det['M'][$k];
|
|
||||||
}
|
|
||||||
$result = strtr($formula, $vars);
|
|
||||||
|
|
||||||
//$r = $AccCat->calculate($result);
|
|
||||||
$r = dol_eval($result, 1, 1, 1);
|
|
||||||
|
|
||||||
print '<td class="liste_total right"><span class="amount">'.price($r).'</span></td>';
|
|
||||||
$sommes[$code]['M'][$k] += $r;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print "</tr>\n";
|
print "</tr>\n";
|
||||||
|
|
||||||
//var_dump($sommes);
|
//var_dump($sommes);
|
||||||
} else // normal category
|
} else { // normal category
|
||||||
{
|
|
||||||
$code = $cat['code']; // Category code we process
|
$code = $cat['code']; // Category code we process
|
||||||
|
|
||||||
$totCat = array();
|
$totCat = array();
|
||||||
@ -435,23 +423,25 @@ if ($modecompta == 'CREANCES-DETTES') {
|
|||||||
// Set $cpts with array of accounts in the category/group
|
// Set $cpts with array of accounts in the category/group
|
||||||
$cpts = $AccCat->getCptsCat($cat['rowid']);
|
$cpts = $AccCat->getCptsCat($cat['rowid']);
|
||||||
// We should loop over empty $cpts array, else the category _code_ is used in the formula, which leads to wrong result if the code is a number.
|
// We should loop over empty $cpts array, else the category _code_ is used in the formula, which leads to wrong result if the code is a number.
|
||||||
if (empty($cpts)) $cpts[] = array();
|
if (empty($cpts)) {
|
||||||
|
$cpts[] = array();
|
||||||
|
}
|
||||||
|
|
||||||
$arrayofaccountforfilter = array();
|
$arrayofaccountforfilter = array();
|
||||||
foreach ($cpts as $i => $cpt) { // Loop on each account.
|
foreach ($cpts as $i => $cpt) { // Loop on each account.
|
||||||
$arrayofaccountforfilter[] = $cpt['account_number'];
|
if (!is_null($cpt['account_number'])) {
|
||||||
|
$arrayofaccountforfilter[] = $cpt['account_number'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// N-1
|
// N-1
|
||||||
if (!empty($arrayofaccountforfilter)) {
|
if (!empty($arrayofaccountforfilter)) {
|
||||||
$return = $AccCat->getSumDebitCredit($arrayofaccountforfilter, $date_start_previous, $date_end_previous, $cat['dc'] ? $cat['dc'] : 0);
|
$return = $AccCat->getSumDebitCredit($arrayofaccountforfilter, $date_start_previous, $date_end_previous, $cat['dc'] ? $cat['dc'] : 0);
|
||||||
|
|
||||||
if ($return < 0) {
|
if ($return < 0) {
|
||||||
setEventMessages(null, $AccCat->errors, 'errors');
|
setEventMessages(null, $AccCat->errors, 'errors');
|
||||||
$resultNP = 0;
|
$resultNP = 0;
|
||||||
} else {
|
} else {
|
||||||
foreach ($cpts as $i => $cpt) { // Loop on each account.
|
foreach ($cpts as $i => $cpt) { // Loop on each account found
|
||||||
$resultNP = empty($AccCat->sdcperaccount[$cpt['account_number']]) ? 0 : $AccCat->sdcperaccount[$cpt['account_number']];
|
$resultNP = empty($AccCat->sdcperaccount[$cpt['account_number']]) ? 0 : $AccCat->sdcperaccount[$cpt['account_number']];
|
||||||
|
|
||||||
$totCat['NP'] += $resultNP;
|
$totCat['NP'] += $resultNP;
|
||||||
@ -499,37 +489,38 @@ if ($modecompta == 'CREANCES-DETTES') {
|
|||||||
|
|
||||||
// Now output columns for row $code ('VTE', 'MAR', ...)
|
// Now output columns for row $code ('VTE', 'MAR', ...)
|
||||||
|
|
||||||
print "<tr>";
|
print '<tr'.($showaccountdetail != 'no' ? ' class="trforbreak"' : '').'>';
|
||||||
|
|
||||||
// Column group
|
// Column group
|
||||||
print '<td class="width200">';
|
print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($cat['code']).'">';
|
||||||
print dol_escape_htmltag($cat['code']);
|
print dol_escape_htmltag($cat['code']);
|
||||||
print '</td>';
|
print '</td>';
|
||||||
|
|
||||||
// Label of group
|
// Label of group
|
||||||
print '<td>';
|
$labeltoshow = dol_escape_htmltag($cat['label']);
|
||||||
print dol_escape_htmltag($cat['label']);
|
|
||||||
if (count($cpts) > 0 && !empty($cpts[0])) { // Show example of 5 first accounting accounts
|
if (count($cpts) > 0 && !empty($cpts[0])) { // Show example of 5 first accounting accounts
|
||||||
$i = 0;
|
$i = 0;
|
||||||
foreach ($cpts as $cpt) {
|
foreach ($cpts as $cpt) {
|
||||||
if ($i > 5) {
|
if ($i > 5) {
|
||||||
print '...)';
|
$labeltoshow .= '...)';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if ($i > 0) {
|
if ($i > 0) {
|
||||||
print ', ';
|
$labeltoshow .= ', ';
|
||||||
} else {
|
} else {
|
||||||
print ' (';
|
$labeltoshow .= ' (';
|
||||||
}
|
}
|
||||||
print dol_escape_htmltag($cpt['account_number']);
|
$labeltoshow .= dol_escape_htmltag($cpt['account_number']);
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
if ($i <= 5) {
|
if ($i <= 5) {
|
||||||
print ')';
|
$labeltoshow .= ')';
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
print ' - <span class="warning">'.$langs->trans("GroupIsEmptyCheckSetup").'</span>';
|
$labeltoshow .= ' - <span class="warning">'.$langs->trans("GroupIsEmptyCheckSetup").'</span>';
|
||||||
}
|
}
|
||||||
|
print '<td class="tdoverflowmax250" title="'.dol_escape_htmltag(dol_string_nohtmltag($labeltoshow)).'">';
|
||||||
|
print $labeltoshow;
|
||||||
print '</td>';
|
print '</td>';
|
||||||
|
|
||||||
print '<td class="right"><span class="amount">'.price($totCat['NP']).'</span></td>';
|
print '<td class="right"><span class="amount">'.price($totCat['NP']).'</span></td>';
|
||||||
@ -558,7 +549,7 @@ if ($modecompta == 'CREANCES-DETTES') {
|
|||||||
if ($showaccountdetail == 'all' || $resultN != 0) {
|
if ($showaccountdetail == 'all' || $resultN != 0) {
|
||||||
print '<tr>';
|
print '<tr>';
|
||||||
print '<td></td>';
|
print '<td></td>';
|
||||||
print '<td class="tdoverflowmax200">';
|
print '<td class="tdoverflowmax250">';
|
||||||
print ' '.length_accountg($cpt['account_number']);
|
print ' '.length_accountg($cpt['account_number']);
|
||||||
print ' - ';
|
print ' - ';
|
||||||
print $cpt['account_label'];
|
print $cpt['account_label'];
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user