1 package C4
::Barcodes
::hbyymmincr
;
3 # Copyright 2008 LibLime
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
29 use vars
qw($VERSION @ISA);
30 use vars qw($debug $cgi_debug); # from C4::Debug, of course
31 use vars qw($branch $width);
34 $VERSION = 3.07.00.049;
35 @ISA = qw(C4::Barcodes);
40 $width = 4; # FIXME: 4 is too small for sizeable or multi-branch libraries.
42 # Generates barcode where hb = home branch Code, yymm = year/month catalogued, incr = incremental number,
43 # increment resets yearly -fbcit
47 my $query = "SELECT MAX(SUBSTRING(barcode,-$width)), barcode FROM items WHERE barcode REGEXP ? GROUP BY barcode";
48 $debug and print STDERR
"(hbyymmincr) db_max query: $query\n";
49 my $sth = C4
::Context
->dbh->prepare($query);
53 $iso = C4
::Dates
->new($input,'iso')->output('iso'); # try to set the date w/ 2nd arg
55 warn "Failed to create 'iso' Dates object with input '$input'. Reverting to today's date.";
56 $iso = C4
::Dates
->new->output('iso'); # failover back to today
59 $iso = C4
::Dates
->new->output('iso');
61 my $year = substr($iso,2,2); # i.e. "08" for 2008
62 my $andtwo = $width+2;
63 $sth->execute("^[a-zA-Z]{1,}" . $year . "[0-9]{$andtwo}"); # the extra two digits are the month. we don't care what they are, just that they are there.
65 warn "No existing hbyymmincr barcodes found. Reverting to initial value.";
66 return $self->initial;
68 my ($row) = $sth->fetchrow_hashref;
69 my $max = $row->{barcode
};
70 warn "barcode max (hbyymmincr format): $max" if $debug;
76 # FIXME: populated branch?
77 my $iso = C4
::Dates
->new->output('iso'); # like "2008-07-02"
78 return $self->branch . substr($iso,2,2) . substr($iso,5,2) . sprintf('%' . "$width.$width" . 'd',1);
81 sub parse
{ # return 3 parts of barcode: non-incrementing, incrementing, non-incrementing
83 my $barcode = (@_) ?
shift : $self->value;
84 my $branch = $self->branch;
85 unless ($barcode =~ /($branch\d{4})(\d+)$/) {
86 carp
"Barcode '$barcode' has no incrementing part!";
87 return ($barcode,undef,undef);
89 $debug and warn "Barcode '$barcode' parses into: '$1', '$2', ''";
90 return ($1,$2,''); # the third part is in anticipation of barcodes that include checkdigits
95 (@_) and $self->{branch
} = shift;
96 return $self->{branch
};
100 (@_) and $width = shift; # hitting the class variable.
103 sub process_head
{ # (self,head,whole,specific)
104 my ($self,$head,$whole,$specific) = @_;
105 $specific and return $head; # if this is built off an existing barcode, just return the head unchanged.
106 $head =~ s/\d{4}$//; # else strip the old yymm
107 my $iso = C4
::Dates
->new->output('iso'); # like "2008-07-02"
108 return $head . substr($iso,2,2) . substr($iso,5,2);
112 $debug and warn "hbyymmincr: new_object called";
113 my $class_or_object = shift;
114 my $type = ref($class_or_object) || $class_or_object;
115 my $from_obj = ref($class_or_object) ?
1 : 0; # are we building off another Barcodes object?
116 my $self = $class_or_object->default_self('hbyymmincr');
118 $self->branch(@_ ?
shift : $from_obj ?
$class_or_object->branch : $branch);
119 # take the branch from argument, or existing object, or default
121 $debug and print STDERR
"(hbyymmincr) new_object: ", Dumper
($self), "\n";
130 This format is deprecated and SHOULD NOT BE USED.
132 It is fairly clear the originator of the format did not intend to accomodate
133 multiple branch libraries, given that the format caps the available namespace to
134 10,000 barcodes per year TOTAL.
136 Also, the question of what to do with an item that changes branch is unsettled.
137 Nothing prevents the barcode from working fine, but it will look out of place
138 with the old branchcode in it. Rebarcoding a single item is trivial, but if you
139 consider the scenario of branches being consolidated, it is an unnecessary
140 burden to force the rebarcoding of thousands of items, especially when the format
141 will limit you to under 10,000 on the year!
143 The main purpose of the format seems to be to get the branch code into the barcode.
144 This is wholly unnecessary, since the barcodes can be printed with the branchcode
145 directly on it, without it being part of the barcode itself.
147 The API for this module should exist almost exclusively through C4::Barcodes.
148 One novel aspect of this format is the fact that the barcode is tied to a branch.