Fix problem with create function add patch 9 and 10

This commit is contained in:
sparkyx 2006-04-20 16:50:01 +00:00
parent 7fa5acbcd1
commit d1e09c9cf0
3 changed files with 104 additions and 23 deletions

View file

@ -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;

View file

@ -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;