New: Can use tag {mm} before {yy} even when there is a reset into

numbering masks.
Qual: Enhance phpunit tests to include this case.
This commit is contained in:
Laurent Destailleur
2013-09-11 14:18:56 +02:00
parent 50ce834dd0
commit 0bb18cb05c
3 changed files with 113 additions and 62 deletions

View File

@@ -549,6 +549,7 @@ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='',$m
$maskcounter=$reg[1];
$maskraz=-1;
$maskoffset=0;
$resetEveryMonth=false;
if (dol_strlen($maskcounter) < 3) return 'CounterMustHaveMoreThan3Digits';
// Extract value for third party mask counter
@@ -622,21 +623,32 @@ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='',$m
if ($maskraz > 12) return 'ErrorBadMaskBadRazMonth';
// Define posy, posm and reg
if ($maskraz > 0)
if ($maskraz > 1) // if reset is not first month, we need month and year into mask
{
if (! preg_match('/^(.*)\{(y+)\}\{(m+)\}/i',$maskwithonlyymcode)
&& ! preg_match('/^(.*)\{(m+)\}\{(y+)\}/i',$maskwithonlyymcode)) return 'ErrorCantUseRazInStartedYearIfNoYearMonthInMask';
if (preg_match('/^(.*)\{(y+)\}\{(m+)\}/i',$maskwithonlyymcode,$reg)) { $posy=2; $posm=3; }
elseif (preg_match('/^(.*)\{(m+)\}\{(y+)\}/i',$maskwithonlyymcode,$reg)) { $posy=3; $posm=2; }
else return 'ErrorCantUseRazInStartedYearIfNoYearMonthInMask';
if (dol_strlen($reg[$posy]) < 2) return 'ErrorCantUseRazWithYearOnOneDigit';
}
else
else // if reset is for a specific month in year, we need year
{
if (! preg_match('/^(.*)\{(y+)\}/i',$maskwithonlyymcode)) return 'ErrorCantUseRazIfNoYearInMask';
if (preg_match('/^(.*)\{(y+)\}/i',$maskwithonlyymcode,$reg)) { $posy=2; $posm=0; }
if (preg_match('/^(.*)\{(m+)\}\{(y+)\}/i',$maskwithonlyymcode,$reg)) { $posy=3; $posm=2; }
else if (preg_match('/^(.*)\{(y+)\}\{(m+)\}/i',$maskwithonlyymcode,$reg)) { $posy=2; $posm=3; }
else if (preg_match('/^(.*)\{(y+)\}/i',$maskwithonlyymcode,$reg)) { $posy=2; $posm=0; }
else return 'ErrorCantUseRazIfNoYearInMask';
}
//print "x".$maskwithonlyymcode." ".$maskraz." ".$posy." ".$posm;
//var_dump($reg);
// Define length
$yearlen = $posy?dol_strlen($reg[$posy]):0;
$monthlen = $posm?dol_strlen($reg[$posm]):0;
// Define pos
$yearpos = (dol_strlen($reg[1])+1);
$monthpos = ($yearpos+$yearlen);
if ($posy == 3 && $posm == 2) { // if month is before year
$monthpos = (dol_strlen($reg[1])+1);
$yearpos = ($monthpos+$monthlen);
}
//print "xxx ".$maskwithonlyymcode." maskraz=".$maskraz." posy=".$posy." yearlen=".$yearlen." yearpos=".$yearpos." posm=".$posm." monthlen=".$monthlen." monthpos=".$monthpos." yearoffsettype=".$yearoffsettype." resetEveryMonth=".$resetEveryMonth."\n";
// Define $yearcomp and $monthcomp (that will be use in the select where to search max number)
$monthcomp=$maskraz;
@@ -662,7 +674,6 @@ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='',$m
// For backward compatibility
else if (date("m",$date) < $maskraz && empty($resetEveryMonth)) { $yearoffset=-1; } // If current month lower that month of return to zero, year is previous year
$yearlen = dol_strlen($reg[$posy]);
if ($yearlen == 4) $yearcomp=sprintf("%04d",date("Y",$date)+$yearoffset);
elseif ($yearlen == 2) $yearcomp=sprintf("%02d",date("y",$date)+$yearoffset);
elseif ($yearlen == 1) $yearcomp=substr(date("y",$date),2,1)+$yearoffset;
@@ -671,14 +682,6 @@ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='',$m
if ($yearlen == 4) $yearcomp1=sprintf("%04d",date("Y",$date)+$yearoffset+1);
elseif ($yearlen == 2) $yearcomp1=sprintf("%02d",date("y",$date)+$yearoffset+1);
$monthlen = dol_strlen($reg[$posm]);
$yearpos = (dol_strlen($reg[1])+1);
$monthpos = ($yearpos+$yearlen);
if ($posy == 3) {
$monthpos = (dol_strlen($reg[1])+1);
$yearpos = ($monthpos+$monthlen);
}
$sqlwhere.="(";
$sqlwhere.=" (SUBSTRING(".$field.", ".$yearpos.", ".$yearlen.") = '".$yearcomp."'";
$sqlwhere.=" AND SUBSTRING(".$field.", ".$monthpos.", ".$monthlen.") >= '".str_pad($monthcomp, $monthlen, '0', STR_PAD_LEFT)."')";
@@ -687,20 +690,14 @@ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='',$m
$sqlwhere.=" AND SUBSTRING(".$field.", ".$monthpos.", ".$monthlen.") < '".str_pad($monthcomp, $monthlen, '0', STR_PAD_LEFT)."') ";
$sqlwhere.=')';
}
else if($resetEveryMonth) {
$monthlen = dol_strlen($reg[$posm]);
$yearpos = (dol_strlen($reg[1])+1);
$monthpos = ($yearpos+$yearlen);
if ($posy == 3) {
$monthpos = (dol_strlen($reg[1])+1);
$yearpos = ($monthpos+$monthlen);
}
$sqlwhere.=" SUBSTRING(".$field.", ".$yearpos.", ".$yearlen.") = '".$yearcomp."'";
$sqlwhere.=" AND SUBSTRING(".$field.", ".$monthpos.", ".$monthlen.") = '".str_pad($monthcomp, $monthlen, '0', STR_PAD_LEFT)."' ";
else if ($resetEveryMonth)
{
$sqlwhere.="(SUBSTRING(".$field.", ".$yearpos.", ".$yearlen.") = '".$yearcomp."'";
$sqlwhere.=" AND SUBSTRING(".$field.", ".$monthpos.", ".$monthlen.") = '".str_pad($monthcomp, $monthlen, '0', STR_PAD_LEFT)."')";
}
else // reset is done on january
{
$sqlwhere.='(SUBSTRING('.$field.', '.(dol_strlen($reg[1])+1).', '.dol_strlen($reg[2]).") = '".$yearcomp."')";
$sqlwhere.='(SUBSTRING('.$field.', '.$yearpos.', '.$yearlen.") = '".$yearcomp."')";
}
}
//print "sqlwhere=".$sqlwhere." yearcomp=".$yearcomp."<br>\n"; // sqlwhere and yearcomp defined only if we ask a reset
@@ -1451,46 +1448,46 @@ function dolGetElementUrl($objectid,$objecttype,$withpicto=0,$option='')
// To work with non standard path
if ($objecttype == 'facture' || $objecttype == 'invoice') {
$classpath = 'compta/facture/class';
$module='facture';
$classpath = 'compta/facture/class';
$module='facture';
$subelement='facture';
}
if ($objecttype == 'commande' || $objecttype == 'order') {
$classpath = 'commande/class';
$module='commande';
$classpath = 'commande/class';
$module='commande';
$subelement='commande';
}
if ($objecttype == 'propal') {
$classpath = 'comm/propal/class';
}
if ($objecttype == 'shipping') {
$classpath = 'expedition/class';
$subelement = 'expedition';
$classpath = 'expedition/class';
$subelement = 'expedition';
$module = 'expedition_bon';
}
if ($objecttype == 'delivery') {
$classpath = 'livraison/class';
$subelement = 'livraison';
$classpath = 'livraison/class';
$subelement = 'livraison';
$module = 'livraison_bon';
}
if ($objecttype == 'contract') {
$classpath = 'contrat/class';
$module='contrat';
$classpath = 'contrat/class';
$module='contrat';
$subelement='contrat';
}
if ($objecttype == 'member') {
$classpath = 'adherents/class';
$module='adherent';
$classpath = 'adherents/class';
$module='adherent';
$subelement='adherent';
}
if ($objecttype == 'cabinetmed_cons') {
$classpath = 'cabinetmed/class';
$module='cabinetmed';
$classpath = 'cabinetmed/class';
$module='cabinetmed';
$subelement='cabinetmedcons';
}
if ($objecttype == 'fichinter') {
$classpath = 'fichinter/class';
$module='ficheinter';
$classpath = 'fichinter/class';
$module='ficheinter';
$subelement='fichinter';
}
@@ -1498,13 +1495,13 @@ function dolGetElementUrl($objectid,$objecttype,$withpicto=0,$option='')
$classfile = strtolower($subelement); $classname = ucfirst($subelement);
if ($objecttype == 'invoice_supplier') {
$classfile = 'fournisseur.facture';
$classfile = 'fournisseur.facture';
$classname='FactureFournisseur';
$classpath = 'fourn/class';
$module='fournisseur';
}
if ($objecttype == 'order_supplier') {
$classfile = 'fournisseur.commande';
$classfile = 'fournisseur.commande';
$classname='CommandeFournisseur';
$classpath = 'fourn/class';
$module='fournisseur';