Bug 3577 - Barcode.pl does not cater variable length branch codes in hbyymmincr format
Summary: Barcode.pl does not cater variable length branch codes in hbyymmincr format
Status: CLOSED DUPLICATE of bug 6474
Alias: None
Product: Koha
Classification: Unclassified
Component: Cataloging (show other bugs)
Version: 3.4
Hardware: PC All
: PATCH-Sent (DO NOT USE) normal (vote)
Assignee: Galen Charlton
QA Contact: Bugs List
: 5659 (view as bug list)
Depends on:
Reported: 2009-09-03 01:51 UTC by Chris Cormack
Modified: 2012-10-26 00:41 UTC (History)
3 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Text to go in the release notes:
Version(s) released in:

Proposed fix for bug 3577 (1.50 KB, patch)
2011-01-26 15:01 UTC, Ian Walls
Details | Diff | Splinter Review
screenshot (12.92 KB, image/png)
2011-01-30 15:39 UTC, Katrin Fischer

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Cormack 2010-05-21 01:12:28 UTC

---- Reported by mwilson@globaladvisors.biz 2009-09-03 13:51:06 ----

The Barcode.pl script attempts to auto-increment the barcode by isolating the maximum barcode in the item database. It does this by isolating the last four numerals of the barcodes and choosing the maximum value.

The problem is that the SELECT query assumes a two letter branch code. If the branch code varies, the SELECT query fails to isolate the correct portion of the branch code. It therefore incorrectly maximises and the increment is wrong causing duplicate barcodes.

The exact line is:

$query = "SELECT MAX(CAST(SUBSTRING(barcode,7,4) AS signed)) FROM items WHERE barcode REGEXP ?";

The solution would be to limit branch codes to two letters or to isolate only the last four numerals of the barcode string before maximising.

Incidently, surely this also limits the barcode to 9999 items?

--- Bug imported by chris@bigballofwax.co.nz 2010-05-21 01:12 UTC  ---

This bug was previously known as _bug_ 3577 at http://bugs.koha.org/cgi-bin/bugzilla3/show_bug.cgi?id=3577

Unknown operating system Linux - Debian. Setting to default OS "All".
Actual time not defined. Setting to 0.0
The original reporter of this bug does not have
   an account here. Reassigning to the person who moved
   it here: chris@bigballofwax.co.nz.
   Previous reporter was mwilson@globaladvisors.biz.

Comment 1 Ian Walls 2011-01-26 15:01:59 UTC
Created attachment 3024 [details] [review]
Proposed fix for bug 3577

Katrin to test (for bug 5659)
Comment 2 Ian Walls 2011-01-26 15:02:44 UTC
*** Bug 5659 has been marked as a duplicate of this bug. ***
Comment 3 Katrin Fischer 2011-01-30 15:39:12 UTC
Created attachment 3032 [details]

Hi sekjal,

the patch works great for the example libraries which all have 3 letter branchcodes. We use the ISIL as branchcode for our libraries. After I added a new library using the ISIL only the next barcode was generated correctly. After that the same barcode was being generated again and again. After I deleted the item for the ISL branch, the barcodes were generated correctly again. (see screensot)
Comment 4 Ian Walls 2011-06-24 19:57:09 UTC
This is marked as Failed QA, but I'm seeing an equivalent fix in the current HEAD... can anyone confirm that this is still an issue?
Comment 5 Katrin Fischer 2011-07-17 12:45:58 UTC
I tested this on current master and still see problems and with the change form the patch:

1) Turn system preference autobarcode to hbyymmincr
2) Add items to a new record
  a) Add 2 items for branch MPL - Midway. Works. (MPL11070001,MPL11070002)
  b) Add 1 item for branch DE-576 - works. (DE-57611070003)
  c) Add 2nd item for branch DE-576 (DE-57611070003 - duplicate!)
Perhaps the - in the branch code is the cause of the problem. I can add 1 item for it at the time, and add MPL items after it. But it's not possible to add 2 items in a row for DE-576.
Comment 6 Sophie MEYNIEUX 2011-07-22 09:26:44 UTC
Yes, the pb is the - in the branchcode.
This is corrected with patch proposed in bug 6474 http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=6474
Comment 7 Sophie MEYNIEUX 2011-07-22 09:27:48 UTC

*** This bug has been marked as a duplicate of bug 6474 ***