2
0
forked from Wavyzz/dolibarr

Add tag {cccc0000} in generic numering modules (from a work of Raphael)

This commit is contained in:
Laurent Destailleur
2008-06-20 21:10:24 +00:00
parent 2af507d7a3
commit fb982b6fd3
11 changed files with 384 additions and 649 deletions

View File

@@ -15,95 +15,95 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* or see http://www.gnu.org/
*
* $Id$
* $Source$
*
*/
/**
\file htdocs/includes/modules/commande/mod_commande_opale.php
\ingroup commande
\brief Fichier contenant la classe du mod<6F>le de num<75>rotation de r<>f<EFBFBD>rence de commande Opale
\version $Revision$
*/
/**
\file htdocs/includes/modules/commande/mod_commande_opale.php
\ingroup commande
\brief Fichier contenant la classe du mod<6F>le de num<75>rotation de r<>f<EFBFBD>rence de commande Opale
\version $Id$
*/
include_once("modules_commande.php");
/**
\class mod_commande_opale
\brief Classe du mod<6F>le de num<75>rotation de r<>f<EFBFBD>rence de commande Opale
*/
\class mod_commande_opale
\brief Classe du mod<6F>le de num<75>rotation de r<>f<EFBFBD>rence de commande Opale
*/
class mod_commande_opale extends ModeleNumRefCommandes
{
var $version='dolibarr'; // 'development', 'experimental', 'dolibarr'
var $error = '';
var $nom = 'Opale';
/** \brief Constructeur
*/
function mod_commande_opale()
{
$this->nom = "Opale";
}
/** \brief Constructeur
*/
function mod_commande_opale()
{
$this->nom = "Opale";
}
/** \brief Renvoi la description du modele de num<75>rotation
* \return string Texte descripif
*/
function info()
{
return "Renvoie le num<75>ro sous la forme num<75>rique COMhexa, o<> hexa repr<70>sente un incr<63>ment global cod<6F> en h<>xad<61>cimal. (COM-000-001 <20> COM-FFF-FFF)";
}
/** \brief Renvoi un exemple de num<75>rotation
* \return string Example
*/
function getExample()
{
return "COM-000-001";
}
/** \brief Renvoi la description du modele de num<75>rotation
* \return string Texte descripif
*/
function info()
{
return "Renvoie le num<75>ro sous la forme num<75>rique COMhexa, o<> hexa repr<70>sente un incr<63>ment global cod<6F> en h<>xad<61>cimal. (COM-000-001 <20> COM-FFF-FFF)";
}
/** \brief Renvoi prochaine valeur attribu<62>e
* \return string Valeur
*/
function getNextValue()
{
global $db;
/** \brief Renvoi un exemple de num<75>rotation
* \return string Example
*/
function getExample()
{
return "COM-000-001";
}
// D'abord on r<>cup<75>re la valeur max (r<>ponse imm<6D>diate car champ ind<6E>x<EFBFBD>)
$com='';
$sql = "SELECT MAX(ref)";
$sql.= " FROM ".MAIN_DB_PREFIX."commande";
$sql.= " WHERE ref like 'COM%'";
$resql=$db->query($sql);
if ($resql)
{
$row = $db->fetch_row($resql);
if ($row)
{
//on extrait la valeur max et on la passe en d<>cimale
$max = hexdec((substr($row[0],4,3)).(substr($row[0],8,3)));
}
}
else
{
$max=0;
}
$yy = strftime("%y",time());
$hex = strtoupper(dechex($max+1));
$ref = substr("000000".($hex),-6);
return 'COM-'.substr($ref,0,3)."-".substr($ref,3,3);
}
/** \brief Renvoie la r<>f<EFBFBD>rence de commande suivante non utilis<69>e
* \param objsoc Objet soci<63>t<EFBFBD>
* \return string Texte descripif
*/
function commande_get_num($objsoc=0)
{
return $this->getNextValue();
}
/** \brief Renvoi prochaine valeur attribu<62>e
* \return string Valeur
*/
function getNextValue()
{
global $db;
// D'abord on r<>cup<75>re la valeur max (r<>ponse imm<6D>diate car champ ind<6E>x<EFBFBD>)
$com='';
$sql = "SELECT MAX(ref)";
$sql.= " FROM ".MAIN_DB_PREFIX."commande";
$sql.= " WHERE ref like 'COM%'";
$resql=$db->query($sql);
if ($resql)
{
$row = $db->fetch_row($resql);
if ($row)
{
//on extrait la valeur max et on la passe en d<>cimale
$max = hexdec((substr($row[0],4,3)).(substr($row[0],8,3)));
}
}
else
{
$max=0;
}
$yy = strftime("%y",time());
$hex = strtoupper(dechex($max+1));
$ref = substr("000000".($hex),-6);
return 'COM-'.substr($ref,0,3)."-".substr($ref,3,3);
}
/** \brief Renvoie la r<>f<EFBFBD>rence de commande suivante non utilis<69>e
* \param objsoc Objet soci<63>t<EFBFBD>
* \return string Texte descripif
*/
function commande_get_num($objsoc=0)
{
return $this->getNextValue();
}
}
?>

View File

@@ -2,6 +2,7 @@
/* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2007 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2007 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2008 Raphael Bertrand (Resultic) <raphael.bertrand@resultic.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -48,7 +49,7 @@ class mod_commande_saphir extends ModeleNumRefCommandes
global $conf,$langs;
$langs->load("bills");
$form = new Form($db);
$texte = $langs->trans('GenericNumRefModelDesc')."<br>\n";
@@ -78,8 +79,11 @@ class mod_commande_saphir extends ModeleNumRefCommandes
{
global $conf,$langs,$mysoc;
$numExample = $this->getNextValue($mysoc,$propalspecimen);
$old_code_client=$mysoc->code_client;
$mysoc->code_client='CCCCCCCCCC';
$numExample = $this->getNextValue($mysoc,'');
$mysoc->code_client=$old_code_client;
if (! $numExample)
{
$numExample = $langs->trans('NotConfigured');
@@ -96,6 +100,8 @@ class mod_commande_saphir extends ModeleNumRefCommandes
{
global $db,$conf;
require_once(DOL_DOCUMENT_ROOT ."/lib/functions2.lib.php");
// On d<>fini critere recherche compteur
$mask=$conf->global->COMMANDE_SAPHIR_MASK;
@@ -105,97 +111,8 @@ class mod_commande_saphir extends ModeleNumRefCommandes
return 0;
}
// Extract value for mask counter, mask raz and mask offset
if (! eregi('\{(0+)([@\+][0-9]+)?([@\+][0-9]+)?\}',$mask,$reg)) return 'ErrorBadMask';
$masktri=$reg[1].$reg[2].$reg[3];
$maskcounter=$reg[1];
$maskraz=-1;
$maskoffset=0;
if (strlen($maskcounter) < 3) return 'CounterMustHaveMoreThan3Digits';
$maskwithonlyymcode=$mask;
$maskwithonlyymcode=eregi_replace('\{(0+)([@\+][0-9]+)?([@\+][0-9]+)?\}',$maskcounter,$maskwithonlyymcode);
$maskwithonlyymcode=eregi_replace('\{dd\}','dd',$maskwithonlyymcode);
$maskwithnocode=$maskwithonlyymcode;
$maskwithnocode=eregi_replace('\{yyyy\}','yyyy',$maskwithnocode);
$maskwithnocode=eregi_replace('\{yy\}','yy',$maskwithnocode);
$maskwithnocode=eregi_replace('\{y\}','y',$maskwithnocode);
$maskwithnocode=eregi_replace('\{mm\}','mm',$maskwithnocode);
//print "maskwithonlyymcode=".$maskwithonlyymcode." maskwithnocode=".$maskwithnocode."\n<br>";
// If an offset is asked
if (! empty($reg[2]) && eregi('^\+',$reg[2])) $maskoffset=eregi_replace('^\+','',$reg[2]);
if (! empty($reg[3]) && eregi('^\+',$reg[3])) $maskoffset=eregi_replace('^\+','',$reg[3]);
// If a restore to zero after a month is asked we check if there is already a value for this year.
if (! empty($reg[2]) && eregi('^@',$reg[2])) $maskraz=eregi_replace('^@','',$reg[2]);
if (! empty($reg[3]) && eregi('^@',$reg[3])) $maskraz=eregi_replace('^@','',$reg[3]);
if ($maskraz >= 0)
{
if ($maskraz > 12) return 'ErrorBadMask';
if ($maskraz > 1 && ! eregi('^(.*)\{(y+)\}\{(m+)\}',$maskwithonlyymcode,$reg)) return 'ErrorCantUseRazInStartedYearIfNoYearMonthInMask';
if ($maskraz <= 1 && ! eregi('^(.*)\{(y+)\}',$maskwithonlyymcode,$reg)) return 'ErrorCantUseRazIfNoYearInMask';
//print "x".$maskwithonlyymcode." ".$maskraz;
// Define $yearcomp and $monthcomp (that will be use de filter request to search max number)
$monthcomp=$maskraz;
$yearoffset=0;
$yearcomp=0;
if (date("m") < $maskraz) { $yearoffset=-1; } // If current month lower that month of return to zero, year is previous year
if (strlen($reg[2]) == 4) $yearcomp=sprintf("%04d",date("Y")+$yearoffset);
if (strlen($reg[2]) == 2) $yearcomp=sprintf("%02d",date("y")+$yearoffset);
if (strlen($reg[2]) == 1) $yearcomp=substr(date("y"),2,1)+$yearoffset;
$sqlwhere='';
$sqlwhere.='SUBSTRING(ref, '.(strlen($reg[1])+1).', '.strlen($reg[2]).') >= '.$yearcomp;
if ($monthcomp > 1) // Test useless if monthcomp = 1 (or 0 is same as 1)
{
$sqlwhere.=' AND SUBSTRING(ref, '.(strlen($reg[1])+strlen($reg[2])+1).', '.strlen($reg[3]).') >= '.$monthcomp;
}
}
//print "masktri=".$masktri." maskcounter=".$maskcounter." maskraz=".$maskraz." maskoffset=".$maskoffset."<br>\n";
$numFinal=get_next_value($db,$mask,'commande','ref','',$objsoc->code_client);
$posnumstart=strpos($maskwithnocode,$maskcounter); // Pos of counter in final string (from 0 to ...)
if ($posnumstart < 0) return 'ErrorBadMask';
$sqlstring='SUBSTRING(ref, '.($posnumstart+1).', '.strlen($maskcounter).')';
//print "x".$sqlstring;
// Get counter in database
$counter=0;
$sql = "SELECT MAX(".$sqlstring.") as val";
$sql.= " FROM ".MAIN_DB_PREFIX."commande";
$sql.= " WHERE ref not like '(%'";
if ($sqlwhere) $sql.=' AND '.$sqlwhere;
//print $sql;
dolibarr_syslog("mod_commande_saphir::getNextValue sql=".$sql, LOG_DEBUG);
$resql=$db->query($sql);
if ($resql)
{
$obj = $db->fetch_object($resql);
$counter = $obj->val;
}
else dolibarr_print_error($db);
if (empty($counter) || eregi('[^0-9]',$counter)) $counter=$maskoffset;
$counter++;
// Build numFinal
$numFinal = $mask;
// We replace special codes
$numFinal = str_replace('{yyyy}',date("Y"),$numFinal);
$numFinal = str_replace('{yy}',date("y"),$numFinal);
$numFinal = str_replace('{y}' ,substr(date("y"),2,1),$numFinal);
$numFinal = str_replace('{mm}',date("m"),$numFinal);
$numFinal = str_replace('{dd}',date("d"),$numFinal);
// Now we replace the counter
$maskbefore='{'.$masktri.'}';
$maskafter=str_pad($counter,strlen($maskcounter),"0",STR_PAD_LEFT);
//print 'x'.$maskbefore.'-'.$maskafter.'y';
$numFinal = str_replace($maskbefore,$maskafter,$numFinal);
dolibarr_syslog("mod_commande_saphir::getNextValue return ".$numFinal);
return $numFinal;
}