Bug 13686 Add a hint about collation to the alphabet syspref
[koha.git] / C4 / Barcodes / ValueBuilder.pm
blob341d339fd0e3a6417ee0be661a625a66ec44b29d
1 #!/usr/bin/perl
3 # Copyright 2008-2010 Foundations Bible College
4 # Parts copyright 2012 C & P Bibliography Services
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
11 # version.
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along
18 # with Koha; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 package C4::Barcodes::ValueBuilder::incremental;
22 use C4::Context;
23 my $DEBUG = 0;
25 sub get_barcode {
26 my ($args) = @_;
27 my $nextnum;
28 # not the best, two catalogers could add the same barcode easily this way :/
29 my $query = "select max(abs(barcode)) from items";
30 my $sth = C4::Context->dbh->prepare($query);
31 $sth->execute();
32 while (my ($count)= $sth->fetchrow_array) {
33 $nextnum = $count;
35 $nextnum++;
36 return $nextnum;
41 package C4::Barcodes::ValueBuilder::hbyymmincr;
42 use C4::Context;
43 my $DEBUG = 0;
45 sub get_barcode {
46 my ($args) = @_;
47 my $nextnum = 0;
48 my $year = substr($args->{year}, -2);
49 my $month = $args->{mon};
50 my $query = "SELECT MAX(CAST(SUBSTRING(barcode,-4) AS signed)) AS number FROM items WHERE barcode REGEXP ?";
51 my $sth = C4::Context->dbh->prepare($query);
52 $sth->execute("^[-a-zA-Z]{1,}$year$month");
53 while (my ($count)= $sth->fetchrow_array) {
54 $nextnum = $count if $count;
55 $nextnum = 0 if $nextnum == 9999; # this sequence only allows for cataloging 9999 items per month
56 warn "Existing incremental number = $nextnum" if $DEBUG;
58 $nextnum++;
59 $nextnum = sprintf("%0*d", "4",$nextnum);
60 $nextnum = $year . $month . $nextnum;
61 warn "New hbyymmincr Barcode = $nextnum" if $DEBUG;
62 my $scr = "
63 for (i=0 ; i<document.f.field_value.length ; i++) {
64 if (document.f.tag[i].value == '$args->{loctag}' && document.f.subfield[i].value == '$args->{locsubfield}') {
65 fnum = i;
68 if (\$('#' + id).val() == '') {
69 \$('#' + id).val(document.f.field_value[fnum].value + '$nextnum');
72 return $nextnum, $scr;
76 package C4::Barcodes::ValueBuilder::annual;
77 use C4::Context;
78 my $DEBUG = 0;
80 sub get_barcode {
81 my ($args) = @_;
82 my $nextnum;
83 my $query = "select max(cast( substring_index(barcode, '-',-1) as signed)) from items where barcode like ?";
84 my $sth=C4::Context->dbh->prepare($query);
85 $sth->execute("$args->{year}%");
86 while (my ($count)= $sth->fetchrow_array) {
87 warn "Examining Record: $count" if $DEBUG;
88 $nextnum = $count if $count;
90 $nextnum++;
91 $nextnum = sprintf("%0*d", "4",$nextnum);
92 $nextnum = "$args->{year}-$nextnum";
93 return $nextnum;
99 =head1 Barcodes::ValueBuilder
101 This module is intended as a shim to ease the eventual transition from
102 having all barcode-related code in the value builder plugin .pl file
103 to using C4::Barcodes. Since the shift will require a rather significant
104 amount of refactoring, this module will return value builder-formatted
105 results, at first by merely running the code that was formerly in the
106 barcodes.pl value builder, but later by using C4::Barcodes.
108 =cut