Check(); // Retrieve the rate of vat, it $t == -1 it means no VAT if ( $t != -1 && isNumber($t) == 1 ) { $tva_rate=new Acc_Tva($cn); $tva_rate->set_parameter('id',$t); /** *if the tva_rate->load failed we don't compute tva */ if ( $tva_rate->load() != 0 ) { $tva_rate->set_parameter('rate',0); } } $total=new Acc_Compute(); bcscale(4); $amount=round(bcmul($p,$q),2); $total->set_parameter('amount',$amount); if ( $t != -1 && isNumber($t) == 1 ) { $total->set_parameter('amount_vat_rate',$tva_rate->get_parameter('rate')); $total->compute_vat(); if ($tva_rate->get_parameter('both_side')== 1) $total->set_parameter('amount_vat', 0); $tvac=($tva_rate->get_parameter('rate') == 0 || $tva_rate->get_parameter('both_side')== 1) ? $amount : bcadd($total->get_parameter('amount_vat'),$amount); header("Content-type: text/html; charset: utf8",true); echo '{"ctl":"'.$n.'","htva":"'.$amount.'","tva":"'.$total->get_parameter('amount_vat').'","tvac":"'.$tvac.'"}'; } else { /* there is no vat to compute */ header("Content-type: text/html; charset: utf8",true); echo '{"ctl":"'.$n.'","htva":"'.$amount.'","tva":"NA","tvac":"'.$amount.'"}'; } ?>