瀏覽代碼

Fix: Solve conflict into migration/backup/restore (child tables
must be after parent tables).
Fix: Migration of old version

Laurent Destailleur 12 年之前
父節點
當前提交
db91526643

+ 3 - 3
htdocs/accountancy/class/accountancysystem.class.php

@@ -59,15 +59,15 @@ class AccountancySystem
 	function create($user)
 	{
 		$now=dol_now();
-		
-		$sql = "INSERT INTO ".MAIN_DB_PREFIX."accountingsystem";
+
+		$sql = "INSERT INTO ".MAIN_DB_PREFIX."accounting_system";
 		$sql.= " (date_creation, fk_user_author, numero,intitule)";
 		$sql.= " VALUES (".$this->db->idate($now).",".$user->id.",'".$this->numero."','".$this->intitule."')";
 
 		$resql = $this->db->query($sql);
 		if ($resql)
 		{
-			$id = $this->db->last_insert_id(MAIN_DB_PREFIX."accountingsystem");
+			$id = $this->db->last_insert_id(MAIN_DB_PREFIX."accounting_system");
 
 			if ($id > 0)
 			{

+ 16 - 16
htdocs/admin/accounting.php

@@ -41,9 +41,9 @@ $compta_mode = defined('COMPTA_MODE')?COMPTA_MODE:'RECETTES-DEPENSES';
 if ($action == 'setcomptamode')
 {
 	$compta_mode = GETPOST('compta_mode','alpha');
-	
+
 	$res = dolibarr_set_const($db, 'COMPTA_MODE', $compta_mode,'chaine',0,'',$conf->entity);
-	
+
 	if (! $res > 0) $error++;
 
  	if (! $error)
@@ -60,9 +60,9 @@ if ($action == 'setcomptamode')
 if ($action == 'setchart')
 {
 	$chartofaccounts = GETPOST('chartofaccounts','alpha');
-	
+
 	$res = dolibarr_set_const($db, 'CHARTOFACCOUNTS', $chartofaccounts,'chaine',0,'',$conf->entity);
-	
+
 	if (! $res > 0) $error++;
 
  	if (! $error)
@@ -81,9 +81,9 @@ if ($action == 'update' || $action == 'add')
 	$constvalue = GETPOST('constvalue','alpha');
 	$consttype = GETPOST('consttype','alpha');
 	$constnote = GETPOST('constnote','alpha');
-	
+
 	$res = dolibarr_set_const($db, $constname, $constvalue, $consttype, 0, $constnote, $conf->entity);
-	
+
 	if (! $res > 0) $error++;
 
  	if (! $error)
@@ -157,13 +157,13 @@ if (! empty($conf->global->ACCOUNTING_SELECTCHART) && ! empty($conf->accounting-
 {
   print '<br>';
   print_titre($langs->trans("Definechartofaccounts"));
-  
+
   print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
   print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'" />';
-  
+
   print '<table class="noborder" width="100%">';
   $var=True;
-  
+
   print '<tr class="liste_titre">';
   print '<td>';
   print '<input type="hidden" name="action" value="setchart">';
@@ -176,9 +176,9 @@ if (! empty($conf->global->ACCOUNTING_SELECTCHART) && ! empty($conf->accounting-
   print "<td>";
   print '<select class="flat" name="chartofaccounts" id="chartofaccounts">';
   print '<option value="0">'.$langs->trans("DoNotSuggestChart").'</option>';
-  
+
   $sql = "SELECT rowid, pcg_version, fk_pays, label, active";
-  $sql.= " FROM ".MAIN_DB_PREFIX."accountingsystem";
+  $sql.= " FROM ".MAIN_DB_PREFIX."accounting_system";
   $sql.= " WHERE active = 1";
   $sql.= " AND fk_pays = ".$mysoc->country_id;
   $var=True;
@@ -191,11 +191,11 @@ if (! empty($conf->global->ACCOUNTING_SELECTCHART) && ! empty($conf->accounting-
       {
           $var=!$var;
           $row = $db->fetch_row($resql);
-  
+
           print '<option value="'.$row[0].'"';
           print $conf->global->CHARTOFACCOUNTS == $row[0] ? ' selected="selected"':'';
           print '>'.$row[1].' - '.$row[3].'</option>';
-  
+
           $i++;
       }
   }
@@ -250,11 +250,11 @@ foreach ($list as $key)
 	print '<input type="hidden" name="action" value="update">';
 	print '<input type="hidden" name="consttype" value="string">';
 	print '<input type="hidden" name="constname" value="'.$key.'">';
-	
+
 	print '<tr '.$bc[$var].' class="value">';
 
 	// Param
-	$libelle = $langs->trans($key); 
+	$libelle = $langs->trans($key);
 	print '<td>'.$libelle;
 	//print ' ('.$key.')';
 	print "</td>\n";
@@ -266,7 +266,7 @@ foreach ($list as $key)
 	print '<input type="submit" class="button" value="'.$langs->trans('Modify').'" name="button"> &nbsp; ';
 	print "</td></tr>\n";
 	print '</form>';
-	
+
 	$i++;
 }
 

+ 2 - 2
htdocs/admin/dict.php

@@ -99,7 +99,7 @@ $tabname[20]= MAIN_DB_PREFIX."c_input_method";
 $tabname[21]= MAIN_DB_PREFIX."c_availability";
 $tabname[22]= MAIN_DB_PREFIX."c_input_reason";
 $tabname[23]= MAIN_DB_PREFIX."accountingaccount";
-$tabname[24]= MAIN_DB_PREFIX."accountingsystem";
+$tabname[24]= MAIN_DB_PREFIX."accounting_system";
 
 // Dictionary labels
 $tablib=array();
@@ -153,7 +153,7 @@ $tabsql[20]= "SELECT rowid   as rowid, code, libelle, active FROM ".MAIN_DB_PREF
 $tabsql[21]= "SELECT c.rowid as rowid, code, label, active FROM ".MAIN_DB_PREFIX."c_availability AS c";
 $tabsql[22]= "SELECT rowid   as rowid, code, label, active FROM ".MAIN_DB_PREFIX."c_input_reason";
 $tabsql[23]= "SELECT rowid   as rowid, fk_pcg_version, pcg_type, pcg_subtype, account_number as accountancy_code, account_parent, label, active FROM ".MAIN_DB_PREFIX."accountingaccount";
-$tabsql[24]= "SELECT s.rowid as rowid, pcg_version, s.fk_pays as pays_id, p.code as pays_code, p.libelle as pays, s.label, s.active FROM ".MAIN_DB_PREFIX."accountingsystem as s, ".MAIN_DB_PREFIX."c_pays as p WHERE s.fk_pays=p.rowid and p.active=1";
+$tabsql[24]= "SELECT s.rowid as rowid, pcg_version, s.fk_pays as pays_id, p.code as pays_code, p.libelle as pays, s.label, s.active FROM ".MAIN_DB_PREFIX."accounting_system as s, ".MAIN_DB_PREFIX."c_pays as p WHERE s.fk_pays=p.rowid and p.active=1";
 
 // Critere de tri du dictionnaire
 $tabsqlsort=array();

+ 27 - 17
htdocs/core/lib/price.lib.php

@@ -46,21 +46,21 @@
  *		@param	int		$info_bits					Miscellanous informations on line
  *		@param	int		$type						0/1=Product/service
  *		@param  string	$seller						Thirdparty seller (we need $seller->country_code property). Provided only if seller is the supplier.
- *		@return result[ 0=total_ht, 
- *						 1=total_vat, 
- *						 2=total_ttc, 
- *						 3=pu_ht, 
- *						 4=pu_tva, 
- *						 5=pu_ttc, 
- *						 6=total_ht_without_discount, 
- *						 7=total_vat_without_discount, 
- *						 8=total_ttc_without_discount, 
- *						 9=amount tax1 for total_ht, 
- *						10=amount tax2 for total_ht, 
- *						11=amount tax1 for pu_ht, 
- *						12=amount tax2 for pu_ht, 
- *						13=not used???, 
- *						14=amount tax1 for total_ht_without_discount, 
+ *		@return result[ 0=total_ht,
+ *						 1=total_vat,
+ *						 2=total_ttc,
+ *						 3=pu_ht,
+ *						 4=pu_tva,
+ *						 5=pu_ttc,
+ *						 6=total_ht_without_discount,
+ *						 7=total_vat_without_discount,
+ *						 8=total_ttc_without_discount,
+ *						 9=amount tax1 for total_ht,
+ *						10=amount tax2 for total_ht,
+ *						11=amount tax1 for pu_ht,
+ *						12=amount tax2 for pu_ht,
+ *						13=not used???,
+ *						14=amount tax1 for total_ht_without_discount,
  *						15=amount tax1 for total_ht_without_discount]
  */
 function calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $remise_percent_global, $price_base_type, $info_bits, $type, $seller = '')
@@ -69,7 +69,17 @@ function calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocalt
 
 	$result=array();
 
-	if (empty($seller) || ! is_object($seller)) $seller=$mysoc;	// If seller is a customer, $seller is not provided, we use $mysoc
+	if (empty($seller) || ! is_object($seller))
+	{
+		if (! is_object($mysoc))	// mysoc may be not defined (during migration process)
+		{
+			$mysoc=new Societe($db);
+			$mysoc->getMysoc($conf);
+		}
+		$seller=$mysoc;	// If seller is a customer, $seller is not provided, we use $mysoc
+		//var_dump($seller->country_id);exit;
+	}
+
 	$countryid=$seller->country_id;
 	if ($uselocaltax1_rate < 0) $uselocaltax1_rate=$seller->localtax1_assuj;
 	if ($uselocaltax2_rate < 0) $uselocaltax2_rate=$seller->localtax2_assuj;
@@ -192,7 +202,7 @@ function calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocalt
 	}
 
 	// if there's some localtax without vat, we calculate localtaxes (we will add them at end)
-    
+
     //If price is 'TTC' we need to have the totals without VAT for a correct calculation
     if ($price_base_type=='TTC')
     {

+ 3 - 3
htdocs/install/mysql/data/llx_accounting.sql

@@ -28,13 +28,13 @@
 --
 
 delete from llx_accountingaccount;
-delete from llx_accountingsystem;
+delete from llx_accounting_system;
 
 --
 -- Descriptif des plans comptables FR PCG99-ABREGE
 --
 
-insert into llx_accountingsystem (rowid, pcg_version, fk_pays, label, active) VALUES (1,'PCG99-ABREGE', 1, 'The simple accountancy french plan', 1);
+insert into llx_accounting_system (rowid, pcg_version, fk_pays, label, active) VALUES (1,'PCG99-ABREGE', 1, 'The simple accountancy french plan', 1);
 
 insert into llx_accountingaccount (rowid, fk_pcg_version, pcg_type, pcg_subtype, account_number, account_parent, label, active) VALUES (  1,'PCG99-ABREGE','CAPIT', 'CAPITAL', '101', '1', 'Capital', '1');
 insert into llx_accountingaccount (rowid, fk_pcg_version, pcg_type, pcg_subtype, account_number, account_parent, label, active) VALUES (  2,'PCG99-ABREGE','CAPIT', 'XXXXXX',  '105', '1', 'Ecarts de réévaluation', '1');
@@ -143,7 +143,7 @@ insert into llx_accountingaccount (rowid, fk_pcg_version, pcg_type, pcg_subtype,
 -- Descriptif des plans comptables FR PCG99-BASE
 --
 
-insert into llx_accountingsystem (rowid, pcg_version, fk_pays, label, active) VALUES (2,'PCG99-BASE', 1, 'The base accountancy french plan', 1);
+insert into llx_accounting_system (rowid, pcg_version, fk_pays, label, active) VALUES (2,'PCG99-BASE', 1, 'The base accountancy french plan', 1);
 
 insert into llx_accountingaccount (rowid, fk_pcg_version, pcg_type, pcg_subtype, account_number, account_parent, label, active) VALUES (103,'PCG99-BASE','CAPIT', 'XXXXXX',   '10',  '1', 'Capital  et réserves', '1');
 insert into llx_accountingaccount (rowid, fk_pcg_version, pcg_type, pcg_subtype, account_number, account_parent, label, active) VALUES (104,'PCG99-BASE','CAPIT', 'CAPITAL', '101', '10', 'Capital', '1');

+ 5 - 0
htdocs/install/mysql/migration/3.1.0-3.2.0.sql

@@ -464,3 +464,8 @@ UPDATE llx_product SET canvas = NULL where canvas = 'service@product';
 DELETE FROM llx_const WHERE __DECRYPT('name')__ = 'SOCIETE_CODECOMPTA_ADDON' AND __DECRYPT('value')__ = 'mod_codecompta_digitaria';
 
 ALTER TABLE llx_c_barcode_type ADD UNIQUE INDEX uk_c_barcode_type(code, entity);
+
+-- To make migration script with version >= 3.3 working correctly
+ALTER TABLE llx_c_tva ADD COLUMN localtax1_type varchar(1) default '0' after localtax1;
+ALTER TABLE llx_c_tva ADD COLUMN localtax2_type varchar(1) default '0' after localtax2;
+

+ 8 - 7
htdocs/install/mysql/migration/3.2.0-3.3.0.sql

@@ -212,8 +212,8 @@ ALTER TABLE llx_boxes ADD UNIQUE INDEX uk_boxes (entity, box_id, position, fk_us
 UPDATE llx_boxes as b SET b.entity = (SELECT bd.entity FROM llx_boxes_def as bd WHERE bd.rowid = b.box_id);
 
 -- TASK #204
-alter table llx_c_tva add column localtax1_type varchar(1) default '0' after localtax1;
-alter table llx_c_tva add column localtax2_type varchar(1) default '0' after localtax2;
+ALTER TABLE llx_c_tva ADD COLUMN localtax1_type varchar(1) default '0' after localtax1;
+ALTER TABLE llx_c_tva ADD COLUMN localtax2_type varchar(1) default '0' after localtax2;
 ALTER TABLE llx_c_tva MODIFY COLUMN localtax1_type varchar(1);
 ALTER TABLE llx_c_tva MODIFY COLUMN localtax2_type varchar(1);
 
@@ -289,8 +289,9 @@ ALTER TABLE llx_c_chargessociales ADD COLUMN accountancy_code varchar(15) DEFAUL
 -- Tables for accountancy expert
 DROP TABLE llx_accountingaccount;
 DROP TABLE llx_accountingsystem;
+DROP TABLE llx_accounting_system;
 
-create table llx_accountingsystem
+create table llx_accounting_system
 (
   rowid             integer         AUTO_INCREMENT PRIMARY KEY,
   pcg_version       varchar(12)     NOT NULL,
@@ -299,7 +300,7 @@ create table llx_accountingsystem
   active            smallint        DEFAULT 0
 )ENGINE=innodb;
 
-ALTER TABLE llx_accountingsystem ADD INDEX idx_accountingsystem_pcg_version (pcg_version);
+ALTER TABLE llx_accounting_system ADD INDEX idx_accounting_system_pcg_version (pcg_version);
 
 create table llx_accountingaccount
 (
@@ -314,12 +315,12 @@ create table llx_accountingaccount
 )ENGINE=innodb;
 
 ALTER TABLE llx_accountingaccount ADD INDEX idx_accountingaccount_fk_pcg_version (fk_pcg_version);
-ALTER TABLE llx_accountingaccount ADD CONSTRAINT fk_accountingaccount_fk_pcg_version FOREIGN KEY (fk_pcg_version) REFERENCES llx_accountingsystem (pcg_version);
+ALTER TABLE llx_accountingaccount ADD CONSTRAINT fk_accountingaccount_fk_pcg_version FOREIGN KEY (fk_pcg_version) REFERENCES llx_accounting_system (pcg_version);
 
 
 -- Data for accountancy expert
 
-insert into llx_accountingsystem (rowid, pcg_version, fk_pays, label, active) VALUES (1,'PCG99-ABREGE', 1, 'The simple accountancy french plan', 1);
+insert into llx_accounting_system (rowid, pcg_version, fk_pays, label, active) VALUES (1,'PCG99-ABREGE', 1, 'The simple accountancy french plan', 1);
 
 insert into llx_accountingaccount (rowid, fk_pcg_version, pcg_type, pcg_subtype, account_number, account_parent, label, active) VALUES (  1,'PCG99-ABREGE','CAPIT', 'CAPITAL', '101', '1', 'Capital', '1');
 insert into llx_accountingaccount (rowid, fk_pcg_version, pcg_type, pcg_subtype, account_number, account_parent, label, active) VALUES (  2,'PCG99-ABREGE','CAPIT', 'XXXXXX',  '105', '1', 'Ecarts de réévaluation', '1');
@@ -424,7 +425,7 @@ insert into llx_accountingaccount (rowid, fk_pcg_version, pcg_type, pcg_subtype,
 insert into llx_accountingaccount (rowid, fk_pcg_version, pcg_type, pcg_subtype, account_number, account_parent, label, active) VALUES (101,'PCG99-ABREGE','PROD',  'XXXXXX',  '787', '7', 'Reprises sur provisions', '1');
 insert into llx_accountingaccount (rowid, fk_pcg_version, pcg_type, pcg_subtype, account_number, account_parent, label, active) VALUES (102,'PCG99-ABREGE','PROD',  'XXXXXX',   '79', '7', 'Transferts de charges', '1');
 
-insert into llx_accountingsystem (rowid, pcg_version, fk_pays, label, active) VALUES (2,'PCG99-BASE', 1, 'The base accountancy french plan', 1);
+insert into llx_accounting_system (rowid, pcg_version, fk_pays, label, active) VALUES (2,'PCG99-BASE', 1, 'The base accountancy french plan', 1);
 
 insert into llx_accountingaccount (rowid, fk_pcg_version, pcg_type, pcg_subtype, account_number, account_parent, label, active) VALUES (103,'PCG99-BASE','CAPIT', 'XXXXXX',   '10',  '1', 'Capital  et réserves', '1');
 insert into llx_accountingaccount (rowid, fk_pcg_version, pcg_type, pcg_subtype, account_number, account_parent, label, active) VALUES (104,'PCG99-BASE','CAPIT', 'CAPITAL', '101', '10', 'Capital', '1');

+ 1 - 1
htdocs/install/mysql/tables/llx_accountingsystem.key.sql → htdocs/install/mysql/tables/llx_accounting_system.key.sql

@@ -18,5 +18,5 @@
 -- ===========================================================================
 
 
-ALTER TABLE llx_accountingsystem ADD INDEX idx_accountingsystem_pcg_version (pcg_version);
+ALTER TABLE llx_accounting_system ADD INDEX idx_accounting_system_pcg_version (pcg_version);
 

+ 1 - 1
htdocs/install/mysql/tables/llx_accountingsystem.sql → htdocs/install/mysql/tables/llx_accounting_system.sql

@@ -18,7 +18,7 @@
 -- Table of "Plan de comptes" for accountancy expert module
 -- ============================================================================
 
-create table llx_accountingsystem
+create table llx_accounting_system
 (
   rowid             integer         AUTO_INCREMENT PRIMARY KEY,
   pcg_version       varchar(12)     NOT NULL,

+ 1 - 1
htdocs/install/mysql/tables/llx_accountingaccount.key.sql

@@ -21,4 +21,4 @@
 ALTER TABLE llx_accountingaccount ADD INDEX idx_accountingaccount_fk_pcg_version (fk_pcg_version);
 
 
-ALTER TABLE llx_accountingaccount ADD CONSTRAINT fk_accountingaccount_fk_pcg_version  FOREIGN KEY (fk_pcg_version)    REFERENCES llx_accountingsystem (pcg_version);
+ALTER TABLE llx_accountingaccount ADD CONSTRAINT fk_accountingaccount_fk_pcg_version  FOREIGN KEY (fk_pcg_version)    REFERENCES llx_accounting_system (pcg_version);

+ 1 - 1
htdocs/install/mysql/tables/llx_livraison.key.sql

@@ -26,4 +26,4 @@ ALTER TABLE llx_livraison ADD INDEX idx_livraison_fk_user_valid (fk_user_valid);
 
 ALTER TABLE llx_livraison ADD CONSTRAINT fk_livraison_fk_soc			FOREIGN KEY (fk_soc)			REFERENCES llx_societe (rowid);
 ALTER TABLE llx_livraison ADD CONSTRAINT fk_livraison_fk_user_author	FOREIGN KEY (fk_user_author)	REFERENCES llx_user (rowid);
-ALTER TABLE llx_livraison ADD CONSTRAINT fk_livraison_fk_user_valid		FOREIGN KEY (fk_user_valid)		REFERENCES llx_user (rowid);
+ALTER TABLE llx_livraison ADD CONSTRAINT fk_livraison_fk_user_valid	FOREIGN KEY (fk_user_valid)	REFERENCES llx_user (rowid);

+ 1 - 1
htdocs/install/pgsql/functions/functions.sql

@@ -57,7 +57,7 @@ CREATE OR REPLACE FUNCTION dol_util_triggerall(DoEnable boolean) RETURNS integer
 
 
 -- Add triggers
-CREATE TRIGGER update_customer_modtime BEFORE UPDATE ON llx_accountingsystem FOR EACH ROW EXECUTE PROCEDURE update_modified_column();
+CREATE TRIGGER update_customer_modtime BEFORE UPDATE ON llx_accounting_system FOR EACH ROW EXECUTE PROCEDURE update_modified_column();
 CREATE TRIGGER update_customer_modtime BEFORE UPDATE ON llx_accountingtransaction FOR EACH ROW EXECUTE PROCEDURE update_modified_column();
 CREATE TRIGGER update_customer_modtime BEFORE UPDATE ON llx_actioncomm FOR EACH ROW EXECUTE PROCEDURE update_modified_column();
 CREATE TRIGGER update_customer_modtime BEFORE UPDATE ON llx_adherent_extrafields FOR EACH ROW EXECUTE PROCEDURE update_modified_column();