New: A generic delivery numbering module (depreciate all others)
This commit is contained in:
parent
34bd512459
commit
0d816f1898
@ -246,9 +246,6 @@ if ($resql)
|
||||
}
|
||||
}
|
||||
|
||||
$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
|
||||
print_fiche_titre($langs->trans("SendingMethod"),$linkback,'setup');
|
||||
|
||||
print '<table class="noborder" width="100%">';
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td width="140">'.$langs->trans("Name").'</td><td>'.$langs->trans("Description").'</td>';
|
||||
|
||||
@ -43,6 +43,14 @@ if (!$user->admin) accessforbidden();
|
||||
/*
|
||||
* Actions
|
||||
*/
|
||||
|
||||
if ($_POST["action"] == 'updateMask')
|
||||
{
|
||||
$maskconstdelivery=$_POST['maskconstdelivery'];
|
||||
$maskdelivery=$_POST['maskdelivery'];
|
||||
if ($maskconstdelivery) dolibarr_set_const($db,$maskconstdelivery,$maskdelivery);
|
||||
}
|
||||
|
||||
if ($_GET["action"] == 'specimen')
|
||||
{
|
||||
$modele=$_GET["module"];
|
||||
@ -171,12 +179,9 @@ $h++;
|
||||
dolibarr_fiche_head($head, $hselected, $langs->trans("ModuleSetup"));
|
||||
|
||||
/*
|
||||
* Module num<EFBFBD>rotation
|
||||
* Module numerotation
|
||||
*/
|
||||
|
||||
$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
|
||||
print_fiche_titre($langs->trans("DeliveryOrderNumberingModules"),$linkback,'setup');
|
||||
|
||||
print '<table class="noborder" width="100%">';
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td width="100">'.$langs->trans("Name").'</td>';
|
||||
@ -204,6 +209,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();
|
||||
@ -227,11 +236,22 @@ if ($handle)
|
||||
|
||||
// Info
|
||||
$htmltooltip='';
|
||||
$nextval=$module->getNextValue($mysoc,$livraison);
|
||||
if ($nextval != $langs->trans("NotAvailable"))
|
||||
$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>: '.$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>';
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2005-2007 Regis Houssin <regis@dolibarr.fr>
|
||||
* Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
*
|
||||
* 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
|
||||
@ -16,17 +17,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_livraison_jade.php
|
||||
\ingroup livraison
|
||||
\brief Fichier contenant la classe du modèle de numérotation de référence de bon de livraison Jade
|
||||
\version $Revision$
|
||||
\version $Id$
|
||||
*/
|
||||
|
||||
require_once(DOL_DOCUMENT_ROOT ."/livraison/mods/modules_livraison.php");
|
||||
@ -39,22 +36,18 @@ require_once(DOL_DOCUMENT_ROOT ."/livraison/mods/modules_livraison.php");
|
||||
|
||||
class mod_livraison_jade extends ModeleNumRefDeliveryOrder
|
||||
{
|
||||
|
||||
/** \brief Constructeur
|
||||
*/
|
||||
function mod_livraison_jade()
|
||||
{
|
||||
$this->nom = "Jade";
|
||||
}
|
||||
var $version='dolibarr'; // 'development', 'experimental', 'dolibarr'
|
||||
var $error = '';
|
||||
var $nom = "Jade";
|
||||
|
||||
|
||||
/** \brief Renvoi la description du modele de numérotation
|
||||
* \return string Texte descripif
|
||||
*/
|
||||
function info()
|
||||
{
|
||||
return "Renvoie le numéro sous la forme numérique BLYY00001, BLYY00002, BLYY00003, ... où YY représente l'année. Le numéro d'incrément qui suit l'année n'est PAS remis à zéro en début d'année.";
|
||||
}
|
||||
/** \brief Renvoi la description du modele de numérotation
|
||||
* \return string Texte descripif
|
||||
*/
|
||||
function info()
|
||||
{
|
||||
return "Renvoie le numéro sous la forme numérique BLYY00001, BLYY00002, BLYY00003, ... où YY représente l'année. Le numéro d'incrément qui suit l'année n'est PAS remis à zéro en début d'année.";
|
||||
}
|
||||
|
||||
/** \brief Renvoi un exemple de numérotation
|
||||
* \return string Example
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/* 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>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@ -17,17 +17,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_livraison_saphir.php
|
||||
\ingroup commande
|
||||
\brief Fichier contenant la classe du modèle de numérotation de référence de livraison Saphir
|
||||
\version $Revision$
|
||||
\version $Id$
|
||||
*/
|
||||
|
||||
require_once(DOL_DOCUMENT_ROOT ."/livraison/mods/modules_livraison.php");
|
||||
@ -38,88 +34,40 @@ require_once(DOL_DOCUMENT_ROOT ."/livraison/mods/modules_livraison.php");
|
||||
*/
|
||||
class mod_livraison_saphir extends ModeleNumRefDeliveryOrder
|
||||
{
|
||||
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 = '';
|
||||
var $nom = 'Saphir';
|
||||
|
||||
|
||||
/** \brief Constructeur
|
||||
*/
|
||||
function mod_livraison_saphir()
|
||||
{
|
||||
$this->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->LIVRAISON_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 bons de livraions</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->LIVRAISON_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->LIVRAISON_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->LIVRAISON_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>';
|
||||
$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="maskconstdelivery" value="LIVRAISON_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="maskdelivery" value="'.$conf->global->LIVRAISON_SAPHIR_MASK.'">',$langs->trans("GenericMaskCodes",$langs->transnoentities("Delivery"),$langs->transnoentities("Delivery"),$langs->transnoentities("Delivery")),1,1).'</td>';
|
||||
|
||||
return $texte;
|
||||
$texte.= '<td align="left" rowspan="2"> <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
|
||||
@ -127,122 +75,130 @@ class mod_livraison_saphir extends ModeleNumRefDeliveryOrder
|
||||
*/
|
||||
function getExample()
|
||||
{
|
||||
global $conf,$langs;
|
||||
global $conf,$langs,$mysoc;
|
||||
|
||||
$numExample = '';
|
||||
|
||||
$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->LIVRAISON_NUM_DELTA?$conf->global->LIVRAISON_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é
|
||||
* \param commande Objet commande
|
||||
* \return string Valeur
|
||||
/** \brief Return next value
|
||||
* \param objsoc Object third party
|
||||
* \param livraison Object proposal
|
||||
* \return string Value if OK, 0 if KO
|
||||
*/
|
||||
function getNextValue($objsoc=0,$livraison='')
|
||||
{
|
||||
global $db,$conf;
|
||||
|
||||
$buildResult = $this->buildMatrice($objsoc,$livraison);
|
||||
|
||||
if ($buildResult == 1)
|
||||
{
|
||||
global $db,$conf;
|
||||
|
||||
// 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."livraison";
|
||||
if ($conf->global->LIVRAISON_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->LIVRAISON_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."livraison";
|
||||
$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);
|
||||
}
|
||||
}
|
||||
// On défini critere recherche compteur
|
||||
$mask=$conf->global->LIVRAISON_SAPHIR_MASK;
|
||||
|
||||
if (! $mask)
|
||||
{
|
||||
$this->error='NotConfigured';
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 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."livraison";
|
||||
$sql.= " WHERE ref REGEXP '^".$searchyy."'";
|
||||
$resql=$db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$row = $db->fetch_row($resql);
|
||||
$max = $row[0];
|
||||
}
|
||||
}
|
||||
else if ($conf->global->LIVRAISON_NUM_DELTA != '' && !eregi('^'.$this->searchLastWithPreviousYear.'',$previousyy))
|
||||
{
|
||||
// on applique le delta une seule fois
|
||||
$max=$conf->global->LIVRAISON_NUM_DELTA?$conf->global->LIVRAISON_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_livraison_saphir::getNextValue return ".$numFinal);
|
||||
return $numFinal;
|
||||
// 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";
|
||||
|
||||
$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."livraison";
|
||||
$sql.= " WHERE ref not like '(%'";
|
||||
if ($sqlwhere) $sql.=' AND '.$sqlwhere;
|
||||
|
||||
//print $sql;
|
||||
dolibarr_syslog("mod_livraison_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_livraison_saphir::getNextValue return ".$numFinal);
|
||||
return $numFinal;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** \brief Renvoie la référence de commande suivante non utilisée
|
||||
* \param objsoc Objet société
|
||||
@ -254,154 +210,6 @@ class mod_livraison_saphir extends ModeleNumRefDeliveryOrder
|
||||
return $this->getNextValue($objsoc,$livraison);
|
||||
}
|
||||
|
||||
|
||||
/** \brief Construction de la matrice de numérotation
|
||||
* \param objsoc Objet société
|
||||
* \return string Valeur
|
||||
*/
|
||||
function buildMatrice($objsoc=0,$livraison='')
|
||||
{
|
||||
global $conf;
|
||||
|
||||
$this->prefix = $conf->global->LIVRAISON_NUM_PREFIX;
|
||||
$this->matrice = $conf->global->LIVRAISON_NUM_MATRICE;
|
||||
$this->searchLast = '';
|
||||
$this->searchLastWithNoYear = '';
|
||||
$this->searchLastWithPreviousYear = '';
|
||||
|
||||
if ($this->matrice != '')
|
||||
{
|
||||
$resultatMatrice = Array();
|
||||
|
||||
$matricePrefix = "PREF|COM"; // PREF : prefix libre (ex: BL pour bon de livraison), 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($livraison) && $livraison->date)
|
||||
{
|
||||
$create_month = strftime("%m",$livraison->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",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",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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@ -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 Eric Seigne <eric.seigne@ryxeo.com>
|
||||
* Copyright (C) 2006 Regis Houssin <regis@dolibarr.fr>
|
||||
*
|
||||
@ -18,9 +18,6 @@
|
||||
* 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$
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -28,7 +25,7 @@
|
||||
\ingroup expedition
|
||||
\brief Fichier contenant la classe mère de generation de bon de livraison en PDF
|
||||
et la classe mère de numérotation des bons de livraisons
|
||||
\version $Revision$
|
||||
\version $Id$
|
||||
*/
|
||||
|
||||
require_once(DOL_DOCUMENT_ROOT.'/lib/functions.inc.php');
|
||||
|
||||
Loading…
Reference in New Issue
Block a user