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); ?> @@ -105,6 +104,7 @@ $Res = $cn->exec_sql($sql); + $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 ""; @@ -141,6 +142,11 @@ foreach ($val as $row) echo $row['tva_poste']; echo ""; + echo ""; + echo " + +
Taux Commentaire PosteUtilisé en même temps au crédit et au débit
"; + $str_msg=( $row['tva_both_side']==1)?'Employé au crédit et débit':'normal' ; + echo $str_msg; + echo ""; echo HtmlInput::submit("rm", "Efface"); echo HtmlInput::submit("mod", "Modifie"); @@ -194,12 +200,14 @@ if (isset($_REQUEST['rm'])) Taux Commentaire PosteDouble côté
input('tva_poste', '') ?> + + Utilisé au débit et au crédit afin d'annuler cette tva + size = 20; + echo $w->input('both', '') + ?> + @@ -302,6 +318,15 @@ if (isset($_REQUEST['mod'])) echo $w->input('tva_poste', $tva_array[$index]['tva_poste']) ?> + + Utilisé au débit et au crédit afin d'annuler cette tva + selected=$tva_array[$index]['tva_both_side']; + $w->size = 20; + echo $w->input('both', '') + ?> + diff --git a/sql/tva.sql b/sql/tva.sql index f54a3cfe2..0520663bc 100644 --- a/sql/tva.sql +++ b/sql/tva.sql @@ -1,74 +1,85 @@ alter table tva_rate add tva_both_side integer ; alter table tva_rate alter tva_both_side set default 0; -update tva_rate set tva_both_side=0;drop FUNCTION comptaproc.tva_modify(integer, text, numeric, text, text); - -CREATE OR REPLACE FUNCTION comptaproc.tva_modify(integer, text, numeric, text, text,integer) - RETURNS integer - LANGUAGE plpgsql -AS $function$ -declare - p_tva_id alias for $1; - p_tva_label alias for $2; - p_tva_rate alias for $3; - p_tva_comment alias for $4; - p_tva_poste alias for $5; - p_tva_both_side alias for $6; - debit text; - credit text; - nCount integer; -begin -if length(trim(p_tva_label)) = 0 then - return 3; -end if; - -if length(trim(p_tva_poste)) != 0 then - if position (',' in p_tva_poste) = 0 then return 4; end if; - debit = split_part(p_tva_poste,',',1); - credit = split_part(p_tva_poste,',',2); - select count(*) into nCount from tmp_pcmn where pcm_val=debit::account_type; - if nCount = 0 then return 4; end if; - select count(*) into nCount from tmp_pcmn where pcm_val=credit::account_type; - if nCount = 0 then return 4; end if; - -end if; -update tva_rate set tva_label=p_tva_label,tva_rate=p_tva_rate,tva_comment=p_tva_comment,tva_poste=p_tva_poste,tva_both_side=p_tva_both_side - where tva_id=p_tva_id; -return 0; -end; -$function$ -drop FUNCTION comptaproc.tva_insert(text, numeric, text, text); -CREATE OR REPLACE FUNCTION comptaproc.tva_insert(text, numeric, text, text,integer) - RETURNS integer - LANGUAGE plpgsql -AS $function$ -declare - l_tva_id integer; - p_tva_label alias for $1; - p_tva_rate alias for $2; - p_tva_comment alias for $3; - p_tva_poste alias for $4; - p_tva_both_side alias for $5; - debit text; - credit text; - nCount integer; -begin -if length(trim(p_tva_label)) = 0 then - return 3; -end if; - -if length(trim(p_tva_poste)) != 0 then - if position (',' in p_tva_poste) = 0 then return 4; end if; - debit = split_part(p_tva_poste,',',1); - credit = split_part(p_tva_poste,',',2); - select count(*) into nCount from tmp_pcmn where pcm_val=debit::account_type; - if nCount = 0 then return 4; end if; - select count(*) into nCount from tmp_pcmn where pcm_val=credit::account_type; - if nCount = 0 then return 4; end if; - -end if; -select into l_tva_id nextval('s_tva') ; -insert into tva_rate(tva_id,tva_label,tva_rate,tva_comment,tva_poste,tva_both_side) - values (l_tva_id,p_tva_label,p_tva_rate,p_tva_comment,p_tva_poste,p_tva_both_side); -return 0; -end; -$function$ +update tva_rate set tva_both_side=0; + +---------------------------------------------------------------------- +-- TVA MODIFY +---------------------------------------------------------------------- +drop FUNCTION comptaproc.tva_modify(integer, text, numeric, text, text); + +CREATE OR REPLACE FUNCTION comptaproc.tva_modify(integer, text, numeric, text, text,integer) + RETURNS integer + LANGUAGE plpgsql +AS $function$ +declare + p_tva_id alias for $1; + p_tva_label alias for $2; + p_tva_rate alias for $3; + p_tva_comment alias for $4; + p_tva_poste alias for $5; + p_tva_both_side alias for $6; + debit text; + credit text; + nCount integer; +begin +if length(trim(p_tva_label)) = 0 then + return 3; +end if; + +if length(trim(p_tva_poste)) != 0 then + if position (',' in p_tva_poste) = 0 then return 4; end if; + debit = split_part(p_tva_poste,',',1); + credit = split_part(p_tva_poste,',',2); + select count(*) into nCount from tmp_pcmn where pcm_val=debit::account_type; + if nCount = 0 then return 4; end if; + select count(*) into nCount from tmp_pcmn where pcm_val=credit::account_type; + if nCount = 0 then return 4; end if; + +end if; +update tva_rate set tva_label=p_tva_label,tva_rate=p_tva_rate,tva_comment=p_tva_comment,tva_poste=p_tva_poste,tva_both_side=p_tva_both_side + where tva_id=p_tva_id; +return 0; +end; +$function$ + +---------------------------------------------------------------------- +-- TVA INSERT +---------------------------------------------------------------------- + +drop FUNCTION comptaproc.tva_insert(text, numeric, text, text); + +CREATE OR REPLACE FUNCTION comptaproc.tva_insert(text, numeric, text, text,integer) + RETURNS integer + LANGUAGE plpgsql +AS $function$ +declare + l_tva_id integer; + p_tva_label alias for $1; + p_tva_rate alias for $2; + p_tva_comment alias for $3; + p_tva_poste alias for $4; + p_tva_both_side alias for $5; + debit text; + credit text; + nCount integer; +begin +if length(trim(p_tva_label)) = 0 then + return 3; +end if; + +if length(trim(p_tva_poste)) != 0 then + if position (',' in p_tva_poste) = 0 then return 4; end if; + debit = split_part(p_tva_poste,',',1); + credit = split_part(p_tva_poste,',',2); + select count(*) into nCount from tmp_pcmn where pcm_val=debit::account_type; + if nCount = 0 then return 4; end if; + select count(*) into nCount from tmp_pcmn where pcm_val=credit::account_type; + if nCount = 0 then return 4; end if; + +end if; +select into l_tva_id nextval('s_tva') ; +insert into tva_rate(tva_id,tva_label,tva_rate,tva_comment,tva_poste,tva_both_side) + values (l_tva_id,p_tva_label,p_tva_rate,p_tva_comment,p_tva_poste,p_tva_both_side); +return 0; +end; +$function$