noalyss Version-9
Public Member Functions | Static Public Member Functions | Data Fields | Private Attributes | Static Private Attributes
Acc_Compute Class Reference

this class aims to compute different amount More...

+ Collaboration diagram for Acc_Compute:

Public Member Functions

 __construct ()
 
 compute_nd ()
 Compute the no deductible part of the amount, it reduce also the vat. More...
 
 compute_nd_vat ()
 
 compute_ndded_vat ()
 
 compute_perso ()
 
 compute_vat ()
 
 convert_euro ()
 
 convert_euro_vat ()
 
 correct ()
 
 display ()
 
 get_info ()
 
 get_parameter ($p_string)
 
 set_parameter ($p_string, $p_value)
 
 verify ($p_obj=null)
 ! More...
 

Static Public Member Functions

static test_me ()
 

Data Fields

 $check
 

Private Attributes

 $order
 

Static Private Attributes

static $variable
 

Detailed Description

this class aims to compute different amount

This class compute without decimal error the following amount

Definition at line 55 of file acc_compute.class.php.

Constructor & Destructor Documentation

◆ __construct()

Acc_Compute::__construct ( )

Definition at line 81 of file acc_compute.class.php.

82 {
83 bcscale(4);
84 foreach (self::$variable as $key=>$value) $this->$key=0;
85 $this->order=0;
86 $this->check=true;
87 }

References $value, and $variable.

Member Function Documentation

◆ compute_nd()

Acc_Compute::compute_nd ( )

Compute the no deductible part of the amount, it reduce also the vat.

Definition at line 138 of file acc_compute.class.php.

139 {
140 if ( $this->check && $this->order > 2 ) throw new Exception ('ORDER NOT RESPECTED');
141
142 $this->amount_nd=bcmul($this->amount,$this->amount_nd_rate);
143 $this->amount_nd=bcdiv($this->amount_nd,100);
144 $this->amount_nd=round($this->amount_nd,2);
145 // the nd part for the vat
146 $nd_vat=bcmul($this->amount_vat,$this->amount_nd_rate);
147 $nd_vat=bcdiv($nd_vat,100);
148 $nd_vat=round($nd_vat,2);
149
150 }

Referenced by Acc_Ledger_Purchase\compute_no_deductible().

◆ compute_nd_vat()

Acc_Compute::compute_nd_vat ( )

Definition at line 151 of file acc_compute.class.php.

152 {
153 if ( $this->check && $this->order > 3 ) throw new Exception ('ORDER NOT RESPECTED');
154 $this->order=4;
155
156 if ($this->amount_vat == 0 ) $this->compute_vat();
157 $this->nd_vat=bcmul($this->amount_vat,$this->nd_vat_rate);
158 $this->nd_vat=bcdiv($this->nd_vat,100);
159 $this->nd_vat=round($this->nd_vat,2);
160 }

References compute_vat().

Referenced by Acc_Ledger_Purchase\compute_no_deductible().

+ Here is the call graph for this function:

◆ compute_ndded_vat()

Acc_Compute::compute_ndded_vat ( )

Definition at line 162 of file acc_compute.class.php.

163 {
164 if ( $this->check && $this->order > 4 ) throw new Exception ('ORDER NOT RESPECTED');
165 $this->order=5;
166
167 if ($this->amount_vat == 0 ) $this->compute_vat();
168 $this->nd_ded_vat=bcmul($this->amount_vat,$this->nd_ded_vat_rate);
169 $this->nd_ded_vat=bcdiv($this->nd_ded_vat,100);
170 $this->nd_ded_vat=round($this->nd_ded_vat,2);
171 }

References compute_vat().

Referenced by Acc_Ledger_Purchase\compute_no_deductible().

+ Here is the call graph for this function:

◆ compute_perso()

Acc_Compute::compute_perso ( )

Definition at line 173 of file acc_compute.class.php.

174 {
175 if ( $this->check && $this->order != 1 ) throw new Exception ('ORDER NOT RESPECTED');
176 $this->order=2;
177 if ( $this->amount == 0 ) return;
178 $this->amount_perso=bcmul($this->amount,$this->amount_perso_rate);
179 $this->amount_perso=bcdiv($this->amount_perso,100);
180 $this->amount_perso=round($this->amount_perso,2);
181
182
183
184 }

Referenced by Acc_Ledger_Purchase\compute_no_deductible().

◆ compute_vat()

Acc_Compute::compute_vat ( )

Definition at line 127 of file acc_compute.class.php.

128 {
129 if ( $this->check && $this->order != 0 ) throw new Exception ('ORDER NOT RESPECTED');
130 $this->amount_vat=bcmul($this->amount,$this->amount_vat_rate);
131 $this->amount_vat=round($this->amount_vat,2);
132 $this->amount_vat_currency=bcmul($this->amount_vat,$this->currency_rate);
133 $this->order=1;
134 }

Referenced by compute_nd_vat(), and compute_ndded_vat().

◆ convert_euro()

Acc_Compute::convert_euro ( )

Definition at line 89 of file acc_compute.class.php.

90 {
91 $local_amount=$this->amount;
92 $this->amount=bcdiv($this->amount,$this->currency_rate,6);
93 $this->amount_currency=$local_amount;
94 }

References $amount.

◆ convert_euro_vat()

Acc_Compute::convert_euro_vat ( )

Definition at line 95 of file acc_compute.class.php.

96 {
97 $local_amount=$this->amount_vat;
98 $this->amount_vat=bcdiv($this->amount_vat,$this->currency_rate,6);
99 $this->amount_vat_currency=$local_amount;
100 }

◆ correct()

Acc_Compute::correct ( )

Definition at line 185 of file acc_compute.class.php.

186 {
187 $this->amount=bcsub($this->amount,$this->amount_perso);
188 // correct the others amount
189 $this->amount=bcsub($this->amount,$this->amount_nd);
190 $this->amount_vat=bcsub($this->amount_vat,$this->nd_ded_vat);
191 $this->amount_vat=round($this->amount_vat,2);
192 $this->amount_vat=bcsub($this->amount_vat,$this->nd_vat);
193 $this->amount_vat=round($this->amount_vat,2);
194
195 }

◆ display()

Acc_Compute::display ( )

Definition at line 224 of file acc_compute.class.php.

225 {
226 foreach (self::$variable as $key=>$value)
227 {
228 echo 'key '.$key.' Description '.$value.' value is '.$this->$key.'<br>';
229 }
230 }

References $value, and $variable.

◆ get_info()

Acc_Compute::get_info ( )

Definition at line 123 of file acc_compute.class.php.

124 {
125 return var_export(self::$variable,true);
126 }

References $variable.

◆ get_parameter()

Acc_Compute::get_parameter (   $p_string)

Definition at line 101 of file acc_compute.class.php.

102 {
103 if ( array_key_exists($p_string,self::$variable) )
104 {
105 $idx=self::$variable[$p_string];
106 return $this->$idx;
107 }
108 else
109 throw new Exception (__FILE__.":".__LINE__._('Erreur attribut inexistant'));
110 }
$idx

References $idx, and $variable.

◆ set_parameter()

Acc_Compute::set_parameter (   $p_string,
  $p_value 
)

Definition at line 111 of file acc_compute.class.php.

112 {
113 if ( array_key_exists($p_string,self::$variable) )
114 {
115 $idx=self::$variable[$p_string];
116 $this->$idx=$p_value;
117 }
118 else
119 throw new Exception (__FILE__.":".__LINE__._('Erreur attribut inexistant'));
120
121
122 }

References $idx, and $variable.

◆ test_me()

static Acc_Compute::test_me ( )
static

Definition at line 231 of file acc_compute.class.php.

232 {
233 $a=new Acc_Compute();
234 echo $a->get_info();
235 echo '<hr>';
236
237 // Compute some operation to see if the computed amount are
238 // correct
239
240 //Test VAT
241 $a->set_parameter('amount',1.23);
242 $a->set_parameter('amount_vat_rate',0.21);
243
244 echo '<h1> Test VAT </h1>';
245 echo '<h2> Data </h2>';
246 $a->display();
247
248 echo '<h2> Result </h2>';
249 $a->compute_vat();
250 $a->display();
251 $a->verify();
252 // Test VAT + perso
253 $a=new Acc_Compute();
254 $a->set_parameter('amount',1.23);
255 $a->set_parameter('amount_vat_rate',0.21);
256 $a->set_parameter('amount_perso_rate',0.5);
257 echo '<h1> Test VAT + Perso</h1>';
258 echo '<h2> Data </h2>';
259 $a->display();
260 $b=clone $a;
261 $a->compute_vat();
262 $a->compute_perso();
263 $a->correct();
264 echo '<h2> Result </h2>';
265 $a->display();
266 $a->verify($b);
267 // TEST VAT + ND
268 // Test VAT + perso
269 $a=new Acc_Compute();
270 $a->set_parameter('amount',1.23);
271 $a->set_parameter('amount_vat_rate',0.21);
272 $a->set_parameter('nd_vat_rate',0.5);
273 $b=clone $a;
274 echo '<h1> Test VAT + ND VAT</h1>';
275 echo '<h2> Data </h2>';
276 $a->display();
277 $a->compute_vat();
278 $a->compute_nd_vat();
279 $a->correct();
280 echo '<h2> Result </h2>';
281 $a->display();
282 $a->verify($b);
283 // TEST VAT + ND
284 // Test VAT + perso
285 $a=new Acc_Compute();
286 $a->set_parameter('amount',1.23);
287 $a->set_parameter('amount_vat_rate',0.21);
288 $a->set_parameter('nd_vat_rate',0.5);
289 $a->set_parameter('amount_perso_rate',0.5);
290
291 $b=clone $a;
292 echo '<h1> Test VAT + ND VAT + perso</h1>';
293 echo '<h2> Data </h2>';
294 $a->display();
295 $a->compute_vat();
296 $a->compute_perso();
297 $a->compute_nd_vat();
298 $a->correct();
299 echo '<h2> Result </h2>';
300 $a->display();
301 $a->verify($b);
302 // TEST VAT + ND
303 $a=new Acc_Compute();
304 $a->set_parameter('amount',1.23);
305 $a->set_parameter('amount_vat_rate',0.21);
306 $a->set_parameter('amount_nd_rate',0.5);
307
308 $b=clone $a;
309 echo '<h1> Test VAT + ND </h1>';
310 echo '<h2> Data </h2>';
311 $a->display();
312 $a->compute_vat();
313 $a->compute_nd();
314
315 $a->compute_perso();
316 $a->compute_nd_vat();
317 $a->correct();
318 echo '<h2> Result </h2>';
319 $a->display();
320 $a->verify($b);
321 // TEST VAT + ND
322 // + Perso
323 $a=new Acc_Compute();
324 $a->set_parameter('amount',1.23);
325 $a->set_parameter('amount_vat_rate',0.21);
326 $a->set_parameter('amount_nd_rate',0.5);
327 $a->set_parameter('amount_perso_rate',0.2857);
328 $b=clone $a;
329 echo '<h1> Test VAT + ND + Perso</h1>';
330 echo '<h2> Data </h2>';
331 $a->display();
332 $a->compute_vat();
333 $a->compute_nd();
334
335 $a->compute_perso();
336 $a->compute_nd_vat();
337 $a->correct();
338 echo '<h2> Result </h2>';
339 $a->display();
340 $a->verify($b);
341// TEST VAT + ND
342 // + Perso
343 $a=new Acc_Compute();
344 $a->set_parameter('amount',1.23);
345 $a->set_parameter('amount_vat_rate',0.21);
346 $a->set_parameter('nd_ded_vat_rate',0.5);
347
348 $b=clone $a;
349 echo '<h1> Test VAT + TVA ND DED</h1>';
350 echo '<h2> Data </h2>';
351 $a->display();
352 $a->compute_vat();
353 $a->compute_nd();
354
355 $a->compute_perso();
356 $a->compute_nd_vat();
357 $a->compute_ndded_vat();
358 $a->correct();
359 echo '<h2> Result </h2>';
360 $a->display();
361 $a->verify($b);
362
363
364 }
this class aims to compute different amount

References $a, and $b.

◆ verify()

Acc_Compute::verify (   $p_obj = null)

!

verify that all the amount are positive or null otherwise throw a exception and the sum of amount + vat must equal to the sum of all the amount of the current object so you have to copy the object before computing anything and pass it as parameter

Parameters
comparewith a object copied before computing, if null there is no comparison

Definition at line 206 of file acc_compute.class.php.

207 {
208 foreach (self::$variable as $key=>$value)
209 if ( $this->$value < 0 )
210 throw new Exception (_("Montant invalide"));
211
212 if ( $p_obj != null )
213 {
214 $sum=0;
215 foreach ( array( 'amount','amount_vat','amount_nd','nd_vat','amount_perso','nd_ded_vat') as $value)
216 $sum=bcadd($sum,$this->$value);
217 if ( $p_obj->amount_vat == 0 ) $p_obj->compute_vat();
218 $cmp=bcadd($p_obj->amount,$p_obj->amount_vat);
219 $diff=bcsub($sum,$cmp);
220 if ( $diff != 0.0 )
221 throw new Exception (_("ECHEC VERIFICATION : valeur totale = $sum valeur attendue = $cmp diff = $diff"));
222 }
223 }

References $diff, $value, and $variable.

Field Documentation

◆ $check

Acc_Compute::$check

Definition at line 78 of file acc_compute.class.php.

◆ $order

Acc_Compute::$order
private

Definition at line 74 of file acc_compute.class.php.

◆ $variable

Acc_Compute::$variable
staticprivate
Initial value:
=array( 'amount'=>'amount',
'amount_vat'=>'amount_vat',
'amount_vat_rate'=>'amount_vat_rate',
'nd_vat'=>'nd_vat',
'nd_vat_rate'=>'nd_vat_rate',
'nd_ded_vat'=>'nd_ded_vat',
'nd_ded_vat_rate'=>'nd_ded_vat_rate',
'amount_nd'=>'amount_nd',
'amount_nd_rate'=>'amount_nd_rate',
'nd_vat_rate'=>'nd_vat_rate',
'amount_perso'=>'amount_perso',
'amount_perso_rate'=>'amount_perso_rate',
'amount_currency'=>'amount_currency',
'amount_vat_currency'=>'amount_vat_currency',
'currency_rate'=>'currency_rate'
)

Definition at line 57 of file acc_compute.class.php.


The documentation for this class was generated from the following file: