FIX in pages of balances

This commit is contained in:
Laurent Destailleur 2021-01-21 18:02:17 +01:00
parent 039cb0685b
commit 0f7bdef1c1
3 changed files with 36 additions and 14 deletions

View File

@ -76,7 +76,7 @@ if ($action == 'add' && $user->rights->accounting->chartofaccount)
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors');
$action = 'create';
} else {
$sql = 'SELECT pcg_version FROM ' . MAIN_DB_PREFIX . 'accounting_system WHERE rowid=' . $conf->global->CHARTOFACCOUNTS;
$sql = 'SELECT pcg_version FROM ' . MAIN_DB_PREFIX . 'accounting_system WHERE rowid='.((int) $conf->global->CHARTOFACCOUNTS);
dol_syslog('accountancy/admin/card.php:: $sql=' . $sql);
$result = $db->query($sql);

View File

@ -16,7 +16,6 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
/**
@ -307,7 +306,7 @@ if ($action != 'export_csv')
$accountingaccountstatic->fetch(null, $line->numero_compte, true);
if (!empty($accountingaccountstatic->account_number)) {
$accounting_account = $accountingaccountstatic->getNomUrl(0, 1);
$accounting_account = $accountingaccountstatic->getNomUrl(0, 1, 0, '', 0, -1, 0, 'accountcard');
} else {
$accounting_account = length_accountg($line->numero_compte);
}
@ -322,10 +321,19 @@ if ($action != 'export_csv')
$root_account_description = $tmparrayforrootaccount['label'];
$root_account_number = $tmparrayforrootaccount['account_number'];
//var_dump($tmparrayforrootaccount);
//var_dump($accounting_account);
//var_dump($accountingaccountstatic);
if (empty($accountingaccountstatic->label) && $accountingaccountstatic->id > 0) {
$link = '<a class="editfielda reposition" href="' . DOL_URL_ROOT . '/accountancy/admin/card.php?action=update&token=' . newToken() . '&id=' . $accountingaccountstatic->id . '">' . img_edit() . '</a>';
} elseif (empty($tmparrayforrootaccount['label'])) {
} elseif ($accounting_account == 'NotDefined') {
$link = '<a href="' . DOL_URL_ROOT . '/accountancy/admin/card.php?action=create&token=' . newToken() . '&accountingaccount=' . length_accountg($line->numero_compte) . '">' . img_edit_add() . '</a>';
} elseif (empty($tmparrayforrootaccount['label'])) {
// $tmparrayforrootaccount['label'] not defined = the account has not parent with a parent.
// This is useless, we should not create a new account when an account has no parent, we must edit it to fix its parent.
// BUG 1: Accounts on level root or level 1 must not have a parent 2 level higher, so shoule not show a link to create another account.
// BUG 2: Adding a link to create a new accounting account here is useless because it is not add as parent of the orphelin.
//$link = '<a href="' . DOL_URL_ROOT . '/accountancy/admin/card.php?action=create&token=' . newToken() . '&accountingaccount=' . length_accountg($line->numero_compte) . '">' . img_edit_add() . '</a>';
}
if (!empty($show_subgroup))
@ -363,8 +371,22 @@ if ($action != 'export_csv')
print '<tr class="oddeven">';
print '<td>'.$accounting_account.'</td>';
if (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE)) print '<td class="nowraponall right">'.price($opening_balance).'</td>';
print '<td class="nowraponall right">'.price($line->debit).'</td>';
print '<td class="nowraponall right">'.price($line->credit).'</td>';
$urlzoom = '';
if ($line->numero_compte) {
$urlzoom = DOL_URL_ROOT.'/accountancy/bookkeeping/listbyaccount.php?search_accountancy_code_start='.urlencode($line->numero_compte).'&search_accountancy_code_end='.urlencode($line->numero_compte);
if (GETPOSTISSET('date_startmonth')) {
$urlzoom .= '&search_date_startmonth='.GETPOST('date_startmonth', 'int').'&search_date_startday='.GETPOST('date_startday', 'int').'&search_date_startyear='.GETPOST('date_startyear', 'int');
}
if (GETPOSTISSET('date_endmonth')) {
$urlzoom .= '&search_date_endmonth='.GETPOST('date_endmonth', 'int').'&search_date_endday='.GETPOST('date_endday', 'int').'&search_date_endyear='.GETPOST('date_endyear', 'int');
}
}
// Debit
print '<td class="nowraponall right"><a href="'.$urlzoom.'">'.price($line->debit).'</a></td>';
// Credit
print '<td class="nowraponall right"><a href="'.$urlzoom.'">'.price($line->credit).'</a></td>';
if (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE)) {
print '<td class="nowraponall right">'.price(price2num($opening_balance + $line->debit - $line->credit, 'MT')).'</td>';
} else {

View File

@ -1914,25 +1914,24 @@ class BookKeeping extends CommonObject
/**
* Return id and description of a root accounting account.
* This function takes the parent of parent to get the root account !
* FIXME: This function takes the parent of parent to get the root account !
*
* @param string $account Accounting account
* @return string Root account
* @return array Array with root account information (max 2 upper level)
*/
public function getRootAccount($account = null)
{
global $conf;
$pcgver = $conf->global->CHARTOFACCOUNTS;
$sql = "SELECT root.rowid, root.account_number, root.label as label";
$sql = "SELECT root.rowid, root.account_number, root.label as label,";
$sql .= " parent.rowid as parent_rowid, parent.account_number as parent_account_number, parent.label as parent_label";
$sql .= " FROM ".MAIN_DB_PREFIX."accounting_account as aa";
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
$sql .= " AND asy.rowid = ".((int) $pcgver);
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as parent ON aa.account_parent = parent.rowid";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as root ON parent.account_parent = root.rowid";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as parent ON aa.account_parent = parent.rowid AND parent.active = 1";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as root ON parent.account_parent = root.rowid AND root.active = 1";
$sql .= " WHERE aa.account_number = '".$this->db->escape($account)."'";
$sql .= " AND parent.active = 1";
$sql .= " AND root.active = 1";
$sql .= " AND aa.entity IN (".getEntity('accountancy').")";
dol_syslog(get_class($this)."::select_account sql=".$sql, LOG_DEBUG);
@ -1943,7 +1942,8 @@ class BookKeeping extends CommonObject
$obj = $this->db->fetch_object($resql);
}
return array('id'=>$obj->rowid, 'account_number'=>$obj->account_number, 'label'=>$obj->label);
$result = array('id'=>$obj->rowid, 'account_number'=>$obj->account_number, 'label'=>$obj->label);
return $result;
} else {
$this->error = "Error ".$this->db->lasterror();
dol_syslog(__METHOD__." ".$this->error, LOG_ERR);