[ 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/includes/modules/propale/ -> mod_propale_marbre.php (source)

   1  <?php
   2  /* Copyright (C) 2005 Laurent Destailleur  <eldy@users.sourceforge.net>
   3   * Copyright (C) 2005 Regis Houssin        <regis.houssin@cap-networks.com>
   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   * or see http://www.gnu.org/
  19   *
  20   * $Id: mod_propale_marbre.php,v 1.5 2005/11/14 17:46:58 hregis Exp $
  21   * $Source: /cvsroot/dolibarr/dolibarr/htdocs/includes/modules/propale/mod_propale_marbre.php,v $
  22   */
  23  
  24  /**
  25           \file       htdocs/includes/modules/propale/mod_propale_marbre.php
  26          \ingroup    propale
  27          \brief      Fichier contenant la classe du modèle de numérotation de référence de propale Marbre
  28          \version    $Revision: 1.5 $
  29  */
  30  
  31  require_once(DOL_DOCUMENT_ROOT ."/includes/modules/propale/modules_propale.php");
  32  
  33  /**        \class      mod_propale_marbre
  34          \brief      Classe du modèle de numérotation de référence de propale Marbre
  35  */
  36  
  37  class mod_propale_marbre extends ModeleNumRefPropales
  38  {
  39      var $error='';
  40      
  41      /**     \brief      Renvoi la description du modele de numérotation
  42       *      \return     string      Texte descripif
  43       */
  44      function info()
  45      {
  46        return "Renvoie le numéro sous la forme PRyymm-nnnn où yy est l'année, mm le mois et nnnn un compteur séquentiel sans rupture et sans remise à 0";
  47      }
  48  
  49  
  50      /**     \brief      Renvoi un exemple de numérotation
  51       *      \return     string      Example
  52       */
  53      function getExample()
  54      {
  55          return "PR0501-0001";
  56      }
  57  
  58  
  59      /**     \brief      Test si les numéros déjà en vigueur dans la base ne provoquent pas de
  60       *                  de conflits qui empechera cette numérotation de fonctionner.
  61       *      \return     boolean     false si conflit, true si ok
  62       */
  63      function canBeActivated()
  64      {
  65          $pryymm='';
  66          
  67          $sql = "SELECT MAX(ref)";
  68          $sql.= " FROM ".MAIN_DB_PREFIX."propal";
  69          $resql=$db->query($sql);
  70          if ($resql)
  71          {
  72              $row = $db->fetch_row($resql);
  73              if ($row) $pryymm = substr($row[0],0,6);
  74          }
  75          if (! $pryymm || eregi('PR[0-9][0-9][0-9][0-9]',$pryymm))
  76          {
  77              return true;
  78          }
  79          else
  80          {
  81              $this->error='Une propal commençant par $pryymm existe en base et est incompatible avec cette numérotation. Supprimer la ou renommer la pour activer ce module.';
  82              return false;    
  83          }
  84      }
  85  
  86      /**     \brief      Renvoi prochaine valeur attribuée
  87       *      \return     string      Valeur
  88       */
  89      function getNextValue()
  90      {
  91          global $db;
  92  
  93          // D'abord on récupère la valeur max (réponse immédiate car champ indéxé)
  94          $pryymm='';
  95          $sql = "SELECT MAX(ref)";
  96          $sql.= " FROM ".MAIN_DB_PREFIX."propal";
  97          $resql=$db->query($sql);
  98          if ($resql)
  99          {
 100              $row = $db->fetch_row($resql);
 101              if ($row) $pryymm = substr($row[0],0,6);
 102          }
 103      
 104          // Si au moins un champ respectant le modèle a été trouvée
 105          if (eregi('PR[0-9][0-9][0-9][0-9]',$pryymm))
 106          {
 107              // Recherche rapide car restreint par un like sur champ indexé
 108              $posindice=8;
 109              $sql = "SELECT MAX(0+SUBSTRING(ref,$posindice))";
 110              $sql.= " FROM ".MAIN_DB_PREFIX."propal";
 111              $sql.= " WHERE ref like '$pryymm}%'";
 112              $resql=$db->query($sql);
 113              if ($resql)
 114              {
 115                  $row = $db->fetch_row($resql);
 116                  $max = $row[0];
 117              }
 118          }
 119          else
 120          {
 121              $max=0;
 122          }        
 123          $yymm = strftime("%y%m",time());
 124          $num = sprintf("%04s",$max+1);
 125          
 126          return  "PR$yymm-$num";
 127      }
 128  
 129  
 130      /**     \brief      Renvoie la référence de propale suivante non utilisée
 131       *      \param      objsoc      Objet société
 132       *      \return     string      Texte descripif
 133       */
 134      function propale_get_num($objsoc=0)
 135      {
 136          return $this->getNextValue();
 137      }
 138  }
 139  
 140  ?>


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