From 5395e8b2d87f4681726d3e1e144ae2a4ec542aea Mon Sep 17 00:00:00 2001 From: sparkyx Date: Wed, 3 May 2006 20:30:15 +0000 Subject: [PATCH] fix problem with rounded amount when deducing 2 special vat Improve debug --- html/admin/sql/patch/upgrade9.sql | 2 +- html/index.php | 2 +- include/user_common.php | 32 +++++++++++------ include/user_form_ach.php | 58 ++++++++++++------------------- include/user_form_fin.php | 2 +- include/user_form_ven.php | 2 +- 6 files changed, 47 insertions(+), 51 deletions(-) diff --git a/html/admin/sql/patch/upgrade9.sql b/html/admin/sql/patch/upgrade9.sql index 956898ba9..abec3bcb5 100644 --- a/html/admin/sql/patch/upgrade9.sql +++ b/html/admin/sql/patch/upgrade9.sql @@ -50,7 +50,7 @@ begin end if; end if; - if p_montant = 0 then + if p_montant = 0.0 then return; end if; insert into jrnx diff --git a/html/index.php b/html/index.php index 8ca31e782..4983c623a 100644 --- a/html/index.php +++ b/html/index.php @@ -29,7 +29,7 @@ BODY { -Version 1.2.2 patch 5 +Version developpement 1.2.2 patch 5

Il est conseillé de ne PAS utiliser Internet Explorer.

diff --git a/include/user_common.php b/include/user_common.php index 75e0721a8..2fad56ec9 100644 --- a/include/user_common.php +++ b/include/user_common.php @@ -103,34 +103,40 @@ echo_debug('user_common.php',__LINE__,"ComputeTotalVat $a_fiche $a_quant $a_pric $flag=true; $a=$a_vat['tva_id']; // Compute vat for this item - $vat_amount=$a_price[$idx]*$a_vat['tva_rate']*$a_quant[$idx]; + $vat_amount=round($a_price[$idx]*$a_vat['tva_rate']*$a_quant[$idx],2); // only the deductible vat if ( $all == false ) { - $vat_amount=$a_price[$idx]*$a_vat['tva_rate']*$a_quant[$idx]; - + //variable containing the nd part + // used when a card has both special rule for vat + $nd1=0; // if a part is not deductible then reduce vat_amount $nd=GetFicheAttribut($p_cn,$a_fiche[$idx],ATTR_DEF_TVA_NON_DEDUCTIBLE); if ( $nd != null && strlen(trim($nd)) != 0 && $nd != 0 ) { - $nd_amount=$a_price[$idx]*$a_vat['tva_rate']*$a_quant[$idx]*$nd; - $vat_amount-=$nd_amount; - + $nd_amount=round($a_price[$idx]*$a_vat['tva_rate']*$a_quant[$idx]*$nd,2); + // problem with round + $vat_amount=$vat_amount-$nd_amount; echo_debug('user_common.php',__LINE__, "A - TVA Attr fiche [$nd] nd amount [ $nd_amount ]". "vat amount [ $vat_amount]"); $flag=false; + // save nd into nd1 + $nd1=$nd; } // if a part is not deductible then reduce vat_amount $nd=GetFicheAttribut($p_cn,$a_fiche[$idx],ATTR_DEF_TVA_NON_DEDUCTIBLE_RECUP); if ( $nd != null && strlen(trim($nd)) != 0 && $nd != 0 ) { - $nd_amount=$a_price[$idx]*$a_vat['tva_rate']*$a_quant[$idx]*$nd; - - $vat_amount-=$nd_amount; + $nd_amount2=round($a_price[$idx]*$a_vat['tva_rate']*$a_quant[$idx]*$nd,2); + + $vat_amount=$vat_amount-$nd_amount2; + // when using both vat, their sum cannot exceed 1, if = 1 then vat = 0 + if ( ($nd+$nd1) == 1) + $vat_amount=0; echo_debug('user_common.php',__LINE__, - "B - TVA Attr fiche [$nd] nd amount [ $nd_amount ]". + "B - TVA Attr fiche [$nd] nd amount [ $nd_amount2 ]". "vat amount [ $vat_amount]"); $flag=false; @@ -184,7 +190,8 @@ function ComputeVat($p_cn, $p_fiche,$p_quant,$p_price,$p_vat ) $a=$a_vat['tva_id']; $vat_amount=$p_price*$a_vat['tva_rate']*$p_quant; } - return $vat_amount; + echo_debug('user_common',__LINE__,'return '.round($vat_amount,2)); + return round($vat_amount,2); } @@ -242,6 +249,9 @@ function InsertJrnx($p_cn,$p_type,$p_user,$p_jrn,$p_poste,$p_date,$p_amount,$p_g type = $p_type p_user $p_user p_date $p_date p_poste $p_poste p_amount $p_amount p_grpt = $p_grpt p_periode = $p_periode"); + + if ( $p_amount == 0) return true; + $debit=($p_type=='c')?'false':'true'; // if negative value the operation is inversed diff --git a/include/user_form_ach.php b/include/user_form_ach.php index 607dc47be..b6f8c9d4a 100644 --- a/include/user_form_ach.php +++ b/include/user_form_ach.php @@ -412,7 +412,7 @@ function form_verify_input($p_cn,$p_jrn,$p_periode,$p_array,$p_number) list ($l_date_start,$l_date_end)=GetPeriode($p_cn,$p_periode); // Date dans la periode active - echo_debug ("date start periode $l_date_start date fin periode $l_date_end date demande $e_date"); + echo_debug ('user_form_ach',__LINE__,"date start periode $l_date_start date fin periode $l_date_end date demande $e_date"); if ( cmpDate($e_date,$l_date_start)<0 || cmpDate($e_date,$l_date_end)>0 ) { @@ -653,43 +653,20 @@ function RecordSell($p_cn,$p_array,$p_user,$p_jrn) $amount_jrn+=$cost; echo_debug('user_form_ach.php',__LINE__,'Total customer:'.$amount_jrn); } + // $amount_jrn=round( $comm=FormatString($e_comm); // Compute vat with ded echo_debug('user_form_achat.php',__LINE__,"Call ComputeTotalVat"); $a_vat=ComputeTotalVat($p_cn,$a_good,$a_quant,$a_price,$a_vat_good,false); - $sum_vat=0.0; - if ( $a_vat != null ){ - foreach ( $a_vat as $element => $t) { - echo_debug('user_form_ach.php',__LINE__," a_vat element $element t $t"); - $sum_vat+=$t; - echo_debug('user_form_ach.php',__LINE__,"sum_vat = $sum_vat"); - } - } - - // Compute vat without reduction - $a_vat_full=ComputeTotalVat($p_cn,$a_good,$a_quant,$a_price,$a_vat_good,true); - $sum_vat_full=0.0; - if ( $a_vat_full != null ){ - foreach ( $a_vat_full as $element => $t) { - echo_debug('user_form_ach.php',__LINE__," a_vat_full element $element t $t"); - $sum_vat_full+=$t; - echo_debug('user_form_ach.php',__LINE__,"sum_vat_full = $sum_vat"); - } - } - // First we add in jrnx + StartSql($p_cn); + // Compute the j_grpt $seq=NextSequence($p_cn,'s_grpt'); - // Debit = client - $poste=GetFicheAttribut($p_cn,$e_client,ATTR_DEF_ACCOUNT); - echo_debug('user_form_achat.php',__LINE__,"get e_client $e_client poste $poste"); - StartSql($p_cn); - echo_debug('user_form_achat.php',__LINE__,"insert client"); - $r=InsertJrnx($p_cn,'c',$p_user->id,$p_jrn,$poste,$e_date,round($amount,2)+round($sum_vat_full,2),$seq,$periode); - if ( $r == false) { $Rollback($p_cn);exit("error 'user_form_ach.php' __LINE__");} + // Credit = goods for ( $i = 0; $i < $nb_item;$i++) { @@ -702,9 +679,9 @@ function RecordSell($p_cn,$p_array,$p_user,$p_jrn) // Put the non deductible part into a special account $non_dedu=GetFicheAttribut($p_cn,$a_good[$i],ATTR_DEF_DEPENSE_NON_DEDUCTIBLE); echo_debug('user_form_ach.php',__LINE__,"value non ded : $non_dedu"); - if ( $non_dedu != null && strlen(trim($non_dedu)) != 0 ) + if ( $non_dedu != null && strlen(trim($non_dedu)) != 0) { - $nd_amount=$a_quant[$i]*$a_price[$i]*$non_dedu; + $nd_amount=round($a_quant[$i]*$a_price[$i]*$non_dedu,2); // save it echo_debug('user_form_ach.php',__LINE__,"InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,'6740',$e_date,round($nd_amount,2),$seq,$periode);"); @@ -716,11 +693,12 @@ function RecordSell($p_cn,$p_array,$p_user,$p_jrn) // Put the non deductible part into a special account $non_dedu=GetFicheAttribut($p_cn,$a_good[$i],ATTR_DEF_TVA_NON_DEDUCTIBLE); echo_debug('user_form_ach.php',__LINE__,"TVA value non ded : $non_dedu"); - if ( $non_dedu != null && strlen(trim($non_dedu)) != 0 ) + if ( $non_dedu != null && strlen(trim($non_dedu)) != 0) { $lvat=ComputeVat($p_cn, $a_good[$i],$a_quant[$i],$a_price[$i], $a_vat_good[$i] ); $ded_vat=($lvat != null )?$lvat*$non_dedu:0; + $ded_vat=round($ded_vat,2); $sum_tva_nd+=$ded_vat; // compute the NDA TVA @@ -741,7 +719,7 @@ function RecordSell($p_cn,$p_array,$p_user,$p_jrn) $a_vat_good[$i] ); $ded_vat=($lvat != null )?$lvat*$non_dedu:0; - $sum_tva_nd+=$ded_vat; + $sum_tva_nd+=round($ded_vat,2); // Save it $tva_ded_impot=new parm_code($p_cn,'TVA_DED_IMPOT'); @@ -768,7 +746,7 @@ function RecordSell($p_cn,$p_array,$p_user,$p_jrn) // Insert Vat - + $sum_tva=0.0; if ( $a_vat != null ) // no vat { @@ -782,15 +760,23 @@ function RecordSell($p_cn,$p_array,$p_user,$p_jrn) echo_debug('user_form_ach',__LINE__,"InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,$poste,$e_date,round($tva_amount,2),$seq,$periode);"); $r=InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,$poste,$e_date,round($tva_amount,2),$seq,$periode); if ( $r == false ) { Rollback($p_cn); exit(" Error 'user_form_ach.php' __LINE__");} - + $sum_tva+=round($tva_amount,2); } } echo_debug('user_form_ach.php',__LINE__,"echeance = $e_ech"); - echo_debug('user_form_ach.php',__LINE__,"sum_vat = $sum_vat"); + echo_debug('user_form_ach.php',__LINE__,"sum_tva = $sum_tva"); echo_debug('user_form_ach.php',__LINE__,"amount_jrn = $amount_jrn"); echo_debug('user_form_ach.php',__LINE__,"sum_tva_nd = $sum_tva_nd"); - $r=InsertJrn($p_cn,$e_date,$e_ech,$p_jrn,"Invoice",round($amount_jrn,2)+round($sum_vat,2)+round($sum_tva_nd,2),$seq,$periode); + // Debit = client + $poste=GetFicheAttribut($p_cn,$e_client,ATTR_DEF_ACCOUNT); + echo_debug('user_form_achat.php',__LINE__,"get e_client $e_client poste $poste"); + echo_debug('user_form_achat.php',__LINE__,"insert client"); + + $r=InsertJrnx($p_cn,'c',$p_user->id,$p_jrn,$poste,$e_date,round($amount_jrn+$sum_tva+$sum_tva_nd,2),$seq,$periode); + if ( $r == false) { $Rollback($p_cn);exit("error 'user_form_ach.php' __LINE__");} + + $r=InsertJrn($p_cn,$e_date,$e_ech,$p_jrn,"--",round($amount_jrn+$sum_tva+$sum_tva_nd,2),$seq,$periode); if ( $r == false ) { Rollback($p_cn); exit(" Error 'user_form_ach.php' __LINE__");} // Set Internal code and Comment $internal=SetInternalCode($p_cn,$seq,$p_jrn); diff --git a/include/user_form_fin.php b/include/user_form_fin.php index 860c1c255..6f21774b9 100644 --- a/include/user_form_fin.php +++ b/include/user_form_fin.php @@ -104,7 +104,7 @@ function form_verify_input($p_cn,$p_jrn,$p_periode,$p_array,$p_number) list ($l_date_start,$l_date_end)=GetPeriode($p_cn,$p_periode); // Date dans la periode active - echo_debug ("date start periode $l_date_start date fin periode $l_date_end date demande $e_date"); + echo_debug ('user_form_fin',__LINE__,"date start periode $l_date_start date fin periode $l_date_end date demande $e_date"); if ( cmpDate($e_date,$l_date_start)<0 || cmpDate($e_date,$l_date_end)>0 ) { diff --git a/include/user_form_ven.php b/include/user_form_ven.php index be4962b90..f0810d1d9 100644 --- a/include/user_form_ven.php +++ b/include/user_form_ven.php @@ -365,7 +365,7 @@ for ($o = 0;$o < $p_number; $o++) { list ($l_date_start,$l_date_end)=GetPeriode($p_cn,$p_periode); // Date dans la periode active - echo_debug ("date start periode $l_date_start date fin periode $l_date_end date demand� $e_date"); + echo_debug ('user_form_ven',__LINE__,"date start periode $l_date_start date fin periode $l_date_end date demande $e_date"); if ( cmpDate($e_date,$l_date_start)<0 || cmpDate($e_date,$l_date_end)>0 ) {