Merge with Dev-Dany

This commit is contained in:
sparkyx 2006-10-07 10:18:06 +00:00
parent 7f79d8f7e6
commit e8235adc49
44 changed files with 1980 additions and 2292 deletions

View file

@ -62,11 +62,12 @@ function GetTvaRate($p_cn,$p_tva_id) {
* \param $a_quantity array
* \param $a_price array
* \param $ap_vat Array of tva id
* \param $a_amount_tva for the expense, if the tva amount is given
* \param $all = false if we reduce VAT
* \return: array
* a[tva_id] = amount vat
*/
function ComputeTotalVat($p_cn, $a_fiche,$a_quant,$a_price,$ap_vat,$all=false ) {
function ComputeTotalVat($p_cn, $a_fiche,$a_quant,$a_price,$ap_vat,$a_vat_amount=null,$all=false ) {
echo_debug('user_common.php',__LINE__,"ComputeTotalVat $a_fiche $a_quant $a_price");
foreach ( $a_fiche as $t=>$el) {
echo_debug('user_common.php',__LINE__,"t $t e $el");
@ -78,7 +79,7 @@ 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 and $ap_vat[$idx] != -1 )
@ -98,53 +99,70 @@ echo_debug('user_common.php',__LINE__,"ComputeTotalVat $a_fiche $a_quant $a_pric
$a_vat=GetTvaRate($p_cn,$tva_id);
// Get the attribut price of the card(fiche)
if ( $a_vat != null and $a_vat['tva_id'] != "" )
{
$flag=true;
$a=$a_vat['tva_id'];
// Compute vat for this item
$vat_amount=round($a_price[$idx]*$a_vat['tva_rate']*$a_quant[$idx],2);
if ( $a_vat != null and $a_vat['tva_id'] != "" )
{
$flag=true;
$a=$a_vat['tva_id'];
// Compute vat for this item
$vat_amount=round($a_price[$idx]*$a_vat['tva_rate']*$a_quant[$idx],2);
// if a vat amount is given
if ( $a_vat_amount != null &&
$a_vat_amount[$idx] != 0 )
$vat_amount= $a_vat_amount[$idx] ;
// only the deductible vat
if ( $all == false )
{
//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=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_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_amount2 ]".
"vat amount [ $vat_amount]");
$flag=false;
}
}
$r[$a]=isset ( $r[$a] )?$r[$a]+$vat_amount:$vat_amount;
}
// only the deductible vat
if ( $all == false )
{
//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 )
{
// if tva amount is given we do not compute it
if ( $a_vat_amount != null &&
$a_vat_amount[$idx] != 0 )
$nd_amount=round($a_price[$idx]*$a_quant[$idx]*$nd,2)+$a_vat_amount[$idx];
else
$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 )
{
// if tva amount is given we do not compute it
if ( $a_vat_amount != null &&
$a_vat_amount[$idx] != 0 )
$nd_amount2=round($a_price[$idx]*$a_quant[$idx]*$nd,2)+$a_vat_amount[$idx];
else
$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_amount2 ]".
"vat amount [ $vat_amount]");
$flag=false;
}
}
$r[$a]=isset ( $r[$a] )?$r[$a]+$vat_amount:$vat_amount;
}
}
echo_debug('user_common.php',__LINE__," return ".var_export($r,true));
@ -455,7 +473,7 @@ function ListJrn($p_cn,$p_jrn,$p_where="",$p_array=null,$p_value=0,$p_paid=0)
//this function returns a tree structure.
$r="";
$r.=JS_VIEW_JRN_DETAIL;
$r.=JS_VIEW_JRN_CANCEL;
$r.=JS_VIEW_JRN_MODIFY;
@ -551,7 +569,7 @@ function ListJrn($p_cn,$p_jrn,$p_where="",$p_array=null,$p_value=0,$p_paid=0)
foreach ($a as $key => $element)
{
$r.= "<A class=\"detail\" HREF=\"javascript:viewDetail('".GetGrpt($p_cn,$element)."','$l_sessid')\" > ".GetInternal($p_cn,$element)."</A>";
$r.= "<A class=\"detail\" HREF=\"javascript:modifyOperation('".$element."','".$l_sessid."')\" > ".GetInternal($p_cn,$element)."</A>";
}//for
}// if ( $a != null ) {
$r.="</TD>";
@ -886,6 +904,10 @@ function jrn_navigation_bar($p_offset,$p_line,$p_size=0,$p_page=1)
}// if
}//foreach
}// if
// action to clean
$url=str_replace('&p_action=delete','',$url);
// compute max of page
$nb_page=($p_line-($p_line%$p_size))/$p_size;
echo_debug('user_common',__LINE__,"nb_page = $nb_page");