Author: danydb Date: 2012-04-24 20:58:20 +0200 (Tue, 24 Apr 2012) New Revision: 4813
Added: phpcompta/tags/rel601/sql/upgrade.sql Log: change SQL Added: phpcompta/tags/rel601/sql/upgrade.sql =================================================================== --- phpcompta/tags/rel601/sql/upgrade.sql (rev 0) +++ phpcompta/tags/rel601/sql/upgrade.sql 2012-04-24 18:58:20 UTC (rev 4813) @@ -0,0 +1,38 @@ +CREATE OR REPLACE FUNCTION comptaproc.check_balance(p_grpt integer) + RETURNS numeric AS +$BODY$ +declare + amount_jrnx_debit numeric; + amount_jrnx_credit numeric; + amount_jrn numeric; +begin + select coalesce(sum (j_montant),0) into amount_jrnx_credit + from jrnx + where + j_grpt=p_grpt + and j_debit=false; + + select coalesce(sum (j_montant),0) into amount_jrnx_debit + from jrnx + where + j_grpt=p_grpt + and j_debit=true; + + select coalesce(jr_montant,0) into amount_jrn + from jrn + where + jr_grpt_id=p_grpt; + + if ( amount_jrnx_debit != amount_jrnx_credit ) + then + return abs(amount_jrnx_debit-amount_jrnx_credit); + end if; + if ( amount_jrn != amount_jrnx_credit) + then + return -1*abs(amount_jrn - amount_jrnx_credit); + end if; + return 0; +end; +$BODY$ + LANGUAGE plpgsql; + --- PhpCompta est un logiciel de comptabilité libre en ligne (full web) Projet opensource http://www.phpcompta.eu _______________________________________________ Phpcompta est un logiciel libre de comptabilité en ligne (http://www.phpcompta.eu) Phpcompta-dev mailing list [email protected] https://lists.nongnu.org/mailman/listinfo/phpcompta-dev
