Restructure file , remove html/admin , backup ...

This commit is contained in:
Dany De Bontridder 2015-10-18 23:39:20 +02:00
parent b57df7c0e8
commit 896f3624c7
169 changed files with 48 additions and 54 deletions

View file

@ -0,0 +1,9 @@
begin;
--- on account_repository
delete from user_global_pref where parameter_type='fr_FR.utf8';
insert into user_global_pref(user_id,parameter_type,parameter_value ) select use_login,'LANG','fr_FR.utf8' from ac_users ;
update version set val=11;
commit;

View file

@ -0,0 +1,25 @@
begin;
delete from jnt_use_dos where use_id not in (select use_id from ac_users);
delete from jnt_use_dos where dos_id not in (select dos_id from ac_dossier);
alter table jnt_use_dos add CONSTRAINT jnt_use_dos_dos_id_fkey FOREIGN KEY (dos_id)
REFERENCES ac_dossier (dos_id) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE;
alter table jnt_use_dos add CONSTRAINT jnt_use_dos_use_id_fkey FOREIGN KEY (use_id)
REFERENCES ac_users (use_id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION;
delete from priv_user where priv_jnt not in (select jnt_id from jnt_use_dos);
alter table jnt_use_dos drop constraint jnt_use_dos_pkey;
alter table jnt_use_dos add constraint jnt_use_dos_pkey PRIMARY KEY (jnt_id);
alter table priv_user add CONSTRAINT priv_user_priv_jnt_fkey FOREIGN KEY (priv_jnt)
REFERENCES jnt_use_dos (jnt_id) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE cascade;
alter table version add primary key (val);
update version set val=12;
commit;

View file

@ -0,0 +1,46 @@
begin;
-- Table: audit_connect
-- DROP TABLE audit_connect;
CREATE TABLE audit_connect
(
ac_id serial NOT NULL,
ac_user text,
ac_date timestamp without time zone DEFAULT now(),
ac_ip text,
ac_state text,
ac_module text,
ac_url text,
CONSTRAINT audit_connect_pkey PRIMARY KEY (ac_id),
CONSTRAINT valid_state CHECK (ac_state = 'FAIL'::text OR ac_state = 'SUCCESS'::text)
);
CREATE OR REPLACE FUNCTION limit_user()
RETURNS trigger AS
$BODY$
begin
NEW.ac_user := substring(NEW.ac_user from 1 for 80);
return NEW;
end; $BODY$
LANGUAGE plpgsql;
CREATE TRIGGER limit_user_trg
BEFORE INSERT OR UPDATE
ON audit_connect
FOR EACH ROW
EXECUTE PROCEDURE limit_user();
-- Index: audit_connect_ac_user
-- DROP INDEX audit_connect_ac_user;
CREATE INDEX audit_connect_ac_user
ON audit_connect
USING btree
(ac_user);
update version set val=13;
commit;

View file

@ -0,0 +1,11 @@
begin;
-- Check: valid_state
ALTER TABLE audit_connect DROP CONSTRAINT valid_state;
ALTER TABLE audit_connect ADD CONSTRAINT valid_state CHECK (ac_state = 'FAIL'::text OR ac_state = 'SUCCESS'::text or ac_state='AUDIT');
-- run to the account_repository
insert into theme values ('EPad','style-epad.css',null);
update priv_user set priv_priv='R' where priv_priv='L';
update priv_user set priv_priv='R' where priv_priv='P';
update version set val=14;
commit;

View file

@ -0,0 +1,25 @@
begin;
update theme set the_name='Mandarine' ,the_filestyle='style-mandarine.css' where the_name='Colored';
update theme set the_name='Mobile' ,the_filestyle='style-mobile.css' where the_name='EPad';
update theme set the_name = 'Classique' where the_name='classic';
update user_global_pref set parameter_value='Classique' where parameter_type='THEME';
update theme set the_filestyle='style-classic.css' where the_filestyle='style.css';
CREATE OR REPLACE FUNCTION public.upgrade_repo(p_version integer)
RETURNS void
AS $function$
declare
is_mono integer;
begin
select count (*) into is_mono from information_schema.tables where table_name='repo_version';
if is_mono = 1 then
update repo_version set val=p_version;
else
update version set val=p_version;
end if;
end;
$function$
language plpgsql;
select upgrade_repo(15);
commit;

View file

@ -0,0 +1,45 @@
begin;
ALTER TABLE ac_dossier drop COLUMN dos_jnt_user ;
delete from jnt_use_dos where jnt_id in (select priv_jnt from priv_user where priv_priv='X');
delete from jnt_use_dos where use_id in (select use_id from ac_users where use_admin=1 or use_active=0);
ALTER TABLE ac_users ADD COLUMN use_email text;
COMMENT ON COLUMN ac_users.use_email IS 'Email of the user';
CREATE OR REPLACE FUNCTION public.upgrade_repo(p_version integer)
RETURNS void
AS $function$
declare
is_mono integer;
begin
select count (*) into is_mono from information_schema.tables where table_name='repo_version';
if is_mono = 1 then
update repo_version set val=p_version;
else
update version set val=p_version;
end if;
end;
$function$
language plpgsql;
drop table priv_user;
CREATE TABLE recover_pass
(
use_id bigint NOT NULL,
request text NOT NULL,
password text NOT NULL,
created_on timestamp with time zone,
created_host text,
recover_on timestamp with time zone,
recover_by text,
CONSTRAINT recover_pass_pkey PRIMARY KEY (request ),
CONSTRAINT ac_users_recover_pass_fk FOREIGN KEY (use_id)
REFERENCES ac_users (use_id) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE
);
CREATE INDEX fki_ac_users_recover_pass_fk ON recover_pass USING btree (use_id );
select upgrade_repo(16);
commit;

View file

@ -0,0 +1,4 @@
delete from jnt_use_dos where dos_id not in (select dos_id from ac_dossier );
delete from jnt_use_dos where dos_id not in (select dos_id from ac_dossier);
update version set val=5;

View file

@ -0,0 +1 @@
update version set val=6;

View file

@ -0,0 +1,21 @@
begin;
create table user_global_pref (
user_id text,
parameter_type text,
parameter_value text
);
comment on table user_global_pref is 'The user''s global parameter ';
comment on column user_global_pref.user_id is 'user''s login ';
comment on column user_global_pref.parameter_type is 'the type of parameter ';
comment on column user_global_pref.parameter_value is 'the value of parameter ';
alter table user_global_pref add constraint fk_user_id foreign key (user_id) references ac_users(use_login) on delete cascade on update cascade;
alter table user_global_pref add constraint pk_user_global_pref primary key (user_id,parameter_type);
insert into user_global_pref select use_login,'PAGESIZE','50' from ac_users;
insert into user_global_pref select use_login,'THEME',use_theme from ac_users;
alter table ac_users drop use_usertype;
alter table ac_users drop use_theme;
update version set val=7;
commit;

View file

@ -0,0 +1,6 @@
begin;
insert into Theme values ('Colored','style-color.css',null);
delete from theme where the_filestyle='style-aqua.css' or the_filestyle='style-elegant.css';
update version set val=8;
commit;

View file

@ -0,0 +1,6 @@
begin;
update modeledef set mod_desc='Comptabilité Belge, à adapter' where mod_id=1;
update modeledef set mod_desc='Comptabilité Française, à adapter' where mod_id=2;
update version set val=9;
commit;

View file

@ -0,0 +1,10 @@
begin;
--- on account_repository
update priv_user set priv_priv='X' where priv_priv='NO';
update priv_user set priv_priv='R' where priv_priv='W';
update user_global_pref set parameter_value='TEXT' where parameter_type='TOPMENU';
update version set val=10;
commit;

View file

@ -0,0 +1,29 @@
begin;
insert into tva_rate values (5,'0%',0, 'Pas soumis à la TVA',null);
update fiche_def_ref set frd_class_base=2400 where frd_id=7;
update version set val=8;
-- banque n'a pas de gestion stock
delete from jnt_fic_attr where fd_id=1 and ad_id=19;
-- client n'a pas de gestion stock
delete from jnt_fic_attr where fd_id=2 and ad_id=19;
-- default periode for phpcompta
update user_pref set pref_periode=40 where pref_user='phpcompta';
-- create index ix_j_grp on jrnx(j_grpt);
-- create index ix_jr_grp on jrn(jr_grpt_id);
update jrnx set j_tech_per = jr_tech_per from jrn where j_grpt=jr_grpt_id and j_tech_per is null;
alter table jrnx alter j_tech_per set not null;
alter table jrn alter jr_tech_per set not null;
alter table jrn alter jr_montant type numeric(8,4);
alter table jrnx alter j_montant type numeric(8,4);
update version set val=7;
commit;
drop trigger tr_jrn_check_balance on jrn ;
drop function proc_check_balance();
drop function check_balance(text);
drop table user_local_pref;
commit;

View file

@ -0,0 +1,140 @@
begin;
-- 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 'balance 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;
-- add quick_code to the vw_client view
drop view vw_client;
create view vw_client as
SELECT a.f_id, a.av_text AS name, a1.av_text as quick_code,b.av_text AS tva_num, c.av_text AS poste_comptable, d.av_text AS rue, e.av_text AS code_postal, f.av_text AS pays, g.av_text AS telephone, h.av_text AS email
FROM ( SELECT jnt_fic_att_value.jft_id, fiche.f_id, fiche_def.frd_id, fiche.fd_id, fiche_def.fd_class_base, fiche_def.fd_label, fiche_def.fd_create_account, fiche_def_ref.frd_text, fiche_def_ref.frd_class_base, jnt_fic_att_value.ad_id, attr_value.av_text
FROM fiche
JOIN fiche_def USING (fd_id)
JOIN fiche_def_ref USING (frd_id)
JOIN jnt_fic_att_value USING (f_id)
JOIN attr_value USING (jft_id)
WHERE jnt_fic_att_value.ad_id = 1) a
inner JOIN ( SELECT jnt_fic_att_value.jft_id, fiche.f_id, fiche_def.frd_id, fiche.fd_id, fiche_def.fd_class_base, fiche_def.fd_label, fiche_def.fd_create_account, fiche_def_ref.frd_text, fiche_def_ref.frd_class_base, jnt_fic_att_value.ad_id, attr_value.av_text
FROM fiche
JOIN fiche_def USING (fd_id)
JOIN fiche_def_ref USING (frd_id)
JOIN jnt_fic_att_value USING (f_id)
JOIN attr_value USING (jft_id)
WHERE jnt_fic_att_value.ad_id = 13) b USING (f_id)
inner JOIN ( SELECT jnt_fic_att_value.jft_id, fiche.f_id, fiche_def.frd_id, fiche.fd_id, fiche_def.fd_class_base, fiche_def.fd_label, fiche_def.fd_create_account, fiche_def_ref.frd_text, fiche_def_ref.frd_class_base, jnt_fic_att_value.ad_id, attr_value.av_text
FROM fiche
JOIN fiche_def USING (fd_id)
JOIN fiche_def_ref USING (frd_id)
JOIN jnt_fic_att_value USING (f_id)
JOIN attr_value USING (jft_id)
WHERE jnt_fic_att_value.ad_id = 23) a1 USING (f_id)
inner JOIN ( SELECT jnt_fic_att_value.jft_id, fiche.f_id, fiche_def.frd_id, fiche.fd_id, fiche_def.fd_class_base, fiche_def.fd_label, fiche_def.fd_create_account, fiche_def_ref.frd_text, fiche_def_ref.frd_class_base, jnt_fic_att_value.ad_id, attr_value.av_text
FROM fiche
JOIN fiche_def USING (fd_id)
JOIN fiche_def_ref USING (frd_id)
JOIN jnt_fic_att_value USING (f_id)
JOIN attr_value USING (jft_id)
WHERE jnt_fic_att_value.ad_id = 5) c USING (f_id)
inner JOIN ( SELECT jnt_fic_att_value.jft_id, fiche.f_id, fiche_def.frd_id, fiche.fd_id, fiche_def.fd_class_base, fiche_def.fd_label, fiche_def.fd_create_account, fiche_def_ref.frd_text, fiche_def_ref.frd_class_base, jnt_fic_att_value.ad_id, attr_value.av_text
FROM fiche
JOIN fiche_def USING (fd_id)
JOIN fiche_def_ref USING (frd_id)
JOIN jnt_fic_att_value USING (f_id)
JOIN attr_value USING (jft_id)
WHERE jnt_fic_att_value.ad_id = 14) d USING (f_id)
inner JOIN ( SELECT jnt_fic_att_value.jft_id, fiche.f_id, fiche_def.frd_id, fiche.fd_id, fiche_def.fd_class_base, fiche_def.fd_label, fiche_def.fd_create_account, fiche_def_ref.frd_text, fiche_def_ref.frd_class_base, jnt_fic_att_value.ad_id, attr_value.av_text
FROM fiche
JOIN fiche_def USING (fd_id)
JOIN fiche_def_ref USING (frd_id)
JOIN jnt_fic_att_value USING (f_id)
JOIN attr_value USING (jft_id)
WHERE jnt_fic_att_value.ad_id = 15) e USING (f_id)
inner JOIN ( SELECT jnt_fic_att_value.jft_id, fiche.f_id, fiche_def.frd_id, fiche.fd_id, fiche_def.fd_class_base, fiche_def.fd_label, fiche_def.fd_create_account, fiche_def_ref.frd_text, fiche_def_ref.frd_class_base, jnt_fic_att_value.ad_id, attr_value.av_text
FROM fiche
JOIN fiche_def USING (fd_id)
JOIN fiche_def_ref USING (frd_id)
JOIN jnt_fic_att_value USING (f_id)
JOIN attr_value USING (jft_id)
WHERE jnt_fic_att_value.ad_id = 16) f USING (f_id)
inner JOIN ( SELECT jnt_fic_att_value.jft_id, fiche.f_id, fiche_def.frd_id, fiche.fd_id, fiche_def.fd_class_base, fiche_def.fd_label, fiche_def.fd_create_account, fiche_def_ref.frd_text, fiche_def_ref.frd_class_base, jnt_fic_att_value.ad_id, attr_value.av_text
FROM fiche
JOIN fiche_def USING (fd_id)
JOIN fiche_def_ref USING (frd_id)
JOIN jnt_fic_att_value USING (f_id)
JOIN attr_value USING (jft_id)
WHERE jnt_fic_att_value.ad_id = 17) g USING (f_id)
LEFT JOIN ( SELECT jnt_fic_att_value.jft_id, fiche.f_id, fiche_def.frd_id, fiche.fd_id, fiche_def.fd_class_base, fiche_def.fd_label, fiche_def.fd_create_account, fiche_def_ref.frd_text, fiche_def_ref.frd_class_base, jnt_fic_att_value.ad_id, attr_value.av_text
FROM fiche
JOIN fiche_def USING (fd_id)
JOIN fiche_def_ref USING (frd_id)
JOIN jnt_fic_att_value USING (f_id)
JOIN attr_value USING (jft_id)
WHERE jnt_fic_att_value.ad_id = 18) h USING (f_id)
WHERE a.frd_id = 9;
update version set val=11;
commit;

View file

@ -0,0 +1,27 @@
begin;
alter table attr_def add ad_extra text ;
insert into attr_def (ad_id,ad_text,ad_type,ad_size) values (33,'Date Fin','date',8);
ALTER TABLE fiche_detail DROP CONSTRAINT "$2";
ALTER TABLE fiche_detail
ADD CONSTRAINT fiche_detail_attr_def_fk FOREIGN KEY (ad_id)
REFERENCES attr_def (ad_id) MATCH SIMPLE
ON UPDATE cascade ON DELETE cascade;
ALTER TABLE jnt_fic_attr DROP CONSTRAINT "$2";
ALTER TABLE jnt_fic_attr
ADD CONSTRAINT jnt_fic_attr_attr_def_fk FOREIGN KEY (ad_id)
REFERENCES attr_def (ad_id) MATCH SIMPLE
ON UPDATE cascade ON DELETE cascade;
insert into menu_ref(me_code,me_menu,me_type) values ('CVS:reportinit','Export définition d''un raport','PR');
insert into profile_menu (me_code,p_id,p_type_display) values ('CVS:reportinit',1,'P');
insert into profile_menu (me_code,p_id,p_type_display) values ('CVS:reportinit',2,'P');
update version set val=101;
commit;

View file

@ -0,0 +1,11 @@
begin;
delete from letter_deb where ld_id in (select a.ld_id from letter_deb as a join letter_deb as b on (a.j_id=b.j_id and a.ld_id > b.ld_id));
delete from letter_cred where lc_id in (select a.lc_id from letter_cred as a join letter_cred as b on (a.j_id=b.j_id and a.lc_id > b.lc_id));
ALTER TABLE letter_deb ADD CONSTRAINT letter_deb_j_id_key UNIQUE(j_id );
ALTER TABLE letter_cred ADD CONSTRAINT letter_cred_j_id_key UNIQUE(j_id );
update version set val=102;
commit;

View file

@ -0,0 +1,499 @@
begin;
CREATE OR REPLACE FUNCTION comptaproc.check_balance(p_grpt integer)
RETURNS numeric AS
$BODY$
declare
amount_jrnx_debit numeric;
amount_jrnx_credit numeric;
amount_jrn numeric;
begin
select coalesce(sum (j_montant),0) into amount_jrnx_credit
from jrnx
where
j_grpt=p_grpt
and j_debit=false;
select coalesce(sum (j_montant),0) into amount_jrnx_debit
from jrnx
where
j_grpt=p_grpt
and j_debit=true;
select coalesce(jr_montant,0) 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;
update op_predef set od_direct='t' where od_jrn_type='ODS';
update profile_menu set p_order=p_order*10;
INSERT INTO menu_ref(
me_code, me_menu, me_file, me_url, me_description, me_parameter,
me_javascript, me_type)
VALUES ('BK', 'Banque', 'bank.inc.php', null, 'Information Banque', null,null,'ME');
INSERT INTO profile_menu(
me_code, me_code_dep, p_id, p_order, p_type_display, pm_default)
VALUES ('BK', 'GESTION', 1, 35, 'E', 0);
INSERT INTO profile_menu(
me_code, me_code_dep, p_id, p_order, p_type_display, pm_default)
VALUES ('BK', 'GESTION', 2, 35, 'E', 0);
update menu_ref set me_description='Grand livre analytique' where me_code='ANCGL';
alter table action_gestion add ag_remind_date date;
drop table jrn_action;
update action_gestion set ag_dest=null;
alter table action_gestion alter ag_dest type bigint using ag_dest::numeric;
alter table action_gestion alter ag_dest set default null;
COMMENT ON COLUMN action_gestion.ag_dest IS ' is the profile which has to take care of this action ';
ALTER TABLE action_gestion
ADD CONSTRAINT profile_fkey FOREIGN KEY (ag_dest)
REFERENCES profile (p_id) MATCH SIMPLE
ON UPDATE SET NULL ON DELETE SET NULL;
CREATE TABLE action_gestion_comment
(
agc_id bigserial NOT NULL, -- PK
ag_id bigint, -- FK to action_gestion
agc_date timestamp with time zone,
agc_comment text, -- comment
tech_user text, -- user_login
CONSTRAINT action_gestion_comment_pkey PRIMARY KEY (agc_id ),
CONSTRAINT action_gestion_comment_ag_id_fkey FOREIGN KEY (ag_id)
REFERENCES action_gestion (ag_id) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE
);
ALTER TABLE action_gestion_comment ALTER COLUMN agc_date SET DEFAULT now();
COMMENT ON COLUMN action_gestion_comment.agc_id IS 'PK';
COMMENT ON COLUMN action_gestion_comment.ag_id IS 'FK to action_gestion';
COMMENT ON COLUMN action_gestion_comment.agc_comment IS 'comment';
COMMENT ON COLUMN action_gestion_comment.tech_user IS 'user_login';
insert into action_gestion_comment (ag_id,agc_date,agc_comment,tech_user) select ag_id,ag_timestamp,ag_comment,ag_owner from action_gestion;
ALTER TABLE action_gestion drop COLUMN ag_comment;
CREATE TABLE action_gestion_operation
(
ago_id bigserial NOT NULL, -- pk
ag_id bigint, -- fk to action_gestion
jr_id bigint, -- fk to jrn
CONSTRAINT action_comment_operation_pkey PRIMARY KEY (ago_id ),
CONSTRAINT action_comment_operation_ag_id_fkey FOREIGN KEY (ag_id)
REFERENCES action_gestion (ag_id) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE,
CONSTRAINT action_comment_operation_jr_id_fkey FOREIGN KEY (jr_id)
REFERENCES jrn (jr_id) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE
);
COMMENT ON COLUMN action_gestion_operation.ago_id IS 'pk';
COMMENT ON COLUMN action_gestion_operation.ag_id IS 'fk to action_gestion';
COMMENT ON COLUMN action_gestion_operation.jr_id IS 'fk to jrn';
CREATE TABLE link_action_type
(
l_id bigserial NOT NULL, -- PK
l_desc character varying,
CONSTRAINT link_action_type_pkey PRIMARY KEY (l_id )
);
CREATE TABLE action_gestion_related
(
aga_id bigserial NOT NULL, -- pk
aga_least bigint NOT NULL, -- fk to action_gestion, smallest ag_id
aga_greatest bigint NOT NULL, -- fk to action_gestion greatest ag_id
aga_type bigint, -- Type de liens
CONSTRAINT action_gestion_related_pkey PRIMARY KEY (aga_id ),
CONSTRAINT action_gestion_related_aga_greatest_fkey FOREIGN KEY (aga_greatest)
REFERENCES action_gestion (ag_id) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE,
CONSTRAINT action_gestion_related_aga_least_fkey FOREIGN KEY (aga_least)
REFERENCES action_gestion (ag_id) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE,
CONSTRAINT action_gestion_related_aga_type_fkey FOREIGN KEY (aga_type)
REFERENCES link_action_type (l_id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT ux_aga_least_aga_greatest UNIQUE (aga_least , aga_greatest )
);
COMMENT ON COLUMN action_gestion_related.aga_id IS 'pk';
COMMENT ON COLUMN action_gestion_related.aga_least IS 'fk to action_gestion, smallest ag_id';
COMMENT ON COLUMN action_gestion_related.aga_greatest IS 'fk to action_gestion greatest ag_id';
COMMENT ON COLUMN action_gestion_related.aga_type IS 'Type de liens';
CREATE INDEX link_action_type_fki
ON action_gestion_related
USING btree
(aga_type );
-- Trigger: trg_action_gestion_related on action_gestion_related
CREATE OR REPLACE FUNCTION comptaproc.action_gestion_related_ins_up()
RETURNS trigger AS
$BODY$
declare
nTmp bigint;
begin
if NEW.aga_least > NEW.aga_greatest then
nTmp := NEW.aga_least;
NEW.aga_least := NEW.aga_greatest;
NEW.aga_greatest := nTmp;
end if;
if NEW.aga_least = NEW.aga_greatest then
return NULL;
end if;
return NEW;
end;
$BODY$
LANGUAGE plpgsql ;
-- DROP TRIGGER trg_action_gestion_related ON action_gestion_related;
CREATE TRIGGER trg_action_gestion_related
BEFORE INSERT OR UPDATE
ON action_gestion_related
FOR EACH ROW
EXECUTE PROCEDURE comptaproc.action_gestion_related_ins_up();
insert into action_gestion_related(aga_least,aga_greatest) select ag_id,ag_ref_ag_id from action_gestion where ag_ref_ag_id<>0;
update menu_ref set me_menu='Action Gestion' where me_code='FOLLOW';
DROP FUNCTION comptaproc.action_get_tree(bigint);
insert into menu_ref(me_code,me_menu,me_type) values ('CSV:ActionGestion','Export Action Gestion','PR');
insert into profile_menu(me_code,p_id,p_type_display,pm_default) values ('CSV:ActionGestion',1,'P',0);
ALTER TABLE document_type ADD COLUMN dt_prefix text;
COMMENT ON COLUMN document_type.dt_prefix IS 'Prefix for ag_ref';
update document_type set dt_prefix= upper(substr(replace(dt_value,' ',''),0,7))||dt_id::text;
CREATE TABLE user_sec_action_profile
(
ua_id bigserial NOT NULL, -- pk
p_id bigint, -- fk to profile
p_granted bigint, -- fk to profile
ua_right character(1), -- Type of right : R for readonly W for write
CONSTRAINT user_sec_action_profile_pkey PRIMARY KEY (ua_id ),
CONSTRAINT user_sec_action_profile_p_id_fkey FOREIGN KEY (p_id)
REFERENCES profile (p_id) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE,
CONSTRAINT user_sec_action_profile_p_granted_fkey FOREIGN KEY (p_granted)
REFERENCES profile (p_id) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE,
CONSTRAINT user_sec_action_profile_ua_right_check CHECK (ua_right = ANY (ARRAY['R'::bpchar, 'W'::bpchar]))
);
COMMENT ON TABLE user_sec_action_profile IS 'Available profile for user';
COMMENT ON COLUMN user_sec_action_profile.ua_id IS 'pk';
COMMENT ON COLUMN user_sec_action_profile.p_id IS 'fk to profile';
COMMENT ON COLUMN user_sec_action_profile.ua_right IS 'Type of right : R for readonly W for write';
INSERT INTO profile (p_name, p_id, p_desc, with_calc, with_direct_form) VALUES ('Public', -1, 'faux groupe', NULL, NULL);
insert into user_sec_action_profile(p_id,p_granted,ua_right) select 1,p_id,'W' from profile;
insert into user_sec_action_profile(p_id,p_granted ,ua_right) select 2,p_id,'W' from profile;
insert into parameter values('MY_STOCK','N');
INSERT INTO menu_ref(me_code, me_menu, me_file, me_url, me_description, me_parameter,
me_javascript, me_type)
VALUES ('CFGSTOCK', 'Configuration des dépôts', 'stock_cfg.inc.php', null, 'Configuration dépôts', null,null,'ME');
INSERT INTO profile_menu(me_code, me_code_dep, p_id, p_order, p_type_display, pm_default)
VALUES ('CFGSTOCK', 'PARAM', 1, 40, 'E', 0);
update menu_ref set me_file=null where me_code='STOCK';
update profile_menu set me_code_dep='COMPTA',p_order=90 where me_code='STOCK' and me_code_dep='ADV';
CREATE TABLE stock_repository
(
r_id bigserial NOT NULL, -- pk
r_name text, -- name of the stock
r_adress text, -- adress of the stock
r_country text, -- country of the stock
r_city text, -- City of the stock
r_phone text, -- City of the stock
CONSTRAINT stock_repository_pkey PRIMARY KEY (r_id )
);
COMMENT ON TABLE stock_repository IS 'stock repository';
COMMENT ON COLUMN stock_repository.r_id IS 'pk';
COMMENT ON COLUMN stock_repository.r_name IS 'name of the stock';
COMMENT ON COLUMN stock_repository.r_adress IS 'adress of the stock';
COMMENT ON COLUMN stock_repository.r_country IS 'country of the stock';
COMMENT ON COLUMN stock_repository.r_city IS 'City of the stock';
COMMENT ON COLUMN stock_repository.r_phone IS 'Phone number';
insert into stock_repository(r_name) values ('Dépôt par défaut');
CREATE TABLE profile_sec_repository
(
ur_id bigserial NOT NULL, -- pk
p_id bigint, -- fk to profile
r_id bigint,
ur_right character(1), -- Type of right : R for readonly W for write
CONSTRAINT profile_sec_repository_pkey PRIMARY KEY (ur_id ),
CONSTRAINT profile_sec_repository_p_id_fkey FOREIGN KEY (p_id)
REFERENCES profile (p_id) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE,
CONSTRAINT profile_sec_repository_r_id_fkey FOREIGN KEY (r_id)
REFERENCES stock_repository (r_id) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE,
CONSTRAINT user_sec_profile_ur_right_check CHECK (ur_right = ANY (ARRAY['R'::bpchar, 'W'::bpchar]))
);
COMMENT ON TABLE profile_sec_repository IS 'Available profile for user';
COMMENT ON COLUMN profile_sec_repository.ur_id IS 'pk';
COMMENT ON COLUMN profile_sec_repository.p_id IS 'fk to profile';
COMMENT ON COLUMN profile_sec_repository.r_id IS 'fk to stock_repository';
COMMENT ON COLUMN profile_sec_repository.ur_right IS 'Type of right : R for readonly W for write';
alter table stock_goods add r_id bigint;
alter table profile_sec_repository add constraint profile_sec_repository_r_id_p_id_u unique (r_id,p_id);
alter table user_sec_action_profile add constraint user_sec_action_profile_p_id_p_granted_u unique (p_id,p_granted);
update stock_goods set r_id=1;
insert into profile_sec_repository (p_id,r_id,ur_right) select p_id,1,'W' from profile where p_id > 0;
CREATE INDEX fk_stock_good_repository_r_id ON stock_goods (r_id );
alter table action_gestion drop ag_cal;
update menu_ref set me_file=null where me_code='STOCK';
insert into menu_ref (me_code,me_file,me_menu,me_description,me_type) values ('STOCK_HISTO','stock_histo.inc.php','Historique stock','Historique des mouvement de stock','ME');
insert into menu_ref (me_code,me_file,me_menu,me_description,me_type) values ('STOCK_STATE','stock_state.inc.php','Etat des stock','Etat des stock','ME');
insert into menu_ref (me_code,me_file,me_menu,me_description,me_type) values ('STOCK_INVHISTO','stock_inv_histo.inc.php','Histo. Changement','Liste des changements manuels des stocks','ME');
insert into menu_ref (me_code,me_menu,me_type) values ('CSV:StockHisto','Export Historique mouvement stock','PR');
insert into menu_ref (me_code,me_menu,me_type) values ('CSV:StockResmList','Export Résumé list stock','PR');
insert into profile_menu(me_code,me_code_dep,p_id,p_order,p_type_display) values ('STOCK_HISTO','STOCK',1,10,'E');
insert into profile_menu(me_code,me_code_dep,p_id,p_order,p_type_display) values ('STOCK_STATE','STOCK',1,20,'E');
insert into profile_menu(me_code,me_code_dep,p_id,p_order,p_type_display) values ('STOCK_HISTO','STOCK',2,10,'E');
insert into profile_menu(me_code,me_code_dep,p_id,p_order,p_type_display) values ('STOCK_STATE','STOCK',2,20,'E');
insert into profile_menu(me_code,me_code_dep,p_id,p_order,p_type_display) values ('STOCK_INVHISTO','STOCK',1,30,'E');
insert into profile_menu(me_code,me_code_dep,p_id,p_order,p_type_display) values ('STOCK_INVHISTO','STOCK',2,30,'E');
insert into profile_menu(me_code,p_id,p_type_display) values ('CSV:StockHisto',1,'P');
insert into profile_menu(me_code,p_id,p_type_display) values ('CSV:StockResmList',1,'P');
insert into profile_menu(me_code,p_id,p_type_display) values ('CSV:StockHisto',2,'P');
insert into profile_menu(me_code,p_id,p_type_display) values ('CSV:StockResmList',2,'P');
insert into menu_ref (me_code,me_file,me_menu,me_description,me_type) values ('STOCK_INV','stock_inv.inc.php','Modification Stocks','Modification des stocks (inventaire)','ME');
insert into profile_menu(me_code,me_code_dep,p_id,p_order,p_type_display) values ('STOCK_INV','STOCK',1,30,'E');
insert into profile_menu(me_code,me_code_dep,p_id,p_order,p_type_display) values ('STOCK_INV','STOCK',2,30,'E');
-- clean stock_goods
delete from stock_goods where sg_code is null or sg_code='' or sg_code not in (select ad_value from fiche_detail as fd where ad_id=19 and ad_value is not null);
CREATE INDEX fki_jrnx_j_grpt ON jrnx (j_grpt );
CREATE INDEX fki_jrn_jr_grpt_id ON jrn (jr_grpt_id );
--
insert into fiche_def (fd_id,frd_id,fd_label) values (500000,15,'Stock');
insert into jnt_fic_attr (fd_id,ad_id,jnt_order) values (500000,1,10);
insert into jnt_fic_attr (fd_id,ad_id,jnt_order) values (500000,9,20);
insert into jnt_fic_attr (fd_id,ad_id,jnt_order) values (500000,23,30);
create or replace function migrate_stock() returns void
as
$body$
declare
rt_row text;
n_fid bigint;
begin
for rt_row in select distinct ad_value from fiche_Detail where ad_id=19 and ad_value is not null and ad_Value <> ''
loop
insert into fiche (fd_id) values(500000) returning f_id into n_fid;
insert into fiche_detail (f_id,ad_id,ad_value) values (n_fid,1,rt_row);
insert into fiche_detail (f_id,ad_id,ad_value) values (n_fid,9,'Code stock '||rt_row);
insert into fiche_detail (f_id,ad_id,ad_value) values (n_fid,23,'STOCK'||n_fid::text);
update fiche_detail set ad_value='STOCK'||n_fid::text where ad_id=19 and ad_value=rt_row;
update stock_goods set sg_code='STOCK'||n_fid::text where sg_code=rt_row;
end loop;
end;
$body$ language plpgsql;
select migrate_stock();
select migrate_stock();
drop function migrate_stock();
update attr_def set ad_type='card', ad_extra='[sql] fd_id = 500000 ' where ad_id=19;
create table tmp_stockgood (s_id bigserial primary key,s_date timestamp default now());
create table tmp_stockgood_detail(d_id bigserial primary key,s_id bigint references tmp_stockgood(s_id) on delete cascade,
sg_code text,s_qin numeric(20,4),s_qout numeric(20,4),r_id bigint,f_id bigint);
CREATE OR REPLACE FUNCTION comptaproc.fiche_detail_qcode_upd()
RETURNS trigger AS
$BODY$
declare
i record;
begin
if NEW.ad_id=23 and NEW.ad_value != OLD.ad_value then
RAISE NOTICE 'new qcode [%] old qcode [%]',NEW.ad_value,OLD.ad_value;
for i in select ad_id from attr_def where ad_type = 'card' or ad_id=25 loop
update fiche_detail set ad_value=NEW.ad_value where ad_value=OLD.ad_value and ad_id=i.ad_id;
RAISE NOTICE 'change for ad_id [%] ',i.ad_id;
if i.ad_id=19 then
RAISE NOTICE 'Change in stock_goods OLD[%] by NEW[%]',OLD.ad_value,NEW.ad_value;
update stock_goods set sg_code=NEW.ad_value where sg_code=OLD.ad_value;
end if;
end loop;
end if;
return NEW;
end;
$BODY$
LANGUAGE plpgsql VOLATILE;
CREATE TRIGGER fiche_detail_upd_trg BEFORE UPDATE ON fiche_detail FOR EACH ROW EXECUTE PROCEDURE comptaproc.fiche_detail_qcode_upd();
update menu_ref set me_description='Gestion des attributs de fiches ' where me_code='CFGATCARD';
ALTER TABLE stock_goods ADD COLUMN c_id bigint;
CREATE TABLE stock_change
(
c_id bigserial NOT NULL,
c_comment text,
c_date date,
tech_user text,
r_id bigint,
tech_date time with time zone NOT NULL DEFAULT now(),
CONSTRAINT stock_change_pkey PRIMARY KEY (c_id ),
CONSTRAINT stock_change_r_id_fkey FOREIGN KEY (r_id)
REFERENCES stock_repository (r_id) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE
);
ALTER TABLE stock_goods ADD CONSTRAINT stock_goods_c_id_fkey FOREIGN KEY (c_id) REFERENCES stock_change (c_id) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE;
update action_gestion set ag_dest=-1 ;
alter table action_gestion alter ag_dest set not null;
alter table action_gestion alter ag_dest set default -1;
update menu_ref set me_code='CSV:reportinit' where me_code='CVS:reportinit';
update menu_ref set me_file='export_histo_csv.php' where me_code='CSV:histo';
update menu_ref set me_file='export_ledger_csv.php' where me_code='CSV:ledger';
update menu_ref set me_file='export_ledger_pdf.php' where me_code='PDF:ledger';
update menu_ref set me_file='export_poste_detail_csv.php' where me_code='CSV:postedetail';
update menu_ref set me_file='export_poste_detail_pdf.php' where me_code='PDF:postedetail';
update menu_ref set me_file='export_fiche_detail_csv.php' where me_code='CSV:fichedetail';
update menu_ref set me_file='export_fiche_detail_pdf.php' where me_code='PDF:fichedetail';
update menu_ref set me_file='export_fiche_balance_csv.php' where me_code='CSV:fiche_balance';
update menu_ref set me_file='export_fiche_balance_pdf.php' where me_code='PDF:fiche_balance';
update menu_ref set me_file='export_form_csv.php' where me_code='CSV:report';
update menu_ref set me_file='export_form_pdf.php' where me_code='PDF:report';
update menu_ref set me_file='export_fiche_csv.php' where me_code='CSV:fiche';
update menu_ref set me_file='export_fiche_pdf.php' where me_code='PDF:fiche';
update menu_ref set me_file='export_gl_csv.php' where me_code='CSV:glcompte';
update menu_ref set me_file='export_gl_pdf.php' where me_code='PDF:glcompte';
update menu_ref set me_file='export_security_pdf.php' where me_code='PDF:sec';
update menu_ref set me_file='export_anc_list_csv.php' where me_code='CSV:AncList';
update menu_ref set me_file='export_anc_balance_simple_csv.php' where me_code='CSV:AncBalSimple';
update menu_ref set me_file='export_anc_balance_simple_pdf.php' where me_code='PDF:AncBalSimple';
update menu_ref set me_file='export_anc_balance_double_csv.php' where me_code='CSV:AncBalDouble';
update menu_ref set me_file='export_anc_balance_double_pdf.php' where me_code='PDF:AncBalDouble';
update menu_ref set me_file='export_balance_csv.php' where me_code='CSV:balance';
update menu_ref set me_file='export_balance_pdf.php' where me_code='PDF:balance';
update menu_ref set me_file='export_anc_table_csv.php' where me_code='CSV:AncTable';
update menu_ref set me_file='export_anc_acc_list_csv.php' where me_code='CSV:AncAccList';
update menu_ref set me_file='export_anc_balance_group_csv.php' where me_code='CSV:AncBalGroup';
update menu_ref set me_file='export_bilan_oth.php' where me_code='OTH:Bilan';
update menu_ref set me_file='export_anc_grandlivre_csv.php' where me_code='CSV:AncGrandLivre';
update menu_ref set me_file='export_reportinit_csv.php' where me_code='CSV:reportinit';
update menu_ref set me_file='export_follow_up_csv.php' where me_code='CSV:ActionGestion';
update menu_ref set me_file='export_stock_histo_csv.php' where me_code='CSV:StockHisto';
update menu_ref set me_file='export_stock_resume_list.php' where me_code='CSV:StockResmList';
INSERT INTO menu_ref(
me_code, me_menu, me_file, me_url, me_description, me_parameter,
me_javascript, me_type)
VALUES ('CFGDOCST', 'Etat des documents', 'doc_state.inc.php', null, 'Etat des documents', null,null,'ME');
INSERT INTO profile_menu(
me_code, me_code_dep, p_id, p_order, p_type_display, pm_default)
VALUES ('CFGDOCST', 'DIVPARM', 1, 9, 'E', 0);
INSERT INTO profile_menu(
me_code, me_code_dep, p_id, p_order, p_type_display, pm_default)
VALUES ('CFGDOCST', 'DIVPARM', 2,9, 'E', 0);
alter sequence document_state_s_id_seq restart with 100;
CREATE INDEX quant_purchase_jrn_fki
ON quant_purchase
USING btree
(qp_internal );
ALTER TABLE quant_purchase DROP CONSTRAINT quant_purchase_qp_internal_fkey;
ALTER TABLE quant_purchase
ADD CONSTRAINT quant_purchase_qp_internal_fkey FOREIGN KEY (qp_internal)
REFERENCES jrn (jr_internal) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;
ALTER TABLE quant_sold DROP CONSTRAINT quant_sold_qs_internal_fkey;
ALTER TABLE quant_sold
ADD CONSTRAINT quant_sold_qs_internal_fkey FOREIGN KEY (qs_internal)
REFERENCES jrn (jr_internal) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;
CREATE INDEX quant_sold_jrn_fki
ON quant_sold
USING btree
(qs_internal );
create sequence uos_pk_seq;
create table tool_uos ( uos_value bigint default nextval ('uos_pk_seq') primary key );
update menu_ref set me_code='CFGCARD',me_file='cfgfiche.inc.php' where me_code='CARD';
update menu_ref set me_code='CARD',me_file='fiche.inc.php' where me_code='PRINTCARD';
update profile_menu set me_code='CARD' where me_code='CFGCARD';
update profile_menu set me_code='CFGCARD' , me_code_dep='PARAM' where me_code='CARD' and me_code_dep='PRINT';
update menu_ref set me_menu='Fiche',me_description='Liste,Balance,Historique par fiche' where me_code='CARD';
update menu_ref set me_menu='Fiche',me_description='Configuration de catégorie de fiches' where me_code='CFGCARD';
drop table user_sec_extension;
update attr_def set ad_type='card', ad_extra='[sql] frd_id in (4,8,9,14)' where ad_id=25;
update attr_Def set ad_extra='2' where ad_type='numeric';
update attr_Def set ad_extra='4' where ad_id=31;
update version set val=103;
commit;

View file

@ -0,0 +1,37 @@
begin;
CREATE OR REPLACE FUNCTION comptaproc.format_account(p_account account_type)
RETURNS account_type AS
$BODY$
declare
sResult account_type;
begin
sResult := lower(p_account);
sResult := translate(sResult,E'éèêëàâäïîüûùöôç','eeeeaaaiiuuuooc');
sResult := translate(sResult,E' $€µ£%.+-/\\!(){}(),;_&|"#''^<>*','');
return upper(sResult);
end;
$BODY$
LANGUAGE plpgsql ;
COMMENT ON FUNCTION comptaproc.format_account(account_type) IS 'format the accounting :
- upper case
- remove space and special char.
';
update tmp_pcmn set pcm_val_parent = '62' where pcm_val='6202';
update fiche_detail set ad_value = (to_number(ad_value,'9.99')*100)::text where ad_id in (21,22,20,31) and ad_value is not null and ad_value <> '';
update menu_ref set me_code='ACHISTO' WHERE me_code='ACHIMP';
update menu_ref set me_code='VEHISTO' WHERE me_code='VENIMP';
update menu_ref set me_code='FIHISTO' WHERE me_code='FIMP';
update menu_ref set me_code='ODHISTO' WHERE me_code='ODSIMP';
update version set val=104;
commit;

View file

@ -0,0 +1,105 @@
begin;
CREATE OR REPLACE FUNCTION comptaproc.insert_quick_code(nf_id integer, tav_text text)
RETURNS integer AS
$BODY$
declare
ns integer;
nExist integer;
tText text;
begin
tText := lower(trim(tav_text));
tText := replace(tText,' ','');
tText := translate(tText,E' $€µ£%.+-/\\!(){}(),;_&|"#''^<>*','');
tText := translate(tText,E'éèêëàâäïîüûùöôç','eeeeaaaiiuuuooc');
loop
-- take the next sequence
select nextval('s_jnt_fic_att_value') into ns;
if length (tText) = 0 or tText is null then
tText := 'FID'||ns;
end if;
-- av_text already used ?
select count(*) into nExist
from fiche_detail
where
ad_id=23 and ad_value=upper(tText);
if nExist = 0 then
exit;
end if;
tText:='FID'||ns;
end loop;
insert into fiche_detail(jft_id,f_id,ad_id,ad_value) values (ns,nf_id,23,upper(tText));
return ns;
end;
$BODY$
LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION comptaproc.update_quick_code(njft_id integer, tav_text text)
RETURNS integer AS
$BODY$
declare
ns integer;
nExist integer;
tText text;
old_qcode varchar;
begin
-- get current value
select ad_value into old_qcode from fiche_detail where jft_id=njft_id;
-- av_text didn't change so no update
if tav_text = upper( trim(old_qcode)) then
return 0;
end if;
tText := trim(lower(tav_text));
tText := replace(tText,' ','');
tText := translate(tText,E' $€µ£%.+-/\\!(){}(),;_&|"#''^<>*','');
tText := translate(tText,E'éèêëàâäïîüûùöôç','eeeeaaaiiuuuooc');
tText := upper(tText);
if length ( tText) = 0 or tText is null then
return 0;
end if;
ns := njft_id;
loop
-- av_text already used ?
select count(*) into nExist
from fiche_detail
where
ad_id=23 and ad_value=tText;
if nExist = 0 then
exit;
end if;
if tText = 'FID'||ns then
-- take the next sequence
select nextval('s_jnt_fic_att_value') into ns;
end if;
tText :='FID'||ns;
end loop;
update fiche_detail set ad_value = tText where jft_id=njft_id;
-- update also the contact
update fiche_detail set ad_value = tText
where jft_id in
( select jft_id
from fiche_detail
where ad_id=25 and ad_value=old_qcode);
update jrnx set j_qcode=tText where j_qcode = old_qcode;
return ns;
end;
$BODY$
LANGUAGE plpgsql;
update version set val=105;
commit;

View file

@ -0,0 +1,109 @@
begin;
CREATE OR REPLACE FUNCTION comptaproc.insert_quick_code(nf_id integer, tav_text text)
RETURNS integer AS
$BODY$
declare
ns integer;
nExist integer;
tText text;
begin
tText := lower(trim(tav_text));
tText := replace(tText,' ','');
tText := translate(tText,E' $€µ£%.+-/\\!(){}(),;_&|"#''^<>*','');
tText := translate(tText,E'éèêëàâäïîüûùöôç','eeeeaaaiiuuuooc');
loop
-- take the next sequence
select nextval('s_jnt_fic_att_value') into ns;
if length (tText) = 0 or tText is null then
tText := 'FID'||ns;
end if;
-- av_text already used ?
select count(*) into nExist
from fiche_detail
where
ad_id=23 and ad_value=upper(tText);
if nExist = 0 then
exit;
end if;
tText:='FID'||ns;
end loop;
insert into fiche_detail(jft_id,f_id,ad_id,ad_value) values (ns,nf_id,23,upper(tText));
return ns;
end;
$BODY$
LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION comptaproc.update_quick_code(njft_id integer, tav_text text)
RETURNS integer AS
$BODY$
declare
ns integer;
nExist integer;
tText text;
old_qcode varchar;
begin
-- get current value
select ad_value into old_qcode from fiche_detail where jft_id=njft_id;
-- av_text didn't change so no update
if tav_text = upper( trim(old_qcode)) then
return 0;
end if;
tText := trim(lower(tav_text));
tText := replace(tText,' ','');
tText := translate(tText,E' $€µ£%.+-/\\!(){}(),;_&|"#''^<>*','');
tText := translate(tText,E'éèêëàâäïîüûùöôç','eeeeaaaiiuuuooc');
tText := upper(tText);
if length ( tText) = 0 or tText is null then
return 0;
end if;
ns := njft_id;
loop
-- av_text already used ?
select count(*) into nExist
from fiche_detail
where
ad_id=23 and ad_value=tText;
if nExist = 0 then
exit;
end if;
if tText = 'FID'||ns then
-- take the next sequence
select nextval('s_jnt_fic_att_value') into ns;
end if;
tText :='FID'||ns;
end loop;
update fiche_detail set ad_value = tText where jft_id=njft_id;
-- update also the contact
update fiche_detail set ad_value = tText
where jft_id in
( select jft_id
from fiche_detail
where ad_id=25 and ad_value=old_qcode);
update jrnx set j_qcode=tText where j_qcode = old_qcode;
return ns;
end;
$BODY$
LANGUAGE plpgsql;
alter table document_state add s_status char(1);
update document_state set s_status='C' where s_id in (1,4);
update version set val=106;
commit;

View file

@ -0,0 +1,69 @@
begin;
update attr_def set ad_text='Compte bancaire' where ad_id=3;
ALTER TABLE mod_payment DROP CONSTRAINT mod_payment_mp_fd_id_fkey ;
ALTER TABLE mod_payment ADD CONSTRAINT mod_payment_mp_fd_id_fkey FOREIGN KEY (mp_fd_id) REFERENCES fiche_def (fd_id) MATCH SIMPLE ON UPDATE cascade ON DELETE cascade;
ALTER TABLE mod_payment DROP CONSTRAINT mod_payment_mp_jrn_def_id_fkey ;
ALTER TABLE mod_payment ADD CONSTRAINT mod_payment_mp_jrn_def_id_fkey FOREIGN KEY (mp_jrn_def_id) REFERENCES jrn_def (jrn_def_id) MATCH SIMPLE ON UPDATE CASCADE ON DELETE CASCADE;
ALTER TABLE fiche_def ADD COLUMN fd_description text;
update fiche_def set fd_description='Achats de marchandises' where fd_id=1;
update fiche_def set fd_description='Catégorie qui contient la liste des clients' where fd_id=2;
update fiche_def set fd_description='Catégorie qui contient la liste des comptes financiers: banque, caisse,...' where fd_id=3;
update fiche_def set fd_description='Catégorie qui contient la liste des fournisseurs' where fd_id=4;
update fiche_def set fd_label='Services & Biens Divers',fd_description='Catégorie qui contient la liste des charges diverses' where fd_id=5;
update fiche_def set fd_description='Catégorie qui contient la liste des prestations, marchandises... que l''on vend ' where fd_id=6;
update jrn_def set jrn_deb_max_line=5 where jrn_deb_max_line is null;
CREATE OR REPLACE FUNCTION comptaproc.periode_exist(p_date text,p_periode_id bigint)
RETURNS integer
AS $function$
declare n_p_id int4;
begin
select p_id into n_p_id
from parm_periode
where
p_start <= to_date(p_date,'DD.MM.YYYY')
and
p_end >= to_date(p_date,'DD.MM.YYYY')
and
p_id <> p_periode_id;
if NOT FOUND then
return -1;
end if;
return n_p_id;
end;$function$
LANGUAGE plpgsql;
create or replace function comptaproc.check_periode () returns trigger
as
$$
declare
nPeriode int;
begin
if periode_exist(to_char(NEW.p_start,'DD.MM.YYYY'),NEW.p_id) <> -1 then
nPeriode:=periode_exist(to_char(NEW.p_start,'DD.MM.YYYY'),NEW.p_id) ;
raise info 'Overlap periode start % periode %',NEW.p_start,nPeriode;
return null;
end if;
if periode_exist(to_char(NEW.p_end,'DD.MM.YYYY'),NEW.p_id) <> -1 then
nPeriode:=periode_exist(to_char(NEW.p_start,'DD.MM.YYYY'),NEW.p_id) ;
raise info 'Overlap periode end % periode %',NEW.p_end,nPeriode;
return null;
end if;
return NEW;
end;
$$ language plpgsql
;
create trigger parm_periode_check_periode_trg before update or insert on parm_periode for each row execute procedure check_periode();
update version set val=107;
commit;

View file

@ -0,0 +1,303 @@
begin;
-- si la fiche utilise le code DEPENSE PRIVEE alors ajout dans QP_DEP_PRIV
create or replace view m as
select qp_id, qp_price from quant_purchase join fiche_detail on (qp_fiche=f_id and ad_id=5) where ad_value in (select p_value from parm_code where p_code='DEP_PRIV');
update quant_purchase as e set qp_dep_priv=(select qp_price from m where m.qp_id=e.qp_id);
update quant_purchase as e set qp_dep_priv=(select qp_price from m where m.qp_id=e.qp_id);
update quant_purchase as e set qp_dep_priv=0 where qp_dep_priv is null;
-- évite les valeurs nulles dans quant_purchase
update quant_purchase set qp_dep_priv = 0 where qp_dep_priv is null;
drop view m;
-- update script insert_quant_purchase
CREATE OR REPLACE FUNCTION comptaproc.insert_quant_purchase(
p_internal text,
p_j_id numeric,
p_fiche text,
p_quant numeric,
p_price numeric,
p_vat numeric,
p_vat_code integer,
p_nd_amount numeric,
p_nd_tva numeric,
p_nd_tva_recup numeric,
p_dep_priv numeric,
p_client text,
p_tva_sided numeric)
RETURNS void AS
$BODY$
declare
fid_client integer;
fid_good integer;
account_priv account_type;
fid_good_account account_type;
n_dep_priv numeric;
begin
n_dep_priv := 0;
select p_value into account_priv from parm_code where p_code='DEP_PRIV';
select f_id into fid_client from
fiche_detail where ad_id=23 and ad_value=upper(trim(p_client));
select f_id into fid_good from
fiche_detail where ad_id=23 and ad_value=upper(trim(p_fiche));
select ad_value into fid_good_account from fiche_detail where ad_id=5 and f_id=fid_good;
if strpos( fid_good_account , account_priv ) = 1 then
n_dep_priv=p_price;
end if;
insert into quant_purchase
(qp_internal,
j_id,
qp_fiche,
qp_quantite,
qp_price,
qp_vat,
qp_vat_code,
qp_nd_amount,
qp_nd_tva,
qp_nd_tva_recup,
qp_supplier,
qp_dep_priv,
qp_vat_sided)
values
(p_internal,
p_j_id,
fid_good,
p_quant,
p_price,
p_vat,
p_vat_code,
p_nd_amount,
p_nd_tva,
p_nd_tva_recup,
fid_client,
n_dep_priv,
p_tva_sided);
return;
end;
$BODY$
LANGUAGE plpgsql;
-- ajout code manquant dans parm_code
create or replace function add_parm_code() returns void as
$fct$
declare
country_code text;
begin
select pr_value into country_code from parameter where pr_id='MY_COUNTRY';
if country_code='FR' then
insert into parm_code (p_code,p_comment,p_value) values ('DNA','Dépense non déductible','67');
insert into parm_code (p_code,p_comment,p_value) values ('TVA_DNA','TVA non déductible','');
insert into parm_code (p_code,p_comment,p_value) values ('TVA_DED_IMPOT','TVA déductible à l''impôt','');
insert into parm_code (p_code,p_comment,p_value) values ('COMPTE_COURANT','Poste comptable pour le compte courant','');
insert into parm_code (p_code,p_comment,p_value) values ('COMPTE_TVA','TVA à payer ou à recevoir','');
end if;
end;
$fct$
language plpgsql;
select add_parm_code();
drop function add_parm_code();
update parm_code set p_value='67' where p_value='6740' and p_code='DNA';
alter table menu_ref add me_description_etendue text;
insert into menu_ref(me_code,me_menu,me_file, me_url,me_description,me_parameter,me_javascript,me_type,me_description_etendue)
values
('NAVI','Navigateur',null,null,'Menu simplifié pour retrouver rapidement un menu',null,'ask_navigator(<DOSSIER>)','ME','Le navigateur vous présente une liste de menu auquel vous avez accès et vous permet d''accèder plus rapidement au menu que vous souhaitez rapidement');
insert into profile_menu (me_code,me_code_dep,p_id,p_order, p_type_display,pm_default)
values
('NAVI',null,1,90,'M',0), ('NAVI',null,2,90,'M',0);
insert into menu_ref(me_code,me_menu,me_file, me_url,me_description,me_parameter,me_javascript,me_type,me_description_etendue)
values
('BOOKMARK','Favori',null,null,'Raccourci vers vos menus préférés',null,'show_bookmark(<DOSSIER>)','ME','Ce menu vous présente un menu rapide des menus que vous utilisez le plus souvent');
insert into profile_menu (me_code,me_code_dep,p_id,p_order, p_type_display,pm_default)
values
('BOOKMARK',null,1,85,'M',0), ('BOOKMARK',null,2,85,'M',0);
update menu_ref set me_menu='Impression Journaux' where me_code='PRINTJRN';
update menu_ref set me_description='Impression des journaux' where me_code='PRINTJRN';
update menu_ref set me_menu='Liste Suivi' where me_code='FOLLOW';
update menu_ref set me_description='Document de suivi sous forme de liste' where me_code='FOLLOW';
update menu_ref set me_javascript='popup_recherche(<DOSSIER>)' where me_code='SEARCH';
update menu_ref set me_file=null,me_javascript='set_preference(<DOSSIER>)' , me_description_etendue='Préférence de l''utilisateur, apparence de l''application pour l''utilisateur, période par défaut et mot de passe' where me_code='PREFERENCE';
/*
* Vue montrant toutes les possibilités
*/
CREATE OR REPLACE VIEW v_menu_description AS
WITH t_menu AS (
SELECT mr.me_menu, pm.me_code, pm.me_code_dep, pm.p_type_display, pu.user_name, mr.me_file, mr.me_javascript, mr.me_description, mr.me_description_etendue
FROM profile_menu pm
JOIN profile_user pu ON pu.p_id = pm.p_id
JOIN profile p ON p.p_id = pm.p_id
JOIN menu_ref mr USING (me_code)
)
SELECT DISTINCT (COALESCE(v3.me_code || '/'::text, ''::text) || COALESCE(v2.me_code, ''::text)) ||
CASE
WHEN v2.me_code IS NULL THEN COALESCE(v1.me_code, ''::text)
WHEN v2.me_code IS NOT NULL THEN COALESCE('/'::text || v1.me_code, ''::text)
ELSE NULL::text
END AS code, v1.me_code, v1.me_description, v1.me_description_etendue, v1.me_file, v1.user_name, '> '::text || v1.me_menu AS v1menu,
CASE
WHEN COALESCE(v3.me_menu, ''::text) <> ''::text THEN ' > '::text || v2.me_menu
ELSE v2.me_menu
END AS v2menu, v3.me_menu AS v3menu, v3.p_type_display,
coalesce(v1.me_javascript,coalesce(v2.me_javascript,v3.me_javascript)) as javascript
FROM t_menu v1
LEFT JOIN t_menu v2 ON v1.me_code_dep = v2.me_code
LEFT JOIN t_menu v3 ON v2.me_code_dep = v3.me_code
WHERE v1.p_type_display <> 'P'::text AND (COALESCE(v1.me_file, ''::text) <> ''::text OR COALESCE(v1.me_javascript, ''::text) <> ''::text);
COMMENT ON VIEW v_menu_description
IS 'Description des menus';
CREATE TABLE bookmark
(
b_id serial primary key,
b_order integer default 1,
b_action text,
login text
);
comment on table bookmark is 'Bookmark of the connected user';
create table tags (
t_id serial primary key,
t_tag text not null,
t_description text
);
create table action_tags
(
at_id serial primary key,
t_id integer references tags(t_id) on delete cascade on update cascade,
ag_id integer references action_gestion(ag_id) on delete cascade on update cascade
);
/* Config tag */
insert into menu_ref(me_code,me_menu,me_file, me_url,me_description,me_parameter,me_javascript,me_type,me_description_etendue)
values
('CFGTAG','Configuration étiquette','cfgtags.inc.php',null,'Configuration des tags',null,null,'ME','Configuration des étiquettes. Vous pouvez en ajouter, en supprimer ou les modifier');
insert into profile_menu (me_code,me_code_dep,p_id,p_order, p_type_display,pm_default)
values
('CFGTAG','PARAM',1,390,'E',0);
update fiche_def_ref set frd_text='Trésorerie' where frd_id=4;
CREATE OR REPLACE FUNCTION comptaproc.insert_quick_code(nf_id integer, tav_text text)
RETURNS integer AS
$BODY$
declare
ns integer;
nExist integer;
tText text;
tBase text;
tName text;
nCount Integer;
nDuplicate Integer;
begin
tText := lower(trim(tav_text));
tText := replace(tText,' ','');
tText := translate(tText,E' $€µ£%.+-/\\!(){}(),;_&|"#''^<>*','');
tText := translate(tText,E'éèêëàâäïîüûùöôç','eeeeaaaiiuuuooc');
nDuplicate := 0;
tBase := tText;
loop
-- take the next sequence
select nextval('s_jnt_fic_att_value') into ns;
if length (tText) = 0 or tText is null then
select count(*) into nCount from fiche_detail where f_id=nf_id and ad_id=1;
if nCount = 0 then
tText := 'FICHE'||ns::text;
else
select ad_value into tName from fiche_detail where f_id=nf_id and ad_id=1;
tName := lower(trim(tName));
tName := substr(tName,1,6);
tName := replace(tName,' ','');
tName := translate(tName,E' $€µ£%.+-/\\!(){}(),;_&|"#''^<>*','');
tName := translate(tName,E'éèêëàâäïîüûùöôç','eeeeaaaiiuuuooc');
tBase := tName;
if nDuplicate = 0 then
tText := tName;
else
tText := tName||nDuplicate::text;
end if;
end if;
end if;
-- av_text already used ?
select count(*) into nExist
from fiche_detail
where
ad_id=23 and ad_value=upper(tText);
if nExist = 0 then
exit;
end if;
nDuplicate := nDuplicate + 1 ;
tText := tBase || nDuplicate::text;
if nDuplicate > 9999 then
raise Exception 'too many duplicate % duplicate# %',tText,nDuplicate;
end if;
end loop;
insert into fiche_detail(jft_id,f_id,ad_id,ad_value) values (ns,nf_id,23,upper(tText));
return ns;
end;
$BODY$
LANGUAGE plpgsql VOLATILE;
alter table op_predef add od_description text;
create or replace function comptaproc.opd_limit_description()
returns trigger
as
$BEGIN$
declare
sDescription text;
begin
sDescription := NEW.od_description;
NEW.od_description := substr(sDescription,1,80);
return NEW;
end;
$BEGIN$
LANGUAGE plpgsql;
create trigger opd_limit_description before update or insert on op_predef for each row execute procedure comptaproc.opd_limit_description();
update menu_ref set me_menu = 'Trésorerie' where me_code='MENUFIN';
create or replace function do_insert() returns void
as
$$
declare
nCount integer;
begin
select count(*) into nCount from menu_ref where me_file='contact.inc.php';
if nCount = 0 then
insert into menu_ref(ME_CODE,me_menu,me_file,me_description,me_type) values ('CONTACT','Contact','contact.inc.php','Liste des contacts','ME');
end if;
end;
$$
language plpgsql;
select do_insert();
drop function do_insert();
update version set val=108;
commit;

View file

@ -0,0 +1,265 @@
begin;
update menu_ref set me_description_etendue='Liste de tous vos contacts' where me_code='CONTACT' ;
update menu_ref set me_description_etendue='Vous permet d''encoder des achats, dépenses, des notes de frais ou des notes de crédits, vous pouvez spécifier un bénéficiaire ou un autre moyen de paiement' where me_code='ACH' ;
update menu_ref set me_description_etendue='Historique des imputations analytiques' where me_code='ANCHOP' ;
update menu_ref set me_description_etendue='Balance simple des imputations analytiques' where me_code='ANCBS' ;
update menu_ref set me_description_etendue='Tableau lié à la comptabilité' where me_code='ANCTAB' ;
update menu_ref set me_description_etendue='Lien entre comptabilité et Comptabilité analytique' where me_code='ANCBCC' ;
update menu_ref set me_description_etendue='Balance par groupe' where me_code='ANCGR' ;
update menu_ref set me_description_etendue='Permet d''ajouter des taux de TVA ou de les modifier ainsi que les postes comptables de ces TVA, ces TVA sont utilisables dans les menus de vente et d''achat' where me_code='CFGTVA' ;
update menu_ref set me_description_etendue='Encodage de tous vos revenus ou vente' where me_code='VEN' ;
update menu_ref set me_description_etendue='Ajout de menu ou de plugins' where me_code='CFGMENU' ;
update menu_ref set me_description_etendue='Suivi des fournisseurs : devis, lettres, email....' where me_code='SUPPL' ;
update menu_ref set me_description_etendue='Opérations diverses en Analytique' where me_code='ANCODS' ;
update menu_ref set me_description_etendue='Création de rapport sur mesure, comme les ratios, vous permet de créer des graphiques de vos données (vente, achat...)' where me_code='REPORT' ;
update menu_ref set me_description_etendue='Menu regroupant les plugins' where me_code='EXT' ;
update menu_ref set me_description_etendue='Les opérations prédéfinies sont des opérations que vous faites régulièrement (loyer, abonnement,...) ' where me_code='PREDOP' ;
update menu_ref set me_description_etendue='Axe analytique' where me_code='PLANANC' ;
update menu_ref set me_description_etendue='Regroupement de compte analytique' where me_code='ANCGROUP' ;
update menu_ref set me_description_etendue='Opération diverses tels que les amortissements, les augmentations de capital, les salaires, ...' where me_code='ODS' ;
update menu_ref set me_description_etendue='Encodage d''un extrait bancaire (=relevé bancaire)' where me_code='FIN' ;
update menu_ref set me_description_etendue='Historique de toutes vos opérations un menu de recherche dans une nouvelle fenêtre, vous permettra de retrouver rapidement l''opération qui vous intéresse' where me_code='JSSEARCH' ;
update menu_ref set me_description_etendue='Suivi client : devis, réunion, courrier, commande...' where me_code='CUST' ;
update menu_ref set me_description_etendue='Vous permet d''ajouter de nouveaux type de documents (bordereau de livraison, devis..)' where me_code='CFGCATDOC' ;
update menu_ref set me_description_etendue='Lettrage par fiche' where me_code='LETCARD' ;
update menu_ref set me_description_etendue='Historique de toutes vos opérations dans les journaux d''achats un menu de recherche, vous permettra de retrouver rapidement l''opération qui vous intéresse' where me_code='ACHISTO' ;
update menu_ref set me_description_etendue='Historique de toutes vos opérations dans les journaux d''opérations diverses un menu de recherche, vous permettra de retrouver rapidement l''opération qui vous intéresse' where me_code='ODHISTO' ;
update menu_ref set me_description_etendue='Impression du détail d''un poste comptable' where me_code='PRINTPOSTE' ;
update menu_ref set me_description_etendue='Impression de rapport personnalisé, il est aussi possible d''exporter en CSV afin de faire des graphiques' where me_code='PRINTREPORT' ;
update menu_ref set me_description_etendue='Impression du grand livre' where me_code='PRINTGL' ;
update menu_ref set me_description_etendue='Impression des balances comptables' where me_code='PRINTBAL' ;
update menu_ref set me_description_etendue='Regroupement pour les menus d''achats(nouvelle opération, historique...)' where me_code='MENUACH' ;
update menu_ref set me_description_etendue='Regroupement pour les menus et les profils' where me_code='MOD' ;
update menu_ref set me_description_etendue='Module paramètres' where me_code='PARAM' ;
update menu_ref set me_description_etendue='Menu impression' where me_code='PRINT' ;
update menu_ref set me_description_etendue='Regroupement des menus des journaux de trésorerie' where me_code='BK' ;
update menu_ref set me_description_etendue='Grand livre pour la comptabilité analytique' where me_code='ANCGL' ;
update menu_ref set me_description_etendue='Module gestion' where me_code='GESTION' ;
update menu_ref set me_description_etendue='Menu Lettrage' where me_code='LET' ;
update menu_ref set me_description_etendue='Choix de votre dossier' where me_code='ACCESS' ;
update menu_ref set me_description_etendue='Module comptabilité' where me_code='COMPTA' ;
update menu_ref set me_description_etendue='Menu de différents paramètres' where me_code='DIVPARM' ;
update menu_ref set me_description_etendue='Déconnexion ' where me_code='LOGOUT' ;
update menu_ref set me_description_etendue='Configuration des profils des utilisateurs, permet de fixer les journaux, profils dans les documents et stock que ce profil peut utiliser. Cela limite les utilisateurs puisque ceux-ci ont un profil' where me_code='CFGPRO' ;
update menu_ref set me_description_etendue='Config. poste comptable de base' where me_code='CFGACC' ;
update menu_ref set me_description_etendue='Permet d''avoir la balance de toutes vos fiches, les résumés exportables en CSV, les historiques avec ou sans lettrages' where me_code='CARD' ;
update menu_ref set me_description_etendue='Préférence de l''utilisateur, apparence de l''application pour l''utilisateur, période par défaut et mot de passe' where me_code='PREFERENCE' ;
update menu_ref set me_description_etendue='Configuration des tags ou dossiers, on l''appele tag ou dossier suivant la façon dont vous utilisez
cette fonctionnalité. Vous pouvez en ajouter, en supprimer ou les modifier' where me_code='CFGTAG' ;
update menu_ref set me_description_etendue='Balance double croisées des imputations analytiques' where me_code='ANCBC2' ;
update menu_ref set me_description_etendue='Information sur votre société : nom, adresse... utilisé lors de la génération de documents' where me_code='COMPANY' ;
update menu_ref set me_description_etendue='Gestion des périodes : clôture, ajout de période, afin de créer des périodes vous pouvez aussi utiliser le plugin outil comptable' where me_code='PERIODE' ;
update menu_ref set me_description_etendue='Vérifie que votre comptabilité ne contient pas d''erreur de base, tels que l''équilibre entre le passif et l''actif, l''utilisation des postes comptables...' where me_code='VERIFBIL' ;
update menu_ref set me_description_etendue='Ecriture d''ouverture ou écriture à nouveau, reporte les soldes des comptes de l''année passé du poste comptable 0xxx à 5xxxx sur l''année courante' where me_code='OPEN' ;
update menu_ref set me_description_etendue='Chargement de modèles de documents qui seront générés par NOALYSS, les formats utilisables sont libreoffice, html, text et rtf' where me_code='CFGDOC' ;
update menu_ref set me_description_etendue='Création et modification des journaux, préfixe des pièces justificatives, numérotation, catégories de fiches accessibles à ce journal' where me_code='CFGLED' ;
update menu_ref set me_description_etendue='Configuration de la sécurité, vous permet de donner un profil à vos utilisateurs, cela leur permettra d''utiliser ce que vous souhaitez qu''ils puissent utiliser' where me_code='CFGSEC' ;
update menu_ref set me_description_etendue='Permet d''ajouter de nouveaux attributs que vous pourrez par la suite ajouter à des catégories de fiches' where me_code='CFGATCARD' ;
update menu_ref set me_description_etendue='Etat des stock de l''exercice indiqué' where me_code='STOCK_STATE' ;
update menu_ref set me_description_etendue='Modification des stocks, menu utilisé pour l''inventaire' where me_code='STOCK_INV' ;
update menu_ref set me_description_etendue='Liste des changements manuels des stocks, inventaire, transfert de marchandises entre dépôts...' where me_code='STOCK_INVHISTO' ;
update menu_ref set me_description_etendue='Le navigateur vous présente une liste de menu auquel vous avez accès et vous permet d''accèder plus rapidement au menu que vous souhaitez' where me_code='NAVI' ;
update menu_ref set me_description_etendue='Historique de toutes vos opérations dans tous les journaux auquels vous avez accès, vous permettra de retrouver rapidement l''opération qui vous intéresse sur base de la date, du poste comptable, des montants...' where me_code='SEARCH' ;
update menu_ref set me_description_etendue='Historique de toutes vos opérations un menu de recherche, vous permettra de retrouver rapidement l''opération qui vous intéresse' where me_code='HIST' ;
update menu_ref set me_description_etendue='Permet de faire correspondre vos extraits bancaires avec les opérations de vente ou d''achat, le lettrage se fait automatiquement' where me_code='FREC' ;
update menu_ref set me_description_etendue='Solde des journaux de trésorerie cela concerne les comptes en banques, caisse , les chèques... ' where me_code='FSALDO' ;
update menu_ref set me_description_etendue='lettrage par poste comptable' where me_code='LETACC' ;
update menu_ref set me_description_etendue='Balance par catégorie de fiche ou pour toutes les fiches ayant un poste comptable' where me_code='CARDBAL' ;
update menu_ref set me_description_etendue='Modification de votre plan comptable, parfois il est plus rapide d''utiliser le plugin "Poste Comptable"' where me_code='CFGPCMN' ;
update menu_ref set me_description_etendue='Historique de toutes vos opérations dans les journaux de vente un menu de recherche, vous permettra de retrouver rapidement l''opération qui vous intéresse' where me_code='VEHISTO' ;
update menu_ref set me_description_etendue='Historique de toutes vos opérations dans les journaux de trésorerie un menu de recherche, vous permettra de retrouver rapidement l''opération qui vous intéresse' where me_code='FIHISTO' ;
update menu_ref set me_description_etendue='Impression des rapprochements : opérations non rapprochées ou avec des montants différents' where me_code='PRINTREC' ;
update menu_ref set me_description_etendue='Impression de bilan, ce module est basique, il est plus intéressant d''utiliser le plugin "rapport avancés"' where me_code='PRINTBILAN' ;
update menu_ref set me_description_etendue='Configuration des entrepots de dépôts' where me_code='CFGSTOCK' ;
update menu_ref set me_description_etendue='Permet d''ajouter de nouvelles catégorie de fiche, d''ajouter des attributs à ces catégories (numéro de téléphone, gsm, email...)' where me_code='STOCK' ;
update menu_ref set me_description_etendue='Permet de changer le poste comptable de base des catégories de fiches' where me_code='CFGCARDCAT' ;
update menu_ref set me_description_etendue='Permet d''ajouter de nouvelles catégorie de fiche, d''ajouter des attributs à ces catégories (numéro de téléphone, gsm, email...)' where me_code='CFGCARD' ;
update menu_ref set me_description_etendue='Permet d''ajouter des état pour les documents utilisés dans le suivi (à faire, à suivre...)' where me_code='CFGDOCST' ;
update menu_ref set me_description_etendue='Regroupement pour les menus d''opérations diverses (nouvelle opération, historique...)' where me_code='MENUODS' ;
update menu_ref set me_description_etendue='Impression des journaux avec les détails pour les parties privés, la TVA et ce qui est non déductibles en ce qui concerne les journaux de vente et d''achat' where me_code='PRINTJRN' ;
update menu_ref set me_description_etendue='Regroupement des menus ventes et recettes' where me_code='VENMENU' ;
update menu_ref set me_description_etendue='Impression compta. analytique' where me_code='ANCIMP' ;
update menu_ref set me_description_etendue='Module comptabilité analytique' where me_code='ANC' ;
update menu_ref set me_description_etendue='Tableau de suivi, vous permet de voir en un coup d''oeil vos dernières opérations, un petit calendrier, une liste de chose à faire...' where me_code='DASHBOARD' ;
update menu_ref set me_description_etendue='Menu regroupant la création de rapport, la vérification de la comptabilité...' where me_code='ADV' ;
update menu_ref set me_description_etendue='Ce menu vous présente un menu rapide de vos menus préférés' where me_code='BOOKMARK' ;
update menu_ref set me_description_etendue='Regroupement pour les menus de trésorerie (nouvelle opération, historique...)' where me_code='MENUFIN' ;
update menu_ref set me_description_etendue='Liste de vos suivis, en fait de tous les documents, réunions ... dont vous avez besoin afin de suivre vos clients, fournisseurs ou administrations. Il permet la génération de documents comme les devis, les bordereau de livraison...' where me_code='FOLLOW' ;
update menu_ref set me_description_etendue='Configuration des moyens de paiements que vous voulez utiliser dans les journaux de type VEN ou ACH, les moyens de paiement permettent de générer l''opération de trésorerie en même temps que l''achat, la note de frais ou la vente' where me_code='CFGPAY' ;
update menu_ref set me_description_etendue='Suivi des administrations : courrrier, déclarations.' where me_code='ADM' ;
update menu_ref set me_description_etendue='Prévision de vos achats, revenus, permet de suivre l''évolution de votre société. Vos prévisions sont des formules sur les postes comptables et vous permettent aussi vos marges brutes.' where me_code='FORECAST' ;
CREATE OR REPLACE VIEW v_detail_sale AS
with m as
(select sum(qs_price) as htva, sum(qs_vat) as tot_vat,jr_id from quant_sold join jrnx using (j_id) join jrn on (j_grpt=jr_grpt_id) group by jr_id)
SELECT jrn.jr_id,
jrn.jr_date,
jrn.jr_tech_per,
jrn.jr_comment,
jrn.jr_pj_number,
jrn.jr_internal,
jrn.jr_def_id,
jrnx.j_poste,
jrnx.j_text,
jrnx.j_qcode,
quant_sold.qs_fiche as item_card,
a.name AS item_name,
quant_sold.qs_client,
b.vw_name AS tiers_name,
b.quick_code,
tva_rate.tva_label,
tva_rate.tva_comment,
tva_rate.tva_both_side,
quant_sold.qs_vat_sided as vat_sided,
quant_sold.qs_vat_code as vat_code,
quant_sold.qs_vat as vat,
quant_sold.qs_price as price,
quant_sold.qs_quantite as quantity,
quant_sold.qs_price / quant_sold.qs_quantite AS price_per_unit
, htva
,tot_vat
FROM jrn
JOIN jrnx ON jrn.jr_grpt_id = jrnx.j_grpt
JOIN quant_sold USING (j_id)
JOIN vw_fiche_name a ON quant_sold.qs_fiche = a.f_id
JOIN vw_fiche_attr b ON quant_sold.qs_client = b.f_id
JOIN tva_rate ON quant_sold.qs_vat_code = tva_rate.tva_id
join m on (m.jr_id=jrn.jr_id)
;
CREATE OR REPLACE VIEW v_detail_purchase AS
WITH m AS (
SELECT sum(quant_purchase.qp_price) AS htva, sum(quant_purchase.qp_vat) AS tot_vat, jrn.jr_id
FROM quant_purchase
JOIN jrnx USING (j_id)
JOIN jrn ON jrnx.j_grpt = jrn.jr_grpt_id
GROUP BY jrn.jr_id
)
SELECT jrn.jr_id,
jrn.jr_date
, jrn.jr_tech_per
, jrn.jr_comment
, jrn.jr_pj_number
, jrn.jr_internal
, jrn.jr_def_id
, jrnx.j_poste
, jrnx.j_text
, jrnx.j_qcode
, quant_purchase.qp_fiche AS item_card
, a.name AS item_name
, quant_purchase.qp_supplier
, b.vw_name AS tiers_name
, b.quick_code
, tva_rate.tva_label
, tva_rate.tva_comment
, tva_rate.tva_both_side
, quant_purchase.qp_vat_sided AS vat_sided
, quant_purchase.qp_vat_code AS vat_code
, quant_purchase.qp_vat AS vat
, quant_purchase.qp_price AS price
, quant_purchase.qp_quantite AS quantity
, quant_purchase.qp_price / quant_purchase.qp_quantite AS price_per_unit
, quant_purchase.qp_nd_amount AS non_ded_amount
, quant_purchase.qp_nd_tva AS non_ded_tva
, quant_purchase.qp_nd_tva_recup AS non_ded_tva_recup
, m.htva, m.tot_vat
FROM jrn
JOIN jrnx ON jrn.jr_grpt_id = jrnx.j_grpt
JOIN quant_purchase USING (j_id)
JOIN vw_fiche_name a ON quant_purchase.qp_fiche = a.f_id
JOIN vw_fiche_attr b ON quant_purchase.qp_supplier = b.f_id
JOIN tva_rate ON quant_purchase.qp_vat_code = tva_rate.tva_id
JOIN m ON m.jr_id = jrn.jr_id;
create or replace view v_quant_detail as
with quant as
(select
j_id,
qp_fiche as fiche_id,
qp_supplier as tiers,
qp_vat as vat_amount,
qp_price as price,
qp_vat_code as vat_code,
qp_dep_priv as dep_priv,
qp_nd_tva as nd_tva,
qp_nd_tva_recup as nd_tva_recup,
qp_nd_amount as nd_amount,
qp_vat_sided as vat_sided
from quant_purchase
union all
select
j_id,
qs_fiche,
qs_client,
qs_vat,
qs_price,
qs_vat_code,
0,
0,
0,
0,
qs_vat_sided
from
quant_sold
)
select
jr_id,quant.tiers,jrn_def_name,jrn_def_type,name,jr_comment,jr_montant,sum(price) as price,vat_code,sum(vat_amount) as vat_amount,sum(dep_priv) as dep_priv,sum(nd_tva) as nd_tva,sum(nd_tva_recup) as nd_tva_recup,sum(nd_amount) as nd_amount,vat_sided,tva_label
from
jrn
join jrnx on (jrnx.j_grpt=jrn.jr_grpt_id)
join quant using (j_id)
left join vw_fiche_name on (tiers=vw_fiche_name.f_id)
join jrn_def on (jrn_def_id=jr_def_id)
join tva_rate on (tva_id=vat_code)
group by
jr_id,quant.tiers,jr_comment,jr_montant,vat_code,vat_sided,name,jrn_def_name,jrn_def_type,tva_label;
insert into menu_ref(me_code,me_menu,me_file, me_url,me_description,me_parameter,me_javascript,me_type,me_description_etendue)
values
('CSV:Reconciliation','Export opérations rapprochées','export_rec_csv.php',null,'Export opérations rapprochées en CSV',null,null,'PR','');
insert into profile_menu (me_code,me_code_dep,p_id,p_order, p_type_display,pm_default)
values
('CSV:Reconciliation',null,1,0,'P',0), ('CSV:Reconciliation',null,2,null,'P',0);
alter table stock_change alter tech_date type time;
alter table jrn add column jr_date_paid date;
create or replace function set_paiement_date() returns void
as
$body$
declare
row_jrn jrn%ROWTYPE;
cursor_jrn cursor for select * from jrn where substr(jr_internal,1,1) in ('A','V') and jr_date_paid is null;
n_rec jrn_rapt.jr_id%TYPE;
nCount integer;
jrn_date jrn.jr_date%TYPE;
begin
for row_jrn in cursor_jrn
loop
select count(*) into nCount from jrn_rapt where jr_id=row_jrn.jr_id or jra_concerned=row_jrn.jr_id;
if nCount = 1 then
select jr_id into n_rec from jrn_rapt where jra_concerned=row_jrn.jr_id;
if NOT FOUND then
select jra_concerned into n_rec from jrn_rapt where jr_id=row_jrn.jr_id;
end if;
select jr_date into jrn_date from jrn where jr_id=n_rec;
update jrn set jr_date_paid = jrn_date where current of cursor_jrn;
end if;
end loop;
end;
$body$
language plpgsql;
select set_paiement_date();
drop function set_paiement_date();
update version set val=109;
commit;

View file

@ -0,0 +1,32 @@
begin;
alter table jrn_def add jrn_def_description text;
CREATE OR REPLACE FUNCTION comptaproc.t_jrn_def_description()
RETURNS trigger
AS $function$
declare
str varchar(200);
BEGIN
str := substr(NEW.jrn_def_description,1,200);
NEW.jrn_def_description := str;
RETURN NEW;
END;
$function$
LANGUAGE plpgsql
;
create trigger jrn_def_description_ins_upd before insert or update on jrn_def for each row execute procedure comptaproc.t_jrn_def_description();
update jrn_def set jrn_def_description='Concerne tous les achats, factures reçues, notes de crédit reçues et notes de frais' where jrn_def_id=3;
update jrn_def set jrn_def_description='Concerne tous les mouvements financiers (comptes en banque, caisses, visa...)' where jrn_def_id=1;
update jrn_def set jrn_def_description='Concerne toutes les opérations comme les amortissements, les comptes TVA, ...' where jrn_def_id=4;
update jrn_def set jrn_def_description='Concerne toutes les ventes, notes de crédit envoyées' where jrn_def_id=2;
alter table document add d_description text;
update document set d_description = d_filename;
update version set val=110;
commit;

View file

@ -0,0 +1,126 @@
begin;
create table parm_code (
p_code text primary key,
p_value text,
p_comment text
);
INSERT INTO parm_code VALUES ('DNA', '6740', 'Dépense non déductible');
INSERT INTO parm_code VALUES ('CUSTOMER', '400', 'Poste comptable de base pour les clients');
INSERT INTO parm_code VALUES ('COMPTE_TVA', '451', 'TVA à payer');
INSERT INTO parm_code VALUES ('BANQUE', '550', 'Poste comptable de base pour les banques');
INSERT INTO parm_code VALUES ('VIREMENT_INTERNE', '58', 'Poste Comptable pour les virements internes');
INSERT INTO parm_code VALUES ('COMPTE_COURANT', '56', 'Poste comptable pour le compte courant');
INSERT INTO parm_code VALUES ('CAISSE', '57', 'Poste comptable pour la caisse');
INSERT INTO parm_code VALUES ('TVA_DNA', '6740', 'Tva non déductible s');
INSERT INTO parm_code VALUES ('TVA_DED_IMPOT', '619000', 'Tva déductible par l''impôt');
INSERT INTO parm_code VALUES ('VENTE ', '70', 'Poste comptable de base pour les ventes');
-- Function: tva_delete(p_tva_id int4)
CREATE OR REPLACE FUNCTION tva_delete(int4)
RETURNS void AS
$BODY$
declare
p_tva_id alias for $1;
nCount integer;
begin
nCount=0;
select count(*) into nCount from quant_sold where qs_vat_code=p_tva_id;
if nCount = 0 then
delete from tva_rate where tva_id=p_tva_id;
end if;
return;
end;
$BODY$
LANGUAGE plpgsql VOLATILE;
-- Function: tva_insert(int4, text, numeric, text, text)
CREATE OR REPLACE FUNCTION tva_insert(int4, text, "numeric", text, text)
RETURNS int4 AS
$BODY$
declare
p_tva_id alias for $1;
p_tva_label alias for $2;
p_tva_rate alias for $3;
p_tva_comment alias for $4;
p_tva_poste alias for $5;
debit text;
credit text;
nCount integer;
begin
-- verify that label is not null
if length(trim(p_tva_label)) = 0 then
return 3;
end if;
select count(*) into nCount from tva_rate
where tva_id=p_tva_id;
if nCount != 0 then
return 5;
end if;
-- check is poste exists
if length(trim(p_tva_poste)) != 0 then
-- check if it is a comma list
if position (',' in p_tva_poste) = 0 then return 4; end if;
-- separate "credit" and "debit"
debit = split_part(p_tva_poste,',',1);
credit = split_part(p_tva_poste,',',2);
-- check if those account exist
select count(*) into nCount from tmp_pcmn where pcm_val=debit;
if nCount = 0 then return 4; end if;
select count(*) into nCount from tmp_pcmn where pcm_val=credit;
if nCount = 0 then return 4; end if;
end if;
insert into tva_rate(tva_id,tva_label,tva_rate,tva_comment,tva_poste)
values (p_tva_id,p_tva_label,p_tva_rate,p_tva_comment,p_tva_poste);
return 0;
end;
$BODY$
LANGUAGE plpgsql VOLATILE;
-- Function: tva_insert(p_tva_id text, p_tva_label text, p_tva_rate text, p_tva_comment text, p_tva_poste text)
CREATE OR REPLACE FUNCTION tva_modify(integer, text, numeric, text, text)
RETURNS int4 AS
$BODY$declare
p_tva_id alias for $1;
p_tva_label alias for $2;
p_tva_rate alias for $3;
p_tva_comment alias for $4;
p_tva_poste alias for $5;
debit text;
credit text;
nCount integer;
begin
-- verify that label is not null
if length(trim(p_tva_label)) = 0 then
return 3;
end if;
-- check is poste exists
if length(trim(p_tva_poste)) != 0 then
-- check if it is a comma list
if position (',' in p_tva_poste) = 0 then return 4; end if;
-- separate "credit" and "debit"
debit = split_part(p_tva_poste,',',1);
credit = split_part(p_tva_poste,',',2);
-- check if those account exist
select count(*) into nCount from tmp_pcmn where pcm_val=debit;
if nCount = 0 then return 4; end if;
select count(*) into nCount from tmp_pcmn where pcm_val=credit;
if nCount = 0 then return 4; end if;
end if;
update tva_rate set tva_label=p_tva_label,tva_rate=p_tva_rate,tva_comment=p_tva_comment,tva_poste=p_tva_poste
where tva_id=p_tva_id;
return 0;
end;
$BODY$
LANGUAGE plpgsql VOLATILE;
update version set val=12;
commit;

View file

@ -0,0 +1,26 @@
begin;
create or replace view v_menu_description_favori as
WITH t_menu AS (
SELECT mr.me_menu, pm.me_code, pm.me_code_dep, pm.p_type_display, pu.user_name, mr.me_file, mr.me_javascript, mr.me_description, mr.me_description_etendue
FROM profile_menu pm
JOIN profile_user pu ON pu.p_id = pm.p_id
JOIN profile p ON p.p_id = pm.p_id
JOIN menu_ref mr USING (me_code)
)
SELECT DISTINCT (COALESCE(v3.me_code || '/'::text, ''::text) || COALESCE(v2.me_code, ''::text)) ||
CASE
WHEN v2.me_code IS NULL THEN COALESCE(v1.me_code, ''::text)
WHEN v2.me_code IS NOT NULL THEN COALESCE('/'::text || v1.me_code, ''::text)
ELSE NULL::text
END AS code, v1.me_code, v1.me_description, v1.me_description_etendue, v1.me_file, v1.user_name, '> '::text || v1.me_menu AS v1menu,
CASE
WHEN COALESCE(v3.me_menu, ''::text) <> ''::text THEN ' > '::text || v2.me_menu
ELSE v2.me_menu
END AS v2menu, v3.me_menu AS v3menu, v3.p_type_display, COALESCE(v1.me_javascript, COALESCE(v2.me_javascript, v3.me_javascript)) AS javascript
FROM t_menu v1
LEFT JOIN t_menu v2 ON v1.me_code_dep = v2.me_code
LEFT JOIN t_menu v3 ON v2.me_code_dep = v3.me_code
WHERE v1.p_type_display <> 'P'::text;
update version set val=111;
commit;

View file

@ -0,0 +1,38 @@
begin;
insert into menu_ref(me_code,me_menu,me_file, me_url,me_description,me_parameter,me_javascript,me_type,me_description_etendue)
values
('MANAGER','Administrateur','manager.inc.php',null,'Suivi des gérants, administrateurs et salariés',null,null,'ME','Suivi de vos salariés, managers ainsi que des administrateurs, pour les documents et les opérations comptables');
insert into profile_menu (me_code,me_code_dep,p_id,p_order, p_type_display,pm_default)
values
('MANAGER','GESTION',1,25,'E',0), ('MANAGER','GESTION',2,25,'E',0);
insert into menu_ref(me_code,me_menu,me_file, me_url,me_description,me_parameter,me_javascript,me_type,me_description_etendue)
values
('CFGDEFMENU','Menu par défaut','default_menu.inc.php',null,'Configuration des menus par défaut',null,null,'ME','Configuration des menus par défaut, ces menus sont appelés par des actions dans d''autres menus');
insert into profile_menu (me_code,me_code_dep,p_id,p_order, p_type_display,pm_default)
values
('CFGDEFMENU','MOD',1,30,'E',0);
insert into menu_ref(me_code,me_menu,me_file, me_url,me_description,me_parameter,me_javascript,me_type,me_description_etendue)
values
('AGENDA','Agenda','calendar.inc.php',null,'Agenda',null,null,'ME','Agenda, présentation du suivi sous forme d''agenda ');
insert into profile_menu (me_code,me_code_dep,p_id,p_order, p_type_display,pm_default)
values
('AGENDA','NULL',1,410,'M',0),('AGENDA','NULL',2,410,'M',0);
create table menu_default
(
md_id serial primary key,
md_code text not null unique ,
me_code text not null
);
insert into menu_default (md_code,me_code) values ('code_invoice','COMPTA/VENMENU/VEN'),('code_follow','GESTION/FOLLOW');
update menu_ref set me_file='customer.inc.php' where me_code ='CUST';
update version set val=112;
commit;

View file

@ -0,0 +1,15 @@
begin;
ALTER TABLE operation_analytique ADD COLUMN oa_jrnx_id_source bigint;
COMMENT ON COLUMN operation_analytique.oa_jrnx_id_source IS 'jrnx.j_id source of this amount, this amount is computed from an amount giving a ND VAT.Normally NULL is there is no ND VAT.';
ALTER TABLE operation_analytique ADD COLUMN oa_signed character(1);
ALTER TABLE operation_analytique ALTER COLUMN oa_signed SET DEFAULT 'Y'::bpchar;
update operation_analytique set oa_signed='Y';
ALTER TABLE operation_analytique ALTER COLUMN oa_signed SET NOT NULL;
COMMENT ON COLUMN operation_analytique.oa_signed IS 'Sign of the amount';
update version set val=113;
commit;

View file

@ -0,0 +1,7 @@
begin;
alter table operation_analytique rename oa_signed to oa_positive;
update version set val=114;
commit;

View file

@ -0,0 +1,51 @@
begin;
DROP VIEW v_detail_purchase;
CREATE OR REPLACE VIEW v_detail_purchase AS
WITH m AS (
SELECT sum(quant_purchase.qp_price) AS htva, sum(quant_purchase.qp_vat) AS tot_vat, jrn.jr_id
FROM quant_purchase
JOIN jrnx USING (j_id)
JOIN jrn ON jrnx.j_grpt = jrn.jr_grpt_id
GROUP BY jrn.jr_id
)
SELECT jrn.jr_id, jrn.jr_date, jrn.jr_date_paid,jr_ech,
jrn.jr_tech_per, jrn.jr_comment,
jrn.jr_pj_number, jrn.jr_internal,
jrn.jr_def_id, jrnx.j_poste,
jrnx.j_text, jrnx.j_qcode,
quant_purchase.qp_fiche AS item_card, a.name AS item_name,
quant_purchase.qp_supplier, b.vw_name AS tiers_name,
b.quick_code, tva_rate.tva_label,
tva_rate.tva_comment, tva_rate.tva_both_side, quant_purchase.qp_vat_sided AS vat_sided, quant_purchase.qp_vat_code AS vat_code, quant_purchase.qp_vat AS vat, quant_purchase.qp_price AS price, quant_purchase.qp_quantite AS quantity, quant_purchase.qp_price / quant_purchase.qp_quantite AS price_per_unit, quant_purchase.qp_nd_amount AS non_ded_amount, quant_purchase.qp_nd_tva AS non_ded_tva, quant_purchase.qp_nd_tva_recup AS non_ded_tva_recup, m.htva, m.tot_vat
FROM jrn
JOIN jrnx ON jrn.jr_grpt_id = jrnx.j_grpt
JOIN quant_purchase USING (j_id)
JOIN vw_fiche_name a ON quant_purchase.qp_fiche = a.f_id
JOIN vw_fiche_attr b ON quant_purchase.qp_supplier = b.f_id
JOIN tva_rate ON quant_purchase.qp_vat_code = tva_rate.tva_id
JOIN m ON m.jr_id = jrn.jr_id;
DROP VIEW v_detail_sale;
CREATE OR REPLACE VIEW v_detail_sale AS
WITH m AS (
SELECT sum(quant_sold.qs_price) AS htva, sum(quant_sold.qs_vat) AS tot_vat, jrn.jr_id
FROM quant_sold
JOIN jrnx USING (j_id)
JOIN jrn ON jrnx.j_grpt = jrn.jr_grpt_id
GROUP BY jrn.jr_id
)
SELECT jrn.jr_id, jrn.jr_date, jrn.jr_date_paid,jr_ech,jrn.jr_tech_per, jrn.jr_comment, jrn.jr_pj_number, jrn.jr_internal, jrn.jr_def_id, jrnx.j_poste, jrnx.j_text, jrnx.j_qcode, quant_sold.qs_fiche AS item_card, a.name AS item_name, quant_sold.qs_client, b.vw_name AS tiers_name, b.quick_code, tva_rate.tva_label, tva_rate.tva_comment, tva_rate.tva_both_side, quant_sold.qs_vat_sided AS vat_sided, quant_sold.qs_vat_code AS vat_code, quant_sold.qs_vat AS vat, quant_sold.qs_price AS price, quant_sold.qs_quantite AS quantity, quant_sold.qs_price / quant_sold.qs_quantite AS price_per_unit, m.htva, m.tot_vat
FROM jrn
JOIN jrnx ON jrn.jr_grpt_id = jrnx.j_grpt
JOIN quant_sold USING (j_id)
JOIN vw_fiche_name a ON quant_sold.qs_fiche = a.f_id
JOIN vw_fiche_attr b ON quant_sold.qs_client = b.f_id
JOIN tva_rate ON quant_sold.qs_vat_code = tva_rate.tva_id
join m on m.jr_id=jrn.jr_id;
update version set val=115;
commit;

View file

@ -0,0 +1,9 @@
begin;
INSERT INTO menu_ref(me_code, me_menu, me_file, me_type)VALUES ('PDF:AncReceipt', 'Export pièce PDF', 'export_anc_receipt_pdf.php','PR');
insert into profile_menu(me_code,p_id,p_type_display,pm_default) values ('PDF:AncReceipt',1,'P',0);
update version set val=116;
commit;

View file

@ -0,0 +1,225 @@
begin;
insert into fiche_def_ref(frd_id,frd_text) values (26,'Projet');
insert into attr_min (frd_id,ad_id) values (26,1),(26,9);
CREATE OR REPLACE FUNCTION public.upgrade_repo(p_version integer)
RETURNS void
AS $function$
declare
is_mono integer;
begin
select count (*) into is_mono from information_schema.tables where table_name='repo_version';
if is_mono = 1 then
update repo_version set val=p_version;
else
update version set val=p_version;
end if;
end;
$function$
language plpgsql;
-- bug
alter table action_gestion alter ag_title type text;
INSERT INTO menu_ref(me_code, me_menu, me_file, me_type,me_description_etendue)VALUES ('ANCKEY', 'Clef de répartition', 'anc_key.inc.php','ME','Permet de gèrer les clefs de répartition en comptabilité analytique');
insert into profile_menu(me_code,p_id,p_type_display,pm_default,me_code_dep,p_order) values ('ANCKEY',1,'E',0,'ANC',15);
insert into profile_menu(me_code,p_id,p_type_display,pm_default,me_code_dep,p_order) values ('ANCKEY',2,'E',0,'ANC',15);
INSERT INTO menu_ref(me_code, me_menu, me_file, me_type,me_description_etendue)VALUES ('CFGPLUGIN', 'Configuration extension', 'cfgplugin.inc.php','ME','Permet d''installer et d''activer facilement des extensions');
insert into profile_menu(me_code,p_id,p_type_display,pm_default,me_code_dep,p_order) values ('CFGPLUGIN',1,'E',0,'PARAM',15);
insert into profile_menu(me_code,p_id,p_type_display,pm_default,me_code_dep,p_order) values ('CFGPLUGIN',2,'E',0,'PARAM',15);
create table key_distribution (
kd_id serial primary key,
kd_name text,
kd_description text);
create table key_distribution_ledger (
kl_id serial primary key,
kd_id bigint not null references key_distribution(kd_id) on update cascade on delete cascade,
jrn_def_id bigint not null references jrn_def(jrn_def_id) on update cascade on delete cascade
);
create table key_distribution_detail(
ke_id serial primary key,
kd_id bigint not null references key_distribution(kd_id) on update cascade on delete cascade,
ke_row integer not null,
ke_percent numeric(20,4) not null
);
create table key_distribution_activity
(
ka_id serial primary key,
ke_id bigint not null references key_distribution_detail(ke_id) on update cascade on delete cascade,
po_id bigint references poste_analytique(po_id) on update cascade on delete cascade,
pa_id bigint not null references plan_analytique(pa_id) on update cascade on delete cascade
);
comment on table key_distribution is 'Distribution key for analytic';
comment on table key_distribution_activity is 'activity (account) linked to the row';
comment on column key_distribution.kd_id is 'PK';
comment on column key_distribution.kd_name is 'Name of the key';
comment on column key_distribution.kd_description is 'Description of the key';
comment on table key_distribution_ledger is 'Legder where the distribution key can be used' ;
comment on column key_distribution_ledger.kl_id is 'pk';
comment on column key_distribution_ledger.kd_id is 'fk to key_distribution';
comment on column key_distribution_ledger.jrn_def_id is 'fk to jrnd_def, ledger where this key is available';
comment on table key_distribution_detail is 'Row of activity and percent';
comment on column key_distribution_detail.ke_id is 'pk';
comment on column key_distribution_detail.kd_id is 'fk to key_distribution';
comment on column key_distribution_detail.ke_row is 'group order';
comment on table key_distribution_activity is 'Contains the analytic account';
comment on column key_distribution_activity.ka_id is 'pk';
comment on column key_distribution_activity.ke_id is 'fk to key_distribution_detail';
comment on column key_distribution_activity.po_id is 'fk to poste_analytique';
comment on column key_distribution_activity.pa_id is 'fk to plan_analytique';
drop view vw_fiche_attr cascade;
CREATE view vw_fiche_attr as
SELECT a.f_id, a.fd_id, a.ad_value AS vw_name, k.ad_value AS vw_first_name, b.ad_value AS vw_sell, c.ad_value AS vw_buy, d.ad_value AS tva_code, tva_rate.tva_id, tva_rate.tva_rate, tva_rate.tva_label, e.ad_value AS vw_addr, f.ad_value AS vw_cp, j.ad_value AS quick_code, h.ad_value AS vw_description, i.ad_value AS tva_num, fiche_def.frd_id,l.ad_value as accounting
FROM ( SELECT fiche.f_id, fiche.fd_id, fiche_detail.ad_value
FROM fiche
LEFT JOIN fiche_detail USING (f_id)
WHERE fiche_detail.ad_id = 1) a
LEFT JOIN ( SELECT fiche_detail.f_id, fiche_detail.ad_value
FROM fiche_detail
WHERE fiche_detail.ad_id = 6) b ON a.f_id = b.f_id
LEFT JOIN ( SELECT fiche_detail.f_id, fiche_detail.ad_value
FROM fiche_detail
WHERE fiche_detail.ad_id = 7) c ON a.f_id = c.f_id
LEFT JOIN ( SELECT fiche_detail.f_id, fiche_detail.ad_value
FROM fiche_detail
WHERE fiche_detail.ad_id = 2) d ON a.f_id = d.f_id
LEFT JOIN ( SELECT fiche_detail.f_id, fiche_detail.ad_value
FROM fiche_detail
WHERE fiche_detail.ad_id = 14) e ON a.f_id = e.f_id
LEFT JOIN ( SELECT fiche_detail.f_id, fiche_detail.ad_value
FROM fiche_detail
WHERE fiche_detail.ad_id = 15) f ON a.f_id = f.f_id
LEFT JOIN ( SELECT fiche_detail.f_id, fiche_detail.ad_value
FROM fiche_detail
WHERE fiche_detail.ad_id = 23) j ON a.f_id = j.f_id
LEFT JOIN ( SELECT fiche_detail.f_id, fiche_detail.ad_value
FROM fiche_detail
WHERE fiche_detail.ad_id = 9) h ON a.f_id = h.f_id
LEFT JOIN ( SELECT fiche_detail.f_id, fiche_detail.ad_value
FROM fiche_detail
WHERE fiche_detail.ad_id = 13) i ON a.f_id = i.f_id
LEFT JOIN ( SELECT fiche_detail.f_id, fiche_detail.ad_value
FROM fiche_detail
WHERE fiche_detail.ad_id = 32) k ON a.f_id = k.f_id
LEFT JOIN tva_rate ON d.ad_value = tva_rate.tva_id::text
JOIN fiche_def USING (fd_id)
LEFT JOIN ( SELECT fiche_detail.f_id, fiche_detail.ad_value
FROM fiche_detail
WHERE fiche_detail.ad_id = 5) l ON a.f_id = l.f_id;
create view v_detail_sale as
WITH m AS (
SELECT sum(quant_sold.qs_price) AS htva, sum(quant_sold.qs_vat) AS tot_vat,sum(quant_sold.qs_vat_sided) as tot_tva_np, jrn.jr_id
FROM quant_sold
JOIN jrnx USING (j_id)
JOIN jrn ON jrnx.j_grpt = jrn.jr_grpt_id
GROUP BY jrn.jr_id
)
SELECT jrn.jr_id, jrn.jr_date, jrn.jr_date_paid, jrn.jr_ech, jrn.jr_tech_per, jrn.jr_comment, jrn.jr_pj_number, jrn.jr_internal, jrn.jr_def_id, jrnx.j_poste, jrnx.j_text, jrnx.j_qcode, quant_sold.qs_fiche AS item_card, a.name AS item_name, quant_sold.qs_client, b.vw_name AS tiers_name, b.quick_code, tva_rate.tva_label, tva_rate.tva_comment, tva_rate.tva_both_side, quant_sold.qs_vat_sided AS vat_sided, quant_sold.qs_vat_code AS vat_code, quant_sold.qs_vat AS vat, quant_sold.qs_price AS price, quant_sold.qs_quantite AS quantity, quant_sold.qs_price / quant_sold.qs_quantite AS price_per_unit, m.htva, m.tot_vat,m.tot_tva_np
FROM jrn
JOIN jrnx ON jrn.jr_grpt_id = jrnx.j_grpt
JOIN quant_sold USING (j_id)
JOIN vw_fiche_name a ON quant_sold.qs_fiche = a.f_id
JOIN vw_fiche_attr b ON quant_sold.qs_client = b.f_id
JOIN tva_rate ON quant_sold.qs_vat_code = tva_rate.tva_id
JOIN m ON m.jr_id = jrn.jr_id;
create view v_detail_purchase as
WITH m AS (
SELECT sum(quant_purchase.qp_price) AS htva, sum(quant_purchase.qp_vat) AS tot_vat, sum(quant_purchase.qp_vat_sided) as tot_tva_np, jrn.jr_id
FROM quant_purchase
JOIN jrnx USING (j_id)
JOIN jrn ON jrnx.j_grpt = jrn.jr_grpt_id
GROUP BY jrn.jr_id
)
SELECT jrn.jr_id, jrn.jr_date, jrn.jr_date_paid, jrn.jr_ech, jrn.jr_tech_per, jrn.jr_comment, jrn.jr_pj_number, jrn.jr_internal, jrn.jr_def_id, jrnx.j_poste, jrnx.j_text, jrnx.j_qcode, quant_purchase.qp_fiche AS item_card, a.name AS item_name,
quant_purchase.qp_supplier, b.vw_name AS tiers_name, b.quick_code, tva_rate.tva_label,
tva_rate.tva_comment, tva_rate.tva_both_side,
quant_purchase.qp_vat_sided AS vat_sided,
quant_purchase.qp_vat_code AS vat_code,
quant_purchase.qp_vat AS vat,
quant_purchase.qp_price AS price,
quant_purchase.qp_quantite AS quantity,
quant_purchase.qp_price / quant_purchase.qp_quantite AS price_per_unit,
quant_purchase.qp_nd_amount AS non_ded_amount,
quant_purchase.qp_nd_tva AS non_ded_tva,
quant_purchase.qp_nd_tva_recup AS non_ded_tva_recup,
m.htva, m.tot_vat
,m.tot_tva_np
FROM jrn
JOIN jrnx ON jrn.jr_grpt_id = jrnx.j_grpt
JOIN quant_purchase USING (j_id)
JOIN vw_fiche_name a ON quant_purchase.qp_fiche = a.f_id
JOIN vw_fiche_attr b ON quant_purchase.qp_supplier = b.f_id
JOIN tva_rate ON quant_purchase.qp_vat_code = tva_rate.tva_id
JOIN m ON m.jr_id = jrn.jr_id;
create index jrnx_j_qcode_ix on jrnx (j_qcode);
CREATE TABLE action_person
(
ap_id SERIAL NOT NULL,
ag_id int4 NOT NULL references action_gestion(ag_id) on update cascade on delete cascade,
f_id int4 not null references fiche(f_id) on update cascade on delete cascade,
PRIMARY KEY (ap_id));
COMMENT ON TABLE action_person IS 'Person involved in the action';
comment on column action_person.ap_id is 'pk';
comment on column action_person.ag_id is 'fk to action_action';
comment on column action_person.ag_id is 'fk to fiche';
ALTER TABLE action_person ADD CONSTRAINT action_gestion_ag_id_fk2 FOREIGN KEY (ag_id) REFERENCES action_gestion (ag_id);
ALTER TABLE action_person ADD CONSTRAINT fiche_f_id_fk2 FOREIGN KEY (f_id) REFERENCES fiche(f_id);
alter table action_gestion alter f_id_dest drop not null;
update action_gestion set f_id_dest = null where f_id_dest = 0;
update action_gestion set f_id_dest =null where f_id_dest not in (select f_id from fiche);
ALTER TABLE action_gestion ADD CONSTRAINT fiche_f_id_fk3 FOREIGN KEY (f_id_dest) REFERENCES fiche(f_id);
create index fk_action_person_action_gestion on action_person (ag_id);
create index fk_action_person_fiche on action_person (f_id);
CREATE OR REPLACE FUNCTION comptaproc.category_card_before_delete()
RETURNS trigger AS
$BODY$
begin
if OLD.fd_id > 499000 then
return null;
end if;
return OLD;
end;
$BODY$
language plpgsql;
CREATE TRIGGER trg_category_card_before_delete
BEFORE delete
ON fiche_def
FOR EACH ROW
EXECUTE PROCEDURE comptaproc.category_card_before_delete();
alter table action_gestion add constraint fk_action_gestion_document_type foreign key (ag_type) references document_type(dt_id);
update version set val=117;
commit;

View file

@ -0,0 +1,184 @@
begin;
ALTER TABLE action ALTER COLUMN ac_code TYPE character varying(30);
INSERT INTO action(ac_id, ac_description, ac_module, ac_code)
VALUES (1110, 'Enlever une pièce justificative', 'compta', 'RMRECEIPT');
INSERT INTO action(ac_id, ac_description, ac_module, ac_code)
VALUES (1120, 'Effacer une opération ', 'compta', 'RMOPER');
INSERT INTO action(ac_id, ac_description, ac_module, ac_code)
VALUES (1210, 'Partager une note', 'note', 'SHARENOTE');
INSERT INTO action(ac_id, ac_description, ac_module, ac_code)
VALUES (1220, 'Créer une note publique', 'note', 'SHARENOTEPUBLIC');
INSERT INTO action(ac_id, ac_description, ac_module, ac_code)
VALUES (1230, 'Effacer une note publique', 'note', 'SHARENOTEREMOVE');
CREATE TABLE todo_list_shared (id serial primary key, todo_list_id int4 NOT NULL, use_login text NOT NULL, CONSTRAINT unique_todo_list_id_login
UNIQUE (todo_list_id, use_login));
ALTER TABLE todo_list_shared ADD CONSTRAINT fk_todo_list_shared_todo_list FOREIGN KEY (todo_list_id) REFERENCES todo_list (tl_id);
comment on table todo_list_shared is 'Note of todo list shared with other users';
comment on column todo_list_shared.todo_list_id is 'fk to todo_list';
comment on column todo_list_shared.use_login is 'user login';
alter table todo_list add is_public char(1) default 'N';
comment on column todo_list.is_public is 'Flag for the public parameter';
ALTER TABLE todo_list ALTER COLUMN is_public SET NOT NULL;
ALTER TABLE todo_list ADD CONSTRAINT ck_is_public CHECK (is_public in ('Y','N'));
update menu_ref set me_menu = 'Favori &#9733; ' where me_code='BOOKMARK';
update menu_ref set me_menu = 'Sortie &#9094;' where me_code='LOGOUT';
insert into menu_ref(me_code,me_menu,me_file, me_url,me_description,me_parameter,me_javascript,me_type,me_description_etendue)
values
('BALAGE','Balance agée','balance_age.inc.php',null,'Balance agée',null,null,'ME','Balance agée pour les clients et fournisseurs') ,
('CSV:balance_age','Export Balance agée','export_balance_age_csv.php',null,'Balance agée',null,null,'PR','Balance agée pour les clients et fournisseurs') ;
insert into profile_menu (me_code,me_code_dep,p_id,p_order, p_type_display,pm_default)
values
('BALAGE','PRINT',1,550,'E',0),('BALAGE','PRINT',2,550,'E',0),
('CSV:balance_age',null,1,null,'P',0),('CSV:balance_age',null,2,null,'P',0);
CREATE OR REPLACE FUNCTION comptaproc.account_compute(p_f_id integer)
RETURNS account_type AS
$BODY$
declare
class_base fiche_def.fd_class_base%type;
maxcode numeric;
sResult text;
bAlphanum bool;
sName text;
begin
select fd_class_base into class_base
from
fiche_def join fiche using (fd_id)
where
f_id=p_f_id;
raise notice 'account_compute class base %',class_base;
bAlphanum := account_alphanum();
if bAlphanum = false then
raise info 'account_compute : Alphanum is false';
select count (pcm_val) into maxcode from tmp_pcmn where pcm_val_parent = class_base;
if maxcode = 0 then
maxcode:=class_base::numeric;
else
select max (pcm_val) into maxcode from tmp_pcmn where pcm_val_parent = class_base;
maxcode:=maxcode::numeric;
end if;
if maxcode::text = class_base then
maxcode:=class_base::numeric*1000;
end if;
maxcode:=maxcode+1;
raise notice 'account_compute Max code %',maxcode;
sResult:=maxcode::account_type;
else
raise info 'account_compute : Alphanum is true';
-- if alphanum, use name
select ad_value into sName from fiche_detail where f_id=p_f_id and ad_id=1;
raise info 'name is %',sName;
if sName is null then
raise exception 'Cannot compute an accounting without the name of the card for %',p_f_id;
end if;
sResult := class_base||sName;
sResult := substr(sResult,1,40);
raise info 'Result is %',sResult;
end if;
return sResult::account_type;
end;
$BODY$
LANGUAGE plpgsql ;
CREATE OR REPLACE FUNCTION comptaproc.account_insert(p_f_id integer, p_account text)
RETURNS text AS
$BODY$
declare
nParent tmp_pcmn.pcm_val_parent%type;
sName varchar;
sNew tmp_pcmn.pcm_val%type;
bAuto bool;
nFd_id integer;
sClass_Base fiche_def.fd_class_base%TYPE;
nCount integer;
first text;
second text;
s_account text;
begin
if p_account is not null and length(trim(p_account)) != 0 then
-- if there is coma in p_account, treat normally
if position (',' in p_account) = 0 then
raise info 'p_account is not empty';
s_account := substr( p_account,1 , 40);
select count(*) into nCount from tmp_pcmn where pcm_val=s_account::account_type;
raise notice 'found in tmp_pcm %',nCount;
if nCount !=0 then
raise info 'this account exists in tmp_pcmn ';
perform attribut_insert(p_f_id,5,s_account);
else
-- account doesn't exist, create it
select ad_value into sName from
fiche_detail
where
ad_id=1 and f_id=p_f_id;
nParent:=account_parent(s_account::account_type);
insert into tmp_pcmn(pcm_val,pcm_lib,pcm_val_parent) values (s_account::account_type,sName,nParent);
perform attribut_insert(p_f_id,5,s_account);
end if;
else
raise info 'presence of a comma';
-- there is 2 accounts separated by a comma
first := split_part(p_account,',',1);
second := split_part(p_account,',',2);
-- check there is no other coma
raise info 'first value % second value %', first, second;
if position (',' in first) != 0 or position (',' in second) != 0 then
raise exception 'Too many comas, invalid account';
end if;
perform attribut_insert(p_f_id,5,p_account);
end if;
else
raise info 'A000 : p_account is empty';
select fd_id into nFd_id from fiche where f_id=p_f_id;
bAuto:= account_auto(nFd_id);
select fd_class_base into sClass_base from fiche_def where fd_id=nFd_id;
raise info 'sClass_Base : %',sClass_base;
if bAuto = true and sClass_base similar to '[[:digit:]]*' then
raise info 'account generated automatically';
sNew:=account_compute(p_f_id);
raise info 'sNew %', sNew;
select ad_value into sName from
fiche_detail
where
ad_id=1 and f_id=p_f_id;
nParent:=account_parent(sNew);
sNew := account_add (sNew,sName);
perform attribut_insert(p_f_id,5,sNew);
else
-- if there is an account_base then it is the default
select fd_class_base::account_type into sNew from fiche_def join fiche using (fd_id) where f_id=p_f_id;
if sNew is null or length(trim(sNew)) = 0 then
raise notice 'count is null';
perform attribut_insert(p_f_id,5,null);
else
perform attribut_insert(p_f_id,5,sNew);
end if;
end if;
end if;
return 0;
end;
$BODY$ LANGUAGE plpgsql ;
update version set val=118;
commit;

View file

@ -0,0 +1,167 @@
begin;
alter table profile_menu add pm_id_dep bigint ;
comment on column profile_menu.pm_id_dep is 'parent of this menu item';
CREATE OR REPLACE VIEW v_menu_dependency AS
WITH t_menu AS (
SELECT pm.pm_id, mr.me_menu, pm.me_code, pm.me_code_dep, pm.p_type_display, mr.me_file, mr.me_javascript, mr.me_description, mr.me_description_etendue, p.p_id
FROM profile_menu pm
JOIN profile p ON p.p_id = pm.p_id
JOIN menu_ref mr USING (me_code)
)
SELECT DISTINCT (COALESCE(v3.me_code || '/'::text, ''::text) || COALESCE(v2.me_code, ''::text)) ||
CASE
WHEN v2.me_code IS NULL THEN COALESCE(v1.me_code, ''::text)
WHEN v2.me_code IS NOT NULL THEN COALESCE('/'::text || v1.me_code, ''::text)
ELSE NULL::text
END AS code, v1.pm_id, v1.me_code, v1.me_description, v1.me_description_etendue, v1.me_file, '> '::text || v1.me_menu AS v1menu,
CASE
WHEN v2.pm_id IS NOT NULL THEN v2.pm_id
WHEN v3.pm_id IS NOT NULL THEN v3.pm_id
ELSE NULL::integer
END AS higher_dep,
CASE
WHEN COALESCE(v3.me_menu, ''::text) <> ''::text THEN ' > '::text || v2.me_menu
ELSE v2.me_menu
END AS v2menu, v3.me_menu AS v3menu, v3.p_type_display, COALESCE(v1.me_javascript, COALESCE(v2.me_javascript, v3.me_javascript)) AS javascript, v1.p_id, v2.p_id AS v2pid, v3.p_id AS v3pid
FROM t_menu v1
LEFT JOIN t_menu v2 ON v1.me_code_dep = v2.me_code
LEFT JOIN t_menu v3 ON v2.me_code_dep = v3.me_code
WHERE COALESCE(v2.p_id, v1.p_id) = v1.p_id AND COALESCE(v3.p_id, v1.p_id) = v1.p_id AND v1.p_type_display <> 'P'::text
ORDER BY v1.pm_id;
CREATE OR REPLACE FUNCTION modify_menu_system(n_profile numeric)
RETURNS void AS
$BODY$
declare
r_duplicate profile_menu%ROWTYPE;
str_duplicate text;
n_lowest_id numeric; -- lowest pm_id : update the dependency in profile_menu
n_highest_id numeric; -- highest pm_id insert into profile_menu
begin
for str_duplicate in
select me_code
from profile_menu
where
p_id=n_profile and
p_type_display <> 'P' and
pm_id_dep is null
group by me_code
having count(*) > 1
loop
raise info 'str_duplicate %',str_duplicate;
for r_duplicate in select *
from profile_menu
where
p_id=n_profile and
me_code_dep=str_duplicate
loop
raise info 'r_duplicate %',r_duplicate;
-- get the lowest
select a.pm_id into n_lowest_id from profile_menu a join profile_menu b on (a.me_code=b.me_code and a.p_id = b.p_id)
where
a.me_code=str_duplicate
and a.p_id=n_profile
and a.pm_id < b.pm_id;
raise info 'lowest is %',n_lowest_id;
-- get the highest
select a.pm_id into n_highest_id from profile_menu a join profile_menu b on (a.me_code=b.me_code and a.p_id = b.p_id)
where
a.me_code=str_duplicate
and a.p_id=n_profile
and a.pm_id > b.pm_id;
raise info 'highest is %',n_highest_id;
-- update the first one
update profile_menu set pm_id_dep = n_lowest_id where pm_id=r_duplicate.pm_id;
-- insert a new one
insert into profile_menu (me_code,
me_code_dep,
p_id,
p_order,
p_type_display,
pm_default,
pm_id_dep)
values (r_duplicate.me_code,
r_duplicate.me_code_dep,
r_duplicate.p_id,
r_duplicate.p_order,
r_duplicate.p_type_display,
r_duplicate.pm_default,
n_highest_id);
end loop;
end loop;
end;
$BODY$
language plpgsql;
select modify_menu_system(1);
select modify_menu_system(2);
update profile_menu set pm_id_dep=(select higher_dep from v_menu_dependency as a where
a.pm_id= profile_menu.pm_id) where pm_id_dep is null and p_id=1;
update profile_menu set pm_id_dep=(select higher_dep from v_menu_dependency as a where
a.pm_id= profile_menu.pm_id) where pm_id_dep is null and p_id=2;
CREATE OR REPLACE VIEW v_menu_profile AS
WITH t_menu AS (
SELECT pm.pm_id,pm.pm_id_dep, pm.me_code, pm.me_code_dep, pm.p_type_display,pm.p_id
FROM profile_menu pm
JOIN profile p ON p.p_id = pm.p_id
)
SELECT DISTINCT
(COALESCE(v3.me_code || '/'::text, ''::text) || COALESCE(v2.me_code, ''::text)) ||
CASE
WHEN v2.me_code IS NULL THEN COALESCE(v1.me_code, ''::text)
WHEN v2.me_code IS NOT NULL THEN COALESCE('/'::text || v1.me_code, ''::text)
ELSE NULL::text
END AS code,
v3.p_type_display,
coalesce(v3.pm_id,0) as pm_id_v3,
coalesce(v2.pm_id,0) as pm_id_v2,
v1.pm_id as pm_id_v1
,v1.p_id
FROM t_menu v1
LEFT JOIN t_menu v2 ON v1.pm_id_dep = v2.pm_id
LEFT JOIN t_menu v3 ON v2.pm_id_dep= v3.pm_id
WHERE v1.p_type_display <> 'P'::text
;
COMMENT ON VIEW v_menu_profile IS 'Give the profile and the menu + dependencies';
CREATE OR REPLACE VIEW v_menu_description AS
WITH t_menu AS (
SELECT pm.pm_id,pm.pm_id_dep,pm.p_id,mr.me_menu, pm.me_code, pm.me_code_dep, pm.p_type_display, pu.user_name, mr.me_file, mr.me_javascript, mr.me_description, mr.me_description_etendue
FROM profile_menu pm
JOIN profile_user pu ON pu.p_id = pm.p_id
JOIN profile p ON p.p_id = pm.p_id
JOIN menu_ref mr USING (me_code)
)
SELECT DISTINCT (COALESCE(v3.me_code || '/'::text, ''::text) || COALESCE(v2.me_code, ''::text)) ||
CASE
WHEN v2.me_code IS NULL THEN COALESCE(v1.me_code, ''::text)
WHEN v2.me_code IS NOT NULL THEN COALESCE('/'::text || v1.me_code, ''::text)
ELSE NULL::text
END AS code, v1.me_code, v1.me_description, v1.me_description_etendue, v1.me_file, v1.user_name, '> '::text || v1.me_menu AS v1menu,
CASE
WHEN COALESCE(v3.me_menu, ''::text) <> ''::text THEN ' > '::text || v2.me_menu
ELSE v2.me_menu
END AS v2menu, v3.me_menu AS v3menu, v3.p_type_display, COALESCE(v1.me_javascript, COALESCE(v2.me_javascript, v3.me_javascript)) AS javascript,
v1.pm_id,v1.pm_id_dep,v1.p_id
FROM t_menu v1
LEFT JOIN t_menu v2 ON v1.me_code_dep = v2.me_code
LEFT JOIN t_menu v3 ON v2.me_code_dep = v3.me_code
WHERE v1.p_type_display <> 'P'::text AND (COALESCE(v1.me_file, ''::text) <> ''::text OR COALESCE(v1.me_javascript, ''::text) <> ''::text);
COMMENT ON VIEW v_menu_description IS 'Description des menus';
update version set val=119;
commit;

View file

@ -0,0 +1,5 @@
begin;
update menu_ref set me_file = null where me_code='EXT';
update version set val=120;
commit;

View file

@ -0,0 +1,11 @@
begin;
ALTER TABLE quant_sold ADD CONSTRAINT qs_id_pk PRIMARY KEY(qs_id);
COMMENT ON TABLE quant_sold IS 'Contains about invoice for customer';
drop table user_pref;
-- trim the space
update parm_code set p_code=trim(p_code);
update version set val=13;
commit;

View file

@ -0,0 +1,280 @@
begin;
update menu_ref set me_file = null where me_code='EXT';
update op_predef_detail set opd_poste=trim(opd_poste) ;
CREATE OR REPLACE FUNCTION comptaproc.fiche_detail_qcode_upd()
RETURNS trigger AS
$BODY$
declare
i record;
begin
if NEW.ad_id=23 and NEW.ad_value != OLD.ad_value then
RAISE NOTICE 'new qcode [%] old qcode [%]',NEW.ad_value,OLD.ad_value;
update jrnx set j_qcode=NEW.ad_value where j_qcode = OLD.ad_value;
update op_predef_detail set opd_poste=NEW.ad_value where opd_poste=OLD.ad_value;
raise notice 'TRG fiche_detail update op_predef_detail set opd_poste=% where opd_poste=%;',NEW.ad_value,OLD.ad_value;
for i in select ad_id from attr_def where ad_type = 'card' or ad_id=25 loop
update fiche_detail set ad_value=NEW.ad_value where ad_value=OLD.ad_value and ad_id=i.ad_id;
RAISE NOTICE 'change for ad_id [%] ',i.ad_id;
if i.ad_id=19 then
RAISE NOTICE 'Change in stock_goods OLD[%] by NEW[%]',OLD.ad_value,NEW.ad_value;
update stock_goods set sg_code=NEW.ad_value where sg_code=OLD.ad_value;
end if;
end loop;
end if;
return NEW;
end;
$BODY$
LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION comptaproc.update_quick_code(njft_id integer, tav_text text)
RETURNS integer AS
$BODY$
declare
ns integer;
nExist integer;
tText text;
old_qcode varchar;
num_rows_jrnx integer;
num_rows_predef integer;
begin
-- get current value
select ad_value into old_qcode from fiche_detail where jft_id=njft_id;
-- av_text didn't change so no update
if tav_text = upper( trim(old_qcode)) then
raise notice 'nothing to change % %' , tav_text,old_qcode;
return 0;
end if;
tText := trim(lower(tav_text));
tText := replace(tText,' ','');
-- valid alpha is [ . : - _ ]
tText := translate(tText,E' $€µ£%+/\\!(){}(),;&|"#''^<>*','');
tText := translate(tText,E'éèêëàâäïîüûùöôç','eeeeaaaiiuuuooc');
tText := upper(tText);
if length ( tText) = 0 or tText is null then
return 0;
end if;
ns := njft_id;
loop
-- av_text already used ?
select count(*) into nExist
from fiche_detail
where
ad_id=23 and ad_value=tText;
if nExist = 0 then
exit;
end if;
if tText = 'FID'||ns then
-- take the next sequence
select nextval('s_jnt_fic_att_value') into ns;
end if;
tText :='FID'||ns;
end loop;
update fiche_detail set ad_value = tText where jft_id=njft_id;
-- update also the contact
update fiche_detail set ad_value = tText
where jft_id in
( select jft_id
from fiche_detail
where ad_id=25 and ad_value=old_qcode);
return ns;
end;
$BODY$
LANGUAGE plpgsql ;
CREATE OR REPLACE FUNCTION comptaproc.insert_quick_code(nf_id integer, tav_text text)
RETURNS integer AS
$BODY$
declare
ns integer;
nExist integer;
tText text;
tBase text;
tName text;
nCount Integer;
nDuplicate Integer;
begin
tText := lower(trim(tav_text));
tText := replace(tText,' ','');
tName:= translate(tName,E' $€µ£%+/\\!(){}(),;&|"#''^<>*','');
tText := translate(tText,E'éèêëàâäïîüûùöôç','eeeeaaaiiuuuooc');
nDuplicate := 0;
tBase := tText;
loop
-- take the next sequence
select nextval('s_jnt_fic_att_value') into ns;
if length (tText) = 0 or tText is null then
select count(*) into nCount from fiche_detail where f_id=nf_id and ad_id=1;
if nCount = 0 then
tText := 'FICHE'||ns::text;
else
select ad_value into tName from fiche_detail where f_id=nf_id and ad_id=1;
tName := lower(trim(tName));
tName := substr(tName,1,6);
tName := replace(tName,' ','');
tName:= translate(tName,E' $€µ£%+/\\!(){}(),;&|"#''^<>*','');
tName := translate(tName,E'éèêëàâäïîüûùöôç','eeeeaaaiiuuuooc');
tBase := tName;
if nDuplicate = 0 then
tText := tName;
else
tText := tName||nDuplicate::text;
end if;
end if;
end if;
-- av_text already used ?
select count(*) into nExist
from fiche_detail
where
ad_id=23 and ad_value=upper(tText);
if nExist = 0 then
exit;
end if;
nDuplicate := nDuplicate + 1 ;
tText := tBase || nDuplicate::text;
if nDuplicate > 9999 then
raise Exception 'too many duplicate % duplicate# %',tText,nDuplicate;
end if;
end loop;
insert into fiche_detail(jft_id,f_id,ad_id,ad_value) values (ns,nf_id,23,upper(tText));
return ns;
end;
$BODY$
LANGUAGE plpgsql;
create or replace function insert_menu()
returns void as
$BODY$
declare
n_count integer := 0;
begin
select count(*) into n_count from menu_ref where me_code='CONTACT';
if n_count = 0 then
insert into menu_ref(me_code,
me_file,
me_menu,
me_description,me_type,me_description_etendue)
values
('CONTACT',
'contact.inc.php',
'Contact','Liste de vos contacts','ME','Liste de vos contacts normalement liée à des fiches de sociétés');
end if;
select count(*) into n_count from profile_menu where me_code='CONTACT' and p_id=1;
if n_count = 0 then
insert into profile_menu(me_code,me_code_dep,p_id,p_order,p_type_display,pm_default,pm_id_dep) select 'CONTACT','GESTION',1,22,'E',0,(select pm_id from profile_menu where me_code='GESTION' and p_id=1);
end if;
select count(*) into n_count from profile_menu where me_code='CONTACT' and p_id=2;
if n_count = 0 then
insert into profile_menu(me_code,me_code_dep,p_id,p_order,p_type_display,pm_default,pm_id_dep) select 'CONTACT','GESTION',2,22,'E',0,(select pm_id from profile_menu where me_code='GESTION' and p_id=2);
end if;
end;
$BODY$
LANGUAGE plpgsql;
select insert_menu();
drop function insert_menu();
drop view v_all_menu;
CREATE OR REPLACE VIEW v_all_menu AS
SELECT pm.me_code,
pm.pm_id,
pm.me_code_dep,
pm.p_order,
pm.p_type_display,
p.p_name,
p.p_desc,
mr.me_menu,
mr.me_file,
mr.me_url,
mr.me_parameter,
mr.me_javascript,
mr.me_type,
pm.p_id,
mr.me_description
FROM profile_menu pm
JOIN profile p ON p.p_id = pm.p_id
JOIN menu_ref mr USING (me_code)
ORDER BY pm.p_order;
DROP FUNCTION comptaproc.get_profile_menu(text);
CREATE OR REPLACE FUNCTION comptaproc.get_profile_menu(p_profile integer)
RETURNS SETOF menu_tree AS
$BODY$
declare
a menu_tree;
e menu_tree;
begin
for a in select me_code,me_description from v_all_menu where p_id=p_profile
and me_code_dep is null and me_type <> 'PR' and me_type <>'SP'
loop
return next a;
for e in select * from get_menu_tree(a.code,p_profile)
loop
return next e;
end loop;
end loop;
return;
end;
$BODY$
LANGUAGE plpgsql ;
DROP FUNCTION comptaproc.get_menu_tree(text, text);
CREATE OR REPLACE FUNCTION comptaproc.get_menu_tree(p_code text, p_profile integer)
RETURNS SETOF menu_tree AS
$BODY$
declare
i menu_tree;
e menu_tree;
a text;
x v_all_menu%ROWTYPE;
begin
for x in select * from v_all_menu where me_code_dep=p_code::text and p_id=p_profile
loop
if x.me_code_dep is not null then
i.code := x.me_code_dep||'/'||x.me_code;
else
i.code := x.me_code;
end if;
i.description := x.me_description;
return next i;
for e in select * from get_menu_tree(x.me_code,p_profile)
loop
e.code:=x.me_code_dep||'/'||e.code;
return next e;
end loop;
end loop;
return;
end;
$BODY$
LANGUAGE plpgsql;
update version set val=121;
commit;

View file

@ -0,0 +1,566 @@
begin;
-- dropped all the views
-- Name: vw_client; Type: VIEW; Schema: public; Owner: phpcompta
DROP VIEW vw_client ;
-- Name: vw_fiche_attr; Type: VIEW; Schema: public; Owner: phpcompta
DROP VIEW vw_fiche_attr ;
-- Name: vw_fiche_def; Type: VIEW; Schema: public; Owner: phpcompta
DROP VIEW vw_fiche_def ;
-- Name: vw_fiche_min; Type: VIEW; Schema: public; Owner: phpcompta
DROP VIEW vw_fiche_min ;
-- Name: vw_poste_qcode; Type: VIEW; Schema: public; Owner: phpcompta
DROP VIEW vw_poste_qcode;
-- Stan's problem : account were not large enough
-- Converted to numeric to avoid integer limit
create domain poste_comptable as numeric(25);
alter table tmp_pcmn alter pcm_val type poste_comptable;
alter table tmp_pcmn alter pcm_val_parent type poste_comptable;
alter table jrnx alter j_poste TYPE poste_comptable ;
alter table centralized alter c_poste TYPE poste_comptable ;
alter table fiche_def alter fd_class_base TYPE poste_comptable ;
-- recreate all the views
CREATE VIEW vw_client AS
SELECT a.f_id, a.av_text AS name, a1.av_text AS quick_code, b.av_text AS tva_num, c.av_text AS poste_comptable, d.av_text AS rue, e.av_text AS code_postal, f.av_text AS pays, g.av_text AS telephone, h.av_text AS email FROM (((((((((SELECT jnt_fic_att_value.jft_id, fiche.f_id, fiche_def.frd_id, fiche.fd_id, fiche_def.fd_class_base, fiche_def.fd_label, fiche_def.fd_create_account, fiche_def_ref.frd_text, fiche_def_ref.frd_class_base, jnt_fic_att_value.ad_id, attr_value.av_text FROM ((((fiche JOIN fiche_def USING (fd_id)) JOIN fiche_def_ref USING (frd_id)) JOIN jnt_fic_att_value USING (f_id)) JOIN attr_value USING (jft_id)) WHERE (jnt_fic_att_value.ad_id = 1)) a JOIN (SELECT jnt_fic_att_value.jft_id, fiche.f_id, fiche_def.frd_id, fiche.fd_id, fiche_def.fd_class_base, fiche_def.fd_label, fiche_def.fd_create_account, fiche_def_ref.frd_text, fiche_def_ref.frd_class_base, jnt_fic_att_value.ad_id, attr_value.av_text FROM ((((fiche JOIN fiche_def USING (fd_id)) JOIN fiche_def_ref USING (frd_id)) JOIN jnt_fic_att_value USING (f_id)) JOIN attr_value USING (jft_id)) WHERE (jnt_fic_att_value.ad_id = 13)) b USING (f_id)) JOIN (SELECT jnt_fic_att_value.jft_id, fiche.f_id, fiche_def.frd_id, fiche.fd_id, fiche_def.fd_class_base, fiche_def.fd_label, fiche_def.fd_create_account, fiche_def_ref.frd_text, fiche_def_ref.frd_class_base, jnt_fic_att_value.ad_id, attr_value.av_text FROM ((((fiche JOIN fiche_def USING (fd_id)) JOIN fiche_def_ref USING (frd_id)) JOIN jnt_fic_att_value USING (f_id)) JOIN attr_value USING (jft_id)) WHERE (jnt_fic_att_value.ad_id = 23)) a1 USING (f_id)) JOIN (SELECT jnt_fic_att_value.jft_id, fiche.f_id, fiche_def.frd_id, fiche.fd_id, fiche_def.fd_class_base, fiche_def.fd_label, fiche_def.fd_create_account, fiche_def_ref.frd_text, fiche_def_ref.frd_class_base, jnt_fic_att_value.ad_id, attr_value.av_text FROM ((((fiche JOIN fiche_def USING (fd_id)) JOIN fiche_def_ref USING (frd_id)) JOIN jnt_fic_att_value USING (f_id)) JOIN attr_value USING (jft_id)) WHERE (jnt_fic_att_value.ad_id = 5)) c USING (f_id)) JOIN (SELECT jnt_fic_att_value.jft_id, fiche.f_id, fiche_def.frd_id, fiche.fd_id, fiche_def.fd_class_base, fiche_def.fd_label, fiche_def.fd_create_account, fiche_def_ref.frd_text, fiche_def_ref.frd_class_base, jnt_fic_att_value.ad_id, attr_value.av_text FROM ((((fiche JOIN fiche_def USING (fd_id)) JOIN fiche_def_ref USING (frd_id)) JOIN jnt_fic_att_value USING (f_id)) JOIN attr_value USING (jft_id)) WHERE (jnt_fic_att_value.ad_id = 14)) d USING (f_id)) JOIN (SELECT jnt_fic_att_value.jft_id, fiche.f_id, fiche_def.frd_id, fiche.fd_id, fiche_def.fd_class_base, fiche_def.fd_label, fiche_def.fd_create_account, fiche_def_ref.frd_text, fiche_def_ref.frd_class_base, jnt_fic_att_value.ad_id, attr_value.av_text FROM ((((fiche JOIN fiche_def USING (fd_id)) JOIN fiche_def_ref USING (frd_id)) JOIN jnt_fic_att_value USING (f_id)) JOIN attr_value USING (jft_id)) WHERE (jnt_fic_att_value.ad_id = 15)) e USING (f_id)) JOIN (SELECT jnt_fic_att_value.jft_id, fiche.f_id, fiche_def.frd_id, fiche.fd_id, fiche_def.fd_class_base, fiche_def.fd_label, fiche_def.fd_create_account, fiche_def_ref.frd_text, fiche_def_ref.frd_class_base, jnt_fic_att_value.ad_id, attr_value.av_text FROM ((((fiche JOIN fiche_def USING (fd_id)) JOIN fiche_def_ref USING (frd_id)) JOIN jnt_fic_att_value USING (f_id)) JOIN attr_value USING (jft_id)) WHERE (jnt_fic_att_value.ad_id = 16)) f USING (f_id)) JOIN (SELECT jnt_fic_att_value.jft_id, fiche.f_id, fiche_def.frd_id, fiche.fd_id, fiche_def.fd_class_base, fiche_def.fd_label, fiche_def.fd_create_account, fiche_def_ref.frd_text, fiche_def_ref.frd_class_base, jnt_fic_att_value.ad_id, attr_value.av_text FROM ((((fiche JOIN fiche_def USING (fd_id)) JOIN fiche_def_ref USING (frd_id)) JOIN jnt_fic_att_value USING (f_id)) JOIN attr_value USING (jft_id)) WHERE (jnt_fic_att_value.ad_id = 17)) g USING (f_id)) LEFT JOIN (SELECT jnt_fic_att_value.jft_id, fiche.f_id, fiche_def.frd_id, fiche.fd_id, fiche_def.fd_class_base, fiche_def.fd_label, fiche_def.fd_create_account, fiche_def_ref.frd_text, fiche_def_ref.frd_class_base, jnt_fic_att_value.ad_id, attr_value.av_text FROM ((((fiche JOIN fiche_def USING (fd_id)) JOIN fiche_def_ref USING (frd_id)) JOIN jnt_fic_att_value USING (f_id)) JOIN attr_value USING (jft_id)) WHERE (jnt_fic_att_value.ad_id = 18)) h USING (f_id)) WHERE (a.frd_id = 9);
CREATE VIEW vw_fiche_attr AS
SELECT a.f_id, a.fd_id, a.av_text AS vw_name, b.av_text AS vw_sell, c.av_text AS vw_buy, d.av_text AS tva_code, tva_rate.tva_id, tva_rate.tva_rate, tva_rate.tva_label, e.av_text AS vw_addr, f.av_text AS vw_cp, j.av_text AS quick_code, fiche_def.frd_id FROM (((((((((SELECT fiche.f_id, fiche.fd_id, attr_value.av_text FROM (((fiche JOIN jnt_fic_att_value USING (f_id)) JOIN attr_value USING (jft_id)) JOIN attr_def USING (ad_id)) WHERE (jnt_fic_att_value.ad_id = 1)) a LEFT JOIN (SELECT fiche.f_id, attr_value.av_text FROM (((fiche JOIN jnt_fic_att_value USING (f_id)) JOIN attr_value USING (jft_id)) JOIN attr_def USING (ad_id)) WHERE (jnt_fic_att_value.ad_id = 6)) b ON ((a.f_id = b.f_id))) LEFT JOIN (SELECT fiche.f_id, attr_value.av_text FROM (((fiche JOIN jnt_fic_att_value USING (f_id)) JOIN attr_value USING (jft_id)) JOIN attr_def USING (ad_id)) WHERE (jnt_fic_att_value.ad_id = 7)) c ON ((a.f_id = c.f_id))) LEFT JOIN (SELECT fiche.f_id, attr_value.av_text FROM (((fiche JOIN jnt_fic_att_value USING (f_id)) JOIN attr_value USING (jft_id)) JOIN attr_def USING (ad_id)) WHERE (jnt_fic_att_value.ad_id = 2)) d ON ((a.f_id = d.f_id))) LEFT JOIN (SELECT fiche.f_id, attr_value.av_text FROM (((fiche JOIN jnt_fic_att_value USING (f_id)) JOIN attr_value USING (jft_id)) JOIN attr_def USING (ad_id)) WHERE (jnt_fic_att_value.ad_id = 14)) e ON ((a.f_id = e.f_id))) LEFT JOIN (SELECT fiche.f_id, attr_value.av_text FROM (((fiche JOIN jnt_fic_att_value USING (f_id)) JOIN attr_value USING (jft_id)) JOIN attr_def USING (ad_id)) WHERE (jnt_fic_att_value.ad_id = 15)) f ON ((a.f_id = f.f_id))) LEFT JOIN (SELECT fiche.f_id, attr_value.av_text FROM (((fiche JOIN jnt_fic_att_value USING (f_id)) JOIN attr_value USING (jft_id)) JOIN attr_def USING (ad_id)) WHERE (jnt_fic_att_value.ad_id = 23)) j ON ((a.f_id = j.f_id))) LEFT JOIN tva_rate ON ((d.av_text = (tva_rate.tva_id)::text))) JOIN fiche_def USING (fd_id));
CREATE VIEW vw_fiche_def AS
SELECT jnt_fic_attr.fd_id, jnt_fic_attr.ad_id, attr_def.ad_text, attr_value.av_text, fiche_def.fd_class_base, fiche_def.fd_label, fiche_def.fd_create_account, fiche_def.frd_id FROM (((((jnt_fic_att_value JOIN attr_value USING (jft_id)) JOIN fiche USING (f_id)) JOIN jnt_fic_attr USING (fd_id)) JOIN attr_def ON ((attr_def.ad_id = jnt_fic_attr.ad_id))) JOIN fiche_def USING (fd_id));
CREATE VIEW vw_fiche_min AS
SELECT attr_min.frd_id, attr_min.ad_id, attr_def.ad_text, fiche_def_ref.frd_text, fiche_def_ref.frd_class_base FROM ((attr_min JOIN attr_def USING (ad_id)) JOIN fiche_def_ref USING (frd_id));
CREATE VIEW vw_poste_qcode AS
SELECT a.f_id, a.av_text AS j_poste, b.av_text AS j_qcode FROM ((SELECT jnt_fic_att_value.f_id, attr_value.av_text FROM (attr_value JOIN jnt_fic_att_value USING (jft_id)) WHERE (jnt_fic_att_value.ad_id = 5)) a JOIN (SELECT jnt_fic_att_value.f_id, attr_value.av_text FROM (attr_value JOIN jnt_fic_att_value USING (jft_id)) WHERE (jnt_fic_att_value.ad_id = 23)) b USING (f_id));
-- comment
COMMENT ON VIEW vw_fiche_def IS 'all the attributs for card family';
-- Name: VIEW vw_fiche_min; Type: COMMENT; Schema: public; Owner: phpcompta
COMMENT ON VIEW vw_fiche_min IS 'minimum attribut for reference card';
create or replace function account_auto (p_fd_id fiche_def.fd_id%type)
returns bool
as
$$
-- account_auto
-- param fd_id
-- return true if the card generate automatically an account
declare
l_auto bool;
begin
select fd_create_account into l_auto from fiche_def where fd_id=p_fd_id;
if l_auto is null then
l_auto:=false;
end if;
return l_auto;
end;
$$ language plpgsql;
create or replace function account_compute(p_f_id fiche.f_id%type)
returns poste_comptable
as
$body$
-- account_compute
-- param f_id
-- compute the next account
-- return new account
declare
class_base poste_comptable;
maxcode int8;
begin
-- Get the class base
select fd_class_base into class_base
from
fiche_def join fiche using (fd_id)
where
f_id=p_f_id;
raise notice 'class base %',class_base;
select max(pcm_val) into maxcode from tmp_pcmn where pcm_val = class_base;
if maxcode = class_base then
maxcode=class_base*1000+1;
end if;
raise notice 'Max code %',maxcode;
return maxcode+1;
end;
$body$ language plpgsql;
create or replace function attribut_insert ( p_f_id integer, p_ad_id integer, p_value varchar)
returns void
as
$$
-- attribut_integer
-- parameter : f_id, ad_id, p_value
-- purpose add an attribute to a card
-- it inserts a row into jnt_fic_att_value and attr_value
declare
n_jft_id integer;
begin
select nextval('s_jnt_fic_att_value') into n_jft_id;
insert into jnt_fic_att_value (jft_id,f_id,ad_id) values (n_jft_id,p_f_id,p_ad_id);
insert into attr_value (jft_id,av_text) values (n_jft_id,p_value);
return;
end;
$$
language plpgsql volatile;
CREATE OR REPLACE FUNCTION account_insert(p_f_id fiche.f_id%type,p_account tmp_pcmn.pcm_val%type)
RETURNS int4 AS
$BODY$
declare
-- account_insert
-- parameter f_id,p_account label of account
-- purpose : create a new account for a card
-- check if the accound needs to be created automatically
-- if p_account is empty or null
-- into tables attr_value
nParent tmp_pcmn.pcm_val_parent%type;
sName varchar;
nNew tmp_pcmn.pcm_val%type;
bAuto bool;
nFd_id integer;
nCount integer;
begin
-- if p_value empty
if length(trim(p_account)) != 0 then
-- does the account exist ?
select * into nCount from tmp_pcmn where pcm_val=p_account;
if nCount !=0 then
-- retrieve name
select av_text into sName from
attr_value join jnt_fic_att_value using (jft_id)
where
ad_id=1 and f_id=p_f_id;
-- get parent
nParent:=account_parent(p_account);
-- account doesn't exist we need to add id
insert into tmp_pcmn(pcm_val,pcm_lib,pcm_val_parent)
values (p_account,sName,nParent);
-- insert as card's attribute
perform attribut_insert(p_f_id,5,to_char(nNew,'999999999999'));
end if;
else
select fd_id into nFd_id from fiche where f_id=p_f_id;
bAuto:= account_auto(nFd_id);
if bAuto = true then
-- create automatically the account
-- compute the next account
nNew:=account_compute(p_f_id);
raise debug 'nNew %', nNew;
-- retrieve name
select av_text into sName from
attr_value join jnt_fic_att_value using (jft_id)
where
ad_id=1 and f_id=p_f_id;
-- get parent
nParent:=account_parent(nNew);
-- account doesn't exist we need to add id
perform account_add (nNew,sName);
-- insert as card's attribute
perform attribut_insert(p_f_id,5,to_char(nNew,'999999999999'));
else
perform attribut_insert(p_f_id,5,null);
end if;
end if;
return 0;
end;
$BODY$
LANGUAGE 'plpgsql' VOLATILE;
create or replace function account_parent(p_account tmp_pcmn.pcm_val%type)
returns
-- account_parent
-- parameter pcm_val%type;
-- purpose compute the parent account
poste_comptable
as
$$
declare
nParent tmp_pcmn.pcm_val_parent%type;
sParent varchar;
nCount integer;
begin
sParent:=to_char(p_account,'9999999999999999');
sParent:=trim(sParent);
nParent:=0;
while nParent = 0 loop
select count(*) into nCount
from tmp_pcmn
where
pcm_val = to_number(sParent,'9999999999999999');
if nCount != 0 then
nParent:=to_number(sParent,'9999999999999999');
end if;
sParent:= substr(sParent,1,length(sParent)-1);
if length(sParent) <= 0 then
raise exception 'Impossible de trouver le compte parent pour %',p_account;
end if;
end loop;
return nParent;
end;
$$ language plpgsql volatile;
-- Function: account_update()
-- DROP FUNCTION account_update();
CREATE OR REPLACE FUNCTION account_update(p_f_id fiche.f_id%type,p_account tmp_pcmn.pcm_val%type)
RETURNS int4 AS
$BODY$
-- account_update
-- parameter f_id, pcm_val
-- purpose update the account of a card and create it into PCMN if it doesn't exist yet
--
declare
nMax fiche.f_id%type;
nCount integer;
nParent tmp_pcmn.pcm_val_parent%type;
sName varchar;
nJft_id attr_value.jft_id%type;
begin
-- if p_value empty
if length(trim(p_account)) != 0 then
-- does the account exist ?
select count(*) into nCount from tmp_pcmn where pcm_val=p_account;
if nCount = 0 then
-- retrieve name
select av_text into sName from
attr_value join jnt_fic_att_value using (jft_id)
where
ad_id=1 and f_id=p_f_id;
-- get parent
nParent:=fiche_account_parent(p_f_id);
-- account doesn't exist we need to add id
insert into tmp_pcmn(pcm_val,pcm_lib,pcm_val_parent) values (p_account,sName,nParent);
end if;
end if;
-- we retrieve jft_id
select jft_id into njft_id from jnt_fic_att_value where f_id=p_f_id and ad_id=5;
-- we update the account
update attr_value set av_text=p_account where jft_id=njft_id;
return njft_id;
end;
$BODY$
LANGUAGE 'plpgsql' VOLATILE;
create or replace function account_add (p_id tmp_pcmn.pcm_val%type,p_name varchar)
returns void
as
$$
-- account_add (p_id tmp_pcmn.pcm_val%type,p_name varchar)
-- parameter
-- p_id id of the account
-- name account's name
-- purpose insert a new account if it doesn't exist yet
declare
nParent tmp_pcmn.pcm_val_parent%type;
nCount integer;
begin
select count(*) into nCount from tmp_pcmn where pcm_val=p_id;
if nCount = 0 then
nParent=account_parent(p_id);
insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent)
values (p_id, p_name,nParent);
end if;
return;
end ;
$$ language plpgsql;
create table document_type (
dt_id serial primary key,
dt_value varchar(80)
);
comment on table document_type is 'Type of document : meeting, invoice,...';
CREATE or replace FUNCTION t_document_type_insert() RETURNS trigger AS $body$
BEGIN
execute 'create sequence seq_doc_type_'||NEW.dt_id;
raise notice 'Creating sequence seq_doc_type_%',NEW.dt_id;
RETURN NEW;
END;
$body$ LANGUAGE plpgsql;
CREATE TRIGGER trigger_document_type_i after INSERT oN document_type
FOR EACH ROW EXECUTE PROCEDURE t_document_type_insert();
INSERT INTO document_type VALUES (1,'Document Interne');
INSERT INTO document_type VALUES (2,'Bons de commande client');
INSERT INTO document_type VALUES (3,'Bon de commande Fournisseur');
INSERT INTO document_type VALUES (4,'Facture');
INSERT INTO document_type VALUES (5,'Lettre de rappel');
INSERT INTO document_type VALUES (6,'Courrier');
INSERT INTO document_type VALUES (7,'Proposition');
INSERT INTO document_type VALUES (8,'Email');
INSERT INTO document_type VALUES (9,'Divers');
alter sequence document_type_dt_id_seq restart with 10;
create table document_modele (
md_id serial primary key,
md_name text not null,
md_lob oid,
md_type integer not null ,
md_filename text,
md_mimetype text
);
comment on table document_modele is ' contains all the template for the documents';
alter table document_modele add constraint md_type foreign key (md_type) references document_type(dt_id);
create or replace function card_class_base(p_f_id fiche.f_id%type)
returns fiche_def.fd_class_base%type
as
$$
declare
n_poste fiche_def.fd_class_base%type;
begin
-- card_class_base (integer)
-- param: $1 fiche.f_id
-- purpose : retrieve the class of a card
--
select fd_class_base into n_poste from fiche_def join fiche using (fd_id)
where f_id=p_f_id;
if not FOUND then
raise exception 'Invalid fiche card_class_base(%)',p_f_id;
end if;
return n_poste;
end;
$$ language plpgsql;
-- fiche_account_parent
create or replace function fiche_account_parent(p_f_id integer)
returns poste_comptable as $$
declare
-- fiche_account_parent returns the fd_class_base
-- parameter f_id (from fiche)
ret poste_comptable;
begin
select fd_class_base into ret from fiche_def join fiche using (fd_id) where f_id=p_f_id;
if not FOUND then
raise exception '% N''existe pas',p_f_id;
end if;
return ret;
end;
$$
language plpgsql ;
delete from form where fo_fr_id=3000000;
delete from formdef where fr_id=3000000;
INSERT INTO formdef (fr_id, fr_label) VALUES (3000000, 'TVA déclaration Belge');
--
-- Data for TOC entry 2 (OID 315304)
-- Name: formdef; Type: TABLE DATA; Schema: public; Owner: dany
--
--
INSERT INTO form VALUES (3000398, 3000000, 1, 'Prestation [ case 03 ]', '[700%]-[7000005]');
INSERT INTO form VALUES (3000399, 3000000, 2, 'Prestation intra [ case 47 ]', '[7000005]');
INSERT INTO form VALUES (3000400, 3000000, 3, 'Tva due [case 54]', '[4513]+[4512]+[4511] FROM=01.2005');
INSERT INTO form VALUES (3000401, 3000000, 4, 'Marchandises, matière première et auxiliaire [case 81 ]', '[60%]');
INSERT INTO form VALUES (3000402, 3000000, 7, 'Service et bien divers [case 82]', '[61%]');
INSERT INTO form VALUES (3000403, 3000000, 8, 'bien d''invest [ case 83 ]', '[2400%]');
INSERT INTO form VALUES (3000404, 3000000, 9, 'TVA déductible [ case 59 ]', 'abs([4117]-[411%])');
INSERT INTO form VALUES (3000405, 3000000, 8, 'TVA non ded -> voiture', '[610022]*0.21/2');
INSERT INTO form VALUES (3000406, 3000000, 9, 'Acompte TVA', '[4117]');
-- create the table document
create table document
(
d_id serial primary key,
ag_id int4 not null,
d_lob oid,
d_number int8 not null,
d_filename text,
d_mimetype text
);
comment on table document is 'This table contains all the documents : summary and lob files';
create sequence document_seq;
comment on sequence document_seq is 'Sequence for the sequence bound to the document modele';
CREATE TABLE document_state (
s_id serial NOT NULL,
s_value character varying(50) NOT NULL
);
COMMENT ON TABLE document_state IS 'State of the document';
SELECT pg_catalog.setval(pg_catalog.pg_get_serial_sequence('document_state', 's_id'), 3, true);
INSERT INTO document_state VALUES (1, 'Envoyé');
INSERT INTO document_state VALUES (2, 'Brouillon');
INSERT INTO document_state VALUES (3, 'A envoyer');
INSERT INTO document_state VALUES (4, 'Reçu');
ALTER TABLE ONLY document_state ADD CONSTRAINT document_state_pkey PRIMARY KEY (s_id);
alter sequence s_attr_def restart with 24;
insert into attr_def (ad_text) values ('Ville');
insert into attr_min values(9,24);
insert into attr_min values(8,24);
insert into attr_min values(14,24);
-- upgrade all customer
insert into jnt_fic_attr select fd_id,24 from jnt_fic_attr join fiche_def using (fd_id) where frd_id=9 and ad_id=1;
-- supplier
insert into jnt_fic_attr select fd_id,24 from jnt_fic_attr join fiche_def using (fd_id) where frd_id=8 and ad_id=1;
-- administration
insert into jnt_fic_attr select fd_id,24 from jnt_fic_attr join fiche_def using (fd_id) where frd_id=9 and ad_id=14;
--
create table action_gestion (
ag_id serial primary key,
ag_type int4,
f_id_dest int4 not null,
f_id_exp int4 not null,
ag_title varchar(70),
ag_timestamp timestamp default now(),
ag_cal char(1) default 'C',
ag_ref_ag_id int4,
ag_comment text
);
comment on table action_gestion is 'Action for Managing';
-- add contact
alter sequence s_fiche_def_ref restart 16;
insert into fiche_def_ref(frd_text) values ('Contact');
insert into attr_def(ad_text) values ('Société');
insert into attr_def(ad_text) values ('Fax');
insert into attr_min values(16,1);
insert into attr_min values(16,17);
insert into attr_min values(16,18);
insert into attr_min values(16,25);
insert into attr_min values(16,26);
insert into attr_def (ad_text) values ('GSM');
insert into attr_min values(16,27);
CREATE or replace FUNCTION t_jrn_def_sequence() RETURNS trigger AS $body$
BEGIN
execute 'create sequence s_jrn_'||NEW.jrn_def_id;
raise notice 'Creating sequence s_jrn_%',NEW.jrn_def_id;
RETURN NEW;
END;
$body$ LANGUAGE plpgsql;
CREATE TRIGGER trigger_jrn_def_sequence_i after INSERT oN jrn_def
FOR EACH ROW EXECUTE PROCEDURE t_jrn_def_sequence();
create view vw_supplier as SELECT a.f_id, a.av_text AS name, a1.av_text AS quick_code, b.av_text AS tva_num, c.av_text AS poste_comptable, d.av_text AS rue, e.av_text AS code_postal, f.av_text AS pays, g.av_text AS telephone, h.av_text AS email
FROM ( SELECT jnt_fic_att_value.jft_id, fiche.f_id, fiche_def.frd_id, fiche.fd_id, fiche_def.fd_class_base, fiche_def.fd_label, fiche_def.fd_create_account, fiche_def_ref.frd_text, fiche_def_ref.frd_class_base, jnt_fic_att_value.ad_id, attr_value.av_text
FROM fiche
JOIN fiche_def USING (fd_id)
JOIN fiche_def_ref USING (frd_id)
JOIN jnt_fic_att_value USING (f_id)
JOIN attr_value USING (jft_id)
WHERE jnt_fic_att_value.ad_id = 1) a
JOIN ( SELECT jnt_fic_att_value.jft_id, fiche.f_id, fiche_def.frd_id, fiche.fd_id, fiche_def.fd_class_base, fiche_def.fd_label, fiche_def.fd_create_account, fiche_def_ref.frd_text, fiche_def_ref.frd_class_base, jnt_fic_att_value.ad_id, attr_value.av_text
FROM fiche
JOIN fiche_def USING (fd_id)
JOIN fiche_def_ref USING (frd_id)
JOIN jnt_fic_att_value USING (f_id)
JOIN attr_value USING (jft_id)
WHERE jnt_fic_att_value.ad_id = 13) b USING (f_id)
JOIN ( SELECT jnt_fic_att_value.jft_id, fiche.f_id, fiche_def.frd_id, fiche.fd_id, fiche_def.fd_class_base, fiche_def.fd_label, fiche_def.fd_create_account, fiche_def_ref.frd_text, fiche_def_ref.frd_class_base, jnt_fic_att_value.ad_id, attr_value.av_text
FROM fiche
JOIN fiche_def USING (fd_id)
JOIN fiche_def_ref USING (frd_id)
JOIN jnt_fic_att_value USING (f_id)
JOIN attr_value USING (jft_id)
WHERE jnt_fic_att_value.ad_id = 23) a1 USING (f_id)
JOIN ( SELECT jnt_fic_att_value.jft_id, fiche.f_id, fiche_def.frd_id, fiche.fd_id, fiche_def.fd_class_base, fiche_def.fd_label, fiche_def.fd_create_account, fiche_def_ref.frd_text, fiche_def_ref.frd_class_base, jnt_fic_att_value.ad_id, attr_value.av_text
FROM fiche
JOIN fiche_def USING (fd_id)
JOIN fiche_def_ref USING (frd_id)
JOIN jnt_fic_att_value USING (f_id)
JOIN attr_value USING (jft_id)
WHERE jnt_fic_att_value.ad_id = 5) c USING (f_id)
JOIN ( SELECT jnt_fic_att_value.jft_id, fiche.f_id, fiche_def.frd_id, fiche.fd_id, fiche_def.fd_class_base, fiche_def.fd_label, fiche_def.fd_create_account, fiche_def_ref.frd_text, fiche_def_ref.frd_class_base, jnt_fic_att_value.ad_id, attr_value.av_text
FROM fiche
JOIN fiche_def USING (fd_id)
JOIN fiche_def_ref USING (frd_id)
JOIN jnt_fic_att_value USING (f_id)
JOIN attr_value USING (jft_id)
WHERE jnt_fic_att_value.ad_id = 14) d USING (f_id)
JOIN ( SELECT jnt_fic_att_value.jft_id, fiche.f_id, fiche_def.frd_id, fiche.fd_id, fiche_def.fd_class_base, fiche_def.fd_label, fiche_def.fd_create_account, fiche_def_ref.frd_text, fiche_def_ref.frd_class_base, jnt_fic_att_value.ad_id, attr_value.av_text
FROM fiche
JOIN fiche_def USING (fd_id)
JOIN fiche_def_ref USING (frd_id)
JOIN jnt_fic_att_value USING (f_id)
JOIN attr_value USING (jft_id)
WHERE jnt_fic_att_value.ad_id = 15) e USING (f_id)
JOIN ( SELECT jnt_fic_att_value.jft_id, fiche.f_id, fiche_def.frd_id, fiche.fd_id, fiche_def.fd_class_base, fiche_def.fd_label, fiche_def.fd_create_account, fiche_def_ref.frd_text, fiche_def_ref.frd_class_base, jnt_fic_att_value.ad_id, attr_value.av_text
FROM fiche
JOIN fiche_def USING (fd_id)
JOIN fiche_def_ref USING (frd_id)
JOIN jnt_fic_att_value USING (f_id)
JOIN attr_value USING (jft_id)
WHERE jnt_fic_att_value.ad_id = 16) f USING (f_id)
JOIN ( SELECT jnt_fic_att_value.jft_id, fiche.f_id, fiche_def.frd_id, fiche.fd_id, fiche_def.fd_class_base, fiche_def.fd_label, fiche_def.fd_create_account, fiche_def_ref.frd_text, fiche_def_ref.frd_class_base, jnt_fic_att_value.ad_id, attr_value.av_text
FROM fiche
JOIN fiche_def USING (fd_id)
JOIN fiche_def_ref USING (frd_id)
JOIN jnt_fic_att_value USING (f_id)
JOIN attr_value USING (jft_id)
WHERE jnt_fic_att_value.ad_id = 17) g USING (f_id)
LEFT JOIN ( SELECT jnt_fic_att_value.jft_id, fiche.f_id, fiche_def.frd_id, fiche.fd_id, fiche_def.fd_class_base, fiche_def.fd_label, fiche_def.fd_create_account, fiche_def_ref.frd_text, fiche_def_ref.frd_class_base, jnt_fic_att_value.ad_id, attr_value.av_text
FROM fiche
JOIN fiche_def USING (fd_id)
JOIN fiche_def_ref USING (frd_id)
JOIN jnt_fic_att_value USING (f_id)
JOIN attr_value USING (jft_id)
WHERE jnt_fic_att_value.ad_id = 18) h USING (f_id)
WHERE a.frd_id = 8;
insert into parameter (pr_id) values ('MY_TEL');
insert into parameter (pr_id) values ('MY_PAYS');
insert into parameter (pr_id) values ('MY_FAX');
alter table document add d_state int;
alter table action_gestion add ag_ref text;
create unique index k_ag_ref on action_gestion(ag_ref);
update version set val=14;
insert into action values(28,'Module Suivi Document');
insert into action values(22,'Module Client');
insert into action values (24,'Module Fournisseur');
insert into action values (26,'Module Administration');
insert into action values (30,'Module Gestion');
insert into format_csv_banque values ('Argenta Belgique','argenta_be.inc.php');
insert into format_csv_banque values ('CBC Belgique','cbc_be.inc.php');
CREATE SEQUENCE s_cbc
INCREMENT BY 1
NO MAXVALUE
NO MINVALUE
CACHE 1;
commit;

View file

@ -0,0 +1,45 @@
begin;
alter table import_tmp add column status varchar(1);
alter table import_tmp alter status set default 'n';
create or replace function trim_cvs_quote() returns trigger as $trim$
declare
modified import_tmp%ROWTYPE;
begin
modified:=NEW;
modified.devise=replace(new.devise,'"','');
modified.poste_comptable=replace(new.poste_comptable,'"','');
modified.compte_ordre=replace(NEW.COMPTE_ORDRE,'"','');
modified.detail=replace(NEW.DETAIL,'"','');
modified.num_compte=replace(NEW.NUM_COMPTE,'"','');
return modified;
end;
$trim$ language plpgsql;
update import_tmp set status = 't' where ok=true;
update import_tmp set status = 'n' where ok = false;
update import_tmp set status = 'n' where ok is null;
alter table import_tmp add constraint chk_status check (status in ('n','w','d','t'));
alter table import_tmp drop column ok ;
comment on table import_tmp is 'Table temporaire pour l''importation des banques en format CSV';
comment on column import_tmp.status is 'Status doit être w pour en attente, t pour transfèrer ou d à effacer';
create or replace function trim_cvs_quote() returns trigger as $trim$
declare
modified import_tmp%ROWTYPE;
begin
modified:=NEW;
modified.devise=replace(new.devise,'"','');
modified.poste_comptable=replace(new.poste_comptable,'"','');
modified.compte_ordre=replace(NEW.COMPTE_ORDRE,'"','');
modified.detail=replace(NEW.DETAIL,'"','');
modified.num_compte=replace(NEW.NUM_COMPTE,'"','');
return modified;
end;
$trim$ language plpgsql;
update version set val=15;
commit;

View file

@ -0,0 +1,4 @@
begin;
update attr_def set ad_text='code postal' where ad_id=15;
update version set val=16;
commit;

View file

@ -0,0 +1,25 @@
begin;
create or replace function card_class_base(p_f_id fiche.f_id%type)
returns fiche_def.fd_class_base%type
as
$$
declare
n_poste fiche_def.fd_class_base%type;
begin
-- card_class_base (integer)
-- param: $1 fiche.f_id
-- purpose : retrieve the class of a card
--
select fd_class_base into n_poste from fiche_def join fiche using
(fd_id)
where f_id=p_f_id;
if not FOUND then
raise exception 'Invalid fiche card_class_base(%)',p_f_id;
end if;
return n_poste;
end;
$$ language plpgsql;
update version set val=17;
commit;

View file

@ -0,0 +1,14 @@
begin;
-- add quick code for contact
insert into attr_min (frd_id,ad_id) values (16,23);
insert into jnt_fic_attr select fd_id,23 from fiche_Def where frd_id=16;
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
where fd_id in (select fd_id from fiche_Def where frd_id=16);
insert into attr_value select jft_id,'FID'||f_id from jnt_fic_att_value join fiche using(f_id) where ad_id=23 and
fd_id in (select fd_id from fiche_Def where frd_id=16);
update version set val=18;
commit;

View file

@ -0,0 +1,5 @@
begin;
alter table parm_periode drop constraint parm_periode_p_start_key;
update version set val=19;
commit;

View file

@ -0,0 +1,181 @@
begin;
-- bug 1753
create or replace function correct_sequence ( p_sequence text,p_col text, p_table text )
returns integer
as
$body$
declare
-- fonction description
-- Often the primary key is a sequence number and sometimes
-- the value of the sequence is not synchronized with the
-- primary key
-- parameter p_sequence : sequence name
-- parameter p_col : col of the pk
-- parameter p_table : concerned table
-- variable
-- last value of the sequence
last_sequence int8;
-- max value of the pk
max_sequence int8;
-- n integer
n integer;
begin
-- the sequence exist ?
select count(*) into n from pg_class where relkind='S' and relname=lower(p_sequence);
if n = 0 then
raise exception ' Unknow sequence % ',p_sequence;
end if;
select count(*) into n from pg_class where relkind='r' and relname=lower(p_table);
if n = 0 then
raise exception ' Unknow table % ',p_table;
end if;
execute 'select last_value from '||p_sequence into last_sequence;
raise notice 'Last value of the sequence is %', last_sequence;
execute 'select max('||p_col||') from '||p_table into max_sequence;
if max_sequence is null then
max_sequence := 0;
end if;
raise notice 'Max value of the sequence is %', max_sequence;
max_sequence:= max_sequence +1;
execute 'alter sequence '||p_sequence||' restart with '||max_sequence;
return 0;
end;
$body$ language plpgsql;
comment on function correct_sequence (text,text,text) is ' Often the primary key is a sequence number and sometimes the value of the sequence is not synchronized with the primary key ( p_sequence : sequence name, p_col : col of the pk,p_table : concerned table';
commit;
begin;
select correct_sequence('s_jnt_fic_att_value','jft_id','jnt_fic_att_value');
-- bug 17544
-- add a pk to the table jnt_fic_attr
alter table jnt_fic_attr add jnt_id int8;
create sequence s_jnt_id;
alter table jnt_fic_attr alter jnt_id set default nextval('s_jnt_id');
update jnt_fic_attr set jnt_id=nextval('s_jnt_id');
alter table jnt_fic_attr add constraint pk_jnt_fic_attr primary key (jnt_id);
-- remove duplicate attr
delete from jnt_fic_attr where jnt_id in ( select a.jnt_id from jnt_fic_attr a join jnt_fic_attr b on (a.fd_id=b.fd_id and a.ad_id=b.ad_id) where a.jnt_id > b.jnt_id);
-- bug 17543
--account_compute
CREATE or replace FUNCTION account_parent(p_account poste_comptable) RETURNS poste_comptable
AS $$
declare
nParent tmp_pcmn.pcm_val_parent%type;
sParent varchar;
nCount integer;
begin
sParent:=to_char(p_account,'9999999999999999');
sParent:=trim(sParent);
nParent:=0;
while nParent = 0 loop
select count(*) into nCount
from tmp_pcmn
where
pcm_val = to_number(sParent,'9999999999999999');
if nCount != 0 then
nParent:=to_number(sParent,'9999999999999999');
end if;
sParent:= substr(sParent,1,length(sParent)-1);
if length(sParent) <= 0 then
raise exception 'Impossible de trouver le compte parent pour %',p_account;
end if;
end loop;
raise notice 'account_parent : Parent is %',nParent;
return nParent;
end;
$$
LANGUAGE plpgsql;
commit;
CREATE or replace FUNCTION account_compute(p_f_id integer) RETURNS poste_comptable
AS $$
declare
class_base poste_comptable;
maxcode int8;
begin
select fd_class_base into class_base
from
fiche_def join fiche using (fd_id)
where
f_id=p_f_id;
raise notice 'account_compute class base %',class_base;
select max(pcm_val) into maxcode from tmp_pcmn where pcm_val_parent = class_base;
if maxcode = class_base then
maxcode:=class_base*1000;
end if;
maxcode:=maxcode+1;
raise notice 'account_compute Max code %',maxcode;
return maxcode;
end;
$$
LANGUAGE plpgsql;
--
-- Name: account_insert(integer, poste_comptable); Type: FUNCTION; Schema: public; Owner: phpcompta
--
CREATE or replace FUNCTION account_insert(p_f_id integer, p_account poste_comptable) RETURNS integer
AS $$
declare
nParent tmp_pcmn.pcm_val_parent%type;
sName varchar;
nNew tmp_pcmn.pcm_val%type;
bAuto bool;
nFd_id integer;
nCount integer;
begin
if length(trim(p_account)) != 0 then
raise notice 'p_account is not empty';
select * into nCount from tmp_pcmn where pcm_val=p_account;
if nCount !=0 then
raise notice 'this account exists in tmp_pcmn ';
select av_text into sName from
attr_value join jnt_fic_att_value using (jft_id)
where
ad_id=1 and f_id=p_f_id;
nParent:=account_parent(p_account);
insert into tmp_pcmn(pcm_val,pcm_lib,pcm_val_parent)
values (p_account,sName,nParent);
perform attribut_insert(p_f_id,5,to_char(nNew,'999999999999'));
end if;
else
raise notice 'p_account is empty';
select fd_id into nFd_id from fiche where f_id=p_f_id;
bAuto:= account_auto(nFd_id);
if bAuto = true then
raise notice 'account generated automatically';
nNew:=account_compute(p_f_id);
raise notice 'nNew %', nNew;
select av_text into sName from
attr_value join jnt_fic_att_value using (jft_id)
where
ad_id=1 and f_id=p_f_id;
nParent:=account_parent(nNew);
perform account_add (nNew,sName);
perform attribut_insert(p_f_id,5,to_char(nNew,'999999999999'));
else
perform attribut_insert(p_f_id,5,null);
end if;
end if;
return 0;
end;
$$
LANGUAGE plpgsql;
update version set val=20;
commit;

View file

@ -0,0 +1,125 @@
begin;
CREATE or replace FUNCTION insert_quant_sold
(p_internal text,
p_fiche character varying,
p_quant integer,
p_price numeric,
p_vat numeric,
p_vat_code integer,
p_client character varying)
RETURNS void
AS
$body$
declare
fid_client integer;
fid_good integer;
begin
select f_id into fid_client from
attr_value join jnt_fic_att_value using (jft_id) where ad_id=23 and av_text=upper(p_client);
select f_id into fid_good from
attr_value join jnt_fic_att_value using (jft_id) where ad_id=23 and av_text=upper(p_fiche);
insert into quant_sold
(qs_internal,qs_fiche,qs_quantite,qs_price,qs_vat,qs_vat_code,qs_client)
values
(p_internal,fid_good,p_quant,p_price,p_vat,p_vat_code,fid_client);
return;
end;
$body$ LANGUAGE plpgsql;
-- add quick code for contact
insert into attr_min (frd_id,ad_id)
select distinct 16,23
from attr_min
where not exists (select * from attr_min where ad_id=23 and frd_id=16);
insert into jnt_fic_attr (fd_id,ad_id)
select fd_id,23 from fiche_def where frd_id=16
and not exists (select *
from jnt_fic_attr join fiche_def using (fd_id)
where frd_id=16 and ad_id=23);
CREATE or replace FUNCTION update_quick_code(njft_id integer, tav_text text) RETURNS integer
AS $body$
declare
ns integer;
nExist integer;
tText text;
old_qcode varchar;
begin
-- get current value
select av_text into old_qcode from attr_value where jft_id=njft_id;
-- av_text didn't change so no update
if tav_text = upper( trim(old_qcode)) then
return 0;
end if;
tText := trim(upper(tav_text));
tText := replace(tText,' ','');
if length ( tText) = 0 or tText is null then
return 0;
end if;
ns := njft_id;
loop
-- av_text already used ?
select count(*) into nExist
from jnt_fic_att_value join attr_value using (jft_id)
where
ad_id=23 and av_text=tText;
if nExist = 0 then
exit;
end if;
if tText = 'FID'||ns then
-- take the next sequence
select nextval('s_jnt_fic_att_value') into ns;
end if;
tText :='FID'||ns;
end loop;
update attr_value set av_text = tText where jft_id=njft_id;
-- update also the contact
update attr_value set av_text = tText
where jft_id in
( select jft_id
from jnt_fic_att_value join attr_value using (jft_id)
where ad_id=25 and av_text=old_qcode);
update jrnx set j_qcode=tText where j_qcode = old_qcode;
return ns;
end;
$body$
LANGUAGE plpgsql;
update parm_periode set p_end = p_start where p_end is null;
alter table parm_periode alter p_end set not null;
create or replace function drop_it (p_constraint varchar)
returns void as
$body$
declare
-- drop a constraint if it exists
nCount integer;
begin
select count(*) into nCount from pg_constraint where conname=p_constraint;
if nCount = 1 then
execute 'alter table parm_periode drop constraint '||p_constraint ;
end if;
end;
$body$ language plpgsql;
select drop_it('parm_periode_p_start_key');
create unique index x_periode on parm_periode (p_start,p_end);
update version set val=21;
commit;

View file

@ -0,0 +1,14 @@
begin;
alter table import_tmp add jr_rapt text;
delete from jnt_fic_attr
where jnt_id in (
select a.jnt_id
from jnt_fic_attr as a join jnt_fic_attr as b
on (a.fd_id=b.fd_id and a.ad_id=b.ad_id)
where b.jnt_id > a.jnt_id);
create unique index fd_id_ad_id_x on jnt_fic_attr( fd_id,ad_id);
update version set val=22;
commit;

View file

@ -0,0 +1,88 @@
begin;
create or replace function account_insert (p_f_id integer, p_account poste_comptable)
RETURNS int4 AS
$body$
declare
nParent tmp_pcmn.pcm_val_parent%type;
sName varchar;
nNew tmp_pcmn.pcm_val%type;
bAuto bool;
nFd_id integer;
nCount integer;
begin
if length(trim(p_account)) != 0 then
raise notice 'p_account is not empty';
select * into nCount from tmp_pcmn where pcm_val=p_account;
if nCount !=0 then
raise notice 'this account exists in tmp_pcmn ';
perform attribut_insert(p_f_id,5,to_char(p_account,'999999999999'));
else
-- account doesn't exist, create it
select av_text into sName from
attr_value join jnt_fic_att_value using (jft_id)
where
ad_id=1 and f_id=p_f_id;
nParent:=account_parent(p_account);
insert into tmp_pcmn(pcm_val,pcm_lib,pcm_val_parent)
values (p_account,sName,nParent);
perform attribut_insert(p_f_id,5,to_char(nNew,'999999999999'));
end if;
else
raise notice 'p_account is empty';
select fd_id into nFd_id from fiche where f_id=p_f_id;
bAuto:= account_auto(nFd_id);
if bAuto = true then
raise notice 'account generated automatically';
nNew:=account_compute(p_f_id);
raise notice 'nNew %', nNew;
select av_text into sName from
attr_value join jnt_fic_att_value using (jft_id)
where
ad_id=1 and f_id=p_f_id;
nParent:=account_parent(nNew);
perform account_add (nNew,sName);
perform attribut_insert(p_f_id,5,to_char(nNew,'999999999999'));
else
perform attribut_insert(p_f_id,5,null);
end if;
end if;
return 0;
end;
$body$
LANGUAGE 'plpgsql' VOLATILE;
-- Function: attribut_insert(p_f_id int4, p_ad_id int4, p_value "varchar")
-- DROP FUNCTION attribut_insert(p_f_id int4, p_ad_id int4, p_value "varchar");
CREATE OR REPLACE FUNCTION attribut_insert(p_f_id int4, p_ad_id int4, p_value "varchar")
RETURNS void AS
$BODY$
declare
n_jft_id integer;
begin
select nextval('s_jnt_fic_att_value') into n_jft_id;
insert into jnt_fic_att_value (jft_id,f_id,ad_id) values (n_jft_id,p_f_id,p_ad_id);
insert into attr_value (jft_id,av_text) values (n_jft_id,trim(p_value));
return;
end;
$BODY$ LANGUAGE 'plpgsql' VOLATILE;
update attr_value set av_text=trim(av_text);
update jrnx set j_qcode = B.av_text from
(select f_id,av_text from attr_value join jnt_fic_att_value using (jft_id)
where ad_id=5) as A
join ( select f_id,av_text from attr_value join jnt_fic_att_value using (jft_id)
where ad_id=23) as B using(f_id) where j_poste=a.av_text;
update jrnx set j_qcode = upper(j_qcode);
update version set val=23;
commit;

View file

@ -0,0 +1,40 @@
begin;
delete from jnt_fic_attr where jnt_id in ( select a.jnt_id from jnt_fic_attr a join jnt_fic_attr b using (fd_id, ad_id) where a.jnt_id > b.jnt_id);
alter table quant_sold alter qs_quantite type numeric(20,4);
drop fUNCTION public.insert_quant_sold(p_internal text, p_fiche character varying, p_quant integer, p_price numeric,
p_vat numeric, p_vat_code integer, p_client character varying) ;
CREATE FUNCTION insert_quant_sold(
p_internal text,
p_fiche character varying,
p_quant numeric,
p_price numeric,
p_vat numeric,
p_vat_code integer,
p_client character varying) RETURNS void
AS $$
declare
fid_client integer;
fid_good integer;
begin
select f_id into fid_client from
attr_value join jnt_fic_att_value using (jft_id) where ad_id=23 and av_text=upper(p_client);
select f_id into fid_good from
attr_value join jnt_fic_att_value using (jft_id) where ad_id=23 and av_text=upper(p_fiche);
insert into quant_sold
(qs_internal,qs_fiche,qs_quantite,qs_price,qs_vat,qs_vat_code,qs_client)
values
(p_internal,fid_good,p_quant,p_price,p_vat,p_vat_code,fid_client);
return;
end;
$$
LANGUAGE plpgsql;
update version set val=24;
commit;

View file

@ -0,0 +1,7 @@
begin;
delete from attr_min where ad_id=5;
update version set val=25;
commit;

View file

@ -0,0 +1,67 @@
begin;
create or replace function account_insert (p_f_id integer, p_account poste_comptable)
RETURNS int4 AS
$body$
declare
nParent tmp_pcmn.pcm_val_parent%type;
sName varchar;
nNew tmp_pcmn.pcm_val%type;
bAuto bool;
nFd_id integer;
nCount integer;
begin
if length(trim(p_account)) != 0 then
raise notice 'p_account is not empty';
select * into nCount from tmp_pcmn where pcm_val=p_account;
if nCount !=0 then
raise notice 'this account exists in tmp_pcmn ';
perform attribut_insert(p_f_id,5,to_char(p_account,'999999999999999999999999'));
else
-- account doesn't exist, create it
select av_text into sName from
attr_value join jnt_fic_att_value using (jft_id)
where
ad_id=1 and f_id=p_f_id;
nParent:=account_parent(p_account);
insert into tmp_pcmn(pcm_val,pcm_lib,pcm_val_parent)
values (p_account,sName,nParent);
perform attribut_insert(p_f_id,5,to_char(nNew,'999999999999999999999999'));
end if;
else
raise notice 'p_account is empty';
select fd_id into nFd_id from fiche where f_id=p_f_id;
bAuto:= account_auto(nFd_id);
if bAuto = true then
raise notice 'account generated automatically';
nNew:=account_compute(p_f_id);
raise notice 'nNew %', nNew;
select av_text into sName from
attr_value join jnt_fic_att_value using (jft_id)
where
ad_id=1 and f_id=p_f_id;
nParent:=account_parent(nNew);
perform account_add (nNew,sName);
perform attribut_insert(p_f_id,5,to_char(nNew,'999999999999999999999999'));
else
-- if there is an account_base then it is the default
select fd_class_base into nNew from fiche_def join fiche using (fd_id) where f_id=p_f_id;
if nNew is null or length(trim(nNew)) = 0 then
raise notice 'count is null';
perform attribut_insert(p_f_id,5,null);
else
perform attribut_insert(p_f_id,5,to_char(nNew,'999999999999999999999999'));
end if;
end if;
end if;
return 0;
end;
$body$
LANGUAGE 'plpgsql' VOLATILE;
update version set val=26;
commit;

View file

@ -0,0 +1,94 @@
begin;
CREATE or replace FUNCTION account_compute(p_f_id integer) RETURNS poste_comptable
AS $$
declare
class_base poste_comptable;
maxcode poste_comptable;
begin
select fd_class_base into class_base
from
fiche_def join fiche using (fd_id)
where
f_id=p_f_id;
raise notice 'account_compute class base %',class_base;
select count (pcm_val) into maxcode from tmp_pcmn where pcm_val_parent = class_base;
if maxcode = 0 then
maxcode:=class_base;
else
select max (pcm_val) into maxcode from tmp_pcmn where pcm_val_parent = class_base;
end if;
if maxcode = class_base then
maxcode:=class_base*1000;
end if;
maxcode:=maxcode+1;
raise notice 'account_compute Max code %',maxcode;
return maxcode;
end;
$$
LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION account_insert(p_f_id integer, p_account poste_comptable) RETURNS integer
AS $$
declare
nParent tmp_pcmn.pcm_val_parent%type;
sName varchar;
nNew tmp_pcmn.pcm_val%type;
bAuto bool;
nFd_id integer;
nCount integer;
begin
if length(trim(p_account)) != 0 then
raise notice 'p_account is not empty';
select * into nCount from tmp_pcmn where pcm_val=p_account;
if nCount !=0 then
raise notice 'this account exists in tmp_pcmn ';
perform attribut_insert(p_f_id,5,to_char(p_account,'999999999999999999999999'));
else
-- account doesn't exist, create it
select av_text into sName from
attr_value join jnt_fic_att_value using (jft_id)
where
ad_id=1 and f_id=p_f_id;
nParent:=account_parent(p_account);
insert into tmp_pcmn(pcm_val,pcm_lib,pcm_val_parent) values (p_account,sName,nParent);
perform attribut_insert(p_f_id,5,to_char(p_account,'999999999999999999999999'));
end if;
else
raise notice 'p_account is empty';
select fd_id into nFd_id from fiche where f_id=p_f_id;
bAuto:= account_auto(nFd_id);
if bAuto = true then
raise notice 'account generated automatically';
nNew:=account_compute(p_f_id);
raise notice 'nNew %', nNew;
select av_text into sName from
attr_value join jnt_fic_att_value using (jft_id)
where
ad_id=1 and f_id=p_f_id;
nParent:=account_parent(nNew);
perform account_add (nNew,sName);
perform attribut_insert(p_f_id,5,to_char(nNew,'999999999999999999999999'));
else
-- if there is an account_base then it is the default
select fd_class_base into nNew from fiche_def join fiche using (fd_id) where f_id=p_f_id;
if nNew is null or length(trim(nNew)) = 0 then
raise notice 'count is null';
perform attribut_insert(p_f_id,5,null);
else
perform attribut_insert(p_f_id,5,to_char(nNew,'999999999999999999999999'));
end if;
end if;
end if;
return 0;
end;
$$
LANGUAGE plpgsql;
update version set val=27;
commit;

View file

@ -0,0 +1,8 @@
begin;
insert into format_csv_banque values ('Dexia','dexia_be.inc.php');
alter table stock_goods alter sg_quantity type numeric(8,4);
alter table stock_goods add sg_comment varchar(80);
alter table stock_goods add sg_exercice varchar(4);
update version set val=28;
commit;

View file

@ -0,0 +1,14 @@
begin;
delete from user_sec_act where ua_act_id in (2,9,19,18);
delete from action where ac_id=2;
delete from action where ac_id=9;
delete from action where ac_id=19;
delete from action where ac_id=18;
update action set ac_description='Lecture du Grand-Livre' where ac_id=1;
insert into action values (31,'Gestion des périodes comptables');
update action set ac_description = 'Lecture des fiches' where ac_id=3;
update action set ac_description = 'Ajout de fiche et modification' where ac_id=15;
update action set ac_description = 'Création et modifications des rapports' where ac_id=5;
update version set val=29;
commit;

View file

@ -0,0 +1,31 @@
begin;
CREATE or REPLACE FUNCTION account_update(p_f_id integer, p_account poste_comptable) RETURNS integer
AS $$
declare
nMax fiche.f_id%type;
nCount integer;
nParent tmp_pcmn.pcm_val_parent%type;
sName varchar;
nJft_id attr_value.jft_id%type;
begin
if length(trim(p_account)) != 0 then
select count(*) into nCount from tmp_pcmn where pcm_val=p_account;
if nCount = 0 then
select av_text into sName from
attr_value join jnt_fic_att_value using (jft_id)
where
ad_id=1 and f_id=p_f_id;
nParent:=account_parent(p_account);
insert into tmp_pcmn(pcm_val,pcm_lib,pcm_val_parent) values (p_account,sName,nParent);
end if;
end if;
select jft_id into njft_id from jnt_fic_att_value where f_id=p_f_id and ad_id=5;
update attr_value set av_text=p_account where jft_id=njft_id;
return njft_id;
end;
$$
LANGUAGE plpgsql;
update version set val=30;
commit;

View file

@ -0,0 +1,14 @@
begin ;
alter table jrn_action drop constraint "$1";
alter table jrn_def drop constraint "$1";
update jrn_action set ja_jrn_type='ODS' where ja_jrn_type='OD ';
update jrn_def set jrn_def_type='ODS' where jrn_def_type = 'OD ';
update jrn_type set jrn_type_id='ODS' where jrn_type_id ='OD ';
alter table jrn_action add constraint "$1" foreign key (ja_jrn_type) references jrn_type(jrn_type_id);
alter table jrn_def add constraint "$1" FOREIGN KEY (jrn_def_type) REFERENCES jrn_type(jrn_type_id);
update version set val=31;
commit;

View file

@ -0,0 +1,613 @@
begin ;
CREATE or replace FUNCTION insert_quant_sold(
p_internal text,
p_jid numeric,
p_fiche character varying,
p_quant numeric,
p_price numeric,
p_vat numeric,
p_vat_code integer,
p_client character varying)
RETURNS void
AS $$
declare
fid_client integer;
fid_good integer;
begin
select f_id into fid_client from
attr_value join jnt_fic_att_value using (jft_id) where ad_id=23 and av_text=upper(p_client);
select f_id into fid_good from
attr_value join jnt_fic_att_value using (jft_id) where ad_id=23 and av_text=upper(p_fiche);
insert into quant_sold
(qs_internal,j_id,qs_fiche,qs_quantite,qs_price,qs_vat,qs_vat_code,qs_client,qs_valid)
values
(p_internal,p_jid,fid_good,p_quant,p_price,p_vat,p_vat_code,fid_client,'Y');
return;
end;
$$
LANGUAGE plpgsql;
CREATE or REPLACE FUNCTION account_update(p_f_id integer, p_account poste_comptable) RETURNS integer
AS $$
declare
nMax fiche.f_id%type;
nCount integer;
nParent tmp_pcmn.pcm_val_parent%type;
sName varchar;
nJft_id attr_value.jft_id%type;
begin
if length(trim(p_account)) != 0 then
select count(*) into nCount from tmp_pcmn where pcm_val=p_account;
if nCount = 0 then
select av_text into sName from
attr_value join jnt_fic_att_value using (jft_id)
where
ad_id=1 and f_id=p_f_id;
nParent:=account_parent(p_account);
insert into tmp_pcmn(pcm_val,pcm_lib,pcm_val_parent) values (p_account,sName,nParent);
end if;
end if;
select jft_id into njft_id from jnt_fic_att_value where f_id=p_f_id and ad_id=5;
update attr_value set av_text=p_account where jft_id=njft_id;
return njft_id;
end;
$$
LANGUAGE plpgsql;
CREATE TABLE quant_purchase (
qp_id integer DEFAULT nextval(('s_quantity'::text)::regclass) NOT NULL,
qp_internal text NOT NULL,
j_id integer not null,
qp_fiche integer NOT NULL,
qp_quantite numeric(20,4) NOT NULL,
qp_price numeric(20,4),
qp_vat numeric(20,4) default 0.0,
qp_vat_code integer,
qp_nd_amount numeric(20,4) default 0.0,
qp_nd_tva numeric(20,4) default 0.0,
qp_nd_tva_recup numeric(20,4) default 0.0,
qp_supplier integer NOT NULL,
qp_valid char(1) default 'Y' not null
);
ALTER TABLE ONLY quant_purchase
ADD CONSTRAINT qp_id_pk PRIMARY KEY (qp_id);
ALTER TABLE ONLY quant_purchase
ADD CONSTRAINT quant_purchase_j_id_fkey FOREIGN KEY (j_id) REFERENCES jrnx(j_id) ON UPDATE CASCADE ON DELETE CASCADE;
---
truncate quant_sold;
alter table quant_sold ADD qs_valid char(1) ;
alter table quant_sold add j_id integer;
alter table quant_sold alter j_id set not null;
ALTER TABLE ONLY quant_sold
ADD CONSTRAINT quant_sold_j_id_fkey FOREIGN KEY (j_id) REFERENCES jrnx(j_id) ON UPDATE CASCADE ON DELETE CASCADE;
update quant_sold set qs_valid='Y';
alter table quant_sold alter qs_valid set default 'Y';
alter table quant_sold alter qs_valid set not null;
CREATE or replace FUNCTION insert_quant_purchase
(p_internal text,
p_j_id numeric,
p_fiche character varying,
p_quant numeric,
p_price numeric,
p_vat numeric,
p_vat_code integer,
p_nd_amount numeric,
p_nd_tva numeric,
p_nd_tva_recup numeric,
p_client character varying) RETURNS void
AS $$
declare
fid_client integer;
fid_good integer;
begin
select f_id into fid_client from
attr_value join jnt_fic_att_value using (jft_id) where ad_id=23 and av_text=upper(p_client);
select f_id into fid_good from
attr_value join jnt_fic_att_value using (jft_id) where ad_id=23 and av_text=upper(p_fiche);
insert into quant_purchase
(qp_internal,
j_id,
qp_fiche,
qp_quantite,
qp_price,
qp_vat,
qp_vat_code,
qp_nd_amount,
qp_nd_tva,
qp_nd_tva_recup,
qp_supplier)
values
(p_internal,
p_j_id,
fid_good,
p_quant,
p_price,
p_vat,
p_vat_code,
p_nd_amount,
p_nd_tva,
p_nd_tva_recup,
fid_client);
return;
end;
$$
LANGUAGE plpgsql;
insert into tmp_pcmn(pcm_val,pcm_lib,pcm_val_parent) values(9,'Comptes hors Compta',0);
COMMENT ON TABLE parameter IS 'parameter of the company';
--
-- Name: plan_analytique; Type: TABLE; Schema: public; Owner: phpcompta; Tablespace:
--
CREATE TABLE plan_analytique (
pa_id integer NOT NULL,
pa_name text DEFAULT 'Sans Nom'::text NOT NULL,
pa_description text
);
--
-- Name: TABLE plan_analytique; Type: COMMENT; Schema: public; Owner: phpcompta
--
COMMENT ON TABLE plan_analytique IS 'Plan Analytique (max 5)';
--
-- Name: plan_analytique_pa_id_seq; Type: SEQUENCE; Schema: public; Owner: phpcompta
--
CREATE SEQUENCE plan_analytique_pa_id_seq
START WITH 1
INCREMENT BY 1
NO MAXVALUE
NO MINVALUE
CACHE 1;
--
-- Name: pa_id; Type: DEFAULT; Schema: public; Owner: phpcompta
--
ALTER TABLE plan_analytique ALTER COLUMN pa_id SET DEFAULT nextval('plan_analytique_pa_id_seq'::regclass);
--
-- Name: plan_analytique_pa_name_key; Type: CONSTRAINT; Schema: public; Owner: phpcompta; Tablespace:
--
ALTER TABLE ONLY plan_analytique
ADD CONSTRAINT plan_analytique_pa_name_key UNIQUE (pa_name);
--
-- Name: plan_analytique_pkey; Type: CONSTRAINT; Schema: public; Owner: phpcompta; Tablespace:
--
ALTER TABLE ONLY plan_analytique
ADD CONSTRAINT plan_analytique_pkey PRIMARY KEY (pa_id);
-- Ajout table operation_analytique
-- Ajout table poste_analytique
--
-- Name: poste_analytique; Type: TABLE; Schema: public; Owner: phpcompta; Tablespace:
--
CREATE TABLE poste_analytique (
po_id integer NOT NULL,
po_name text NOT NULL,
pa_id integer NOT NULL,
po_amount numeric(20,4) DEFAULT 0.0 NOT NULL,
po_description text
);
--
-- Name: TABLE poste_analytique; Type: COMMENT; Schema: public; Owner: phpcompta
--
COMMENT ON TABLE poste_analytique IS 'Poste Analytique';
--
-- Name: poste_analytique_po_id_seq; Type: SEQUENCE; Schema: public; Owner: phpcompta
--
CREATE SEQUENCE poste_analytique_po_id_seq
START WITH 1
INCREMENT BY 1
NO MAXVALUE
NO MINVALUE
CACHE 1;
--
-- Name: po_id; Type: DEFAULT; Schema: public; Owner: phpcompta
--
ALTER TABLE poste_analytique ALTER COLUMN po_id SET DEFAULT nextval('poste_analytique_po_id_seq'::regclass);
--
-- Name: poste_analytique_pkey; Type: CONSTRAINT; Schema: public; Owner: phpcompta; Tablespace:
--
ALTER TABLE ONLY poste_analytique
ADD CONSTRAINT poste_analytique_pkey PRIMARY KEY (po_id);
--
-- Name: poste_analytique_pa_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: phpcompta
--
ALTER TABLE ONLY poste_analytique
ADD CONSTRAINT poste_analytique_pa_id_fkey FOREIGN KEY (pa_id) REFERENCES plan_analytique(pa_id) ON UPDATE CASCADE ON DELETE CASCADE;
--
-- Name: operation_analytique; Type: TABLE; Schema: public; Owner: phpcompta; Tablespace:
--
create sequence s_oa_group;
CREATE TABLE operation_analytique (
oa_id integer NOT NULL,
po_id integer NOT NULL,
pa_id integer not null,
oa_amount numeric(20,4) NOT NULL,
oa_description text,
oa_debit boolean DEFAULT true NOT NULL,
j_id integer,
oa_group integer DEFAULT nextval('s_oa_group'::regclass) NOT NULL,
oa_date date NOT NULL
);
--
-- Name: TABLE operation_analytique; Type: COMMENT; Schema: public; Owner: phpcompta
--
COMMENT ON TABLE operation_analytique IS 'History of the analytic account';
--
-- Name: historique_analytique_ha_id_seq; Type: SEQUENCE; Schema: public; Owner: phpcompta
--
CREATE SEQUENCE historique_analytique_ha_id_seq
START WITH 1
INCREMENT BY 1
NO MAXVALUE
NO MINVALUE
CACHE 1;
--
-- Name: oa_id; Type: DEFAULT; Schema: public; Owner: phpcompta
--
ALTER TABLE operation_analytique ALTER COLUMN oa_id SET DEFAULT nextval('historique_analytique_ha_id_seq'::regclass);
--
-- Name: historique_analytique_pkey; Type: CONSTRAINT; Schema: public; Owner: phpcompta; Tablespace:
--
ALTER TABLE ONLY operation_analytique
ADD CONSTRAINT historique_analytique_pkey PRIMARY KEY (oa_id);
--
-- Name: operation_analytique_j_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: phpcompta
--
ALTER TABLE ONLY operation_analytique
ADD CONSTRAINT operation_analytique_j_id_fkey FOREIGN KEY (j_id) REFERENCES jrnx(j_id) ON UPDATE CASCADE ON DELETE CASCADE;
--
-- Name: operation_analytique_po_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: phpcompta
--
ALTER TABLE ONLY operation_analytique
ADD CONSTRAINT operation_analytique_po_id_fkey FOREIGN KEY (po_id) REFERENCES poste_analytique(po_id) ON UPDATE CASCADE ON DELETE CASCADE;
INSERT INTO parameter VALUES ('MY_ANALYTIC', 'nu');
alter table jrn add constraint ux_internal unique (jr_internal);
alter table user_sec_jrn add constraint uj_priv_id_fkey foreign key(uj_jrn_id) references jrn_def(jrn_def_id) on update cascade on delete cascade;
alter table user_sec_jrn drop constraint "$1";
alter table operation_analytique add oa_row int4;
create or replace function upper_po_name() returns trigger as $$
declare
name text;
begin
name:=upper(NEW.po_name);
name:=trim(name);
name:=replace(name,' ','');
NEW.po_name:=name;
return NEW;
end;
$$ LANGUAGE plpgsql;
create or replace function upper_pa_name() returns trigger as $$
declare
name text;
begin
name:=upper(NEW.pa_name);
name:=trim(name);
name:=replace(name,' ','');
NEW.pa_name:=name;
return NEW;
end;
$$ LANGUAGE plpgsql;
CREATE TRIGGER t_upper_po_name BEFORE INSERT OR UPDATE ON poste_analytique
FOR EACH ROW EXECUTE PROCEDURE upper_po_name();
CREATE TRIGGER t_upper_pa_name before INSERT OR UPDATE on plan_analytique
FOR EACH ROW EXECUTE PROCEDURE upper_pa_name();
create unique index ux_po_name on poste_analytique (po_name);
insert into parameter (pr_id,pr_value) select distinct 'MY_COUNTRY',pcm_country from tmp_pcmn limit 1;
alter table tmp_pcmn drop pcm_country;
CREATE TABLE bilan (
b_id integer NOT NULL,
b_name text NOT NULL,
b_file_template text NOT NULL,
b_file_form text,
b_type text NOT NULL
);
--
-- Name: TABLE bilan; Type: COMMENT; Schema: public; Owner: phpcompta
--
COMMENT ON TABLE bilan IS 'contains the template and the data for generating different documents ';
--
-- Name: COLUMN bilan.b_id; Type: COMMENT; Schema: public; Owner: phpcompta
--
COMMENT ON COLUMN bilan.b_id IS 'primary key';
--
-- Name: COLUMN bilan.b_name; Type: COMMENT; Schema: public; Owner: phpcompta
--
COMMENT ON COLUMN bilan.b_name IS 'Name of the document';
--
-- Name: COLUMN bilan.b_file_template; Type: COMMENT; Schema: public; Owner: phpcompta
--
COMMENT ON COLUMN bilan.b_file_template IS 'path of the template (document/...)';
--
-- Name: COLUMN bilan.b_file_form; Type: COMMENT; Schema: public; Owner: phpcompta
--
COMMENT ON COLUMN bilan.b_file_form IS 'path of the file with forms';
--
-- Name: COLUMN bilan.b_type; Type: COMMENT; Schema: public; Owner: phpcompta
--
COMMENT ON COLUMN bilan.b_type IS 'type = ODS, RTF...';
--
-- Name: bilan_b_id_seq; Type: SEQUENCE; Schema: public; Owner: phpcompta
--
CREATE SEQUENCE bilan_b_id_seq
INCREMENT BY 1
NO MAXVALUE
NO MINVALUE
CACHE 1;
--
-- Name: bilan_b_id_seq; Type: SEQUENCE SET; Schema: public; Owner: phpcompta
--
SELECT pg_catalog.setval('bilan_b_id_seq', 4, true);
--
-- Name: b_id; Type: DEFAULT; Schema: public; Owner: phpcompta
--
ALTER TABLE bilan ALTER COLUMN b_id SET DEFAULT nextval('bilan_b_id_seq'::regclass);
--
-- Data for Name: bilan; Type: TABLE DATA; Schema: public; Owner: phpcompta
--
INSERT INTO bilan VALUES (1, 'Bilan Belge complet', 'document/fr_be/bnb.rtf', 'document/fr_be/bnb.form', 'RTF');
--
-- Name: bilan_b_name_key; Type: CONSTRAINT; Schema: public; Owner: phpcompta; Tablespace:
--
ALTER TABLE ONLY bilan
ADD CONSTRAINT bilan_b_name_key UNIQUE (b_name);
--
-- Name: bilan_pkey; Type: CONSTRAINT; Schema: public; Owner: phpcompta; Tablespace:
--
ALTER TABLE ONLY bilan
ADD CONSTRAINT bilan_pkey PRIMARY KEY (b_id);
--
-- PostgreSQL database dump complete
--
CREATE TABLE op_predef (
od_id integer NOT NULL,
jrn_def_id integer NOT NULL,
od_name text NOT NULL,
od_item integer NOT NULL,
od_jrn_type text NOT NULL
);
--
-- Name: TABLE op_predef; Type: COMMENT; Schema: public; Owner: phpcompta
--
COMMENT ON TABLE op_predef IS 'predefined operation';
--
-- Name: COLUMN op_predef.jrn_def_id; Type: COMMENT; Schema: public; Owner: phpcompta
--
COMMENT ON COLUMN op_predef.jrn_def_id IS 'jrn_id';
--
-- Name: COLUMN op_predef.od_name; Type: COMMENT; Schema: public; Owner: phpcompta
--
COMMENT ON COLUMN op_predef.od_name IS 'name of the operation';
--
-- Name: op_def_op_seq; Type: SEQUENCE; Schema: public; Owner: phpcompta
--
CREATE SEQUENCE op_def_op_seq
INCREMENT BY 1
NO MAXVALUE
NO MINVALUE
CACHE 1;
--
-- Name: od_id; Type: DEFAULT; Schema: public; Owner: phpcompta
--
ALTER TABLE op_predef ALTER COLUMN od_id SET DEFAULT nextval('op_def_op_seq'::regclass);
--
-- Name: op_def_op_name_key; Type: CONSTRAINT; Schema: public; Owner: phpcompta; Tablespace:
--
ALTER TABLE ONLY op_predef
ADD CONSTRAINT op_def_op_name_key UNIQUE (od_name,jrn_def_id);
--
-- Name: op_def_pkey; Type: CONSTRAINT; Schema: public; Owner: phpcompta; Tablespace:
--
ALTER TABLE ONLY op_predef
ADD CONSTRAINT op_def_pkey PRIMARY KEY (od_id);
--
-- Name: jrn_def_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: phpcompta
--
ALTER TABLE ONLY op_predef
ADD CONSTRAINT jrn_def_id_fk FOREIGN KEY (jrn_def_id) REFERENCES jrn_def(jrn_def_id) ON UPDATE CASCADE ON DELETE CASCADE;
CREATE TABLE op_predef_detail (
opd_id integer NOT NULL,
od_id integer NOT NULL,
opd_poste text NOT NULL,
opd_amount numeric(20,4),
opd_tva_id integer,
opd_quantity numeric(20,4),
opd_debit boolean NOT NULL,
opd_tva_amount numeric(20,4),
opd_comment text
);
--
-- Name: TABLE op_predef_detail; Type: COMMENT; Schema: public; Owner: phpcompta
--
COMMENT ON TABLE op_predef_detail IS 'contains the detail of predefined operations';
--
-- Name: op_predef_detail_opd_id_seq; Type: SEQUENCE; Schema: public; Owner: phpcompta
--
CREATE SEQUENCE op_predef_detail_opd_id_seq
INCREMENT BY 1
NO MAXVALUE
NO MINVALUE
CACHE 1;
--
-- Name: opd_id; Type: DEFAULT; Schema: public; Owner: phpcompta
--
ALTER TABLE op_predef_detail ALTER COLUMN opd_id SET DEFAULT nextval('op_predef_detail_opd_id_seq'::regclass);
--
-- Name: op_predef_detail_pkey; Type: CONSTRAINT; Schema: public; Owner: phpcompta; Tablespace:
--
ALTER TABLE ONLY op_predef_detail
ADD CONSTRAINT op_predef_detail_pkey PRIMARY KEY (opd_id);
INSERT INTO "action" VALUES (50, 'Definir les Plans Analytiques et les postes');
INSERT INTO "action" VALUES (51, 'Impression CA');
INSERT INTO "action" VALUES (52, 'Operations Diverses CA');
update version set val=32;
commit;

View file

@ -0,0 +1,10 @@
begin ;
delete from jrn where jr_internal is null;
delete from jrnx where j_grpt not in (select jr_grpt_id from jrn);
alter table op_predef add od_direct bool;
update op_predef set od_direct=false;
alter table op_predef alter od_direct set not null;
alter table op_predef_detail add od_qc bool;
update version set val=33;
commit;

View file

@ -0,0 +1,6 @@
begin ;
alter table op_predef_detail rename od_qc to opd_qc;
update version set val=34;
commit;

View file

@ -0,0 +1,72 @@
begin;
CREATE or replace FUNCTION t_jrn_def_sequence() RETURNS "trigger"
AS $$
declare
nCounter integer;
BEGIN
select count(*) into nCounter
from pg_class where relname='s_jrn_'||NEW.jrn_def_id;
if nCounter = 0 then
execute 'create sequence s_jrn_'||NEW.jrn_def_id;
raise notice 'Creating sequence s_jrn_%',NEW.jrn_def_id;
end if;
RETURN NEW;
END;
$$
LANGUAGE plpgsql;
create or replace function correct_sequence_jrn () returns void
as $$
declare
nCounter integer;
nJrn_id record;
begin
for nJrn_id in select jrn_Def_id from jrn_def loop
select count(*) into nCounter
from pg_class where relname='s_jrn_'||nJrn_id.jrn_def_id;
if nCounter = 0 then
execute 'create sequence s_jrn_'||nJrn_id.jrn_def_id;
raise notice 'Creating sequence s_jrn_%',nJrn_id.jrn_def_id;
end if;
end loop;
end;
$$
LANGUAGE plpgsql;
select correct_sequence_jrn();
drop function correct_sequence_jrn();
CREATE OR REPLACE FUNCTION tva_delete(int4)
RETURNS void AS
$BODY$
declare
p_tva_id alias for $1;
nCount integer;
begin
nCount=0;
select count(*) into nCount from quant_sold where qs_vat_code=p_tva_id;
if nCount != 0 then
return;
end if;
select count(*) into nCount from quant_purchase where qp_vat_code=p_tva_id;
if nCount != 0 then
return;
end if;
delete from tva_rate where tva_id=p_tva_id;
return;
end;
$BODY$
LANGUAGE 'plpgsql' VOLATILE;
update version set val=35;
commit;

View file

@ -0,0 +1,45 @@
begin;
CREATE or replace FUNCTION t_document_modele_validate() RETURNS "trigger"
AS $$
declare
lText text;
modified document_modele%ROWTYPE;
begin
modified=NEW;
modified.md_filename=replace(NEW.md_filename,' ','_');
return modified;
end;
$$ LANGUAGE plpgsql;
CREATE or replace FUNCTION t_document_validate() RETURNS "trigger"
AS $$
declare
lText text;
modified document%ROWTYPE;
begin
modified=NEW;
modified.d_filename=replace(NEW.d_filename,' ','_');
return modified;
end;
$$ LANGUAGE plpgsql;
CREATE TRIGGER document_validate
BEFORE INSERT OR UPDATE ON document
FOR EACH ROW
EXECUTE PROCEDURE t_document_validate();
CREATE TRIGGER document_modele_validate
BEFORE INSERT OR UPDATE ON document_modele
FOR EACH ROW
EXECUTE PROCEDURE t_document_modele_validate();
update operation_analytique set oa_debit=j_debit from jrnx where jrnx.j_id=operation_analytique.j_id ;
update version set val=36;
commit;

View file

@ -0,0 +1,44 @@
INSERT INTO parm_poste (p_value, p_type) VALUES (1, 'PAS');
INSERT INTO parm_poste (p_value, p_type) VALUES (101, 'PASINV');
INSERT INTO parm_poste (p_value, p_type) VALUES (141, 'PASINV');
INSERT INTO parm_poste (p_value, p_type) VALUES (42, 'PAS');
INSERT INTO parm_poste (p_value, p_type) VALUES (43, 'PAS');
INSERT INTO parm_poste (p_value, p_type) VALUES (44, 'PAS');
INSERT INTO parm_poste (p_value, p_type) VALUES (45, 'PAS');
INSERT INTO parm_poste (p_value, p_type) VALUES (46, 'PAS');
INSERT INTO parm_poste (p_value, p_type) VALUES (47, 'PAS');
INSERT INTO parm_poste (p_value, p_type) VALUES (48, 'PAS');
INSERT INTO parm_poste (p_value, p_type) VALUES (492, 'PAS');
INSERT INTO parm_poste (p_value, p_type) VALUES (493, 'PAS');
INSERT INTO parm_poste (p_value, p_type) VALUES (2, 'ACT');
INSERT INTO parm_poste (p_value, p_type) VALUES (2409, 'ACTINV');
INSERT INTO parm_poste (p_value, p_type) VALUES (3, 'ACT');
INSERT INTO parm_poste (p_value, p_type) VALUES (5, 'ACT');
INSERT INTO parm_poste (p_value, p_type) VALUES (491, 'ACT');
INSERT INTO parm_poste (p_value, p_type) VALUES (490, 'ACT');
INSERT INTO parm_poste (p_value, p_type) VALUES (6, 'CHA');
INSERT INTO parm_poste (p_value, p_type) VALUES (7, 'PRO');
INSERT INTO parm_poste (p_value, p_type) VALUES (4, 'ACT');
INSERT INTO parm_poste (p_value, p_type) VALUES (40, 'ACT');
INSERT INTO parm_poste (p_value, p_type) VALUES (5501, 'ACTINV');
INSERT INTO parm_poste (p_value, p_type) VALUES (5511, 'ACTINV');
INSERT INTO parm_poste (p_value, p_type) VALUES (5521, 'ACTINV');
INSERT INTO parm_poste (p_value, p_type) VALUES (5531, 'ACTINV');
INSERT INTO parm_poste (p_value, p_type) VALUES (5541, 'ACTINV');
INSERT INTO parm_poste (p_value, p_type) VALUES (5551, 'ACTINV');
INSERT INTO parm_poste (p_value, p_type) VALUES (5561, 'ACTINV');
INSERT INTO parm_poste (p_value, p_type) VALUES (5571, 'ACTINV');
INSERT INTO parm_poste (p_value, p_type) VALUES (5581, 'ACTINV');
INSERT INTO parm_poste (p_value, p_type) VALUES (5591, 'ACTINV');
INSERT INTO parm_poste (p_value, p_type) VALUES (6311, 'CHAINV');
INSERT INTO parm_poste (p_value, p_type) VALUES (6321, 'CHAINV');
INSERT INTO parm_poste (p_value, p_type) VALUES (6331, 'CHAINV');
INSERT INTO parm_poste (p_value, p_type) VALUES (6341, 'CHAINV');
INSERT INTO parm_poste (p_value, p_type) VALUES (6351, 'CHAINV');
INSERT INTO parm_poste (p_value, p_type) VALUES (6361, 'CHAINV');
INSERT INTO parm_poste (p_value, p_type) VALUES (6371, 'CHAINV');
INSERT INTO parm_poste (p_value, p_type) VALUES (649, 'CHAINV');
INSERT INTO parm_poste (p_value, p_type) VALUES (6511, 'CHAINV');
INSERT INTO parm_poste (p_value, p_type) VALUES (6701, 'CHAINV');
INSERT INTO parm_poste (p_value, p_type) VALUES (608, 'CHAINV');
INSERT INTO parm_poste (p_value, p_type) VALUES (709, 'PROINV');

View file

@ -0,0 +1,45 @@
--
-- PostgreSQL database dump
--
SET client_encoding = 'utf8';
SET standard_conforming_strings = off;
SET check_function_bodies = false;
SET client_min_messages = warning;
SET escape_string_warning = off;
SET search_path = public, pg_catalog;
--
-- Data for Name: parm_poste; Type: TABLE DATA; Schema: public; Owner: phpcompta
--
INSERT INTO parm_poste (p_value, p_type) VALUES (1, 'PAS');
INSERT INTO parm_poste (p_value, p_type) VALUES (12, 'CON');
INSERT INTO parm_poste (p_value, p_type) VALUES (2, 'ACT');
INSERT INTO parm_poste (p_value, p_type) VALUES (3, 'ACT');
INSERT INTO parm_poste (p_value, p_type) VALUES (41, 'ACT');
INSERT INTO parm_poste (p_value, p_type) VALUES (42, 'PAS');
INSERT INTO parm_poste (p_value, p_type) VALUES (43, 'PAS');
INSERT INTO parm_poste (p_value, p_type) VALUES (44, 'PAS');
INSERT INTO parm_poste (p_value, p_type) VALUES (45, 'PAS');
INSERT INTO parm_poste (p_value, p_type) VALUES (46, 'CON');
INSERT INTO parm_poste (p_value, p_type) VALUES (47, 'CON');
INSERT INTO parm_poste (p_value, p_type) VALUES (481, 'PAS');
INSERT INTO parm_poste (p_value, p_type) VALUES (482, 'PAS');
INSERT INTO parm_poste (p_value, p_type) VALUES (483, 'PAS');
INSERT INTO parm_poste (p_value, p_type) VALUES (484, 'PAS');
INSERT INTO parm_poste (p_value, p_type) VALUES (485, 'PAS');
INSERT INTO parm_poste (p_value, p_type) VALUES (486, 'PAS');
INSERT INTO parm_poste (p_value, p_type) VALUES (487, 'ACT');
INSERT INTO parm_poste (p_value, p_type) VALUES (49, 'PAS');
INSERT INTO parm_poste (p_value, p_type) VALUES (5, 'ACT');
INSERT INTO parm_poste (p_value, p_type) VALUES (6, 'CHA');
INSERT INTO parm_poste (p_value, p_type) VALUES (7, 'PAS');
INSERT INTO parm_poste (p_value, p_type) VALUES (40, 'ACT');
--
-- PostgreSQL database dump complete
--

View file

@ -0,0 +1,695 @@
begin;
alter table import_tmp add n_montant numeric(20,4);
update import_tmp set n_montant=to_number(montant,'999999999.99');
alter table import_tmp drop montant;
alter table import_tmp rename n_montant to montant;
-- alter table import_tmp alter montant type numeric(20,4);
alter table import_tmp alter montant set default 0;
alter table import_tmp alter montant set not null;
alter table import_tmp alter code set not null;
alter table import_tmp alter date_exec set not null;
alter table import_tmp alter date_valeur set not null;
COMMENT ON TABLE import_tmp IS 'Table temporaire pour l''importation des banques en format CSV';
COMMENT ON COLUMN import_tmp.status IS 'Status w waiting, d delete t transfert';
alter table poste_analytique add ga_id varchar (10);
CREATE or replace FUNCTION t_document_validate() RETURNS "trigger"
AS $$
declare
lText text;
modified document%ROWTYPE;
begin
modified:=NEW;
modified.d_filename:=replace(NEW.d_filename,' ','_');
return modified;
end;
$$
LANGUAGE plpgsql;
CREATE or replace FUNCTION t_document_type_insert() RETURNS "trigger"
AS $$
declare
nCounter integer;
BEGIN
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;
end if;
RETURN NEW;
END;
$$
LANGUAGE plpgsql;
CREATE or replace FUNCTION t_document_modele_validate() RETURNS "trigger"
AS $$
declare
lText text;
modified document_modele%ROWTYPE;
begin
modified:=NEW;
modified.md_filename:=replace(NEW.md_filename,' ','_');
return modified;
end;
$$
LANGUAGE plpgsql;
CREATE TABLE groupe_analytique
(
ga_id varchar(10) NOT NULL,
pa_id int,
ga_description text,
CONSTRAINT pk_ga_id PRIMARY KEY (ga_id)
) ;
CREATE OR REPLACE FUNCTION group_analytic_ins_upd()
RETURNS "trigger" AS
$BODY$
declare
name text;
begin
name:=upper(NEW.ga_id);
name:=trim(name);
name:=replace(name,' ','');
NEW.ga_id:=name;
return NEW;
end;$BODY$
LANGUAGE 'plpgsql' VOLATILE;
CREATE OR REPLACE FUNCTION group_analytique_del()
RETURNS "trigger" AS
$BODY$
begin
update poste_analytique set ga_id=null
where ga_id=OLD.ga_id;
return OLD;
end;$BODY$
LANGUAGE 'plpgsql' VOLATILE;
CREATE OR REPLACE FUNCTION poste_analytique_ins_upd()
RETURNS "trigger" AS
$BODY$declare
name text;
rCount record;
begin
name:=upper(NEW.po_name);
name:=trim(name);
name:=replace(name,' ','');
NEW.po_name:=name;
if NEW.ga_id is NULL then
return NEW;
end if;
if length(trim(NEW.ga_id)) = 0 then
NEW.ga_id:=NULL;
return NEW;
end if;
perform 'select ga_id from groupe_analytique where ga_id='||NEW.ga_id;
if NOT FOUND then
raise exception' Inexistent Group Analytic %',NEW.ga_id;
end if;
return NEW;
end;$BODY$
LANGUAGE 'plpgsql' VOLATILE;
CREATE OR REPLACE FUNCTION plan_analytic_ins_upd()
RETURNS "trigger" AS
$BODY$
declare
name text;
begin
name:=upper(NEW.pa_name);
name:=trim(name);
name:=replace(name,' ','');
NEW.pa_name:=name;
return NEW;
end;
$BODY$
LANGUAGE 'plpgsql' VOLATILE;
CREATE TRIGGER t_poste_analytique_ins_upd
BEFORE INSERT OR UPDATE
ON poste_analytique
FOR EACH ROW
EXECUTE PROCEDURE poste_analytique_ins_upd();
CREATE TRIGGER t_plan_analytique_ins_upd
BEFORE INSERT OR UPDATE
ON plan_analytique
FOR EACH ROW
EXECUTE PROCEDURE plan_analytic_ins_upd();
CREATE TRIGGER t_group_analytic_del
before DELETE
ON groupe_analytique
FOR EACH ROW
EXECUTE PROCEDURE group_analytique_del();
CREATE TRIGGER t_group_analytic_ins_upd
BEFORE INSERT OR UPDATE
ON groupe_analytique
FOR EACH ROW
EXECUTE PROCEDURE group_analytic_ins_upd();
drop TRIGGER t_upper_pa_name on plan_analytique;
drop TRIGGER t_upper_po_name on poste_analytique;
drop function upper_pa_name();
drop function upper_po_name();
CREATE TABLE bud_hypothese
(
bh_id int4 NOT NULL,
bh_name text NOT NULL,
bh_saldo numeric(20,4) DEFAULT 0,
bh_description text,
pa_id int4,
CONSTRAINT pk_bud_hypo PRIMARY KEY (bh_id),
CONSTRAINT fk_bud_hypo_pa_id FOREIGN KEY (pa_id)
REFERENCES plan_analytique (pa_id) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE
)
WITHOUT OIDS;
create sequence seq_bud_hypothese_bh_id;
alter table bud_hypothese alter bh_id set default nextval('seq_bud_hypothese_bh_id');
--
-- Name: bud_card; Type: TABLE; Schema: public; Owner: phpcompta; Tablespace:
--
CREATE TABLE bud_card (
bc_id integer NOT NULL,
bc_code character varying(10) NOT NULL,
bc_description text,
bc_price_unit numeric(20,4) DEFAULT 0.0 NOT NULL,
bc_unit character varying(20),
bh_id integer
);
--
-- Name: TABLE bud_card; Type: COMMENT; Schema: public; Owner: phpcompta
--
COMMENT ON TABLE bud_card IS 'card for budget module';
--
-- Name: COLUMN bud_card.bh_id; Type: COMMENT; Schema: public; Owner: phpcompta
--
COMMENT ON COLUMN bud_card.bh_id IS 'fk to bud_hypothese';
--
-- Name: bud_card_bc_id_seq; Type: SEQUENCE; Schema: public; Owner: phpcompta
--
CREATE SEQUENCE bud_card_bc_id_seq
INCREMENT BY 1
NO MAXVALUE
NO MINVALUE
CACHE 1;
--
-- Name: bc_id; Type: DEFAULT; Schema: public; Owner: phpcompta
--
ALTER TABLE bud_card ALTER COLUMN bc_id SET DEFAULT nextval('bud_card_bc_id_seq'::regclass);
--
-- Name: pk_bud_card_bc_id; Type: CONSTRAINT; Schema: public; Owner: phpcompta; Tablespace:
--
ALTER TABLE ONLY bud_card
ADD CONSTRAINT pk_bud_card_bc_id PRIMARY KEY (bc_id);
--
-- Name: uq_bud_card_bc_code; Type: CONSTRAINT; Schema: public; Owner: phpcompta; Tablespace:
--
ALTER TABLE ONLY bud_card
ADD CONSTRAINT uq_bud_card_bc_code_bh_id UNIQUE (bc_code,bh_id);
ALTER TABLE bud_card ADD CONSTRAINT fk_bud_hypo_bh_id FOREIGN KEY (bh_id) REFERENCES bud_hypothese (bh_id)
ON UPDATE CASCADE ON DELETE CASCADE;
CREATE INDEX fki_bud_hypo_bh_id ON bud_card(bh_id);
ALTER TABLE bud_card ALTER COLUMN bh_id SET NOT NULL;
--
-- Name: bud_detail; Type: TABLE; Schema: public; Owner: phpcompta; Tablespace:
--
CREATE TABLE bud_detail (
bd_id integer NOT NULL,
po_id integer,
bc_id integer,
bh_id integer,
pcm_val poste_comptable
);
--
-- Name: TABLE bud_detail; Type: COMMENT; Schema: public; Owner: phpcompta
--
COMMENT ON TABLE bud_detail IS 'Detail for card ';
--
-- Name: COLUMN bud_detail.bd_id; Type: COMMENT; Schema: public; Owner: phpcompta
--
COMMENT ON COLUMN bud_detail.bd_id IS 'primary key';
--
-- Name: COLUMN bud_detail.po_id; Type: COMMENT; Schema: public; Owner: phpcompta
--
COMMENT ON COLUMN bud_detail.po_id IS 'FK to poste_analytique';
--
-- Name: COLUMN bud_detail.bc_id; Type: COMMENT; Schema: public; Owner: phpcompta
--
COMMENT ON COLUMN bud_detail.bc_id IS 'fk to bud_card';
--
-- Name: COLUMN bud_detail.pcm_val; Type: COMMENT; Schema: public; Owner: phpcompta
--
COMMENT ON COLUMN bud_detail.pcm_val IS 'fk to tmp_pcmn';
--
-- Name: bud_detail_bd_id_seq; Type: SEQUENCE; Schema: public; Owner: phpcompta
--
CREATE SEQUENCE bud_detail_bd_id_seq
INCREMENT BY 1
NO MAXVALUE
NO MINVALUE
CACHE 1;
--
-- Name: bd_id; Type: DEFAULT; Schema: public; Owner: phpcompta
--
ALTER TABLE bud_detail ALTER COLUMN bd_id SET DEFAULT nextval('bud_detail_bd_id_seq'::regclass);
--
-- Name: pk_bud_detail; Type: CONSTRAINT; Schema: public; Owner: phpcompta; Tablespace:
--
ALTER TABLE ONLY bud_detail
ADD CONSTRAINT pk_bud_detail PRIMARY KEY (bd_id);
--
-- Name: fki_bud_card; Type: INDEX; Schema: public; Owner: phpcompta; Tablespace:
--
CREATE INDEX fki_bud_card ON bud_detail USING btree (bc_id);
--
-- Name: fki_tmp_pcmn; Type: INDEX; Schema: public; Owner: phpcompta; Tablespace:
--
CREATE INDEX fki_tmp_pcmn ON bud_detail USING btree (pcm_val);
--
-- Name: fk_bud_card; Type: FK CONSTRAINT; Schema: public; Owner: phpcompta
--
ALTER TABLE ONLY bud_detail
ADD CONSTRAINT fk_bud_card FOREIGN KEY (bc_id) REFERENCES bud_card(bc_id) ON UPDATE CASCADE ON DELETE CASCADE;;
ALTER TABLE ONLY bud_detail
add constraint fk_bud_hypothese_not_null FOREIGN KEY (bh_id) REFERENCES bud_hypothese(bh_id) ON UPDATE CASCADE ON DELETE CASCADE;;
--
-- Name: fk_tmp_pcmn; Type: FK CONSTRAINT; Schema: public; Owner: phpcompta
--
ALTER TABLE ONLY bud_detail
ADD CONSTRAINT fk_tmp_pcmn FOREIGN KEY (pcm_val) REFERENCES tmp_pcmn(pcm_val) ON UPDATE CASCADE ON DELETE CASCADE;
--
-- Name: bud_detail_periode; Type: TABLE; Schema: public; Owner: phpcompta; Tablespace:
--
CREATE TABLE bud_detail_periode (
bdp_id integer NOT NULL,
bdp_amount numeric(20,4) DEFAULT 0.0,
p_id integer NOT NULL,
bd_id integer
);
--
-- Name: TABLE bud_detail_periode; Type: COMMENT; Schema: public; Owner: phpcompta
--
COMMENT ON TABLE bud_detail_periode IS 'Module budget detail by periode';
--
-- Name: COLUMN bud_detail_periode.p_id; Type: COMMENT; Schema: public; Owner: phpcompta
--
COMMENT ON COLUMN bud_detail_periode.p_id IS 'fk to parm_periode';
--
-- Name: COLUMN bud_detail_periode.bd_id; Type: COMMENT; Schema: public; Owner: phpcompta
--
COMMENT ON COLUMN bud_detail_periode.bd_id IS 'fk to bud_detail';
--
-- Name: bud_detail_periode_bdp_id_seq; Type: SEQUENCE; Schema: public; Owner: phpcompta
--
CREATE SEQUENCE bud_detail_periode_bdp_id_seq
START WITH 1
INCREMENT BY 1
NO MAXVALUE
NO MINVALUE
CACHE 1;
--
-- Name: bdp_id; Type: DEFAULT; Schema: public; Owner: phpcompta
--
ALTER TABLE bud_detail_periode ALTER COLUMN bdp_id SET DEFAULT nextval('bud_detail_periode_bdp_id_seq'::regclass);
--
-- Name: pk_budget_detail_period; Type: CONSTRAINT; Schema: public; Owner: phpcompta; Tablespace:
--
ALTER TABLE ONLY bud_detail_periode
ADD CONSTRAINT pk_budget_detail_period PRIMARY KEY (bdp_id);
--
-- Name: fk_bud_detail_bd_id; Type: FK CONSTRAINT; Schema: public; Owner: phpcompta
--
ALTER TABLE ONLY bud_detail_periode
ADD CONSTRAINT fk_bud_detail_bd_id FOREIGN KEY (bd_id) REFERENCES bud_detail(bd_id) ON UPDATE CASCADE ON DELETE CASCADE;
--
-- Name: fk_parm_periode; Type: FK CONSTRAINT; Schema: public; Owner: phpcompta
--
ALTER TABLE ONLY bud_detail_periode
ADD CONSTRAINT fk_parm_periode FOREIGN KEY (p_id) REFERENCES parm_periode(p_id) ON UPDATE CASCADE ON DELETE CASCADE;
CREATE OR REPLACE FUNCTION bud_detail_ins_upd()
RETURNS "trigger" AS
$BODY$declare
mline bud_detail%ROWTYPE;
begin
mline:=NEW;
if mline.po_id = -1 then
mline.po_id:=NULL;
end if;
return mline;
end;$BODY$
LANGUAGE 'plpgsql' VOLATILE;
CREATE OR REPLACE FUNCTION bud_card_ins_upd()
RETURNS "trigger" AS
$BODY$declare
sCode text;
begin
sCode:=trim(upper(NEW.bc_code));
sCode:=replace(sCode,' ','_');
sCode:=substr(sCode,1,10);
NEW.bc_code:=sCode;
return NEW;
end;$BODY$
LANGUAGE 'plpgsql' VOLATILE;
--
-- Name: t_bud_card_ins_up; Type: TRIGGER; Schema: public; Owner: phpcompta
--
CREATE TRIGGER t_bud_card_ins_up
BEFORE INSERT OR UPDATE ON bud_card
FOR EACH ROW
EXECUTE PROCEDURE bud_card_ins_upd();
--
-- Name: bud_hypothese_bh_id; Type: FK CONSTRAINT; Schema: public; Owner: phpcompta
--
ALTER TABLE ONLY bud_card
ADD CONSTRAINT bud_hypothese_bh_id FOREIGN KEY (bh_id) REFERENCES bud_hypothese(bh_id) ON UPDATE CASCADE ON DELETE CASCADE;
CREATE TRIGGER t_bud_detail_ins_upd
BEFORE INSERT OR UPDATE
ON bud_detail
FOR EACH ROW
EXECUTE PROCEDURE bud_detail_ins_upd();
CREATE TABLE jrn_periode
(
jrn_def_id int4 NOT NULL,
p_id int4 NOT NULL,
status text,
CONSTRAINT jrn_periode_pk PRIMARY KEY (jrn_def_id, p_id),
CONSTRAINT jrn_per_jrn_def_id FOREIGN KEY (jrn_def_id)
REFERENCES jrn_def (jrn_def_id) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE,
CONSTRAINT jrn_periode_p_id FOREIGN KEY (p_id)
REFERENCES parm_periode (p_id) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE
);
insert into jrn_periode(p_id,jrn_def_id,status) select p_id,jrn_def_id,
case when p_central='t' then 'CE'
when p_closed='t' then 'CL'
else 'OP'
end
from
parm_periode cross join jrn_def;
CREATE OR REPLACE FUNCTION jrn_def_add()
RETURNS "trigger" AS
$BODY$begin
execute 'insert into jrn_periode(p_id,jrn_def_id,status) select p_id,'||NEW.jrn_def_id||',
case when p_central=true then ''CE''
when p_closed=true then ''CL''
else ''OP''
end
from
parm_periode ';
return NEW;
end;$BODY$
LANGUAGE 'plpgsql' VOLATILE;
CREATE TRIGGER t_jrn_def_add_periode
AFTER INSERT
ON jrn_def
FOR EACH ROW
EXECUTE PROCEDURE jrn_def_add();
CREATE OR REPLACE FUNCTION jrn_check_periode()
RETURNS "trigger" AS
$BODY$
declare
bClosed bool;
str_status text;
begin
select p_closed into bClosed from parm_periode
where p_id=NEW.jr_tech_per;
if bClosed = true then
raise exception 'Periode fermee';
end if;
select status into str_status from jrn_periode
where p_id =NEW.jr_tech_per and jrn_def_id=NEW.jr_def_id;
if str_status <> 'OP' then
raise exception 'Periode fermee';
end if;
return NEW;
end;$BODY$
LANGUAGE 'plpgsql' VOLATILE;
CREATE TRIGGER t_check_jrn
BEFORE INSERT OR DELETE
ON jrn
FOR EACH ROW
EXECUTE PROCEDURE jrn_check_periode();
drop TRIGGER tr_jrn_check_balance on jrn;
CREATE OR REPLACE FUNCTION jrn_def_delete()
RETURNS "trigger" AS
$BODY$
declare
nb numeric;
begin
select count(*) into nb from jrn where jr_def_id=OLD.jrn_def_id;
if nb <> 0 then
raise exception 'EFFACEMENT INTERDIT: JOURNAL UTILISE';
end if;
return OLD;
end;$BODY$
LANGUAGE 'plpgsql' VOLATILE;
CREATE TRIGGER t_jrn_def_delete
BEFORE DELETE
ON jrn_def
FOR EACH ROW
EXECUTE PROCEDURE jrn_def_delete();
CREATE OR REPLACE FUNCTION proc_check_balance()
RETURNS "trigger" AS
$BODY$
declare
diff numeric;
tt integer;
begin
if TG_OP = 'INSERT' or TG_OP='UPDATE' then
tt=NEW.jr_grpt_id;
diff:=check_balance(tt);
if diff != 0 then
raise exception 'balance error %',diff ;
end if;
return NEW;
end if;
end;
$BODY$
LANGUAGE 'plpgsql' VOLATILE;
CREATE TRIGGER t_check_balance
AFTER INSERT OR UPDATE
ON jrn
FOR EACH ROW
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 p_type into str_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);
update version set val=37;
commit;

View file

@ -0,0 +1,43 @@
begin;
CREATE OR REPLACE FUNCTION jrn_check_periode()
RETURNS "trigger" AS
$BODY$
declare
bClosed bool;
str_status text;
ljr_tech_per jrn.jr_tech_per%TYPE;
ljr_def_id jrn.jr_def_id%TYPE;
lreturn jrn%ROWTYPE;
begin
if TG_OP='INSERT' then
ljr_tech_per :=NEW.jr_tech_per;
ljr_def_id :=NEW.jr_def_id;
lreturn :=NEW;
end if;
if TG_OP='DELETE' then
ljr_tech_per :=OLD.jr_tech_per;
ljr_def_id :=OLD.jr_def_id;
lreturn :=OLD;
end if;
select p_closed into bClosed from parm_periode
where p_id=ljr_tech_per;
if bClosed = true then
raise exception 'Periode fermee';
end if;
select status into str_status from jrn_periode
where p_id =ljr_tech_per and jrn_def_id=ljr_def_id;
if str_status <> 'OP' then
raise exception 'Periode fermee';
end if;
return lreturn;
end;$BODY$
LANGUAGE 'plpgsql' VOLATILE;
update version set val=38;
commit;

View file

@ -0,0 +1,28 @@
begin;
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 p_type into str_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;
update version set val=39;
commit;

View file

@ -0,0 +1,41 @@
begin;
create table info_def (
id_type text primary key,
id_description text null
);
comment on table info_def is 'Contains the types of additionnal info we can add to a operation';
create or replace function info_def_ins_upd() returns trigger
AS
$$
declare
row_info_def info_def%ROWTYPE;
str_type text;
begin
row_info_def:=NEW;
str_type:=upper(trim(NEW.id_type));
str_type:=replace(str_type,' ','');
str_type:=replace(str_type,',','');
str_type:=replace(str_type,';','');
if length(str_type) =0 then
raise exception 'id_type cannot be null';
end if;
row_info_def.id_type:=str_type;
return row_info_def;
end;
$$ language plpgsql;
create trigger info_def_ins_upd_t before insert or update on info_def for each row execute procedure info_def_ins_upd();
create table jrn_info (
ji_id serial primary key,
jr_id integer not null,
id_type text not null,
ji_value text
);
alter table jrn_info add constraint fk_jrn foreign key (jr_id) references jrn(jr_id) on delete cascade on update cascade;
alter table jrn_info add constraint fk_info_def foreign key (id_type) references info_def(id_type) on delete cascade on update cascade;
insert into info_def values ('BON_COMMANDE','Numero de bon de commande') ;
insert into info_def values ('OTHER','Info diverses');
insert into attr_def values(30,'Numero de client');
update version set val=40;
commit;

View file

@ -0,0 +1,64 @@
-- upgrade
comment on table action is 'The different privileges';
comment on table attr_def is 'The available attributs for the cards';
comment on table attr_min is 'The minimum attributs for the cards';
comment on table attr_min is 'The value of attributs for the cards';
comment on table centralized is 'The centralized journal';
comment on table fiche is 'Cards';
comment on table fiche_def is 'Cards definition';
comment on table fiche_def_ref is 'Family Cards definition';
comment on table form is 'Forms';
comment on table form is 'Forms content';
comment on table jnt_fic_att_value is 'join between the card and the attribut definition';
comment on table jnt_fic_attr is 'join between the family card and the attribut definition';
comment on table jrn is 'Journal: content one line for a group of accountancy writing';
comment on table jrnx is 'Journal: content one line for each accountancy writing';
comment on table jrn_action is 'Possible action when we are in journal (menu)';
comment on table jrn_def is 'Definition of a journal, his properties';
comment on table jrn_rapt is 'Rapprochement between operation';
comment on table jrn_type is 'Type of journal (Sell, Buy, Financial...)';
comment on table parm_money is 'Currency conversion';
comment on table parm_periode is 'Periode definition';
comment on table stock_goods is 'About the goods';
comment on table tmp_pcmn is 'Plan comptable minimum normalisé';
comment on table tva_rate is 'Rate of vat';
create sequence s_central;
-- create index x_jr_grpt_id on jrn (jr_grpt_id);
-- create index x_j_grpt on jrnx(j_grpt);
create index x_poste on jrnx(j_poste );
delete from jrn_action where ja_name='Impression' or ja_name = 'Recherche';
delete from fiche where f_id not in (select f_id from jnt_fic_att_value);
alter table jrn add jr_opid int4;
alter table jrn add jr_c_opid int4;
create SEQUENCE s_central_order;
alter table centralized add c_order int4;
-- decentralize
delete from centralized;
create sequence s_internal;
select setval('s_centralized',1,false);
update jrnx set j_centralized='f';
alter table parm_periode add p_central bool;
alter table parm_periode alter p_central set default false;
update parm_periode set p_central ='f';
--for uploading doc
alter table jrn add jr_pj oid ;
alter table jrn add jr_pj_name text;
alter table jrn add jr_pj_type text;
-- task 3858
delete from user_sec_act WHERE ua_act_id =14;
delete from action where ac_id=14;
insert into action values (18,'Devise');
insert into action values (19,'Période');
insert into action values (20,'Voir la balance des comptes');
-- task 3374
insert into jrn_action (ja_id,ja_name,ja_desc,ja_url,ja_action,ja_jrn_type)
values (40,'Soldes','Voir les soldes des comptes en banques',
'user_jrn.php','action=solde','FIN');
-- always last line
update version set val=5;

View file

@ -0,0 +1,49 @@
begin;
insert into parm_code values ('DEP_PRIV',4890,'Depense a charge du gerant');
insert into attr_def values (31,'Depense à  charge du gérant (partie privée)');
alter table quant_purchase add qp_dep_priv numeric(20,4) default 0.0;
CREATE FUNCTION insert_quant_purchase(p_internal text, p_j_id numeric, p_fiche character varying, p_quant numeric, p_price numeric, p_vat numeric, p_vat_code integer, p_nd_amount numeric, p_nd_tva numeric, p_nd_tva_recup numeric,p_dep_priv numeric , p_client character varying) RETURNS void
AS $$
declare
fid_client integer;
fid_good integer;
begin
select f_id into fid_client from
attr_value join jnt_fic_att_value using (jft_id) where ad_id=23 and av_text=upper(p_client);
select f_id into fid_good from
attr_value join jnt_fic_att_value using (jft_id) where ad_id=23 and av_text=upper(p_fiche);
insert into quant_purchase
(qp_internal,
j_id,
qp_fiche,
qp_quantite,
qp_price,
qp_vat,
qp_vat_code,
qp_nd_amount,
qp_nd_tva,
qp_nd_tva_recup,
qp_supplier,
qp_dep_priv)
values
(p_internal,
p_j_id,
fid_good,
p_quant,
p_price,
p_vat,
p_vat_code,
p_nd_amount,
p_nd_tva,
p_nd_tva_recup,
fid_client,
p_dep_priv);
return;
end;
$$
LANGUAGE plpgsql;
update version set val=41;
commit;

View file

@ -0,0 +1,99 @@
begin;
CREATE TABLE del_action
(
del_id serial NOT NULL,
del_name text NOT NULL,
del_time timestamp,
CONSTRAINT del_action_pkey PRIMARY KEY (del_id)
) ;
CREATE TABLE del_jrn
(
jr_id int4,
jr_def_id int4,
jr_montant numeric(20,4),
jr_comment text,
jr_date date,
jr_grpt_id int4,
jr_internal text,
jr_tech_date timestamp,
jr_tech_per int4,
jrn_ech date,
jr_ech date,
jr_rapt text,
jr_valid bool,
jr_opid int4,
jr_c_opid int4,
jr_pj oid,
jr_pj_name text,
jr_pj_type text,
del_jrn_date timestamp
) ;
ALTER TABLE del_jrn
ADD CONSTRAINT jr_id PRIMARY KEY(jr_id);
CREATE TABLE del_jrnx
(
j_id int4,
j_date date,
j_montant numeric(20,4),
j_poste poste_comptable,
j_grpt int4,
j_rapt text,
j_jrn_def int4,
j_debit bool,
j_text text,
j_centralized bool,
j_internal text,
j_tech_user text,
j_tech_date timestamp,
j_tech_per int4,
j_qcode text
) ;
ALTER TABLE del_jrnx
ADD CONSTRAINT j_id PRIMARY KEY(j_id);
CREATE OR REPLACE FUNCTION jrn_del()
RETURNS "trigger" AS
$BODY$
declare
row jrn%ROWTYPE;
begin
row:=OLD;
insert into del_jrn select *,now() from jrn where jr_id=row.jr_id;
return row;
end;
$BODY$
LANGUAGE 'plpgsql' VOLATILE;
CREATE OR REPLACE FUNCTION jrnx_del()
RETURNS "trigger" AS
$BODY$
declare
row jrnx%ROWTYPE;
begin
row:=OLD;
insert into del_jrnx select * from jrnx where j_id=row.j_id;
return row;
end;
$BODY$
LANGUAGE 'plpgsql' VOLATILE;
CREATE TRIGGER t_jrnx_del
BEFORE DELETE
ON jrnx
FOR EACH ROW
EXECUTE PROCEDURE jrnx_del();
CREATE TRIGGER t_jrn_del
BEFORE DELETE
ON jrn
FOR EACH ROW
EXECUTE PROCEDURE jrn_del();
update version set val=42;
commit;

View file

@ -0,0 +1,12 @@
begin;
delete from tva_rate where tva_id in (select tva_id from tva_rate group by tva_id having count(tva_id) > 1);
update quant_sold set qs_vat_code = null where qs_vat_Code not in (select tva_id from tva_rate);
update quant_purchase set qp_vat_code = null where qp_vat_Code not in (select tva_id from tva_rate);
alter table tva_rate add constraint tva_id_pk primary key (tva_id);
alter table quant_purchase add constraint qp_vat_code_fk foreign key(qp_vat_code) references tva_rate(tva_id);
alter table quant_sold add constraint qs_vat_code_fk foreign key(qs_vat_code) references tva_rate(tva_id);
update version set val=43;
commit;

View file

@ -0,0 +1,4 @@
begin;
delete from bud_detail where bd_id not in (select bd_id from bud_detail_periode);
update version set val=44;
commit;

View file

@ -0,0 +1,57 @@
begin;
CREATE OR REPLACE FUNCTION insert_jrnx(p_date "varchar", p_montant "numeric", p_poste int4, p_grpt int4, p_jrn_def int4, p_debit bool, p_tech_user text, p_tech_per int4, p_qcode text)
RETURNS void AS
$BODY$
declare
sCode varchar;
nCount_qcode integer;
begin
sCode=trim(p_qcode);
-- if p_qcode is empty try to find one
if length(sCode) = 0 or p_qcode is null then
select count(*) into nCount_qcode
from vw_poste_qcode where j_poste=p_poste;
-- if we find only one q_code for a accountancy account
-- then retrieve it
if nCount_qcode = 1 then
select j_qcode into sCode
from vw_poste_qcode where j_poste=p_poste;
else
sCode=NULL;
end if;
end if;
insert into jrnx
(
j_date,
j_montant,
j_poste,
j_grpt,
j_jrn_def,
j_debit,
j_tech_user,
j_tech_per,
j_qcode
) values
(
to_date(p_date,'DD.MM.YYYY'),
p_montant,
p_poste,
p_grpt,
p_jrn_def,
p_debit,
p_tech_user,
p_tech_per,
sCode
);
return;
end;
$BODY$
LANGUAGE 'plpgsql' VOLATILE;
update version set val=45;

View file

@ -0,0 +1,124 @@
begin;
CREATE or replace FUNCTION account_insert(p_f_id integer, p_account poste_comptable) RETURNS integer
AS $$
declare
nParent tmp_pcmn.pcm_val_parent%type;
sName varchar;
nNew tmp_pcmn.pcm_val%type;
bAuto bool;
nFd_id integer;
nCount integer;
begin
if length(trim(p_account::text)) != 0 then
raise debug 'p_account is not empty';
select count(*) into nCount from tmp_pcmn where pcm_val=p_account;
raise notice 'found in tmp_pcm %',nCount;
if nCount !=0 then
raise notice 'this account exists in tmp_pcmn ';
perform attribut_insert(p_f_id,5,to_char(p_account,'999999999999999999999999'));
else
-- account doesn't exist, create it
select av_text into sName from
attr_value join jnt_fic_att_value using (jft_id)
where
ad_id=1 and f_id=p_f_id;
nParent:=account_parent(p_account);
insert into tmp_pcmn(pcm_val,pcm_lib,pcm_val_parent) values (p_account,sName,nParent);
perform attribut_insert(p_f_id,5,to_char(p_account,'999999999999999999999999'));
end if;
else
raise notice 'p_account is empty';
select fd_id into nFd_id from fiche where f_id=p_f_id;
bAuto:= account_auto(nFd_id);
if bAuto = true then
raise notice 'account generated automatically';
nNew:=account_compute(p_f_id);
raise notice 'nNew %', nNew;
select av_text into sName from
attr_value join jnt_fic_att_value using (jft_id)
where
ad_id=1 and f_id=p_f_id;
nParent:=account_parent(nNew);
perform account_add (nNew,sName);
perform attribut_insert(p_f_id,5,to_char(nNew,'999999999999999999999999'));
else
-- if there is an account_base then it is the default
select fd_class_base::text into nNew from fiche_def join fiche using (fd_id) where f_id=p_f_id;
if nNew is null or length(trim(nNew)) = 0 then
raise notice 'count is null';
perform attribut_insert(p_f_id,5,null);
else
perform attribut_insert(p_f_id,5,to_char(nNew,'999999999999999999999999'));
end if;
end if;
end if;
return 0;
end;
$$
LANGUAGE plpgsql;
CREATE or replace FUNCTION account_parent(p_account poste_comptable) RETURNS poste_comptable
AS $$
declare
nParent tmp_pcmn.pcm_val_parent%type;
sParent varchar;
nCount integer;
begin
sParent:=to_char(p_account,'9999999999999999');
sParent:=trim(sParent::text);
nParent:=0;
while nParent = 0 loop
select count(*) into nCount
from tmp_pcmn
where
pcm_val = to_number(sParent,'9999999999999999');
if nCount != 0 then
nParent:=to_number(sParent,'9999999999999999');
end if;
sParent:= substr(sParent,1,length(sParent)-1);
if length(sParent) <= 0 then
raise exception 'Impossible de trouver le compte parent pour %',p_account;
end if;
end loop;
raise notice 'account_parent : Parent is %',nParent;
return nParent;
end;
$$
LANGUAGE plpgsql;
CREATE or replace FUNCTION account_update(p_f_id integer, p_account poste_comptable) RETURNS integer
AS $$
declare
nMax fiche.f_id%type;
nCount integer;
nParent tmp_pcmn.pcm_val_parent%type;
sName varchar;
nJft_id attr_value.jft_id%type;
begin
if length(trim(p_account::text)) != 0 then
select count(*) into nCount from tmp_pcmn where pcm_val=p_account;
if nCount = 0 then
select av_text into sName from
attr_value join jnt_fic_att_value using (jft_id)
where
ad_id=1 and f_id=p_f_id;
nParent:=account_parent(p_account);
insert into tmp_pcmn(pcm_val,pcm_lib,pcm_val_parent) values (p_account,sName,nParent);
end if;
end if;
select jft_id into njft_id from jnt_fic_att_value where f_id=p_f_id and ad_id=5;
update attr_value set av_text=p_account where jft_id=njft_id;
return njft_id;
end;
$$
LANGUAGE plpgsql;
update version set val=47;
commit;

View file

@ -0,0 +1,3 @@
begin;
update version set val=47;
commit;

View file

@ -0,0 +1,58 @@
begin;
drop function insert_jrnx(varchar,numeric,integer,integer,integer,boolean,text,integer,text);
CREATE or replace FUNCTION insert_jrnx(p_date character varying, p_montant numeric, p_poste poste_comptable, p_grpt integer, p_jrn_def integer, p_debit boolean, p_tech_user text, p_tech_per integer, p_qcode text) RETURNS void
AS $$
declare
sCode varchar;
nCount_qcode integer;
begin
sCode=trim(p_qcode);
-- if p_qcode is empty try to find one
if length(sCode) = 0 or p_qcode is null then
select count(*) into nCount_qcode
from vw_poste_qcode where j_poste=p_poste::text;
-- if we find only one q_code for a accountancy account
-- then retrieve it
if nCount_qcode = 1 then
select j_qcode into sCode
from vw_poste_qcode where j_poste=p_poste;
else
sCode=NULL;
end if;
end if;
insert into jrnx
(
j_date,
j_montant,
j_poste,
j_grpt,
j_jrn_def,
j_debit,
j_tech_user,
j_tech_per,
j_qcode
) values
(
to_date(p_date,'DD.MM.YYYY'),
p_montant,
p_poste,
p_grpt,
p_jrn_def,
p_debit,
p_tech_user,
p_tech_per,
sCode
);
return;
end;
$$
LANGUAGE plpgsql;
update version set val=48;
commit;

View file

@ -0,0 +1,71 @@
begin;
create sequence s_tva start with 1000;
alter table tva_rate alter tva_id set default nextval('s_tva');
alter table form drop constraint "$1";
alter table form add constraint formdef_fk foreign key (fo_fr_id) references formdef(fr_id) on update cascade on delete cascade;
drop function tva_insert(integer,text,numeric,text,text);
CREATE or replace 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;
if nCount = 0 then return 4; end if;
select count(*) into nCount from tmp_pcmn where pcm_val=credit;
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;
CREATE TABLE todo_list (
tl_id integer NOT NULL,
tl_date date NOT NULL,
tl_title text NOT NULL,
tl_desc text,
use_login text NOT NULL
);
COMMENT ON TABLE todo_list IS 'Todo list';
CREATE SEQUENCE todo_list_tl_id_seq
START WITH 1
INCREMENT BY 1
NO MAXVALUE
NO MINVALUE
CACHE 1;
ALTER TABLE todo_list ALTER COLUMN tl_id SET DEFAULT nextval('todo_list_tl_id_seq'::regclass);
ALTER TABLE ONLY todo_list ADD CONSTRAINT todo_list_pkey PRIMARY KEY (tl_id);
update version set val=49;
commit;

View file

@ -0,0 +1,23 @@
begin;
alter table jnt_fic_attr add column jnt_order int;
update jnt_fic_attr set jnt_order = 1;
alter table jnt_fic_attr alter jnt_order set not null;
update jnt_fic_attr set jnt_order = 4 where ad_id=5;
update jnt_fic_attr set jnt_order = 120 where ad_id=6;
update jnt_fic_attr set jnt_order = 130 where ad_id=7;
update jnt_fic_attr set jnt_order = 20 where ad_id=9;
update jnt_fic_attr set jnt_order = 30 where ad_id=13;
update jnt_fic_attr set jnt_order = 40 where ad_id=14;
update jnt_fic_attr set jnt_order = 70 where ad_id=16;
update jnt_fic_attr set jnt_order = 80 where ad_id=17;
update jnt_fic_attr set jnt_order = 90 where ad_id=18;
update jnt_fic_attr set jnt_order = 400 where ad_id=23;
update jnt_fic_attr set jnt_order = 60 where ad_id=24;
update jnt_fic_attr set jnt_order = 100 where ad_id=26;
update jnt_fic_attr set jnt_order = 110 where ad_id=27;
update jnt_fic_attr set jnt_order = 50 where ad_id=15;
update jnt_fic_attr set jnt_order = 30 where ad_id=5;
update jnt_fic_attr set jnt_order = 0 where ad_id=1;
update version set val=50;
commit;

View file

@ -0,0 +1,97 @@
-- create vw_client view
create view vw_client as
select a.f_id,
a.av_text as name,
b.av_text as tva_num,c.av_text as poste_comptable,
d.av_text as rue,
e.av_text as code_postal,
f.av_text as pays,
g.av_text as telephone,
h.av_text as email
from (
select * from fiche join fiche_def using (fd_id)
join fiche_def_ref using (frd_id)
join jnt_fic_att_value using (f_id) join attr_value using (jft_id) where ad_id=1 ) a
left join (
select * from fiche join fiche_def using (fd_id)
join fiche_def_ref using (frd_id)
join jnt_fic_att_value using (f_id) join attr_value using (jft_id) where ad_id=13 ) b using (f_id)
left join (
select * from fiche join fiche_def using (fd_id)
join fiche_def_ref using (frd_id)
join jnt_fic_att_value using (f_id)
join attr_value using (jft_id)
where ad_id=5 ) c using (f_id)
left join (
select * from fiche join fiche_def using (fd_id)
join fiche_def_ref using (frd_id)
join jnt_fic_att_value using (f_id)
join attr_value using (jft_id)
where ad_id=14 ) d using (f_id)
left join (
select * from fiche join fiche_def using (fd_id)
join fiche_def_ref using (frd_id)
join jnt_fic_att_value using (f_id)
join attr_value using (jft_id)
where ad_id=15 ) e using (f_id)
left join (
select * from fiche join fiche_def using (fd_id)
join fiche_def_ref using (frd_id)
join jnt_fic_att_value using (f_id)
join attr_value using (jft_id)
where ad_id=16 ) f using (f_id)
left join (
select * from fiche join fiche_def using (fd_id)
join fiche_def_ref using (frd_id)
join jnt_fic_att_value using (f_id)
join attr_value using (jft_id)
where ad_id=17 ) g using (f_id)
left join (
select * from fiche join fiche_def using (fd_id)
join fiche_def_ref using (frd_id)
join jnt_fic_att_value using (f_id)
join attr_value using (jft_id)
where ad_id=18 ) h using (f_id)
where a.frd_id=9;
-- all the min attribut for card reference
create view vw_fiche_min
as select frd_id, ad_id, ad_text, frd_text, frd_class_base
from
attr_min join attr_Def using (ad_id)
join fiche_Def_ref using (frd_id);
-- definition for card
create view vw_fiche_Def as
SELECT fd_id,
ad_id,
ad_text,
fd_class_base,
fd_label,
fd_create_account,
frd_id
FROM jnt_fic_attr
JOIN attr_def USING (ad_id)
JOIN fiche_def USING (fd_id);
-- comments
comment on view vw_fiche_min is 'minimum attribut for reference card';
comment on view vw_fiche_def is 'all the attributs for card family';
comment on view vw_client is 'minimum attribut for the customer (frd_id=9)';
-- new table : parameter
create table parameter (
pr_id text primary key,
pr_value text
);
insert into parameter (pr_id) values ('MY_NAME');
insert into parameter (pr_id) values ('MY_CP');
insert into parameter (pr_id) values ('MY_COMMUNE');
insert into parameter (pr_id) values ('MY_TVA');
insert into parameter (pr_id) values ('MY_STREET');
insert into parameter (pr_id) values ('MY_NUMBER');
update version set val=6;

View file

@ -0,0 +1,57 @@
begin;
CREATE OR REPLACE FUNCTION insert_jrnx(p_date character varying, p_montant numeric, p_poste poste_comptable, p_grpt integer, p_jrn_def integer, p_debit boolean, p_tech_user text, p_tech_per integer, p_qcode text)
RETURNS void AS
$BODY$
declare
sCode varchar;
nCount_qcode integer;
begin
sCode=trim(p_qcode);
-- if p_qcode is empty try to find one
if length(sCode) = 0 or p_qcode is null then
select count(*) into nCount_qcode
from vw_poste_qcode where j_poste=p_poste::text;
-- if we find only one q_code for a accountancy account
-- then retrieve it
if nCount_qcode = 1 then
select j_qcode::text into sCode
from vw_poste_qcode where j_poste=p_poste::text;
else
sCode=NULL;
end if;
end if;
insert into jrnx
(
j_date,
j_montant,
j_poste,
j_grpt,
j_jrn_def,
j_debit,
j_tech_user,
j_tech_per,
j_qcode
) values
(
to_date(p_date,'DD.MM.YYYY'),
p_montant,
p_poste,
p_grpt,
p_jrn_def,
p_debit,
p_tech_user,
p_tech_per,
sCode
);
return;
end;
$BODY$
LANGUAGE 'plpgsql' VOLATILE;
update version set val=51;
commit;

View file

@ -0,0 +1,4 @@
begin;
insert into parameter values ('MY_STRICT','N');
update version set val=52;
commit;

View file

@ -0,0 +1,37 @@
begin;
CREATE TABLE mod_payment (
mp_id serial,
mp_lib text NOT NULL,
mp_jrn_def_id integer NOT NULL,
mp_type character varying(3) NOT NULL,
mp_fd_id bigint ,
mp_qcode text
);
COMMENT ON TABLE mod_payment IS 'Contains the different media of payment and the corresponding ledger';
INSERT INTO mod_payment (mp_id, mp_lib, mp_jrn_def_id, mp_type, mp_fd_id, mp_qcode) VALUES (2, 'Caisse', 1, 'VEN', NULL, NULL);
INSERT INTO mod_payment (mp_id, mp_lib, mp_jrn_def_id, mp_type, mp_fd_id, mp_qcode) VALUES (4, 'Caisse', 1, 'ACH', NULL, NULL);
INSERT INTO mod_payment (mp_id, mp_lib, mp_jrn_def_id, mp_type, mp_fd_id, mp_qcode) VALUES (1, 'Paiement électronique', 1, 'VEN', NULL, NULL);
INSERT INTO mod_payment (mp_id, mp_lib, mp_jrn_def_id, mp_type, mp_fd_id, mp_qcode) VALUES (3, 'Par gérant ou administrateur', 2, 'ACH', NULL, NULL);
ALTER TABLE ONLY mod_payment
ADD CONSTRAINT mod_payment_pkey PRIMARY KEY (mp_id);
ALTER TABLE ONLY mod_payment
ADD CONSTRAINT mod_payment_mp_fd_id_fkey FOREIGN KEY (mp_fd_id) REFERENCES fiche_def(fd_id);
ALTER TABLE ONLY mod_payment
ADD CONSTRAINT mod_payment_mp_jrn_def_id_fkey FOREIGN KEY (mp_jrn_def_id) REFERENCES jrn_def(jrn_def_id);
INSERT INTO document_type (dt_id, dt_value) VALUES (10, 'Note de frais');
insert into fiche_def_ref (frd_id,frd_text) values (25,'Compte Salarié / Administrateur');
insert into attr_min values (25,1);
insert into attr_min values(25,4);
insert into attr_min values (25,3);
insert into attr_min values(25,5);
insert into attr_min values (25,15);
insert into attr_min values(25,16);
insert into attr_min values(25,24);
insert into attr_min values(25,23);
update version set val=53;
commit;

View file

@ -0,0 +1,52 @@
begin;
CREATE OR REPLACE FUNCTION html_quote(p_string text)
RETURNS text AS
$BODY$
declare
r text;
begin
r:=p_string;
r:=replace(r,'<','&lt;');
r:=replace(r,'>','&gt;');
r:=replace(r,'''','&quot;');
return r;
end;$BODY$
LANGUAGE plpgsql;
COMMENT ON FUNCTION html_quote(text) IS 'remove harmfull HTML char';
CREATE OR REPLACE FUNCTION tva_modify(integer, text, numeric, text, text)
RETURNS integer AS
$BODY$
declare
p_tva_id alias for $1;
p_tva_label alias for $2;
p_tva_rate alias for $3;
p_tva_comment alias for $4;
p_tva_poste alias for $5;
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;
update tva_rate set tva_label=p_tva_label,tva_rate=p_tva_rate,tva_comment=p_tva_comment,tva_poste=p_tva_poste
where tva_id=p_tva_id;
return 0;
end;
$BODY$
LANGUAGE plpgsql;
update version set val=54;
commit;

View file

@ -0,0 +1,52 @@
begin;
create or replace function fiche_attribut_synchro (p_fd_id fiche_def.fd_id%TYPE) returns void as
$BODY$
declare
-- this sql gives the f_id and the missing attribute (ad_id)
list_missing cursor for select f_id,fd_id,ad_id,jnt_order from jnt_fic_attr join fiche as A using (fd_id) where fd_id=p_fd_id and ad_id not in (select ad_id from fiche join jnt_fic_att_value using (f_id) where fd_id=jnt_fic_attr.fd_id and A.f_id=f_id);
rec record;
-- value of the last insert
jnt jnt_fic_att_value%ROWTYPE;
begin
open list_missing;
loop
fetch list_missing into rec;
IF NOT FOUND then
exit;
end if;
-- insert a value into jnt_fic_att_value
insert into jnt_fic_att_value (f_id,ad_id) values (rec.f_id,rec.ad_id) returning * into jnt;
-- now we insert into attr_value
insert into attr_value values (jnt.jft_id,'');
end loop;
close list_missing;
end;
$BODY$ language plpgsql;
create or replace function attribute_correct_order () returns void as
$BODY$
declare
crs_correct cursor for select A.jnt_id,A.jnt_order from jnt_fic_attr as A join jnt_fic_attr as B using (fd_id) where A.jnt_order=B.jnt_order and A.jnt_id > B.jnt_id;
rec record;
begin
open crs_correct;
loop
fetch crs_correct into rec;
if NOT FOUND then
close crs_correct;
return;
end if;
update jnt_fic_attr set jnt_order=jnt_order + 1 where jnt_id = rec.jnt_id;
end loop;
close crs_correct;
perform attribute_correct_order ();
end;
$BODY$ language plpgsql;
select fiche_attribut_synchro(fd_id) from fiche_def;
select attribute_correct_order();
update version set val=55;
commit;

View file

@ -0,0 +1,6 @@
begin;
alter table import_tmp alter bq_account type text;
update version set val=56;
commit;

View file

@ -0,0 +1,168 @@
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;
end;
$BODY$
LANGUAGE 'plpgsql';
select create_missing_sequence();
CREATE OR REPLACE FUNCTION drop_index(p_constraint character varying)
RETURNS void AS
$BODY$
declare
nCount integer;
begin
select count(*) into nCount from pg_indexes where indexname=p_constraint;
if nCount = 1 then
execute 'drop index '||p_constraint ;
end if;
end;
$BODY$
LANGUAGE 'plpgsql';
-- on dossier
insert into parameter (pr_id,pr_value) values ('MY_TVA_USE','Y');
insert into parameter (pr_id,pr_value) values ('MY_PJ_SUGGEST','Y');
-- new security
alter table action add ac_module text;
alter table action add ac_code varchar(9);
create unique index uj_login_uj_jrn_id on user_sec_jrn(uj_login,uj_jrn_id);
-- PostgreSQL database dump
--
delete from user_Sec_act;
delete from action;
COMMENT ON TABLE action IS 'The different privileges';
select drop_index('x_act');
INSERT INTO action (ac_id, ac_description, ac_module, ac_code) VALUES (100, 'Accès en lecture', 'budget', 'BUDLEC');
INSERT INTO action (ac_id, ac_description, ac_module, ac_code) VALUES (110, 'Création hypothèse', 'budget', 'BUDHYP');
INSERT INTO action (ac_id, ac_description, ac_module, ac_code) VALUES (120, 'Création de fiche', 'budget', 'BUDFIC');
INSERT INTO action (ac_id, ac_description, ac_module, ac_code) VALUES (130, 'Impression', 'budget', 'BUDIMP');
INSERT INTO action (ac_id, ac_description, ac_module, ac_code) VALUES (210, 'Ajout de plan analytique', 'compta_anal', 'CAPA');
INSERT INTO action (ac_id, ac_description, ac_module, ac_code) VALUES (220, 'Ajout de poste analytique', 'compta_anal', 'CAPO');
INSERT INTO action (ac_id, ac_description, ac_module, ac_code) VALUES (230, 'Ajout de groupe analytique', 'compta_anal', 'CAGA');
INSERT INTO action (ac_id, ac_description, ac_module, ac_code) VALUES (235, 'Ajout d''operation diverses', 'compta_anal', 'CAOD');
INSERT INTO action (ac_id, ac_description, ac_module, ac_code) VALUES (240, 'Impression', 'compta_anal', 'CAIMP');
INSERT INTO action (ac_id, ac_description, ac_module, ac_code) VALUES (300, 'Gestion', 'gestion', 'GESTION');
INSERT INTO action (ac_id, ac_description, ac_module, ac_code) VALUES (305, 'Import en Banque', 'gestion', 'GEBQ');
INSERT INTO action (ac_id, ac_description, ac_module, ac_code) VALUES (307, 'Effacement d''opération', 'gestion', 'GEOP');
INSERT INTO action (ac_id, ac_description, ac_module, ac_code) VALUES (310, 'Courrier (lecture & écriture)', 'gestion', 'GECOUR');
INSERT INTO action (ac_id, ac_description, ac_module, ac_code) VALUES (311, 'Fournisseur', 'gestion', 'GESUPPL');
INSERT INTO action (ac_id, ac_description, ac_module, ac_code) VALUES (312, 'Client', 'gestion', 'GECUST');
-- INSERT INTO action (ac_id, ac_description, ac_module, ac_code) VALUES (320, 'gestion de stock', 'gestion', 'GESTOCK');
INSERT INTO action (ac_id, ac_description, ac_module, ac_code) VALUES (700, 'Rapport', 'impression', 'IMPRAP');
INSERT INTO action (ac_id, ac_description, ac_module, ac_code) VALUES (710, 'Journaux', 'impression', 'IMPJRN');
INSERT INTO action (ac_id, ac_description, ac_module, ac_code) VALUES (720, 'Fiche', 'impression', 'IMPFIC');
INSERT INTO action (ac_id, ac_description, ac_module, ac_code) VALUES (730, 'Poste', 'impression', 'IMPPOSTE');
INSERT INTO action (ac_id, ac_description, ac_module, ac_code) VALUES (740, 'Bilan', 'impression', 'IMPBIL');
INSERT INTO action (ac_id, ac_description, ac_module, ac_code) VALUES (750, 'Balance', 'impression', 'IMPBAL');
INSERT INTO action (ac_id, ac_description, ac_module, ac_code) VALUES (800, 'Ajout de fiche', 'fiche', 'FICADD');
INSERT INTO action (ac_id, ac_description, ac_module, ac_code) VALUES (805, 'Création, modification et effacement de fiche', 'fiche', 'FIC');
INSERT INTO action (ac_id, ac_description, ac_module, ac_code) VALUES (910, 'création, modification et effacement de catégorie de fiche', 'fiche', 'FICCAT');
INSERT INTO action (ac_id, ac_description, ac_module, ac_code) VALUES (1100, 'Mode comptabilité analytique', 'parametre', 'PARCA');
INSERT INTO action (ac_id, ac_description, ac_module, ac_code) VALUES (1110, 'Ajout de période', 'parametre', 'PARPER');
INSERT INTO action (ac_id, ac_description, ac_module, ac_code) VALUES (1120, 'Catégorie des fiches', 'parametre', 'PARFIC');
INSERT INTO action (ac_id, ac_description, ac_module, ac_code) VALUES (1130, 'Document', 'parametre', 'PARDOC');
INSERT INTO action (ac_id, ac_description, ac_module, ac_code) VALUES (1140, 'Modification journaux', 'parametre', 'PARJRN');
INSERT INTO action (ac_id, ac_description, ac_module, ac_code) VALUES (1150, 'TVA', 'parametre', 'PARTVA');
INSERT INTO action (ac_id, ac_description, ac_module, ac_code) VALUES (1160, 'Moyen de paiement', 'parametre', 'PARMP');
INSERT INTO action (ac_id, ac_description, ac_module, ac_code) VALUES (1180, 'Clôture ', 'parametre', 'PARCLO');
INSERT INTO action (ac_id, ac_description, ac_module, ac_code) VALUES (1185, 'Changement du plan comptable ', 'parametre', 'PARPCMN');
INSERT INTO action (ac_id, ac_description, ac_module, ac_code) VALUES (1170, 'Poste Comptable de base', 'parametre', 'PARPOS');
INSERT INTO action (ac_id, ac_description, ac_module, ac_code) VALUES (1190, 'Centralisation', 'parametre', 'PARCENT');
INSERT INTO action (ac_id, ac_description, ac_module, ac_code) VALUES (1200, 'Écriture d''ouverture', 'parametre', 'PAREO');
INSERT INTO action (ac_id, ac_description, ac_module, ac_code) VALUES (1210, 'Mode strict', 'parametre', 'PARSTR');
INSERT INTO action (ac_id, ac_description, ac_module, ac_code) VALUES (1220, 'Coordonnées société', 'parametre', 'PARCOORD');
INSERT INTO action (ac_id, ac_description, ac_module, ac_code) VALUES (1230, 'Création de rapport', 'parametre', 'PARRAP');
INSERT INTO action (ac_id, ac_description, ac_module, ac_code) VALUES (1240, 'Effacement et création d''opération prédéfinie', 'parametre', 'PARPREDE');
INSERT INTO action (ac_id, ac_description, ac_module, ac_code) VALUES (1245, 'Sécurité du dossier', 'parametre', 'PARSEC');
INSERT INTO action (ac_id, ac_description, ac_module, ac_code) VALUES (1500, 'Stock (lecture)', 'stock', 'STOLE');
INSERT INTO action (ac_id, ac_description, ac_module, ac_code) VALUES (1510, 'Stock (changement)', 'stock', 'STOWRITE');
ALTER TABLE jrn ADD COLUMN jr_pj_number text;
ALTER TABLE del_jrn ADD COLUMN jr_pj_number text;
ALTER TABLE jrn_def ADD COLUMN jrn_def_pj_pref text;
update jrn_def set jrn_def_pj_pref=jrn_def_type ;
CREATE OR REPLACE FUNCTION jrn_del()
RETURNS trigger AS
$BODY$
declare
row jrn%ROWTYPE;
begin
row:=OLD;
insert into del_jrn ( jr_id,
jr_def_id,
jr_montant,
jr_comment,
jr_date,
jr_grpt_id,
jr_internal,
jr_tech_date,
jr_tech_per,
jrn_ech,
jr_ech,
jr_rapt,
jr_valid,
jr_opid,
jr_c_opid,
jr_pj,
jr_pj_name,
jr_pj_type,
jr_pj_number,
del_jrn_date)
select jr_id,
jr_def_id,
jr_montant,
jr_comment,
jr_date,
jr_grpt_id,
jr_internal,
jr_tech_date,
jr_tech_per,
jrn_ech,
jr_ech,
jr_rapt,
jr_valid,
jr_opid,
jr_c_opid,
jr_pj,
jr_pj_name,
jr_pj_type,
jr_pj_number
,now() from jrn where jr_id=row.jr_id;
return row;
end;
$BODY$
LANGUAGE 'plpgsql' ;
update version set val=57;
commit;

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

@ -0,0 +1,7 @@
begin;
INSERT INTO format_csv_banque(name, include_file) VALUES('VMS Keytrade', 'keytrade_be.inc.php');
update version set val=59;
commit;

View file

@ -0,0 +1,414 @@
begin;
insert into parameter(pr_id,pr_value) values ('MY_CHECK_PERIODE','Y');
alter table jrn add jr_mt text ;
update jrn set jr_mt= extract (microseconds from jr_tech_date);
create index x_mt on jrn(jr_mt);
DROP FUNCTION insert_quant_purchase(text, numeric, character varying, numeric, numeric,numeric, integer, numeric, numeric, numeric, character varying);
DROP FUNCTION insert_quant_sold(text, character varying, numeric, numeric, numeric, integer, character varying);
alter table groupe_analytique add constraint fk_pa_id foreign key(pa_id) references plan_analytique(pa_id) on delete cascade;
alter table stock_goods add constraint fk_stock_good_f_id foreign key(f_id) references fiche(f_id) ;
drop table invoice;
DROP FUNCTION account_parent(poste_comptable);
CREATE FUNCTION account_parent(p_account poste_comptable)
RETURNS poste_comptable AS
$BODY$
declare
nParent tmp_pcmn.pcm_val_parent%type;
sParent varchar;
nCount integer;
begin
sParent:=to_char(p_account,'9999999999999999');
sParent:=trim(sParent::text);
nParent:=0;
while nParent = 0 loop
select count(*) into nCount
from tmp_pcmn
where
pcm_val = to_number(sParent,'9999999999999999');
if nCount != 0 then
nParent:=to_number(sParent,'9999999999999999');
exit;
end if;
sParent:= substr(sParent,1,length(sParent)-1);
if length(sParent) <= 0 then
raise exception 'Impossible de trouver le compte parent pour %',p_account;
end if;
end loop;
raise notice 'account_parent : Parent is %',nParent;
return nParent;
end;
$BODY$
LANGUAGE 'plpgsql';
alter table document drop column d_state;
--alter table action_gestion set ag_title type text;
ALTER TABLE action_gestion ADD COLUMN ag_hour text default null;
ALTER TABLE action_gestion ADD COLUMN ag_priority integer;
ALTER TABLE action_gestion ALTER COLUMN ag_priority SET DEFAULT 2;
ALTER TABLE action_gestion ADD COLUMN ag_dest text;
ALTER TABLE action_gestion ADD COLUMN ag_owner text;
ALTER TABLE action_gestion ADD COLUMN ag_contact int8;
CREATE OR REPLACE FUNCTION action_gestion_ins_upd()
RETURNS trigger AS
$BODY$
begin
NEW.ag_title := substr(trim(NEW.ag_title),1,70);
NEW.ag_hour := substr(trim(NEW.ag_hour),1,5);
return NEW;
end;
$BODY$
LANGUAGE 'plpgsql' VOLATILE;
CREATE TRIGGER action_gestion_t_insert_update
BEFORE INSERT OR UPDATE
ON action_gestion
FOR EACH ROW
EXECUTE PROCEDURE action_gestion_ins_upd();
COMMENT ON TRIGGER action_gestion_t_insert_update ON action_gestion IS 'Truncate the column ag_title to 70 char';
ALTER TABLE action_gestion ADD COLUMN ag_state integer;
update action_gestion set f_id_dest=f_id_exp where f_id_exp != 0;
alter table action_gestion drop column f_id_exp;
UPDATE document_state SET s_value= 'Clôturé' WHERE s_id=1;
UPDATE document_state SET s_value= 'A suivre' WHERE s_id=2;
UPDATE document_state SET s_value= 'A faire' WHERE s_id=3;
UPDATE document_state SET s_value= 'Abandonné' WHERE s_id=4;
CREATE TABLE action_detail
(
ad_id serial,
f_id int8,
ad_text text,
ad_pu numeric(20,4) DEFAULT 0,
ad_quant numeric(20,4) DEFAULT 0,
ad_tva_id integer DEFAULT 0,
ad_tva_amount numeric(20,4) DEFAULT 0,
ad_total_amount numeric(20,4) DEFAULT 0,
ag_id integer NOT NULL DEFAULT 0,
CONSTRAINT action_detail_pkey PRIMARY KEY (ad_id),
CONSTRAINT action_detail_ag_id_fkey FOREIGN KEY (ag_id)
REFERENCES action_gestion (ag_id) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE
);
COMMENT ON TABLE action_detail IS 'Detail of action_gestion, see class Action_Detail';
-- trim the qcode
CREATE OR REPLACE FUNCTION insert_quant_purchase(p_internal text, p_j_id numeric, p_fiche character varying, p_quant numeric, p_price numeric, p_vat numeric, p_vat_code integer, p_nd_amount numeric, p_nd_tva numeric, p_nd_tva_recup numeric, p_dep_priv numeric, p_client character varying)
RETURNS void AS
$BODY$
declare
fid_client integer;
fid_good integer;
begin
select f_id into fid_client from
attr_value join jnt_fic_att_value using (jft_id) where ad_id=23 and av_text=upper(trim(p_client));
select f_id into fid_good from
attr_value join jnt_fic_att_value using (jft_id) where ad_id=23 and av_text=upper(trim(p_fiche));
insert into quant_purchase
(qp_internal,
j_id,
qp_fiche,
qp_quantite,
qp_price,
qp_vat,
qp_vat_code,
qp_nd_amount,
qp_nd_tva,
qp_nd_tva_recup,
qp_supplier,
qp_dep_priv)
values
(p_internal,
p_j_id,
fid_good,
p_quant,
p_price,
p_vat,
p_vat_code,
p_nd_amount,
p_nd_tva,
p_nd_tva_recup,
fid_client,
p_dep_priv);
return;
end;
$BODY$
LANGUAGE 'plpgsql';
CREATE OR REPLACE FUNCTION insert_quant_sold(p_internal text, p_jid numeric, p_fiche character varying, p_quant numeric, p_price numeric, p_vat numeric, p_vat_code integer, p_client character varying)
RETURNS void AS
$BODY$
declare
fid_client integer;
fid_good integer;
begin
select f_id into fid_client from
attr_value join jnt_fic_att_value using (jft_id) where ad_id=23 and av_text=upper(trim(p_client));
select f_id into fid_good from
attr_value join jnt_fic_att_value using (jft_id) where ad_id=23 and av_text=upper(trim(p_fiche));
insert into quant_sold
(qs_internal,j_id,qs_fiche,qs_quantite,qs_price,qs_vat,qs_vat_code,qs_client,qs_valid)
values
(p_internal,p_jid,fid_good,p_quant,p_price,p_vat,p_vat_code,fid_client,'Y');
return;
end;
$BODY$
LANGUAGE 'plpgsql';
drop view vw_fiche_attr;
create view vw_fiche_attr
as SELECT a.f_id, a.fd_id, a.av_text AS vw_name, b.av_text AS vw_sell, c.av_text AS vw_buy, d.av_text AS tva_code, tva_rate.tva_id, tva_rate.tva_rate, tva_rate.tva_label, e.av_text AS vw_addr, f.av_text AS vw_cp, j.av_text AS quick_code, h.av_text as vw_description,fiche_def.frd_id
FROM ( SELECT fiche.f_id, fiche.fd_id, attr_value.av_text
FROM fiche
JOIN jnt_fic_att_value USING (f_id)
JOIN attr_value USING (jft_id)
JOIN attr_def USING (ad_id)
WHERE jnt_fic_att_value.ad_id = 1) a
LEFT JOIN ( SELECT fiche.f_id, attr_value.av_text
FROM fiche
JOIN jnt_fic_att_value USING (f_id)
JOIN attr_value USING (jft_id)
JOIN attr_def USING (ad_id)
WHERE jnt_fic_att_value.ad_id = 6) b ON a.f_id = b.f_id
LEFT JOIN ( SELECT fiche.f_id, attr_value.av_text
FROM fiche
JOIN jnt_fic_att_value USING (f_id)
JOIN attr_value USING (jft_id)
JOIN attr_def USING (ad_id)
WHERE jnt_fic_att_value.ad_id = 7) c ON a.f_id = c.f_id
LEFT JOIN ( SELECT fiche.f_id, attr_value.av_text
FROM fiche
JOIN jnt_fic_att_value USING (f_id)
JOIN attr_value USING (jft_id)
JOIN attr_def USING (ad_id)
WHERE jnt_fic_att_value.ad_id = 2) d ON a.f_id = d.f_id
LEFT JOIN ( SELECT fiche.f_id, attr_value.av_text
FROM fiche
JOIN jnt_fic_att_value USING (f_id)
JOIN attr_value USING (jft_id)
JOIN attr_def USING (ad_id)
WHERE jnt_fic_att_value.ad_id = 14) e ON a.f_id = e.f_id
LEFT JOIN ( SELECT fiche.f_id, attr_value.av_text
FROM fiche
JOIN jnt_fic_att_value USING (f_id)
JOIN attr_value USING (jft_id)
JOIN attr_def USING (ad_id)
WHERE jnt_fic_att_value.ad_id = 15) f ON a.f_id = f.f_id
LEFT JOIN ( SELECT fiche.f_id, attr_value.av_text
FROM fiche
JOIN jnt_fic_att_value USING (f_id)
JOIN attr_value USING (jft_id)
JOIN attr_def USING (ad_id)
WHERE jnt_fic_att_value.ad_id = 23) j ON a.f_id = j.f_id
LEFT JOIN ( SELECT fiche.f_id, attr_value.av_text
FROM fiche
JOIN jnt_fic_att_value USING (f_id)
JOIN attr_value USING (jft_id)
JOIN attr_def USING (ad_id)
WHERE jnt_fic_att_value.ad_id = 9) h ON a.f_id = h.f_id
LEFT JOIN tva_rate ON d.av_text = tva_rate.tva_id::text
JOIN fiche_def USING (fd_id);
-- ajout n client dans attr_min
insert into attr_min values (2,30);
update attr_def set ad_text='Dpense charge du grant (partie prive)' where ad_id=31;
CREATE OR REPLACE FUNCTION update_account_item_card()
RETURNS void AS
$BODY$
declare
cCard cursor for select jft_id,fd_class_base from fiche join fiche_def using (fd_id)
join jnt_fic_att_value using (f_id)
join attr_value using (jft_id)
where
ad_id=5 and
fd_create_account=false
and av_text = '';
njft_id integer;
sClass_base text;
begin
open cCard;
loop
fetch cCard into njft_id,sClass_base;
if NOT FOUND then
exit;
end if;
update attr_value set av_text=sClass_base where jft_id=njft_id;
end loop;
end;
$BODY$
LANGUAGE 'plpgsql';
select update_account_item_card();
drop function update_account_item_card();
delete from action where ac_module='budget';
drop table bud_hypothese cascade;
drop table bud_detail_periode cascade;
drop table bud_detail cascade;
drop table bud_card cascade;
-- drop sequence bud_card_bc_id_seq;
-- drop sequence bud_detail_bd_id_seq
-- drop sequence bud_detail_bdp_id_seq;
-- drop sequence bud_detail_periode_bdp_id_seq;
comment on column action.ac_code is 'this code will be used in the code with the function User::check_action ';
comment on column action_detail.f_id is 'the concerned card';
comment on column action_detail.ad_text is ' Description ';
comment on column action_detail.ad_pu is ' price per unit ';
comment on column action_detail.ad_quant is 'quantity ';
comment on column action_detail.ad_tva_id is ' tva_id ';
comment on column action_detail.ad_tva_amount is ' tva_amount ';
comment on column action_detail.ad_total_amount is ' total amount';
comment on column action_gestion.ag_type is ' type of action: see document_type ';
comment on column action_gestion.f_id_dest is ' third party ';
comment on column action_gestion.ag_title is ' title ';
comment on column action_gestion.ag_timestamp is ' ';
comment on column action_gestion.ag_cal is ' visible in the calendar if = C';
comment on column action_gestion.ag_ref_ag_id is ' concerning the action ';
comment on column action_gestion.ag_comment is ' comment of the action';
comment on column action_gestion.ag_ref is 'its reference ';
comment on column action_gestion.ag_priority is 'Low, medium, important ';
comment on column action_gestion.ag_dest is ' is the person who has to take care of this action ';
comment on column action_gestion.ag_owner is ' is the owner of this action ';
comment on column action_gestion.ag_contact is ' contact of the third part ';
comment on column action_gestion.ag_state is 'state of the action same as document_state ';
comment on table action_gestion is 'Contains the details for the follow-up of customer, supplier, administration';
-- clean the bud part
delete from document where ag_id=0;
INSERT INTO action(ac_id, ac_description, ac_module, ac_code) VALUES (313, 'Administration', 'gestion', 'GEADM');
INSERT INTO action(ac_id, ac_description, ac_module, ac_code) VALUES (1600, 'Gestion des extensions', 'extension', 'EXTENSION');
INSERT INTO action(ac_id, ac_description, ac_module, ac_code) VALUES (1701, 'Consultation', 'prvision', 'PREVCON');
INSERT INTO action(ac_id, ac_description, ac_module, ac_code) VALUES (1702, 'Modification et cration', 'prvision', 'PREVMOD');
update action_gestion set ag_state=2,ag_priority=2,ag_owner='phpcompta';
-- Function: extension_ins_upd()
-- DROP FUNCTION extension_ins_upd();
CREATE OR REPLACE FUNCTION extension_ins_upd()
RETURNS trigger AS
$BODY$
declare
sCode text;
begin
sCode:=trim(upper(NEW.ex_code));
sCode:=replace(sCode,' ','_');
sCode:=substr(sCode,1,15);
sCode=upper(sCode);
NEW.ex_code:=sCode;
return NEW;
end;
$BODY$
LANGUAGE 'plpgsql';
-- Table: extension
-- DROP TABLE extension;
CREATE TABLE extension
(
ex_id serial NOT NULL,
ex_name character varying(30) NOT NULL,
ex_code character varying(15) NOT NULL,
ex_desc character varying(250),
ex_file character varying NOT NULL,
ex_enable "char" NOT NULL DEFAULT 'Y'::"char",
CONSTRAINT pk_extension PRIMARY KEY (ex_id),
CONSTRAINT idx_ex_code UNIQUE (ex_code)
);
COMMENT ON TABLE extension IS 'Content the needed information for the extension';
COMMENT ON COLUMN extension.ex_id IS 'Primary key';
COMMENT ON COLUMN extension.ex_code IS 'code of the extension ';
COMMENT ON COLUMN extension.ex_name IS 'code of the extension ';
COMMENT ON COLUMN extension.ex_desc IS 'Description of the extension ';
COMMENT ON COLUMN extension.ex_file IS 'path to the extension to include';
COMMENT ON COLUMN extension.ex_enable IS 'Y : enabled; N : disabled ';
CREATE TRIGGER trg_extension_ins_upd
BEFORE INSERT OR UPDATE
ON extension
FOR EACH ROW
EXECUTE PROCEDURE extension_ins_upd();
CREATE TABLE user_sec_extension
(
use_id serial NOT NULL,
ex_id integer NOT NULL,
use_login text NOT NULL,
use_access character(1) NOT NULL DEFAULT 0,
CONSTRAINT user_sec_extension_pkey PRIMARY KEY (use_id),
CONSTRAINT user_sec_extension_ex_id_key UNIQUE (ex_id, use_login)
);
COMMENT ON TABLE user_sec_extension IS 'Security for extension';
CREATE TABLE forecast
(
f_id serial NOT NULL,
f_name text NOT NULL,
CONSTRAINT forecast_pk PRIMARY KEY (f_id)
);
COMMENT ON TABLE forecast IS 'contains the name of the forecast';
CREATE TABLE forecast_cat
(
fc_id serial NOT NULL, -- primary key
fc_desc text NOT NULL, -- text of the category
f_id bigint, -- Foreign key, it is the parent from the table forecast
fc_order integer NOT NULL DEFAULT 0, -- Order of the category, used when displaid
CONSTRAINT forecast_cat_pk PRIMARY KEY (fc_id),
CONSTRAINT forecast_child FOREIGN KEY (f_id)
REFERENCES forecast (f_id) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE
);
COMMENT ON COLUMN forecast_cat.fc_id IS 'primary key';
COMMENT ON COLUMN forecast_cat.fc_desc IS 'text of the category';
COMMENT ON COLUMN forecast_cat.f_id IS 'Foreign key, it is the parent from the table forecast';
COMMENT ON COLUMN forecast_cat.fc_order IS 'Order of the category, used when displaid';
CREATE TABLE forecast_item
(
fi_id serial NOT NULL,
fi_text text,
fi_account text,
fi_card integer,
fi_order integer,
fc_id integer,
fi_amount numeric(20,4) DEFAULT 0,
fi_debit "char" NOT NULL DEFAULT 'd'::"char",
fi_pid integer,
CONSTRAINT forecast_item_pkey PRIMARY KEY (fi_id),
CONSTRAINT card FOREIGN KEY (fi_card)
REFERENCES fiche (f_id) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE,
CONSTRAINT fk_forecast FOREIGN KEY (fc_id)
REFERENCES forecast_cat (fc_id) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE
);
COMMENT ON COLUMN forecast_item.fi_id IS 'Primary key';
COMMENT ON COLUMN forecast_item.fi_text IS 'Label of the i tem';
COMMENT ON COLUMN forecast_item.fi_account IS 'Accountancy entry';
COMMENT ON COLUMN forecast_item.fi_card IS 'Card (fiche.f_id)';
COMMENT ON COLUMN forecast_item.fi_amount IS 'Amount';
COMMENT ON COLUMN forecast_item.fi_debit IS 'possible values are D or C';
COMMENT ON COLUMN forecast_item.fi_order IS 'Order of showing (not used)';
COMMENT ON COLUMN forecast_item.fi_pid IS '0 for every month, or the value parm_periode.p_id ';
update version set val=60;
commit;

View file

@ -0,0 +1,8 @@
begin;
--make sure that p_start < p_end
ALTER TABLE parm_periode ADD CHECK (p_end >= p_start);
insert into tva_rate values (5,'0%',0, 'Pas soumis à la TVA',null);
update version set val=7;
commit;

View file

@ -0,0 +1,40 @@
begin;
alter SEQUENCE document_type_dt_id_seq start 25;
insert into document_type (dt_id,dt_value) values (20,'Réception commande Fournisseur');
insert into document_type (dt_id,dt_value) values (21,'Réception commande Client');
insert into document_type (dt_id,dt_value) values (22,'Réception magazine');
CREATE OR REPLACE FUNCTION extension_ins_upd()
RETURNS "trigger" AS
$BODY$
declare
sCode text;
sFile text;
begin
sCode:=trim(upper(NEW.ex_code));
sCode:=replace(sCode,' ','_');
sCode:=substr(sCode,1,15);
sCode=upper(sCode);
NEW.ex_code:=sCode;
-- remove forbidden char
sFile:=NEW.ex_file;
sFile:=replace(sFile,';','_');
sFile:=replace(sFile,'<','_');
sFile:=replace(sFile,'>','_');
sFile:=replace(sFile,'..','');
sFile:=replace(sFile,'&','');
sFile:=replace(sFile,'|','');
return NEW;
end;
$BODY$
LANGUAGE 'plpgsql';
update version set val=61;
commit;

View file

@ -0,0 +1,13 @@
begin;
insert into tmp_pcmn(pcm_val,pcm_lib,pcm_val_parent,pcm_type) values (4515,'Tva Intracomm 0%',451,'PAS');
insert into tmp_pcmn(pcm_val,pcm_lib,pcm_val_parent,pcm_type) values (4516,'Tva Export 0%',451,'PAS');
insert into tmp_pcmn(pcm_val,pcm_lib,pcm_val_parent,pcm_type) values (4115,'Tva Intracomm 0%',411,'ACT');
insert into tmp_pcmn(pcm_val,pcm_lib,pcm_val_parent,pcm_type) values (4116,'Tva Export 0%',411,'ACT');
insert into tva_rate (tva_id,tva_label,tva_rate,tva_comment,tva_poste) values (5,'INTRA',0,'Tva pour les livraisons / acquisition intra communautaires','4115,4515');
insert into tva_rate (tva_id,tva_label,tva_rate,tva_comment,tva_poste) values (6,'EXPORT',0,'Tva pour les exportations','4116,4516');
update version set val=62;
commit;

View file

@ -0,0 +1,90 @@
begin;
-- insert into parm_code(p_code,p_value,p_comment)values('SUPPLIER','400','Poste comptable par défaut pour les fournisseurs');
-- update tva_rate set tva_poste = '445,445' where tva_poste is null or tva_poste='' or tva_poste like '%,0';
update tva_rate set tva_label='FR_NOR' where tva_id= 101;
update tva_rate set tva_label='FR_RED' where tva_id= 102;
update tva_rate set tva_label='FR_SRED' where tva_id= 103;
update tva_rate set tva_label='FR_ANC' where tva_id= 105;
update tva_rate set tva_label='DOM' where tva_id= 201;
update tva_rate set tva_label='DOM_NPR' where tva_id= 202;
update tva_rate set tva_label='DOM_REDUIT' where tva_id= 203;
update tva_rate set tva_label='DOM_I' where tva_id= 204;
update tva_rate set tva_label='DOM_PRESSE' where tva_id= 205;
update tva_rate set tva_label='DOM_OCTROI' where tva_id= 206;
update tva_rate set tva_label='COR_I' where tva_id= 301;
update tva_rate set tva_label='COR_II' where tva_id= 302;
update tva_rate set tva_label='COR_III' where tva_id= 303;
update tva_rate set tva_label='COR_IV' where tva_id= 304;
update tva_rate set tva_label='INTRA' where tva_id= 401;
update tva_rate set tva_label='DOM_IMMO' where tva_id= 207;
update tva_rate set tva_label='COR_IMMO' where tva_id= 305;
update tva_rate set tva_label='INTRA_IMMMO' where tva_id= 402;
update tva_rate set tva_label='FRANCH' where tva_id= 501;
update tva_rate set tva_label='EXPORT' where tva_id= 502;
update tva_rate set tva_label='AUTRE' where tva_id= 503;
update tva_rate set tva_label='INTRA_LIV' where tva_id= 504;
update tva_rate set tva_label='FR_IMMO' where tva_id= 104;
update tmp_pcmn set pcm_type='ACT' where pcm_val in ('445661','445662','445663');
update tva_rate set tva_poste='4456601,445701' where tva_id='104' and tva_poste='44562,0';
insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent,pcm_type) values (4456601,'TVA 19,6% - France métropolitaine - Taux immobilisations Déductible','4456','ACT');
insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent,pcm_type) values (445701,'TVA 19,6% - France métropolitaine - Taux immobilisations Collectée ','4457','PAS');
update tva_rate set tva_poste='4456602,445702' where tva_id='105' and tva_poste='445,445';
insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent,pcm_type) values (4456602,'TVA x% - France métropolitaine - Taux anciens Déductible','4456','ACT');
insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent,pcm_type) values (445702,'TVA x% - France métropolitaine - Taux anciens Collectée ','4457','PAS');
update tva_rate set tva_poste='4456603,445703' where tva_id='201' and tva_poste='445,445';
insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent,pcm_type) values (4456603,'TVA 8,5% - DOM - Taux normal Déductible','4456','ACT');
insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent,pcm_type) values (445703,'TVA 8,5% - DOM - Taux normal Collectée ','4457','PAS');
update tva_rate set tva_poste='4456604,445704' where tva_id='202' and tva_poste='445,445';
insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent,pcm_type) values (4456604,'TVA 8,5% - DOM - Taux normal NPR Déductible','4456','ACT');
insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent,pcm_type) values (445704,'TVA 8,5% - DOM - Taux normal NPR Collectée ','4457','PAS');
update tva_rate set tva_poste='4456605,445705' where tva_id='203' and tva_poste='445,445';
insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent,pcm_type) values (4456605,'TVA 2,1% - DOM - Taux réduit Déductible','4456','ACT');
insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent,pcm_type) values (445705,'TVA 2,1% - DOM - Taux réduit Collectée ','4457','PAS');
update tva_rate set tva_poste='4456606,445706' where tva_id='204' and tva_poste='445,445';
insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent,pcm_type) values (4456606,'TVA 1,75% - DOM - Taux I Déductible','4456','ACT');
insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent,pcm_type) values (445706,'TVA 1,75% - DOM - Taux I Collectée ','4457','PAS');
update tva_rate set tva_poste='4456607,445707' where tva_id='205' and tva_poste='445,445';
insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent,pcm_type) values (4456607,'TVA 1,05% - DOM - Taux publications de presse Déductible','4456','ACT');
insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent,pcm_type) values (445707,'TVA 1,05% - DOM - Taux publications de presse Collectée ','4457','PAS');
update tva_rate set tva_poste='4456608,445708' where tva_id='206' and tva_poste='445,445';
insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent,pcm_type) values (4456608,'TVA x% - DOM - Taux octroi de mer Déductible','4456','ACT');
insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent,pcm_type) values (445708,'TVA x% - DOM - Taux octroi de mer Collectée ','4457','PAS');
update tva_rate set tva_poste='4456609,445709' where tva_id='207' and tva_poste='445,0';
insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent,pcm_type) values (4456609,'TVA x% - DOM - Taux immobilisations Déductible','4456','ACT');
insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent,pcm_type) values (445709,'TVA x% - DOM - Taux immobilisations Collectée ','4457','PAS');
update tva_rate set tva_poste='44566010,4457010' where tva_id='301' and tva_poste='445,445';
insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent,pcm_type) values (44566010,'TVA 13% - Corse - Taux I Déductible','4456','ACT');
insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent,pcm_type) values (4457010,'TVA 13% - Corse - Taux I Collectée ','4457','PAS');
update tva_rate set tva_poste='44566011,4457011' where tva_id='302' and tva_poste='445,445';
insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent,pcm_type) values (44566011,'TVA 8% - Corse - Taux II Déductible','4456','ACT');
insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent,pcm_type) values (4457011,'TVA 8% - Corse - Taux II Collectée ','4457','PAS');
update tva_rate set tva_poste='44566012,4457012' where tva_id='303' and tva_poste='445,445';
insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent,pcm_type) values (44566012,'TVA 2,1% - Corse - Taux III Déductible','4456','ACT');
insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent,pcm_type) values (4457012,'TVA 2,1% - Corse - Taux III Collectée ','4457','PAS');
update tva_rate set tva_poste='44566013,4457013' where tva_id='304' and tva_poste='445,445';
insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent,pcm_type) values (44566013,'TVA 0,9% - Corse - Taux IV Déductible','4456','ACT');
insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent,pcm_type) values (4457013,'TVA 0,9% - Corse - Taux IV Collectée ','4457','PAS');
update tva_rate set tva_poste='44566014,4457014' where tva_id='305' and tva_poste='445,0';
insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent,pcm_type) values (44566014,'TVA x% - Corse - Taux immobilisations Déductible','4456','ACT');
insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent,pcm_type) values (4457014,'TVA x% - Corse - Taux immobilisations Collectée ','4457','PAS');
update tva_rate set tva_poste='44566015,4457015' where tva_id='401' and tva_poste='445,445';
insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent,pcm_type) values (44566015,'TVA x% - Acquisitions intracommunautaires/Pays Déductible','4456','ACT');
insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent,pcm_type) values (4457015,'TVA x% - Acquisitions intracommunautaires/Pays Collectée ','4457','PAS');
update tva_rate set tva_poste='44566016,4457016' where tva_id='402' and tva_poste='445,0';
insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent,pcm_type) values (44566016,'TVA x% - Acquisitions intracommunautaires immobilisations/Pays Déductible','4456','ACT');
insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent,pcm_type) values (4457016,'TVA x% - Acquisitions intracommunautaires immobilisations/Pays Collectée ','4457','PAS');
update tva_rate set tva_poste='44566017,4457017' where tva_id='501' and tva_poste='';
insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent,pcm_type) values (44566017,'TVA x% - Non imposable : Achats en franchise Déductible','4456','ACT');
insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent,pcm_type) values (4457017,'TVA x% - Non imposable : Achats en franchise Collectée ','4457','PAS');
update tva_rate set tva_poste='44566018,4457018' where tva_id='502' and tva_poste='';
insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent,pcm_type) values (44566018,'TVA x% - Non imposable : Exports hors CE/Pays Déductible','4456','ACT');
insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent,pcm_type) values (4457018,'TVA x% - Non imposable : Exports hors CE/Pays Collectée ','4457','PAS');
update tva_rate set tva_poste='44566019,4457019' where tva_id='503' and tva_poste='';
insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent,pcm_type) values (44566019,'TVA x% - Non imposable : Autres opérations Déductible','4456','ACT');
insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent,pcm_type) values (4457019,'TVA x% - Non imposable : Autres opérations Collectée ','4457','PAS');
update tva_rate set tva_poste='44566020,4457020' where tva_id='504' and tva_poste='';
insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent,pcm_type) values (44566020,'TVA x% - Non imposable : Livraisons intracommunautaires/Pays Déductible','4456','ACT');
insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent,pcm_type) values (4457020,'TVA x% - Non imposable : Livraisons intracommunautaires/Pays Collectée ','4457','PAS');
update version set val=62;
commit;

View file

@ -0,0 +1,15 @@
begin;
-- View: vw_fiche_def
DROP VIEW vw_fiche_def;
CREATE VIEW vw_fiche_def AS
SELECT jnt_fic_attr.fd_id, jnt_fic_attr.ad_id, attr_def.ad_text,fiche_def.fd_class_base, fiche_def.fd_label, fiche_def.fd_create_account, fiche_def.frd_id
from fiche_def
join jnt_fic_attr USING (fd_id)
JOIN attr_def ON attr_def.ad_id = jnt_fic_attr.ad_id
;
COMMENT ON VIEW vw_fiche_def IS 'all the attributs for card family';
commit;

View file

@ -0,0 +1,9 @@
begin;
-- View: vw_fiche_def
create index jnt_fic_att_value_fd_id_idx on jnt_fic_att_value(f_id);
create index jnt_fic_attr_fd_id_idx on jnt_fic_attr(fd_id);
update version set val=63;
commit;

View file

@ -0,0 +1,62 @@
begin;
DROP FUNCTION insert_jrnx(character varying, numeric, poste_comptable, integer, integer, boolean, text, integer, text);
CREATE OR REPLACE FUNCTION insert_jrnx(p_date character varying, p_montant numeric, p_poste poste_comptable, p_grpt integer, p_jrn_def integer, p_debit boolean, p_tech_user text, p_tech_per integer, p_qcode text,p_comment text)
RETURNS void AS
$BODY$
declare
sCode varchar;
nCount_qcode integer;
begin
sCode=trim(p_qcode);
-- if p_qcode is empty try to find one
if length(sCode) = 0 or p_qcode is null then
select count(*) into nCount_qcode
from vw_poste_qcode where j_poste=p_poste::text;
-- if we find only one q_code for a accountancy account
-- then retrieve it
if nCount_qcode = 1 then
select j_qcode::text into sCode
from vw_poste_qcode where j_poste=p_poste::text;
else
sCode=NULL;
end if;
end if;
insert into jrnx
(
j_date,
j_montant,
j_poste,
j_grpt,
j_jrn_def,
j_debit,
j_text,
j_tech_user,
j_tech_per,
j_qcode
) values
(
to_date(p_date,'DD.MM.YYYY'),
p_montant,
p_poste,
p_grpt,
p_jrn_def,
p_debit,
p_comment,
p_tech_user,
p_tech_per,
sCode
);
return;
end;
$BODY$
LANGUAGE plpgsql;
update version set val=64;
commit;

View file

@ -0,0 +1,67 @@
begin;
DROP VIEW vw_fiche_attr;
CREATE OR REPLACE VIEW vw_fiche_attr AS
SELECT a.f_id, a.fd_id, a.av_text AS vw_name, b.av_text AS vw_sell, c.av_text AS vw_buy, d.av_text AS tva_code, tva_rate.tva_id, tva_rate.tva_rate, tva_rate.tva_label, e.av_text AS vw_addr, f.av_text AS vw_cp, j.av_text AS quick_code, h.av_text AS vw_description, i.av_text AS tva_num, fiche_def.frd_id
FROM ( SELECT fiche.f_id, fiche.fd_id, attr_value.av_text
FROM fiche
JOIN jnt_fic_att_value USING (f_id)
JOIN attr_value USING (jft_id)
JOIN attr_def USING (ad_id)
WHERE jnt_fic_att_value.ad_id = 1) a
LEFT JOIN ( SELECT fiche.f_id, attr_value.av_text
FROM fiche
JOIN jnt_fic_att_value USING (f_id)
JOIN attr_value USING (jft_id)
JOIN attr_def USING (ad_id)
WHERE jnt_fic_att_value.ad_id = 6) b ON a.f_id = b.f_id
LEFT JOIN ( SELECT fiche.f_id, attr_value.av_text
FROM fiche
JOIN jnt_fic_att_value USING (f_id)
JOIN attr_value USING (jft_id)
JOIN attr_def USING (ad_id)
WHERE jnt_fic_att_value.ad_id = 7) c ON a.f_id = c.f_id
LEFT JOIN ( SELECT fiche.f_id, attr_value.av_text
FROM fiche
JOIN jnt_fic_att_value USING (f_id)
JOIN attr_value USING (jft_id)
JOIN attr_def USING (ad_id)
WHERE jnt_fic_att_value.ad_id = 2) d ON a.f_id = d.f_id
LEFT JOIN ( SELECT fiche.f_id, attr_value.av_text
FROM fiche
JOIN jnt_fic_att_value USING (f_id)
JOIN attr_value USING (jft_id)
JOIN attr_def USING (ad_id)
WHERE jnt_fic_att_value.ad_id = 14) e ON a.f_id = e.f_id
LEFT JOIN ( SELECT fiche.f_id, attr_value.av_text
FROM fiche
JOIN jnt_fic_att_value USING (f_id)
JOIN attr_value USING (jft_id)
JOIN attr_def USING (ad_id)
WHERE jnt_fic_att_value.ad_id = 15) f ON a.f_id = f.f_id
LEFT JOIN ( SELECT fiche.f_id, attr_value.av_text
FROM fiche
JOIN jnt_fic_att_value USING (f_id)
JOIN attr_value USING (jft_id)
JOIN attr_def USING (ad_id)
WHERE jnt_fic_att_value.ad_id = 23) j ON a.f_id = j.f_id
LEFT JOIN ( SELECT fiche.f_id, attr_value.av_text
FROM fiche
JOIN jnt_fic_att_value USING (f_id)
JOIN attr_value USING (jft_id)
JOIN attr_def USING (ad_id)
WHERE jnt_fic_att_value.ad_id = 9) h ON a.f_id = h.f_id
LEFT JOIN ( SELECT fiche.f_id, attr_value.av_text
FROM fiche
JOIN jnt_fic_att_value USING (f_id)
JOIN attr_value USING (jft_id)
JOIN attr_def USING (ad_id)
WHERE jnt_fic_att_value.ad_id = 13) i ON a.f_id = i.f_id
LEFT JOIN tva_rate ON d.av_text = tva_rate.tva_id::text
JOIN fiche_def USING (fd_id);
update version set val=65;
commit;

View file

@ -0,0 +1,4 @@
begin;
SELECT setval('public.mod_payment_mp_id_seq', 10, true);
update version set val=66;
commit;

View file

@ -0,0 +1,134 @@
begin;
drop function account_insert(p_f_id integer, p_account poste_comptable);
CREATE OR REPLACE FUNCTION account_insert(p_f_id integer, p_account text)
RETURNS integer AS
$BODY$
declare
nParent tmp_pcmn.pcm_val_parent%type;
sName varchar;
nNew tmp_pcmn.pcm_val%type;
bAuto bool;
nFd_id integer;
nCount integer;
first text;
second text;
begin
if length(trim(p_account)) != 0 then
-- if there is coma in p_account, treat normally
if position (',' in p_account) = 0 then
raise info 'p_account is not empty';
select count(*) into nCount from tmp_pcmn where pcm_val=p_account;
raise notice 'found in tmp_pcm %',nCount;
if nCount !=0 then
raise info 'this account exists in tmp_pcmn ';
perform attribut_insert(p_f_id,5,p_account);
else
-- account doesn't exist, create it
select av_text into sName from
attr_value join jnt_fic_att_value using (jft_id)
where
ad_id=1 and f_id=p_f_id;
nParent:=account_parent(p_account::poste_comptable);
insert into tmp_pcmn(pcm_val,pcm_lib,pcm_val_parent) values (p_account::poste_comptable,sName,nParent);
perform attribut_insert(p_f_id,5,p_account);
end if;
else
raise info 'presence of a comma';
-- there is 2 accounts separated by a comma
first := split_part(p_account,',',1);
second := split_part(p_account,',',2);
-- check there is no other coma
raise info 'first value % second value %', first, second;
if position (',' in first) != 0 or position (',' in second) != 0 then
raise exception 'Too many comas, invalid account';
end if;
perform attribut_insert(p_f_id,5,p_account);
end if;
else
raise info 'p_account is empty';
select fd_id into nFd_id from fiche where f_id=p_f_id;
bAuto:= account_auto(nFd_id);
if bAuto = true then
raise notice 'account generated automatically';
nNew:=account_compute(p_f_id);
raise notice 'nNew %', nNew;
select av_text into sName from
attr_value join jnt_fic_att_value using (jft_id)
where
ad_id=1 and f_id=p_f_id;
nParent:=account_parent(nNew);
perform account_add (nNew,sName);
perform attribut_insert(p_f_id,5,to_char(nNew,'999999999999999999999999'));
else
-- if there is an account_base then it is the default
select fd_class_base::text into nNew from fiche_def join fiche using (fd_id) where f_id=p_f_id;
if nNew is null or length(trim(nNew)) = 0 then
raise notice 'count is null';
perform attribut_insert(p_f_id,5,null);
else
perform attribut_insert(p_f_id,5,to_char(nNew,'999999999999999999999999'));
end if;
end if;
end if;
return 0;
end;
$BODY$
LANGUAGE 'plpgsql';
drop function account_update(p_f_id integer, p_account poste_comptable);
CREATE OR REPLACE FUNCTION account_update(p_f_id integer, p_account text)
RETURNS integer AS
$BODY$
declare
nMax fiche.f_id%type;
nCount integer;
nParent tmp_pcmn.pcm_val_parent%type;
sName varchar;
nJft_id attr_value.jft_id%type;
first text;
second text;
begin
if length(trim(p_account)) != 0 then
if position (',' in p_account) = 0 then
select count(*) into nCount from tmp_pcmn where pcm_val=p_account;
if nCount = 0 then
select av_text into sName from
attr_value join jnt_fic_att_value using (jft_id)
where
ad_id=1 and f_id=p_f_id;
nParent:=account_parent(p_account::poste_comptable);
insert into tmp_pcmn(pcm_val,pcm_lib,pcm_val_parent) values (p_account::poste_comptable,sName,nParent);
end if;
else
raise info 'presence of a comma';
-- there is 2 accounts separated by a comma
first := split_part(p_account,',',1);
second := split_part(p_account,',',2);
-- check there is no other coma
raise info 'first value % second value %', first, second;
if position (',' in first) != 0 or position (',' in second) != 0 then
raise exception 'Too many comas, invalid account';
end if;
end if;
end if;
select jft_id into njft_id from jnt_fic_att_value where f_id=p_f_id and ad_id=5;
update attr_value set av_text=p_account where jft_id=njft_id;
return njft_id;
end;
$BODY$
LANGUAGE 'plpgsql';
update version set val=67;
commit;

View file

@ -0,0 +1,177 @@
begin;
DROP VIEW vw_fiche_def;
DROP VIEW vw_supplier;
DROP VIEW vw_client;
alter table fiche_def alter fd_class_base type text;
CREATE OR REPLACE VIEW vw_fiche_def AS
SELECT jnt_fic_attr.fd_id, jnt_fic_attr.ad_id, attr_def.ad_text, fiche_def.fd_class_base, fiche_def.fd_label, fiche_def.fd_create_account, fiche_def.frd_id
FROM fiche_def
JOIN jnt_fic_attr USING (fd_id)
JOIN attr_def ON attr_def.ad_id = jnt_fic_attr.ad_id;
COMMENT ON VIEW vw_fiche_def IS 'all the attributs for card family';
CREATE OR REPLACE VIEW vw_supplier AS
SELECT a.f_id, a.av_text AS name, a1.av_text AS quick_code, b.av_text AS tva_num, c.av_text AS poste_comptable, d.av_text AS rue, e.av_text AS code_postal, f.av_text AS pays, g.av_text AS telephone, h.av_text AS email
FROM ( SELECT jnt_fic_att_value.jft_id, fiche.f_id, fiche_def.frd_id, fiche.fd_id, fiche_def.fd_class_base, fiche_def.fd_label, fiche_def.fd_create_account, fiche_def_ref.frd_text, fiche_def_ref.frd_class_base, jnt_fic_att_value.ad_id, attr_value.av_text
FROM fiche
JOIN fiche_def USING (fd_id)
JOIN fiche_def_ref USING (frd_id)
JOIN jnt_fic_att_value USING (f_id)
JOIN attr_value USING (jft_id)
WHERE jnt_fic_att_value.ad_id = 1) a
JOIN ( SELECT jnt_fic_att_value.jft_id, fiche.f_id, fiche_def.frd_id, fiche.fd_id, fiche_def.fd_class_base, fiche_def.fd_label, fiche_def.fd_create_account, fiche_def_ref.frd_text, fiche_def_ref.frd_class_base, jnt_fic_att_value.ad_id, attr_value.av_text
FROM fiche
JOIN fiche_def USING (fd_id)
JOIN fiche_def_ref USING (frd_id)
JOIN jnt_fic_att_value USING (f_id)
JOIN attr_value USING (jft_id)
WHERE jnt_fic_att_value.ad_id = 13) b USING (f_id)
JOIN ( SELECT jnt_fic_att_value.jft_id, fiche.f_id, fiche_def.frd_id, fiche.fd_id, fiche_def.fd_class_base, fiche_def.fd_label, fiche_def.fd_create_account, fiche_def_ref.frd_text, fiche_def_ref.frd_class_base, jnt_fic_att_value.ad_id, attr_value.av_text
FROM fiche
JOIN fiche_def USING (fd_id)
JOIN fiche_def_ref USING (frd_id)
JOIN jnt_fic_att_value USING (f_id)
JOIN attr_value USING (jft_id)
WHERE jnt_fic_att_value.ad_id = 23) a1 USING (f_id)
JOIN ( SELECT jnt_fic_att_value.jft_id, fiche.f_id, fiche_def.frd_id, fiche.fd_id, fiche_def.fd_class_base, fiche_def.fd_label, fiche_def.fd_create_account, fiche_def_ref.frd_text, fiche_def_ref.frd_class_base, jnt_fic_att_value.ad_id, attr_value.av_text
FROM fiche
JOIN fiche_def USING (fd_id)
JOIN fiche_def_ref USING (frd_id)
JOIN jnt_fic_att_value USING (f_id)
JOIN attr_value USING (jft_id)
WHERE jnt_fic_att_value.ad_id = 5) c USING (f_id)
JOIN ( SELECT jnt_fic_att_value.jft_id, fiche.f_id, fiche_def.frd_id, fiche.fd_id, fiche_def.fd_class_base, fiche_def.fd_label, fiche_def.fd_create_account, fiche_def_ref.frd_text, fiche_def_ref.frd_class_base, jnt_fic_att_value.ad_id, attr_value.av_text
FROM fiche
JOIN fiche_def USING (fd_id)
JOIN fiche_def_ref USING (frd_id)
JOIN jnt_fic_att_value USING (f_id)
JOIN attr_value USING (jft_id)
WHERE jnt_fic_att_value.ad_id = 14) d USING (f_id)
JOIN ( SELECT jnt_fic_att_value.jft_id, fiche.f_id, fiche_def.frd_id, fiche.fd_id, fiche_def.fd_class_base, fiche_def.fd_label, fiche_def.fd_create_account, fiche_def_ref.frd_text, fiche_def_ref.frd_class_base, jnt_fic_att_value.ad_id, attr_value.av_text
FROM fiche
JOIN fiche_def USING (fd_id)
JOIN fiche_def_ref USING (frd_id)
JOIN jnt_fic_att_value USING (f_id)
JOIN attr_value USING (jft_id)
WHERE jnt_fic_att_value.ad_id = 15) e USING (f_id)
JOIN ( SELECT jnt_fic_att_value.jft_id, fiche.f_id, fiche_def.frd_id, fiche.fd_id, fiche_def.fd_class_base, fiche_def.fd_label, fiche_def.fd_create_account, fiche_def_ref.frd_text, fiche_def_ref.frd_class_base, jnt_fic_att_value.ad_id, attr_value.av_text
FROM fiche
JOIN fiche_def USING (fd_id)
JOIN fiche_def_ref USING (frd_id)
JOIN jnt_fic_att_value USING (f_id)
JOIN attr_value USING (jft_id)
WHERE jnt_fic_att_value.ad_id = 16) f USING (f_id)
JOIN ( SELECT jnt_fic_att_value.jft_id, fiche.f_id, fiche_def.frd_id, fiche.fd_id, fiche_def.fd_class_base, fiche_def.fd_label, fiche_def.fd_create_account, fiche_def_ref.frd_text, fiche_def_ref.frd_class_base, jnt_fic_att_value.ad_id, attr_value.av_text
FROM fiche
JOIN fiche_def USING (fd_id)
JOIN fiche_def_ref USING (frd_id)
JOIN jnt_fic_att_value USING (f_id)
JOIN attr_value USING (jft_id)
WHERE jnt_fic_att_value.ad_id = 17) g USING (f_id)
LEFT JOIN ( SELECT jnt_fic_att_value.jft_id, fiche.f_id, fiche_def.frd_id, fiche.fd_id, fiche_def.fd_class_base, fiche_def.fd_label, fiche_def.fd_create_account, fiche_def_ref.frd_text, fiche_def_ref.frd_class_base, jnt_fic_att_value.ad_id, attr_value.av_text
FROM fiche
JOIN fiche_def USING (fd_id)
JOIN fiche_def_ref USING (frd_id)
JOIN jnt_fic_att_value USING (f_id)
JOIN attr_value USING (jft_id)
WHERE jnt_fic_att_value.ad_id = 18) h USING (f_id)
WHERE a.frd_id = 8;
CREATE OR REPLACE VIEW vw_client AS
SELECT a.f_id, a.av_text AS name, a1.av_text AS quick_code, b.av_text AS tva_num, c.av_text AS poste_comptable, d.av_text AS rue, e.av_text AS code_postal, f.av_text AS pays, g.av_text AS telephone, h.av_text AS email
FROM ( SELECT jnt_fic_att_value.jft_id, fiche.f_id, fiche_def.frd_id, fiche.fd_id, fiche_def.fd_class_base, fiche_def.fd_label, fiche_def.fd_create_account, fiche_def_ref.frd_text, fiche_def_ref.frd_class_base, jnt_fic_att_value.ad_id, attr_value.av_text
FROM fiche
JOIN fiche_def USING (fd_id)
JOIN fiche_def_ref USING (frd_id)
JOIN jnt_fic_att_value USING (f_id)
JOIN attr_value USING (jft_id)
WHERE jnt_fic_att_value.ad_id = 1) a
JOIN ( SELECT jnt_fic_att_value.jft_id, fiche.f_id, fiche_def.frd_id, fiche.fd_id, fiche_def.fd_class_base, fiche_def.fd_label, fiche_def.fd_create_account, fiche_def_ref.frd_text, fiche_def_ref.frd_class_base, jnt_fic_att_value.ad_id, attr_value.av_text
FROM fiche
JOIN fiche_def USING (fd_id)
JOIN fiche_def_ref USING (frd_id)
JOIN jnt_fic_att_value USING (f_id)
JOIN attr_value USING (jft_id)
WHERE jnt_fic_att_value.ad_id = 13) b USING (f_id)
JOIN ( SELECT jnt_fic_att_value.jft_id, fiche.f_id, fiche_def.frd_id, fiche.fd_id, fiche_def.fd_class_base, fiche_def.fd_label, fiche_def.fd_create_account, fiche_def_ref.frd_text, fiche_def_ref.frd_class_base, jnt_fic_att_value.ad_id, attr_value.av_text
FROM fiche
JOIN fiche_def USING (fd_id)
JOIN fiche_def_ref USING (frd_id)
JOIN jnt_fic_att_value USING (f_id)
JOIN attr_value USING (jft_id)
WHERE jnt_fic_att_value.ad_id = 23) a1 USING (f_id)
JOIN ( SELECT jnt_fic_att_value.jft_id, fiche.f_id, fiche_def.frd_id, fiche.fd_id, fiche_def.fd_class_base, fiche_def.fd_label, fiche_def.fd_create_account, fiche_def_ref.frd_text, fiche_def_ref.frd_class_base, jnt_fic_att_value.ad_id, attr_value.av_text
FROM fiche
JOIN fiche_def USING (fd_id)
JOIN fiche_def_ref USING (frd_id)
JOIN jnt_fic_att_value USING (f_id)
JOIN attr_value USING (jft_id)
WHERE jnt_fic_att_value.ad_id = 5) c USING (f_id)
JOIN ( SELECT jnt_fic_att_value.jft_id, fiche.f_id, fiche_def.frd_id, fiche.fd_id, fiche_def.fd_class_base, fiche_def.fd_label, fiche_def.fd_create_account, fiche_def_ref.frd_text, fiche_def_ref.frd_class_base, jnt_fic_att_value.ad_id, attr_value.av_text
FROM fiche
JOIN fiche_def USING (fd_id)
JOIN fiche_def_ref USING (frd_id)
JOIN jnt_fic_att_value USING (f_id)
JOIN attr_value USING (jft_id)
WHERE jnt_fic_att_value.ad_id = 14) d USING (f_id)
JOIN ( SELECT jnt_fic_att_value.jft_id, fiche.f_id, fiche_def.frd_id, fiche.fd_id, fiche_def.fd_class_base, fiche_def.fd_label, fiche_def.fd_create_account, fiche_def_ref.frd_text, fiche_def_ref.frd_class_base, jnt_fic_att_value.ad_id, attr_value.av_text
FROM fiche
JOIN fiche_def USING (fd_id)
JOIN fiche_def_ref USING (frd_id)
JOIN jnt_fic_att_value USING (f_id)
JOIN attr_value USING (jft_id)
WHERE jnt_fic_att_value.ad_id = 15) e USING (f_id)
JOIN ( SELECT jnt_fic_att_value.jft_id, fiche.f_id, fiche_def.frd_id, fiche.fd_id, fiche_def.fd_class_base, fiche_def.fd_label, fiche_def.fd_create_account, fiche_def_ref.frd_text, fiche_def_ref.frd_class_base, jnt_fic_att_value.ad_id, attr_value.av_text
FROM fiche
JOIN fiche_def USING (fd_id)
JOIN fiche_def_ref USING (frd_id)
JOIN jnt_fic_att_value USING (f_id)
JOIN attr_value USING (jft_id)
WHERE jnt_fic_att_value.ad_id = 16) f USING (f_id)
JOIN ( SELECT jnt_fic_att_value.jft_id, fiche.f_id, fiche_def.frd_id, fiche.fd_id, fiche_def.fd_class_base, fiche_def.fd_label, fiche_def.fd_create_account, fiche_def_ref.frd_text, fiche_def_ref.frd_class_base, jnt_fic_att_value.ad_id, attr_value.av_text
FROM fiche
JOIN fiche_def USING (fd_id)
JOIN fiche_def_ref USING (frd_id)
JOIN jnt_fic_att_value USING (f_id)
JOIN attr_value USING (jft_id)
WHERE jnt_fic_att_value.ad_id = 17) g USING (f_id)
LEFT JOIN ( SELECT jnt_fic_att_value.jft_id, fiche.f_id, fiche_def.frd_id, fiche.fd_id, fiche_def.fd_class_base, fiche_def.fd_label, fiche_def.fd_create_account, fiche_def_ref.frd_text, fiche_def_ref.frd_class_base, jnt_fic_att_value.ad_id, attr_value.av_text
FROM fiche
JOIN fiche_def USING (fd_id)
JOIN fiche_def_ref USING (frd_id)
JOIN jnt_fic_att_value USING (f_id)
JOIN attr_value USING (jft_id)
WHERE jnt_fic_att_value.ad_id = 18) h USING (f_id)
WHERE a.frd_id = 9;
CREATE OR REPLACE FUNCTION fiche_def_ins_upd()
RETURNS "trigger" AS
$BODY$
begin
if position (',' in NEW.fd_class_base) != 0 then
NEW.fd_create_account='f';
end if;
return NEW;
end;$BODY$
LANGUAGE 'plpgsql';
CREATE TRIGGER fiche_def_ins_upd
BEFORE INSERT OR UPDATE
ON fiche_def
FOR EACH ROW
EXECUTE PROCEDURE fiche_def_ins_upd();
ALTER TABLE stock_goods DROP CONSTRAINT fk_stock_good_f_id;
ALTER TABLE stock_goods
ADD CONSTRAINT fk_stock_good_f_id FOREIGN KEY (f_id)
REFERENCES fiche (f_id) MATCH SIMPLE
ON UPDATE cascade ON DELETE cascade;
update version set val=68;
commit;

View file

@ -0,0 +1,86 @@
begin;
CREATE OR REPLACE FUNCTION account_insert(p_f_id integer, p_account text)
RETURNS integer AS
$BODY$
declare
nParent tmp_pcmn.pcm_val_parent%type;
sName varchar;
nNew tmp_pcmn.pcm_val%type;
bAuto bool;
nFd_id integer;
nCount integer;
first text;
second text;
begin
if length(trim(p_account)) != 0 then
-- if there is coma in p_account, treat normally
if position (',' in p_account) = 0 then
raise info 'p_account is not empty';
select count(*) into nCount from tmp_pcmn where pcm_val=p_account::poste_comptable;
raise notice 'found in tmp_pcm %',nCount;
if nCount !=0 then
raise info 'this account exists in tmp_pcmn ';
perform attribut_insert(p_f_id,5,p_account);
else
-- account doesn't exist, create it
select av_text into sName from
attr_value join jnt_fic_att_value using (jft_id)
where
ad_id=1 and f_id=p_f_id;
nParent:=account_parent(p_account::poste_comptable);
insert into tmp_pcmn(pcm_val,pcm_lib,pcm_val_parent) values (p_account::poste_comptable,sName,nParent);
perform attribut_insert(p_f_id,5,p_account);
end if;
else
raise info 'presence of a comma';
-- there is 2 accounts separated by a comma
first := split_part(p_account,',',1);
second := split_part(p_account,',',2);
-- check there is no other coma
raise info 'first value % second value %', first, second;
if position (',' in first) != 0 or position (',' in second) != 0 then
raise exception 'Too many comas, invalid account';
end if;
perform attribut_insert(p_f_id,5,p_account);
end if;
else
raise info 'p_account is empty';
select fd_id into nFd_id from fiche where f_id=p_f_id;
bAuto:= account_auto(nFd_id);
if bAuto = true then
raise notice 'account generated automatically';
nNew:=account_compute(p_f_id);
raise notice 'nNew %', nNew;
select av_text into sName from
attr_value join jnt_fic_att_value using (jft_id)
where
ad_id=1 and f_id=p_f_id;
nParent:=account_parent(nNew);
perform account_add (nNew,sName);
perform attribut_insert(p_f_id,5,to_char(nNew,'999999999999999999999999'));
else
-- if there is an account_base then it is the default
select fd_class_base::text into nNew from fiche_def join fiche using (fd_id) where f_id=p_f_id;
if nNew is null or length(trim(nNew)) = 0 then
raise notice 'count is null';
perform attribut_insert(p_f_id,5,null);
else
perform attribut_insert(p_f_id,5,to_char(nNew,'999999999999999999999999'));
end if;
end if;
end if;
return 0;
end;
$BODY$
LANGUAGE 'plpgsql';
update version set val=69;
commit;

Some files were not shown because too many files have changed in this diff Show more