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