noalyss  Version-6.7.2
Public Member Functions | Data Fields
Customer Class Reference

class Customer are a specific kind of card More...

Inheritance diagram for Customer:
Fiche

Public Member Functions

 __construct ($p_cn, $p_id=0)
 Constructor /* only a db connection is needed.
 get_by_account ($p_poste=0)
 Get all info contains in the view thanks to the poste elt (account)
 VatListing ($p_year)
 Get all the info for making a vat listing for the vat administration.

Data Fields

 $country
 $cp
 $name
 $poste
 $street
 $vat_number

Detailed Description

class Customer are a specific kind of card

Definition at line 36 of file class_customer.php.


Constructor & Destructor Documentation

Customer::__construct ( p_cn,
p_id = 0 
)

Constructor /* only a db connection is needed.

Reimplemented from Fiche.

Definition at line 48 of file class_customer.php.

    {
        $this->fiche_def_ref=FICHE_TYPE_CLIENT;
        parent::__construct($p_cn,$p_id) ;

    }

Member Function Documentation

Customer::get_by_account ( p_poste = 0)

Get all info contains in the view thanks to the poste elt (account)

Definition at line 57 of file class_customer.php.

References $Res, Fiche\$row, $sql, cn, Database\fetch_array(), name, Database\num_row(), and poste.

    {
        $this->poste=($p_poste==0)?$this->poste:$p_poste;
        $sql="select * from vw_client where poste_comptable=$1";
        $Res=$this->cn->exec_sql($sql,array($this->poste));
        if ( Database::num_row($Res) == 0) return null;
        if ( Database::num_row($Res) > 1 ) throw new Exception ('Plusieurs fiches avec le même poste',1);
        // There is only _one_ row by customer
        $row=Database::fetch_array($Res,0);
        $this->name=$row['name'];
        $this->id=$row['f_id'];
        $this->street=$row['rue'];
        $this->cp=$row['code_postal'];
        $this->country=$row['pays'];
        $this->vat_number=$row['tva_num'];

    }
Customer::VatListing ( p_year)

Get all the info for making a vat listing for the vat administration.

Parameters:
$p_year
Returns:
double array structure is ( j_poste,name,vat_number,amount,tva,customer(object)

Definition at line 84 of file class_customer.php.

References $amount, $e, $l, $Res, $s, $sql, cn, Database\fetch_all(), Database\fetch_array(), and Database\num_row().

    {
        $cond_sql=" and   A.j_date = B.j_date and extract(year from A.j_date) ='$p_year'";
        /* List of customer  */
        $aCustomer=$this->cn->get_array('select f_id,name,quick_code,tva_num,poste_comptable from vw_client '.
                                        " where tva_num !='' ");

        /* Use the code */

        // BASE ACCOUNT
        // for belgium
        $s=new Acc_Parm_Code($this->cn,'VENTE');
        $s->load();
        $SOLD=$s->p_value;

        $c=new Acc_Parm_Code($this->cn,'CUSTOMER');
        $c->load();
        $CUSTOMER=$c->p_value;

        $t=new Acc_Parm_Code($this->cn,'COMPTE_TVA');
        $t->load();
        $TVA=$t->p_value;

        $a_Res=array();
        /* for each customer compute VAT, Amount...*/
        foreach ($aCustomer as $l )
        {
            // Seek the customer
            //---
            $customer=$l['quick_code'];
            $a_Res[$customer]['name']=$l['name'];
            $a_Res[$customer]['vat_number']=$l['tva_num'];
            $a_Res[$customer]['amount']=0;
            $a_Res[$customer]['tva']=0;
            $a_Res[$customer]['poste_comptable']=$l['poste_comptable'];
            /* retrieve only operation of sold and vat */
            // Get all the sell operation
            //----
            $sql="select distinct j_grpt
                 from
                 jrnx as A
                 join jrnx as B using (j_grpt)
                 where
                 A.j_qcode = '".$l['quick_code']."' and
                 B.j_poste::text like '".$SOLD."%'
                 $cond_sql
                 ";

            $Res=$this->cn->exec_sql($sql);
            // Foreach operation
            // where 7% or tva account are involved
            // and store the result in an array (a_Res)
            //---

            for ($i=0; $i < Database::num_row($Res);$i++)
            {
                // Get each row
                //---
                $row1=Database::fetch_array($Res,$i);


                // select the operation
                //----
                $Res2=$this->cn->exec_sql("select j_poste,j_montant,j_debit from jrnx where j_grpt=".$row1['j_grpt']);
                $a_row=Database::fetch_all($Res2);

                // Store the amount in the array
                //---
                foreach ($a_row as $e)
                {
                    $amount=0;
                    $tva=0;
                    if ( substr($e['j_poste'],0, strlen($SOLD))===$SOLD)
                    {
                        $amount=($e['j_debit']=='f')?$e['j_montant']:$e['j_montant']*-1;
                    }
                    if ( substr($e['j_poste'],0, strlen($TVA))===$TVA)
                    {
                        $tva=($e['j_debit']=='f')?$e['j_montant']:$e['j_montant']*-1;
                    }
                    // store sold
                    //---
                    $a_Res[$customer]['amount']=(isset($a_Res[$customer]['amount']))?$a_Res[$customer]['amount']:0;
                    $a_Res[$customer]['amount']+=$amount;

                    // store vat
                    //---
                    $a_Res[$customer]['tva']=(isset($a_Res[$customer]['tva']))?$a_Res[$customer]['tva']:0;
                    $a_Res[$customer]['tva']+=$tva;

                    // store customef info
                    //---
                    $a_Res[$customer]['customer']=$customer;
                }
            }// foreach $a
        } // foreach ( customer)

        return $a_Res;
    }

Field Documentation

Customer::$country

$country Country

Definition at line 42 of file class_customer.php.

Customer::$cp

$cp Zip code

Definition at line 43 of file class_customer.php.

Customer::$name

$name name of the company

Definition at line 40 of file class_customer.php.

Customer::$poste

$poste poste comptable

Definition at line 39 of file class_customer.php.

Customer::$street

$street Street

Definition at line 41 of file class_customer.php.

Customer::$vat_number

$vat_number vat number

Definition at line 44 of file class_customer.php.


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