altocompta/html/compute.php
Dany De Bontridder 9ac52c4ce6 Merged revisions 3015-3016 via svnmerge from
svn+ssh://danydb@svn/svn/phpcompta/branches/rel500

........
  r3015 | danydb | 2010-04-16 12:25:57 +0200 (Fri, 16 Apr 2010) | 5 lines
  
  Quick_writing
  =============
  
  Limit the operation to the ODS ledger and no longer to any ledgers
........
  r3016 | danydb | 2010-04-16 12:36:14 +0200 (Fri, 16 Apr 2010) | 8 lines
  
  TVA_IPOPUP
  ==========
  Add a new widget to let user select a VAT into a POPUP
  Add javascript to set the label and tva_id
  Check if TVA is valid (compute.php, acc_ledger.php)
........
2010-04-16 10:38:27 +00:00

80 lines
2.5 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();
// 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);
/**
*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 ) {
$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.'"}';
}
?>