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

class_supplier.php

Go to the documentation of this file.
00001 <?
00002 /*
00003  *   This file is part of PhpCompta.
00004  *
00005  *   PhpCompta is free software; you can redistribute it and/or modify
00006  *   it under the terms of the GNU General Public License as published by
00007  *   the Free Software Foundation; either version 2 of the License, or
00008  *   (at your option) any later version.
00009  *
00010  *   PhpCompta is distributed in the hope that it will be useful,
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *   GNU General Public License for more details.
00014  *
00015  *   You should have received a copy of the GNU General Public License
00016  *   along with PhpCompta; if not, write to the Free Software
00017  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 */
00019 /* $Revision: 1.4 $ */
00020 // Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
00021 require_once("constant.php");
00022 require_once("postgres.php");
00023 require_once("class_parm_code.php");
00024 require_once("class_widget.php");
00025 
00026 require_once('class_fiche.php');
00027 require_once('class_poste.php');
00028 require_once('user_common.php');
00036 // Use the view vw_supplier
00037 // 
00038 class Supplier extends fiche{
00039 
00040   var $poste;      
00041   var $name;        
00042   var $street;      
00043   var $country;     
00044   var $cp;          
00045   var $vat_number;  
00049   function Supplier($p_cn,$p_id=0) {
00050       $this->fiche_def_ref=FICHE_TYPE_FOURNISSEUR;
00051       fiche::fiche($p_cn,$p_id) ;
00052 
00053   }
00057   function GetFromPoste($p_poste=0) {
00058     $this->poste=($p_poste==0)?$this->poste:$p_poste;
00059     $sql="select * from vw_supplier 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 supplier
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   }
00072 
00083   function Summary($p_search) 
00084     {
00085       $p_search=FormatString($p_search);
00086       $url=urlencode($_SERVER['REQUEST_URI']);
00087       $script=$_SERVER['SCRIPT_NAME'];
00088       // Creation of the nav bar
00089       // Get the max numberRow
00090       $all_supplier=$this->CountByDef($this->fiche_def_ref,$p_search); 
00091       // Get offset and page variable
00092       $offset=( isset ($_REQUEST['offset'] )) ?$_REQUEST['offset']:0;
00093       $page=(isset($_REQUEST['page']))?$_REQUEST['page']:1;
00094       $bar=jrn_navigation_bar($offset,$all_supplier,$_SESSION['g_pagesize'],$page);
00095       // set a filter ?
00096       $search="";
00097       if ( trim($p_search) != "" )
00098         {
00099           $search=" and f_id in
00100 (select f_id from jnt_fic_att_value 
00101                   join fiche using (f_id) 
00102                   join attr_value using (jft_id)
00103                 where
00104                 ad_id=1 and av_text ~* '$p_search')";
00105         }
00106       // Get The result Array
00107       $step_supplier=$this->GetAll($offset,$search);
00108       if ( $all_supplier == 0 ) return "";
00109       $r=$bar;
00110       $r.='<table>
00111 <TR style="background-color:lightgrey;">
00112 <TH>Quick Code</TH>
00113 <th>Nom</th>
00114 <th>Adresse</th>
00115 <th>Solde</th>
00116 <th colspan="3">Action </th>
00117 </TR>';
00118       if ( sizeof ($step_supplier ) == 0 )
00119         return $r;
00120       foreach ($step_supplier as $supplier ) {
00121         $r.="<TR>";
00122         $e=sprintf('<A HREF="%s?p_action=fournisseur&sa=detail&f_id=%d&url=%s" title="Détail"> ',
00123                     $script,$supplier->id,$url);
00124 
00125         $r.="<TD> $e".$supplier->strAttribut(ATTR_DEF_QUICKCODE)."</A></TD>";
00126         $r.="<TD>".$supplier->strAttribut(ATTR_DEF_NAME)."</TD>";
00127         $r.="<TD>".$supplier->strAttribut(ATTR_DEF_ADRESS).
00128           " ".$supplier->strAttribut(ATTR_DEF_CP).
00129           " ".$supplier->strAttribut(ATTR_DEF_PAYS).
00130           "</TD>";
00131 
00132         $post=new poste($this->cn,$supplier->strAttribut(ATTR_DEF_ACCOUNT));
00133         /* Filter on the default year */
00134         $User=new cl_user($this->cn);
00135         $filter_year="  j_tech_per in (select p_id from parm_periode ".
00136                      "where p_exercice='".$User->getExercice()."')";
00137         $a=$post->GetSoldeDetail($filter_year);
00138 
00139 
00140         $r.=sprintf('<TD align="right"> %15.2f&euro;</TD>',$a['solde']);
00141 
00142 
00143         $r.=sprintf('<td><A HREF="%s?p_action=contact&qcode=%s&url=%s" title="Contact">Contact</A></td>',
00144                     $script,$supplier->strAttribut(ATTR_DEF_QUICKCODE),$url);
00145         $r.=sprintf('<td><A HREF="%s?p_action=suivi_courrier&sa=list&qcode=%s&url=%s" title="Action">Courrier</A></td> ',
00146                     $script,$supplier->strAttribut(ATTR_DEF_QUICKCODE) ,$url);
00147 
00148 
00149 
00150         $r.='<td><A HREF="commercial.php?p_action=depense&sa=list&p_periode=-1&qcode='.$supplier->strAttribut(ATTR_DEF_QUICKCODE).'&url='.$url.'" title="Historique Facture">Facture</A></td>';
00151 
00152         $r.='</TD>';
00153 
00154         $r.="</TR>";
00155 
00156       }
00157       $r.="</TABLE>";
00158       $r.=$bar;
00159       return $r;
00160     }
00161 
00162 }
00163 
00164 ?>