Bugzilla – Attachment 11836 Details for
Bug 8691
Add a new 'hbincr' barcode plugin for cataloging
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 8691 - add a new 'hbincr' barcode plugin, for cataloging
Bug-8691---add-a-new-hbincr-barcode-plugin-for-cat.patch (text/plain), 9.94 KB, created by
Mason James
on 2012-08-27 01:20:12 UTC
(
hide
)
Description:
Bug 8691 - add a new 'hbincr' barcode plugin, for cataloging
Filename:
MIME Type:
Creator:
Mason James
Created:
2012-08-27 01:20:12 UTC
Size:
9.94 KB
patch
obsolete
>From 2c6b67229a29049776aa47fb758ea336c828c8fd Mon Sep 17 00:00:00 2001 >From: Mason James <mtj@kohaaloha.com> >Date: Mon, 27 Aug 2012 13:14:02 +1200 >Subject: [PATCH] Bug 8691 - add a new 'hbincr' barcode plugin, for cataloging >Content-Type: text/plain; charset="utf-8" >http://koha-community.org > >--- > C4/Barcodes.pm | 3 + > C4/Barcodes/hbincr.pm | 129 ++++++++++++++++++++ > cataloguing/value_builder/barcode.pl | 40 +++++- > .../en/modules/admin/preferences/cataloguing.pref | 1 + > 4 files changed, 167 insertions(+), 6 deletions(-) > create mode 100644 C4/Barcodes/hbincr.pm > >diff --git a/C4/Barcodes.pm b/C4/Barcodes.pm >index 2e81da6..5fa0a68 100644 >--- a/C4/Barcodes.pm >+++ b/C4/Barcodes.pm >@@ -1,6 +1,7 @@ > package C4::Barcodes; > > # Copyright 2008 LibLime >+# Copyright 2012 KohaAloha > # > # This file is part of Koha. > # >@@ -26,6 +27,7 @@ use C4::Context; > use C4::Debug; > use C4::Dates; > use C4::Barcodes::hbyymmincr; >+use C4::Barcodes::hbincr; > use C4::Barcodes::annual; > use C4::Barcodes::incremental; > use C4::Barcodes::EAN13; >@@ -177,6 +179,7 @@ our $types = { > annual => sub {C4::Barcodes::annual->new_object(@_); }, > incremental => sub {C4::Barcodes::incremental->new_object(@_);}, > hbyymmincr => sub {C4::Barcodes::hbyymmincr->new_object(@_); }, >+ hbincr => sub {C4::Barcodes::hbincr->new_object(@_); }, > OFF => sub {C4::Barcodes::OFF->new_object(@_); }, > EAN13 => sub {C4::Barcodes::EAN13->new_object(@_); }, > }; >diff --git a/C4/Barcodes/hbincr.pm b/C4/Barcodes/hbincr.pm >new file mode 100644 >index 0000000..e457750 >--- /dev/null >+++ b/C4/Barcodes/hbincr.pm >@@ -0,0 +1,129 @@ >+package C4::Barcodes::hbincr; >+ >+# Copyright 2012 KohaAloha >+# >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it under the >+# terms of the GNU General Public License as published by the Free Software >+# Foundation; either version 2 of the License, or (at your option) any later >+# version. >+# >+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY >+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR >+# A PARTICULAR PURPOSE. See the GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License along >+# with Koha; if not, write to the Free Software Foundation, Inc., >+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. >+ >+use strict; >+use warnings; >+ >+use Carp; >+ >+use C4::Context; >+use C4::Debug; >+use C4::Dates; >+ >+#use Smart::Comments '####'; >+ >+use vars qw($VERSION @ISA); >+use vars qw($debug $cgi_debug); # from C4::Debug, of course >+use vars qw($branch $width); >+ >+BEGIN { >+ # $VERSION = 0.01; >+ @ISA = qw(C4::Barcodes); >+} >+ >+INIT { >+ $branch = ''; >+ $width = 8; >+} >+ >+# Generates barcode where hb = homebranch code, incr = an 8 digit number incremental number >+ >+sub db_max ($;$) { >+ my $self = shift; >+ my $query = >+"SELECT MAX(SUBSTRING(barcode,-$width)), barcode FROM items WHERE barcode REGEXP ? GROUP BY barcode"; >+ $debug and print STDERR "(hbincr) db_max query: $query\n"; >+ my $sth = C4::Context->dbh->prepare($query); >+ >+ $sth->execute("^[a-zA-Z]{1,}"); >+ unless ( $sth->rows ) { >+ warn "No existing hbincr barcodes found. Reverting to initial value."; >+ return $self->initial; >+ } >+ >+ my ($row) = $sth->fetchrow_hashref; >+ my $max = $row->{barcode}; >+ warn "barcode max (hbincr format): $max" if $debug; >+ return ( $max || 0 ); >+} >+ >+sub initial () { >+ my $self = shift; >+ return $self->branch; >+} >+ >+sub parse ($;$) >+{ # return 3 parts of barcode: non-incrementing, incrementing, non-incrementing >+ my $self = shift; >+ my $barcode = (@_) ? shift : $self->value; >+ my $branch = $self->branch; >+ unless ( $barcode =~ /($branch)(\d+)$/ ) { >+ carp "Barcode '$barcode' has no incrementing part!"; >+ return ( $barcode, undef, undef ); >+ } >+ $debug and warn "Barcode '$barcode' parses into: '$1', '$2', ''"; >+ return ( $1, $2, '' ) >+ ; # the third part is in anticipation of barcodes that include checkdigits >+} >+ >+sub branch ($;$) { >+ my $self = shift; >+ (@_) and $self->{branch} = shift; >+ return $self->{branch}; >+} >+ >+sub width ($;$) { >+ my $self = shift; >+ (@_) and $width = shift; # hitting the class variable. >+ return $width; >+} >+ >+sub process_head($$;$$) { # (self,head,whole,specific) >+ my ( $self, $head, $whole, $specific ) = @_; >+ $specific >+ and return >+ $head >+ ; # if this is built off an existing barcode, just return the head unchanged. >+ $head =~ s/\d{8}$//; # else strip the old >+ # my $iso = C4::Dates->new->output('iso'); # like "2008-07-02" >+ return $head; >+} >+ >+sub new_object { >+ $debug and warn "hbincr: new_object called"; >+ my $class_or_object = shift; >+ my $type = ref($class_or_object) || $class_or_object; >+ my $from_obj = >+ ref($class_or_object) >+ ? 1 >+ : 0; # are we building off another Barcodes object? >+ my $self = $class_or_object->default_self('hbincr'); >+ bless $self, $type; >+ $self->branch( >+ @_ ? shift : $from_obj ? $class_or_object->branch : $branch ); >+ >+ # take the branch from argument, or existing object, or default >+ use Data::Dumper; >+ $debug and print STDERR "(hbincr) new_object: ", Dumper($self), "\n"; >+ return $self; >+} >+ >+1; >+__END__ >+ >diff --git a/cataloguing/value_builder/barcode.pl b/cataloguing/value_builder/barcode.pl >index 0ec6b62..f4edcc9 100755 >--- a/cataloguing/value_builder/barcode.pl >+++ b/cataloguing/value_builder/barcode.pl >@@ -21,13 +21,12 @@ use strict; > use warnings; > no warnings 'redefine'; # otherwise loading up multiple plugins fills the log with subroutine redefine warnings > >+use C4::Debug; > use C4::Context; > require C4::Dates; > > use Algorithm::CheckDigits; > >-my $DEBUG = 0; >- > =head1 > > plugin_parameters : other parameters added when the plugin is called by the dopop function >@@ -67,7 +66,7 @@ sub plugin_javascript { > my $query; > my $scr; > my $autoBarcodeType = C4::Context->preference("autoBarcode"); >- warn "Barcode type = $autoBarcodeType" if $DEBUG; >+ warn "Barcode type = $autoBarcodeType" if $debug; > if ((not $autoBarcodeType) or $autoBarcodeType eq 'OFF') { > # don't return a value unless we have the appropriate syspref set > return ($function_name, >@@ -83,7 +82,7 @@ sub plugin_javascript { > my $sth=$dbh->prepare($query); > $sth->execute("$year%"); > while (my ($count)= $sth->fetchrow_array) { >- warn "Examining Record: $count" if $DEBUG; >+ warn "Examining Record: $count" if $debug; > $nextnum = $count if $count; > } > $nextnum++; >@@ -100,6 +99,8 @@ sub plugin_javascript { > } > $nextnum++; > } >+ >+ > elsif ($autoBarcodeType eq 'hbyymmincr') { # Generates a barcode where hb = home branch Code, yymm = year/month catalogued, incr = incremental number, reset yearly -fbcit > $year = substr($year, -2); > $query = "SELECT MAX(CAST(SUBSTRING(barcode,-4) AS signed)) AS number FROM items WHERE barcode REGEXP ?"; >@@ -108,12 +109,38 @@ sub plugin_javascript { > while (my ($count)= $sth->fetchrow_array) { > $nextnum = $count if $count; > $nextnum = 0 if $nextnum == 9999; # this sequence only allows for cataloging 10000 books per month >- warn "Existing incremental number = $nextnum" if $DEBUG; >+ warn "Existing incremental number = $nextnum" if $debug; > } > $nextnum++; > $nextnum = sprintf("%0*d", "4",$nextnum); > $nextnum = $year . $mon . $nextnum; >- warn "New hbyymmincr Barcode = $nextnum" if $DEBUG; >+ warn "New hbyymmincr Barcode = $nextnum" if $debug; >+ $scr = " >+ for (i=0 ; i<document.f.field_value.length ; i++) { >+ if (document.f.tag[i].value == '$loctag' && document.f.subfield[i].value == '$locsubfield') { >+ fnum = i; >+ } >+ } >+ if (\$('#' + id).val() == '' || force) { >+ \$('#' + id).val(document.f.field_value[fnum].value + '$nextnum'); >+ } >+ "; >+ } >+ >+ elsif ($autoBarcodeType eq 'hbincr') { # Generates a barcode where hb = home branch Code, incr = an 8 digit incremental number >+ >+ $query = "SELECT MAX(CAST(SUBSTRING(barcode,-8) AS signed)) AS number FROM items WHERE barcode REGEXP ?"; >+ my $sth = $dbh->prepare($query); >+ $sth->execute("^[-a-zA-Z]{1,}"); >+ while (my ($count)= $sth->fetchrow_array) { >+ $nextnum = $count if $count; >+ >+ warn "Existing incremental number = $nextnum" if $debug; >+ } >+ $nextnum++; >+ $nextnum = sprintf("%0*d", "8",$nextnum); >+ $nextnum = $nextnum; >+ warn "New hbincr Barcode = $nextnum" if $debug; > $scr = " > for (i=0 ; i<document.f.field_value.length ; i++) { > if (document.f.tag[i].value == '$loctag' && document.f.subfield[i].value == '$locsubfield') { >@@ -147,6 +174,7 @@ sub plugin_javascript { > warn "ERROR: unknown autoBarcode: $autoBarcodeType"; > } > >+ > # default js body (if not filled by hbyymmincr) > $scr or $scr = <<END_OF_JS; > if (\$('#' + id).val() == '' || force) { >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref >index c683da7..7e4c088 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref >@@ -94,6 +94,7 @@ Cataloging: > annual: generated in the form <year>-0001, <year>-0002. > hbyymmincr: generated in the form <branchcode>yymm0001. > EAN13: incremental EAN-13 barcodes >+ hbincr: generated in the form <branchcode>00000001. > "OFF": not generated automatically. > Display: > - >-- >1.7.2.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 8691
: 11836