New: A generic supplier order numbering module (depreciate all others)

This commit is contained in:
Laurent Destailleur 2008-03-05 22:49:23 +00:00
parent 88f469fb77
commit 34bd512459
7 changed files with 196 additions and 603 deletions

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2007 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2007 Regis Houssin <regis@dolibarr.fr> * Copyright (C) 2005-2007 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org> * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be> * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
@ -18,15 +18,13 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
*/ */
/** /**
\file htdocs/admin/fournisseur.php \file htdocs/admin/fournisseur.php
\ingroup fournisseur \ingroup fournisseur
\brief Page d'administration-configuration du module Fournisseur \brief Page d'administration-configuration du module Fournisseur
\version $Revision$ \version $Id$
*/ */
require("./pre.inc.php"); require("./pre.inc.php");
@ -42,9 +40,18 @@ $langs->load("orders");
if (!$user->admin) if (!$user->admin)
accessforbidden(); accessforbidden();
/* /*
* Actions * Actions
*/ */
if ($_POST["action"] == 'updateMask')
{
$maskconstorder=$_POST['maskconstorder'];
$maskorder=$_POST['maskorder'];
if ($maskconstorder) dolibarr_set_const($db,$maskconstorder,$maskorder);
}
if ($_GET["action"] == 'specimen') if ($_GET["action"] == 'specimen')
{ {
$modele=$_GET["module"]; $modele=$_GET["module"];
@ -185,6 +192,10 @@ if ($handle)
$module = new $file; $module = new $file;
// Show modules according to features level
if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
$var=!$var; $var=!$var;
print '<tr '.$bc[$var].'><td>'.$module->nom."</td><td>\n"; print '<tr '.$bc[$var].'><td>'.$module->nom."</td><td>\n";
print $module->info(); print $module->info();
@ -206,16 +217,27 @@ if ($handle)
$commande=new CommandeFournisseur($db); $commande=new CommandeFournisseur($db);
// Info // Info
$htmltooltip=''; $htmltooltip='';
$nextval=$module->getNextValue($mysoc,$commande); $htmltooltip.='<b>'.$langs->trans("Version").'</b>: '.$module->getVersion().'<br>';
if ($nextval != $langs->trans("NotAvailable")) $facture->type=0;
{ $nextval=$module->getNextValue($mysoc,$propale);
$htmltooltip='<b>'.$langs->trans("NextValue").'</b>: '.$nextval; if ("$nextval" != $langs->trans("NotAvailable")) // Keep " on nextval
} {
print '<td align="center">'; $htmltooltip.='<b>'.$langs->trans("NextValue").'</b>: ';
print $html->textwithhelp('',$htmltooltip,1,0); if ($nextval)
print '</td>'; {
$htmltooltip.=$nextval.'<br>';
}
else
{
$htmltooltip.=$langs->trans($module->error).'<br>';
}
}
print '<td align="center">';
print $html->textwithhelp('',$htmltooltip,1,0);
print '</td>';
print '</tr>'; print '</tr>';
} }

View File

@ -1,5 +1,5 @@
<?php <?php
/* Copyright (C) 2005 Laurent Destailleur <eldy@users.sourceforge.net> /* Copyright (C) 2005-2008 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2006 Regis Houssin <regis@dolibarr.fr> * Copyright (C) 2005-2006 Regis Houssin <regis@dolibarr.fr>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -16,37 +16,28 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* or see http://www.gnu.org/ * or see http://www.gnu.org/
*
* $Id$
* $Source$
*/ */
/** /**
\file htdocs/four/commande/modules/mod_commande_fournisseur_muguet.php \file htdocs/four/commande/modules/mod_commande_fournisseur_muguet.php
\ingroup commande \ingroup commande
\brief Fichier contenant la classe du modèle de numérotation de référence de commande fournisseur Muguet \brief Fichier contenant la classe du modèle de numérotation de référence de commande fournisseur Muguet
\version $Revision$ \version $Id$
*/ */
require_once(DOL_DOCUMENT_ROOT ."/fourn/commande/modules/modules_commandefournisseur.php"); require_once(DOL_DOCUMENT_ROOT ."/fourn/commande/modules/modules_commandefournisseur.php");
/** \class mod_commande_fournisseur_muguet /** \class mod_commande_fournisseur_muguet
\brief Classe du modèle de numérotation de référence de commande fournisseur Muguet \brief Classe du modèle de numérotation de référence de commande fournisseur Muguet
*/ */
class mod_commande_fournisseur_muguet extends ModeleNumRefSuppliersOrders class mod_commande_fournisseur_muguet extends ModeleNumRefSuppliersOrders
{ {
var $version='dolibarr'; // 'development', 'experimental', 'dolibarr'
var $error = '';
var $nom = 'Muguet';
var $prefix='CF'; var $prefix='CF';
var $error='';
/*
* \brief Constructeur
*/
function mod_commande_fournisseur_muguet()
{
$this->nom = "Muguet";
}
/** \brief Renvoi la description du modele de numérotation /** \brief Renvoi la description du modele de numérotation
* \return string Texte descripif * \return string Texte descripif

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2007 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2007 Regis Houssin <regis@dolibarr.fr> * Copyright (C) 2005-2007 Regis Houssin <regis@dolibarr.fr>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -17,109 +17,58 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* or see http://www.gnu.org/ * or see http://www.gnu.org/
*
* $Id$
* $Source$
*
*/ */
/** /**
\file htdocs/includes/modules/commande/mod_commande_saphir.php \file htdocs/includes/modules/commande/mod_commande_saphir.php
\ingroup commande \ingroup commande
\brief Fichier contenant la classe du modèle de numérotation de référence de commande fournisseur Orchidee \brief Fichier contenant la classe du modèle de numérotation de référence de commande fournisseur Orchidee
\version $Revision$ \version $Id$
*/ */
require_once(DOL_DOCUMENT_ROOT ."/fourn/commande/modules/modules_commandefournisseur.php"); require_once(DOL_DOCUMENT_ROOT ."/fourn/commande/modules/modules_commandefournisseur.php");
/** /**
\class mod_commande_fournisseur_orchidee \class mod_commande_fournisseur_orchidee
\brief Classe du modèle de numérotation de référence de commande fournisseur Orchidee \brief Classe du modèle de numérotation de référence de commande fournisseur Orchidee
*/ */
class mod_commande_fournisseur_orchidee extends ModeleNumRefSuppliersOrders class mod_commande_fournisseur_orchidee extends ModeleNumRefSuppliersOrders
{ {
var $prefix; var $version='dolibarr'; // 'development', 'experimental', 'dolibarr'
var $matrice;
var $numMatrice = Array();
var $yy;
var $mm;
var $numbitcounter;
var $searchLast;
var $searchLastWithNoYear;
var $searchLastWithPreviousYear;
var $error = ''; var $error = '';
var $nom = 'Orchidee';
/** \brief Constructeur
*/
function mod_commande_fournisseur_orchidee()
{
$this->nom = "Orchidee";
}
/** \brief Renvoi la description du modele de numérotation /** \brief Renvoi la description du modele de numérotation
* \return string Texte descripif * \return string Texte descripif
*/ */
function info() function info()
{ {
global $conf,$langs; global $conf,$langs;
$langs->load("bills"); $langs->load("bills");
$form = new Form($db); $form = new Form($db);
$texte = $langs->trans('OrchideeNumRefModelDesc1')."<br>\n"; $texte = $langs->trans('GenericNumRefModelDesc')."<br>\n";
$texte.= '<table class="nobordernopadding" width="100%">'; $texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
$texte.= '<input type="hidden" name="action" value="updateMask">';
// Paramétrage de la matrice $texte.= '<input type="hidden" name="maskconstorder" value="COMMANDE_FOURNISSEUR_ORCHIDEE_MASK">';
$texte.= '<tr><td>Matrice de disposition des objets (prefix,mois,année,compteur...)</td>'; $texte.= '<table class="nobordernopadding" width="100%">';
$texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
$texte.= '<input type="hidden" name="action" value="updateMatrice">'; // Parametrage du prefix des factures
$texte.= '<td align="right"><input type="text" class="flat" size="30" name="matrice" value="'.$conf->global->COMMANDE_FOURNISSEUR_NUM_MATRICE.'"></td>'; $texte.= '<tr><td>'.$langs->trans("Mask").':</td>';
$texte.= '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"></td>'; $texte.= '<td align="right">'.$form->textwithhelp('<input type="text" class="flat" size="24" name="maskorder" value="'.$conf->global->COMMANDE_FOURNISSEUR_ORCHIDEE_MASK.'">',$langs->trans("GenericMaskCodes",$langs->transnoentities("Order"),$langs->transnoentities("Order"),$langs->transnoentities("Order")),1,1).'</td>';
$texte.= '<td aligne="center">'.$form->textwithhelp('',$langs->trans("MatriceOrderDesc"),1,1).'</td>';
$texte.= '</tr></form>';
// Paramétrage du prefix des commandes
$texte.= '<tr><td>Préfix des commandes</td>';
$texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
$texte.= '<input type="hidden" name="action" value="updatePrefixCommande">';
$texte.= '<td align="right"><input type="text" class="flat" size="30" name="prefixcommande" value="'.$conf->global->COMMANDE_FOURNISSEUR_NUM_PREFIX.'"></td>';
$texte.= '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"></td>';
$texte.= '<td aligne="center">'.$form->textwithhelp('',$langs->trans("PrefixOrderDesc"),1,1).'</td>';
$texte.= '</tr></form>';
// On détermine un offset sur le compteur
$texte.= '<tr><td>Appliquer un offset sur le compteur</td>';
$texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
$texte.= '<input type="hidden" name="action" value="setOffset">';
$texte.= '<td align="right"><input type="text" class="flat" size="30" name="offset" value="'.$conf->global->COMMANDE_FOURNISSEUR_NUM_DELTA.'"></td>';
$texte.= '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"></td>';
$texte.= '<td aligne="center">'.$form->textwithhelp('',$langs->trans("OffsetDesc"),1,1).'</td>';
$texte.= '</tr></form>';
// On défini le debut d'année fiscale
$texte.= '<tr><td>Début d\'année fiscale</td>';
$texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
$texte.= '<input type="hidden" name="action" value="setFiscalMonth">';
$texte.= '<td align="right">';
$texte.= $form->select_month($conf->global->SOCIETE_FISCAL_MONTH_START,'fiscalmonth',1);
$texte.= '</td><td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"></td>';
$texte.= '<td aligne="center">'.$form->textwithwarning('',$langs->trans("FiscalMonthStartDesc"),1).'</td>';
$texte.= '</tr></form>';
// On défini si le compteur se remet à zero en debut d'année
$texte.= '<tr><td>Le compteur se remet à zéro en début d\'année</td>';
$texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
$texte.= '<input type="hidden" name="action" value="setNumRestart">';
$texte.= '<td align="right">';
$texte.= $form->selectyesno('numrestart',$conf->global->COMMANDE_FOURNISSEUR_NUM_RESTART_BEGIN_YEAR,1);
$texte.= '</td><td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"></td>';
$texte.= '<td aligne="center">'.$form->textwithhelp('',$langs->trans("NumRestartDesc"),1,1).'</td>';
$texte.= '</tr></form>';
$texte.= '</table><br>';
return $texte; $texte.= '<td align="left" rowspan="2">&nbsp; <input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"></td>';
$texte.= '</tr>';
$texte.= '</table>';
$texte.= '</form>';
return $texte;
} }
/** \brief Renvoi un exemple de numérotation /** \brief Renvoi un exemple de numérotation
@ -127,118 +76,128 @@ function info()
*/ */
function getExample() function getExample()
{ {
global $conf,$langs; global $conf,$langs,$mysoc;
$buildResult = $this->buildMatrice(); $numExample = $this->getNextValue($mysoc,$commandespecimen);
if ($buildResult == 1) if (! $numExample)
{ {
// On récupère le nombre de chiffres du compteur $numExample = $langs->trans('NotConfigured');
$arg = '%0'.$this->numbitcounter.'s'; }
$num = sprintf($arg,$conf->global->COMMANDE_FOURNISSEUR_NUM_DELTA?$conf->global->COMMANDE_FOURNISSEUR_NUM_DELTA:1); return $numExample;
//On construit le numéro à partir de la matrice
foreach($this->numMatrice as $objetMatrice)
{
if ($objetMatrice == '-') $numExample .= $objetMatrice;
if ($objetMatrice == '$prefix') $numExample .= $this->prefix;
if ($objetMatrice == '$yy') $numExample .= $this->yy;
if ($objetMatrice == '$mm') $numExample .= $this->mm;
if ($objetMatrice == '$num') $numExample .= $num;
}
}
else
{
$numExample = $langs->trans('NotConfigured');
}
return $numExample;
} }
/** \brief Renvoi prochaine valeur attribuée /** \brief Return next value
* \param objsoc Objet société * \param objsoc Object third party
* \param commande Objet commande fournisseur * \param commande Object supplier order
* \return string Valeur * \return string Value if OK, 0 if KO
*/ */
function getNextValue($objsoc=0,$commande='') function getNextValue($objsoc=0,$commande='')
{ {
global $db,$conf; global $db,$conf;
$buildResult = $this->buildMatrice($objsoc,$commande);
if ($buildResult == 1)
{
// On récupère la valeur max (réponse immédiate car champ indéxé) // On défini critere recherche compteur
$posindice = $this->numbitcounter; $mask=$conf->global->COMMANDE_FOURNISSEUR_ORCHIDEE_MASK;
$searchyy='';
$sql = "SELECT MAX(ref)"; if (! $mask)
$sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur"; {
if ($conf->global->COMMANDE_FOURNISSEUR_NUM_RESTART_BEGIN_YEAR) $sql.= " WHERE ref REGEXP '^".$this->searchLast."'"; $this->error='NotConfigured';
$resql=$db->query($sql); return 0;
if ($resql) }
{
$row = $db->fetch_row($resql);
if ($row) $searchyy = substr($row[0],0,-$posindice);
}
if ($conf->global->COMMANDE_FOURNISSEUR_NUM_DELTA != '')
{
//on vérifie si il y a une année précédente
//pour éviter que le delta soit appliqué de nouveau sur la nouvelle année
$previousyy='';
$sql = "SELECT MAX(ref)";
$sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur";
$sql.= " WHERE ref REGEXP '^".$this->searchLastWithPreviousYear."'";
$resql=$db->query($sql);
if ($resql)
{
$row = $db->fetch_row($resql);
if ($row) $previousyy = substr($row[0],0,-$posindice);
}
}
// Si au moins un champ respectant le modèle a été trouvée // Extract value for mask counter, mask raz and mask offset
if (eregi('^'.$this->searchLastWithNoYear.'',$searchyy)) if (! eregi('\{(0+)([@\+][0-9]+)?([@\+][0-9]+)?\}',$mask,$reg)) return 'ErrorBadMask';
{ $masktri=$reg[1].$reg[2].$reg[3];
// Recherche rapide car restreint par un like sur champ indexé $maskcounter=$reg[1];
$sql = "SELECT MAX(0+SUBSTRING(ref,-".$posindice."))"; $maskraz=-1;
$sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur"; $maskoffset=0;
$sql.= " WHERE ref REGEXP '^".$searchyy."'"; if (strlen($maskcounter) < 3) return 'CounterMustHaveMoreThan3Digits';
$resql=$db->query($sql);
if ($resql) $maskwithonlyymcode=$mask;
{ $maskwithonlyymcode=eregi_replace('\{(0+)([@\+][0-9]+)?([@\+][0-9]+)?\}',$maskcounter,$maskwithonlyymcode);
$row = $db->fetch_row($resql); $maskwithonlyymcode=eregi_replace('\{dd\}','dd',$maskwithonlyymcode);
$max = $row[0]; $maskwithnocode=$maskwithonlyymcode;
} $maskwithnocode=eregi_replace('\{yyyy\}','yyyy',$maskwithnocode);
} $maskwithnocode=eregi_replace('\{yy\}','yy',$maskwithnocode);
else if ($conf->global->COMMANDE_FOURNISSEUR_NUM_DELTA != '' && !eregi('^'.$this->searchLastWithPreviousYear.'',$previousyy)) $maskwithnocode=eregi_replace('\{y\}','y',$maskwithnocode);
{ $maskwithnocode=eregi_replace('\{mm\}','mm',$maskwithnocode);
// on applique le delta une seule fois //print "maskwithonlyymcode=".$maskwithonlyymcode." maskwithnocode=".$maskwithnocode."\n<br>";
$max=$conf->global->COMMANDE_FOURNISSEUR_NUM_DELTA?$conf->global->COMMANDE_FOURNISSEUR_NUM_DELTA-1:0;
} // If an offset is asked
else if (! empty($reg[2]) && eregi('^\+',$reg[2])) $maskoffset=eregi_replace('^\+','',$reg[2]);
{ if (! empty($reg[3]) && eregi('^\+',$reg[3])) $maskoffset=eregi_replace('^\+','',$reg[3]);
$max=0;
} // 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]);
// On applique le nombre de chiffres du compteur if (! empty($reg[3]) && eregi('^@',$reg[3])) $maskraz=eregi_replace('^@','',$reg[3]);
$arg = '%0'.$this->numbitcounter.'s'; if ($maskraz >= 0)
$num = sprintf($arg,$max+1); {
$numFinal = ''; if ($maskraz > 12) return 'ErrorBadMask';
if ($maskraz > 1 && ! eregi('^(.*)\{(y+)\}\{(m+)\}',$maskwithonlyymcode,$reg)) return 'ErrorCantUseRazInStartedYearIfNoYearMonthInMask';
foreach($this->numMatrice as $objetMatrice) if ($maskraz <= 1 && ! eregi('^(.*)\{(y+)\}',$maskwithonlyymcode,$reg)) return 'ErrorCantUseRazIfNoYearInMask';
{ //print "x".$maskwithonlyymcode." ".$maskraz;
if ($objetMatrice == '-') $numFinal .= $objetMatrice;
if ($objetMatrice == '$prefix') $numFinal .= $this->prefix; // Define $yearcomp and $monthcomp (that will be use de filter request to search max number)
if ($objetMatrice == '$yy') $numFinal .= $this->yy; $monthcomp=$maskraz;
if ($objetMatrice == '$mm') $numFinal .= $this->mm; $yearoffset=0;
if ($objetMatrice == '$num') $numFinal .= $num; $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);
dolibarr_syslog("mod_commande_fournisseur_orchidee::getNextValue return ".$numFinal); if (strlen($reg[2]) == 2) $yearcomp=sprintf("%02d",date("y")+$yearoffset);
return $numFinal; 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";
$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_fournisseur";
$sql.= " WHERE ref not like '(%'";
if ($sqlwhere) $sql.=' AND '.$sqlwhere;
//print $sql;
dolibarr_syslog("mod_commande_fournisseur_orchidee::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_ireplace('{yyyy}',date("Y"),$numFinal);
$numFinal = str_ireplace('{yy}',date("y"),$numFinal);
$numFinal = str_ireplace('{y}' ,substr(date("y"),2,1),$numFinal);
$numFinal = str_ireplace('{mm}',date("m"),$numFinal);
$numFinal = str_ireplace('{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_ireplace($maskbefore,$maskafter,$numFinal);
dolibarr_syslog("mod_commande_fournisseur_orchidee::getNextValue return ".$numFinal);
return $numFinal;
}
/** \brief Renvoie la référence de commande suivante non utilisée /** \brief Renvoie la référence de commande suivante non utilisée
@ -250,154 +209,6 @@ function info()
{ {
return $this->getNextValue($objsoc,$commande); return $this->getNextValue($objsoc,$commande);
} }
/** \brief Construction de la matrice de numérotation
* \param objsoc Objet société
* \return string Valeur
*/
function buildMatrice($objsoc=0,$commande='')
{
global $conf;
$this->prefix = $conf->global->COMMANDE_FOURNISSEUR_NUM_PREFIX;
$this->matrice = $conf->global->COMMANDE_FOURNISSEUR_NUM_MATRICE;
$this->searchLast = '';
$this->searchLastWithNoYear = '';
$this->searchLastWithPreviousYear = '';
if ($this->matrice != '')
{
$resultatMatrice = Array();
$matricePrefix = "PREF|COM"; // PREF : prefix libre (ex: CF pour commande fournisseur), COM : prefix du client
$matriceYear = "[A]{2,4}"; // l'année est sur 2 ou 4 chiffres
$matriceMonth = "[M]{2}"; // le mois est sur 2 chiffres
$matriceCounter = "[C]{1,}"; //le compteur a un nombre de chiffres libre
$matriceTiret = "[-]{1}"; // on recherche si il y a des tirets de séparation
$matriceSearch = Array('prefix'=>$matricePrefix,
'year'=>$matriceYear,
'month'=>$matriceMonth,
'counter'=>$matriceCounter
);
// on détermine l'emplacement des tirets
$resultTiret = preg_split('/'.$matriceTiret.'/',$this->matrice, -1, PREG_SPLIT_OFFSET_CAPTURE);
$j = 0;
$k = 0;
// on détermine les objets de la matrice
for ($i = 0; $i < count($resultTiret); $i++)
{
foreach($resultTiret[$i] as $idResultTiret => $valueResultTiret)
{
// Ajout des tirets
if ($j != $resultTiret[$i][1])
{
$this->numMatrice[$k] = '-';
$this->searchLast .= '-';
$this->searchLastWithNoYear .= '-';
$this->searchLastWithPreviousYear .= '-';
$j = $resultTiret[$i][1];
$k++;
}
foreach($matriceSearch as $idMatrice => $valueMatrice)
{
$resultCount = eregi(''.$valueMatrice.'',$valueResultTiret,$resultatMatrice);
if ($resultCount)
{
// On récupère le préfix utilisé
if ($idMatrice == 'prefix')
{
if ($resultatMatrice[0] == 'COM')
{
if ($objsoc->prefix_comm)
{
$this->prefix = $objsoc->prefix_comm;
}
else
{
$this->prefix = 'COM';
}
$this->numMatrice[$k] = '$prefix';
$this->searchLast .= $this->prefix;
$this->searchLastWithNoYear .= $this->prefix;
$this->searchLastWithPreviousYear .= $this->prefix;
$k++;
}
else if ($resultatMatrice[0] == 'PREF')
{
$this->numMatrice[$k] = '$prefix';
$this->searchLast .= $this->prefix;
$this->searchLastWithNoYear .= $this->prefix;
$this->searchLastWithPreviousYear .= $this->prefix;
$k++;
}
}
else if ($idMatrice == 'year')
{
// On récupère le nombre de chiffres pour l'année
$numbityear = $resultCount;
// On défini le mois du début d'année fiscale
$current_month = date("n");
if (is_object($commande) && $commande->date)
{
$create_month = strftime("%m",$commande->date);
}
else
{
$create_month = $current_month;
}
// On change d'année fiscal si besoin
if($conf->global->SOCIETE_FISCAL_MONTH_START > 1 && $current_month >= $conf->global->SOCIETE_FISCAL_MONTH_START && $create_month >= $conf->global->SOCIETE_FISCAL_MONTH_START)
{
$this->yy = substr(strftime("%Y",dolibarr_mktime(0,0,0,date("m"),date("d"),date("Y")+1)),$numbityear);
}
else
{
$this->yy = substr(strftime("%Y",time()),$numbityear);
}
$this->numMatrice[$k] = '$yy';
$this->searchLast .= $this->yy;
for ($l = 1; $l <= $numbityear; $l++)
{
$this->searchLastWithNoYear .= '[0-9]';
}
$previousYear = substr(strftime("%Y",dolibarr_mktime(0,0,0,date("m"),date("d"),date("Y")-1)),$numbityear);
$this->searchLastWithPreviousYear .= $previousYear;
$k++;
}
else if ($idMatrice == 'month')
{
// On récupère le mois si besoin
$this->mm = strftime("%m",time());
$this->numMatrice[$k] = '$mm';
$this->searchLast .= '[0-9][0-9]';
$this->searchLastWithNoYear .= '[0-9][0-9]';
$this->searchLastWithPreviousYear .= '[0-9][0-9]';
$k++;
}
else if ($idMatrice == 'counter')
{
// On récupère le nombre de chiffres pour le compteur
$this->numbitcounter = $resultCount;
$this->numMatrice[$k] = '$num';
$k++;
}
}
}
}
}
return 1;
}
else
{
return -3;
}
}
} }
?> ?>

View File

@ -1,133 +0,0 @@
<?php
/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2005-2006 Regis Houssin <regis@dolibarr.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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* 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/fourn/commande/modules/pdf/mod_commande_fournisseur_rose.php
\ingroup fournisseur
\brief Fichier contenant la classe du modèle de numérotation de référence de commande fournisseur Rose
\version $Revision$
*/
require_once(DOL_DOCUMENT_ROOT ."/fourn/commande/modules/modules_commandefournisseur.php");
/**
\class mod_commande_fournisseur_rose
\brief Classe du modèle de numérotation de référence de commande fournisseur Rose
*/
class mod_commande_fournisseur_rose extends ModeleNumRefSuppliersOrders
{
/** \brief Constructeur
*/
function mod_commande_fournisseur_rose()
{
$this->nom = "Rose";
}
/** \brief Renvoi la description du modele de numérotation
* \return string Texte descripif
*/
function info()
{
$texte = "Renvoie le numéro sous la forme numérique CFYYNNNN, où YY représente l'année et NNNN Le numéro d'incrément. Ce dernier n'est PAS remis à zéro en début d'année.<br>\n";
$texte.= "Si la constante COMMANDE_FOURNISSEUR_ROSE_DELTA est définie, un offset est appliqué sur le compteur";
if (defined("COMMANDE_FOURNISSEUR_ROSE_DELTA"))
{
$texte .= " (Définie et vaut: ".COMMANDE_FOURNISSEUR_ROSE_DELTA.")";
}
else
{
$texte .= " (N'est pas définie)";
}
return $texte;
}
/** \brief Renvoi un exemple de numérotation
* \return string Example
*/
function getExample()
{
$y = strftime("%y",time());
if (defined("COMMANDE_FOURNISSEUR_ROSE_DELTA"))
{
$num = sprintf("%02d",COMMANDE_FOURNISSEUR_ROSE_DELTA);
return "CF".$y.substr("000".$num, strlen("000".$num)-4,4);
}
else
{
return "CF".$y."0001";
}
}
/**
* \brief Renvoie le prochaine numéro de référence de commande non utilisé
* \param objsoc Objet société
* \return string Numéro de référence de commande non utilisé
*/
function getNextValue($objsoc=0)
{
global $db;
$sql = "SELECT count(*) FROM ".MAIN_DB_PREFIX."commande_fournisseur WHERE fk_statut <> 0";
$resql = $db->query($sql);
if ( $resql )
{
$row = $db->fetch_row($resql);
$num = $row[0];
}
if (!defined("COMMANDE_FOURNISSEUR_ROSE_DELTA"))
{
define("COMMANDE_FOURNISSEUR_ROSE_DELTA", 0);
}
$num = $num + COMMANDE_FOURNISSEUR_ROSE_DELTA;
$y = strftime("%y",time());
return 'CF'.$y.sprintf("%04s",$num);
}
/** \brief Renvoie la référence de commande suivante non utilisée
* \param objsoc Objet société
* \return string Texte descripif
*/
function commande_get_num($objsoc=0)
{
return $this->getNextValue($objsoc);
}
}
?>

View File

@ -1,104 +0,0 @@
<?php
/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2005-2006 Regis Houssin <regis@dolibarr.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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* 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/fourn/commande/modules/pdf/mod_commande_fournisseur_tulipe.php
\ingroup fournisseur
\brief Fichier contenant la classe du modèle de numérotation de référence de commande fournisseur Tulipe
\version $Revision$
*/
include_once("modules_commandefournisseur.php");
/**
\class mod_commande_fournisseur_tulipe
\brief Classe du modèle de numérotation de référence de commande fournisseur Tulipe
*/
class mod_commande_fournisseur_tulipe extends ModeleNumRefSuppliersOrders
{
/**
* \brief Constructeur
*/
function mod_commande_fournisseur_tulipe()
{
$this->nom = "Tulipe";
}
/** \brief Renvoi la description du modele de numérotation
* \return string Texte descripif
*/
function info()
{
$texte = "Renvoie le numéro sous la forme numérique CFNNNNNN, où NNNNNN représente numéro d'incrément. Ce dernier n'est PAS remis à zéro en début d'année.";
return $texte;
}
/** \brief Renvoi un exemple de numérotation
* \return string Example
*/
function getExample()
{
return "CF000001";
}
/**
* \brief Renvoie le prochaine numéro de référence de commande non utilisé
* \param objsoc objet société
* \return string numéro de référence de commande non utilisé
*/
function getNextValue($objsoc=0)
{
global $db;
$sql = "SELECT count(*) FROM ".MAIN_DB_PREFIX."commande_fournisseur WHERE fk_statut <> 0";
$resql = $db->query($sql);
if ( $resql )
{
$row = $db->fetch_row($resql);
$num = $row[0];
}
return 'CF'.sprintf("%06s",$num);
}
/** \brief Renvoie la référence de commande suivante non utilisée
* \param objsoc Objet société
* \return string Texte descripif
*/
function commande_get_num($objsoc=0)
{
return $this->getNextValue($objsoc);
}
}
?>

View File

@ -18,10 +18,6 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* or see http://www.gnu.org/ * or see http://www.gnu.org/
*
* $Id$
* $Source$
*
*/ */
/** /**
@ -29,7 +25,7 @@
\ingroup commande \ingroup commande
\brief Fichier contenant la classe mère de generation des commandes fournisseurs en PDF \brief Fichier contenant la classe mère de generation des commandes fournisseurs en PDF
et la classe mère de numérotation des commandes fournisseurs et la classe mère de numérotation des commandes fournisseurs
\version $Revision$ \version $Id$
*/ */
require_once(DOL_DOCUMENT_ROOT.'/includes/fpdf/fpdfi/fpdi_protection.php'); require_once(DOL_DOCUMENT_ROOT.'/includes/fpdf/fpdfi/fpdi_protection.php');
@ -133,6 +129,19 @@ class ModeleNumRefSuppliersOrders
return $langs->trans("NotAvailable"); return $langs->trans("NotAvailable");
} }
/** \brief Renvoi version du module numerotation
* \return string Valeur
*/
function getVersion()
{
global $langs;
$langs->load("admin");
if ($this->version == 'development') return $langs->trans("VersionDevelopment");
if ($this->version == 'experimental') return $langs->trans("VersionExperimental");
if ($this->version == 'dolibarr') return DOL_VERSION;
return $langs->trans("NotAvailable");
}
} }

View File

@ -16,9 +16,6 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* or see http://www.gnu.org/ * or see http://www.gnu.org/
*
* $Id$
* $Source$
*/ */
/** /**
@ -26,7 +23,7 @@
\ingroup propale \ingroup propale
\brief Fichier contenant la classe mère de generation des propales en PDF \brief Fichier contenant la classe mère de generation des propales en PDF
et la classe mère de numérotation des propales et la classe mère de numérotation des propales
\version $Revision$ \version $Id$
*/ */
require_once(DOL_DOCUMENT_ROOT.'/lib/functions.inc.php'); require_once(DOL_DOCUMENT_ROOT.'/lib/functions.inc.php');
@ -143,7 +140,7 @@ class ModeleNumRefPropales
if ($this->version == 'experimental') return $langs->trans("VersionExperimental"); if ($this->version == 'experimental') return $langs->trans("VersionExperimental");
if ($this->version == 'dolibarr') return DOL_VERSION; if ($this->version == 'dolibarr') return DOL_VERSION;
return $langs->trans("NotAvailable"); return $langs->trans("NotAvailable");
} }
} }