diff --git a/html/admin/sql/patch/upgrade76.sql b/html/admin/sql/patch/upgrade76.sql index 7d2fdc12a..892461d44 100644 --- a/html/admin/sql/patch/upgrade76.sql +++ b/html/admin/sql/patch/upgrade76.sql @@ -1,4 +1,6 @@ begin; +drop table if exists quant_fin; + CREATE TABLE quant_fin ( qf_id bigserial NOT NULL, @@ -68,5 +70,14 @@ end; $_$ language plpgsql; select comptaproc.fill_quant_fin(); + +alter table del_jrn drop constraint jr_id; +alter table del_jrn add dj_id serial; +alter table del_jrn add constraint dj_id primary key(dj_id); + +alter table del_jrnx drop constraint j_id; +alter table del_jrnx add djx_id serial; +alter table del_jrnx add constraint djx_id primary key(djx_id); + update version set val=77; commit; \ No newline at end of file diff --git a/html/admin/sql/patch/upgrade77.sql b/html/admin/sql/patch/upgrade77.sql new file mode 100644 index 000000000..1809ce14c --- /dev/null +++ b/html/admin/sql/patch/upgrade77.sql @@ -0,0 +1,83 @@ +begin; +drop table if exists quant_fin; + +CREATE TABLE quant_fin +( + qf_id bigserial NOT NULL, + qf_bank bigint, + jr_id bigint, + qf_other bigint, + qf_amount numeric(20,4) DEFAULT 0, + CONSTRAINT quant_fin_pk PRIMARY KEY (qf_id), + CONSTRAINT fk_card FOREIGN KEY (qf_bank) + REFERENCES fiche (f_id) MATCH SIMPLE + ON UPDATE CASCADE ON DELETE CASCADE, + CONSTRAINT fk_card_other FOREIGN KEY (qf_other) + REFERENCES fiche (f_id) MATCH SIMPLE + ON UPDATE CASCADE ON DELETE CASCADE, + CONSTRAINT fk_jrn FOREIGN KEY (jr_id) + REFERENCES jrn (jr_id) MATCH SIMPLE + ON UPDATE CASCADE ON DELETE CASCADE +); +COMMENT ON TABLE quant_fin IS 'Simple operation for financial'; + +create or replace function comptaproc.fill_quant_fin() returns void as +$_$ +declare + sBank text; + sCassa text; + rec record; + recBank record; + nCount integer; + nAmount numeric; + nBank integer; + nOther 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'; + + 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') + 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; + nBank := 0; nOther:=0; + for recBank in select j_id, j_montant,j_debit,j_qcode,j_poste from jrnx where j_grpt=rec.jr_grpt_id + loop + if recBank.j_poste like sBank||'%' then + -- retrieve f_id for bank + select f_id into nBank from vw_poste_qcode where j_qcode=recBank.j_qcode; + if recBank.j_debit = false then + nAmount=recBank.j_montant*(-1); + else + nAmount=recBank.j_montant; + end if; + else + select f_id into nOther from vw_poste_qcode where j_qcode=recBank.j_qcode; + end if; + end loop; + if nBank != 0 and nOther != 0 then + insert into quant_fin (jr_id,qf_bank,qf_other,qf_amount) values (rec.jr_id,nBank,nOther,nAmount); + end if; + end loop; + return; +end; +$_$ +language plpgsql; + +select comptaproc.fill_quant_fin(); + +alter table del_jrn drop constraint jr_id; +alter table del_jrn add dj_id serial; +alter table del_jrn add constraint dj_id primary key(dj_id); + +alter table del_jrnx drop constraint j_id; +alter table del_jrnx add djx_id serial; +alter table del_jrnx add constraint djx_id primary key(djx_id); +update version set val=78; +commit; \ No newline at end of file diff --git a/include/class_acc_ledger.php b/include/class_acc_ledger.php index 4235bafb5..cf2c92097 100644 --- a/include/class_acc_ledger.php +++ b/include/class_acc_ledger.php @@ -1512,7 +1512,7 @@ jr_comment||' ('||jr_internal||')'||case when jr_pj_number is not null and jr_pj $this->db->exec_sql("update jrn set jr_internal='".$internal."' where ". " jr_grpt_id = ".$seq); - + $this->internal=$internal; // Save now the predef op //------------------------ if ( isset($save_opd)) { diff --git a/include/class_acc_ledger_fin.php b/include/class_acc_ledger_fin.php index 1a382c362..8d8ec25f3 100644 --- a/include/class_acc_ledger_fin.php +++ b/include/class_acc_ledger_fin.php @@ -697,7 +697,7 @@ class Acc_Ledger_Fin extends Acc_Ledger { $idx_operation++; $acc_operation->pj=$e_pj.str_pad($idx_operation,2,0,STR_PAD_LEFT); - error_log($acc_operation->pj."\n",3,"/tmp/phpcompta.log"); + $jr_id=$acc_operation->insert_jrn(); $acc_operation->set_pj(); diff --git a/include/impress_inc.php b/include/impress_inc.php index b2ff470a8..250d890f6 100644 --- a/include/impress_inc.php +++ b/include/impress_inc.php @@ -195,7 +195,7 @@ function CheckFormula($p_string) { // Remove T,t $p_string=str_replace("T","",$p_string); $p_string=str_replace("t","",$p_string); - error_log($p_string."\n",3,'/tmp/phpcompta.log'); + if ( myereg ("^(\\$[a-zA-Z]*[0-9]*=){0,1}((\[{0,1}[0-9]+\.*[0-9]*%{0,1}\]{0,1})+ *([+-\*/])* *(\[{0,1}[0-9]+\.*[0-9]*%{0,1}\]{0,1})*)*(([+-\*/])*\\$([a-zA-Z])+[0-9]*([+-\*/])*)* *( *FROM=[0-9][0-0].20[0-9][0-9]){0,1}$",$p_string) == false) { return false;