altocompta/html/compute.php
Dany De Bontridder 9c2e1427c2 Merged revisions 3001-3012 via svnmerge from
file:///home/developper/svn/phpcompta/branches/rel500

........
  r3007 | danydb | 2010-04-12 23:31:21 +0200 (Mon, 12 Apr 2010) | 4 lines
  
  
  Use ITva_Select in class_acc_legder_purchase.php
........
  r3008 | danydb | 2010-04-13 00:58:43 +0200 (Tue, 13 Apr 2010) | 8 lines
  
  
  TVA Ipopup
  ==========
  
  Add a new widget which show the tva in a popup and let it select the code you need
  it will replace the obsolete TVA_Select
........
  r3009 | danydb | 2010-04-13 20:15:59 +0200 (Tue, 13 Apr 2010) | 4 lines
  
  
  Todo : add the todo for the use of the new widget Tva_Popup
........
  r3010 | danydb | 2010-04-14 18:58:56 +0200 (Wed, 14 Apr 2010) | 1 line
  
   Add a new function in class periode : last_day
........
  r3011 | danydb | 2010-04-14 19:00:09 +0200 (Wed, 14 Apr 2010) | 1 line
  
   Add a new function in class periode : last_day correct typo
........
2010-04-14 22:15:03 +00:00

84 lines
2.6 KiB
PHP

<?php
/*
* This file is part of PhpCompta.
*
* PhpCompta is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* PhpCompta is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PhpCompta; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* $Revision$ */
// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
/*!\file
* \brief respond ajax request, the get contains
* the value :
* - c for qcode
* - t for tva_id -1 if there is no TVA to compute
* - p for price
* - q for quantity
* - n for number of the ctrl
* - gDossier
* - PHPSESSID
* Must return at least tva, htva and tvac
*/
require_once ('constant.php');
require_once ('class_database.php');
require_once ('debug.php');
require_once ('class_acc_compute.php');
require_once('class_dossier.php');
require_once ('class_acc_tva.php');
require_once ('class_user.php');
// Check if the needed field does exist
extract ($_GET);
foreach (array('t','c','p','q','n','gDossier') as $a) {
if ( ! isset (${$a}) ) { echo "error $a is not set "; exit();}
}
$cn=new Database(dossier::id());
$User=new User($cn);
$User->Check();
/**
*@todo check with my_own if the vat must be computed instead of
*a special value
*/
// Retrieve the rate of vat, it $t == -1 it means no VAT
if ( $t != -1 ){
$tva_rate=new Acc_Tva($cn);
$tva_rate->set_parameter('id',$t);
/**
*@todo if the tva_rate->load failed we have to return an
*error message "invalid tva"
*/
$tva_rate->load();
}
$total=new Acc_Compute();
bcscale(4);
$amount=round(bcmul($p,$q),2);
$total->set_parameter('amount',$amount);
if ( $t != -1 ) {
$total->set_parameter('amount_vat_rate',$tva_rate->get_parameter('rate'));
$total->compute_vat();
$tvac=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.'"}';
}
?>