noalyss Version-9
compute.php
Go to the documentation of this file.
1<?php
2/*
3 * This file is part of NOALYSS.
4 *
5 * NOALYSS is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * NOALYSS is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with NOALYSS; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18*/
19
20// Copyright Author Dany De Bontridder danydb@aevalys.eu
21
22/*!\file
23 * \brief respond ajax request, the get contains
24 * the value :
25 * - c for qcode
26 * - t for tva_id -1 if there is no TVA to compute
27 * - p for price
28 * - q for quantity
29 * - n for number of the ctrl
30 * - gDossier
31 * Must return at least tva, htva and tvac
32 */
33require_once '../include/constant.php';
34require_once NOALYSS_INCLUDE.'/class/database.class.php';
35require_once NOALYSS_INCLUDE.'/class/acc_compute.class.php';
36require_once NOALYSS_INCLUDE.'/class/dossier.class.php';
37require_once NOALYSS_INCLUDE.'/class/acc_tva.class.php';
38require_once NOALYSS_INCLUDE . '/class/noalyss_user.class.php';
39
40require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
41MaintenanceMode("block.html");
42
43// Check if the needed field does exist
44extract ($_GET, EXTR_SKIP );
45foreach (array('t','c','p','q','n','gDossier') as $a)
46{
47 if ( ! isset (${$a}) )
48 {
49 echo "error $a is not set ";
50 exit();
51 }
52
53}
55$tax_ac_id=$http->request("other_tax_id","number",-1);
56// sometime number uses coma instead of dot for dec
59
61$User=new Noalyss_user($cn);
62$User->Check();
63$User->check_dossier(Dossier::id());
64
65// Retrieve the rate of vat, it $t == -1 it means no VAT
66if ( $t != -1 && isNumber($t) == 1 )
67{
69 $tva_rate->set_parameter('id',$t);
70 /**
71 *if the tva_rate->load failed we don't compute tva
72 */
73 if ( $tva_rate->load() != 0 )
74 {
75 $tva_rate->set_parameter('rate',0);
76 }
77}
78
80bcscale(4);
81if ( isNUmber($p) && isNumber($q)) {
82 $amount=round(bcmul($p,$q,4),2);
83} else {
84 $amount = 0;
85}
86$total->set_parameter('amount',$amount);
88if ( $tax_ac_id !=-1) {
89 $other_tax=new Acc_Other_Tax_SQL($cn,$tax_ac_id);
90 $other_tax_amount=round(bcmul($amount,$other_tax->getp("ac_rate"),4)/100,2);
91}
92if ( $t != -1 && isNumber($t) == 1 )
93{
94 $total->set_parameter('amount_vat_rate',$tva_rate->get_parameter('rate'));
95 $total->compute_vat();
96 if ($tva_rate->get_parameter('both_side')== 1) $total->set_parameter('amount_vat', 0);
97 $tvac=($tva_rate->get_parameter('rate') == 0 || $tva_rate->get_parameter('both_side')== 1) ? $amount : bcadd($total->get_parameter('amount_vat'),$amount);
98
99 header("Content-type: text/html; charset: utf8",true);
100 $result=["ctl"=>$n,"htva"=>$amount,"tva"=>$total->get_parameter("amount_vat"),"tvac"=>$tvac,
101 "other_tax"=>$other_tax_amount];
102 echo json_encode($result);
103}
104else
105{
106 /* there is no vat to compute */
107 header("Content-type: text/html; charset: utf8",true);
108 $result=["ctl"=>$n,"htva"=>$amount,"tva"=>"NA","tvac"=>$amount, "other_tax"=>$other_tax_amount];
109 echo json_encode($result);
110}
111?>
112
isNumber($p_int)
Definition: ac_common.php:215
MaintenanceMode($p_file)
When you want to prevent users to connect, create a file in noalyss/ (NOALYSS_BASE) with the message ...
Definition: ac_common.php:1663
noalyss_str_replace($search, $replace, $string)
Definition: ac_common.php:1553
catch(Exception $e) $tva_rate
$_GET['qcode']
this class aims to compute different amount
ORM public.acc_other_tax.
Acc_Tva is used for to map the table tva_rate parameter are.
static id()
return the 'gDossier' value after a check
static connect()
manage the http input (get , post, request) and extract from an array
$result
Definition: compute.php:108
$cn
Definition: compute.php:60
$tax_ac_id
Definition: compute.php:55
$User
Definition: compute.php:61
$other_tax_amount
Definition: compute.php:87
foreach(array('t', 'c', 'p', 'q', 'n', 'gDossier') as $a) $http
Definition: compute.php:54
$p
Definition: compute.php:57
$q
Definition: compute.php:58
if( $t !=-1 &&isNumber($t)==1) $total
Definition: compute.php:79
for($e=0; $e< count($afiche); $e++) exit