diff --git a/html/admin/sql/patch/upgrade9.sql b/html/admin/sql/patch/upgrade9.sql
index 97007eb8c..956898ba9 100644
--- a/html/admin/sql/patch/upgrade9.sql
+++ b/html/admin/sql/patch/upgrade9.sql
@@ -50,7 +50,9 @@ begin
end if;
end if;
-
+ if p_montant = 0 then
+ return;
+ end if;
insert into jrnx
(
j_date,
diff --git a/html/style-light.css b/html/style-light.css
index f80d2e58a..cc4beb17a 100644
--- a/html/style-light.css
+++ b/html/style-light.css
@@ -159,6 +159,7 @@ table.mtitle {
text-align:center
}
td.mshort {
+ height:15px;
text-align:center;
border: 1px solid;
color:#5D90CD ;
@@ -168,33 +169,34 @@ td.mlltitle {
text-align:center;
height:30px;
width:30px;
- font-size:12px;
+ font-size:10px;
}
td.mltitle {
text-align:center;
height:30px;
- width:60px;
- font-size:12px;
+ width:60px;
+ font-size:10px;
border: 1px solid;
background-color:#DDE6FF;
}
td.mtitle {
text-align:center;
- width:75px;
+ width:95px;
+ height :30px;
font-size:10px;
- border: 1px solid;
- padding:3px;
+// border: 1px solid;
+// padding:3px;
background-color:#DDE6FF;
}
span.mtitle2 {
background-color:red;
- font-size:12px;
+ font-size:10px;
border-style:groove
}
span.mtitle {
color:gray;
background-color:blue;
- font-size:12px;
+ font-size:10px;
border-style:groove
}
span.odd {
@@ -225,15 +227,19 @@ td.even{
}
td.cell{
// border:1px solid blue;
- padding: 4px;
+ height:32px;
+ padding: 1px;
+ width:70px;
}
td.selectedcell{
- border-style:solid;
- border-width:1pt;
+ border-style:inset;
+ border-color:blue;
+ border-width:1pt ;
width:75px;
font-size:10px;
- background:blue ;
+ background:#5D90CD ;
color:white;
+ text-align:center;
}
a.mtitle {
@@ -249,7 +255,8 @@ a.mtitle:hover {
background-color:#5D90CD;
text-decoration:none;
display:block;
-
+ border-style:groove;
+ border-color:blue;
}
a.cell {
text-decoration:none;
@@ -270,7 +277,7 @@ a.cell:hover {
a.mtitle2 {
height:30px;
text-decoration:none;
- color:blue;
+ color:white;
}
a.mtitle2:hover {
diff --git a/include/debug.php b/include/debug.php
index a1ecfbc14..008f4c6c2 100644
--- a/include/debug.php
+++ b/include/debug.php
@@ -30,7 +30,8 @@ function echo_debug ($file,$line="",$msg="") {
$cn=pg_connect($l_Db);
$file=FormatString($file);
$line=FormatString($line);
- $msg='domaine :'.domaine.' '.FormatString($msg);
+
+ $msg='domaine :'.domaine.' '.FormatString(var_export($msg,true));
$sql= "insert into log (lg_file,lg_line,lg_msg) ".
"values ('$file','$line','$msg');";
diff --git a/include/user_common.php b/include/user_common.php
index 10cbfa3c3..c5cc6dd3c 100644
--- a/include/user_common.php
+++ b/include/user_common.php
@@ -78,14 +78,21 @@ echo_debug('user_common.php',__LINE__,"ComputeTotalVat $a_fiche $a_quant $a_pric
echo_debug ('user_common.php',__LINE__,"idx $idx element $element");
// if the card id is null or empty
if ( strlen(trim($element))==0) continue;
-
+
// Get the tva_id
if ( $ap_vat != null and
- isNumber($ap_vat[$idx])== 1)
- $tva_id=$ap_vat[$idx];
+ isNumber($ap_vat[$idx])== 1 and $ap_vat[$idx] != -1 )
+ {
+ $tva_id=$ap_vat[$idx];
+ echo_debug('user_common',__LINE__,' tva_id is given');
+ echo_debug('user_common',__LINE__,$ap_vat);
+ }
else
- $tva_id=GetFicheAttribut($p_cn,$a_fiche[$idx],ATTR_DEF_TVA);
-
+ {
+ $tva_id=GetFicheAttribut($p_cn,$element,ATTR_DEF_TVA);
+ echo_debug('user_common',__LINE__,'retrieve tva_id');
+ }
+ echo_debug('user_common',__LINE__,"tva id $tva_id");
if ( $tva_id == null ) continue;
// for each fiche find the tva_rate and tva_id
$a_vat=GetTvaRate($p_cn,$tva_id);
@@ -98,37 +105,42 @@ echo_debug('user_common.php',__LINE__,"ComputeTotalVat $a_fiche $a_quant $a_pric
// Compute vat for this item
$vat_amount=$a_price[$idx]*$a_vat['tva_rate']*$a_quant[$idx];
+ // only the deductible vat
if ( $all == false )
{
// 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 )
+ if ( $nd != null && strlen(trim($nd)) != 0 && $nd != 0 )
{
$nd_amount=$a_price[$idx]*$a_vat['tva_rate']*$a_quant[$idx]*$nd;
$vat_amount=$a_price[$idx]*$a_vat['tva_rate']*$a_quant[$idx];
- echo_debug('user_common.php',__LINE__,"TVA Attr fiche [$nd] nd amount [ $nd_amount ]".
- "vat amount [ $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;
}
// 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 )
+ if ( $nd != null && strlen(trim($nd)) != 0 && $nd != 0 )
{
$nd_amount=$a_price[$idx]*$a_vat['tva_rate']*$a_quant[$idx]*$nd;
$vat_amount=$a_price[$idx]*$a_vat['tva_rate']*$a_quant[$idx];
- echo_debug('user_common.php',__LINE__,"TVA Attr fiche [$nd] nd amount [ $nd_amount ]".
- "vat amount [ $vat_amount]");
$vat_amount-=$nd_amount;
+ echo_debug('user_common.php',__LINE__,
+ "B - TVA Attr fiche [$nd] nd amount [ $nd_amount ]".
+ "vat amount [ $vat_amount]");
+
$flag=false;
}
}
+
$r[$a]=isset ( $r[$a] )?$r[$a]+$vat_amount:$vat_amount;
}
-
}
- echo_debug('user_common.php',__LINE__," return $r");
+ echo_debug('user_common.php',__LINE__," return ".var_export($r,true));
return $r;
@@ -154,24 +166,26 @@ echo_debug('user_common.php',__LINE__,"ComputeTotalVat $a_fiche $a_quant $a_pric
function ComputeVat($p_cn, $p_fiche,$p_quant,$p_price,$p_vat )
{
echo_debug('user_common.php',__LINE__,"function ComputeVat($p_cn,$p_fiche,$p_quant,$p_price,$p_vat )");
- // Get the tva_id
- if ( $p_vat != null and isNumber($p_vat)== 1)
- $tva_id=$p_vat;
- else
- $tva_id=GetFicheAttribut($p_cn,$p_fiche,ATTR_DEF_TVA);
-
- if ( $tva_id == null ) return -1;
- // for each fiche find the tva_rate and tva_id
- $a_vat=GetTvaRate($p_cn,$tva_id);
- $vat_amount=-1;
- // Get the attribut price of the card(fiche)
- if ( $a_vat != null and $a_vat['tva_id'] != "" )
- { $a=$a_vat['tva_id'];
+ // Get the tva_id
+ if ( $p_vat != null and isNumber($p_vat)== 1 and $p_vat != -1)
+ $tva_id=$p_vat;
+ else
+ $tva_id=GetFicheAttribut($p_cn,$p_fiche,ATTR_DEF_TVA);
+
+ echo_debug('user_common',__LINE__,"ComputeVat tva id = $tva_id");
+ if ( $tva_id == null ) return -1;
+ // for each fiche find the tva_rate and tva_id
+ $a_vat=GetTvaRate($p_cn,$tva_id);
+ $vat_amount=-1;
+ // Get the attribut price of the card(fiche)
+ if ( $a_vat != null and $a_vat['tva_id'] != "" )
+ {
+ $a=$a_vat['tva_id'];
$vat_amount=$p_price*$a_vat['tva_rate']*$p_quant;
}
- return $vat_amount;
-
-
+ return $vat_amount;
+
+
}
@@ -480,16 +494,17 @@ function ListJrn($p_cn,$p_jrn,$p_where="",$p_array=null,$p_value=0)
// Get the jrn type
$jrn_prop=GetJrnProp($p_cn,$row['jrn_def_id'],1);
$positive=0;
- //STAN following code will never be executed, as $positive=0 TO CHECK with DANY
- if ( $positive=1 && $jrn_prop['jrn_def_type'] == 'FIN' )
- {
- $positive = CountSql($p_cn,"select * from jrn inner join jrnx on jr_grpt_id=j_grpt ".
- " where jr_id=".$row['jr_id']." and (j_poste like '55%' or j_poste like '57%' )".
- " and j_debit='f'");
- }
+
+ // Check ledger type
+ if ( $jrn_prop['jrn_def_type'] == 'FIN' )
+ {
+ $positive = CountSql($p_cn,"select * from jrn inner join jrnx on jr_grpt_id=j_grpt ".
+ " where jr_id=".$row['jr_id']." and (j_poste like '55%' or j_poste like '57%' )".
+ " and j_debit='f'");
+ }
$r.="
";
//STAN $positive always == 0
- $r.=( $positive != 0 )?" - ".sprintf("%8.2f",$row['jr_montant'])."":sprintf("%8.2f",$row['jr_montant']);
+ $r.=( $positive != 0 )?" - ".sprintf("%8.2f",$row['jr_montant'])."":sprintf("%8.2f",$row['jr_montant']);
$r.=" | ";
// Rapprochement
diff --git a/include/user_form_ach.php b/include/user_form_ach.php
index 1e16c484f..8e0aec4ae 100644
--- a/include/user_form_ach.php
+++ b/include/user_form_ach.php
@@ -520,7 +520,7 @@ function FormAchView ($p_cn,$p_jrn,$p_periode,$p_array,$p_submit,$p_number,$p_pi
// VAT
- $vat=(isNumber(${"e_march$i"."_tva_id"})==0)?getFicheAttribut($p_cn,${"e_march$i"},ATTR_DEF_TVA):${"e_march$i"."_tva_id"};
+ $vat=(isNumber(${"e_march$i"."_tva_id"})==0 || ${"e_march$i"."_tva_id"}==-1 )?getFicheAttribut($p_cn,${"e_march$i"},ATTR_DEF_TVA):${"e_march$i"."_tva_id"};
// vat label
// vat rate
@@ -636,7 +636,7 @@ function RecordSell($p_cn,$p_array,$p_user,$p_jrn)
$a_good[$i]=${"e_march$i"};
$a_quant[$i]=${"e_quant$i"};
$a_price[$i]=0;
- $a_vat1[$i]=${"e_march$i"."_tva_id"};
+ $a_vat_good[$i]=${"e_march$i"."_tva_id"};
// check wether the price is set or no
if ( isNumber(${"e_march$i"."_sell"}) == 0 ) {
if ( $a_good[$i] !="" ) {
@@ -651,10 +651,13 @@ function RecordSell($p_cn,$p_array,$p_user,$p_jrn)
$amount+=$cost;
// if cost < 0 => not added to jrn.jr_amount
$amount_jrn+=($cost<0)?0:$cost;
+ echo_debug('user_form_ach.php',__LINE__,'Total customer:'.$amount_jrn);
}
$comm=FormatString($e_comm);
-echo_debug('user_form_achat.php',__LINE__,"Call ComputeTotalVat");
- $a_vat=ComputeTotalVat($p_cn,$a_good,$a_quant,$a_price,$a_vat1,false);
+
+ // 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) {
@@ -663,16 +666,17 @@ echo_debug('user_form_achat.php',__LINE__,"Call ComputeTotalVat");
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_vat1,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 element $element t $t");
- $sum_vat_full+=$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
// Compute the j_grpt
@@ -694,45 +698,59 @@ echo_debug('user_form_achat.php',__LINE__,"Call ComputeTotalVat");
// don't record operation of 0
if ( $a_price[$i]*$a_quant[$i] == 0 ) continue;
- $amount=$a_price[$i]*$a_quant[$i];
- // 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 )
- {
- $nd_amount=$a_quant[$i]*$a_price[$i]*$non_dedu;
- $j_id=InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,'6740',$e_date,round($nd_amount,2),$seq,$periode);
- if ( $j_id == false) { Rollback($p_cn);exit("error 'user_form_ach.php' __LINE__");}
- $amount=$amount-$nd_amount;
- }
- // 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 )
- {
- $ded_vat=ComputeVat($p_cn, $a_good[$i],$a_quant[$i],$a_price[$i],
- $a_vat1[$i] )*$non_dedu;
- $sum_tva_nd+=$ded_vat;
- $j_id=InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,'6740',$e_date,round($ded_vat,2),$seq,$periode);
- if ( $j_id == false) { Rollback($p_cn);exit("error 'user_form_ach.php' __LINE__");}
- }
+ $amount=$a_price[$i]*$a_quant[$i];
+ // 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 )
+ {
+ $nd_amount=$a_quant[$i]*$a_price[$i]*$non_dedu;
- // Put the non deductible part into a special account
- $non_dedu=GetFicheAttribut($p_cn,$a_good[$i],ATTR_DEF_TVA_NON_DEDUCTIBLE_RECUP);
- echo_debug('user_form_ach.php',__LINE__,"TVA value non ded : $non_dedu");
- if ( $non_dedu != null && strlen(trim($non_dedu)) != 0 )
+ // 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);");
+ $j_id=InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,'6740',$e_date,round($nd_amount,2),$seq,$periode);
+ if ( $j_id == false) { Rollback($p_cn);exit("error 'user_form_ach.php' __LINE__");}
+ $amount=$amount-$nd_amount;
+ }
+ // 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 )
+ {
+ $lvat=ComputeVat($p_cn, $a_good[$i],$a_quant[$i],$a_price[$i],
+ $a_vat_good[$i] );
+ $ded_vat=($lvat>0)?$lvat*$non_dedu:0;
+ $sum_tva_nd+=$ded_vat;
+
+ echo_debug('user_form_ach.php',__LINE__,
+ "InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,'6190',$e_date,round($ded_vat,2),$seq,$periode);");
+ $j_id=InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,'6740',$e_date,round($ded_vat,2),$seq,$periode);
+ if ( $j_id == false) { Rollback($p_cn);exit("error 'user_form_ach.php' __LINE__");}
+ }
+
+ // Put the non deductible part into a special account
+ $non_dedu=GetFicheAttribut($p_cn,$a_good[$i],ATTR_DEF_TVA_NON_DEDUCTIBLE_RECUP);
+ echo_debug('user_form_ach.php',__LINE__,"TVA value non ded : $non_dedu");
+ if ( $non_dedu != null && strlen(trim($non_dedu)) != 0 )
{
- $ded_vat=ComputeVat($p_cn, $a_good[$i],$a_quant[$i],$a_price[$i],
- $a_vat1[$i] )*$non_dedu;
- $sum_tva_nd+=$ded_vat;
- $j_id=InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,'6190',$e_date,round($ded_vat,2),$seq,$periode);
- if ( $j_id == false) { Rollback($p_cn);exit("error 'user_form_ach.php' __LINE__");}
+ $lvat=ComputeVat($p_cn, $a_good[$i],$a_quant[$i],$a_price[$i],
+ $a_vat_good[$i] );
+ $ded_vat=($lvat>0)?$lvat*$non_dedu:0;
+
+ $sum_tva_nd+=$ded_vat;
+
+ // Save it
+ echo_debug('user_form_ach.php',__LINE__,
+ "InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,'6190',$e_date,round($ded_vat,2),$seq,$periode);");
+ $j_id=InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,'6190',$e_date,round($ded_vat,2),$seq,$periode);
+ if ( $j_id == false) { Rollback($p_cn);exit("error 'user_form_ach.php' __LINE__");}
}
// record into jrnx
+ echo_debug('user_form_ach.php',__LINE__,"InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,$poste,$e_date,round($amount,2),$seq,$periode);");
$j_id=InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,$poste,$e_date,round($amount,2),$seq,$periode);
if ( $j_id == false) { Rollback($p_cn);exit("error 'user_form_ach.php' __LINE__");}
// always save quantity but in withStock we can find what card need a stock management
@@ -748,16 +766,24 @@ echo_debug('user_form_achat.php',__LINE__,"Call ComputeTotalVat");
if ( $a_vat != null ) // no vat
{
+
+ echo_debug('user_form_ach',__LINE__,'a_vat = '.var_export($a_vat,true));
foreach ($a_vat as $tva_id => $tva_amount )
{
+ echo_debug('user_form_ach',__LINE__," tva_amount = $tva_amount tva_id=$tva_id");
$poste=GetTvaPoste($p_cn,$tva_id,'d');
if ($tva_amount == 0 ) continue;
+ 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__");}
}
}
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__,"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);
if ( $r == false ) { Rollback($p_cn); exit(" Error 'user_form_ach.php' __LINE__");}
// Set Internal code and Comment