Main Page | Namespace List | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

Customer Class Reference

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

Inheritance diagram for Customer:

fiche

Public Member Functions

 Customer ($p_cn, $p_id=0)
 Constructor /* only a db connection is needed.
 GetFromPoste ($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.
 Summary ($p_search)

Data Fields

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

Detailed Description

class Customer are a specific kind of card

Definition at line 38 of file class_customer.php.


Constructor & Destructor Documentation

Customer::Customer p_cn,
p_id = 0
 

Constructor /* only a db connection is needed.

Definition at line 49 of file class_customer.php.

References fiche::fiche().

00049                                    {
00050       $this->fiche_def_ref=FICHE_TYPE_CLIENT;
00051       fiche::fiche($p_cn,$p_id) ;
00052 
00053   }


Member Function Documentation

Customer::GetFromPoste 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, $row, $sql, ExecSql(), f_id, and name.

Referenced by VatListing().

00057                                     {
00058     $this->poste=($p_poste==0)?$this->poste:$p_poste;
00059     $sql="select * from vw_client where poste_comptable=".$this->poste;
00060     $Res=ExecSql($this->cn,$sql);
00061     if ( pg_NumRows($Res) == 0) return null;
00062     // There is only _one_ row by customer
00063     $row=pg_fetch_array($Res,0);
00064     $this->name=$row['name'];
00065     $this->id=$row['f_id'];    
00066     $this->street=$row['rue'];    
00067     $this->cp=$row['code_postal'];
00068     $this->country=$row['pays'];
00069     $this->vat_number=$row['tva_num'];
00070 
00071   }

Customer::Summary p_search  ) 
 

Summary

show the default screen

parm :

  • p_search (filter) gen :
  • return: string to display

Definition at line 195 of file class_customer.php.

References $a, $bar, $e, $filter_year, $offset, $page, $r, $search, $url, $User, fiche::CountByDef(), FormatString(), fiche::GetAll(), jrn_navigation_bar(), poste, and table.

00196     {
00197       $p_search=FormatString($p_search);
00198       $url=urlencode($_SERVER['REQUEST_URI']);
00199       $script=$_SERVER['SCRIPT_NAME'];
00200       // Creation of the nav bar
00201       // Get the max numberRow
00202       $all_client=$this->CountByDef($this->fiche_def_ref,$p_search); 
00203       // Get offset and page variable
00204       $offset=( isset ($_REQUEST['offset'] )) ?$_REQUEST['offset']:0;
00205       $page=(isset($_REQUEST['page']))?$_REQUEST['page']:1;
00206       $bar=jrn_navigation_bar($offset,$all_client,$_SESSION['g_pagesize'],$page);
00207       // set a filter ?
00208       $search="";
00209       if ( trim($p_search) != "" )
00210         {
00211           $search=" and f_id in
00212 (select f_id from jnt_fic_att_value 
00213                   join fiche using (f_id) 
00214                   join attr_value using (jft_id)
00215                 where
00216                 ad_id=1 and av_text ~* '$p_search')";
00217         }
00218       // Get The result Array
00219       $step_client=$this->GetAll($offset,$search);
00220       if ( $all_client == 0 ) return "";
00221       $r=$bar;
00222       $r.='<table>
00223 <TR style="background-color:lightgrey;">
00224 <TH>Quick Code</TH>
00225 <th>Nom</th>
00226 <th>Adresse</th>
00227 <th>Solde</th>
00228 <th colspan="3">Action </th>
00229 </TR>';
00230       if ( sizeof ($step_client ) == 0 )
00231         return $r;
00232       foreach ($step_client as $client ) {
00233         $r.="<TR>";
00234         $e=sprintf('<A HREF="%s?p_action=client&sa=detail&f_id=%d&url=%s" title="Détail"> ',
00235                     $script,$client->id,$url);
00236 
00237         $r.="<TD> $e".$client->strAttribut(ATTR_DEF_QUICKCODE)."</A></TD>";
00238         $r.="<TD>".$client->strAttribut(ATTR_DEF_NAME)."</TD>";
00239         $r.="<TD>".$client->strAttribut(ATTR_DEF_ADRESS).
00240           " ".$client->strAttribut(ATTR_DEF_CP).
00241           " ".$client->strAttribut(ATTR_DEF_PAYS).
00242           "</TD>";
00243 
00244         $post=new poste($this->cn,$client->strAttribut(ATTR_DEF_ACCOUNT));
00245         /* Filter on the default year */
00246         $User=new cl_user($this->cn);
00247         $filter_year="  j_tech_per in (select p_id from parm_periode ".
00248                      "where p_exercice='".$User->getExercice()."')";
00249         $a=$post->GetSoldeDetail($filter_year);
00250         $r.=sprintf('<TD align="right"> %15.2f&euro;</TD>',$a['solde']);
00251         $r.="<TD>";
00252 
00253         $r.=sprintf('<A HREF="%s?p_action=contact&qcode=%s&url=%s" title="Contact">Contact</A></td>',
00254                     $script,$client->strAttribut(ATTR_DEF_QUICKCODE),$url);
00255         $r.=sprintf('<td><A HREF="%s?p_action=suivi_courrier&sa=list&qcode=%s&url=%s" title="Action">Courrier</A></td> ',
00256                     $script,$client->strAttribut(ATTR_DEF_QUICKCODE) ,$url);
00257 
00258 
00259 
00260         $r.='<td><A HREF="commercial.php?p_action=facture&sa=list&p_periode=-1&qcode='.$client->strAttribut(ATTR_DEF_QUICKCODE).'&url='.$url.'" title="Historique Facture">Facture</A></td>';
00261 
00262         $r.='</TD>';
00263 
00264         $r.="</TR>";
00265 
00266       }
00267       $r.="</TABLE>";
00268       $r.=$bar;
00269       return $r;
00270     }

Customer::VatListing p_year  ) 
 

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

Todo:
optimize SQL
Parameters:
periode 
Returns:
double array structure is ( j_poste,name,vat_number,amount,tva,customer(object)

Definition at line 84 of file class_customer.php.

References $a_Res, $c, $customer, $e, $Res, $Res2, $sql, $t, ExecSql(), GetFromPoste(), and name.

00084                                {
00085     $cond_sql=" and A.j_date = B.j_date 
00086       and extract(year from A.j_date) ='$p_year'";
00087     
00088     // BASE ACCOUNT
00089     // for belgium
00090     $s=new parm_code($this->cn,'VENTE');
00091     $s->Get();
00092     $SOLD=$s->p_value;
00093 
00094     $c=new parm_code($this->cn,'CUSTOMER');
00095     $c->Get();
00096     $CUSTOMER=$c->p_value;
00097 
00098     $t=new parm_code($this->cn,'COMPTE_TVA');
00099     $t->Get();
00100     $TVA=$t->p_value;
00101     // Get all the sell operation
00102     //----
00103     $sql="select  j_grpt 
00104       from
00105 jrnx as A
00106  join jrnx as B using (j_grpt)
00107 where
00108        A.j_poste like '".$CUSTOMER."%' and
00109        B.j_poste like '".$SOLD."%' 
00110       $cond_sql
00111 ";
00112 
00113     $Res=ExecSql($this->cn,$sql);
00114     // Foreach operation 
00115     // where 7% or tva account are involved
00116     // and store the result in an array (a_Res)
00117     //---
00118     $a_Res=array();
00119     for ($i=0; $i < pg_NumRows($Res);$i++) {
00120       // Get each row
00121       //---
00122       $row1=pg_fetch_array($Res,$i);
00123   
00124       // select the operation
00125       //----
00126       $Res2=ExecSql($this->cn,"select j_poste,j_montant,j_debit from jrnx where j_grpt=".$row1['j_grpt']); 
00127       $a_row=array();
00128       // Store the result in the array 
00129       //---
00130       for ($e=0;$e < pg_NumRows($Res2);$e++) {
00131         $a_row[]=pg_fetch_array($Res2,$e);
00132       }
00133       
00134       // Seek the customer
00135       //---
00136       foreach ($a_row as $e) {
00137         if ( substr($e['j_poste'],0, strlen($CUSTOMER))==$CUSTOMER) {
00138           $customer=$e['j_poste'];
00139           // Retrieve name and vat number
00140           $this->GetFromPoste($customer);
00141           $a_Res[$customer]['name']=$this->name;
00142           $a_Res[$customer]['vat_number']=$this->vat_number;
00143           break;
00144           
00145         }
00146       }// foreach $a
00147       // Store the amount in the array
00148       //---
00149       foreach ($a_row as $e) {
00150         $amount=0;
00151         $tva=0;
00152         if ( substr($e['j_poste'],0, strlen($SOLD))==$SOLD) {
00153           $amount=($e['j_debit']=='f')?$e['j_montant']:$e['j_montant']*-1;
00154         }
00155         if ( substr($e['j_poste'],0, strlen($TVA))==$TVA) {
00156           $tva=($e['j_debit']=='f')?$e['j_montant']:$e['j_montant']*-1;
00157         }
00158         // store sold
00159         //---
00160         $a_Res[$customer]['amount']=(isset($a_Res[$customer]['amount']))?$a_Res[$customer]['amount']:0;         
00161   $a_Res[$customer]['amount']+=$amount;
00162 
00163         // store vat
00164         //---
00165         $a_Res[$customer]['tva']=(isset($a_Res[$customer]['tva']))?$a_Res[$customer]['tva']:0;
00166         $a_Res[$customer]['tva']+=$tva;  
00167   
00168         // store customef info
00169         //---
00170         $a_Res[$customer]['customer']=$customer;
00171 
00172   //if not submitted to VAT, remove from list:
00173   //STAN: currently commented out because I don't know if it is really what we need.
00174   //Dany : yes we need it because the decla. concerns only the registered customer at the VAT 
00175         if (!isset($a_Res[$customer]['vat_number']) || strcmp($a_Res[$customer]['vat_number'], "") == 0)
00176           {
00177             unset($a_Res[$customer]);
00178           }
00179         
00180       }// foreach $a
00181 
00182     }
00183     return $a_Res;
00184   }


Field Documentation

Customer::$country
 

Country

Definition at line 43 of file class_customer.php.

Customer::$cp
 

Zip code

Definition at line 44 of file class_customer.php.

Customer::$name
 

name of the company

Definition at line 41 of file class_customer.php.

Customer::$poste
 

poste comptable

Definition at line 40 of file class_customer.php.

Customer::$street
 

Street

Definition at line 42 of file class_customer.php.

Customer::$vat_number
 

vat number

Definition at line 45 of file class_customer.php.


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