forked from Wavyzz/dolibarr
Add tag {cccc0000} in generic numering modules (from a work of Raphael)
This commit is contained in:
@@ -382,21 +382,14 @@ if ($_GET["action"] == 'create')
|
|||||||
$modFicheinter = new $obj;
|
$modFicheinter = new $obj;
|
||||||
$numpr = $modFicheinter->getNextValue($societe,$ficheinter);
|
$numpr = $modFicheinter->getNextValue($societe,$ficheinter);
|
||||||
|
|
||||||
|
if ($_GET["socid"])
|
||||||
|
{
|
||||||
print "<form name='fichinter' action=\"fiche.php\" method=\"post\">";
|
print "<form name='fichinter' action=\"fiche.php\" method=\"post\">";
|
||||||
|
|
||||||
print '<table class="border" width="100%">';
|
print '<table class="border" width="100%">';
|
||||||
|
|
||||||
if ($_GET["socid"])
|
|
||||||
{
|
|
||||||
print '<input type="hidden" name="socid" value='.$_GET["socid"].'>';
|
print '<input type="hidden" name="socid" value='.$_GET["socid"].'>';
|
||||||
print "<tr><td>".$langs->trans("Company")."</td><td>".$societe->getNomUrl(1)."</td></tr>";
|
print "<tr><td>".$langs->trans("Company")."</td><td>".$societe->getNomUrl(1)."</td></tr>";
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
print "<tr><td>".$langs->trans("Company")."</td><td>";
|
|
||||||
$html->select_societes('','socid','',1);
|
|
||||||
print "</td></tr>";
|
|
||||||
}
|
|
||||||
|
|
||||||
print "<tr><td>".$langs->trans("Date")."</td><td>";
|
print "<tr><td>".$langs->trans("Date")."</td><td>";
|
||||||
$html->select_date(time(),"p",'','','','fichinter');
|
$html->select_date(time(),"p",'','','','fichinter');
|
||||||
@@ -407,7 +400,7 @@ if ($_GET["action"] == 'create')
|
|||||||
print "<tr><td>".$langs->trans("Ref")."</td>";
|
print "<tr><td>".$langs->trans("Ref")."</td>";
|
||||||
print "<td><input name=\"ref\" value=\"$numpr\"></td></tr>\n";
|
print "<td><input name=\"ref\" value=\"$numpr\"></td></tr>\n";
|
||||||
|
|
||||||
if ($conf->projet->enabled && $_GET["socid"])
|
if ($conf->projet->enabled)
|
||||||
{
|
{
|
||||||
// Projet associe
|
// Projet associe
|
||||||
$langs->load("project");
|
$langs->load("project");
|
||||||
@@ -466,6 +459,22 @@ if ($_GET["action"] == 'create')
|
|||||||
|
|
||||||
print '</table>';
|
print '</table>';
|
||||||
print '</form>';
|
print '</form>';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
print "<form name='fichinter' action=\"fiche.php\" method=\"get\">";
|
||||||
|
print '<table class="border" width="100%">';
|
||||||
|
print "<tr><td>".$langs->trans("Company")."</td><td>";
|
||||||
|
$html->select_societes('','socid','',1);
|
||||||
|
print "</td></tr>";
|
||||||
|
print '<tr><td colspan="2" align="center">';
|
||||||
|
print "<input type=\"hidden\" name=\"action\" value=\"create\">";
|
||||||
|
print '<input type="submit" class="button" value="'.$langs->trans("CreateDraftIntervention").'">';
|
||||||
|
print '</td></tr>';
|
||||||
|
print '</table>';
|
||||||
|
print '</form>';
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
elseif ($_GET["id"] > 0)
|
elseif ($_GET["id"] > 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ class mod_commande_fournisseur_orchidee extends ModeleNumRefSuppliersOrders
|
|||||||
global $conf,$langs;
|
global $conf,$langs;
|
||||||
|
|
||||||
$langs->load("bills");
|
$langs->load("bills");
|
||||||
|
$langs->load("admin");
|
||||||
|
|
||||||
$form = new Form($db);
|
$form = new Form($db);
|
||||||
|
|
||||||
@@ -78,7 +79,10 @@ class mod_commande_fournisseur_orchidee extends ModeleNumRefSuppliersOrders
|
|||||||
{
|
{
|
||||||
global $conf,$langs,$mysoc;
|
global $conf,$langs,$mysoc;
|
||||||
|
|
||||||
$numExample = $this->getNextValue($mysoc,$commandespecimen);
|
$old_code_client=$mysoc->code_client;
|
||||||
|
$mysoc->code_client='CCCCCCCCCC';
|
||||||
|
$numExample = $this->getNextValue($mysoc,'');
|
||||||
|
$mysoc->code_client=$old_code_client;
|
||||||
|
|
||||||
if (! $numExample)
|
if (! $numExample)
|
||||||
{
|
{
|
||||||
@@ -96,6 +100,8 @@ class mod_commande_fournisseur_orchidee extends ModeleNumRefSuppliersOrders
|
|||||||
{
|
{
|
||||||
global $db,$conf;
|
global $db,$conf;
|
||||||
|
|
||||||
|
require_once(DOL_DOCUMENT_ROOT ."/lib/functions2.lib.php");
|
||||||
|
|
||||||
// On d<>fini critere recherche compteur
|
// On d<>fini critere recherche compteur
|
||||||
$mask=$conf->global->COMMANDE_FOURNISSEUR_ORCHIDEE_MASK;
|
$mask=$conf->global->COMMANDE_FOURNISSEUR_ORCHIDEE_MASK;
|
||||||
|
|
||||||
@@ -105,97 +111,8 @@ class mod_commande_fournisseur_orchidee extends ModeleNumRefSuppliersOrders
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract value for mask counter, mask raz and mask offset
|
$numFinal=get_next_value($db,$mask,'commande_fournisseur','ref','',$objsoc->code_client);
|
||||||
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."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_replace('{yyyy}',date("Y"),$numFinal);
|
|
||||||
$numFinal = str_replace('{yy}',date("y"),$numFinal);
|
|
||||||
$numFinal = str_replace('{y}' ,substr(date("y"),2,1),$numFinal);
|
|
||||||
$numFinal = str_replace('{mm}',date("m"),$numFinal);
|
|
||||||
$numFinal = str_replace('{dd}',date("d"),$numFinal);
|
|
||||||
|
|
||||||
// Now we replace the counter
|
|
||||||
$maskbefore='{'.$masktri.'}';
|
|
||||||
$maskafter=str_pad($counter,strlen($maskcounter),"0",STR_PAD_LEFT);
|
|
||||||
//print 'x'.$maskbefore.'-'.$maskafter.'y';
|
|
||||||
$numFinal = str_replace($maskbefore,$maskafter,$numFinal);
|
|
||||||
|
|
||||||
dolibarr_syslog("mod_commande_fournisseur_orchidee::getNextValue return ".$numFinal);
|
|
||||||
return $numFinal;
|
return $numFinal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,18 +15,14 @@
|
|||||||
* 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_opale.php
|
\file htdocs/includes/modules/commande/mod_commande_opale.php
|
||||||
\ingroup commande
|
\ingroup commande
|
||||||
\brief Fichier contenant la classe du mod<6F>le de num<75>rotation de r<>f<EFBFBD>rence de commande Opale
|
\brief Fichier contenant la classe du mod<6F>le de num<75>rotation de r<>f<EFBFBD>rence de commande Opale
|
||||||
\version $Revision$
|
\version $Id$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
include_once("modules_commande.php");
|
include_once("modules_commande.php");
|
||||||
|
|
||||||
@@ -34,10 +30,14 @@ include_once("modules_commande.php");
|
|||||||
/**
|
/**
|
||||||
\class mod_commande_opale
|
\class mod_commande_opale
|
||||||
\brief Classe du mod<6F>le de num<75>rotation de r<>f<EFBFBD>rence de commande Opale
|
\brief Classe du mod<6F>le de num<75>rotation de r<>f<EFBFBD>rence de commande Opale
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class mod_commande_opale extends ModeleNumRefCommandes
|
class mod_commande_opale extends ModeleNumRefCommandes
|
||||||
{
|
{
|
||||||
|
var $version='dolibarr'; // 'development', 'experimental', 'dolibarr'
|
||||||
|
var $error = '';
|
||||||
|
var $nom = 'Opale';
|
||||||
|
|
||||||
|
|
||||||
/** \brief Constructeur
|
/** \brief Constructeur
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
/* 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-2007 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) 2008 Raphael Bertrand (Resultic) <raphael.bertrand@resultic.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
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -78,7 +79,10 @@ class mod_commande_saphir extends ModeleNumRefCommandes
|
|||||||
{
|
{
|
||||||
global $conf,$langs,$mysoc;
|
global $conf,$langs,$mysoc;
|
||||||
|
|
||||||
$numExample = $this->getNextValue($mysoc,$propalspecimen);
|
$old_code_client=$mysoc->code_client;
|
||||||
|
$mysoc->code_client='CCCCCCCCCC';
|
||||||
|
$numExample = $this->getNextValue($mysoc,'');
|
||||||
|
$mysoc->code_client=$old_code_client;
|
||||||
|
|
||||||
if (! $numExample)
|
if (! $numExample)
|
||||||
{
|
{
|
||||||
@@ -96,6 +100,8 @@ class mod_commande_saphir extends ModeleNumRefCommandes
|
|||||||
{
|
{
|
||||||
global $db,$conf;
|
global $db,$conf;
|
||||||
|
|
||||||
|
require_once(DOL_DOCUMENT_ROOT ."/lib/functions2.lib.php");
|
||||||
|
|
||||||
// On d<>fini critere recherche compteur
|
// On d<>fini critere recherche compteur
|
||||||
$mask=$conf->global->COMMANDE_SAPHIR_MASK;
|
$mask=$conf->global->COMMANDE_SAPHIR_MASK;
|
||||||
|
|
||||||
@@ -105,97 +111,8 @@ class mod_commande_saphir extends ModeleNumRefCommandes
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract value for mask counter, mask raz and mask offset
|
$numFinal=get_next_value($db,$mask,'commande','ref','',$objsoc->code_client);
|
||||||
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."commande";
|
|
||||||
$sql.= " WHERE ref not like '(%'";
|
|
||||||
if ($sqlwhere) $sql.=' AND '.$sqlwhere;
|
|
||||||
|
|
||||||
//print $sql;
|
|
||||||
dolibarr_syslog("mod_commande_saphir::getNextValue sql=".$sql, LOG_DEBUG);
|
|
||||||
$resql=$db->query($sql);
|
|
||||||
if ($resql)
|
|
||||||
{
|
|
||||||
$obj = $db->fetch_object($resql);
|
|
||||||
$counter = $obj->val;
|
|
||||||
}
|
|
||||||
else dolibarr_print_error($db);
|
|
||||||
if (empty($counter) || eregi('[^0-9]',$counter)) $counter=$maskoffset;
|
|
||||||
$counter++;
|
|
||||||
|
|
||||||
// Build numFinal
|
|
||||||
$numFinal = $mask;
|
|
||||||
|
|
||||||
// We replace special codes
|
|
||||||
$numFinal = str_replace('{yyyy}',date("Y"),$numFinal);
|
|
||||||
$numFinal = str_replace('{yy}',date("y"),$numFinal);
|
|
||||||
$numFinal = str_replace('{y}' ,substr(date("y"),2,1),$numFinal);
|
|
||||||
$numFinal = str_replace('{mm}',date("m"),$numFinal);
|
|
||||||
$numFinal = str_replace('{dd}',date("d"),$numFinal);
|
|
||||||
|
|
||||||
// Now we replace the counter
|
|
||||||
$maskbefore='{'.$masktri.'}';
|
|
||||||
$maskafter=str_pad($counter,strlen($maskcounter),"0",STR_PAD_LEFT);
|
|
||||||
//print 'x'.$maskbefore.'-'.$maskafter.'y';
|
|
||||||
$numFinal = str_replace($maskbefore,$maskafter,$numFinal);
|
|
||||||
|
|
||||||
dolibarr_syslog("mod_commande_saphir::getNextValue return ".$numFinal);
|
|
||||||
return $numFinal;
|
return $numFinal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
/* 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-2007 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) 2008 Raphael Bertrand (Resultic) <raphael.bertrand@resultic.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
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -83,7 +84,10 @@ class mod_facture_mercure extends ModeleNumRefFactures
|
|||||||
{
|
{
|
||||||
global $conf,$langs,$mysoc;
|
global $conf,$langs,$mysoc;
|
||||||
|
|
||||||
$numExample = $this->getNextValue($mysoc,$facturespecimen);
|
$old_code_client=$mysoc->code_client;
|
||||||
|
$mysoc->code_client='CCCCCCCCCC';
|
||||||
|
$numExample = $this->getNextValue($mysoc,'');
|
||||||
|
$mysoc->code_client=$old_code_client;
|
||||||
|
|
||||||
if (! $numExample)
|
if (! $numExample)
|
||||||
{
|
{
|
||||||
@@ -101,8 +105,10 @@ class mod_facture_mercure extends ModeleNumRefFactures
|
|||||||
{
|
{
|
||||||
global $db,$conf;
|
global $db,$conf;
|
||||||
|
|
||||||
// On défini critere recherche compteur
|
require_once(DOL_DOCUMENT_ROOT ."/lib/functions2.lib.php");
|
||||||
if ($facture->type == 2) $mask=$conf->global->FACTURE_MERCURE_MASK_CREDIT;
|
|
||||||
|
// On defini critere recherche compteur
|
||||||
|
if (is_object($facture) && $facture->type == 2) $mask=$conf->global->FACTURE_MERCURE_MASK_CREDIT;
|
||||||
else $mask=$conf->global->FACTURE_MERCURE_MASK_INVOICE;
|
else $mask=$conf->global->FACTURE_MERCURE_MASK_INVOICE;
|
||||||
|
|
||||||
if (! $mask)
|
if (! $mask)
|
||||||
@@ -111,99 +117,12 @@ class mod_facture_mercure extends ModeleNumRefFactures
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract value for mask counter, mask raz and mask offset
|
$where='';
|
||||||
if (! eregi('\{(0+)([@\+][0-9]+)?([@\+][0-9]+)?\}',$mask,$reg)) return 'ErrorBadMask';
|
if ($facture->type == 2) $where.= " AND type = 2";
|
||||||
$masktri=$reg[1].$reg[2].$reg[3];
|
else $where.=" AND type != 2";
|
||||||
$maskcounter=$reg[1];
|
|
||||||
$maskraz=-1;
|
|
||||||
$maskoffset=0;
|
|
||||||
if (strlen($maskcounter) < 3) return 'CounterMustHaveMoreThan3Digits';
|
|
||||||
|
|
||||||
$maskwithonlyymcode=$mask;
|
$numFinal=get_next_value($db,$mask,'facture','facnumber',$where,$objsoc->code_client);
|
||||||
$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."facture";
|
|
||||||
$sql.= " WHERE facnumber not like '(%'";
|
|
||||||
if ($facture->type == 2) $sql.= " AND type = 2";
|
|
||||||
else $sql.=" AND type != 2";
|
|
||||||
if ($sqlwhere) $sql.=' AND '.$sqlwhere;
|
|
||||||
|
|
||||||
//print $sql;
|
|
||||||
dolibarr_syslog("mod_facture_mercure::getNextValue sql=".$sql, LOG_DEBUG);
|
|
||||||
$resql=$db->query($sql);
|
|
||||||
if ($resql)
|
|
||||||
{
|
|
||||||
$obj = $db->fetch_object($resql);
|
|
||||||
$counter = $obj->val;
|
|
||||||
}
|
|
||||||
else dolibarr_print_error($db);
|
|
||||||
if (empty($counter) || eregi('[^0-9]',$counter)) $counter=$maskoffset;
|
|
||||||
$counter++;
|
|
||||||
|
|
||||||
// Build numFinal
|
|
||||||
$numFinal = $mask;
|
|
||||||
|
|
||||||
// We replace special codes
|
|
||||||
$numFinal = str_replace('{yyyy}',date("Y"),$numFinal);
|
|
||||||
$numFinal = str_replace('{yy}',date("y"),$numFinal);
|
|
||||||
$numFinal = str_replace('{y}' ,substr(date("y"),2,1),$numFinal);
|
|
||||||
$numFinal = str_replace('{mm}',date("m"),$numFinal);
|
|
||||||
$numFinal = str_replace('{dd}',date("d"),$numFinal);
|
|
||||||
|
|
||||||
// Now we replace the counter
|
|
||||||
$maskbefore='{'.$masktri.'}';
|
|
||||||
$maskafter=str_pad($counter,strlen($maskcounter),"0",STR_PAD_LEFT);
|
|
||||||
//print 'x'.$maskbefore.'-'.$maskafter.'y';
|
|
||||||
$numFinal = str_replace($maskbefore,$maskafter,$numFinal);
|
|
||||||
|
|
||||||
dolibarr_syslog("mod_facture_mercure::getNextValue return ".$numFinal);
|
|
||||||
return $numFinal;
|
return $numFinal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
/* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
/* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||||
* Copyright (C) 2004-2008 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) 2008 Raphael Bertrand (Resultic) <raphael.bertrand@resultic.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
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -83,7 +84,10 @@ class mod_arctic extends ModeleNumRefFicheinter
|
|||||||
{
|
{
|
||||||
global $conf,$langs,$mysoc;
|
global $conf,$langs,$mysoc;
|
||||||
|
|
||||||
$numExample = $this->getNextValue($mysoc,$propalspecimen);
|
$old_code_client=$mysoc->code_client;
|
||||||
|
$mysoc->code_client='CCCCCCCCCC';
|
||||||
|
$numExample = $this->getNextValue($mysoc,'');
|
||||||
|
$mysoc->code_client=$old_code_client;
|
||||||
|
|
||||||
if (! $numExample)
|
if (! $numExample)
|
||||||
{
|
{
|
||||||
@@ -94,12 +98,15 @@ class mod_arctic extends ModeleNumRefFicheinter
|
|||||||
|
|
||||||
/** \brief Renvoi prochaine valeur attribu<62>e
|
/** \brief Renvoi prochaine valeur attribu<62>e
|
||||||
* \param objsoc Objet soci<63>t<EFBFBD>
|
* \param objsoc Objet soci<63>t<EFBFBD>
|
||||||
|
* \param ficheinter Object ficheinter
|
||||||
* \return string Valeur
|
* \return string Valeur
|
||||||
*/
|
*/
|
||||||
function getNextValue($objsoc=0,$ficheinter='')
|
function getNextValue($objsoc=0,$ficheinter='')
|
||||||
{
|
{
|
||||||
global $db,$conf;
|
global $db,$conf;
|
||||||
|
|
||||||
|
require_once(DOL_DOCUMENT_ROOT ."/lib/functions2.lib.php");
|
||||||
|
|
||||||
// On d<>fini critere recherche compteur
|
// On d<>fini critere recherche compteur
|
||||||
$mask=$conf->global->FICHINTER_ARTIC_MASK;
|
$mask=$conf->global->FICHINTER_ARTIC_MASK;
|
||||||
|
|
||||||
@@ -109,97 +116,8 @@ class mod_arctic extends ModeleNumRefFicheinter
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract value for mask counter, mask raz and mask offset
|
$numFinal=get_next_value($db,$mask,'fichinter','ref','',$objsoc->code_client);
|
||||||
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."propal";
|
|
||||||
$sql.= " WHERE ref not like '(%'";
|
|
||||||
if ($sqlwhere) $sql.=' AND '.$sqlwhere;
|
|
||||||
|
|
||||||
//print $sql;
|
|
||||||
dolibarr_syslog("mod_arctic::getNextValue sql=".$sql, LOG_DEBUG);
|
|
||||||
$resql=$db->query($sql);
|
|
||||||
if ($resql)
|
|
||||||
{
|
|
||||||
$obj = $db->fetch_object($resql);
|
|
||||||
$counter = $obj->val;
|
|
||||||
}
|
|
||||||
else dolibarr_print_error($db);
|
|
||||||
if (empty($counter) || eregi('[^0-9]',$counter)) $counter=$maskoffset;
|
|
||||||
$counter++;
|
|
||||||
|
|
||||||
// Build numFinal
|
|
||||||
$numFinal = $mask;
|
|
||||||
|
|
||||||
// We replace special codes
|
|
||||||
$numFinal = str_replace('{yyyy}',date("Y"),$numFinal);
|
|
||||||
$numFinal = str_replace('{yy}',date("y"),$numFinal);
|
|
||||||
$numFinal = str_replace('{y}' ,substr(date("y"),2,1),$numFinal);
|
|
||||||
$numFinal = str_replace('{mm}',date("m"),$numFinal);
|
|
||||||
$numFinal = str_replace('{dd}',date("d"),$numFinal);
|
|
||||||
|
|
||||||
// Now we replace the counter
|
|
||||||
$maskbefore='{'.$masktri.'}';
|
|
||||||
$maskafter=str_pad($counter,strlen($maskcounter),"0",STR_PAD_LEFT);
|
|
||||||
//print 'x'.$maskbefore.'-'.$maskafter.'y';
|
|
||||||
$numFinal = str_replace($maskbefore,$maskafter,$numFinal);
|
|
||||||
|
|
||||||
dolibarr_syslog("mod_arctic::getNextValue return ".$numFinal);
|
|
||||||
return $numFinal;
|
return $numFinal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
/* 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-2007 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) 2008 Raphael Bertrand (Resultic) <raphael.bertrand@resultic.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
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -78,7 +79,10 @@ class mod_propale_saphir extends ModeleNumRefPropales
|
|||||||
{
|
{
|
||||||
global $conf,$langs,$mysoc;
|
global $conf,$langs,$mysoc;
|
||||||
|
|
||||||
$numExample = $this->getNextValue($mysoc);
|
$old_code_client=$mysoc->code_client;
|
||||||
|
$mysoc->code_client='CCCCCCCCCC';
|
||||||
|
$numExample = $this->getNextValue($mysoc,'');
|
||||||
|
$mysoc->code_client=$old_code_client;
|
||||||
|
|
||||||
if (! $numExample)
|
if (! $numExample)
|
||||||
{
|
{
|
||||||
@@ -89,12 +93,15 @@ class mod_propale_saphir extends ModeleNumRefPropales
|
|||||||
|
|
||||||
/** \brief Return next value
|
/** \brief Return next value
|
||||||
* \param objsoc Object third party
|
* \param objsoc Object third party
|
||||||
|
* \param propal Object commercial proposal
|
||||||
* \return string Value if OK, 0 if KO
|
* \return string Value if OK, 0 if KO
|
||||||
*/
|
*/
|
||||||
function getNextValue($objsoc)
|
function getNextValue($objsoc,$propal='')
|
||||||
{
|
{
|
||||||
global $db,$conf;
|
global $db,$conf;
|
||||||
|
|
||||||
|
require_once(DOL_DOCUMENT_ROOT ."/lib/functions2.lib.php");
|
||||||
|
|
||||||
// On d<>fini critere recherche compteur
|
// On d<>fini critere recherche compteur
|
||||||
$mask=$conf->global->PROPALE_SAPHIR_MASK;
|
$mask=$conf->global->PROPALE_SAPHIR_MASK;
|
||||||
|
|
||||||
@@ -104,97 +111,8 @@ class mod_propale_saphir extends ModeleNumRefPropales
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract value for mask counter, mask raz and mask offset
|
$numFinal=get_next_value($db,$mask,'propal','ref','',$objsoc->code_client);
|
||||||
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."propal";
|
|
||||||
$sql.= " WHERE ref not like '(%'";
|
|
||||||
if ($sqlwhere) $sql.=' AND '.$sqlwhere;
|
|
||||||
|
|
||||||
//print $sql;
|
|
||||||
dolibarr_syslog("mod_propale_saphir::getNextValue sql=".$sql, LOG_DEBUG);
|
|
||||||
$resql=$db->query($sql);
|
|
||||||
if ($resql)
|
|
||||||
{
|
|
||||||
$obj = $db->fetch_object($resql);
|
|
||||||
$counter = $obj->val;
|
|
||||||
}
|
|
||||||
else dolibarr_print_error($db);
|
|
||||||
if (empty($counter) || eregi('[^0-9]',$counter)) $counter=$maskoffset;
|
|
||||||
$counter++;
|
|
||||||
|
|
||||||
// Build numFinal
|
|
||||||
$numFinal = $mask;
|
|
||||||
|
|
||||||
// We replace special codes
|
|
||||||
$numFinal = str_replace('{yyyy}',date("Y"),$numFinal);
|
|
||||||
$numFinal = str_replace('{yy}',date("y"),$numFinal);
|
|
||||||
$numFinal = str_replace('{y}' ,substr(date("y"),2,1),$numFinal);
|
|
||||||
$numFinal = str_replace('{mm}',date("m"),$numFinal);
|
|
||||||
$numFinal = str_replace('{dd}',date("d"),$numFinal);
|
|
||||||
|
|
||||||
// Now we replace the counter
|
|
||||||
$maskbefore='{'.$masktri.'}';
|
|
||||||
$maskafter=str_pad($counter,strlen($maskcounter),"0",STR_PAD_LEFT);
|
|
||||||
//print 'x'.$maskbefore.'-'.$maskafter.'y';
|
|
||||||
$numFinal = str_replace($maskbefore,$maskafter,$numFinal);
|
|
||||||
|
|
||||||
dolibarr_syslog("mod_propale_saphir::getNextValue return ".$numFinal);
|
|
||||||
return $numFinal;
|
return $numFinal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -190,12 +190,13 @@ SetupIsReadyForUse=Install is finished and Dolibarr is ready to use with this ne
|
|||||||
CurrentVersion=Dolibarr current version
|
CurrentVersion=Dolibarr current version
|
||||||
CallUpdatePage=Go to the page that updates database structure and datas %s.
|
CallUpdatePage=Go to the page that updates database structure and datas %s.
|
||||||
LastStableVersion=Last stable version
|
LastStableVersion=Last stable version
|
||||||
GenericMaskCodes=You may enter any numbering mask. In this mask, the following tags could be used:<br><b>{000000}</b> corresponds 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 from the left in order to have as many zeros as the mask. <br><b>{000000+000}</b> same as previous but an offset corresponding to the number to the right of the + sign is applied starting on first %s. <br><b>{000000@x}</b> same as previous but the 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> day (01 to 31).<br><b>{mm}</b> month (01 to 12).<br><b>{yy}</b>, <b>{yyyy}</b> or <b>{y}</b> year over 2, 4 or 1 numbers.<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>
|
GenericMaskCodes=You may enter any numbering mask. In this mask, the following tags could be used:<br><b>{000000}</b> corresponds 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 from the left in order to have as many zeros as the mask. <br><b>{000000+000}</b> same as previous but an offset corresponding to the number to the right of the + sign is applied starting on first %s. <br><b>{000000@x}</b> same as previous but the counter is reset to zero when month x is reached (x between 1 and 12). If this option is used and x is 2 or higher, then sequence {yy}{mm} or {yyyy}{mm} is also required. <br><b>{dd}</b> day (01 to 31).<br><b>{mm}</b> month (01 to 12).<br><b>{yy}</b>, <b>{yyyy}</b> or <b>{y}</b> year over 2, 4 or 1 numbers.<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.
|
GenericNumRefModelDesc=Return a customizable number according to a defined mask.
|
||||||
ServerAvailableOnIPOrPort=Server is available at address <b>%s</b> on port <b>%s</b>
|
ServerAvailableOnIPOrPort=Server is available at address <b>%s</b> on port <b>%s</b>
|
||||||
ServerNotAvailableOnIPOrPort=Server is not available at address <b>%s</b> on port <b>%s</b>
|
ServerNotAvailableOnIPOrPort=Server is not available at address <b>%s</b> on port <b>%s</b>
|
||||||
DoTestServerAvailability=Test server connectivity
|
DoTestServerAvailability=Test server connectivity
|
||||||
DoTestSend=Test sending
|
DoTestSend=Test sending
|
||||||
|
ErrorCantUseRazInStartedYearIfNoYearMonthInMask=Error, can't user option @ if sequence {yy}{mm} or {yyyy}{mm} is not in mask.
|
||||||
|
|
||||||
# Modules
|
# Modules
|
||||||
Module0Name=Users & groups
|
Module0Name=Users & groups
|
||||||
|
|||||||
@@ -189,12 +189,14 @@ SetupIsReadyForUse=L'installation est termin
|
|||||||
CurrentVersion=Version en cours de Dolibarr
|
CurrentVersion=Version en cours de Dolibarr
|
||||||
CallUpdatePage=Appeler la page de mise a jour de la structure et donn<6E>es de la base %s.
|
CallUpdatePage=Appeler la page de mise a jour de la structure et donn<6E>es de la base %s.
|
||||||
LastStableVersion=Derni<6E>re version stable
|
LastStableVersion=Derni<6E>re version stable
|
||||||
GenericMaskCodes=Vous pouvez saisir tout masque de num<75>rotation. Dans ce masque, les balises suivantes peuvent etre utilis<69>es:<br><b>{000000}</b> correspond a un num<75>ro qui sera incr<63>ment<6E> <20> chaque %s. Mettre autant de z<>ro que la longueur d<>sir<69>e du compteur. Le compteur sera compl<70>t<EFBFBD> par des 0 <20> gauche afin d'avoir autant de z<>ro que dans le masque.<br><b>{000000+000}</b> idem pr<70>c<EFBFBD>demment mais un offset correpondant au nombre <20> droite du + est appliqu<71> d<>s la premiere %s.<br><b>{000000@x}</b> idem pr<70>c<EFBFBD>demment mais le compteur est remis <20> zero le xeme mois de l'ann<6E>e (x entre 1 et 12). Si cette option est utilis<69>e, la balise {yy} est aussi obligatoire ainsi que {mm} si x vaut 2 ou plus. <br><b>{dd}</b> jour (01 <20> 31).<br><b>{mm}</b> mois (01 <20> 12).<br><b>{yy}</b>, <b>{yyyy}</b> ou <b>{y}</b> annee sur 2, 4 ou 1 chiffres.<br>Tout autre caract<63>re dans le masque sera laiss<73> inchang<6E>.<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>
|
GenericMaskCodes=Vous pouvez saisir tout masque de num<75>rotation. Dans ce masque, les balises suivantes peuvent etre utilis<69>es:<br><b>{000000}</b> correspond a un num<75>ro qui sera incr<63>ment<6E> <20> chaque %s. Mettre autant de z<>ro que la longueur d<>sir<69>e du compteur. Le compteur sera compl<70>t<EFBFBD> par des 0 <20> gauche afin d'avoir autant de z<>ro que dans le masque.<br><b>{000000+000}</b> idem pr<70>c<EFBFBD>demment mais un offset correpondant au nombre <20> droite du + est appliqu<71> d<>s la premiere %s.<br><b>{000000@x}</b> idem pr<70>c<EFBFBD>demment mais le compteur est remis <20> zero le xeme mois de l'ann<6E>e (x entre 1 et 12). Si cette option est utilis<69>e et x vaut 2 ou plus, alors la sequence {yy}{mm} ou {yyyy}{mm} est obligatoire. <br><b>{dd}</b> jour (01 <20> 31).<br><b>{mm}</b> mois (01 <20> 12).<br><b>{yy}</b>, <b>{yyyy}</b> ou <b>{y}</b> annee sur 2, 4 ou 1 chiffres.<br>Tout autre caract<63>re dans le masque sera laiss<73> inchang<6E>.<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<75>ro personalisable selon un masque <20> d<>finir.
|
GenericNumRefModelDesc=Renvoie un num<75>ro personalisable selon un masque <20> d<>finir.
|
||||||
ServerAvailableOnIPOrPort=Serveur disponible a l'adresse <b>%s</b> sur le port <b>%s</b>
|
ServerAvailableOnIPOrPort=Serveur disponible a l'adresse <b>%s</b> sur le port <b>%s</b>
|
||||||
ServerNotAvailableOnIPOrPort=Serveur non disponible <20> l'adresse <b>%s</b> sur le port <b>%s</b>
|
ServerNotAvailableOnIPOrPort=Serveur non disponible <20> l'adresse <b>%s</b> sur le port <b>%s</b>
|
||||||
DoTestServerAvailability=Tester disponibilit<69> serveur
|
DoTestServerAvailability=Tester disponibilit<69> serveur
|
||||||
DoTestSend=Tester envoi
|
DoTestSend=Tester envoi
|
||||||
|
ErrorCantUseRazInStartedYearIfNoYearMonthInMask=Erreur, ne peut utiliser l'option @ si la s<>quence {yy}{mm} ou {yyyy}{mm} n'est pas dans le masque.
|
||||||
|
|
||||||
# Modules
|
# Modules
|
||||||
Module0Name=Utilisateurs & groupes
|
Module0Name=Utilisateurs & groupes
|
||||||
Module0Desc=Gestion des utilisateurs et groupes
|
Module0Desc=Gestion des utilisateurs et groupes
|
||||||
|
|||||||
218
htdocs/lib/functions2.lib.php
Normal file
218
htdocs/lib/functions2.lib.php
Normal file
@@ -0,0 +1,218 @@
|
|||||||
|
<?php
|
||||||
|
/* Copyright (C) 2008 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||||
|
* Copyright (C) 2008 Raphael Bertrand (Resultic) <raphael.bertrand@resultic.fr>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* 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/
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
\file htdocs/lib/functions.lib.php
|
||||||
|
\brief Ensemble de fonctions de base de dolibarr sous forme d'include
|
||||||
|
\version $Id$
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return next value for a mask
|
||||||
|
*
|
||||||
|
* @param unknown_type $db
|
||||||
|
* @param $mask
|
||||||
|
* @param unknown_type $table
|
||||||
|
* @param unknown_type $field
|
||||||
|
* @return string New value
|
||||||
|
*/
|
||||||
|
function get_next_value($db,$mask,$table,$field,$where='',$valueforccc='')
|
||||||
|
{
|
||||||
|
// 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';
|
||||||
|
|
||||||
|
// Extract value for third party mask counter
|
||||||
|
if (eregi('\{(c+)(0*)\}',$mask,$regClientRef))
|
||||||
|
{
|
||||||
|
$maskrefclient=$regClientRef[1].$regClientRef[2];
|
||||||
|
$maskrefclient_maskclientcode=$regClientRef[1];
|
||||||
|
$maskrefclient_maskcounter=$regClientRef[2];
|
||||||
|
$maskrefclient_maskoffset=0; //default value of maskrefclient_counter offset
|
||||||
|
$maskrefclient_clientcode=substr($valueforccc,0,strlen($maskrefclient_maskclientcode));//get n first characters of client code to form maskrefclient_clientcode
|
||||||
|
$maskrefclient_clientcode=str_pad($maskrefclient_clientcode,strlen($maskrefclient_maskclientcode),"#",STR_PAD_RIGHT);//padding maskrefclient_clientcode for having exactly n characters in maskrefclient_clientcode
|
||||||
|
$maskrefclient_clientcode=sanitize_string($maskrefclient_clientcode);//sanitize maskrefclient_clientcode for sql insert and sql select like
|
||||||
|
if (strlen($maskrefclient_maskcounter) > 0 && strlen($maskrefclient_maskcounter) < 3) return 'CounterMustHaveMoreThan3Digits';
|
||||||
|
}
|
||||||
|
else $maskrefclient='';
|
||||||
|
|
||||||
|
$maskwithonlyymcode=$mask;
|
||||||
|
$maskwithonlyymcode=eregi_replace('\{(0+)([@\+][0-9]+)?([@\+][0-9]+)?\}',$maskcounter,$maskwithonlyymcode);
|
||||||
|
$maskwithonlyymcode=eregi_replace('\{dd\}','dd',$maskwithonlyymcode);
|
||||||
|
$maskwithonlyymcode=eregi_replace('\{(c+)(0*)\}',$maskrefclient,$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);
|
||||||
|
// Now maskwithnocode = 0000ddmmyyyyccc for example
|
||||||
|
// and maskcounter = 0000 for example
|
||||||
|
//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]);
|
||||||
|
|
||||||
|
// Define $sqlwhere
|
||||||
|
// 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 'ErrorBadMaskBadRazMonth';
|
||||||
|
|
||||||
|
// Define reg
|
||||||
|
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 in the select where 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('.$field.', '.(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('.$field.', '.(strlen($reg[1])+strlen($reg[2])+1).', '.strlen($reg[3]).') >= '.$monthcomp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//print "masktri=".$masktri." maskcounter=".$maskcounter." maskraz=".$maskraz." maskoffset=".$maskoffset."<br>\n";
|
||||||
|
|
||||||
|
// Define $sqlstring
|
||||||
|
$posnumstart=strpos($maskwithnocode,$maskcounter); // Pos of counter in final string (from 0 to ...)
|
||||||
|
if ($posnumstart < 0) return 'ErrorBadMaskFailedToLocatePosOfSequence';
|
||||||
|
$sqlstring='SUBSTRING('.$field.', '.($posnumstart+1).', '.strlen($maskcounter).')';
|
||||||
|
//print "x".$sqlstring;
|
||||||
|
|
||||||
|
// Define $maskLike
|
||||||
|
$maskLike = sanitize_string($mask);
|
||||||
|
$maskLike = str_replace("%","_",$maskLike);
|
||||||
|
// Replace protected special codes with matching number of _ as wild card caracter
|
||||||
|
$maskLike = str_replace(sanitize_string('{yyyy}'),'____',$maskLike);
|
||||||
|
$maskLike = str_replace(sanitize_string('{yy}'),'__',$maskLike);
|
||||||
|
$maskLike = str_replace(sanitize_string('{y}'),'_',$maskLike);
|
||||||
|
$maskLike = str_replace(sanitize_string('{mm}'),'__',$maskLike);
|
||||||
|
$maskLike = str_replace(sanitize_string('{dd}'),'__',$maskLike);
|
||||||
|
$maskLike = str_replace(sanitize_string('{'.$masktri.'}'),str_pad("",strlen($maskcounter),"_"),$maskLike);
|
||||||
|
if ($maskrefclient) $maskLike = str_replace(sanitize_string('{'.$maskrefclient.'}'),str_pad("",strlen($maskrefclient),"_"),$maskLike);
|
||||||
|
|
||||||
|
// Get counter in database
|
||||||
|
$counter=0;
|
||||||
|
$sql = "SELECT MAX(".$sqlstring.") as val";
|
||||||
|
$sql.= " FROM ".MAIN_DB_PREFIX.$table;
|
||||||
|
// $sql.= " WHERE ".$field." not like '(%'";
|
||||||
|
$sql.= " WHERE ".$field." like '".$maskLike."'";
|
||||||
|
if ($where) $sql.=$where;
|
||||||
|
if ($sqlwhere) $sql.=' AND '.$sqlwhere;
|
||||||
|
|
||||||
|
dolibarr_syslog("functions2::get_next_value 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++;
|
||||||
|
|
||||||
|
if ($maskrefclient_maskcounter)
|
||||||
|
{
|
||||||
|
//print "maskrefclient_maskcounter=".$maskrefclient_maskcounter." maskwithnocode=".$maskwithnocode." maskrefclient=".$maskrefclient."\n<br>";
|
||||||
|
|
||||||
|
// Define $sqlstring
|
||||||
|
$maskrefclient_posnumstart=strpos($maskwithnocode,$maskrefclient_maskcounter,strpos($maskwithnocode,$maskrefclient)); // Pos of counter in final string (from 0 to ...)
|
||||||
|
if ($maskrefclient_posnumstart <= 0) return 'ErrorBadMask';
|
||||||
|
$maskrefclient_sqlstring='SUBSTRING('.$field.', '.($maskrefclient_posnumstart+1).', '.strlen($maskrefclient_maskcounter).')';
|
||||||
|
//print "x".$sqlstring;
|
||||||
|
|
||||||
|
// Define $maskrefclient_maskLike
|
||||||
|
$maskrefclient_maskLike = sanitize_string($mask);
|
||||||
|
$maskrefclient_maskLike = str_replace("%","_",$maskrefclient_maskLike);
|
||||||
|
// Replace protected special codes with matching number of _ as wild card caracter
|
||||||
|
$maskrefclient_maskLike = str_replace(sanitize_string('{yyyy}'),'____',$maskrefclient_maskLike);
|
||||||
|
$maskrefclient_maskLike = str_replace(sanitize_string('{yy}'),'__',$maskrefclient_maskLike);
|
||||||
|
$maskrefclient_maskLike = str_replace(sanitize_string('{y}'),'_',$maskrefclient_maskLike);
|
||||||
|
$maskrefclient_maskLike = str_replace(sanitize_string('{mm}'),'__',$maskrefclient_maskLike);
|
||||||
|
$maskrefclient_maskLike = str_replace(sanitize_string('{dd}'),'__',$maskrefclient_maskLike);
|
||||||
|
$maskrefclient_maskLike = str_replace(sanitize_string('{'.$masktri.'}'),str_pad("",strlen($maskcounter),"_"),$maskrefclient_maskLike);
|
||||||
|
$maskrefclient_maskLike = str_replace(sanitize_string('{'.$maskrefclient.'}'),$maskrefclient_clientcode.str_pad("",strlen($maskrefclient_maskcounter),"_"),$maskrefclient_maskLike);
|
||||||
|
|
||||||
|
// Get counter in database
|
||||||
|
$maskrefclient_counter=0;
|
||||||
|
$maskrefclient_sql = "SELECT MAX(".$maskrefclient_sqlstring.") as val";
|
||||||
|
$maskrefclient_sql.= " FROM ".MAIN_DB_PREFIX.$table;
|
||||||
|
//$sql.= " WHERE ".$field." not like '(%'";
|
||||||
|
$maskrefclient_sql.= " WHERE ".$field." like '".$maskrefclient_maskLike."'";
|
||||||
|
if ($sqlwhere) $maskrefclient_sql.=' AND '.$sqlwhere; //use the same sqlwhere as general mask
|
||||||
|
$maskrefclient_sql.=' AND (SUBSTRING('.$field.', '.(strpos($maskwithnocode,$maskrefclient)+1).', '.strlen($maskrefclient_maskclientcode).")='".$maskrefclient_clientcode."')";
|
||||||
|
|
||||||
|
dolibarr_syslog("functions2::get_next_value maskrefclient_sql=".$maskrefclient_sql, LOG_DEBUG);
|
||||||
|
$maskrefclient_resql=$db->query($maskrefclient_sql);
|
||||||
|
if ($maskrefclient_resql)
|
||||||
|
{
|
||||||
|
$maskrefclient_obj = $db->fetch_object($maskrefclient_resql);
|
||||||
|
$maskrefclient_counter = $maskrefclient_obj->val;
|
||||||
|
}
|
||||||
|
else dolibarr_print_error($db);
|
||||||
|
if (empty($maskrefclient_counter) || eregi('[^0-9]',$maskrefclient_counter)) $maskrefclient_counter=$maskrefclient_maskoffset;
|
||||||
|
$maskrefclient_counter++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build numFinal
|
||||||
|
$numFinal = $mask;
|
||||||
|
|
||||||
|
// We replace special codes except refclient
|
||||||
|
$numFinal = str_replace('{yyyy}',date("Y"),$numFinal);
|
||||||
|
$numFinal = str_replace('{yy}',date("y"),$numFinal);
|
||||||
|
$numFinal = str_replace('{y}' ,substr(date("y"),2,1),$numFinal);
|
||||||
|
$numFinal = str_replace('{mm}',date("m"),$numFinal);
|
||||||
|
$numFinal = str_replace('{dd}',date("d"),$numFinal);
|
||||||
|
if ($maskclientcode) $numFinal = str_replace(('{'.$maskclientcode.'}'),$clientcode,$numFinal);
|
||||||
|
|
||||||
|
// Now we replace the counter
|
||||||
|
$maskbefore='{'.$masktri.'}';
|
||||||
|
$maskafter=str_pad($counter,strlen($maskcounter),"0",STR_PAD_LEFT);
|
||||||
|
//print 'x'.$maskbefore.'-'.$maskafter.'y';
|
||||||
|
$numFinal = str_replace($maskbefore,$maskafter,$numFinal);
|
||||||
|
|
||||||
|
// Now we replace the refclient
|
||||||
|
if ($maskrefclient)
|
||||||
|
{
|
||||||
|
//print "maskrefclient=".$maskrefclient." maskwithonlyymcode=".$maskwithonlyymcode." maskwithnocode=".$maskwithnocode."\n<br>";
|
||||||
|
$maskrefclient_maskbefore='{'.$maskrefclient.'}';
|
||||||
|
$maskrefclient_maskafter=$maskrefclient_clientcode.str_pad($maskrefclient_counter,strlen($maskrefclient_maskcounter),"0",STR_PAD_LEFT);
|
||||||
|
$numFinal = str_replace($maskrefclient_maskbefore,$maskrefclient_maskafter,$numFinal);
|
||||||
|
}
|
||||||
|
|
||||||
|
dolibarr_syslog("functions2::get_next_value return ".$numFinal,LOG_DEBUG);
|
||||||
|
return $numFinal;
|
||||||
|
}
|
||||||
@@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
\file htdocs/includes/modules/commande/mod_livraison_saphir.php
|
\file htdocs/includes/modules/commande/mod_livraison_saphir.php
|
||||||
\ingroup commande
|
\ingroup expedition
|
||||||
\brief Fichier contenant la classe du mod<6F>le de num<75>rotation de r<>f<EFBFBD>rence de livraison Saphir
|
\brief Fichier contenant la classe du mod<6F>le de num<75>rotation de r<>f<EFBFBD>rence de livraison Saphir
|
||||||
\version $Id$
|
\version $Id$
|
||||||
*/
|
*/
|
||||||
@@ -77,7 +77,10 @@ class mod_livraison_saphir extends ModeleNumRefDeliveryOrder
|
|||||||
{
|
{
|
||||||
global $conf,$langs,$mysoc;
|
global $conf,$langs,$mysoc;
|
||||||
|
|
||||||
$numExample = $this->getNextValue($mysoc,$propalspecimen);
|
$old_code_client=$mysoc->code_client;
|
||||||
|
$mysoc->code_client='CCCCCCCCCC';
|
||||||
|
$numExample = $this->getNextValue($mysoc,'');
|
||||||
|
$mysoc->code_client=$old_code_client;
|
||||||
|
|
||||||
if (! $numExample)
|
if (! $numExample)
|
||||||
{
|
{
|
||||||
@@ -96,6 +99,8 @@ class mod_livraison_saphir extends ModeleNumRefDeliveryOrder
|
|||||||
{
|
{
|
||||||
global $db,$conf;
|
global $db,$conf;
|
||||||
|
|
||||||
|
require_once(DOL_DOCUMENT_ROOT ."/lib/functions2.lib.php");
|
||||||
|
|
||||||
// On d<>fini critere recherche compteur
|
// On d<>fini critere recherche compteur
|
||||||
$mask=$conf->global->LIVRAISON_SAPHIR_MASK;
|
$mask=$conf->global->LIVRAISON_SAPHIR_MASK;
|
||||||
|
|
||||||
@@ -105,97 +110,8 @@ class mod_livraison_saphir extends ModeleNumRefDeliveryOrder
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract value for mask counter, mask raz and mask offset
|
$numFinal=get_next_value($db,$mask,'livraison','ref','',$objsoc->code_client);
|
||||||
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_replace('{yyyy}',date("Y"),$numFinal);
|
|
||||||
$numFinal = str_replace('{yy}',date("y"),$numFinal);
|
|
||||||
$numFinal = str_replace('{y}' ,substr(date("y"),2,1),$numFinal);
|
|
||||||
$numFinal = str_replace('{mm}',date("m"),$numFinal);
|
|
||||||
$numFinal = str_replace('{dd}',date("d"),$numFinal);
|
|
||||||
|
|
||||||
// Now we replace the counter
|
|
||||||
$maskbefore='{'.$masktri.'}';
|
|
||||||
$maskafter=str_pad($counter,strlen($maskcounter),"0",STR_PAD_LEFT);
|
|
||||||
//print 'x'.$maskbefore.'-'.$maskafter.'y';
|
|
||||||
$numFinal = str_replace($maskbefore,$maskafter,$numFinal);
|
|
||||||
|
|
||||||
dolibarr_syslog("mod_livraison_saphir::getNextValue return ".$numFinal);
|
|
||||||
return $numFinal;
|
return $numFinal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user