noalyss Version-9
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
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
45// TVA id or TVA code
46$t=$http->get("t");
47// string qcode card
48$c=$http->get("c");
49// Price
50$p=$http->get("p");
51// quantity
52$q=$http->get("q");
53// row number (from 0) used to identify the row
54$n=$http->get("n");
55
56$tax_ac_id=$http->request("other_tax_id","number",-1);
57// sometime number uses coma instead of dot for dec
60
61$cn=Dossier::connect();
62$User=new Noalyss_user($cn);
63$User->Check();
64$User->check_dossier(Dossier::id());
65
66// Retrieve the rate of vat, it $t == -1 it means no VAT
67if ( $t != -1 )
68{
70
71 /**
72 *if the tva_rate->load failed we don't compute tva
73 */
74 if ( $tva_rate->load() != 0 )
75 {
76 $tva_rate->set_parameter('rate',0);
77 }
78}
79
81bcscale(4);
82if ( isNUmber($p) && isNumber($q)) {
83 $amount=round(bcmul($p,$q,4),2);
84} else {
85 $amount = 0;
86}
87$total->set_parameter('amount',$amount);
89if ( $tax_ac_id !=-1) {
90 $other_tax=new Acc_Other_Tax_SQL($cn,$tax_ac_id);
91 $other_tax_amount=round(bcmul($amount,$other_tax->getp("ac_rate"),4)/100,2);
92}
93if ( $t != -1 )
94{
95 $total->set_parameter('amount_vat_rate',$tva_rate->get_parameter('rate'));
96 $total->compute_vat();
97 if ($tva_rate->get_parameter('both_side')== 1) $total->set_parameter('amount_vat', 0);
98 $tvac=($tva_rate->get_parameter('rate') == 0 || $tva_rate->get_parameter('both_side')== 1) ? $amount : bcadd($total->get_parameter('amount_vat'),$amount);
99
100 header("Content-type: text/html; charset: utf8",true);
101 $result=["ctl"=>$n,"htva"=>$amount,"tva"=>$total->get_parameter("amount_vat"),"tvac"=>$tvac,
102 "other_tax"=>$other_tax_amount];
103 echo json_encode($result);
104}
105else
106{
107 /* there is no vat to compute */
108 header("Content-type: text/html; charset: utf8",true);
109 $result=["ctl"=>$n,"htva"=>$amount,"tva"=>"NA","tvac"=>$amount, "other_tax"=>$other_tax_amount];
110 echo json_encode($result);
111}
112?>
113
isNumber($p_int)
MaintenanceMode($p_file)
When you want to prevent users to connect, create a file in noalyss/ (NOALYSS_BASE) with the message ...
noalyss_str_replace($search, $replace, $string)
catch(Exception $e) $tva_rate
$p
Definition calendar.php:9
this class aims to compute different amount
ORM public.acc_other_tax.
static build($db, $p_code)
retrieve TVA rate thanks the code that could be the tva_id or tva_code.
manage the http input (get , post, request) and extract from an array
$t
Definition compute.php:46
$tax_ac_id
Definition compute.php:56
if( $t !=-1) $total
Definition compute.php:80
$other_tax_amount
Definition compute.php:88
$n
Definition compute.php:54
$c
Definition compute.php:48