From 71c0be20b972d0fd3efac0da60a2980d92bb83a5 Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@destailleur.fr>
Date: Thu, 15 Jun 2017 10:30:32 +0200
Subject: [PATCH] Change data structure for bookkeeping v6

---
 dev/translation/erp_comparison_translation.txt        |  4 ++--
 htdocs/install/mysql/migration/5.0.0-6.0.0.sql        | 11 ++++++++++-
 .../mysql/tables/llx_accounting_bookkeeping.sql       |  5 +++--
 3 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/dev/translation/erp_comparison_translation.txt b/dev/translation/erp_comparison_translation.txt
index daa1bc79e92..fb96c17e3f9 100644
--- a/dev/translation/erp_comparison_translation.txt
+++ b/dev/translation/erp_comparison_translation.txt
@@ -8,7 +8,7 @@ Contact/address		Contact person		Partner/Contact (individual)
 Financial			??					Invoicing
 
 Income / Expense	??					Profit / Loss
-Balance									Net profit
-
+Balance				??					Net profit
+Subledger account	Subledger account	??
 
 
diff --git a/htdocs/install/mysql/migration/5.0.0-6.0.0.sql b/htdocs/install/mysql/migration/5.0.0-6.0.0.sql
index bc09bf25ca3..46e3b698100 100644
--- a/htdocs/install/mysql/migration/5.0.0-6.0.0.sql
+++ b/htdocs/install/mysql/migration/5.0.0-6.0.0.sql
@@ -188,9 +188,18 @@ ALTER TABLE llx_bank_account ADD CONSTRAINT fk_bank_account_accountancy_journal
 
 --Update general ledger for FEC format & harmonization
 ALTER TABLE llx_accounting_bookkeeping MODIFY COLUMN code_tiers varchar(32);
+ALTER TABLE llx_accounting_bookkeeping CHANGE COLUMN code_tiers thirdparty_code varchar(32);
+
+--Subledger account
+ALTER TABLE llx_accounting_bookkeeping ADD COLUMN subledger_account varchar(32);
+ALTER TABLE llx_accounting_bookkeeping CHANGE COLUMN thirdparty_label subledger_label varchar(255);    	-- If field was already created, rename it	
+ALTER TABLE llx_accounting_bookkeeping ADD COLUMN subledger_label varchar(255) AFTER subledger_account;	-- If field dod not exists yet
+
+update llx_accounting_bookkeeping set subledger_account = numero_compte where subledger_account IS NULL;
+
 ALTER TABLE llx_accounting_bookkeeping MODIFY COLUMN label_compte varchar(255);
 ALTER TABLE llx_accounting_bookkeeping MODIFY COLUMN code_journal varchar(32);
-ALTER TABLE llx_accounting_bookkeeping ADD COLUMN thirdparty_label varchar(255) AFTER code_tiers;
+
 ALTER TABLE llx_accounting_bookkeeping ADD COLUMN label_operation varchar(255) AFTER label_compte;
 ALTER TABLE llx_accounting_bookkeeping ADD COLUMN multicurrency_amount double AFTER sens;
 ALTER TABLE llx_accounting_bookkeeping ADD COLUMN multicurrency_code varchar(255) AFTER multicurrency_amount;
diff --git a/htdocs/install/mysql/tables/llx_accounting_bookkeeping.sql b/htdocs/install/mysql/tables/llx_accounting_bookkeeping.sql
index 651fee6c339..ad1160c356d 100644
--- a/htdocs/install/mysql/tables/llx_accounting_bookkeeping.sql
+++ b/htdocs/install/mysql/tables/llx_accounting_bookkeeping.sql
@@ -26,8 +26,9 @@ CREATE TABLE llx_accounting_bookkeeping
   doc_ref               varchar(300) NOT NULL,		-- 					| facture_client/reglement_client/... reference number
   fk_doc                integer NOT NULL,			-- 					| facture_client/reglement_client/... rowid
   fk_docdet             integer NOT NULL,			-- 					| facture_client/reglement_client/... line rowid
-  code_tiers            varchar(32),				-- FEC:CompAuxNum	| account number of auxiliary account
-  thirdparty_label      varchar(255),				-- FEC:CompAuxLib	| label of auxiliary account
+  thirdparty_code       varchar(32),                -- Third party code (customer or supplier) when record is saved (may help debug) 
+  subledger_account     varchar(32),				-- FEC:CompAuxNum	| account number of subledger account
+  subledger_label       varchar(255),				-- FEC:CompAuxLib	| label of subledger account
   numero_compte         varchar(32) NOT NULL,		-- FEC:CompteNum	| account number
   label_compte          varchar(255) NOT NULL,		-- FEC:CompteLib	| label of account
   label_operation       varchar(255),				-- FEC:EcritureLib	| label of the operation
-- 
GitLab