Fix Bug for Postgresql 8.3

This commit is contained in:
Dany De Bontridder 2009-07-16 17:56:40 +00:00
parent 1032e7a6b4
commit d05b39e40e
3 changed files with 80 additions and 23 deletions

View file

@ -0,0 +1,43 @@
begin;
DROP FUNCTION tva_insert (text,numeric,text,text);
CREATE FUNCTION tva_insert(text, numeric, text, text) RETURNS integer
AS $_$
declare
l_tva_id integer;
p_tva_label alias for $1;
p_tva_rate alias for $2;
p_tva_comment alias for $3;
p_tva_poste alias for $4;
debit text;
credit text;
nCount integer;
begin
if length(trim(p_tva_label)) = 0 then
return 3;
end if;
if length(trim(p_tva_poste)) != 0 then
if position (',' in p_tva_poste) = 0 then return 4; end if;
debit = split_part(p_tva_poste,',',1);
credit = split_part(p_tva_poste,',',2);
select count(*) into nCount from tmp_pcmn where pcm_val=debit::poste_comptable;
if nCount = 0 then return 4; end if;
select count(*) into nCount from tmp_pcmn where pcm_val=credit::poste_comptable;
if nCount = 0 then return 4; end if;
end if;
select into l_tva_id nextval('s_tva') ;
insert into tva_rate(tva_id,tva_label,tva_rate,tva_comment,tva_poste)
values (l_tva_id,p_tva_label,p_tva_rate,p_tva_comment,p_tva_poste);
return 0;
end;
$_$
LANGUAGE plpgsql;
update version set val=58;
commit;

View file

@ -26,7 +26,7 @@
require_once ('config.inc.php');
require_once('constant.security.php');
define ("DBVERSION",57);
define ("DBVERSION",58);
define ("MAX_COMPTE",4);
define ('MAX_BUD_DETAIL',20);

View file

@ -1,26 +1,40 @@
begin;
CREATE OR REPLACE FUNCTION create_missing_sequence()
RETURNS integer AS
$BODY$
declare
p_sequence text;
nSeq integer;
c1 cursor for select jrn_def_id from jrn_def;
begin
open c1;
loop
fetch c1 into nSeq;
if not FOUND THEN
close c1;
return 0;
end if;
p_sequence:='s_jrn_pj'||nSeq::text;
execute 'create sequence '||p_sequence;
end loop;
close c1;
return 0;
DROP FUNCTION tva_insert (text,numeric,text,text);
CREATE FUNCTION tva_insert(text, numeric, text, text) RETURNS integer
AS $_$
declare
l_tva_id integer;
p_tva_label alias for $1;
p_tva_rate alias for $2;
p_tva_comment alias for $3;
p_tva_poste alias for $4;
debit text;
credit text;
nCount integer;
begin
if length(trim(p_tva_label)) = 0 then
return 3;
end if;
if length(trim(p_tva_poste)) != 0 then
if position (',' in p_tva_poste) = 0 then return 4; end if;
debit = split_part(p_tva_poste,',',1);
credit = split_part(p_tva_poste,',',2);
select count(*) into nCount from tmp_pcmn where pcm_val=debit::poste_comptable;
if nCount = 0 then return 4; end if;
select count(*) into nCount from tmp_pcmn where pcm_val=credit::poste_comptable;
if nCount = 0 then return 4; end if;
end if;
select into l_tva_id nextval('s_tva') ;
insert into tva_rate(tva_id,tva_label,tva_rate,tva_comment,tva_poste)
values (l_tva_id,p_tva_label,p_tva_rate,p_tva_comment,p_tva_poste);
return 0;
end;
$BODY$
LANGUAGE 'plpgsql';
$_$
LANGUAGE plpgsql;
commit;