From 53c6638a90abce44c41f54ed82d70018ff03254e Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Thu, 23 May 2013 11:07:56 +0200 Subject: [PATCH 1/2] Reset every month with @99 was not working properly. --- htdocs/core/lib/functions2.lib.php | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/htdocs/core/lib/functions2.lib.php b/htdocs/core/lib/functions2.lib.php index d8f86063e18..93b17930cfe 100644 --- a/htdocs/core/lib/functions2.lib.php +++ b/htdocs/core/lib/functions2.lib.php @@ -611,7 +611,10 @@ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='',$m if ($maskraz > 0) // A reset is required { - if ($maskraz == 99) $maskraz = date('m'); + if ($maskraz == 99) { + $maskraz = date('m'); + $resetEveryMonth = true; + } if ($maskraz > 12) return 'ErrorBadMaskBadRazMonth'; // Define posy, posm and reg @@ -653,13 +656,13 @@ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='',$m else if ($date >= $newyeardate && $yearoffsettype == '-') $yearoffset=-1; } // For backward compatibility - else if (date("m",$date) < $maskraz) { $yearoffset=-1; } // If current month lower that month of return to zero, year is previous year + 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; - if ($monthcomp > 1) // Test with month is useless if monthcomp = 0 or 1 (0 is same as 1) (regis: $monthcomp can't equal 0) + if ($monthcomp > 1 && empty($resetEveryMonth)) // Test with month is useless if monthcomp = 0 or 1 (0 is same as 1) (regis: $monthcomp can't equal 0) { if ($yearlen == 4) $yearcomp1=sprintf("%04d",date("Y",$date)+$yearoffset+1); elseif ($yearlen == 2) $yearcomp1=sprintf("%02d",date("y",$date)+$yearoffset+1); @@ -680,6 +683,17 @@ 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 // reset is done on january { $sqlwhere.='(SUBSTRING('.$field.', '.(dol_strlen($reg[1])+1).', '.dol_strlen($reg[2]).") = '".$yearcomp."')"; From ebb8171d28b7e93b40ec1d96dbc97068d2dc62d8 Mon Sep 17 00:00:00 2001 From: Christophe Battarel Date: Thu, 23 May 2013 11:36:00 +0200 Subject: [PATCH 2/2] fix bug when creating fichinter from order (create function should receive $user as parm) --- htdocs/fichinter/fiche.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/fichinter/fiche.php b/htdocs/fichinter/fiche.php index a6a1291734b..29742f00a97 100644 --- a/htdocs/fichinter/fiche.php +++ b/htdocs/fichinter/fiche.php @@ -178,7 +178,7 @@ else if ($action == 'add' && $user->rights->ficheinter->creer) $object->linked_objects = array_merge($object->linked_objects, $_POST['other_linked_objects']); } - $id = $object->create(); + $id = $object->create($user); if ($id > 0) {