Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 require_once("constant.php");
00021 require_once('class_database.php');
00022 require_once("class_acc_parm_code.php");
00023 require_once('class_periode.php');
00024 require_once('class_fiche.php');
00025 require_once('class_acc_account_ledger.php');
00026 require_once('user_common.php');
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 class Customer extends Fiche
00037 {
00038
00039 var $poste;
00040 var $name;
00041 var $street;
00042 var $country;
00043 var $cp;
00044 var $vat_number;
00045
00046
00047
00048 function __construct($p_cn,$p_id=0)
00049 {
00050 $this->fiche_def_ref=FICHE_TYPE_CLIENT;
00051 parent::__construct($p_cn,$p_id) ;
00052
00053 }
00054
00055
00056
00057 function get_by_account($p_poste=0)
00058 {
00059 $this->poste=($p_poste==0)?$this->poste:$p_poste;
00060 $sql="select * from vw_client where poste_comptable=$1";
00061 $Res=$this->cn->exec_sql($sql,array($this->poste));
00062 if ( Database::num_row($Res) == 0) return null;
00063 if ( Database::num_row($Res) > 1 ) throw new Exception ('Plusieurs fiches avec le même poste',1);
00064
00065 $row=Database::fetch_array($Res,0);
00066 $this->name=$row['name'];
00067 $this->id=$row['f_id'];
00068 $this->street=$row['rue'];
00069 $this->cp=$row['code_postal'];
00070 $this->country=$row['pays'];
00071 $this->vat_number=$row['tva_num'];
00072
00073 }
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084 function VatListing($p_year)
00085 {
00086 $cond_sql=" and A.j_date = B.j_date and extract(year from A.j_date) ='$p_year'";
00087
00088 $aCustomer=$this->cn->get_array('select f_id,name,quick_code,tva_num,poste_comptable from vw_client '.
00089 " where tva_num !='' ");
00090
00091
00092
00093
00094
00095 $s=new Acc_Parm_Code($this->cn,'VENTE');
00096 $s->load();
00097 $SOLD=$s->p_value;
00098
00099 $c=new Acc_Parm_Code($this->cn,'CUSTOMER');
00100 $c->load();
00101 $CUSTOMER=$c->p_value;
00102
00103 $t=new Acc_Parm_Code($this->cn,'COMPTE_TVA');
00104 $t->load();
00105 $TVA=$t->p_value;
00106
00107 $a_Res=array();
00108
00109 foreach ($aCustomer as $l )
00110 {
00111
00112
00113 $customer=$l['quick_code'];
00114 $a_Res[$customer]['name']=$l['name'];
00115 $a_Res[$customer]['vat_number']=$l['tva_num'];
00116 $a_Res[$customer]['amount']=0;
00117 $a_Res[$customer]['tva']=0;
00118 $a_Res[$customer]['poste_comptable']=$l['poste_comptable'];
00119
00120
00121
00122 $sql="select distinct j_grpt
00123 from
00124 jrnx as A
00125 join jrnx as B using (j_grpt)
00126 where
00127 A.j_qcode = '".$l['quick_code']."' and
00128 B.j_poste::text like '".$SOLD."%'
00129 $cond_sql
00130 ";
00131
00132 $Res=$this->cn->exec_sql($sql);
00133
00134
00135
00136
00137
00138 for ($i=0; $i < Database::num_row($Res);$i++)
00139 {
00140
00141
00142 $row1=Database::fetch_array($Res,$i);
00143
00144
00145
00146
00147 $Res2=$this->cn->exec_sql("select j_poste,j_montant,j_debit from jrnx where j_grpt=".$row1['j_grpt']);
00148 $a_row=Database::fetch_all($Res2);
00149
00150
00151
00152 foreach ($a_row as $e)
00153 {
00154 $amount=0;
00155 $tva=0;
00156 if ( substr($e['j_poste'],0, strlen($SOLD))===$SOLD)
00157 {
00158 $amount=($e['j_debit']=='f')?$e['j_montant']:$e['j_montant']*-1;
00159 }
00160 if ( substr($e['j_poste'],0, strlen($TVA))===$TVA)
00161 {
00162 $tva=($e['j_debit']=='f')?$e['j_montant']:$e['j_montant']*-1;
00163 }
00164
00165
00166 $a_Res[$customer]['amount']=(isset($a_Res[$customer]['amount']))?$a_Res[$customer]['amount']:0;
00167 $a_Res[$customer]['amount']+=$amount;
00168
00169
00170
00171 $a_Res[$customer]['tva']=(isset($a_Res[$customer]['tva']))?$a_Res[$customer]['tva']:0;
00172 $a_Res[$customer]['tva']+=$tva;
00173
00174
00175
00176 $a_Res[$customer]['customer']=$customer;
00177 }
00178 }
00179 }
00180
00181 return $a_Res;
00182 }
00183
00184
00185 }
00186
00187 ?>