diff --git a/html/admin/setup.php b/html/admin/setup.php index e243bda8f..001a89a52 100644 --- a/html/admin/setup.php +++ b/html/admin/setup.php @@ -118,13 +118,19 @@ function ExecuteScript($p_cn,$script) { $sql=$buffer; continue; } + if ( strpos(strtolower($buffer),"create or replace function")===0 ) { + echo "found a function"; + $flag_function=true; + $sql=$buffer; + continue; + } // No semi colon -> multiline command if ( $flag_function== false && strpos($buffer,';') == false ) { $sql.=$buffer; continue; } if ( $flag_function ) { - if ( strpos(strtolower($buffer), "language plpgsql") == false ) { + if ( strpos(strtolower($buffer), "language plpgsql") === false ) { $sql.=$buffer; continue; } @@ -221,13 +227,13 @@ if ( $version[0] != '8' ) { offre pas, installez en une en la compilant.

Lisez attentivement la notice sur postgresql.org pour migrer vos bases de données en 8

- -

Database Setting

+

Database Setting

9 if ( GetVersion($db) == 8 ) { ExecuteScript($db,'sql/patch/upgrade8.sql'); - } // version == 9 + } // version == 9->10 if ( GetVersion($db) == 9 ) { ExecuteScript($db,'sql/patch/upgrade9.sql'); - } // version == 8->9 + } // version == 10->11 + if ( GetVersion($db) == 10 ) { + ExecuteScript($db,'sql/patch/upgrade10.sql'); + } // version + if ( DEBUG == 'false') ob_end_clean(); }//for @@ -471,6 +481,10 @@ if (DEBUG == 'false' ) ob_start(); if ( GetVersion($db) == 9 ) { ExecuteScript($db,'sql/patch/upgrade9.sql'); } // version == 9 + if ( GetVersion($db) == 10 ) { + ExecuteScript($db,'sql/patch/upgrade10.sql'); + } // version + if ( DEBUG == 'false') ob_end_clean(); } diff --git a/html/admin/sql/patch/upgrade10.sql b/html/admin/sql/patch/upgrade10.sql new file mode 100644 index 000000000..627d59840 --- /dev/null +++ b/html/admin/sql/patch/upgrade10.sql @@ -0,0 +1,72 @@ +begin; +-- Function: proc_check_balance() + +-- DROP FUNCTION proc_check_balance(); + +CREATE OR REPLACE FUNCTION proc_check_balance() + RETURNS "trigger" AS +$BODY$ +declare + diff numeric; + tt integer; +begin + if TG_OP = 'INSERT' then + tt=NEW.jr_grpt_id; + diff:=check_balance(tt); + if diff != 0 then + raise exception 'Rounded error %',diff ; + end if; + return NEW; + end if; +end; +$BODY$ + LANGUAGE plpgsql VOLATILE; + + +-- Function: check_balance(p_grpt text) + +DROP FUNCTION check_balance(text); + +CREATE OR REPLACE FUNCTION check_balance(p_grpt integer) + RETURNS "numeric" AS +$BODY$ +declare + amount_jrnx_debit numeric; + amount_jrnx_credit numeric; + amount_jrn numeric; +begin + select sum (j_montant) into amount_jrnx_credit + from jrnx + where + j_grpt=p_grpt + and j_debit=false; + + select sum (j_montant) into amount_jrnx_debit + from jrnx + where + j_grpt=p_grpt + and j_debit=true; + + select jr_montant into amount_jrn + from jrn + where + jr_grpt_id=p_grpt; + + if ( amount_jrnx_debit != amount_jrnx_credit ) + then + return abs(amount_jrnx_debit-amount_jrnx_credit); + end if; + if ( amount_jrn != amount_jrnx_credit) + then + return -1*abs(amount_jrn - amount_jrnx_credit); + end if; + return 0; +end; +$BODY$ + LANGUAGE plpgsql VOLATILE; + + + + +update version set val=11; +commit; \ No newline at end of file diff --git a/html/admin/sql/patch/upgrade9.sql b/html/admin/sql/patch/upgrade9.sql index 4563f88bb..97007eb8c 100644 --- a/html/admin/sql/patch/upgrade9.sql +++ b/html/admin/sql/patch/upgrade9.sql @@ -2,11 +2,11 @@ begin; -- index needed create unique index attr_value_jft_id on attr_value (jft_id); -- add quick code -insert into attr_def (ad_text) values('Quick Code'); +insert into attr_def (ad_id,ad_text) values(23,'Quick Code'); -- update existing card & template insert into attr_min select frd_id,23 from fiche_def_ref; insert into jnt_fic_attr select fd_id,23 from fiche_Def; -insert into jnt_fic_att_value(f_id,ad_id) select f_id,23 from fiche; +insert into jnt_fic_att_value(jft_id,f_id,ad_id) select nextval('s_jnt_fic_att_value')+200,f_id,23 from fiche; -- generate a quick code insert into attr_value select jft_id,'FID'||f_id from jnt_fic_att_value join fiche using(f_id) where ad_id=23; -- add quick code to jrnx @@ -28,9 +28,7 @@ create or replace function insert_jrnx ( p_tech_user jrnx.j_tech_user%type, p_tech_per jrnx.j_tech_per%type, p_qcode jrnx.j_qcode%type -) returns void -as -$body$ +) returns void as $body$ declare sCode varchar; nCount_qcode integer; @@ -80,7 +78,7 @@ begin return; end; $body$ -language plpgsql; + language plpgsql; @@ -89,9 +87,7 @@ language plpgsql; -- DROP FUNCTION update_quick_code(int4, text); CREATE OR REPLACE FUNCTION update_quick_code(njft_id int4,tav_text text) - RETURNS int4 AS -$BODY$ - + RETURNS int4 AS $BODY$ declare ns integer; nExist integer; @@ -135,7 +131,7 @@ $BODY$ return ns; end; $BODY$ - LANGUAGE 'plpgsql' VOLATILE; + LANGUAGE plpgsql VOLATILE; @@ -169,8 +165,7 @@ create or replace function insert_quant_sold ( p_price quant_sold.qs_price%type, p_vat quant_sold.qs_vat%type, p_vat_code quant_sold.qs_vat_code%type, - p_client varchar) returns void as -$body$ + p_client varchar) returns void as $body$ declare fid_client integer; fid_good integer; @@ -189,7 +184,7 @@ begin return; end; $body$ - LANGUAGE 'plpgsql' VOLATILE; + LANGUAGE plpgsql VOLATILE; @@ -198,8 +193,7 @@ $body$ -- DROP FUNCTION insert_quick_code(int4, text); CREATE OR REPLACE FUNCTION insert_quick_code(nf_id int4, tav_text text) - RETURNS int4 AS -$BODY$ + RETURNS int4 AS $BODY$ declare ns integer; nExist integer; @@ -232,9 +226,10 @@ $BODY$ return ns; end; $BODY$ - LANGUAGE 'plpgsql' VOLATILE; + LANGUAGE plpgsql VOLATILE; ---ALTER FUNCTION insert_quick_code(int4, text) OWNER TO dany; + +drop view vw_fiche_attr ; DROP VIEW vw_fiche_attr;