View | Details | Raw Unified | Return to bug 8691
Collapse All | Expand All

(-)a/C4/Barcodes.pm (+3 lines)
Lines 1-6 Link Here
1
package C4::Barcodes;
1
package C4::Barcodes;
2
2
3
# Copyright 2008 LibLime
3
# Copyright 2008 LibLime
4
# Copyright 2012 KohaAloha
4
#
5
#
5
# This file is part of Koha.
6
# This file is part of Koha.
6
#
7
#
Lines 26-31 use C4::Context; Link Here
26
use C4::Debug;
27
use C4::Debug;
27
use C4::Dates;
28
use C4::Dates;
28
use C4::Barcodes::hbyymmincr;
29
use C4::Barcodes::hbyymmincr;
30
use C4::Barcodes::hbincr;
29
use C4::Barcodes::annual;
31
use C4::Barcodes::annual;
30
use C4::Barcodes::incremental;
32
use C4::Barcodes::incremental;
31
use C4::Barcodes::EAN13;
33
use C4::Barcodes::EAN13;
Lines 177-182 our $types = { Link Here
177
	annual      => sub {C4::Barcodes::annual->new_object(@_);     },
179
	annual      => sub {C4::Barcodes::annual->new_object(@_);     },
178
	incremental => sub {C4::Barcodes::incremental->new_object(@_);},
180
	incremental => sub {C4::Barcodes::incremental->new_object(@_);},
179
	hbyymmincr  => sub {C4::Barcodes::hbyymmincr->new_object(@_); },
181
	hbyymmincr  => sub {C4::Barcodes::hbyymmincr->new_object(@_); },
182
	hbincr      => sub {C4::Barcodes::hbincr->new_object(@_); },
180
	OFF         => sub {C4::Barcodes::OFF->new_object(@_);        },
183
	OFF         => sub {C4::Barcodes::OFF->new_object(@_);        },
181
    EAN13       => sub {C4::Barcodes::EAN13->new_object(@_);      },
184
    EAN13       => sub {C4::Barcodes::EAN13->new_object(@_);      },
182
};
185
};
(-)a/C4/Barcodes/hbincr.pm (+129 lines)
Line 0 Link Here
1
package C4::Barcodes::hbincr;
2
3
# Copyright 2012 KohaAloha
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 2 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use strict;
21
use warnings;
22
23
use Carp;
24
25
use C4::Context;
26
use C4::Debug;
27
use C4::Dates;
28
29
#use Smart::Comments '####';
30
31
use vars qw($VERSION @ISA);
32
use vars qw($debug $cgi_debug);    # from C4::Debug, of course
33
use vars qw($branch $width);
34
35
BEGIN {
36
    #    $VERSION = 0.01;
37
    @ISA = qw(C4::Barcodes);
38
}
39
40
INIT {
41
    $branch = '';
42
    $width  = 8;
43
}
44
45
# Generates barcode where hb = homebranch code, incr = an 8 digit number incremental number
46
47
sub db_max ($;$) {
48
    my $self = shift;
49
    my $query =
50
"SELECT MAX(SUBSTRING(barcode,-$width)), barcode FROM items WHERE barcode REGEXP ? GROUP BY barcode";
51
    $debug and print STDERR "(hbincr) db_max query: $query\n";
52
    my $sth = C4::Context->dbh->prepare($query);
53
54
    $sth->execute("^[a-zA-Z]{1,}");
55
    unless ( $sth->rows ) {
56
        warn "No existing hbincr barcodes found.  Reverting to initial value.";
57
        return $self->initial;
58
    }
59
60
    my ($row) = $sth->fetchrow_hashref;
61
    my $max = $row->{barcode};
62
    warn "barcode max (hbincr format): $max" if $debug;
63
    return ( $max || 0 );
64
}
65
66
sub initial () {
67
    my $self = shift;
68
    return $self->branch;
69
}
70
71
sub parse ($;$)
72
{  # return 3 parts of barcode: non-incrementing, incrementing, non-incrementing
73
    my $self    = shift;
74
    my $barcode = (@_) ? shift : $self->value;
75
    my $branch  = $self->branch;
76
    unless ( $barcode =~ /($branch)(\d+)$/ ) {
77
        carp "Barcode '$barcode' has no incrementing part!";
78
        return ( $barcode, undef, undef );
79
    }
80
    $debug and warn "Barcode '$barcode' parses into: '$1', '$2', ''";
81
    return ( $1, $2, '' )
82
      ; # the third part is in anticipation of barcodes that include checkdigits
83
}
84
85
sub branch ($;$) {
86
    my $self = shift;
87
    (@_) and $self->{branch} = shift;
88
    return $self->{branch};
89
}
90
91
sub width ($;$) {
92
    my $self = shift;
93
    (@_) and $width = shift;    # hitting the class variable.
94
    return $width;
95
}
96
97
sub process_head($$;$$) {       # (self,head,whole,specific)
98
    my ( $self, $head, $whole, $specific ) = @_;
99
    $specific
100
      and return
101
      $head
102
      ; # if this is built off an existing barcode, just return the head unchanged.
103
    $head =~ s/\d{8}$//;    # else strip the old
104
         #   my $iso = C4::Dates->new->output('iso');    # like "2008-07-02"
105
    return $head;
106
}
107
108
sub new_object {
109
    $debug and warn "hbincr: new_object called";
110
    my $class_or_object = shift;
111
    my $type = ref($class_or_object) || $class_or_object;
112
    my $from_obj =
113
      ref($class_or_object)
114
      ? 1
115
      : 0;    # are we building off another Barcodes object?
116
    my $self = $class_or_object->default_self('hbincr');
117
    bless $self, $type;
118
    $self->branch(
119
        @_ ? shift : $from_obj ? $class_or_object->branch : $branch );
120
121
    # take the branch from argument, or existing object, or default
122
    use Data::Dumper;
123
    $debug and print STDERR "(hbincr) new_object: ", Dumper($self), "\n";
124
    return $self;
125
}
126
127
1;
128
__END__
129
(-)a/cataloguing/value_builder/barcode.pl (-6 / +34 lines)
Lines 21-33 use strict; Link Here
21
use warnings;
21
use warnings;
22
no warnings 'redefine'; # otherwise loading up multiple plugins fills the log with subroutine redefine warnings
22
no warnings 'redefine'; # otherwise loading up multiple plugins fills the log with subroutine redefine warnings
23
23
24
use C4::Debug;
24
use C4::Context;
25
use C4::Context;
25
require C4::Dates;
26
require C4::Dates;
26
27
27
use Algorithm::CheckDigits;
28
use Algorithm::CheckDigits;
28
29
29
my $DEBUG = 0;
30
31
=head1
30
=head1
32
31
33
plugin_parameters : other parameters added when the plugin is called by the dopop function
32
plugin_parameters : other parameters added when the plugin is called by the dopop function
Lines 67-73 sub plugin_javascript { Link Here
67
	my $query;
66
	my $query;
68
    my $scr;
67
    my $scr;
69
	my $autoBarcodeType = C4::Context->preference("autoBarcode");
68
	my $autoBarcodeType = C4::Context->preference("autoBarcode");
70
    warn "Barcode type = $autoBarcodeType" if $DEBUG;
69
    warn "Barcode type = $autoBarcodeType" if $debug;
71
	if ((not $autoBarcodeType) or $autoBarcodeType eq 'OFF') {
70
	if ((not $autoBarcodeType) or $autoBarcodeType eq 'OFF') {
72
        # don't return a value unless we have the appropriate syspref set
71
        # don't return a value unless we have the appropriate syspref set
73
		return ($function_name, 
72
		return ($function_name, 
Lines 83-89 sub plugin_javascript { Link Here
83
		my $sth=$dbh->prepare($query);
82
		my $sth=$dbh->prepare($query);
84
		$sth->execute("$year%");
83
		$sth->execute("$year%");
85
		while (my ($count)= $sth->fetchrow_array) {
84
		while (my ($count)= $sth->fetchrow_array) {
86
            warn "Examining Record: $count" if $DEBUG;
85
            warn "Examining Record: $count" if $debug;
87
    		$nextnum = $count if $count;
86
    		$nextnum = $count if $count;
88
		}
87
		}
89
		$nextnum++;
88
		$nextnum++;
Lines 100-105 sub plugin_javascript { Link Here
100
		}
99
		}
101
		$nextnum++;
100
		$nextnum++;
102
    }
101
    }
102
103
103
    elsif ($autoBarcodeType eq 'hbyymmincr') {      # Generates a barcode where hb = home branch Code, yymm = year/month catalogued, incr = incremental number, reset yearly -fbcit
104
    elsif ($autoBarcodeType eq 'hbyymmincr') {      # Generates a barcode where hb = home branch Code, yymm = year/month catalogued, incr = incremental number, reset yearly -fbcit
104
        $year = substr($year, -2);
105
        $year = substr($year, -2);
105
        $query = "SELECT MAX(CAST(SUBSTRING(barcode,-4) AS signed)) AS number FROM items WHERE barcode REGEXP ?";
106
        $query = "SELECT MAX(CAST(SUBSTRING(barcode,-4) AS signed)) AS number FROM items WHERE barcode REGEXP ?";
Lines 108-119 sub plugin_javascript { Link Here
108
        while (my ($count)= $sth->fetchrow_array) {
109
        while (my ($count)= $sth->fetchrow_array) {
109
            $nextnum = $count if $count;
110
            $nextnum = $count if $count;
110
            $nextnum = 0 if $nextnum == 9999; # this sequence only allows for cataloging 10000 books per month
111
            $nextnum = 0 if $nextnum == 9999; # this sequence only allows for cataloging 10000 books per month
111
            warn "Existing incremental number = $nextnum" if $DEBUG;
112
            warn "Existing incremental number = $nextnum" if $debug;
112
        }
113
        }
113
        $nextnum++;
114
        $nextnum++;
114
        $nextnum = sprintf("%0*d", "4",$nextnum);
115
        $nextnum = sprintf("%0*d", "4",$nextnum);
115
        $nextnum = $year . $mon . $nextnum;
116
        $nextnum = $year . $mon . $nextnum;
116
        warn "New hbyymmincr Barcode = $nextnum" if $DEBUG;
117
        warn "New hbyymmincr Barcode = $nextnum" if $debug;
118
        $scr = " 
119
        for (i=0 ; i<document.f.field_value.length ; i++) {
120
            if (document.f.tag[i].value == '$loctag' && document.f.subfield[i].value == '$locsubfield') {
121
                fnum = i;
122
            }
123
        }
124
        if (\$('#' + id).val() == '' || force) {
125
            \$('#' + id).val(document.f.field_value[fnum].value + '$nextnum');
126
        }
127
        ";
128
    }
129
130
    elsif ($autoBarcodeType eq 'hbincr') {      # Generates a barcode where hb = home branch Code, incr = an 8 digit incremental number
131
132
        $query = "SELECT MAX(CAST(SUBSTRING(barcode,-8) AS signed)) AS number FROM items WHERE barcode REGEXP ?";
133
        my $sth = $dbh->prepare($query);
134
        $sth->execute("^[-a-zA-Z]{1,}");
135
        while (my ($count)= $sth->fetchrow_array) {
136
            $nextnum = $count if $count;
137
138
            warn "Existing incremental number = $nextnum" if $debug;
139
        }
140
        $nextnum++;
141
        $nextnum = sprintf("%0*d", "8",$nextnum);
142
        $nextnum =  $nextnum;
143
        warn "New hbincr Barcode = $nextnum" if $debug;
117
        $scr = " 
144
        $scr = " 
118
        for (i=0 ; i<document.f.field_value.length ; i++) {
145
        for (i=0 ; i<document.f.field_value.length ; i++) {
119
            if (document.f.tag[i].value == '$loctag' && document.f.subfield[i].value == '$locsubfield') {
146
            if (document.f.tag[i].value == '$loctag' && document.f.subfield[i].value == '$locsubfield') {
Lines 147-152 sub plugin_javascript { Link Here
147
        warn "ERROR: unknown autoBarcode: $autoBarcodeType";
174
        warn "ERROR: unknown autoBarcode: $autoBarcodeType";
148
    }
175
    }
149
176
177
150
    # default js body (if not filled by hbyymmincr)
178
    # default js body (if not filled by hbyymmincr)
151
    $scr or $scr = <<END_OF_JS;
179
    $scr or $scr = <<END_OF_JS;
152
if (\$('#' + id).val() == '' || force) {
180
if (\$('#' + id).val() == '' || force) {
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref (-1 / +1 lines)
Lines 94-99 Cataloging: Link Here
94
                  annual: generated in the form &lt;year&gt;-0001, &lt;year&gt;-0002.
94
                  annual: generated in the form &lt;year&gt;-0001, &lt;year&gt;-0002.
95
                  hbyymmincr: generated in the form &lt;branchcode&gt;yymm0001.
95
                  hbyymmincr: generated in the form &lt;branchcode&gt;yymm0001.
96
                  EAN13: incremental EAN-13 barcodes
96
                  EAN13: incremental EAN-13 barcodes
97
                  hbincr: generated in the form &lt;branchcode&gt;00000001.
97
                  "OFF": not generated automatically.
98
                  "OFF": not generated automatically.
98
    Display:
99
    Display:
99
        -
100
        -
100
- 

Return to bug 8691