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

This commit is contained in:
Laurent Destailleur 2008-03-05 22:20:30 +00:00
parent f7d61cac0c
commit 2a90226b61
11 changed files with 232 additions and 399 deletions

View File

@ -1,6 +1,6 @@
<?php
/* Copyright (C) 2003-2006 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) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
* Copyright (C) 2004 Andre Cianfarani <acianfa@free.fr>
@ -19,15 +19,13 @@
* 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.
*
* $Id$
*/
/**
\file htdocs/admin/commande.php
\ingroup commande
\brief Page d'administration-configuration du module Commande
\version $Revision$
\version $Id$
*/
require("./pre.inc.php");
@ -45,6 +43,14 @@ if (!$user->admin)
/*
* Actions
*/
if ($_POST["action"] == 'updateMask')
{
$maskconstorder=$_POST['maskconstorder'];
$maskorder=$_POST['maskorder'];
if ($maskconstorder) dolibarr_set_const($db,$maskconstorder,$maskorder);
}
if ($_GET["action"] == 'specimen')
{
$modele=$_GET["module"];
@ -198,6 +204,10 @@ if ($handle)
$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;
print '<tr '.$bc[$var].'><td>'.$module->nom."</td><td>\n";
print $module->info();
@ -219,13 +229,24 @@ if ($handle)
$commande=new Commande($db);
// Info
$htmltooltip='';
// Info
$htmltooltip='';
$htmltooltip.='<b>'.$langs->trans("Version").'</b>: '.$module->getVersion().'<br>';
$facture->type=0;
$nextval=$module->getNextValue($mysoc,$commande);
if ($nextval != $langs->trans("NotAvailable"))
{
$htmltooltip='<b>'.$langs->trans("NextValue").'</b>: '.$nextval;
}
if ("$nextval" != $langs->trans("NotAvailable")) // Keep " on nextval
{
$htmltooltip.='<b>'.$langs->trans("NextValue").'</b>: ';
if ($nextval)
{
$htmltooltip.=$nextval.'<br>';
}
else
{
$htmltooltip.=$langs->trans($module->error).'<br>';
}
}
print '<td align="center">';
print $html->textwithhelp('',$htmltooltip,1,0);
print '</td>';
@ -402,9 +423,9 @@ print '<td align="right"><input type="submit" class="button" value="'.$langs->tr
print '</tr>';
print '</form>';
print '</table>';
print '<br>';
llxFooter('$Date$ - $Revision$');
?>

View File

@ -1,6 +1,6 @@
<?php
/* Copyright (C) 2003-2004 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 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2005-2007 Regis Houssin <regis@dolibarr.fr>
*
@ -304,6 +304,7 @@ while (($file = readdir($handle))!==false)
$htmltooltip.=$langs->trans($module->error);
}
}
print '<td align="center">';
print $html->textwithhelp('',$htmltooltip,1,0);
print '</td>';

View File

@ -1,6 +1,6 @@
<?php
/* Copyright (C) 2003-2004 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) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
@ -19,16 +19,13 @@
* 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.
*
* $Id$
* $Source$
*/
/**
\file htdocs/admin/propale.php
\ingroup propale
\brief Page d'administration/configuration du module Propale
\version $Revision$
\version $Id$
*/
require("./pre.inc.php");
@ -48,6 +45,13 @@ if (!$user->admin)
* Actions
*/
if ($_POST["action"] == 'updateMask')
{
$maskconstpropal=$_POST['maskconstpropal'];
$maskpropal=$_POST['maskpropal'];
if ($maskconstpropal) dolibarr_set_const($db,$maskconstpropal,$maskpropal);
}
if ($_GET["action"] == 'specimen')
{
$modele=$_GET["module"];
@ -231,6 +235,10 @@ if ($handle)
$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;
print '<tr '.$bc[$var].'><td>'.$module->nom."</td><td>\n";
print $module->info();
@ -254,12 +262,22 @@ if ($handle)
// Info
$htmltooltip='';
$htmltooltip.='<b>'.$langs->trans("Version").'</b>: '.$module->getVersion().'<br>';
$nextval=$module->getNextValue($mysoc,$propale);
if ($nextval != $langs->trans("NotAvailable"))
{
$htmltooltip.='<b>'.$langs->trans("NextValue").'</b>: '.$nextval;
}
$htmltooltip.='<b>'.$langs->trans("Version").'</b>: '.$module->getVersion().'<br>';
$facture->type=0;
$nextval=$module->getNextValue($mysoc,$propale);
if ("$nextval" != $langs->trans("NotAvailable")) // Keep " on nextval
{
$htmltooltip.='<b>'.$langs->trans("NextValue").'</b>: ';
if ($nextval)
{
$htmltooltip.=$nextval.'<br>';
}
else
{
$htmltooltip.=$langs->trans($module->error).'<br>';
}
}
print '<td align="center">';
print $html->textwithhelp('',$htmltooltip,1,0);
print '</td>';

View File

@ -16,16 +16,13 @@
* 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_marbre.php
\ingroup commande
\brief Fichier contenant la classe du modèle de numérotation de référence de commande Marbre
\version $Revision$
\version $Id$
*/
require_once(DOL_DOCUMENT_ROOT ."/includes/modules/commande/modules_commande.php");
@ -36,17 +33,11 @@ require_once(DOL_DOCUMENT_ROOT ."/includes/modules/commande/modules_commande.php
class mod_commande_marbre extends ModeleNumRefCommandes
{
var $version='dolibarr'; // 'development', 'experimental', 'dolibarr'
var $prefix='CO';
var $error='';
/*
* \brief Constructeur
*/
function mod_commande_marbre()
{
$this->nom = "Marbre";
}
var $nom='Marbre';
/** \brief Renvoi la description du modele de numérotation
* \return string Texte descripif
@ -92,10 +83,12 @@ class mod_commande_marbre extends ModeleNumRefCommandes
return true;
}
/** \brief Renvoi prochaine valeur attribuée
* \return string Valeur
*/
function getNextValue()
/** \brief Return next value
* \param objsoc Objet third party
* \param commande Object order
* \return string Value if OK, 0 if KO
*/
function getNextValue($objsoc=0,$commande)
{
global $db;

View File

@ -17,103 +17,58 @@
* 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_saphir.php
\ingroup commande
\brief Fichier contenant la classe du modèle de numérotation de référence de commande Saphir
\version $Revision$
\version $Id$
*/
require_once(DOL_DOCUMENT_ROOT ."/includes/modules/commande/modules_commande.php");
/**
\class mod_commande_saphir
\brief Classe du modèle de numérotation de référence de commande Saphir
*/
class mod_commande_saphir extends ModeleNumRefCommandes
{
var $prefix;
var $matrice;
var $numMatrice = Array();
var $yy;
var $mm;
var $numbitcounter;
var $searchLast;
var $searchLastWithNoYear;
var $searchLastWithPreviousYear;
var $version='dolibarr'; // 'development', 'experimental', 'dolibarr'
var $error = '';
/** \brief Constructeur
*/
function mod_commande_saphir()
{
$this->nom = "Saphir";
}
var $nom = 'Saphir';
/** \brief Renvoi la description du modele de numérotation
* \return string Texte descripif
*/
function info()
function info()
{
global $conf,$langs;
$langs->load("bills");
$langs->load("bills");
$form = new Form($db);
$form = new Form($db);
$texte = $langs->trans('SaphirNumRefModelDesc1')."<br>\n";
$texte.= '<table class="nobordernopadding" width="100%">';
// Paramétrage de la matrice
$texte.= '<tr><td>Matrice de disposition des objets (prefix,mois,année,compteur...)</td>';
$texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
$texte.= '<input type="hidden" name="action" value="updateMatrice">';
$texte.= '<td align="right"><input type="text" class="flat" size="30" name="matrice" value="'.$conf->global->COMMANDE_NUM_MATRICE.'"></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("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="updatePrefix">';
$texte.= '<td align="right"><input type="text" class="flat" size="30" name="prefix" value="'.$conf->global->COMMANDE_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_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 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_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>';
// On affiche le debut d'année fiscale
$texte.= '<tr><td>Début d\'année fiscale : '.monthArrayOrSelected($conf->global->SOCIETE_FISCAL_MONTH_START).'</td>';
$texte.= '</tr>';
$texte.= '</table><br>';
$texte = $langs->trans('GenericNumRefModelDesc')."<br>\n";
$texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
$texte.= '<input type="hidden" name="action" value="updateMask">';
$texte.= '<input type="hidden" name="maskconstpropal" value="COMMANDE_SAPHIR_MASK">';
$texte.= '<table class="nobordernopadding" width="100%">';
// Parametrage du prefix des factures
$texte.= '<tr><td>'.$langs->trans("Mask").':</td>';
$texte.= '<td align="right">'.$form->textwithhelp('<input type="text" class="flat" size="24" name="maskpropal" value="'.$conf->global->COMMANDE_SAPHIR_MASK.'">',$langs->trans("GenericMaskCodes",$langs->transnoentities("Order"),$langs->transnoentities("Order"),$langs->transnoentities("Order")),1,1).'</td>';
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
@ -121,119 +76,128 @@ function info()
*/
function getExample()
{
global $conf,$langs;
global $conf,$langs,$mysoc;
$numExample = '';
//On construit la matrice
$buildResult = $this->buildMatrice();
$numExample = $this->getNextValue($mysoc,$propalspecimen);
if ($buildResult == 1)
{
// On récupère le nombre de chiffres du compteur
$arg = '%0'.$this->numbitcounter.'s';
$num = sprintf($arg,$conf->global->COMMANDE_NUM_DELTA?$conf->global->COMMANDE_NUM_DELTA:1);
//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;
if (! $numExample)
{
$numExample = $langs->trans('NotConfigured');
}
return $numExample;
}
/** \brief Renvoi prochaine valeur attribuée
* \param objsoc Objet société
* \return string Valeur
/** \brief Return next value
* \param objsoc Objet third party
* \param commande Object order
* \return string Value if OK, 0 if KO
*/
function getNextValue($objsoc=0,$commande)
{
global $db,$conf;
//On construit la matrice
$buildResult = $this->buildMatrice($objsoc,$commande);
if ($buildResult == 1)
{
// On récupère la valeur max (réponse immédiate car champ indéxé)
$posindice = $this->numbitcounter;
$searchyy='';
$sql = "SELECT MAX(ref)";
$sql.= " FROM ".MAIN_DB_PREFIX."commande";
if ($conf->global->COMMANDE_NUM_RESTART_BEGIN_YEAR) $sql.= " WHERE ref REGEXP '^".$this->searchLast."'";
$resql=$db->query($sql);
if ($resql)
{
$row = $db->fetch_row($resql);
if ($row) $searchyy = substr($row[0],0,-$posindice);
}
if ($conf->global->COMMANDE_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";
$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);
}
}
global $db,$conf;
// Si au moins un champ respectant le modèle a été trouvée
if (eregi('^'.$this->searchLastWithNoYear.'',$searchyy))
{
// Recherche rapide car restreint par un like sur champ indexé
$sql = "SELECT MAX(0+SUBSTRING(ref,-".$posindice."))";
$sql.= " FROM ".MAIN_DB_PREFIX."commande";
$sql.= " WHERE ref REGEXP '^".$searchyy."'";
$resql=$db->query($sql);
if ($resql)
{
$row = $db->fetch_row($resql);
$max = $row[0];
}
}
else if ($conf->global->COMMANDE_NUM_DELTA != '' && !eregi('^'.$this->searchLastWithPreviousYear.'',$previousyy))
{
// on applique le delta une seule fois
$max=$conf->global->COMMANDE_NUM_DELTA?$conf->global->COMMANDE_NUM_DELTA-1:0;
}
else
{
$max=0;
}
// On applique le nombre de chiffres du compteur
$arg = '%0'.$this->numbitcounter.'s';
$num = sprintf($arg,$max+1);
$numFinal = '';
foreach($this->numMatrice as $objetMatrice)
{
if ($objetMatrice == '-') $numFinal .= $objetMatrice;
if ($objetMatrice == '$prefix') $numFinal .= $this->prefix;
if ($objetMatrice == '$yy') $numFinal .= $this->yy;
if ($objetMatrice == '$mm') $numFinal .= $this->mm;
if ($objetMatrice == '$num') $numFinal .= $num;
}
dolibarr_syslog("mod_commande_saphir::getNextValue return ".$numFinal);
return $numFinal;
}
}
// On défini critere recherche compteur
$mask=$conf->global->COMMANDE_SAPHIR_MASK;
if (! $mask)
{
$this->error='NotConfigured';
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(facnumber, '.(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(facnumber, '.(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(facnumber, '.($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_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_saphir::getNextValue return ".$numFinal);
return $numFinal;
}
/** \brief Renvoie la référence de commande suivante non utilisée
@ -246,154 +210,6 @@ function info()
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_NUM_PREFIX;
$this->matrice = $conf->global->COMMANDE_NUM_MATRICE;
$this->searchLast = '';
$this->searchLastWithNoYear = '';
$this->searchLastWithPreviousYear = '';
if ($this->matrice != '')
{
$resultatMatrice = Array();
$matricePrefix = "PREF|COM"; // PREF : prefix libre (ex: C pour commande), 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

@ -36,18 +36,9 @@ require_once(DOL_DOCUMENT_ROOT ."/includes/modules/facture/modules_facture.php")
class mod_facture_mercure extends ModeleNumRefFactures
{
var $version='dolibarr'; // 'development', 'experimental', 'dolibarr'
var $prefixinvoice;
var $prefixcreditnote;
var $matrice;
var $numMatrice = Array();
var $yy;
var $mm;
var $numbitcounter;
var $searchLast;
var $searchLastWithNoYear;
var $searchLastWithPreviousYear;
var $error = '';
/** \brief Renvoi la description du modele de numerotation
* \return string Texte descripif
*/
@ -59,7 +50,7 @@ class mod_facture_mercure extends ModeleNumRefFactures
$form = new Form($db);
$texte = $langs->trans('MercureNumRefModelDesc1')."<br>\n";
$texte = $langs->trans('GenericNumRefModelDesc')."<br>\n";
$texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
$texte.= '<input type="hidden" name="action" value="updateMask">';
$texte.= '<input type="hidden" name="maskconstinvoice" value="FACTURE_MERCURE_MASK_INVOICE">';
@ -67,18 +58,16 @@ class mod_facture_mercure extends ModeleNumRefFactures
$texte.= '<table class="nobordernopadding" width="100%">';
// Parametrage du prefix des factures
$texte.= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("InvoiceStandard").')</td>';
// $texte.= '<td align="right"><input type="text" class="flat" size="24" name="prefixfacture" value="'.$conf->global->FACTURE_NUM_PREFIX.'"></td>';
$texte.= '<td align="right">'.$form->textwithhelp('<input type="text" class="flat" size="24" name="maskinvoice" value="'.$conf->global->FACTURE_MERCURE_MASK_INVOICE.'">',$langs->trans("MercureMaskCodes"),1,1).'</td>';
$texte.= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("InvoiceStandard").'):</td>';
$texte.= '<td align="right">'.$form->textwithhelp('<input type="text" class="flat" size="24" name="maskinvoice" value="'.$conf->global->FACTURE_MERCURE_MASK_INVOICE.'">',$langs->trans("GenericMaskCodes",$langs->transnoentities("Invoice"),$langs->transnoentities("Invoice"),$langs->transnoentities("Invoice")),1,1).'</td>';
$texte.= '<td align="left" rowspan="2">&nbsp; <input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"></td>';
$texte.= '</tr>';
// Parametrage du prefix des avoirs
$texte.= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("InvoiceAvoir").')</td>';
//$texte.= '<td align="right"><input type="text" class="flat" size="24" name="prefixavoir" value="'.$conf->global->AVOIR_NUM_PREFIX.'"></td>';
$texte.= '<td align="right">'.$form->textwithhelp('<input type="text" class="flat" size="24" name="maskcredit" value="'.$conf->global->FACTURE_MERCURE_MASK_CREDIT.'">',$langs->trans("MercureMaskCodes"),1,1).'</td>';
$texte.= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("InvoiceAvoir").'):</td>';
$texte.= '<td align="right">'.$form->textwithhelp('<input type="text" class="flat" size="24" name="maskcredit" value="'.$conf->global->FACTURE_MERCURE_MASK_CREDIT.'">',$langs->trans("MercureMaskCodes",$langs->transnoentities("Invoice"),$langs->transnoentities("Invoice"),$langs->transnoentities("Invoice")),1,1).'</td>';
$texte.= '</tr>';
$texte.= '</table>';
@ -94,7 +83,7 @@ class mod_facture_mercure extends ModeleNumRefFactures
{
global $conf,$langs,$mysoc;
$numExample = $this->getNextValue($mysoc,$facture);
$numExample = $this->getNextValue($mysoc,$facturespecimen);
if (! $numExample)
{
@ -230,5 +219,4 @@ class mod_facture_mercure extends ModeleNumRefFactures
}
}
?>

View File

@ -51,7 +51,7 @@ class mod_propale_saphir extends ModeleNumRefPropales
$form = new Form($db);
$texte = $langs->trans('SaphirNumRefModelDesc1')."<br>\n";
$texte = $langs->trans('GenericNumRefModelDesc')."<br>\n";
$texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
$texte.= '<input type="hidden" name="action" value="updateMask">';
$texte.= '<input type="hidden" name="maskconstpropal" value="PROPALE_SAPHIR_MASK">';
@ -89,10 +89,10 @@ class mod_propale_saphir extends ModeleNumRefPropales
/** \brief Return next value
* \param objsoc Object third party
* \param facture Object invoice
* \param propal Object proposal
* \return string Value if OK, 0 if KO
*/
function getNextValue($objsoc,$facture)
function getNextValue($objsoc,$propal)
{
global $db,$conf;
@ -163,14 +163,12 @@ class mod_propale_saphir extends ModeleNumRefPropales
// Get counter in database
$counter=0;
$sql = "SELECT MAX(".$sqlstring.") as val";
$sql.= " FROM ".MAIN_DB_PREFIX."facture";
$sql.= " WHERE facnumber not like '(%'";
if ($facture->type == 2) $sql.= " AND type = 2";
else $sql.=" AND type != 2";
$sql.= " FROM ".MAIN_DB_PREFIX."propal";
$sql.= " WHERE ref not like '(%'";
if ($sqlwhere) $sql.=' AND '.$sqlwhere;
//print $sql;
dolibarr_syslog("mod_facture_mercure::getNextValue sql=".$sql, LOG_DEBUG);
dolibarr_syslog("mod_propale_saphir::getNextValue sql=".$sql, LOG_DEBUG);
$resql=$db->query($sql);
if ($resql)
{

View File

@ -186,6 +186,9 @@ SetupIsReadyForUse=Install is finished and Dolibarr is ready for use with new co
CurrentVersion=Dolibarr current version
CallUpdatePage=Go on page that update database structure and datas %s.
LastStableVersion=Last stable version
GenericMaskCodes=You may enter all mask of numbering. In this mask, the following tags could be used:<br><b>{000000}</b> correspond to a number which will be incremented on each %s. Enter as many zeros as the desired length of the counter. The counter will be completed by zeros at the left in order to have as many zeros as the mask. <br><b>{000000+000}</b> same as previous but a corresponding offset to the number to the right of + is applied beginning by first %s. <br><b>{000000@x}</b> same as previous but counter is reset to zero when month x is reached (x between 1 and 12). If this option is used, tag {yy} is required and also {mm} if x is 2 or higher. <br><b>{dd}</b> invoice day (01 à 31).<br><b>{mm}</b> invoice month (01 à 12).<br><b>{yy}</b> or <b>{yyyy}</b> or <b>{y}</b> year over 2 or 4 numbers of the invoice.<br>All other characters in the mask will remain intact.<br>Spaces are not allowed.<br><br><u>Example on the 99th %s of the third party TheCompany done 31/01/2007:</u><br><b>ABC{yy}{mm}-{000000}</b> will give <b>ABC0701-000099</b><br><b>{0000+100}-ZZZ/{dd}/XXX</b> will give <b>0199-ZZZ/31/XXX</b><br>
GenericNumRefModelDesc=Return a customizable number according to a defined mask.
# Modules
Module0Name=Users & groups
Module0Desc=Users and groups management

View File

@ -341,10 +341,6 @@ PDFTourteauDescription=Invoice model Tourteau
DefinedAndHasThisValue=Defined and value to
IsNotDefined=undefined
# mercure
MercureNumRefModelDesc1=Return a customizable invoice number according to a defined mask.
MercureMaskCodes=You may enter all mask of numbering. In this mask, the following tags could be used:<br><b>{000000}</b> correspond to a number which will be incremented on each invoice. Enter as many zeros as the desired length of the counter. The counter will be completed by zeros at the left in order to have as many zeros as the mask. <br><b>{000000+000}</b> same as previous but a corresponding offset to the number to the right of + is applied beginning by first invoice. <br><b>{000000@x}</b> same as previous but counter is reset to zero when month x is reached (x between 1 and 12). If this option is used, tag {yy} is required and also {mm} if x is 2 or higher. <br><b>{dd}</b> invoice day (01 à 31).<br><b>{mm}</b> invoice month (01 à 12).<br><b>{yy}</b> or <b>{yyyy}</b> or <b>{y}</b> year over 2 or 4 numbers of the invoice.<br>All other characters in the mask will remain intact.<br>Spaces are not allowed.<br><br><u>Example on the 99th invoice of the third party TheCompany done 31/01/2007:</u><br><b>ABC{yy}{mm}-{000000}</b> will give <b>ABC0701-000099</b><br><b>{0000+100}-ZZZ/{dd}/XXX</b> will give <b>0199-ZZZ/31/XXX</b><br>
# terre
TerreNumRefModelDesc1=Return numero with format %syymm-nnnn for standard invoices and %syymm-nnnn for credit notes where yy is year, mm is month and nnnn is a sequence with no break and no return to 0
TerreNumRefModelError=A bill starting with $syymm already exists and is not compatible with this model of sequence. Remove it or rename it to activate this module.

View File

@ -185,6 +185,9 @@ SetupIsReadyForUse=L'installation est termin
CurrentVersion=Version en cours de Dolibarr
CallUpdatePage=Appeler la page de mise a jour de la structure et données de la base %s.
LastStableVersion=Dernière version stable
GenericMaskCodes=Vous pouvez saisir tout masque de numérotation. Dans ce masque, les balises suivantes peuvent etre utilisées:<br><b>{000000}</b> correspond a un numéro qui sera incrémenté à chaque %s. Mettre autant de zéro que la longueur désirée du compteur. Le compteur sera complété par des 0 à gauche afin d'avoir autant de zéro que dans le masque.<br><b>{000000+000}</b> idem précédemment mais un offset correpondant au nombre à droite du + est appliqué dès la premiere %s.<br><b>{000000@x}</b> idem précédemment mais le compteur est remis à zero le xeme mois de l'année (x entre 1 et 12). Si cette option est utilisée, la balise {yy} est aussi obligatoire ainsi que {mm} si x vaut 2 ou plus <br><b>{dd}</b> jour de la facture (01 à 31).<br><b>{mm}</b> jour de la facture (01 à 12).<br><b>{yy}</b> ou <b>{yyyy}</b> ou <b>{y}</b> annee sur 2 ou 4 chiffres de la facture.<br>Tout autre caractère dans le masque sera laissé inchangé.<br>Les espaces ne sont pas permis.<br><br><u>Exemple sur la 99eme %s du tiers LaCompanie faite le 31/03/2007:</u><br><b>ABC{yy}{mm}-{000000}</b> donnera <b>ABC0703-000099</b><br><b>{0000+100}-XXX/{dd}/YYY</b> donnera <b>0199-XXX/31/YYY</b><br>
GenericNumRefModelDesc=Renvoie un numéro personalisable selon un masque à définir.
# Modules
Module0Name=Utilisateurs & groupes
Module0Desc=Gestion des utilisateurs et groupes

View File

@ -340,10 +340,6 @@ PDFTourteauDescription=Mod
DefinedAndHasThisValue=Définie et vaut
IsNotDefined=N'est pas définie
# mercure
MercureNumRefModelDesc1=Renvoie un numéro de facture personalisable selon un masque à définir.
MercureMaskCodes=Vous pouvez saisir tout masque de numérotation. Dans ce masque, les balises suivantes peuvent etre utilisées:<br><b>{000000}</b> correspond a un numéro qui sera incrémenté à chaque facture. Mettre autant de zéro que la longueur désirée du compteur. Le compteur sera complété par des 0 à gauche afin d'avoir autant de zéro que dans le masque.<br><b>{000000+000}</b> idem précédemment mais un offset correpondant au nombre à droite du + est appliqué dès la premiere facture.<br><b>{000000@x}</b> idem précédemment mais le compteur est remis à zero le xeme mois de l'année (x entre 1 et 12). Si cette option est utilisée, la balise {yy} est aussi obligatoire ainsi que {mm} si x vaut 2 ou plus <br><b>{dd}</b> jour de la facture (01 à 31).<br><b>{mm}</b> jour de la facture (01 à 12).<br><b>{yy}</b> ou <b>{yyyy}</b> ou <b>{y}</b> annee sur 2 ou 4 chiffres de la facture.<br>Tout autre caractère dans le masque sera laissé inchangé.<br>Les espaces ne sont pas permis.<br><br><u>Exemple sur la 99eme facture du tiers LaCompanie faite le 31/03/2007:</u><br><b>ABC{yy}{mm}-{000000}</b> donnera <b>ABC0703-000099</b><br><b>{0000+100}-XXX/{dd}/YYY</b> donnera <b>0199-XXX/31/YYY</b><br>
# terre
TerreNumRefModelDesc1=Renvoie le numéro sous la forme %syymm-nnnn pour les factures et %syymm-nnnn pour les avoirs où yy est l'année, mm le mois et nnnn un compteur séquentiel sans rupture et sans remise à 0
TerreNumRefModelError=Une facture commençant par $syymm existe en base et est incompatible avec cette numérotation. Supprimer la ou renommer la pour activer ce module.