diff --git a/dev/extract_text.sh b/dev/extract_text.sh index 91c199045..f1f23b0d2 100644 --- a/dev/extract_text.sh +++ b/dev/extract_text.sh @@ -7,8 +7,11 @@ # Author D. DE BONTRIDDER danydb@aevalys.eu echo "Extract" cd .. +FILE=/tmp/file-list.$$ + +find . -type f -name \*.php > $FILE # CATALOG -xgettext -L PHP -j --from-code=UTF-8 -p html/lang/ html/*.php include/*.php include/template/*.php include/ext/*/*.php include/ext/*/include/*.php include/ext/*/include/template/*.php include/lib/*.php include/ajax/*.php include/export/*.php include/class/*.php +xgettext -L PHP -j --from-code=UTF-8 -p html/lang -f $FILE # For dutch echo "Dutch" diff --git a/html/do.php b/html/do.php index 73669e6db..71f687dca 100644 --- a/html/do.php +++ b/html/do.php @@ -1,5 +1,4 @@ \ No newline at end of file + + diff --git a/include/sql/patch/upgrade129.sql b/include/sql/patch/upgrade129.sql new file mode 100644 index 000000000..80fd93f0a --- /dev/null +++ b/include/sql/patch/upgrade129.sql @@ -0,0 +1,109 @@ +begin; +INSERT INTO public.menu_ref +(me_code, me_menu, me_file, me_url, me_description, me_parameter, me_javascript, me_type, me_description_etendue) +VALUES('CFGCURRENCY', 'Devises', 'acc_currency_cfg.inc.php', NULL, 'Configuration des devises', NULL,NULL,'ME','Permet de configurer les devises'); + +INSERT INTO public.profile_menu +(pm_id, me_code, me_code_dep, p_id, p_order, p_type_display, pm_default, pm_id_dep) +VALUES(nextval('profile_menu_pm_id_seq'), 'CFGCURRENCY', 'PARAM', 1, 50, 'E', 0, 45); + +-- Drop table + +-- DROP TABLE public.currency + +CREATE TABLE public.currency ( + id serial NOT NULL, + cr_code_iso varchar(10) NULL, + CONSTRAINT currency_pk PRIMARY KEY (id), + CONSTRAINT currency_un UNIQUE (cr_code_iso) +); + + +-- Drop table + +-- DROP TABLE public.currency_history + +CREATE TABLE public.currency_history ( + id serial NOT NULL, + ch_value numeric(20,6) NOT NULL, + ch_from date NOT NULL, + currency_id int4 NOT NULL, + CONSTRAINT currency_history_pk PRIMARY KEY (id), + CONSTRAINT currency_history_currency_fk FOREIGN KEY (currency_id) REFERENCES currency(id) + ON DELETE RESTRICT ON UPDATE CASCADE +) +; + +-- Ajouter commentaire sur colonne + +ALTER TABLE public.currency ADD cr_name varchar(80) NULL; +insert into currency (id,cr_code_iso,cr_name) values (0,'EUR','EUR'); +insert into currency (cr_code_iso,cr_name) values ('XCFA','XCFA'); +insert into currency_history (ch_value,ch_from,currency_id) values (1,to_date('01.01.2000','DD.MM.YYYY'),0); +insert into currency_history (ch_value,ch_from,currency_id) values (655.95700,to_date('01.01.2000','DD.MM.YYYY'),1); + +ALTER TABLE public.currency_history ADD CONSTRAINT currency_history_check CHECK (ch_value > 0) ; + +-- Create view to manage the table +create view v_currency_last_value as +with recent_rate as +( select + currency_id,max(ch_from) as rc_from + from + currency_history + group by currency_id + ) +select + cr1.id as currency_id, + cr1.cr_name, + cr1.cr_code_iso, + ch1.id as currency_history_id, + ch1.ch_value as ch_value, + to_char(rc_from,'DD.MM.YYYY') as str_from +from +currency as cr1 +join recent_rate on (currency_id=cr1.id) +join currency_history as ch1 on (recent_rate.currency_id=ch1.currency_id and rc_from=ch1.ch_from); + +COMMENT ON COLUMN public.currency_history.id IS 'pk' ; +COMMENT ON COLUMN public.currency_history.ch_value IS 'rate of currency depending of currency of the folder' ; +COMMENT ON COLUMN public.currency_history.ch_from IS 'Date when the rate is available' ; +COMMENT ON COLUMN public.currency_history.currency_id IS 'FK to currency' ; +COMMENT ON COLUMN public.currency.cr_code_iso IS 'Code ISO' ; +COMMENT ON COLUMN public.currency.cr_name IS 'Name of the currency' ; + + + +-- Drop table + +-- DROP TABLE public.operation_currency + +CREATE TABLE public.operation_currency ( + id bigserial NOT NULL, + oc_amount numeric(20,6) NOT NULL, -- amount in currency + oc_vat_amount numeric(20,6) NULL DEFAULT 0, -- vat amount in currency + oc_price_unit numeric(20,6) NULL, -- unit price in currency + j_id int8 NOT NULL, -- fk to jrnx + CONSTRAINT operation_currency_pk PRIMARY KEY (id) +); + +ALTER TABLE public.operation_currency ADD CONSTRAINT operation_currency_jrnx_fk FOREIGN KEY (j_id) REFERENCES public.jrnx(j_id) ON DELETE CASCADE ON UPDATE CASCADE; + +-- Column comments + +COMMENT ON COLUMN public.operation_currency.oc_amount IS 'amount in currency' ; +COMMENT ON COLUMN public.operation_currency.oc_vat_amount IS 'vat amount in currency' ; +COMMENT ON COLUMN public.operation_currency.oc_price_unit IS 'unit price in currency' ; +COMMENT ON COLUMN public.operation_currency.j_id IS 'fk to jrnx' ; +alter table jrn add currency_id bigint default 0; +update jrn set currency_id=0; +alter table jrn add currency_rate numeric (20,6) default 1; +update jrn set currency_rate=1; +alter table jrn add currency_rate_ref numeric(20,6) default 1; +update jrn set currency_rate_ref=1; +ALTER TABLE public.jrn ADD CONSTRAINT jrn_currency_fk FOREIGN KEY (currency_id) REFERENCES public.currency(id) ON DELETE RESTRICT ON UPDATE RESTRICT; + + + +insert into version (val,v_description) values (130,'Currency : create view , create tables '); +commit; diff --git a/include/sql/patch/upgrade130.sql b/include/sql/patch/upgrade130.sql new file mode 100644 index 000000000..cfecdda82 --- /dev/null +++ b/include/sql/patch/upgrade130.sql @@ -0,0 +1,46 @@ +begin; + +CREATE OR REPLACE FUNCTION isnumeric(text) RETURNS BOOLEAN AS $$ +DECLARE x NUMERIC; +BEGIN + x = $1::NUMERIC; + RETURN TRUE; +EXCEPTION WHEN others THEN + RETURN FALSE; +END; +$$ +STRICT +LANGUAGE plpgsql IMMUTABLE; + +CREATE OR REPLACE FUNCTION isdate(text,text) RETURNS BOOLEAN AS $$ +DECLARE x timestamp; +BEGIN + x := to_date($1,$2); + RETURN TRUE; +EXCEPTION WHEN others THEN + RETURN FALSE; +END; +$$ +LANGUAGE plpgsql; + +ALTER TABLE public.jrn_def ADD currency_id int NULL; +ALTER TABLE public.jrn_def ALTER COLUMN currency_id SET DEFAULT 0; +update public.jrn_def set currency_id = 0 ; +ALTER TABLE public.jrn_def ALTER COLUMN currency_id SET NOT NULL; +ALTER TABLE public.jrn_def ADD CONSTRAINT jrn_def_currency_fk FOREIGN KEY (currency_id) REFERENCES public.currency(id); + +COMMENT ON COLUMN public.jrn_def.currency_id IS 'Default currency for financial ledger'; + + +alter table quant_fin add j_id bigint; + +with j_fin as ( +select jrnx.j_id,quant_fin.qf_id from quant_fin join jrn using (jr_id) join jrnx on (j_grpt=jr_grpt_id and f_id=qf_other) +) +update quant_fin set j_id =j_fin.j_id from j_fin where j_fin.qf_id=quant_fin.qf_id; + +alter table quant_fin add constraint jrnx_j_id_fk foreign key (j_id ) references jrnx(j_id) on delete cascade on update cascade; + + +insert into version (val,v_description) values (131,'Currency : adapt quant_fin'); +commit; diff --git a/include/sql/patch/upgrade131.sql b/include/sql/patch/upgrade131.sql new file mode 100644 index 000000000..17dd1c86f --- /dev/null +++ b/include/sql/patch/upgrade131.sql @@ -0,0 +1,180 @@ +begin; + +drop VIEW public.v_detail_sale; + +CREATE OR REPLACE VIEW public.v_detail_sale as +WITH m AS ( + SELECT sum(quant_sold_1.qs_price) AS htva, + sum(quant_sold_1.qs_vat) AS tot_vat, + sum(quant_sold_1.qs_vat_sided) AS tot_tva_np, + jrn_1.jr_id + FROM quant_sold quant_sold_1 + JOIN jrnx jrnx_1 USING (j_id) + JOIN jrn jrn_1 ON jrnx_1.j_grpt = jrn_1.jr_grpt_id + GROUP BY jrn_1.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, + oc.oc_amount, + oc.oc_vat_amount, + (select cr_code_iso from currency where jrn.currency_id=currency.id) as cr_code_iso + 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 + left join operation_currency as oc on (oc.j_id=jrnx.j_id) +; + +drop VIEW public.v_detail_purchase; + +CREATE OR REPLACE VIEW public.v_detail_purchase +AS WITH m AS ( + SELECT sum(quant_purchase_1.qp_price) AS htva, + sum(quant_purchase_1.qp_vat) AS tot_vat, + sum(quant_purchase_1.qp_vat_sided) AS tot_tva_np, + jrn_1.jr_id + FROM quant_purchase quant_purchase_1 + JOIN jrnx jrnx_1 USING (j_id) + JOIN jrn jrn_1 ON jrnx_1.j_grpt = jrn_1.jr_grpt_id + GROUP BY jrn_1.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, + oc.oc_amount, + oc.oc_vat_amount, + (select cr_code_iso from currency where jrn.currency_id=currency.id) as cr_code_iso + 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 + left join operation_currency as oc on (oc.j_id=jrnx.j_id) +; + + create or replace view v_all_account_currency as +select sum(oc_amount) as sum_oc_amount,sum(oc_vat_amount) as sum_oc_vat_amount,x.j_poste,x.j_id +from +quant_fin as q1 +join (select j_id ,jr_id,f_id,j_poste + from jrnx as j1 join + jrn as j on (j1.j_grpt=jr_grpt_id) +) as x on (q1.jr_id=x.jr_id) +join operation_currency as oc on (oc.j_id=q1.j_id) +group by x.j_poste,x.j_id +union all +select sum(oc_amount),sum(oc_vat_amount),x.j_poste,x.j_id +from +quant_purchase as q1 +join (select j_id ,jr_id,f_id,j_poste,jr_internal + from jrnx as j1 join + jrn as j on (j1.j_grpt=jr_grpt_id) +) as x on (q1.qp_internal=x.jr_internal and (x.f_id=q1.qp_fiche or x.f_id=qp_supplier) ) +join operation_currency as oc on (oc.j_id=q1.j_id) +group by x.j_poste,x.j_id +union all +select sum(oc_amount),sum(oc_vat_amount),x.j_poste,x.j_id +from +quant_sold as q1 +join (select j_id ,jr_id,f_id,j_poste,jr_internal + from jrnx as j1 join + jrn as j on (j1.j_grpt=jr_grpt_id) +) as x on (q1.qs_internal=x.jr_internal and (x.f_id=q1.qs_fiche or x.f_id=q1.qs_client) ) +join operation_currency as oc on (oc.j_id=q1.j_id) +group by x.j_poste,x.j_id +; + +create or replace view v_all_card_currency as +select sum(oc_amount) as sum_oc_amount,sum(oc_vat_amount) as sum_oc_vat_amount,x.f_id,x.j_id +from +quant_fin as q1 +join (select j_id ,jr_id,f_id,j_poste + from jrnx as j1 join + jrn as j on (j1.j_grpt=jr_grpt_id) +) as x on (q1.jr_id=x.jr_id) +join operation_currency as oc on (oc.j_id=q1.j_id) +group by x.f_id,x.j_id +union all +select sum(oc_amount),sum(oc_vat_amount),x.f_id,x.j_id +from +quant_purchase as q1 +join (select j_id ,jr_id,f_id,j_poste,jr_internal + from jrnx as j1 join + jrn as j on (j1.j_grpt=jr_grpt_id) +) as x on (q1.qp_internal=x.jr_internal and (x.f_id=q1.qp_fiche or x.f_id=qp_supplier) ) +join operation_currency as oc on (oc.j_id=q1.j_id) +group by x.f_id,x.j_id +union all +select sum(oc_amount),sum(oc_vat_amount),x.f_id,x.j_id +from +quant_sold as q1 +join (select j_id ,jr_id,f_id,j_poste,jr_internal + from jrnx as j1 join + jrn as j on (j1.j_grpt=jr_grpt_id) +) as x on (q1.qs_internal=x.jr_internal and (x.f_id=q1.qs_fiche or x.f_id=q1.qs_client) ) +join operation_currency as oc on (oc.j_id=q1.j_id) +group by x.f_id,x.j_id +; +insert into version (val,v_description) values (132,'Currency : Create view for managing currency '); +commit; diff --git a/include/template/ledger_detail_bottom.php b/include/template/ledger_detail_bottom.php index 713557847..91b4f7c9c 100644 --- a/include/template/ledger_detail_bottom.php +++ b/include/template/ledger_detail_bottom.php @@ -30,12 +30,12 @@ $aRap=$oRap->get(); $nb_document=($detail->det->jr_pj_name != "")?1:0; - +$nb_aRap=(is_array($aRap))?count($aRap):0; // Array of tab // $a_tab['writing_div']=array('id'=>'writing_div'.$div,'label'=>_('Ecriture Comptable'),'display'=>'none'); $a_tab['info_operation_div']=array('id'=>'info_operation_div'.$div,'label'=>_('Information'),'display'=>'none'); -$a_tab['linked_operation_div']=array('id'=>'linked_operation_div'.$div,'label'=>_('Opérations liées').'('.count($aRap).')','display'=>'none'); +$a_tab['linked_operation_div']=array('id'=>'linked_operation_div'.$div,'label'=>_('Opérations liées').'('.$nb_aRap.')','display'=>'none'); $a_tab['document_operation_div']=array('id'=>'document_operation_div'.$div,'label'=>_('Document').'('.$nb_document.')','display'=>'block'); $a_tab['linked_action_div']=array('id'=>'linked_action_div'.$div,'label'=>_('Actions Gestion').'('.count($a_followup).')','display'=>'none'); $a_tab['analytic_div']=array('id'=>'analytic_div'.$div,'label'=>_('Comptabilité Analytique'),'display'=>'none'); diff --git a/sql/upgrade.sql b/sql/upgrade.sql index f3340f58e..e69de29bb 100644 --- a/sql/upgrade.sql +++ b/sql/upgrade.sql @@ -1,55 +0,0 @@ -CREATE OR REPLACE FUNCTION comptaproc.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, p_tva_sided numeric, p_price_unit numeric) - RETURNS void - LANGUAGE plpgsql -AS $function$ -declare - fid_client integer; - fid_good integer; - account_priv account_type; - fid_good_account account_type; - n_dep_priv numeric; -begin - n_dep_priv := p_dep_priv; - 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, - qp_unit) - 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, - p_price_unit); - return; -end; - $function$ \ No newline at end of file