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