From 85da98dc7323e9f0ee997ffd949fc3702bc94593 Mon Sep 17 00:00:00 2001 From: Dany De Bontridder Date: Thu, 1 Jul 2010 12:45:22 +0000 Subject: [PATCH] Merged revisions 3366 via svnmerge from file:///home/developper/svn/phpcompta/branches/rel510 ........ r3366 | danydb | 2010-07-01 00:46:39 +0200 (Thu, 01 Jul 2010) | 2 lines Fix some bug with extourne ........ --- sql/upgrade.sql | 51 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 3 deletions(-) diff --git a/sql/upgrade.sql b/sql/upgrade.sql index 085a4126f..e0bc6a066 100644 --- a/sql/upgrade.sql +++ b/sql/upgrade.sql @@ -8,10 +8,12 @@ declare sSupplier text; rec record; recBank record; + recSupp_Cust record; nCount integer; nAmount numeric; nBank integer; nOther integer; + nSupp_Cust integer; begin select p_value into sBank from parm_code where p_code='BANQUE'; select p_value into sCassa from parm_code where p_code='CAISSE'; @@ -93,7 +95,7 @@ begin nSupp_Cust := 0; nOther:=0; for recSupp_Cust in select j_id, j_montant,j_debit,j_qcode,j_poste from jrnx where j_grpt=rec.jr_grpt_id loop - if recSupp_Cust.j_poste like sSupplier||'%' or recSupp_Cust.j_poste like sCustomer||'%' then + if recSupp_Cust.j_poste like sSupplier||'%' then -- retrieve f_id for bank select f_id into nSupp_Cust from vw_poste_qcode where j_qcode=recSupp_Cust.j_qcode; if recSupp_Cust.j_debit = true then @@ -101,19 +103,62 @@ begin else nAmount=recSupp_Cust.j_montant; end if; - else + else if recSupp_Cust.j_poste like sCustomer||'%' then + select f_id into nSupp_Cust from vw_poste_qcode where j_qcode=recSupp_Cust.j_qcode; + if recSupp_Cust.j_debit = false then + nAmount=recSupp_Cust.j_montant*(-1); + else + nAmount=recSupp_Cust.j_montant; + end if; + else select f_id into nOther from vw_poste_qcode where j_qcode=recSupp_Cust.j_qcode; + + end if; + end if; + end loop; + if nSupp_Cust != 0 and nOther != 0 then + insert into quant_fin (jr_id,qf_bank,qf_other,qf_amount) values (rec.jr_id,nOther,nSupp_Cust,nAmount); + end if; + end loop; +-- if row remains + for rec in select jr_id,jr_grpt_id from jrn + where jr_def_id in (select jrn_def_id from jrn_def where jrn_def_type='FIN') and jr_id not in (select jr_id from quant_fin) + loop + -- there are only 2 lines for bank operations + -- first debit + select count(j_id) into nCount from jrnx where j_grpt=rec.jr_grpt_id; + if nCount > 2 then + raise notice 'Trop de valeur pour jr_grpt_id % count %',rec.jr_grpt_id,nCount; + return; + end if; + nSupp_Cust := 0; nOther:=0; + for recSupp_Cust in select j_id, j_montant,j_debit,j_qcode,j_poste from jrnx where j_grpt=rec.jr_grpt_id + loop + if recSupp_Cust.j_poste like '441%' then + -- retrieve f_id for bank + select f_id into nSupp_Cust from vw_poste_qcode where j_qcode=recSupp_Cust.j_qcode; + if recSupp_Cust.j_debit = false then + nAmount=recSupp_Cust.j_montant*(-1); + else + nAmount=recSupp_Cust.j_montant; + end if; + else + select f_id into nOther from vw_poste_qcode where j_qcode=recSupp_Cust.j_qcode; + + end if; end loop; if nSupp_Cust != 0 and nOther != 0 then insert into quant_fin (jr_id,qf_bank,qf_other,qf_amount) values (rec.jr_id,nOther,nSupp_Cust,nAmount); end if; end loop; - return; end; $_$ language plpgsql; select comptaproc.fill_quant_fin(); +update jrnx set j_date=jr_date from jrn where j_grpt=jr_grpt_id; +update jrnx set j_jrn_def=jr_def_id from jrn where j_grpt=jr_grpt_id; + commit;