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

   1  <?php
   2  /* Copyright (C) 2002-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
   3   * Copyright (C) 2004-2005 Laurent Destailleur  <eldy@users.sourceforge.net>
   4   *
   5   * $Id: actioncomm.class.php,v 1.27 2005/09/09 21:25:21 eldy Exp $
   6   * $Source: /cvsroot/dolibarr/dolibarr/htdocs/actioncomm.class.php,v $
   7   *
   8   * This program is free software; you can redistribute it and/or modify
   9   * it under the terms of the GNU General Public License as published by
  10   * the Free Software Foundation; either version 2 of the License, or
  11   * (at your option) any later version.
  12   *
  13   * This program is distributed in the hope that it will be useful,
  14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16   * GNU General Public License for more details.
  17   *
  18   * You should have received a copy of the GNU General Public License
  19   * along with this program; if not, write to the Free Software
  20   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21   *
  22   */
  23  
  24  /**
  25          \file       htdocs/actioncomm.class.php
  26          \ingroup    commercial
  27          \brief      Fichier de la classe des actions commerciales
  28          \version    $Revision: 1.27 $
  29  */
  30  
  31  
  32  /**     \class      ActionComm
  33          \brief      Classe permettant la gestion des actions commerciales
  34  */
  35  
  36  class ActionComm
  37  {
  38      var $id;
  39      var $db;
  40      
  41      var $type_id;
  42      var $type_code;
  43      var $type;
  44      var $label;
  45      var $date;
  46      var $priority;
  47      var $user;
  48      var $author;
  49      var $societe;
  50      var $contact;
  51      var $note;
  52      var $percent;
  53      var $error;
  54      
  55      /**
  56       *      \brief      Constructeur
  57       *      \param      db      Handler d'accès base de donnée
  58       */
  59      function ActionComm($db)
  60      {
  61          $this->db = $db;
  62          $this->societe = new Societe($db);
  63          $this->author = new User($db);
  64          if (class_exists("Contact"))
  65          {
  66              $this->contact = new Contact($db);
  67          }
  68      }
  69  
  70      /**
  71       *    \brief      Ajout d'une action en base
  72       *    \param      author      auteur de la creation de l'action
  73       *    \return     int         id de l'action créée, < 0 si erreur
  74       */
  75      function add($author)
  76      {
  77          global $langs,$conf;
  78      
  79          dolibarr_syslog("ActionComm::add");
  80  
  81          if (! $this->percent)  $this->percent = 0;
  82          if (! $this->priority) $this->priority = 0;
  83  
  84          $sql = "INSERT INTO ".MAIN_DB_PREFIX."actioncomm";
  85          $sql.= "(datea,fk_action,fk_soc,note,fk_contact,fk_user_author,fk_user_action,label,percent,priority,";
  86          $sql.= "fk_facture,propalrowid)";
  87          $sql.= " VALUES (";
  88          $sql.= "'".$this->db->idate($this->date)."',";
  89          $sql.= "'".$this->type_id."', '".$this->societe->id."' ,'".addslashes($this->note)."',";
  90          $sql.= ($this->contact->id?$this->contact->id:"null").",";
  91          $sql.= "'$author->id', '".$this->user->id ."', '".addslashes($this->label)."','".$this->percent."','".$this->priority."',";
  92          $sql.= ($this->facid?$this->facid:"null").",";
  93          $sql.= ($this->propalrowid?$this->propalrowid:"null");
  94          $sql.= ");";
  95      
  96          if ($this->db->query($sql) )
  97          {
  98              $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."actioncomm");
  99      
 100             // Appel des triggers
 101              include_once (DOL_DOCUMENT_ROOT . "/interfaces.class.php");
 102              $interface=new Interfaces($this->db);
 103              $interface->run_triggers('ACTION_CREATE',$this,$author,$langs,$conf);
 104              // Fin appel triggers
 105      
 106              return $this->id;
 107          }
 108          else
 109          {
 110              dolibarr_print_error($this->db);
 111              return -1;
 112          }
 113      
 114      }
 115  
 116    /**
 117     *    \brief      Charge l'objet action depuis la base
 118     *    \param      id      id de l'action a récupérer
 119     */
 120    function fetch($id)
 121    {
 122      global $langs;
 123      
 124      $sql = "SELECT ".$this->db->pdate("a.datea")." as da, a.note, a.label, a.fk_action as type_id, c.code, c.libelle, fk_soc, fk_user_author, fk_contact, fk_facture, a.percent";
 125      $sql.= " FROM ".MAIN_DB_PREFIX."actioncomm as a, ".MAIN_DB_PREFIX."c_actioncomm as c";
 126      $sql.= " WHERE a.id=$id AND a.fk_action=c.id;";
 127      
 128      $resql=$this->db->query($sql);
 129      if ($resql)
 130      {
 131          if ($this->db->num_rows($resql))
 132          {
 133              $obj = $this->db->fetch_object($resql);
 134      
 135              $this->id = $id;
 136              $this->type_id = $type_id;
 137              $this->type_code = $obj->code;
 138              $transcode=$langs->trans("Action".$obj->code);
 139              $type_libelle=($transcode!="Action".$obj->code?$transcode:$obj->libelle);
 140              $this->type = $type_libelle;
 141              $this->label = $obj->label;
 142              $this->date = $obj->da;
 143              $this->note =$obj->note;
 144              $this->percent =$obj->percent;
 145              $this->societe->id = $obj->fk_soc;
 146              $this->author->id = $obj->fk_user_author;
 147              $this->contact->id = $obj->fk_contact;
 148              $this->fk_facture = $obj->fk_facture;
 149              if ($this->fk_facture)
 150              {
 151                  $this->objet_url = img_object($langs->trans("ShowBill"),'bill').' '.'<a href="'. DOL_URL_ROOT . '/compta/facture.php?facid='.$this->fk_facture.'">'.$langs->trans("Bill").'</a>';
 152                  $this->objet_url_type = 'facture';
 153              }
 154              $this->fk_propal = $obj->propalrowid;
 155              if ($this->fk_propal)
 156              {
 157                  $this->objet_url = img_object($langs->trans("ShowPropal"),'propal').' '.'<a href="'. DOL_URL_ROOT . '/propal/fiche.php?rowid='.$this->fk_facture.'">'.$langs->trans("Propal").'</a>';
 158                  $this->objet_url_type = 'propal';
 159              }
 160      
 161          }
 162          $this->db->free($resql);
 163      }
 164      else
 165      {
 166          dolibarr_print_error($this->db);
 167      }   
 168    }
 169  
 170    /**
 171     *    \brief      Supprime l'action de la base
 172     *    \param      id      id de l'action a effacer
 173     *    \return     int     1 en cas de succès
 174     */
 175    function delete($id)
 176      {      
 177          $sql = "DELETE FROM ".MAIN_DB_PREFIX."actioncomm WHERE id=$id;";
 178          
 179          if ($this->db->query($sql) )
 180          {
 181              return 1;
 182          }
 183      }
 184  
 185    /**
 186     *    \brief      Met a jour l'action en base
 187     *    \return     int     <0 si ko, >0 si ok
 188     */
 189      function update()
 190      {
 191          if ($this->percent > 100) $this->percent = 100;
 192      
 193          $sql = "UPDATE ".MAIN_DB_PREFIX."actioncomm ";
 194          $sql.= " SET percent='".$this->percent."'";
 195          if ($this->percent == 100) $sql .= ", datea = now()";
 196          if ($this->note) $sql .= ", note = '".addslashes($this->note)."'";
 197          $sql.= ", fk_contact =". $this->contact->id;
 198          $sql.= " WHERE id=$this->id;";
 199      
 200          if ($this->db->query($sql) )
 201          {
 202              return 1;
 203          }
 204      }
 205      
 206      
 207      /**
 208       *      \brief        Charge indicateurs this->nbtodo et this->nbtodolate de tableau de bord
 209       *      \param        user    Objet user
 210       *      \return       int     <0 si ko, >0 si ok
 211       */
 212      function load_board($user)
 213      {
 214          global $conf;
 215          
 216          $this->nbtodo=$this->nbtodolate=0;
 217          $sql = "SELECT a.id,".$this->db->pdate("a.datea")." as da";
 218          $sql.= " FROM ".MAIN_DB_PREFIX."actioncomm as a";
 219          $sql.= " WHERE a.percent < 100";
 220          if ($user->societe_id) $sql.=" AND fk_soc = ".$user->societe_id;
 221          $resql=$this->db->query($sql);
 222          if ($resql)
 223          {
 224              while ($obj=$this->db->fetch_object($resql))
 225              {
 226                  $this->nbtodo++;
 227                  if ($obj->da < (time() - $conf->actions->warning_delay)) $this->nbtodolate++;
 228              }
 229              return 1;
 230          }
 231          else 
 232          {
 233              $this->error=$this->db->error();
 234              return -1;
 235          }
 236      }
 237  
 238  }    
 239  ?>


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