[ 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.commande.class.php (source)

   1  <?php
   2  /* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
   3   * Copyright (C) 2004-2005 Laurent Destailleur  <eldy@users.sourceforge.net>
   4   *
   5   * This program is free software; you can redistribute it and/or modify
   6   * it under the terms of the GNU General Public License as published by
   7   * the Free Software Foundation; either version 2 of the License, or
   8   * (at your option) any later version.
   9   *
  10   * This program is distributed in the hope that it will be useful,
  11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13   * GNU General Public License for more details.
  14   *
  15   * You should have received a copy of the GNU General Public License
  16   * along with this program; if not, write to the Free Software
  17   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18   *
  19   * $Id: fournisseur.commande.class.php,v 1.7.2.2 2005/12/26 16:35:01 hregis Exp $
  20   * $Source: /cvsroot/dolibarr/dolibarr/htdocs/fourn/fournisseur.commande.class.php,v $
  21   */
  22  
  23  /**       
  24          \file       htdocs/fourn/fournisseur.commande.class.php
  25          \ingroup    fournisseur,commande
  26          \brief      Fichier des classes des commandes fournisseurs
  27          \version    $Revision: 1.7.2.2 $
  28  */
  29  
  30  require_once(DOL_DOCUMENT_ROOT."/product.class.php");
  31  
  32  
  33  /**      
  34          \class      CommandeFournisseur
  35          \brief      Classe de gestion de commande fournisseur
  36  */
  37  
  38  class CommandeFournisseur
  39  {
  40    var $db ;
  41    var $id ;
  42    var $brouillon;
  43  
  44    /**   \brief      Constructeur
  45     *    \param      DB      Handler d'accès aux bases de données
  46     */
  47    function CommandeFournisseur($DB)
  48      {
  49        $this->db = $DB;
  50  
  51        $this->statuts[-1] = "Annulée";
  52        $this->statuts[0] = "Brouillon";
  53        $this->statuts[1] = "Validée";
  54        $this->statuts[2] = "Approuvée";
  55        $this->statuts[3] = "Commandée";
  56        $this->statuts[4] = "Reçu partiellement";
  57        $this->statuts[5] = "Clotûrée";
  58        $this->statuts[6] = "Annulée";
  59        $this->statuts[9] = "Refusée";
  60  
  61        $this->products = array();
  62      }
  63  
  64  
  65      /**
  66       * Lit une commande
  67       */
  68      function fetch ($id)
  69      {
  70          $sql = "SELECT c.rowid, c.date_creation, c.ref, c.fk_soc, c.fk_user_author, c.fk_statut, c.amount_ht, c.total_ht, c.total_ttc, c.tva";
  71          $sql .= ", ".$this->db->pdate("c.date_commande")." as date_commande, c.fk_projet, c.remise_percent, c.source, c.fk_methode_commande ";
  72          $sql .= ", c.note";
  73      
  74          $sql .= ", cm.libelle as methode_commande";
  75      
  76          $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as c";
  77          $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_methode_commande_fournisseur as cm ON cm.rowid = c.fk_methode_commande";
  78      
  79          $sql .= " WHERE c.rowid = ".$id;
  80  
  81          $resql = $this->db->query($sql) ;
  82          if ($resql)
  83          {
  84              $obj = $this->db->fetch_object($resql);
  85      
  86              $this->id                  = $obj->rowid;
  87              $this->ref                 = $obj->ref;
  88              $this->soc_id              = $obj->fk_soc;
  89              $this->fourn_id            = $obj->fk_soc;
  90              $this->statut              = $obj->fk_statut;
  91              $this->user_author_id      = $obj->fk_user_author;
  92              $this->total_ht            = $obj->total_ht;
  93              $this->total_tva           = $obj->tva;
  94              $this->total_ttc           = $obj->total_ttc;
  95              $this->date_commande       = $obj->date_commande; // date à laquelle la commande a été transmise
  96              $this->remise_percent      = $obj->remise_percent;
  97              $this->methode_commande_id = $obj->fk_methode_commande;
  98              $this->methode_commande = $obj->methode_commande;
  99      
 100              $this->source              = $obj->source;
 101              $this->facturee            = $obj->facture;
 102              $this->projet_id           = $obj->fk_projet;
 103              $this->note                = stripslashes($obj->note);
 104      
 105              $this->db->free($resql);
 106      
 107              if ($this->statut == 0)
 108              {
 109                  $this->brouillon = 1;
 110              }
 111      
 112              $result = 0;
 113      
 114          }
 115          else
 116          {
 117              dolibarr_syslog("CommandeFournisseur::Fetch Error $sql");
 118              dolibarr_syslog("CommandeFournisseur::Fetch Error ".$this->db->error());
 119              $result = -1;
 120          }
 121      
 122          return $result ;
 123      
 124      }
 125  
 126      /**
 127       *      \brief      Insère ligne de log
 128       *      \param      user        Utilisateur qui modifie la commande
 129       *      \param      statut      Statut de la commande
 130       *      \param      datelog     Date de modification
 131       *      \return     int         <0 si ko, >0 si ok
 132       */
 133      function log($user, $statut, $datelog)
 134      {
 135          $sql = "INSERT INTO ".MAIN_DB_PREFIX."commande_fournisseur_log (datelog, fk_commande, fk_statut, fk_user)";
 136          $sql.= " VALUES (".$this->db->idate($datelog).",".$this->id.", $statut, ".$user->id.")";
 137          
 138          if ( $this->db->query($sql) )
 139          {
 140              return 1;
 141          }
 142          else
 143          {
 144              return -1;
 145          }
 146      }
 147  
 148    /**
 149     * Valide la commande
 150     *
 151     *
 152     */
 153    function valid($user)
 154      {
 155        dolibarr_syslog("CommandeFournisseur::Valid");
 156        $result = 0;
 157        if ($user->rights->fournisseur->commande->valider)
 158      {
 159        $ref = 'CF'.substr('000000'.$this->id, -6);
 160  
 161        $sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur SET ref='$ref', fk_statut = 1";
 162        $sql .= " WHERE rowid = ".$this->id." AND fk_statut = 0 ;";
 163        
 164        if ($this->db->query($sql) )
 165          {
 166            $result = 0;
 167            $this->log($user, 1, time());
 168  
 169            $this->ref = $ref;
 170  
 171            $this->_NotifyApprobator($user);
 172  
 173          }
 174        else
 175          {
 176            dolibarr_syslog("CommandeFournisseur::Valid Error -1");
 177            $result = -1;
 178          }      
 179      }
 180        else
 181      {
 182        dolibarr_syslog("CommandeFournisseur::Valid Not Authorized");
 183      }
 184        return $result ;
 185      }
 186    /**
 187     * Annule la commande
 188     * L'annulation se fait après la validation
 189     *
 190     */
 191    function Cancel($user)
 192      {
 193        //dolibarr_syslog("CommandeFournisseur::Cancel");
 194        $result = 0;
 195        if ($user->rights->fournisseur->commande->annuler)
 196      {
 197  
 198        $statut = 6;
 199  
 200        $sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur SET fk_statut = ".$statut;
 201        $sql .= " WHERE rowid = ".$this->id." AND fk_statut = 1 ;";
 202        
 203        if ($this->db->query($sql) )
 204          {
 205            $result = 0;
 206            $this->log($user, $statut, time());
 207          }
 208        else
 209          {
 210            dolibarr_syslog("CommandeFournisseur::Cancel Error -1");
 211            $result = -1;
 212          }      
 213      }
 214        else
 215      {
 216        dolibarr_syslog("CommandeFournisseur::Cancel Not Authorized");
 217      }
 218        return $result ;
 219      }
 220    /*
 221     *
 222     *
 223     */
 224    function _NotifyApprobator($user)
 225    {
 226      require_once (DOL_DOCUMENT_ROOT."/lib/CMailFile.class.php");
 227      
 228      $this->ReadApprobators();
 229      
 230      if (sizeof($this->approbs) > 0)
 231        {
 232  
 233      $this->_details_text();
 234  
 235      $from = $user->email;
 236      $subject = "Nouvelle commande en attente d'approbation réf : ".$this->ref;
 237  
 238      $message = "Bonjour,\n\n";
 239      $message .= "La commande ".$this->ref." validée par $user->fullname, est en attente de votre approbation.\n\n";
 240  
 241  
 242      $message .= $this->details_text;
 243  
 244      if (sizeof($this->approbs) > 1)
 245        {
 246          $message .= "\nCette demande d'approbation a été envoyée à :\n";
 247          
 248          foreach($this->approbs as $approb)
 249            {
 250          if (strlen($approb[2]))
 251            {
 252              $message .= "- $approb[0] $approb[1] <$approb[2]>\n";
 253            }
 254            }
 255        }
 256  
 257      $message .= "\nCordialement,\n\n";
 258      $message .="--\n(message automatique envoyé par Dolibarr)";        
 259      
 260      foreach($this->approbs as $approb)
 261        {
 262  
 263          $sendto = $approb[2];
 264  
 265          $mailfile = new CMailFile($subject,
 266                       $sendto,
 267                       $from,
 268                       $message, array(), array(), array());
 269          if ( $mailfile->sendfile() )
 270            {
 271          
 272            }
 273        }
 274        }
 275    }
 276    /**
 277     * Approuve une commande
 278     *
 279     *
 280     */
 281    function approve($user)
 282      {
 283        dolibarr_syslog("CommandeFournisseur::Approve");
 284        $result = 0;
 285        if ($user->rights->fournisseur->commande->approuver)
 286      {
 287        $sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur SET fk_statut = 2";
 288        $sql .= " WHERE rowid = ".$this->id." AND fk_statut = 1 ;";
 289        
 290        if ($this->db->query($sql) )
 291          {
 292            $result = 0;
 293            $this->log($user, 2, time());
 294  
 295            $subject = "Votre commande ".$this->ref." a été approuvée";
 296            $message = "Bonjour,\n\n";
 297            $message .= "Votre commande ".$this->ref." a été approuvée, par $user->fullname";
 298            $message .= "\n\nCordialement,\n\n";
 299  
 300            $this->_NotifyCreator($user, $subject, $message);
 301  
 302          }
 303        else
 304          {
 305            dolibarr_syslog("CommandeFournisseur::Approve Error -1");
 306            $result = -1;
 307          }      
 308      }
 309        else
 310      {
 311        dolibarr_syslog("CommandeFournisseur::Approve Not Authorized");
 312      }
 313        return $result ;
 314      }
 315    /**
 316     * Refuse une commande
 317     *
 318     *
 319     */
 320    function refuse($user)
 321      {
 322        dolibarr_syslog("CommandeFournisseur::Refuse");
 323        $result = 0;
 324        if ($user->rights->fournisseur->commande->approuver)
 325      {
 326        $sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur SET fk_statut = 9";
 327        $sql .= " WHERE rowid = ".$this->id;
 328        
 329        if ($this->db->query($sql) )
 330          {
 331            $result = 0;
 332            $this->log($user, 9, time());
 333  
 334            $subject = "Votre commande ".$this->ref." a été refusée";
 335            $message = "Votre commande ".$this->ref." a été refusée, par $user->fullname";
 336  
 337            $this->_NotifyCreator($user, $subject, $message);
 338          }
 339        else
 340          {
 341            dolibarr_syslog("CommandeFournisseur::Refuse Error -1");
 342            $result = -1;
 343          }      
 344      }
 345        else
 346      {
 347        dolibarr_syslog("CommandeFournisseur::Refuse Not Authorized");
 348      }
 349        return $result ;
 350      }
 351    /*
 352     *
 353     *
 354     */
 355    function _NotifyCreator($user, $subject, $message)
 356    {
 357      require_once (DOL_DOCUMENT_ROOT."/lib/CMailFile.class.php");
 358      
 359      $cc = new user($this->db, $this->user_author_id);
 360      $cc->fetch();
 361      
 362      $sendto = $cc->email;
 363      $from = $user->email;
 364  
 365      $mailfile = new CMailFile($subject,
 366                   $sendto,
 367                   $from,
 368                   $message, array(), array(), array());
 369      if ( $mailfile->sendfile() )
 370        {
 371      return 0;
 372        }
 373    }
 374  
 375    /**
 376     * Envoie la commande au fournisseur
 377     *
 378     *
 379     */
 380    function commande($user, $date, $methode)
 381      {
 382        dolibarr_syslog("CommandeFournisseur::Commande");
 383        $result = 0;
 384        if ($user->rights->fournisseur->commande->commander)
 385      {
 386        $sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur SET fk_statut = 3, fk_methode_commande=".$methode.",date_commande=".$this->db->idate("$date");
 387        $sql .= " WHERE rowid = ".$this->id." AND fk_statut = 2 ;";
 388        
 389        if ($this->db->query($sql) )
 390          {
 391            $result = 0;
 392            $this->log($user, 3, $date);
 393          }
 394        else
 395          {
 396            dolibarr_syslog("CommandeFournisseur::Commande Error -1");
 397            $result = -1;
 398          }      
 399      }
 400        else
 401      {
 402        dolibarr_syslog("CommandeFournisseur::Commande Not Authorized");
 403      }
 404        return $result ;
 405      }
 406  
 407      /**
 408       *      \brief      Créé la commande au statut brouillon
 409       *      \param      user        Utilisateur qui crée
 410       *      \return     int         <0 si ko, >0 si ok
 411       */
 412      function create($user)
 413      {
 414          dolibarr_syslog("CommandeFournisseur::Create soc id=".$this->soc_id);
 415  
 416          $this->db->begin();
 417          
 418          /* On positionne en mode brouillon la commande */
 419          $this->brouillon = 1;
 420      
 421          $sql = "INSERT INTO ".MAIN_DB_PREFIX."commande_fournisseur (fk_soc, date_creation, fk_user_author, fk_statut) ";
 422          $sql .= " VALUES (".$this->soc_id.", now(), ".$user->id.",0)";
 423      
 424          if ( $this->db->query($sql) )
 425          {
 426              $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."commande_fournisseur");
 427      
 428              $sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur";
 429              $sql.= " SET ref='(PROV".$this->id.")'";
 430              $sql.= " WHERE rowid=".$this->id;
 431              if ($this->db->query($sql))
 432              {
 433                  // On logue creation pour historique   
 434                  $this->log($user, 0, time());
 435                  
 436                  dolibarr_syslog("CommandeFournisseur::Create : Success");
 437                  $this->db->commit();
 438                  return 1;
 439              }
 440              else
 441              {
 442                  $this->error=$this->db->error()." - ".$sql;
 443                  dolibarr_syslog("CommandeFournisseur::Create: Failed -2 - ".$this->error);
 444                  $this->db->rollback();
 445                  return -2;
 446              }
 447          }
 448          else
 449          {
 450              $this->error=$this->db->error()." - ".$sql;
 451              dolibarr_syslog("CommandeFournisseur::Create: Failed -1 - ".$this->error);
 452              $this->db->rollback();
 453              return -1;
 454          }
 455      }
 456  
 457      /**
 458       *      \brief      Ajoute une ligne de commande
 459       *      \param      desc            Description
 460       *      \param      pu              Prix unitaire
 461       *      \param      qty             Quantité
 462       *      \param      txtva           Taux tva
 463       *      \param      fk_product      Id produit
 464       *      \param      remise_percent  Remise
 465       *      \param      int             <0 si ko, >0 si ok
 466       */
 467      function addline($desc, $pu, $qty, $txtva, $fk_product=0, $remise_percent=0)
 468      {
 469          global $langs;
 470          
 471          $qty  = price2num($qty);
 472          $pu   = price2num($pu);
 473          $desc = trim($desc);
 474          $remise_percent = price2num($remise_percent);
 475          
 476          dolibarr_syslog("Fournisseur_Commande.class.php::addline $desc, $pu, $qty, $txtva, $fk_product, $remise_percent");
 477  
 478          if ($qty < 1 && ! $fk_product)
 479          {
 480              $this->error=$langs->trans("ErrorFieldRequired",$langs->trans("Product"));
 481              return -1;
 482          }
 483      
 484          if ($this->brouillon)
 485          {
 486              $this->db->begin();
 487              
 488              if ($fk_product > 0)
 489              {
 490                  $prod = new Product($this->db, $fk_product);
 491                  if ($prod->fetch($fk_product) > 0)
 492                  {
 493                      $result=$prod->get_buyprice($this->fourn_id,$qty);
 494                      if ($result)
 495                      {
 496                          $desc  = $prod->libelle;
 497                          $txtva = $prod->tva_tx;
 498                          $pu    = $prod->fourn_pu;
 499                          $ref   = $prod->ref;
 500                      }
 501                      else
 502                      {
 503                          $this->error="Aucun tarif trouvé pour cette quantité. Quantité saisie insuffisante ?";
 504                          $this->db->rollback();
 505                          dolibarr_syslog($this->error);
 506                          return -1;
 507                      }
 508                  }
 509              }
 510      
 511              $remise = 0;
 512              $price = price2num($pu);
 513              $subprice = $price;
 514              if ($remise_percent > 0)
 515              {
 516                  $remise = round(($pu * $remise_percent / 100), 2);
 517                  $price = $pu - $remise;
 518              }
 519      
 520              $sql = "INSERT INTO ".MAIN_DB_PREFIX."commande_fournisseurdet (fk_commande,label,description,fk_product, price, qty, tva_tx, remise_percent, subprice, remise, ref)";
 521              $sql .= " VALUES ($this->id, '" . addslashes($desc) . "','" . addslashes($desc) . "',".$fk_product.",".price2num($price).", '$qty', $txtva, $remise_percent,'".price2num($subprice)."','".price2num($remise)."','".$ref."') ;";
 522              if ( $this->db->query( $sql) )
 523              {
 524                  $this->update_price();
 525  
 526                  $this->db->commit();
 527                  return 1;
 528              }
 529              else
 530              {
 531                  $this->db->rollback();
 532                  return -1;
 533              }
 534          }
 535      }
 536  
 537    /**
 538     * Ajoute un produit
 539     *
 540     */
 541    function insert_product_generic($p_desc, $p_price, $p_qty, $p_tva_tx=19.6, $p_product_id=0, $remise_percent=0)
 542      {
 543        if ($this->statut == 0)
 544      {
 545        if (strlen(trim($p_qty)) == 0)
 546          {
 547            $p_qty = 1;
 548          }
 549  
 550        $p_price = ereg_replace(",",".",$p_price);
 551  
 552        $price = $p_price;
 553        $subprice = $p_price;
 554        if ($remise_percent > 0)
 555          {
 556            $remise = round(($p_price * $remise_percent / 100), 2);
 557            $price = $p_price - $remise;
 558          }
 559  
 560        $sql = "INSERT INTO ".MAIN_DB_PREFIX."commandedet (fk_commande, fk_product, qty, price, tva_tx, description, remise_percent, subprice) VALUES ";
 561        $sql .= " ('".$this->id."', '$p_product_id','". $p_qty."','". $price."','".$p_tva_tx."','".addslashes($p_desc)."','$remise_percent', '$subprice') ; ";
 562        
 563        if ($this->db->query($sql) )
 564          {
 565            
 566            if ($this->update_price() > 0)
 567          {          
 568            return 1;
 569          }
 570            else
 571          {
 572            return -1;
 573          }
 574          }
 575        else
 576          {
 577            dolibarr_print_error($this->db);
 578            return -2;
 579          }
 580      }
 581      }
 582    /** 
 583     * Supprime une ligne de la commande
 584     *
 585     */
 586    function delete_line($idligne)
 587      {
 588        if ($this->statut == 0)
 589      {
 590        $sql = "DELETE FROM ".MAIN_DB_PREFIX."commande_fournisseurdet WHERE rowid = ".$idligne;
 591        
 592        if ($this->db->query($sql) )
 593          {
 594            $this->update_price();
 595            
 596            return 0;
 597          }
 598        else
 599          {
 600            return -1;
 601          }
 602      }
 603      }
 604    /**
 605     * Mettre à jour le prix
 606     *
 607     */
 608    function update_price()
 609      {
 610        include_once  DOL_DOCUMENT_ROOT . "/lib/price.lib.php";
 611  
 612        /*
 613         *  Liste des produits a ajouter
 614         */
 615        $sql = "SELECT price, qty, tva_tx ";
 616        $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet ";
 617        $sql .= " WHERE fk_commande = $this->id";
 618  
 619        if ( $this->db->query($sql) )
 620      {
 621        $num = $this->db->num_rows();
 622        $i = 0;
 623        
 624        while ($i < $num)
 625          {
 626            $obj = $this->db->fetch_object();
 627            $products[$i][0] = $obj->price;
 628            $products[$i][1] = $obj->qty;
 629            $products[$i][2] = $obj->tva_tx;
 630            $i++;
 631          }
 632      }
 633        $calculs = calcul_price($products, $this->remise_percent);
 634  
 635        $totalht = $calculs[0];
 636        $totaltva = $calculs[1];
 637        $totalttc = $calculs[2];
 638        $total_remise = $calculs[3];
 639  
 640        $this->remise         = $total_remise;
 641        $this->total_ht       = $totalht;
 642        $this->total_tva      = $totaltva;
 643        $this->total_ttc      = $totalttc;
 644        /*
 645         *
 646         */
 647        $sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur set";
 648        $sql .= "  amount_ht ='".ereg_replace(",",".",$totalht)."'";
 649        $sql .= ", total_ht  ='".ereg_replace(",",".",$totalht)."'";
 650        $sql .= ", tva       ='".ereg_replace(",",".",$totaltva)."'";
 651        $sql .= ", total_ttc ='".ereg_replace(",",".",$totalttc)."'";
 652        $sql .= ", remise    ='".ereg_replace(",",".",$total_remise)."'";
 653        $sql .= " WHERE rowid = $this->id";
 654        if ( $this->db->query($sql) )
 655      {
 656        return 1;
 657      }
 658        else
 659      {
 660        print "Erreur mise à jour du prix<p>".$sql;
 661        return -1;
 662      }
 663      }
 664  
 665    /**
 666     * Supprime la commande
 667     *
 668     */
 669    function delete()
 670    {
 671      $err = 0;
 672  
 673      $this->db->begin();
 674  
 675      $sql = "DELETE FROM ".MAIN_DB_PREFIX."commande_fournisseurdet WHERE fk_commande =". $this->id ;
 676      if (! $this->db->query($sql) ) 
 677        {
 678      $err++;
 679        }
 680  
 681      $sql = "DELETE FROM ".MAIN_DB_PREFIX."commande_fournisseur WHERE rowid =".$this->id;
 682      if (! $this->db->query($sql) ) 
 683        {
 684      $err++;
 685        }
 686  
 687      if ($err == 0)
 688        {
 689      $this->db->commit();
 690      return 1;
 691        }
 692      else
 693        {
 694      $this->db->rollback();
 695      return -1;
 696        }
 697    }
 698    /**
 699     *
 700     *
 701     *
 702     */
 703    function generate_pdf()
 704    {
 705      // Récupération des info sur le fournisseur
 706      $this->fournisseur = new Societe($this->db);
 707      $this->fournisseur->fetch($this->fourn_id);
 708  
 709      $name = 'muscadet';
 710      require_once DOL_DOCUMENT_ROOT.'/fourn/commande/modules/pdf/pdf_fourncomm_'.$name.'.modules.php';
 711  
 712      $var = 'pdf_fourncomm_'.$name;
 713  
 714      $opdf = new $var();
 715      $opdf->write_pdf_file($this);
 716    }
 717  
 718    /**
 719     *
 720     *
 721     */
 722    function get_methodes_commande()
 723    {
 724      $sql = "SELECT rowid, libelle FROM ".MAIN_DB_PREFIX."c_methode_commande_fournisseur";
 725      $sql .= " WHERE active = 1";
 726  
 727      if ($this->db->query($sql))
 728        {
 729      $i = 0;
 730      $num = $this->db->num_rows();
 731      $this->methodes_commande = array();
 732      while ($i < $num)
 733        {
 734          $row = $this->db->fetch_row();
 735  
 736          $this->methodes_commande[$row[0]] = $row[1];
 737  
 738          $i++;
 739        }
 740      return 0;
 741        }
 742      else
 743        {
 744      return -1;
 745        }
 746    }
 747  
 748    /**
 749     * Livraison
 750     *
 751     *
 752     */
 753    function Livraison($user, $date, $type)
 754      {
 755        dolibarr_syslog("CommandeFournisseur::Livraison");
 756        $result = 0;
 757        if ($user->rights->fournisseur->commande->receptionner && $date < time())
 758      {
 759        if ($type == 'par')
 760          {
 761            $statut = 4;
 762          }
 763  
 764        if ($type == 'tot')
 765          {
 766            $statut = 5;
 767          }
 768  
 769        if ($statut == 4 or $statut == 5)
 770          {
 771            $sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur";
 772            $sql .= " SET fk_statut = ".$statut;
 773            $sql .= " WHERE rowid = ".$this->id;
 774            $sql .= " AND (fk_statut = 3 OR fk_statut = 4) ;";
 775            
 776            if ($this->db->query($sql) )
 777          {
 778            $result = 0;
 779            $this->log($user, $statut, $date);
 780          }
 781            else
 782          {
 783            dolibarr_syslog("CommandeFournisseur::Livraison Error -1");
 784            $result = -1;
 785          }      
 786          }
 787        else
 788          {
 789            dolibarr_syslog("CommandeFournisseur::Livraison Error -2");
 790            $result = -2;
 791          }    
 792      }
 793        else
 794      {
 795        dolibarr_syslog("CommandeFournisseur::Livraison Not Authorized");
 796      }
 797        return $result ;
 798      }
 799  
 800    /**
 801     *
 802     *
 803     *
 804     */
 805    function UpdateNote($user, $note)
 806      {
 807        dolibarr_syslog("CommandeFournisseur::UpdateNote");
 808        $result = 0;
 809  
 810        $sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur";
 811  
 812        $sql .= " SET note  ='".trim($note) ."'";
 813  
 814        $sql .= " WHERE rowid = ".$this->id;
 815        
 816        if ($this->db->query($sql) )
 817      {
 818        $result = 0;
 819      }
 820        else
 821      {
 822        dolibarr_syslog("CommandeFournisseur::UpdateNote Error -1");
 823        $result = -1;
 824      }      
 825  
 826        return $result ;
 827      }
 828  
 829    /*
 830     *
 831     *
 832     *
 833     */
 834    function ReadApprobators()
 835    {
 836      $this->approbs = array();
 837  
 838      $sql = "SELECT u.name, u.firstname, u.email";
 839      $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
 840      $sql .= " , ".MAIN_DB_PREFIX."user_rights as ur";
 841      $sql .= " WHERE u.rowid = ur.fk_user";
 842      $sql .= " AND ur.fk_id = 184";
 843      
 844      $resql = $this->db->query($sql);
 845  
 846      if ($resql)
 847        {
 848      $num = $this->db->num_rows($resql);
 849      $i = 0;
 850      
 851      while ($i < $num)
 852        {
 853          $row = $this->db->fetch_row($resql);        
 854          $this->approbs[$i] = $row;
 855          $i++;
 856        }
 857  
 858      $this->db->free($resql);
 859        }
 860      else 
 861        {
 862      dolibarr_syslog("ReadApprobators Erreur");
 863        }    
 864    }
 865    /*
 866     *
 867     *
 868     */
 869    function _details_text()
 870    {
 871      $blank = "                                                                                                                            ";
 872      $this->details_text = substr("Produit".$blank,0,50);
 873      $this->details_text .= substr("Qty".$blank,0,8);
 874      $this->details_text .= substr("Prix".$blank,0,8);
 875      $this->details_text .= "\n";
 876      $this->details_text .= substr("-----------------------------------------------------------------------------------------------------------------------",0,66);
 877      $this->details_text .= "\n";
 878  
 879      $sql = "SELECT l.ref, l.fk_product, l.description, l.price, l.qty";
 880      $sql .= ", l.rowid, l.tva_tx, l.remise_percent, l.subprice";
 881      $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as l ";
 882      $sql .= " WHERE l.fk_commande = ".$this->id." ORDER BY l.rowid";
 883      
 884      $resql = $this->db->query($sql);
 885      if ($resql)
 886        {
 887      $num_lignes = $this->db->num_rows($resql);
 888      $i = 0;
 889      
 890      while ($i < $num_lignes)
 891        {
 892          $objp = $this->db->fetch_object();
 893  
 894          $this->details_text .=  "-".substr(stripslashes($objp->description).$blank, 0, 50);
 895          $this->details_text .= substr($objp->qty.$blank, 0, 7);
 896          $this->details_text .= substr($blank.price($objp->subprice),-8);
 897          $this->details_text .= "\n";
 898          $i++;
 899          
 900        }
 901      $this->details_text .= substr("-----------------------------------------------------------------------------------------------------------------------",0,66);
 902      $this->details_text .= "\n";
 903      $this->details_text .= substr($blank."Total HT : ".price($this->total_ht), -66);
 904      $this->details_text .= "\n";
 905      $this->details_text .= substr($blank."Total TTC : ".price($this->total_ttc), -66);
 906      $this->details_text .= "\n";
 907      
 908      $this->db->free();
 909        } 
 910      else
 911        {
 912      print $this->db->error();
 913        }
 914    }
 915  }
 916  ?>


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