From 955ff14c6f199530e3e9dcc0d0baf1c354018ddb Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Tue, 17 Apr 2018 19:06:14 +0200 Subject: [PATCH 1/4] Fix: correct syntax for postgresql --- htdocs/install/mysql/migration/7.0.0-8.0.0.sql | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/htdocs/install/mysql/migration/7.0.0-8.0.0.sql b/htdocs/install/mysql/migration/7.0.0-8.0.0.sql index 4418b950ae8..f82086922bc 100644 --- a/htdocs/install/mysql/migration/7.0.0-8.0.0.sql +++ b/htdocs/install/mysql/migration/7.0.0-8.0.0.sql @@ -123,12 +123,15 @@ DELETE FROM llx_c_paiement WHERE code = '' or code = '-' or id = 0; ALTER TABLE llx_c_paiement DROP INDEX uk_c_paiement; ALTER TABLE llx_c_paiement ADD UNIQUE INDEX uk_c_paiement_code(entity, code); -- VMYSQL4.3 ALTER TABLE llx_c_paiement CHANGE COLUMN id id INTEGER AUTO_INCREMENT PRIMARY KEY; +-- VPGSQL8.2 CREATE SEQUENCE llx_c_paiement_seq OWNED BY llx_c_paiement.id; +-- VPGSQL8.2 ALTER TABLE llx_c_paiement ADD PRIMARY KEY (id); -- Add missing keys and primary key ALTER TABLE llx_c_payment_term DROP INDEX uk_c_payment_term; ALTER TABLE llx_c_payment_term ADD UNIQUE INDEX uk_c_payment_term_code(entity, code); -- VMYSQL4.3 ALTER TABLE llx_c_payment_term CHANGE COLUMN rowid rowid INTEGER AUTO_INCREMENT PRIMARY KEY; - +-- VPGSQL8.2 CREATE SEQUENCE llx_c_payment_term_seq OWNED BY llx_c_payment_term.rowid; +-- VPGSQL8.2 ALTER TABLE llx_c_payment_term ADD PRIMARY KEY (rowid); ALTER TABLE llx_oauth_token ADD COLUMN tokenstring text; From e0c0f7fd9ba29a25c6e542f07ae6329cae23dd1c Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Tue, 17 Apr 2018 20:04:55 +0200 Subject: [PATCH 2/4] Fix Accountancy --- htdocs/accountancy/bookkeeping/card.php | 6 +++--- htdocs/accountancy/class/bookkeeping.class.php | 10 ++-------- htdocs/core/modules/modAccounting.class.php | 4 ++-- htdocs/langs/en_US/accountancy.lang | 1 + 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/htdocs/accountancy/bookkeeping/card.php b/htdocs/accountancy/bookkeeping/card.php index 885b090fe0c..51829c004f1 100644 --- a/htdocs/accountancy/bookkeeping/card.php +++ b/htdocs/accountancy/bookkeeping/card.php @@ -617,7 +617,7 @@ if ($action == 'create') } print ''; print ''; - print ''; + print ''; print ''; print ''; print ''; @@ -654,7 +654,7 @@ if ($action == 'create') if ($total_debit != $total_credit) { - setEventMessages(null, array($langs->trans('MvtNotCorrectlyBalanced', $total_credit, $total_debit)), 'warnings'); + setEventMessages(null, array($langs->trans('MvtNotCorrectlyBalanced', $total_debit, $total_credit)), 'warnings'); } if ($action == "" || $action == 'add') { @@ -675,7 +675,7 @@ if ($action == 'create') } print ''; print ''; - print ''; + print ''; print ''; print ''; print ''; diff --git a/htdocs/accountancy/class/bookkeeping.class.php b/htdocs/accountancy/class/bookkeeping.class.php index a703e025c76..6c82672f311 100644 --- a/htdocs/accountancy/class/bookkeeping.class.php +++ b/htdocs/accountancy/class/bookkeeping.class.php @@ -246,9 +246,6 @@ class BookKeeping extends CommonObject } $now = dol_now(); - if (empty($this->date_create)) { - $this->date_create = $now; - } $sql = "INSERT INTO " . MAIN_DB_PREFIX . $this->table_element . " ("; $sql .= "doc_date"; @@ -291,7 +288,7 @@ class BookKeeping extends CommonObject $sql .= "," . $this->montant; $sql .= ",'" . $this->db->escape($this->sens) . "'"; $sql .= ",'" . $this->db->escape($this->fk_user_author) . "'"; - $sql .= ",'" . $this->db->idate($this->date_create). "'"; + $sql .= ",'" . $this->db->idate($now). "'"; $sql .= ",'" . $this->db->escape($this->code_journal) . "'"; $sql .= ",'" . $this->db->escape($this->journal_label) . "'"; $sql .= "," . $this->db->escape($this->piece_num); @@ -496,9 +493,6 @@ class BookKeeping extends CommonObject $this->credit = price2num($this->credit, 'MT'); $now = dol_now(); - if (empty($this->date_create)) { - $this->date_create = $now; - } // Check parameters // Put here code to add control on parameters values @@ -545,7 +539,7 @@ class BookKeeping extends CommonObject $sql .= ' ' . (! isset($this->montant) ? 'NULL' : $this->montant ). ','; $sql .= ' ' . (! isset($this->sens) ? 'NULL' : "'" . $this->db->escape($this->sens) . "'") . ','; $sql .= ' ' . $user->id . ','; - $sql .= ' ' . "'" . $this->db->idate($this->date_create) . "',"; + $sql .= ' ' . "'" . $this->db->idate($now) . "',"; $sql .= ' ' . (empty($this->code_journal) ? 'NULL' : "'" . $this->db->escape($this->code_journal) . "'") . ','; $sql .= ' ' . (empty($this->journal_label) ? 'NULL' : "'" . $this->db->escape($this->journal_label) . "'") . ','; $sql .= ' ' . (empty($this->piece_num) ? 'NULL' : $this->db->escape($this->piece_num)).','; diff --git a/htdocs/core/modules/modAccounting.class.php b/htdocs/core/modules/modAccounting.class.php index d8365776d9c..6b1d57051b6 100644 --- a/htdocs/core/modules/modAccounting.class.php +++ b/htdocs/core/modules/modAccounting.class.php @@ -240,11 +240,11 @@ class modAccounting extends DolibarrModules $r++; $this->export_code[$r]=$this->rights_class.'_'.$r; $this->export_label[$r]='Chartofaccounts'; - $this->export_icon[$r]='accounting'; + $this->export_icon[$r]='Accounting'; $this->export_permission[$r]=array(array("accounting","chartofaccount")); $this->export_fields_array[$r]=array('ac.rowid'=>'ChartofaccountsId','ac.pcg_version'=>'Chartofaccounts','aa.rowid'=>'Id','aa.account_number'=>"AccountAccounting",'aa.label'=>"Label",'aa.account_parent'=>"Accountparent",'aa.pcg_type'=>"Pcgtype",'aa.pcg_subtype'=>'Pcgsubtype','aa.active'=>'Status'); $this->export_TypeFields_array[$r]=array('ac.rowid'=>'List:accounting_system:pcg_version','aa.account_number'=>"Text",'aa.label'=>"Text",'aa.pcg_type'=>'Text','aa.pcg_subtype'=>'Text','aa.active'=>'Status'); - $this->export_entities_array[$r]=array('ac.rowid'=>"accounting",'ac.pcg_version'=>"accounting",'aa.rowid'=>'accounting','aa.account_number'=>"accounting",'aa.label'=>"accounting",'aa.accountparent'=>"accounting",'aa.pcg_type'=>"accounting",'aa.pcgsubtype'=>"accounting",'aa_active'=>"accounting"); + $this->export_entities_array[$r]=array('ac.rowid'=>"Accounting",'ac.pcg_version'=>"Accounting",'aa.rowid'=>'Accounting','aa.account_number'=>"Accounting",'aa.label'=>"Accounting",'aa.accountparent'=>"Accounting",'aa.pcg_type'=>"Accounting",'aa.pcgsubtype'=>"Accounting",'aa_active'=>"Accounting"); $this->export_sql_start[$r]='SELECT DISTINCT '; $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'accounting_account as aa, '.MAIN_DB_PREFIX.'accounting_system as ac'; diff --git a/htdocs/langs/en_US/accountancy.lang b/htdocs/langs/en_US/accountancy.lang index c8973887d2d..876e6b37837 100644 --- a/htdocs/langs/en_US/accountancy.lang +++ b/htdocs/langs/en_US/accountancy.lang @@ -1,4 +1,5 @@ # Dolibarr language file - en_US - Accounting Expert +Accounting=Accounting ACCOUNTING_EXPORT_SEPARATORCSV=Column separator for export file ACCOUNTING_EXPORT_DATE=Date format for export file ACCOUNTING_EXPORT_PIECE=Export the number of piece From bab32e05e71665ca26af724e179a79695643e9a2 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Tue, 17 Apr 2018 21:08:40 +0200 Subject: [PATCH 3/4] Fix: best practice for sequence --- htdocs/install/mysql/migration/7.0.0-8.0.0.sql | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/htdocs/install/mysql/migration/7.0.0-8.0.0.sql b/htdocs/install/mysql/migration/7.0.0-8.0.0.sql index bc1d6a4bb4d..aa9772fcfea 100644 --- a/htdocs/install/mysql/migration/7.0.0-8.0.0.sql +++ b/htdocs/install/mysql/migration/7.0.0-8.0.0.sql @@ -14,7 +14,10 @@ -- To restrict request to Mysql version x.y minimum use -- VMYSQLx.y -- To restrict request to Pgsql version x.y minimum use -- VPGSQLx.y -- To make pk to be auto increment (mysql): -- VMYSQL4.3 ALTER TABLE llx_table CHANGE COLUMN rowid rowid INTEGER NOT NULL AUTO_INCREMENT; --- To make pk to be auto increment (postgres): -- VPGSQL8.2 NOT POSSIBLE. MUST DELETE/CREATE TABLE ? MAY BE --VPGSQL8.2 CREATE SEQUENCE llx_table_seq OWNED BY llx_table.id; -- VPGSQL8.2 ALTER TABLE llx_table ADD PRIMARY KEY (id); +-- To make pk to be auto increment (postgres): -- VPGSQL8.2 CREATE SEQUENCE llx_table_rowid_seq OWNED BY llx_table.rowid; + -- VPGSQL8.2 ALTER TABLE llx_table ADD PRIMARY KEY (rowid); + -- VPGSQL8.2 ALTER TABLE llx_table ALTER COLUMN rowid SET DEFAULT nextval('llx_table_rowid_seq'); + -- VPGSQL8.2 SELECT setval('llx_table_rowid_seq', MAX(rowid)) FROM llx_table; -- To set a field as NULL: -- VMYSQL4.3 ALTER TABLE llx_table MODIFY COLUMN name varchar(60) NULL; -- To set a field as NULL: -- VPGSQL8.2 ALTER TABLE llx_table ALTER COLUMN name DROP NOT NULL; -- To set a field as NOT NULL: -- VMYSQL4.3 ALTER TABLE llx_table MODIFY COLUMN name varchar(60) NOT NULL; @@ -123,15 +126,19 @@ DELETE FROM llx_c_paiement WHERE code = '' or code = '-' or id = 0; ALTER TABLE llx_c_paiement DROP INDEX uk_c_paiement; ALTER TABLE llx_c_paiement ADD UNIQUE INDEX uk_c_paiement_code(entity, code); -- VMYSQL4.3 ALTER TABLE llx_c_paiement CHANGE COLUMN id id INTEGER AUTO_INCREMENT PRIMARY KEY; --- VPGSQL8.2 CREATE SEQUENCE llx_c_paiement_seq OWNED BY llx_c_paiement.id; +-- VPGSQL8.2 CREATE SEQUENCE llx_c_paiement_id_seq OWNED BY llx_c_paiement.id; -- VPGSQL8.2 ALTER TABLE llx_c_paiement ADD PRIMARY KEY (id); +-- VPGSQL8.2 ALTER TABLE llx_c_paiement ALTER COLUMN id SET DEFAULT nextval('llx_c_paiement_id_seq'); +-- VPGSQL8.2 SELECT setval('llx_c_paiement_id_seq', MAX(id)) FROM llx_c_paiement; -- Add missing keys and primary key ALTER TABLE llx_c_payment_term DROP INDEX uk_c_payment_term; ALTER TABLE llx_c_payment_term ADD UNIQUE INDEX uk_c_payment_term_code(entity, code); -- VMYSQL4.3 ALTER TABLE llx_c_payment_term CHANGE COLUMN rowid rowid INTEGER AUTO_INCREMENT PRIMARY KEY; --- VPGSQL8.2 CREATE SEQUENCE llx_c_payment_term_seq OWNED BY llx_c_payment_term.rowid; +-- VPGSQL8.2 CREATE SEQUENCE llx_c_payment_term_rowid_seq OWNED BY llx_c_payment_term.rowid; -- VPGSQL8.2 ALTER TABLE llx_c_payment_term ADD PRIMARY KEY (rowid); +-- VPGSQL8.2 ALTER TABLE llx_c_payment_term ALTER COLUMN rowid SET DEFAULT nextval('llx_c_payment_term_rowid_seq'); +-- VPGSQL8.2 SELECT setval('llx_c_payment_term_rowid_seq', MAX(rowid)) FROM llx_c_payment_term; ALTER TABLE llx_oauth_token ADD COLUMN tokenstring text; From ad197d01c1822aa6d71b531f083ca072f153f988 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Tue, 17 Apr 2018 21:16:17 +0200 Subject: [PATCH 4/4] Fix: avoid error --- htdocs/install/mysql/migration/7.0.0-8.0.0.sql | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/htdocs/install/mysql/migration/7.0.0-8.0.0.sql b/htdocs/install/mysql/migration/7.0.0-8.0.0.sql index aa9772fcfea..e03195ed473 100644 --- a/htdocs/install/mysql/migration/7.0.0-8.0.0.sql +++ b/htdocs/install/mysql/migration/7.0.0-8.0.0.sql @@ -14,10 +14,11 @@ -- To restrict request to Mysql version x.y minimum use -- VMYSQLx.y -- To restrict request to Pgsql version x.y minimum use -- VPGSQLx.y -- To make pk to be auto increment (mysql): -- VMYSQL4.3 ALTER TABLE llx_table CHANGE COLUMN rowid rowid INTEGER NOT NULL AUTO_INCREMENT; --- To make pk to be auto increment (postgres): -- VPGSQL8.2 CREATE SEQUENCE llx_table_rowid_seq OWNED BY llx_table.rowid; - -- VPGSQL8.2 ALTER TABLE llx_table ADD PRIMARY KEY (rowid); - -- VPGSQL8.2 ALTER TABLE llx_table ALTER COLUMN rowid SET DEFAULT nextval('llx_table_rowid_seq'); - -- VPGSQL8.2 SELECT setval('llx_table_rowid_seq', MAX(rowid)) FROM llx_table; +-- To make pk to be auto increment (postgres): +-- -- VPGSQL8.2 CREATE SEQUENCE llx_table_rowid_seq OWNED BY llx_table.rowid; +-- -- VPGSQL8.2 ALTER TABLE llx_table ADD PRIMARY KEY (rowid); +-- -- VPGSQL8.2 ALTER TABLE llx_table ALTER COLUMN rowid SET DEFAULT nextval('llx_table_rowid_seq'); +-- -- VPGSQL8.2 SELECT setval('llx_table_rowid_seq', MAX(rowid)) FROM llx_table; -- To set a field as NULL: -- VMYSQL4.3 ALTER TABLE llx_table MODIFY COLUMN name varchar(60) NULL; -- To set a field as NULL: -- VPGSQL8.2 ALTER TABLE llx_table ALTER COLUMN name DROP NOT NULL; -- To set a field as NOT NULL: -- VMYSQL4.3 ALTER TABLE llx_table MODIFY COLUMN name varchar(60) NOT NULL;