Add FK to quant_sold and quand_purchase

This commit is contained in:
Dany De Bontridder 2010-07-03 10:55:45 +00:00
parent edaaa477d1
commit 5f0a6dea86
2 changed files with 21 additions and 166 deletions

View file

@ -5,16 +5,13 @@
5. Depuis les impressions -> balances et impression -> poste, on a les détails des opérations
TODO15 Ajoutez les détails pour l'impression en PDF pour impression poste / fiche
6. TODO5 bug IE : les DIV HTML n'ont pas la bonne taille
TODO18 Acc_Account_Ledger::HtmlTable et Fiche::HtmlTable, il manque la sécurité pour filtrer les journaux
TODO1 réecriture de quant_* la liaison avec la jrn se fait à travers jr_id et non pas jr_internal qui n'est pas indexé.
7. DONE4 Ajout d'un lien sur les postes et client pour accèder avec un DIV contenant l'historique (au moins une partie / présentation par slice)/ bouton suivant-précédent )
8. TODO18 Acc_Account_Ledger::HtmlTable et Fiche::HtmlTable, il manque la sécurité pour filtrer les journaux
9. Ajout d'une FK TODO1 réecriture de quant_* la liaison avec la jrn se fait à travers jr_id et non pas jr_internal qui n'est pas indexé.
Conséquence : réécriture de code, correction modop, ...
TODO2 Object pour extourner proprement une operation, le fichier annulation.php devient inutile (deprecated) depend de TODO1 TODO10
TODO4 Ajout d'un lien sur les postes et client pour accèder avec un DIV contenant l'historique (au moins une partie / présentation par slice)/ bouton suivant-précédent )
IDEE6, categorie de fiche, changer la présentation
TODO7 ajout bouton "ajoutez ligne" pour les OD en CA
@ -36,3 +33,13 @@ TODO13 Bouton validate CA ne fonctionne plus
TODO14 confirmation quand effacement d'un PA (comptabilité analytique -> Plan Analytique)
TODO17 extourne depuis DIV HTML dépend de TODO16
REFLEXION1 Pièce attachée uniquement depuis détail opération ?
TODO19 Le menu Grand Livre devient recherche
TODO20 Ajouter d'attribut avec type : text, nombre ou date; ajouter le javascript équivalent pour la saisie, le numéro de séquence
commence à 10000, afin de ne pas mélanger les attributs que je créé avec ceux des utilisateurs. A ajouter dans la doc comme exemple pour la gestion d'abonnés dont on peut tirer un CSV par impression -> catégorie -> résume
TODO21 Dans DIV HTML donner le code de la TVA dans les détails VEN et ACH

View file

@ -1,164 +1,12 @@
begin;
create or replace function comptaproc.fill_quant_fin() returns void as
$_$
declare
sBank text;
sCassa text;
sCustomer text;
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';
select p_value into sSupplier from parm_code where p_code='SUPPLIER';
select p_value into sCustomer from parm_code where p_code='CUSTOMER';
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;
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;
-- only cash
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;
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 sCassa||'%' 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;
ALTER TABLE quant_purchase
ADD CONSTRAINT quant_purchase_qp_internal_fkey FOREIGN KEY (qp_internal)
REFERENCES jrn (jr_internal) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE;
-- 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 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
nAmount=recSupp_Cust.j_montant*(-1);
else
nAmount=recSupp_Cust.j_montant;
end if;
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;
ALTER TABLE quant_sold
ADD CONSTRAINT quant_sold_qs_internal_fkey FOREIGN KEY (qs_internal)
REFERENCES jrn (jr_internal) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE;
commit;