diff --git a/htdocs/accountancy/admin/account.php b/htdocs/accountancy/admin/account.php
index 3f251e0090b..70f191f3679 100644
--- a/htdocs/accountancy/admin/account.php
+++ b/htdocs/accountancy/admin/account.php
@@ -161,11 +161,11 @@ if ($result) {
print '';
print '
';
- print ' | ';
- print ' | ';
- print ' | ';
- print ' | ';
- print ' | ';
+ print ' | ';
+ print ' | ';
+ print ' | ';
+ print ' | ';
+ print ' | ';
print ' | ';
print '';
print '';
@@ -190,7 +190,7 @@ if ($result) {
print ' | ' . $accountstatic->getNomUrl(1) . ' | ';
print '' . $obj->label . ' | ';
- if ($obj->account_parent)
+ if (! empty($obj->account_parent))
{
$accountparent->id = $obj->rowid2;
$accountparent->label = $obj->label2;
diff --git a/htdocs/accountancy/admin/card.php b/htdocs/accountancy/admin/card.php
index eeb94bddf60..8d1ef913e35 100644
--- a/htdocs/accountancy/admin/card.php
+++ b/htdocs/accountancy/admin/card.php
@@ -59,12 +59,17 @@ if ($action == 'add') {
// Clean code
$account_number = clean_account(GETPOST('account_number')); // Accounting account without zero on the right
+ if (GETPOST('account_category') <= 0) {
+ $account_parent = '';
+ } else {
+ $account_parent = GETPOST('account_category','int');
+ }
$object->fk_pcg_version = $obj->pcg_version;
$object->pcg_type = GETPOST('pcg_type');
$object->pcg_subtype = GETPOST('pcg_subtype');
$object->account_number = $account_number;
- $object->account_parent = GETPOST('account_parent', 'int');
+ $object->account_parent = $account_parent;
$object->account_category = GETPOST('account_category');
$object->label = GETPOST('label', 'alpha');
$object->active = 1;
@@ -96,12 +101,17 @@ if ($action == 'add') {
// Clean code
$account_number = clean_account(GETPOST('account_number')); // Accounting account without zero on the right
-
+ if (GETPOST('account_category') <= 0) {
+ $account_parent = '';
+ } else {
+ $account_parent = GETPOST('account_category','int');
+ }
+
$object->fk_pcg_version = $obj->pcg_version;
$object->pcg_type = GETPOST('pcg_type');
$object->pcg_subtype = GETPOST('pcg_subtype');
$object->account_number = $account_number;
- $object->account_parent = GETPOST('account_parent', 'int');
+ $object->account_parent = account_parent;
$object->account_category = GETPOST('account_category');
$object->label = GETPOST('label', 'alpha');
diff --git a/htdocs/install/mysql/migration/3.9.0-4.0.0.sql b/htdocs/install/mysql/migration/3.9.0-4.0.0.sql
index 78dfbf95be9..b0e42872772 100644
--- a/htdocs/install/mysql/migration/3.9.0-4.0.0.sql
+++ b/htdocs/install/mysql/migration/3.9.0-4.0.0.sql
@@ -342,3 +342,5 @@ CREATE TABLE llx_c_accounting_category (
) ENGINE=innodb;
ALTER TABLE llx_c_accounting_category ADD UNIQUE INDEX uk_c_accounting_category(code);
+
+ALTER TABLE llx_accounting_account MODIFY COLUMN account_parent integer;
diff --git a/htdocs/install/mysql/tables/llx_accounting_account.sql b/htdocs/install/mysql/tables/llx_accounting_account.sql
index e8927cdfda5..d74c1b75105 100644
--- a/htdocs/install/mysql/tables/llx_accounting_account.sql
+++ b/htdocs/install/mysql/tables/llx_accounting_account.sql
@@ -29,7 +29,7 @@ create table llx_accounting_account
pcg_type varchar(20) NOT NULL,
pcg_subtype varchar(20) NOT NULL,
account_number varchar(32) NOT NULL,
- account_parent varchar(32),
+ account_parent integer, -- Hierarchic parent
label varchar(255) NOT NULL,
fk_accounting_category integer DEFAULT 0,
fk_user_author integer DEFAULT NULL,