diff --git a/html/admin/sql/patch/upgrade72.sql b/html/admin/sql/patch/upgrade72.sql
new file mode 100644
index 000000000..974b47574
--- /dev/null
+++ b/html/admin/sql/patch/upgrade72.sql
@@ -0,0 +1,737 @@
+begin;
+create schema comptaproc;
+
+ alter function account_add (poste_comptable,character varying) set schema comptaproc;
+ alter function account_auto (integer) set schema comptaproc;
+ alter function account_compute (integer) set schema comptaproc;
+ alter function account_insert (integer,text) set schema comptaproc;
+ alter function account_parent (poste_comptable) set schema comptaproc;
+ alter function account_update (integer,text) set schema comptaproc;
+ alter function action_gestion_ins_upd () set schema comptaproc;
+ alter function attribut_insert (integer,integer,character varying) set schema comptaproc;
+ alter function attribute_correct_order () set schema comptaproc;
+ alter function card_class_base (integer) set schema comptaproc;
+ alter function check_balance (integer) set schema comptaproc;
+ alter function correct_sequence (text,text,text) set schema comptaproc;
+ alter function create_missing_sequence () set schema comptaproc;
+ alter function drop_index (character varying) set schema comptaproc;
+ alter function drop_it (character varying) set schema comptaproc;
+ alter function extension_ins_upd () set schema comptaproc;
+ alter function fiche_account_parent (integer) set schema comptaproc;
+ alter function fiche_attribut_synchro (integer) set schema comptaproc;
+ alter function fiche_def_ins_upd () set schema comptaproc;
+ alter function find_pcm_type (numeric) set schema comptaproc;
+ alter function group_analytic_ins_upd () set schema comptaproc;
+ alter function group_analytique_del () set schema comptaproc;
+ alter function html_quote (text) set schema comptaproc;
+ alter function info_def_ins_upd () set schema comptaproc;
+ alter 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) set schema comptaproc;
+ alter 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) set schema comptaproc;
+ alter 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) set schema comptaproc;
+ alter function insert_quick_code (integer,text) set schema comptaproc;
+ alter function jrn_check_periode () set schema comptaproc;
+ alter function jrn_def_add () set schema comptaproc;
+ alter function jrn_def_delete () set schema comptaproc;
+ alter function jrn_del () set schema comptaproc;
+ alter function jrnx_del () set schema comptaproc;
+ alter function plan_analytic_ins_upd () set schema comptaproc;
+ alter function poste_analytique_ins_upd () set schema comptaproc;
+ alter function proc_check_balance () set schema comptaproc;
+ alter function t_document_modele_validate () set schema comptaproc;
+ alter function t_document_type_insert () set schema comptaproc;
+ alter function t_document_validate () set schema comptaproc;
+ alter function t_jrn_def_sequence () set schema comptaproc;
+ alter function tmp_pcmn_ins () set schema comptaproc;
+ alter function trim_cvs_quote () set schema comptaproc;
+ alter function trim_space_format_csv_banque () set schema comptaproc;
+ alter function tva_delete (integer) set schema comptaproc;
+ alter function tva_insert (text,numeric,text,text) set schema comptaproc;
+ alter function tva_modify (integer,text,numeric,text,text) set schema comptaproc;
+ alter function update_quick_code (integer,text) set schema comptaproc;
+
+set search_path to public,comptaproc;
+alter table centralized DROP CONSTRAINT "$2";
+alter table jrnx DROP CONSTRAINT "$1";
+
+DROP VIEW vw_client ;
+DROP VIEW vw_fiche_attr ;
+DROP VIEW vw_fiche_def ;
+DROP VIEW vw_fiche_min ;
+DROP VIEW vw_poste_qcode ;
+DROP VIEW vw_supplier ;
+
+create domain account_type varchar(40);
+alter table tmp_pcmn alter pcm_val_parent type account_type;
+alter table tmp_pcmn alter pcm_val type account_type;
+alter table centralized alter c_poste type account_type;
+alter table del_jrnx alter j_poste type account_type;
+alter table fiche_def alter fd_class_base type text;
+alter table jrnx alter j_poste type account_type;
+alter table parm_poste alter p_value type account_type;
+
+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 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);
+
+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;
+
+ALTER TABLE vw_fiche_def OWNER TO trunk;
+COMMENT ON VIEW vw_fiche_def IS 'all the attributs for card family';
+
+
+CREATE OR REPLACE 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 OR REPLACE 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);
+
+CREATE OR REPLACE 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);
+
+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;
+
+alter table jrnx add CONSTRAINT fk_pcmn_val foreign key (j_poste) references tmp_pcmn (pcm_val);
+alter table centralized add CONSTRAINT fk_pcmn_val foreign key (c_poste) references tmp_pcmn (pcm_val);
+
+drop function comptaproc.account_add (p_id poste_comptable,t character varying) ;
+drop function comptaproc.account_parent (a poste_comptable) ;
+drop function comptaproc.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);
+drop function comptaproc.account_update(integer,text);
+drop function comptaproc.find_pcm_type(numeric);
+drop function comptaproc.account_compute(integer);
+
+--
+-- Name: account_update(integer, text); Type: FUNCTION; Schema: comptaproc; Owner: -
+--
+
+CREATE OR REPLACE FUNCTION account_update(p_f_id integer, p_account tmp_pcmn.pcm_val_parent%type ) 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;
+ 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);
+ insert into tmp_pcmn(pcm_val,pcm_lib,pcm_val_parent) values (p_account,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;
+$$
+ LANGUAGE plpgsql;
+
+
+--
+-- Name: insert_jrnx(character varying, numeric, public.account_type, integer, integer, boolean, text, integer, text, text); Type: FUNCTION; Schema: comptaproc; Owner: -
+--
+
+CREATE OR REPLACE FUNCTION insert_jrnx(p_date character varying, p_montant numeric, p_poste tmp_pcmn.pcm_val_parent%type, 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 $$
+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::text 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_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;
+$$
+ LANGUAGE plpgsql;
+
+
+--
+-- Name: tva_insert(text, numeric, text, text); Type: FUNCTION; Schema: comptaproc; Owner: -
+--
+
+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::account_type;
+ if nCount = 0 then return 4; end if;
+ select count(*) into nCount from tmp_pcmn where pcm_val=credit::account_type;
+ 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 OR REPLACE FUNCTION tva_modify(integer, text, numeric, text, text) RETURNS integer
+ AS $_$
+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::account_type;
+ if nCount = 0 then return 4; end if;
+ select count(*) into nCount from tmp_pcmn where pcm_val=credit::account_type;
+ 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;
+$_$
+ LANGUAGE plpgsql;
+
+-- Function: comptaproc.account_add(account_type, character varying)
+
+-- DROP FUNCTION comptaproc.account_add(account_type, character varying);
+
+CREATE OR REPLACE FUNCTION comptaproc.account_add(p_id account_type, p_name character varying)
+ RETURNS void AS
+$BODY$
+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 ;
+$BODY$
+LANGUAGE 'plpgsql';
+-- Function: comptaproc.account_compute(integer)
+
+-- DROP FUNCTION comptaproc.account_compute(integer);
+
+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 account_type;
+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::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;
+ return sResult;
+end;
+$BODY$
+ LANGUAGE 'plpgsql' ;
+-- Function: comptaproc.account_insert(integer, text)
+
+-- DROP FUNCTION comptaproc.account_insert(integer, text);
+
+CREATE OR REPLACE FUNCTION comptaproc.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;
+ sClass_Base fiche_def.fd_class_base%TYPE;
+ 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::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,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::account_type);
+ insert into tmp_pcmn(pcm_val,pcm_lib,pcm_val_parent) values (p_account::account_type,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);
+
+ 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';
+ nNew:=account_compute(p_f_id);
+ raise info '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,nNew);
+
+ else
+ -- if there is an account_base then it is the default
+ select fd_class_base::account_type 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,nNew);
+ end if;
+ end if;
+ end if;
+
+return 0;
+end;
+$BODY$
+ LANGUAGE 'plpgsql' ;
+-- Function: comptaproc.account_parent(account_type)
+
+-- DROP FUNCTION comptaproc.account_parent(account_type);
+
+CREATE OR REPLACE FUNCTION comptaproc.account_parent(p_account account_type)
+ RETURNS account_type AS
+$BODY$
+declare
+ sSubParent tmp_pcmn.pcm_val_parent%type;
+ sResult tmp_pcmn.pcm_val_parent%type;
+ nCount integer;
+begin
+ if p_account is NULL then
+ return NULL;
+ end if;
+ sSubParent:=p_account;
+ while true loop
+ select count(*) into nCount
+ from tmp_pcmn
+ where
+ pcm_val = sSubParent;
+ if nCount != 0 then
+ sResult:= sSubParent;
+ exit;
+ end if;
+ sSubParent:= substr(sSubParent,1,length(sSubParent)-1);
+ if length(sSubParent) <= 0 then
+ raise exception 'Impossible de trouver le compte parent pour %',p_account;
+ end if;
+ raise notice 'sSubParent % % ',sSubParent,length(sSubParent);
+ end loop;
+ raise notice 'account_parent : Parent is %',sSubParent;
+ return sSubParent;
+end;
+$BODY$
+ LANGUAGE 'plpgsql';
+-- Function: comptaproc.card_class_base(integer)
+
+-- DROP FUNCTION comptaproc.card_class_base(integer);
+DROP FUNCTION comptaproc.card_class_base(p_f_id integer);
+
+CREATE OR REPLACE FUNCTION comptaproc.card_class_base(p_f_id integer)
+ RETURNS fiche_def.fd_class_base%TYPE AS
+$BODY$
+declare
+ n_poste fiche_def.fd_class_base%type;
+begin
+
+ 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;
+$BODY$
+ LANGUAGE 'plpgsql' ;
+-- Function: comptaproc.fiche_account_parent(integer)
+
+-- DROP FUNCTION comptaproc.fiche_account_parent(integer);
+
+CREATE OR REPLACE FUNCTION comptaproc.fiche_account_parent(p_f_id integer)
+ RETURNS poste_comptable AS
+$BODY$
+declare
+ret tmp_pcmn.pcm_val%TYPE;
+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;
+$BODY$
+ LANGUAGE 'plpgsql' ;
+CREATE OR REPLACE FUNCTION comptaproc.find_pcm_type(pp_value account_type)
+ RETURNS text AS
+$BODY$
+declare
+ str_type parm_poste.p_type%TYPE;
+ str_value parm_poste.p_type%TYPE;
+ nLength integer;
+begin
+ str_value:=pp_value;
+ nLength:=length(str_value::text);
+ while nLength > 0 loop
+ select p_type into str_type from parm_poste where p_value=str_value;
+ if FOUND then
+ return str_type;
+ end if;
+ nLength:=nLength-1;
+ str_value:=substring(str_value::text from 1 for nLength)::account_type;
+ end loop;
+return 'CON';
+end;
+$BODY$
+ LANGUAGE 'plpgsql' VOLATILE;
+update version set val=73;
+commit;
diff --git a/include/central.inc.php b/include/central.inc.php
index 475a85f5d..3072a62cf 100644
--- a/include/central.inc.php
+++ b/include/central.inc.php
@@ -66,7 +66,7 @@ $period->cn=$cn;
$period->value=0;
$period->type=NOTCENTRALIZED;
try {
-$ret=$period->input();
+ $ret=$period->input();
} catch (Exception $e) {
if ( $e->getCode() != 0 ) {
echo $e->getMessage();
diff --git a/include/class_acc_operation.php b/include/class_acc_operation.php
index 313c2a5f8..1270ab844 100644
--- a/include/class_acc_operation.php
+++ b/include/class_acc_operation.php
@@ -82,7 +82,7 @@ var $jr_id; /*!< pk of jrn */
$debit=($this->type=='c')?'false':'true';
$this->desc=(isset($this->desc))?$this->desc:'';
$Res=$this->db->exec_sql("select insert_jrnx
- ($1::text,abs($2)::numeric,$3::poste_comptable,$4::integer,$5::integer,$6::bool,$7::text,$8::integer,upper($9),$10::text)",
+ ($1::text,abs($2)::numeric,$3::account_type,$4::integer,$5::integer,$6::bool,$7::text,$8::integer,upper($9),$10::text)",
array(
$this->date, //$1
round($this->amount,2), //$2
diff --git a/include/class_fiche_def.php b/include/class_fiche_def.php
index ab6ebc511..c19483be5 100644
--- a/include/class_fiche_def.php
+++ b/include/class_fiche_def.php
@@ -219,10 +219,8 @@ function input ()
// p_class must be added to tmp_pcmn if it is a single accounting
if ( strpos(',',$p_class_base) ==0) {
- $sql=sprintf("select account_add(%d,'%s')",
- $p_class_base,$p_nom_mod);
-
- $Res=$this->cn->exec_sql($sql);
+ $sql="select account_add($1,$2)";
+ $Res=$this->cn->exec_sql($sql,array($p_class_base,$p_nom_mod));
}
// Get the fd_id
diff --git a/include/constant.php b/include/constant.php
index 67f259ac6..6fe63b05d 100644
--- a/include/constant.php
+++ b/include/constant.php
@@ -26,7 +26,7 @@
require_once ('config.inc.php');
require_once('constant.security.php');
-define ("DBVERSION",72);
+define ("DBVERSION",73);
define ("MAX_COMPTE",4);
define ('MAX_ARTICLE',9);
diff --git a/include/impress.inc.php b/include/impress.inc.php
index cd875fd00..8b82fdc9e 100644
--- a/include/impress.inc.php
+++ b/include/impress.inc.php
@@ -34,8 +34,7 @@ $p_array=array(array ("?p_action=impress&type=jrn&".$str_dossier,_("Journaux")),
array("?p_action=impress&type=fiche&".$str_dossier,_("Fiche")),
array("?p_action=impress&type=rapport&".$str_dossier,_("Rapport")),
array('?p_action=impress&type=bal&'.$str_dossier,_('Balance des comptes')),
- array("?p_action=impress&type=bilan&".$str_dossier,_("Bilan")),
- array("?p_action=impress&type=list_client&".$str_dossier,_("Liste Clients Assujettis"))
+ array("?p_action=impress&type=bilan&".$str_dossier,_("Bilan"))
);
$default=( isset ($_GET['type']))?"?p_action=impress&type=".$_GET['type']."&$str_dossier":"";
diff --git a/include/impress_listing_client.inc.php b/include/impress_listing_client.inc.php
deleted file mode 100644
index 14da0052a..000000000
--- a/include/impress_listing_client.inc.php
+++ /dev/null
@@ -1,100 +0,0 @@
-VatListing($_POST['year']);
-
-echo "
-
";
- return;
- }
-
-//-----------------------------------------------------
-// Form
-//-----------------------------------------------------
-$w=new ISelect();
-$w->table=1;
-
-echo '';
-
-?>
diff --git a/sql/trunk/02_alter_function.sql b/sql/trunk/02_alter_function.sql
index 45aff9b9b..ed3a5aac2 100644
--- a/sql/trunk/02_alter_function.sql
+++ b/sql/trunk/02_alter_function.sql
@@ -1,6 +1,4 @@
-- version ==71
-
-begin;
alter function account_add (poste_comptable,character varying) set schema comptaproc;
alter function account_auto (integer) set schema comptaproc;
alter function account_compute (integer) set schema comptaproc;
@@ -9,11 +7,11 @@ begin;
alter function account_update (integer,text) set schema comptaproc;
alter function action_gestion_ins_upd () set schema comptaproc;
alter function attribut_insert (integer,integer,character varying) set schema comptaproc;
- alter function attribute_correct_order () set schema comptaproc;
+ alter function attribute_correct_order () set schema comptaproc;
alter function card_class_base (integer) set schema comptaproc;
alter function check_balance (integer) set schema comptaproc;
alter function correct_sequence (text,text,text) set schema comptaproc;
- alter function create_missing_sequence () set schema comptaproc;
+ alter function create_missing_sequence () set schema comptaproc;
alter function drop_index (character varying) set schema comptaproc;
alter function drop_it (character varying) set schema comptaproc;
alter function extension_ins_upd () set schema comptaproc;
@@ -25,14 +23,14 @@ begin;
alter function group_analytique_del () set schema comptaproc;
alter function html_quote (text) set schema comptaproc;
alter function info_def_ins_upd () set schema comptaproc;
- alter 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) set schema comptaproc;
+ alter 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) set schema comptaproc;
alter 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) set schema comptaproc;
alter 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) set schema comptaproc;
alter function insert_quick_code (integer,text) set schema comptaproc;
alter function jrn_check_periode () set schema comptaproc;
alter function jrn_def_add () set schema comptaproc;
alter function jrn_def_delete () set schema comptaproc;
- alter function jrn_del () set schema comptaproc;
+ alter function jrn_del () set schema comptaproc;
alter function jrnx_del () set schema comptaproc;
alter function plan_analytic_ins_upd () set schema comptaproc;
alter function poste_analytique_ins_upd () set schema comptaproc;
@@ -48,5 +46,3 @@ begin;
alter function tva_insert (text,numeric,text,text) set schema comptaproc;
alter function tva_modify (integer,text,numeric,text,text) set schema comptaproc;
alter function update_quick_code (integer,text) set schema comptaproc;
-commit;
-select 'ERREUR MAUVAISE VERSION' from version where val!=71;
\ No newline at end of file
diff --git a/sql/trunk/03_change_pcm_to_alphanum.sql b/sql/trunk/03_change_pcm_to_alphanum.sql
index df4a43fc1..c8d9e6db0 100644
--- a/sql/trunk/03_change_pcm_to_alphanum.sql
+++ b/sql/trunk/03_change_pcm_to_alphanum.sql
@@ -1,4 +1,3 @@
-begin;
set search_path to public,comptaproc;
alter table centralized DROP CONSTRAINT "$2";
@@ -17,20 +16,20 @@ alter table tmp_pcmn alter pcm_val type account_type;
alter table centralized alter c_poste type account_type;
alter table del_jrnx alter j_poste type account_type;
alter table fiche_def alter fd_class_base type text;
-alter table jrnx alter j_poste type account_type;
+alter table jrnx alter j_poste type account_type;
alter table parm_poste alter p_value type account_type;
-CREATE OR REPLACE VIEW vw_client AS
+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
+ 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
+ FROM fiche
JOIN fiche_def USING (fd_id)
JOIN fiche_def_ref USING (frd_id)
JOIN jnt_fic_att_value USING (f_id)
@@ -88,16 +87,16 @@ CREATE OR REPLACE VIEW vw_client AS
WHERE a.frd_id = 9;
-CREATE OR REPLACE VIEW vw_fiche_attr AS
+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
+ 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
+ FROM fiche
JOIN jnt_fic_att_value USING (f_id)
JOIN attr_value USING (jft_id)
JOIN attr_def USING (ad_id)
@@ -147,55 +146,55 @@ CREATE OR REPLACE VIEW vw_fiche_attr AS
LEFT JOIN tva_rate ON d.av_text = tva_rate.tva_id::text
JOIN fiche_def USING (fd_id);
-CREATE OR REPLACE VIEW vw_fiche_def AS
+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;
ALTER TABLE vw_fiche_def OWNER TO trunk;
-COMMENT ON VIEW vw_fiche_def IS 'all the attributs for card family';
+COMMENT ON VIEW vw_fiche_def IS 'all the attributs for card family';
-CREATE OR REPLACE VIEW vw_fiche_min AS
+CREATE OR REPLACE 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 OR REPLACE VIEW vw_poste_qcode AS
+CREATE OR REPLACE 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
+ 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
+ FROM attr_value
JOIN jnt_fic_att_value USING (jft_id)
WHERE jnt_fic_att_value.ad_id = 23) b USING (f_id);
-CREATE OR REPLACE VIEW vw_poste_qcode AS
+CREATE OR REPLACE 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
+ 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
+ FROM attr_value
JOIN jnt_fic_att_value USING (jft_id)
WHERE jnt_fic_att_value.ad_id = 23) b USING (f_id);
-CREATE OR REPLACE VIEW vw_supplier AS
+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
+ 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
+ FROM fiche
JOIN fiche_def USING (fd_id)
JOIN fiche_def_ref USING (frd_id)
JOIN jnt_fic_att_value USING (f_id)
@@ -255,6 +254,3 @@ CREATE OR REPLACE VIEW vw_supplier AS
alter table jrnx add CONSTRAINT fk_pcmn_val foreign key (j_poste) references tmp_pcmn (pcm_val);
alter table centralized add CONSTRAINT fk_pcmn_val foreign key (c_poste) references tmp_pcmn (pcm_val);
-
-commit;
-select 'ERREUR MAUVAISE VERSION' from version where val!=71;
diff --git a/sql/trunk/04_function_to_change.sql b/sql/trunk/04_function_to_change.sql
index bcfdfee1f..d6529d759 100644
--- a/sql/trunk/04_function_to_change.sql
+++ b/sql/trunk/04_function_to_change.sql
@@ -1,199 +1,9 @@
---
--- PostgreSQL database dump
---
-begin;
-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 = comptaproc, pg_catalog,public;
-
-drop function account_add (p_id poste_comptable,t character varying) ;
-drop function account_parent (a poste_comptable) ;
-drop 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);
-drop function account_update(integer,text);
-drop function find_pcm_type(numeric);
-drop function account_compute(integer);
---
--- Name: account_add(public.account_type, character varying); Type: FUNCTION; Schema: comptaproc; Owner: -
---
-
-CREATE OR REPLACE FUNCTION comptaproc.account_add(p_id tmp_pcmn.pcm_val_parent%type , p_name character varying) RETURNS void
- AS $$
-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;
-
-
-
---
--- Name: account_compute(integer); Type: FUNCTION; Schema: comptaproc; Owner: -
---
-
-CREATE OR REPLACE FUNCTION account_compute(p_f_id integer) RETURNS tmp_pcmn.pcm_val_parent%type
- AS $$
-declare
- class_base tmp_pcmn.pcm_val_parent%type;
- maxcode tmp_pcmn.pcm_val_parent%type;
-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::numeric*1000;
- end if;
- maxcode:=maxcode+1;
- raise notice 'account_compute Max code %',maxcode;
- return maxcode;
-end;
-$$
- LANGUAGE plpgsql;
-
-
---
--- Name: account_insert(integer, text); Type: FUNCTION; Schema: comptaproc; Owner: -
---
-
-CREATE OR REPLACE FUNCTION account_insert(p_f_id integer, p_account text) RETURNS integer
- AS $$
-declare
- nParent tmp_pcmn.pcm_val_parent%type;
- sName varchar;
- nNew tmp_pcmn.pcm_val%type;
- bAuto bool;
- nFd_id integer;
- sClass_Base tmp_pcmn.pcm_val_parent%type;
- 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::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,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::account_type);
- insert into tmp_pcmn(pcm_val,pcm_lib,pcm_val_parent) values (p_account::account_type,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);
-
- select fd_class_base into sClass_base from fiche_def where fd_id=nFid_id;
-
- if bAuto = true and sClass_base ~'^\\d*$' 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,nNew);
-
- else
- -- if there is an account_base then it is the default
- select fd_class_base::account_type 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,nNew);
- end if;
- end if;
- end if;
-
-return 0;
-end;
-$$
- LANGUAGE plpgsql;
-
-
---
--- Name: account_parent(public.account_type); Type: FUNCTION; Schema: comptaproc; Owner: -
---
-
-CREATE OR REPLACE FUNCTION comptaproc.account_parent(p_account public.account_type) RETURNS public.account_type
- AS $$
-declare
- sSubParent tmp_pcmn.pcm_val_parent%type;
- sResult tmp_pcmn.pcm_val_parent%type;
- nCount integer;
-begin
- nParent:=0;
- while nParent = 0 loop
- select count(*) into nCount
- from tmp_pcmn
- where
- pcm_val = sSubParent
- if nCount != 0 then
- sResult:= sSubParent;
- exit;
- end if;
- sSubParent:= substr(sSubParent,1,length(sSubParent)-1);
- if length(sSubParent) <= 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 sSubParent;
-end;
-$$
- LANGUAGE plpgsql;
-
+drop function comptaproc.account_add (p_id poste_comptable,t character varying) ;
+drop function comptaproc.account_parent (a poste_comptable) ;
+drop function comptaproc.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);
+drop function comptaproc.account_update(integer,text);
+drop function comptaproc.find_pcm_type(numeric);
+drop function comptaproc.account_compute(integer);
--
-- Name: account_update(integer, text); Type: FUNCTION; Schema: comptaproc; Owner: -
@@ -210,69 +20,40 @@ declare
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
+ 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;
- else
+ 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;
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;
-
---
--- Name: find_pcm_type(numeric); Type: FUNCTION; Schema: comptaproc; Owner: -
---
-
-CREATE OR REPLACE FUNCTION find_pcm_type(pp_value tmp_pcmn.pcm_val_parent%type) RETURNS text
- AS $$
-declare
- str_type text;
- str_value text;
- n_value numeric;
- nLength integer;
-begin
- str_value:=pp_value;
- nLength:=length(str_value);
- while nLength > 0 loop
- n_value:=str_value::numeric;
- 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;
-$$
- LANGUAGE plpgsql;
-
--
-- Name: insert_jrnx(character varying, numeric, public.account_type, integer, integer, boolean, text, integer, text, text); Type: FUNCTION; Schema: comptaproc; Owner: -
--
@@ -355,12 +136,12 @@ 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);
+ credit = split_part(p_tva_poste,',',2);
select count(*) into nCount from tmp_pcmn where pcm_val=debit::account_type;
if nCount = 0 then return 4; end if;
select count(*) into nCount from tmp_pcmn where pcm_val=credit::account_type;
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)
@@ -371,10 +152,6 @@ $_$
LANGUAGE plpgsql;
---
--- Name: tva_modify(integer, text, numeric, text, text); Type: FUNCTION; Schema: comptaproc; Owner: -
---
-
CREATE OR REPLACE FUNCTION tva_modify(integer, text, numeric, text, text) RETURNS integer
AS $_$
declare
@@ -394,12 +171,12 @@ 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);
+ credit = split_part(p_tva_poste,',',2);
select count(*) into nCount from tmp_pcmn where pcm_val=debit::account_type;
if nCount = 0 then return 4; end if;
select count(*) into nCount from tmp_pcmn where pcm_val=credit::account_type;
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;
@@ -408,4 +185,3 @@ end;
$_$
LANGUAGE plpgsql;
-commit;
diff --git a/sql/trunk/05_account_add.sql b/sql/trunk/05_account_add.sql
index 35d7933c3..53067f15e 100644
--- a/sql/trunk/05_account_add.sql
+++ b/sql/trunk/05_account_add.sql
@@ -18,5 +18,4 @@ begin
return;
end ;
$BODY$
- LANGUAGE 'plpgsql' VOLATILE
- COST 100;
+LANGUAGE 'plpgsql';
diff --git a/sql/trunk/05_account_compute.sql b/sql/trunk/05_account_compute.sql
index fbb4c1aae..5abd8e4b0 100644
--- a/sql/trunk/05_account_compute.sql
+++ b/sql/trunk/05_account_compute.sql
@@ -32,6 +32,4 @@ begin
return sResult;
end;
$BODY$
- LANGUAGE 'plpgsql' VOLATILE
- COST 100;
-ALTER FUNCTION comptaproc.account_compute(integer) OWNER TO trunk;
+ LANGUAGE 'plpgsql' ;
diff --git a/sql/trunk/05_account_insert.sql b/sql/trunk/05_account_insert.sql
index f9eaa2889..de7c0e84d 100644
--- a/sql/trunk/05_account_insert.sql
+++ b/sql/trunk/05_account_insert.sql
@@ -85,6 +85,4 @@ raise info 'sClass_Base : %',sClass_base;
return 0;
end;
$BODY$
- LANGUAGE 'plpgsql' VOLATILE
- COST 100;
-ALTER FUNCTION comptaproc.account_insert(integer, text) OWNER TO trunk;
+ LANGUAGE 'plpgsql' ;
diff --git a/sql/trunk/05_account_parent.sql b/sql/trunk/05_account_parent.sql
index 69f40561a..13ff0dfe7 100644
--- a/sql/trunk/05_account_parent.sql
+++ b/sql/trunk/05_account_parent.sql
@@ -33,6 +33,4 @@ begin
return sSubParent;
end;
$BODY$
- LANGUAGE 'plpgsql' VOLATILE
- COST 100;
-ALTER FUNCTION comptaproc.account_parent(account_type) OWNER TO trunk;
+ LANGUAGE 'plpgsql';
diff --git a/sql/trunk/05_card_class_base.sql b/sql/trunk/05_card_class_base.sql
index 533fc584e..51f77e60d 100644
--- a/sql/trunk/05_card_class_base.sql
+++ b/sql/trunk/05_card_class_base.sql
@@ -1,4 +1,4 @@
--- Function: comptaproc.card_class_base(integer)
+-- Function: comptaproc.card_class_base(integer)
-- DROP FUNCTION comptaproc.card_class_base(integer);
DROP FUNCTION comptaproc.card_class_base(p_f_id integer);
@@ -13,12 +13,10 @@ begin
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
+ if not FOUND then
raise exception 'Invalid fiche card_class_base(%)',p_f_id;
end if;
return n_poste;
-end;
+end;
$BODY$
- LANGUAGE 'plpgsql' VOLATILE
- COST 100;
-ALTER FUNCTION comptaproc.card_class_base(integer) OWNER TO trunk;
+ LANGUAGE 'plpgsql' ;
diff --git a/sql/trunk/05_fiche_account_parent.sql b/sql/trunk/05_fiche_account_parent.sql
index 162226045..784cc0e74 100644
--- a/sql/trunk/05_fiche_account_parent.sql
+++ b/sql/trunk/05_fiche_account_parent.sql
@@ -1,4 +1,4 @@
--- Function: comptaproc.fiche_account_parent(integer)
+-- Function: comptaproc.fiche_account_parent(integer)
-- DROP FUNCTION comptaproc.fiche_account_parent(integer);
@@ -15,6 +15,4 @@ begin
return ret;
end;
$BODY$
- LANGUAGE 'plpgsql' VOLATILE
- COST 100;
-ALTER FUNCTION comptaproc.fiche_account_parent(integer) OWNER TO trunk;
+ LANGUAGE 'plpgsql' ;
diff --git a/sql/trunk/plsql-orig.sql b/sql/trunk/plsql-orig.sql
index b7f7c038a..681cf42e4 100644
--- a/sql/trunk/plsql-orig.sql
+++ b/sql/trunk/plsql-orig.sql
@@ -66,27 +66,27 @@ $$
CREATE FUNCTION account_compute(p_f_id integer) RETURNS public.poste_comptable
AS $$
declare
- class_base poste_comptable;
- maxcode poste_comptable;
+ 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;
+ 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;
@@ -227,34 +227,34 @@ 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::poste_comptable;
if nCount = 0 then
- select av_text into sName from
+ 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
+ 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;
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;
$$
@@ -282,7 +282,7 @@ $$
CREATE FUNCTION attribut_insert(p_f_id integer, p_ad_id integer, p_value character varying) RETURNS void
AS $$
-declare
+declare
n_jft_id integer;
begin
select nextval('s_jnt_fic_att_value') into n_jft_id;
@@ -333,11 +333,11 @@ begin
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
+ if not FOUND then
raise exception 'Invalid fiche card_class_base(%)',p_f_id;
end if;
return n_poste;
-end;
+end;
$$
LANGUAGE plpgsql;
@@ -348,29 +348,29 @@ $$
CREATE FUNCTION check_balance(p_grpt integer) RETURNS numeric
AS $$
-declare
+declare
amount_jrnx_debit numeric;
amount_jrnx_credit numeric;
amount_jrn numeric;
begin
- select sum (j_montant) into amount_jrnx_credit
- from jrnx
- where
+ 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
+ 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
+ select jr_montant into amount_jrn
from jrn
where
jr_grpt_id=p_grpt;
- if ( amount_jrnx_debit != amount_jrnx_credit )
+ if ( amount_jrnx_debit != amount_jrnx_credit )
then
return abs(amount_jrnx_debit-amount_jrnx_credit);
end if;
@@ -401,7 +401,7 @@ begin
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;
+ raise exception ' Unknow table % ',p_table;
end if;
execute 'select last_value from '||p_sequence into last_sequence;
@@ -412,7 +412,7 @@ begin
max_sequence := 0;
end if;
raise notice 'Max value of the sequence is %', max_sequence;
- max_sequence:= max_sequence +1;
+ max_sequence:= max_sequence +1;
execute 'alter sequence '||p_sequence||' restart with '||max_sequence;
return 0;
@@ -443,8 +443,8 @@ begin
loop
fetch c1 into nSeq;
if not FOUND THEN
- close c1;
- return 0;
+ close c1;
+ return 0;
end if;
p_sequence:='s_jrn_pj'||nSeq::text;
execute 'create sequence '||p_sequence;
@@ -463,7 +463,7 @@ $$
CREATE FUNCTION drop_index(p_constraint character varying) RETURNS void
AS $$
-declare
+declare
nCount integer;
begin
select count(*) into nCount from pg_indexes where indexname=p_constraint;
@@ -481,7 +481,7 @@ $$
CREATE FUNCTION drop_it(p_constraint character varying) RETURNS void
AS $$
-declare
+declare
nCount integer;
begin
select count(*) into nCount from pg_constraint where conname=p_constraint;
@@ -560,19 +560,19 @@ declare
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;
+ 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;
+end;
$$
LANGUAGE plpgsql;
@@ -601,21 +601,21 @@ end;$$
CREATE FUNCTION find_pcm_type(pp_value numeric) RETURNS text
AS $$
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);
+ 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;
+ 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);
+ str_value:=substring(str_value from 1 for nLength);
end loop;
return 'CON';
end;
@@ -629,7 +629,7 @@ $$
CREATE FUNCTION group_analytic_ins_upd() RETURNS trigger
AS $$
-declare
+declare
name text;
begin
name:=upper(NEW.ga_id);
@@ -686,7 +686,7 @@ COMMENT ON FUNCTION html_quote(p_string text) IS 'remove harmfull HTML char';
CREATE FUNCTION info_def_ins_upd() RETURNS trigger
AS $$
-declare
+declare
row_info_def info_def%ROWTYPE;
str_type text;
begin
@@ -848,7 +848,7 @@ CREATE FUNCTION insert_quick_code(nf_id integer, tav_text text) RETURNS integer
begin
tText := upper(trim(tav_text));
tText := replace(tText,' ','');
-
+
loop
-- take the next sequence
select nextval('s_jnt_fic_att_value') into ns;
@@ -856,9 +856,9 @@ CREATE FUNCTION insert_quick_code(nf_id integer, tav_text text) RETURNS integer
tText := 'FID'||ns;
end if;
-- av_text already used ?
- select count(*) into nExist
- from jnt_fic_att_value join attr_value using (jft_id)
- where
+ select count(*) into nExist
+ from jnt_fic_att_value join attr_value using (jft_id)
+ where
ad_id=23 and av_text=upper(tText);
if nExist = 0 then
@@ -882,7 +882,7 @@ $$
CREATE FUNCTION jrn_check_periode() RETURNS trigger
AS $$
-declare
+declare
bClosed bool;
str_status text;
ljr_tech_per jrn.jr_tech_per%TYPE;
@@ -892,23 +892,23 @@ begin
if TG_OP='INSERT' then
ljr_tech_per :=NEW.jr_tech_per;
ljr_def_id :=NEW.jr_def_id;
- lreturn :=NEW;
+ 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;
+ lreturn :=OLD;
end if;
-select p_closed into bClosed from parm_periode
+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
+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
@@ -944,7 +944,7 @@ end;$$
CREATE FUNCTION jrn_def_delete() RETURNS trigger
AS $$
-declare
+declare
nb numeric;
begin
select count(*) into nb from jrn where jr_def_id=OLD.jrn_def_id;
@@ -986,7 +986,7 @@ insert into del_jrn ( jr_id,
jr_pj_name,
jr_pj_type,
jr_pj_number,
- del_jrn_date)
+ del_jrn_date)
select jr_id,
jr_def_id,
jr_montant,
@@ -1061,7 +1061,7 @@ rCount record;
begin
name:=upper(NEW.po_name);
name:=trim(name);
-name:=replace(name,' ','');
+name:=replace(name,' ','');
NEW.po_name:=name;
if NEW.ga_id is NULL then
@@ -1087,7 +1087,7 @@ end;$$
CREATE FUNCTION proc_check_balance() RETURNS trigger
AS $$
-declare
+declare
diff numeric;
tt integer;
begin
@@ -1110,7 +1110,7 @@ $$
CREATE FUNCTION t_document_modele_validate() RETURNS trigger
AS $$
-declare
+declare
lText text;
modified document_modele%ROWTYPE;
begin
@@ -1134,9 +1134,9 @@ 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;
+ execute 'create sequence seq_doc_type_'||NEW.dt_id;
end if;
- RETURN NEW;
+ RETURN NEW;
END;
$$
LANGUAGE plpgsql;
@@ -1152,7 +1152,7 @@ declare
lText text;
modified document%ROWTYPE;
begin
- modified:=NEW;
+ modified:=NEW;
modified.d_filename:=replace(NEW.d_filename,' ','_');
return modified;
end;
@@ -1170,14 +1170,14 @@ declare
nCounter integer;
BEGIN
- select count(*) into nCounter
+ 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;
+ execute 'create sequence s_jrn_'||NEW.jrn_def_id;
raise notice 'Creating sequence s_jrn_%',NEW.jrn_def_id;
end if;
- RETURN NEW;
+ RETURN NEW;
END;
$$
LANGUAGE plpgsql;
@@ -1193,7 +1193,7 @@ 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
+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;
@@ -1210,14 +1210,14 @@ $$
CREATE FUNCTION trim_cvs_quote() RETURNS trigger
AS $$
declare
- modified import_tmp%ROWTYPE;
+ 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,'"','');
+ modified.compte_ordre=replace(NEW.COMPTE_ORDRE,'"','');
+ modified.detail=replace(NEW.DETAIL,'"','');
+ modified.num_compte=replace(NEW.NUM_COMPTE,'"','');
return modified;
end;
$$
@@ -1231,10 +1231,10 @@ $$
CREATE FUNCTION trim_space_format_csv_banque() RETURNS trigger
AS $$
declare
- modified format_csv_banque%ROWTYPE;
+ modified format_csv_banque%ROWTYPE;
begin
- modified.name=trim(NEW.NAME);
- modified.include_file=trim(new.include_file);
+ modified.name=trim(NEW.NAME);
+ modified.include_file=trim(new.include_file);
if ( length(modified.name) = 0 ) then
modified.name=null;
end if;
@@ -1242,7 +1242,7 @@ begin
modified.include_file=null;
end if;
- return modified;
+ return modified;
end;
$$
LANGUAGE plpgsql;
@@ -1253,7 +1253,7 @@ $$
--
CREATE FUNCTION tva_delete(integer) RETURNS void
- AS $_$
+ AS $_$
declare
p_tva_id alias for $1;
nCount integer;
@@ -1261,13 +1261,13 @@ begin
nCount=0;
select count(*) into nCount from quant_sold where qs_vat_code=p_tva_id;
if nCount != 0 then
- return;
-
+ return;
+
end if;
select count(*) into nCount from quant_purchase where qp_vat_code=p_tva_id;
if nCount != 0 then
- return;
-
+ return;
+
end if;
delete from tva_rate where tva_id=p_tva_id;
@@ -1300,12 +1300,12 @@ 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);
+ 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)
@@ -1339,12 +1339,12 @@ 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);
+ 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;
@@ -1372,39 +1372,39 @@ CREATE FUNCTION update_quick_code(njft_id integer, tav_text text) RETURNS intege
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
+ 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;
+ 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)
+ 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);