noalyss  Version-6.7.2
 All Data Structures Namespaces Files Functions Variables Enumerations
compute.php
Go to the documentation of this file.
00001 <?php
00002 /*
00003  *   This file is part of NOALYSS.
00004  *
00005  *   NOALYSS is free software; you can redistribute it and/or modify
00006  *   it under the terms of the GNU General Public License as published by
00007  *   the Free Software Foundation; either version 2 of the License, or
00008  *   (at your option) any later version.
00009  *
00010  *   NOALYSS is distributed in the hope that it will be useful,
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *   GNU General Public License for more details.
00014  *
00015  *   You should have received a copy of the GNU General Public License
00016  *   along with NOALYSS; if not, write to the Free Software
00017  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 */
00019 
00020 // Copyright Author Dany De Bontridder danydb@aevalys.eu
00021 
00022 /*!\file
00023  * \brief respond ajax request, the get contains
00024  *  the value :
00025  * - c for qcode
00026  * - t for tva_id -1 if there is no TVA to compute
00027  * - p for price
00028  * - q for quantity
00029  * - n for number of the ctrl
00030  * - gDossier
00031  * Must return at least tva, htva and tvac
00032  */
00033 require_once '../include/constant.php';
00034 require_once ('class_database.php');
00035 require_once ('class_acc_compute.php');
00036 require_once('class_dossier.php');
00037 require_once ('class_acc_tva.php');
00038 require_once ('class_user.php');
00039 
00040 // Check if the needed field does exist
00041 extract ($_GET);
00042 foreach (array('t','c','p','q','n','gDossier') as $a)
00043 {
00044     if ( ! isset (${$a}) )
00045     {
00046         echo "error $a is not set ";
00047         exit();
00048     }
00049 
00050 }
00051 $cn=new Database(dossier::id());
00052 $User=new User($cn);
00053 $User->Check();
00054 // Retrieve the rate of vat, it $t == -1 it means no VAT
00055 if ( $t != -1 && isNumber($t) == 1 )
00056 {
00057     $tva_rate=new Acc_Tva($cn);
00058     $tva_rate->set_parameter('id',$t);
00059     /**
00060      *if the tva_rate->load failed we don't compute tva
00061      */
00062     if ( $tva_rate->load() != 0 )
00063     {
00064         $tva_rate->set_parameter('rate',0);
00065     }
00066 }
00067 
00068 $total=new Acc_Compute();
00069 bcscale(4);
00070 $amount=round(bcmul($p,$q),2);
00071 $total->set_parameter('amount',$amount);
00072 if ( $t != -1 && isNumber($t) == 1 )
00073 {
00074     $total->set_parameter('amount_vat_rate',$tva_rate->get_parameter('rate'));
00075     $total->compute_vat();
00076     $tvac=bcadd($total->get_parameter('amount_vat'),$amount);
00077     header("Content-type: text/html; charset: utf8",true);
00078     echo '{"ctl":"'.$n.'","htva":"'.$amount.'","tva":"'.$total->get_parameter('amount_vat').'","tvac":"'.$tvac.'"}';
00079 }
00080 else
00081 {
00082     /* there is no vat to compute */
00083     header("Content-type: text/html; charset: utf8",true);
00084     echo '{"ctl":"'.$n.'","htva":"'.$amount.'","tva":"NA","tvac":"'.$amount.'"}';
00085 }
00086 ?>
00087 
 All Data Structures Namespaces Files Functions Variables Enumerations