diff --git a/htdocs/core/lib/functions2.lib.php b/htdocs/core/lib/functions2.lib.php index 362c54baa3b..19ff4b52e60 100644 --- a/htdocs/core/lib/functions2.lib.php +++ b/htdocs/core/lib/functions2.lib.php @@ -1227,12 +1227,12 @@ function get_next_value($db, $mask, $table, $field, $where = '', $objsoc = '', $ $maskLike = str_replace("%", "_", $maskLike); // Replace protected special codes with matching number of _ as wild card character - if ($resetEveryMonth ) { // Perf optimization, when a reset is requested at each month, we can include the year and month inside the filter + if ($resetEveryMonth && $yearcomp && $monthcomp) { // Perf optimization, when a reset is requested at each month, we can include the year and month inside the filter $maskLike = preg_replace('/\{yyyy\}/i', $yearcomp, $maskLike); $maskLike = preg_replace('/\{yy\}/i', $yearcomp, $maskLike); $maskLike = preg_replace('/\{y\}/i', $yearcomp, $maskLike); $maskLike = preg_replace('/\{mm\}/i', sprintf("%02d", $monthcomp), $maskLike); - } elseif ($maskraz == 1) { // Perf optimization, when a reset is requested at first month, we can include the year inside the filter, but not the month + } elseif ($maskraz == 1 && $yearcomp) { // Perf optimization, when a reset is requested at first month, we can include the year inside the filter, but not the month $maskLike = preg_replace('/\{yyyy\}/i', $yearcomp, $maskLike); $maskLike = preg_replace('/\{yy\}/i', $yearcomp, $maskLike); $maskLike = preg_replace('/\{y\}/i', $yearcomp, $maskLike);