diff --git a/include/class_acc_ledger_purchase.php b/include/class_acc_ledger_purchase.php index 3f5c4658e..b1c4e36b1 100644 --- a/include/class_acc_ledger_purchase.php +++ b/include/class_acc_ledger_purchase.php @@ -341,7 +341,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger $tot_perso=0; $tot_tva_nd=0; $tot_tva_ndded=0; - + $n_both=0; /* Save all the items without vat and no deductible vat and expense*/ for ($i=0;$i< $nb_item;$i++) { @@ -486,6 +486,8 @@ class Acc_Ledger_Purchase extends Acc_Ledger //----- if ( $g_parameter->MY_TVA_USE=='Y') { + if ( $oTva->get_parameter("both_side")==1) $n_both=$acc_amount->amount_vat; + $r=$this->db->exec_sql("select insert_quant_purchase ". "(null". ",".$j_id. /* 2 */ @@ -498,7 +500,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger ",".$acc_amount->nd_vat. /* 9 */ ",".$acc_amount->nd_ded_vat. /* 10 */ ",".$acc_amount->amount_perso. /* 11 */ - ",'".$e_client."')"); /* 12 */ + ",'".$e_client."',".$n_both.")"); /* 12 */ } else @@ -515,7 +517,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger ",0". ",".$acc_amount->nd_ded_vat. ",".$acc_amount->amount_perso. - ",'".$e_client."')"); + ",'".$e_client."',".$n_both.")"); } @@ -673,7 +675,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger $acc_operation->jrn=$p_jrn; $acc_operation->type='c'; $acc_operation->periode=$tperiode; - $acc_operation->insert_jrnx(); + $acc_operation->insert_jrnx(); } } diff --git a/include/class_acc_ledger_sold.php b/include/class_acc_ledger_sold.php index f9547b870..2735bbde2 100644 --- a/include/class_acc_ledger_sold.php +++ b/include/class_acc_ledger_sold.php @@ -272,6 +272,7 @@ class Acc_Ledger_Sold extends Acc_Ledger $tot_amount=0; $tot_tva=0; $tot_debit=0; + $n_both=0; $this->db->start(); /* Save all the items without vat */ for ($i=0;$i< $nb_item;$i++) @@ -332,6 +333,7 @@ class Acc_Ledger_Sold extends Acc_Ledger else $tva[$idx_tva]=$tva_item; if ($oTva->get_parameter("both_side")==0) $tot_tva=round(bcadd($tva_item,$tot_tva),2); + else $n_both=$tva_item; } /* Save the stock */ @@ -361,7 +363,7 @@ class Acc_Ledger_Sold extends Acc_Ledger if ( $g_parameter->MY_TVA_USE=='Y') { /* save into quant_sold */ - $r=$this->db->exec_sql("select insert_quant_sold ($1,$2,$3,$4,$5,$6,$7,$8)", + $r=$this->db->exec_sql("select insert_quant_sold ($1,$2,$3,$4,$5,$6,$7,$8,$9)", array(null, /* 1 */ $j_id, /* 2 */ ${'e_march'.$i} , /* 3 */ @@ -369,12 +371,13 @@ class Acc_Ledger_Sold extends Acc_Ledger round($amount,2), /* 5 */ $tva_item, /* 6 */ $idx_tva, /* 7 */ - $e_client)); /* 8 */ + $e_client, /* 8 */ + $n_both)); } else { - $r=$this->db->exec_sql("select insert_quant_sold ($1,$2,$3,$4,$5,$6,$7,$8) ", + $r=$this->db->exec_sql("select insert_quant_sold ($1,$2,$3,$4,$5,$6,$7,$8,$9) ", array(null, /* 1 */ $j_id, /* 2 */ ${'e_march'.$i}, /* 3 */ @@ -382,7 +385,8 @@ class Acc_Ledger_Sold extends Acc_Ledger $amount, // 5 0, null, - $e_client)); + $e_client, + 0)); } // if ( $g_parameter->MY_TVA_USE=='Y') { }// end loop : save all items @@ -431,7 +435,6 @@ class Acc_Ledger_Sold extends Acc_Ledger // if TVA is on both side, we deduce it immediately if ( $oTva->get_parameter("both_side")==1) { - echo "remove_tva"; $poste_vat=$oTva->get_side('d'); $cust_amount=bcadd($tot_amount,$tot_tva); $acc_operation=new Acc_Operation($this->db); @@ -444,6 +447,7 @@ class Acc_Ledger_Sold extends Acc_Ledger $acc_operation->periode=$tperiode; $acc_operation->insert_jrnx(); $tot_debit=bcadd($tot_debit,$value); + $n_both=$value; } diff --git a/sql/tva.sql b/sql/tva.sql index 5c694c6ff..6249201c7 100644 --- a/sql/tva.sql +++ b/sql/tva.sql @@ -83,3 +83,76 @@ return 0; end; $function$ LANGUAGE plpgsql; + +alter table quant_purchase add qp_vat_sided number (20,4); +alter table quant_sold add qs_vat_sided number (20,4); + +DROP FUNCTION comptaproc.insert_quant_purchase(text,numeric, character varying,numeric,numeric,numeric,integer,,numeric,numeric,,numeric,numeric,character varying, numeric); +-- procedure insert_quant_purchase +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) + RETURNS void + LANGUAGE plpgsql +AS $function$ +declare + fid_client integer; + fid_good integer; +begin + 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)); + 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) + 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, + p_dep_priv, + p_tva_sided); + return; +end; + $function$ + +DROP FUNCTION comptaproc.insert_quant_sold(text, numeric, character varying, numeric, numeric, numeric, integer, character varying); + +-- procedure insert_quant_sold +CREATE OR REPLACE FUNCTION comptaproc.insert_quant_sold(p_internal text, p_jid numeric, p_fiche character varying, p_quant numeric, p_price numeric, p_vat numeric, p_vat_code integer, p_client character varying,p_tva_sided numeric) + RETURNS void + LANGUAGE plpgsql +AS $function$ +declare + fid_client integer; + fid_good integer; +begin + + 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)); + insert into quant_sold + (qs_internal,j_id,qs_fiche,qs_quantite,qs_price,qs_vat,qs_vat_code,qs_client,qs_valid,qs_vat_sided) + values + (p_internal,p_jid,fid_good,p_quant,p_price,p_vat,p_vat_code,fid_client,'Y',p_tva_sided); + return; +end; + $function$