Patch and database

This commit is contained in:
sparkyx 2008-01-12 21:24:38 +00:00
parent 86ddad4189
commit afbc95f61a
11 changed files with 901 additions and 11 deletions

View file

@ -39,7 +39,6 @@ nCounter integer;
select count(*) into nCounter from pg_class where relname='seq_doc_type_'||NEW.dt_id;
if nCounter = 0 then
execute 'create sequence seq_doc_type_'||NEW.dt_id;
raise notice 'Creating sequence seq_doc_type_%',NEW.dt_id;
end if;
RETURN NEW;
END;
@ -76,7 +75,6 @@ $BODY$
declare
name text;
begin
raise notice 'poste_analytique_write';
name:=upper(NEW.ga_id);
name:=trim(name);
name:=replace(name,' ','');
@ -488,7 +486,6 @@ begin
sCode:=trim(upper(NEW.bc_code));
sCode:=replace(sCode,' ','_');
sCode:=substr(sCode,1,10);
raise notice 'sCode is %',sCode;
NEW.bc_code:=sCode;
return NEW;
end;$BODY$
@ -646,5 +643,78 @@ CREATE TRIGGER t_check_balance
EXECUTE PROCEDURE proc_check_balance();
INSERT INTO "action" (ac_id, ac_description) VALUES (60, 'Module Budget');
alter table tmp_pcmn add column pcm_type text;
ALTER TABLE tmp_pcmn ALTER COLUMN pcm_type set default NULL;
CREATE TABLE parm_poste (
p_value poste_comptable NOT NULL,
p_type text NOT NULL
);
--
-- Name: TABLE parm_poste; Type: COMMENT; Schema: public; Owner: postgres
--
COMMENT ON TABLE parm_poste IS 'Contains data for finding is the type of the account (asset)';
--
-- Name: parm_poste_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace:
--
ALTER TABLE ONLY parm_poste
ADD CONSTRAINT parm_poste_pkey PRIMARY KEY (p_value);
CREATE OR REPLACE FUNCTION find_pcm_type(pp_value "numeric")
RETURNS text AS
$BODY$
declare
str_type text;
str_value text;
n_value numeric;
nLength integer;
begin
str_value:=trim(to_char(pp_value,'99999999999999999999999999999'));
nLength:=length(str_value);
while nLength > 0 loop
n_value:=to_number(str_value,'99999999999999999999999999999');
select into str_type p_type from parm_poste where p_value=n_value;
if FOUND then
return str_type;
end if;
nLength:=nLength-1;
str_value:=substring(str_value from 1 for nLength);
end loop;
return 'CON';
end;
$BODY$
LANGUAGE 'plpgsql' VOLATILE;
CREATE OR REPLACE FUNCTION tmp_pcmn_ins()
RETURNS "trigger" AS
$BODY$
declare
r_record tmp_pcmn%ROWTYPE;
begin
r_record=NEW;
if length(trim(r_record.pcm_type))=0 or r_record.pcm_type is NULL then
r_record.pcm_type:=find_pcm_type(NEW.pcm_val);
return r_record;
end if;
return NEW;
end;
$BODY$
LANGUAGE 'plpgsql' VOLATILE;
CREATE TRIGGER t_tmp_pcmn_ins
BEFORE INSERT
ON tmp_pcmn
FOR EACH ROW
EXECUTE PROCEDURE tmp_pcmn_ins();
update tmp_pcmn set pcm_type=find_pcm_type(pcm_val);
commit;