diff --git a/include/class_acc_ledger_purchase.php b/include/class_acc_ledger_purchase.php index 8386124ae..43fb7e1dc 100644 --- a/include/class_acc_ledger_purchase.php +++ b/include/class_acc_ledger_purchase.php @@ -384,7 +384,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger $acc_amount->amount_vat= ${'e_march'.$i.'_tva_amount'}; } - $tot_tva+=$acc_amount->amount_vat; + if ($oTva->get_parameter("both_side")==0) $tot_tva=bcadd($tot_tva,$acc_amount->amount_vat); } $acc_operation=new Acc_Operation($this->db); @@ -667,6 +667,20 @@ class Acc_Ledger_Purchase extends Acc_Ledger $acc_operation->periode=$tperiode; if ( $value > 0 ) $tot_debit=bcadd($tot_debit,$value); $acc_operation->insert_jrnx(); + // if TVA is on both side, we deduce it immediately + if ( $oTva->get_parameter("both_side")==1) + { + $poste_vat=$oTva->get_side('c'); + $cust_amount=bcadd($tot_amount,$tot_tva); + $acc_operation=new Acc_Operation($this->db); + $acc_operation->date=$e_date; + $acc_operation->poste=$poste_vat; + $acc_operation->amount=$value; + $acc_operation->grpt=$seq; + $acc_operation->jrn=$p_jrn; + $acc_operation->type='c'; + $acc_operation->periode=$tperiode; + } } } diff --git a/include/class_acc_ledger_sold.php b/include/class_acc_ledger_sold.php index 898d43fd7..7f1861c20 100644 --- a/include/class_acc_ledger_sold.php +++ b/include/class_acc_ledger_sold.php @@ -333,7 +333,7 @@ class Acc_Ledger_Sold extends Acc_Ledger $tva[$idx_tva]+=$tva_item; else $tva[$idx_tva]=$tva_item; - $tot_tva=round(bcadd($tva_item,$tot_tva),2); + if ($oTva->get_parameter("both_side")==0) $tot_tva=round(bcadd($tva_item,$tot_tva),2); } /* Save the stock */ @@ -429,6 +429,21 @@ class Acc_Ledger_Sold extends Acc_Ledger $acc_operation->periode=$tperiode; if ($value < 0 ) $tot_debit=bcadd($tot_debit,abs($value)); $acc_operation->insert_jrnx(); + + // if TVA is on both side, we deduce it immediately + if ( $oTva->get_parameter("both_side")==1) + { + $poste_vat=$oTva->get_side('d'); + $cust_amount=bcadd($tot_amount,$tot_tva); + $acc_operation=new Acc_Operation($this->db); + $acc_operation->date=$e_date; + $acc_operation->poste=$poste_vat; + $acc_operation->amount=$value; + $acc_operation->grpt=$seq; + $acc_operation->jrn=$p_jrn; + $acc_operation->type='d'; + $acc_operation->periode=$tperiode; + } } diff --git a/include/class_acc_tva.php b/include/class_acc_tva.php index 43afbbbab..2d3a9501f 100644 --- a/include/class_acc_tva.php +++ b/include/class_acc_tva.php @@ -43,7 +43,8 @@ class Acc_Tva "label"=>"tva_label", "rate"=>"tva_rate", "comment"=>"tva_comment", - "account"=>"tva_poste"); + "account"=>"tva_poste", + "both_side"=>'tva_both_side'); function __construct ($p_init,$p_tva_id=0) { @@ -94,14 +95,15 @@ class Acc_Tva public function insert() { if ( $this->verify() != 0 ) return; - $sql="select tva_insert($1,$2,$3,$4)"; + $sql="select tva_insert($1,$2,$3,$4,$5)"; $res=$this->cn->exec_sql( $sql, array($this->tva_label, $this->tva_rate, $this->tva_comment, - $this->tva_poste) + $this->tva_poste, + $this->tva_both_side) ); $this->tva_id=$this->cn->get_current_seq('s_tva'); $err=Database::fetch_result($res); @@ -110,14 +112,15 @@ class Acc_Tva public function update() { if ( $this->verify() != 0 ) return; - $sql="update tva_rate set tva_label=$1,tva_rate=$2,tva_comment=$3,tva_poste=$4 ". - " where tva_id = $5"; + $sql="update tva_rate set tva_label=$1,tva_rate=$2,tva_comment=$3,tva_poste=$4,tva_both_side=$5 ". + " where tva_id = $6"; $res=$this->cn->exec_sql( $sql, array($this->tva_label, $this->tva_rate, $this->tva_comment, $this->tva_poste, + $this->tva_both_side, $this->tva_id) ); @@ -129,7 +132,7 @@ class Acc_Tva */ public function load() { - $sql="select tva_label,tva_rate, tva_comment,tva_poste from tva_rate where tva_id=$1"; + $sql="select tva_label,tva_rate, tva_comment,tva_poste,tva_both_side from tva_rate where tva_id=$1"; $res=$this->cn->exec_sql( $sql, array($this->tva_id) diff --git a/include/tva.inc.php b/include/tva.inc.php index 44ae0c693..e887eb145 100644 --- a/include/tva.inc.php +++ b/include/tva.inc.php @@ -35,6 +35,7 @@ if (isset($_POST['confirm_rm'])) echo '
Vous ne pouvez pas effacer tous taux' . ' Si votre société n\'utilise pas la TVA, changer dans le menu société
'; } +$both=(isset($_REQUEST['both']))?1:0; //----------------------------------------------------- // Record Change if (isset($_POST['confirm_mod']) @@ -54,23 +55,21 @@ if (isset($_POST['confirm_mod']) { if (isset($_POST['confirm_add'])) { - $sql = "select tva_insert($1,$2,$3,$4)"; + $sql = "select tva_insert($1,$2,$3,$4,$5)"; $res = $cn->exec_sql( $sql, array($tva_label, $tva_rate, $tva_comment, - $tva_poste) + $tva_poste, + $both) ); $err = Database::fetch_result($res); } if (isset($_POST['confirm_mod'])) { $Res = $cn->exec_sql( - "select tva_modify($tva_id,'$tva_label', - '$tva_rate','$tva_comment','$tva_poste')"); - $Res = $cn->exec_sql( - "select tva_modify($1,$2,$3,$4,$5)", array($tva_id, $tva_label, $tva_rate, $tva_comment, $tva_poste) + "select tva_modify($1,$2,$3,$4,$5,$6)", array($tva_id, $tva_label, $tva_rate, $tva_comment, $tva_poste,$both) ); $err = Database::fetch_result($Res); } @@ -96,7 +95,7 @@ if ($own->MY_TVA_USE == 'N') } //----------------------------------------------------- // Display -$sql = "select tva_id,tva_label,tva_rate,tva_comment,tva_poste from tva_rate order by tva_label"; +$sql = "select tva_id,tva_label,tva_rate,tva_comment,tva_poste,tva_both_side from tva_rate order by tva_label"; $Res = $cn->exec_sql($sql); ?>| Taux | Commentaire | Poste | +Utilisé en même temps au crédit et au débit | $row['tva_label'], 'tva_rate' => $row['tva_rate'], 'tva_comment' => $row['tva_comment'], - 'tva_poste' => $row['tva_poste'] + 'tva_poste' => $row['tva_poste'], + 'tva_both_side' => $row['tva_both_side'] ); echo "||
|---|---|---|---|---|---|
| "; + $str_msg=( $row['tva_both_side']==1)?'Employé au crédit et débit':'normal' ; + echo $str_msg; + echo " | "; + echo ""; echo HtmlInput::submit("rm", "Efface"); echo HtmlInput::submit("mod", "Modifie"); @@ -194,12 +200,14 @@ if (isset($_REQUEST['rm'])) | Taux | Commentaire | Poste | +Double côté |
| + |