diff --git a/htdocs/accountancy/admin/card.php b/htdocs/accountancy/admin/card.php
index c905ad25cd0..23ebde7e230 100644
--- a/htdocs/accountancy/admin/card.php
+++ b/htdocs/accountancy/admin/card.php
@@ -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);
diff --git a/htdocs/accountancy/bookkeeping/balance.php b/htdocs/accountancy/bookkeeping/balance.php
index fcd7efdab47..de60bd09897 100644
--- a/htdocs/accountancy/bookkeeping/balance.php
+++ b/htdocs/accountancy/bookkeeping/balance.php
@@ -16,7 +16,6 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
- *
*/
/**
@@ -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 = '' . img_edit() . '';
- } elseif (empty($tmparrayforrootaccount['label'])) {
+ } elseif ($accounting_account == 'NotDefined') {
$link = '' . img_edit_add() . '';
+ } 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 = '' . img_edit_add() . '';
}
if (!empty($show_subgroup))
@@ -363,8 +371,22 @@ if ($action != 'export_csv')
print '
';
print '| '.$accounting_account.' | ';
if (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE)) print ''.price($opening_balance).' | ';
- print ''.price($line->debit).' | ';
- print ''.price($line->credit).' | ';
+
+ $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 ''.price($line->debit).' | ';
+ // Credit
+ print ''.price($line->credit).' | ';
+
if (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE)) {
print ''.price(price2num($opening_balance + $line->debit - $line->credit, 'MT')).' | ';
} else {
diff --git a/htdocs/accountancy/class/bookkeeping.class.php b/htdocs/accountancy/class/bookkeeping.class.php
index 40af8784817..614040fc063 100644
--- a/htdocs/accountancy/class/bookkeeping.class.php
+++ b/htdocs/accountancy/class/bookkeeping.class.php
@@ -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);