Plugins  LAST
 All Data Structures Files Functions Variables Pages
class_tva_amount.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 /* $Revision$ */
20 
21 // Copyright (c) 2002 Author Dany De Bontridder dany@alchimerys.be
22 
23 /*!\file
24  * \brief
25  */
26 
27 
28 /*!\brief
29  *
30  *
31  */
33 {
34 
35  private static $variable=array('amount'=>'amount',
36  'amount_tva'=>'amount_tva',
37  'param'=>'param',
38  'dir'=>'dir',
39  'start_periode'=>'start_periode',
40  'end_periode'=>'end_periode',
41  'grid'=>'grid'
42  );
43  function __construct ($p_init,$p_dir,$p_start_periode,$p_end_periode) {
44  $this->db=$p_init;
45  $this->start_periode=$p_start_periode;
46  $this->end_periode=$p_end_periode;
47  $this->dir=$p_dir;
48  }
49  public function get_parameter($p_string) {
50  if ( array_key_exists($p_string,self::$variable) ) {
51  $idx=self::$variable[$p_string];
52  return $this->$idx;
53  }
54  else
55  throw new Exception("Attribut inexistant $p_string");
56  }
57  public function set_parameter($p_string,$p_value) {
58  if ( array_key_exists($p_string,self::$variable) ) {
59  $idx=self::$variable[$p_string];
60  $this->$idx=$p_value;
61  }
62  else
63  throw new Exception("Attribut inexistant $p_string");
64 
65 
66  }
67  public function get_info() { return var_export(self::$variable,true); }
68  public function verify() {
69  // Verify that the elt we want to add is correct
70  }
71  /**
72  *@brief load parameters and set param to a array of value from parameter_chld
73  */
74  public function load_parameter() {
75  // get the vat code
76  $ctva=$this->db->get_array("select tva_id,pcm_val from tva_belge.parameter_chld where pcode=$1",array($this->grid));
77  if ( count($ctva)== 0 ) {
78  $this->param=null;
79  }
80  $this->param=$ctva;
81  }
82  /**
83  *@brief get the amount of vat thanks its code
84  *@param $p_gril is the gril code
85  *@param $p_dir is out or in in for the table quant_purchase and
86  * out for the table quant_sold
87  *@return a number
88  */
89  function amount_operation() {
90  // get the VAT code
91  $this->load_parameter();
92  $result=0;
93  bcscale(4);
94  for ($i=0;$i<count($this->param);$i++)
95  {
96  $tmp_calc=$this->get_amount_filter($this->param[$i]['tva_id'],$this->param[$i]['pcm_val']);
97  $result=bcadd($result,$tmp_calc);
98 
99  }
100  return round($result,2);
101 
102 
103  }
104  function amount_vat() {
105  // get the VAT code
106  $this->load_parameter();
107  $result=0;
108  bcscale(4);
109  for ($i=0;$i<count($this->param);$i++)
110  {
111  $tmp_calc=$this->get_vat_filter($this->param[$i]['tva_id'],$this->param[$i]['pcm_val']);
112  $result=bcadd($result,$tmp_calc);
113 
114  }
115  return round($result,2);
116 
117 
118  }
119 
120  /**
121  *@brief get the amount of operation from the table quant_sold or quant_purchase
122  *@return amount
123  */
124  private function get_amount_filter($p_code,$p_account) {
125  if ( $this->dir == 'out' && trim($p_account) !='' && trim($p_code) !='' ) {
126  $sql="select coalesce(sum(qs_price),0) as amount from quant_sold
127  join jrnx using (j_id)
128  where qs_vat_code=$1 and (j_date >= to_date($2,'DD.MM.YYYY') and j_date <= to_date($3,'DD.MM.YYYY'))
129  and j_poste::text like ($4)";
130  $res=$this->db->get_array($sql,array($p_code,
131  $this->start_periode,
132  $this->end_periode,
133  $p_account));
134  return $res[0]['amount'];
135  }
136 
137  if ( $this->dir == 'in' && trim($p_account) !='' && trim($p_code) !='' ) {
138  $sql="select coalesce(sum(qp_price),0) as amount from quant_purchase join jrnx using (j_id)
139  where qp_vat_code=$1 and (j_date >= to_date($2,'DD.MM.YYYY') and j_date <= to_date($3,'DD.MM.YYYY'))
140  and j_poste::text like ($4)";
141  $res=$this->db->get_array($sql,array($p_code,
142  $this->start_periode,
143  $this->end_periode,
144  $p_account));
145  return $res[0]['amount'];
146  }
147 
148 
149  return 0;
150  }
151 
152  /**
153  *@brief get the amount of VAT from the table quant_sold or quant_purchase
154  *@return amount
155  */
156  private function get_vat_filter($p_code,$p_account) {
157  if ( $this->dir == 'out' && trim($p_account) !='' && trim($p_code) !='' ) {
158  $sql="select coalesce(sum(qs_vat),0) as amount from quant_sold join jrnx using (j_id)
159  where qs_vat_code=$1 and (j_date >= to_date($2,'DD.MM.YYYY') and j_date <= to_date($3,'DD.MM.YYYY'))
160  and j_poste::text like ($4)";
161  $res=$this->db->get_array($sql,array($p_code,
162  $this->start_periode,
163  $this->end_periode,
164  $p_account));
165  return $res[0]['amount'];
166  }
167 
168  if ( $this->dir == 'in' && trim($p_account) !='' && trim($p_code) !='' ) {
169  $sql="select coalesce(sum(qp_vat),0) as amount from quant_purchase join jrnx using (j_id)
170  where qp_vat_code=$1 and (j_date >= to_date($2,'DD.MM.YYYY') and j_date <= to_date($3,'DD.MM.YYYY'))
171  and j_poste::text like ($4)";
172  $res=$this->db->get_array($sql,array($p_code,
173  $this->start_periode,
174  $this->end_periode,
175  $p_account));
176  return $res[0]['amount'];
177  }
178 
179 
180  return 0;
181  }
182 
183 /**
184  *@brief
185  * record into the ledger the operation for purging the
186  * the vat accouting
187  */
188 function record_ledger() {
189 
190 }
191 
192  /*!\brief
193  *\param
194  *\return
195  *\note
196  *\see
197  *\todo
198  */
199  static function test_me() {
200  }
201 
202 }
203 
204 /* test::test_me(); */
__construct($p_init, $p_dir, $p_start_periode, $p_end_periode)
get_amount_filter($p_code, $p_account)
get the amount of operation from the table quant_sold or quant_purchase
static test_me()
get_parameter($p_string)
amount_operation()
get the amount of vat thanks its code
record_ledger()
record into the ledger the operation for purging the the vat accouting
set_parameter($p_string, $p_value)
$res
$sql
get_vat_filter($p_code, $p_account)
get the amount of VAT from the table quant_sold or quant_purchase
load_parameter()
load parameters and set param to a array of value from parameter_chld