[ Index ]
 

Code source de Dolibarr 2.0.1

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/htdocs/fourn/ -> fournisseur.class.php (source)

   1  <?php
   2  /* Copyright (C) 2004-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
   3   * 
   4   * This program is free software; you can redistribute it and/or modify
   5   * it under the terms of the GNU General Public License as published by
   6   * the Free Software Foundation; either version 2 of the License, or
   7   * (at your option) any later version.
   8   *
   9   * This program is distributed in the hope that it will be useful,
  10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12   * GNU General Public License for more details.
  13   *
  14   * You should have received a copy of the GNU General Public License
  15   * along with this program; if not, write to the Free Software
  16   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17   *
  18   * $Id: fournisseur.class.php,v 1.7 2005/11/03 16:23:12 marc_ocebo Exp $
  19   * $Source: /cvsroot/dolibarr/dolibarr/htdocs/fourn/fournisseur.class.php,v $
  20   *
  21   */
  22  
  23  /**
  24    \file       htdocs/fourn/fournisseur.class.php
  25    \ingroup    fournisseur,societe
  26    \brief      Fichier de la classe des fournisseurs
  27    \version    $Revision: 1.7 $
  28  */
  29  
  30  require_once (DOL_DOCUMENT_ROOT."/societe.class.php");
  31  require_once(DOL_DOCUMENT_ROOT."/fourn/fournisseur.commande.class.php");
  32  require_once(DOL_DOCUMENT_ROOT."/product.class.php");
  33  
  34  
  35  /**
  36    \class Fournisseur
  37    \brief Classe permettant la gestion des fournisseur
  38  */
  39  
  40  class Fournisseur extends Societe {
  41    var $db;
  42  
  43    /**
  44     *    \brief  Constructeur de la classe
  45     *    \param  DB     handler accès base de données
  46     *    \param  id     id societe (0 par defaut)
  47     */
  48       
  49    function Fournisseur($DB, $id=0)
  50    {
  51      global $config;
  52  
  53      $this->db = $DB;
  54      $this->id = $id;
  55      $this->client = 0;
  56      $this->fournisseur = 0;
  57      $this->effectif_id  = 0;
  58      $this->forme_juridique_code  = 0;
  59  
  60      return 0;
  61    }
  62  
  63  
  64    function nb_open_commande()
  65    {
  66      $sql = "SELECT rowid";
  67      $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as cf";
  68      $sql .= " WHERE cf.fk_soc = ".$this->id;
  69      
  70      $result = $this->db->query($sql) ;
  71      
  72      if ( $result )
  73        {
  74      $num = $this->db->num_rows();
  75      
  76      if ($num == 1)
  77        {
  78          $row = $this->db->fetch_row();
  79  
  80          $this->single_open_commande = $row[0];
  81        }
  82        }
  83      return $num;
  84    }
  85  
  86    function NbProduct()
  87    {
  88      $sql = "SELECT count(*)";
  89      $sql .= " FROM ".MAIN_DB_PREFIX."product_fournisseur";
  90      $sql .= " WHERE fk_soc = ".$this->id;
  91      
  92      $resql = $this->db->query($sql) ;
  93      
  94      if ( $resql )
  95        {
  96      $row = $this->db->fetch_row($resql);        
  97      return $row[0];
  98        }
  99      else
 100        {
 101      return -1;
 102        }
 103  
 104    }
 105  
 106  
 107      /**
 108       *      \brief      Créé la commande au statut brouillon
 109       *      \param      user        Utilisateur qui crée
 110       *      \return     int         <0 si ko, id de la commande créée si ok
 111       */
 112      function create_commande($user)
 113      {
 114          dolibarr_syslog("Fournisseur::Create_Commande");
 115          $comm = new CommandeFournisseur($this->db);
 116          $comm->soc_id = $this->id;
 117      
 118          if ($comm->create($user) > 0)
 119          {
 120              dolibarr_syslog("Fournisseur::Create_Commande : Success");
 121              $this->single_open_commande = $comm->id;
 122      
 123              return $comm->id;
 124          }
 125          else
 126          {
 127              dolibarr_syslog("Fournisseur::Create_Commande : Failed");
 128              return -1;
 129          }
 130      }
 131  
 132  
 133    function ProductCommande($user, $product_id)
 134    {
 135      include_once(DOL_DOCUMENT_ROOT."/fourn/fournisseur.commande.class.php");
 136      include_once(DOL_DOCUMENT_ROOT."/product.class.php");
 137  
 138      $commf = new CommandeFournisseur($this->db);
 139      
 140      $nbc = $this->nb_open_commande();
 141      
 142      dolibarr_syslog("Fournisseur::ProductCommande : nbc = ".$nbc);
 143      
 144      if ($nbc == 0)
 145        {
 146      if ( $this->create_commande($user) == 0 )
 147        {
 148          $idc = $this->single_open_commande;
 149        }
 150        }
 151      elseif ($nbc == 1)
 152        {
 153      
 154      $idc = $this->single_open_commande;
 155        }
 156      
 157      if ($idc > 0)
 158        {
 159      $prod = new Product($this->db);
 160      $prod->fetch($product_id);
 161      $prod->fetch_fourn_data($this->id);
 162  
 163      $commf->fetch($idc);
 164      $commf->addline("Toto",120,1,$prod->tva, $prod->id, 0, $prod->ref_fourn);
 165        }
 166    }
 167    
 168      /**
 169       *      \brief      Charge indicateurs this->nb de tableau de bord
 170       *      \return     int         <0 si ko, >0 si ok
 171       */
 172      function load_state_board()
 173      {
 174          global $conf;
 175          
 176          $this->nb=array();
 177  
 178          $sql = "SELECT count(s.idp) as nb";
 179          $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
 180          $sql.= " WHERE s.fournisseur = 1";
 181          $resql=$this->db->query($sql);
 182          if ($resql)
 183          {
 184              while ($obj=$this->db->fetch_object($resql))
 185              {
 186                  $this->nb["suppliers"]=$obj->nb;
 187              }
 188              return 1;
 189          }
 190          else 
 191          {
 192              dolibarr_print_error($this->db);
 193              $this->error=$this->db->error();
 194              return -1;
 195          }
 196  
 197      }
 198  
 199  }
 200  
 201  ?>


Généré le : Mon Nov 26 12:29:37 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics