noalyss  Version-6.7.2
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...

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 ()
 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

Definition at line 55 of file class_acc_compute.php.


Constructor & Destructor Documentation

Definition at line 78 of file class_acc_compute.php.

References $value.

    {
        bcscale(4);
        foreach (self::$variable as $key=>$value)       $this->$key=0;
        $this->order=0;
        $this->check=true;
    }

Member Function Documentation

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

Definition at line 123 of file class_acc_compute.php.

Referenced by Acc_Ledger_Purchase\compute_no_deductible().

    {
        if ( $this->check && $this->order > 2 )  throw new Exception ('ORDER NOT RESPECTED');

        $this->amount_nd=bcmul($this->amount,$this->amount_nd_rate);
        $this->amount_nd=bcdiv($this->amount_nd,100);
        $this->amount_nd=round($this->amount_nd,2);
        // the nd part for the vat
        $nd_vat=bcmul($this->amount_vat,$this->amount_nd_rate);
        $nd_vat=bcdiv($nd_vat,100);
        $nd_vat=round($nd_vat,2);

    }

Definition at line 136 of file class_acc_compute.php.

References compute_vat().

Referenced by Acc_Ledger_Purchase\compute_no_deductible().

    {
        if ( $this->check && $this->order > 3 ) throw new Exception ('ORDER NOT RESPECTED');
        $this->order=4;

        if ($this->amount_vat == 0 ) $this->compute_vat();
        $this->nd_vat=bcmul($this->amount_vat,$this->nd_vat_rate);
        $this->nd_vat=bcdiv($this->nd_vat,100);
        $this->nd_vat=round($this->nd_vat,2);
    }

Definition at line 147 of file class_acc_compute.php.

References compute_vat().

Referenced by Acc_Ledger_Purchase\compute_no_deductible().

    {
        if ( $this->check && $this->order > 4 ) throw new Exception ('ORDER NOT RESPECTED');
        $this->order=5;

        if ($this->amount_vat == 0 ) $this->compute_vat();
        $this->nd_ded_vat=bcmul($this->amount_vat,$this->nd_ded_vat_rate);
        $this->nd_ded_vat=bcdiv($this->nd_ded_vat,100);
        $this->nd_ded_vat=round($this->nd_ded_vat,2);
    }

Definition at line 158 of file class_acc_compute.php.

Referenced by Acc_Ledger_Purchase\compute_no_deductible().

    {
        if ( $this->check && $this->order != 1 ) throw new Exception ('ORDER NOT RESPECTED');
        $this->order=2;
        if ( $this->amount == 0 ) return;
        $this->amount_perso=bcmul($this->amount,$this->amount_perso_rate);
        $this->amount_perso=bcdiv($this->amount_perso,100);
        $this->amount_perso=round($this->amount_perso,2);



    }

Definition at line 113 of file class_acc_compute.php.

Referenced by compute_nd_vat(), and compute_ndded_vat().

    {
        if ( $this->check && $this->order != 0 ) throw new Exception ('ORDER NOT RESPECTED');
        $this->amount_vat=bcmul($this->amount,$this->amount_vat_rate);
        $this->amount_vat=round($this->amount_vat,2);
        $this->order=1;
    }

Definition at line 170 of file class_acc_compute.php.

    {
        $this->amount=bcsub($this->amount,$this->amount_perso);
        // correct the others amount
        $this->amount=bcsub($this->amount,$this->amount_nd);
        $this->amount_vat=bcsub($this->amount_vat,$this->nd_ded_vat);
        $this->amount_vat=round($this->amount_vat,2);
        $this->amount_vat=bcsub($this->amount_vat,$this->nd_vat);
        $this->amount_vat=round($this->amount_vat,2);

    }

Definition at line 208 of file class_acc_compute.php.

References $value, and echo.

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

Definition at line 108 of file class_acc_compute.php.

    {
        return var_export(self::$variable,true);
    }
Acc_Compute::get_parameter ( p_string)

Definition at line 86 of file class_acc_compute.php.

References $idx, and exit.

    {
        if ( array_key_exists($p_string,self::$variable) )
        {
            $idx=self::$variable[$p_string];
            return $this->$idx;
        }
        else
            exit (__FILE__.":".__LINE__._('Erreur attribut inexistant'));
    }
Acc_Compute::set_parameter ( p_string,
p_value 
)

Definition at line 96 of file class_acc_compute.php.

References $idx, and exit.

    {
        if ( array_key_exists($p_string,self::$variable) )
        {
            $idx=self::$variable[$p_string];
            $this->$idx=$p_value;
        }
        else
            exit (__FILE__.":".__LINE__._('Erreur attribut inexistant'));


    }
static Acc_Compute::test_me ( ) [static]

Definition at line 215 of file class_acc_compute.php.

References $a, $b, and echo.

    {
        $a=new Acc_Compute();
        echo $a->get_info();
        echo '<hr>';

        // Compute some operation to see if the computed amount are
        // correct

        //Test VAT
        $a->set_parameter('amount',1.23);
        $a->set_parameter('amount_vat_rate',0.21);

        echo '<h1> Test VAT </h1>';
        echo '<h2> Data </h2>';
        $a->display();

        echo '<h2> Result </h2>';
        $a->compute_vat();
        $a->display();
        $a->verify();
        // Test VAT + perso
        $a=new Acc_Compute();
        $a->set_parameter('amount',1.23);
        $a->set_parameter('amount_vat_rate',0.21);
        $a->set_parameter('amount_perso_rate',0.5);
        echo '<h1> Test VAT + Perso</h1>';
        echo '<h2> Data </h2>';
        $a->display();
        $b=clone $a;
        $a->compute_vat();
        $a->compute_perso();
        $a->correct();
        echo '<h2> Result </h2>';
        $a->display();
        $a->verify($b);
        // TEST VAT + ND
        // Test VAT + perso
        $a=new Acc_Compute();
        $a->set_parameter('amount',1.23);
        $a->set_parameter('amount_vat_rate',0.21);
        $a->set_parameter('nd_vat_rate',0.5);
        $b=clone $a;
        echo '<h1> Test VAT + ND VAT</h1>';
        echo '<h2> Data </h2>';
        $a->display();
        $a->compute_vat();
        $a->compute_nd_vat();
        $a->correct();
        echo '<h2> Result </h2>';
        $a->display();
        $a->verify($b);
        // TEST VAT + ND
        // Test VAT + perso
        $a=new Acc_Compute();
        $a->set_parameter('amount',1.23);
        $a->set_parameter('amount_vat_rate',0.21);
        $a->set_parameter('nd_vat_rate',0.5);
        $a->set_parameter('amount_perso_rate',0.5);

        $b=clone $a;
        echo '<h1> Test VAT + ND VAT + perso</h1>';
        echo '<h2> Data </h2>';
        $a->display();
        $a->compute_vat();
        $a->compute_perso();
        $a->compute_nd_vat();
        $a->correct();
        echo '<h2> Result </h2>';
        $a->display();
        $a->verify($b);
        // TEST VAT + ND
        $a=new Acc_Compute();
        $a->set_parameter('amount',1.23);
        $a->set_parameter('amount_vat_rate',0.21);
        $a->set_parameter('amount_nd_rate',0.5);

        $b=clone $a;
        echo '<h1> Test VAT + ND </h1>';
        echo '<h2> Data </h2>';
        $a->display();
        $a->compute_vat();
        $a->compute_nd();

        $a->compute_perso();
        $a->compute_nd_vat();
        $a->correct();
        echo '<h2> Result </h2>';
        $a->display();
        $a->verify($b);
        // TEST VAT + ND
        // + Perso
        $a=new Acc_Compute();
        $a->set_parameter('amount',1.23);
        $a->set_parameter('amount_vat_rate',0.21);
        $a->set_parameter('amount_nd_rate',0.5);
        $a->set_parameter('amount_perso_rate',0.2857);
        $b=clone $a;
        echo '<h1> Test VAT + ND  + Perso</h1>';
        echo '<h2> Data </h2>';
        $a->display();
        $a->compute_vat();
        $a->compute_nd();

        $a->compute_perso();
        $a->compute_nd_vat();
        $a->correct();
        echo '<h2> Result </h2>';
        $a->display();
        $a->verify($b);
// TEST VAT + ND
        // + Perso
        $a=new Acc_Compute();
        $a->set_parameter('amount',1.23);
        $a->set_parameter('amount_vat_rate',0.21);
        $a->set_parameter('nd_ded_vat_rate',0.5);

        $b=clone $a;
        echo '<h1> Test VAT   +  TVA ND DED</h1>';
        echo '<h2> Data </h2>';
        $a->display();
        $a->compute_vat();
        $a->compute_nd();

        $a->compute_perso();
        $a->compute_nd_vat();
        $a->compute_ndded_vat();
        $a->correct();
        echo '<h2> Result </h2>';
        $a->display();
        $a->verify($b);


    }
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 190 of file class_acc_compute.php.

References $diff, and $value.

    {
        foreach (self::$variable as $key=>$value)
        if ( $this->$value < 0 )
            throw new Exception (_("Montant invalide"));

        if ( $p_obj != null )
        {
            $sum=0;
            foreach ( array( 'amount','amount_vat','amount_nd','nd_vat','amount_perso','nd_ded_vat') as $value)
            $sum=bcadd($sum,$this->$value);
            if ( $p_obj->amount_vat == 0 ) $p_obj->compute_vat();
            $cmp=bcadd($p_obj->amount,$p_obj->amount_vat);
            $diff=bcsub($sum,$cmp);
            if ( $diff != 0.0 )
                throw new Exception (_("ECHEC VERIFICATION  : valeur totale = $sum valeur attendue = $cmp diff = $diff"));
        }
    }

Field Documentation

Acc_Compute::$check

Definition at line 75 of file class_acc_compute.php.

Acc_Compute::$order [private]

Definition at line 71 of file class_acc_compute.php.

Acc_Compute::$variable [static, private]
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'
                                  )

Definition at line 57 of file class_acc_compute.php.


The documentation for this class was generated from the following file:
 All Data Structures Namespaces Files Functions Variables Enumerations