X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=includes%2Freferences.inc;h=420e960e805d0169280c8d8dafd73dcd25656398;hb=7286bbfc939360b0fcb573ae075b2b8e899d96c8;hp=d4b26f962c0a28f41dc7b1f4a4de3705370acded;hpb=a7b452fd6eb392f916992c9858caf35eaa6477bb;p=fa-stable.git diff --git a/includes/references.inc b/includes/references.inc index d4b26f96..420e960e 100644 --- a/includes/references.inc +++ b/includes/references.inc @@ -34,6 +34,8 @@ class references function update($type, $id, $reference) { update_reference($type, $id, $reference); + if ($reference != 'auto') + $this->save_last($reference, $type); } function exists($type, $reference) @@ -62,16 +64,19 @@ class references function increment($reference) { // New method done by Pete. So f.i. WA036 will increment to WA037 and so on. - // If $reference is trailed by digits, and digits only, - // extract them and add 1, then put the alpha prefix back on + // If $reference contains at least one group of digits, + // extract first didgits group and add 1, then put all together. // NB. preg_match returns 1 if the regex matches completely // also $result[0] holds entire string, 1 the first captured, 2 the 2nd etc. - if (preg_match('/^(.*?)(\d+)$/', $reference, $result) == 1) + // + if (preg_match('/^(\D*?)(\d+)(.*)/', $reference, $result) == 1) { - $dig_count = strlen($result[2]); // How many digits? eg. 0003 = 4 - $fmt = '%0' . $dig_count . 'd'; // Make a format string - leading zeroes - $nextval = $result[1] . sprintf($fmt, intval($result[2] + 1)); // Add one on, and put prefix back on - return $nextval; + list($all, $prefix, $number, $postfix) = $result; + $dig_count = strlen($number); // How many digits? eg. 0003 = 4 + $fmt = '%0' . $dig_count . 'd'; // Make a format string - leading zeroes + $nextval = sprintf($fmt, intval($number + 1)); // Add one on, and put prefix back on + + return $prefix.$nextval.$postfix; } else return $reference;