diff --git a/include/constant.php b/include/constant.php index b7d7cc2c2..c11fd1351 100644 --- a/include/constant.php +++ b/include/constant.php @@ -28,7 +28,7 @@ global $version_noalyss; define('NOALYSS_VERSION', 9205 ); // Database schema version -define("DBVERSION", 196); +define("DBVERSION", 197); // version for MONO_DATABASE define("MONO_DATABASE", 25); diff --git a/include/sql/patch/upgrade196.sql b/include/sql/patch/upgrade196.sql new file mode 100644 index 000000000..92014f93a --- /dev/null +++ b/include/sql/patch/upgrade196.sql @@ -0,0 +1,65 @@ +begin; +with correct_periode as (select jr_tech_per, jr_grpt_id from jrn) +update jrnx set j_tech_per = jr_tech_per from correct_periode where correct_periode.jr_grpt_id=j_grpt and correct_periode.jr_tech_per != j_tech_per; + + + +ALTER TABLE public.tva_rate ADD tva_code text ; +ALTER TABLE public.tva_rate ADD CONSTRAINT tva_code_unique UNIQUE (tva_code); +update tva_rate set tva_code=null; + + +drop VIEW public.v_tva_rate; + +CREATE OR REPLACE VIEW public.v_tva_rate +AS SELECT tva_rate.tva_id, + tva_rate.tva_rate, + tva_rate.tva_code, + tva_rate.tva_label, + tva_rate.tva_comment, + split_part(tva_rate.tva_poste, ','::text, 1) AS tva_purchase, + split_part(tva_rate.tva_poste, ','::text, 2) AS tva_sale, + tva_rate.tva_both_side, + tva_rate.tva_payment_purchase, + tva_rate.tva_payment_sale + FROM tva_rate; + +CREATE OR REPLACE FUNCTION update_tva_code () + returns int4 +AS +$BODY$ +declare +/* + * Section for variables + */ + counter int:=0; + letter int; + x record; + e record; + str_tva_code text; +begin + -- basic loop + for x in select distinct tva_rate from public.tva_rate order by tva_rate + loop + letter :=65; + for e in select * from public.tva_rate where tva_rate = x.tva_rate loop + str_tva_code := round(e.tva_rate*1000)::text||chr(letter); + update tva_rate set tva_code=str_tva_code where tva_id=e.tva_id; + letter := letter+1; + counter := counter+1; + end loop; + + end loop; + return counter; +end; +$BODY$ +LANGUAGE plpgsql; + +select update_tva_code(); + +drop function update_tva_code(); +alter table public.tva_rate alter tva_code set not null; + +ALTER TABLE public.op_predef_detail ALTER COLUMN opd_tva_id TYPE text USING opd_tva_id::text; +insert into version (val,v_description) values (197,'Adapt for VAT CODE'); +commit; diff --git a/sql/upgrade.sql b/sql/upgrade.sql index b2a93704b..92014f93a 100644 --- a/sql/upgrade.sql +++ b/sql/upgrade.sql @@ -1,3 +1,4 @@ +begin; with correct_periode as (select jr_tech_per, jr_grpt_id from jrn) update jrnx set j_tech_per = jr_tech_per from correct_periode where correct_periode.jr_grpt_id=j_grpt and correct_periode.jr_tech_per != j_tech_per; @@ -5,9 +6,8 @@ update jrnx set j_tech_per = jr_tech_per from correct_periode where correct_peri ALTER TABLE public.tva_rate ADD tva_code text ; ALTER TABLE public.tva_rate ADD CONSTRAINT tva_code_unique UNIQUE (tva_code); -update tva_rate set tva_code=tva_id::text||'-'||(tva_rate*100)::text; +update tva_rate set tva_code=null; -alter table public.tva_rate alter tva_code set not null; drop VIEW public.v_tva_rate; @@ -24,9 +24,6 @@ AS SELECT tva_rate.tva_id, tva_rate.tva_payment_sale FROM tva_rate; --- update tva_rate set tva_code=(round(tva_rate*100))::text||'-'||tva_id::text; - - CREATE OR REPLACE FUNCTION update_tva_code () returns int4 AS @@ -46,8 +43,7 @@ begin loop letter :=65; for e in select * from public.tva_rate where tva_rate = x.tva_rate loop - str_tva_code := round(e.tva_rate*100)::text||chr(letter); - -- raise notice 'rate % letter % => tva_code %',e.tva_rate,chr(letter),str_tva_code ; + str_tva_code := round(e.tva_rate*1000)::text||chr(letter); update tva_rate set tva_code=str_tva_code where tva_id=e.tva_id; letter := letter+1; counter := counter+1; @@ -62,5 +58,8 @@ LANGUAGE plpgsql; select update_tva_code(); drop function update_tva_code(); +alter table public.tva_rate alter tva_code set not null; ALTER TABLE public.op_predef_detail ALTER COLUMN opd_tva_id TYPE text USING opd_tva_id::text; +insert into version (val,v_description) values (197,'Adapt for VAT CODE'); +commit;