noalyss Version-9
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
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.
 
 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)
 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
 

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

  • vat
  • amount without vat
  • no deductible vat
  • personal part
  • no deductible amount Nothing won't be saved to the database, this class will just compute and complete the object if you need to compute the vat and in another place all the details you'll have to use the clone function private static $variable=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' ); 'autoreverse'=>'autoreverse'

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

Constructor & Destructor Documentation

◆ __construct()

Acc_Compute::__construct ( )

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

86 {
87 bcscale(4);
88 foreach (self::$variable as $key=>$value) $this->$key=0;
89 $this->order=0;
90 $this->check=true;
91 }

References $value.

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 142 of file acc_compute.class.php.

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

Referenced by Acc_Ledger_Purchase\compute_no_deductible().

◆ compute_nd_vat()

Acc_Compute::compute_nd_vat ( )

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

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

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 166 of file acc_compute.class.php.

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

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 177 of file acc_compute.class.php.

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

Referenced by Acc_Ledger_Purchase\compute_no_deductible().

◆ compute_vat()

Acc_Compute::compute_vat ( )

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

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

Referenced by compute_nd_vat(), and compute_ndded_vat().

◆ convert_euro()

Acc_Compute::convert_euro ( )

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

94 {
95 $local_amount=$this->amount;
96 $this->amount=bcdiv($this->amount,$this->currency_rate,6);
97 $this->amount_currency=$local_amount;
98 }

References $amount.

◆ convert_euro_vat()

Acc_Compute::convert_euro_vat ( )

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

100 {
101 $local_amount=$this->amount_vat;
102 $this->amount_vat=bcdiv($this->amount_vat,$this->currency_rate,6);
103 $this->amount_vat_currency=$local_amount;
104 }

◆ correct()

Acc_Compute::correct ( )

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

190 {
191 $this->amount=bcsub($this->amount,$this->amount_perso);
192 // correct the others amount
193 $this->amount=bcsub($this->amount,$this->amount_nd);
194 $this->amount_vat=bcsub($this->amount_vat,$this->nd_ded_vat);
195 $this->amount_vat=round($this->amount_vat,2);
196 $this->amount_vat=bcsub($this->amount_vat,$this->nd_vat);
197 $this->amount_vat=round($this->amount_vat,2);
198
199 }

◆ display()

Acc_Compute::display ( )

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

229 {
230 foreach (self::$variable as $key=>$value)
231 {
232 echo 'key '.$key.' Description '.$value.' value is '.$this->$key.'<br>';
233 }
234 }

References $value.

◆ get_info()

Acc_Compute::get_info ( )

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

128 {
129 return var_export(self::$variable,true);
130 }

◆ get_parameter()

Acc_Compute::get_parameter ( $p_string)

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

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

References $idx.

◆ set_parameter()

Acc_Compute::set_parameter ( $p_string,
$p_value )

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

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

References $idx.

◆ test_me()

static Acc_Compute::test_me ( )
static

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

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

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 210 of file acc_compute.class.php.

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

References $diff, $value, and _.

Field Documentation

◆ $check

Acc_Compute::$check

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

◆ $order

Acc_Compute::$order
private

Definition at line 76 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',
'autoreverse'=>'autoreverse'
)

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


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