From c6f5de6006357299140bdc61273cc976c4b77b08 Mon Sep 17 00:00:00 2001 From: David Cook Date: Wed, 14 Oct 2020 23:07:45 +0000 Subject: [PATCH] Bug 26683: Decompose C4::Barcodes::ValueBuilder to make Perl critic happy --- C4/Barcodes/ValueBuilder.pm | 82 ++----------------------------- C4/Barcodes/ValueBuilder/annual.pm | 65 +++++++++++++++++++++++++ C4/Barcodes/ValueBuilder/hbyymmincr.pm | 85 +++++++++++++++++++++++++++++++++ C4/Barcodes/ValueBuilder/incremental.pm | 64 +++++++++++++++++++++++++ 4 files changed, 217 insertions(+), 79 deletions(-) create mode 100644 C4/Barcodes/ValueBuilder/annual.pm create mode 100644 C4/Barcodes/ValueBuilder/hbyymmincr.pm create mode 100644 C4/Barcodes/ValueBuilder/incremental.pm diff --git a/C4/Barcodes/ValueBuilder.pm b/C4/Barcodes/ValueBuilder.pm index cf5f80299e..5b47270b8d 100644 --- a/C4/Barcodes/ValueBuilder.pm +++ b/C4/Barcodes/ValueBuilder.pm @@ -1,4 +1,3 @@ -#!/usr/bin/perl # # Copyright 2008-2010 Foundations Bible College # Parts copyright 2012 C & P Bibliography Services @@ -18,86 +17,11 @@ # You should have received a copy of the GNU General Public License # along with Koha; if not, see . -package C4::Barcodes::ValueBuilder::incremental; - use Modern::Perl; -use C4::Context; - -sub get_barcode { - my ($args) = @_; - my $nextnum; - # not the best, two catalogers could add the same barcode easily this way :/ - my $query = "select max(abs(barcode)) from items"; - my $sth = C4::Context->dbh->prepare($query); - $sth->execute(); - while (my ($count)= $sth->fetchrow_array) { - $nextnum = $count; - } - $nextnum++; - return $nextnum; -} - -1; - -package C4::Barcodes::ValueBuilder::hbyymmincr; -use C4::Context; - -sub get_barcode { - my ($args) = @_; - my $nextnum = 0; - my $year = substr($args->{year}, -2); - my $month = $args->{mon}; - my $query = "SELECT MAX(CAST(SUBSTRING(barcode,-4) AS signed)) AS number FROM items WHERE barcode REGEXP ?"; - my $sth = C4::Context->dbh->prepare($query); - $sth->execute("^[-a-zA-Z]{1,}$year$month"); - while (my ($count)= $sth->fetchrow_array) { - $nextnum = $count if $count; - $nextnum = 0 if $nextnum == 9999; # this sequence only allows for cataloging 9999 items per month - } - $nextnum++; - $nextnum = sprintf("%0*d", "4",$nextnum); - $nextnum = $year . $month . $nextnum; - my $scr = " - var form = document.getElementById('f'); - if ( !form ) { - form = document.getElementById('serials_edit'); - } - if ( !form ) { - form = document.getElementById('Aform'); - } - for (i=0 ; i{loctag}' && form.subfield[i].value == '$args->{locsubfield}') { - fnum = i; - } - } - if (\$('#' + id).val() == '') { - \$('#' + id).val(form.field_value[fnum].value + '$nextnum'); - } - "; - return $nextnum, $scr; -} - - -package C4::Barcodes::ValueBuilder::annual; -use C4::Context; - -sub get_barcode { - my ($args) = @_; - my $nextnum; - my $query = "select max(cast( substring_index(barcode, '-',-1) as signed)) from items where barcode like ?"; - my $sth=C4::Context->dbh->prepare($query); - $sth->execute($args->{year} . '-%'); - while (my ($count)= $sth->fetchrow_array) { - $nextnum = $count if $count; - } - $nextnum++; - $nextnum = sprintf("%0*d", "4",$nextnum); - $nextnum = "$args->{year}-$nextnum"; - return $nextnum; -} - -1; +use C4::Barcodes::ValueBuilder::incremental; +use C4::Barcodes::ValueBuilder::hbyymmincr; +use C4::Barcodes::ValueBuilder::annual; =head1 Barcodes::ValueBuilder diff --git a/C4/Barcodes/ValueBuilder/annual.pm b/C4/Barcodes/ValueBuilder/annual.pm new file mode 100644 index 0000000000..ab34387894 --- /dev/null +++ b/C4/Barcodes/ValueBuilder/annual.pm @@ -0,0 +1,65 @@ +# +# Copyright 2008-2010 Foundations Bible College +# Parts copyright 2012 C & P Bibliography Services +# +# 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 3 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, see . + +package C4::Barcodes::ValueBuilder::annual; + +use Modern::Perl; +use C4::Context; + +=head1 API + +=cut + +=head2 Functions + +=cut + +=head3 get_barcode + +This is a function for getting the next barcode + +=cut + +sub get_barcode { + my ($args) = @_; + my $nextnum; + my $query = "select max(cast( substring_index(barcode, '-',-1) as signed)) from items where barcode like ?"; + my $sth=C4::Context->dbh->prepare($query); + $sth->execute($args->{year} . '-%'); + while (my ($count)= $sth->fetchrow_array) { + $nextnum = $count if $count; + } + $nextnum++; + $nextnum = sprintf("%0*d", "4",$nextnum); + $nextnum = "$args->{year}-$nextnum"; + return $nextnum; +} + +=head1 Barcodes::ValueBuilder + +This module is intended as a shim to ease the eventual transition from +having all barcode-related code in the value builder plugin .pl file +to using C4::Barcodes. Since the shift will require a rather significant +amount of refactoring, this module will return value builder-formatted +results, at first by merely running the code that was formerly in the +barcodes.pl value builder, but later by using C4::Barcodes. + +=cut + +1; diff --git a/C4/Barcodes/ValueBuilder/hbyymmincr.pm b/C4/Barcodes/ValueBuilder/hbyymmincr.pm new file mode 100644 index 0000000000..7d277a82c0 --- /dev/null +++ b/C4/Barcodes/ValueBuilder/hbyymmincr.pm @@ -0,0 +1,85 @@ +# +# Copyright 2008-2010 Foundations Bible College +# Parts copyright 2012 C & P Bibliography Services +# +# 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 3 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, see . + +package C4::Barcodes::ValueBuilder::hbyymmincr; + +use Modern::Perl; +use C4::Context; + +=head1 API + +=cut + +=head2 Functions + +=cut + +=head3 get_barcode + +This is a function for getting the next barcode + +=cut + +sub get_barcode { + my ($args) = @_; + my $nextnum = 0; + my $year = substr($args->{year}, -2); + my $month = $args->{mon}; + my $query = "SELECT MAX(CAST(SUBSTRING(barcode,-4) AS signed)) AS number FROM items WHERE barcode REGEXP ?"; + my $sth = C4::Context->dbh->prepare($query); + $sth->execute("^[-a-zA-Z]{1,}$year$month"); + while (my ($count)= $sth->fetchrow_array) { + $nextnum = $count if $count; + $nextnum = 0 if $nextnum == 9999; # this sequence only allows for cataloging 9999 items per month + } + $nextnum++; + $nextnum = sprintf("%0*d", "4",$nextnum); + $nextnum = $year . $month . $nextnum; + my $scr = " + var form = document.getElementById('f'); + if ( !form ) { + form = document.getElementById('serials_edit'); + } + if ( !form ) { + form = document.getElementById('Aform'); + } + for (i=0 ; i{loctag}' && form.subfield[i].value == '$args->{locsubfield}') { + fnum = i; + } + } + if (\$('#' + id).val() == '') { + \$('#' + id).val(form.field_value[fnum].value + '$nextnum'); + } + "; + return $nextnum, $scr; +} + +=head1 Barcodes::ValueBuilder + +This module is intended as a shim to ease the eventual transition from +having all barcode-related code in the value builder plugin .pl file +to using C4::Barcodes. Since the shift will require a rather significant +amount of refactoring, this module will return value builder-formatted +results, at first by merely running the code that was formerly in the +barcodes.pl value builder, but later by using C4::Barcodes. + +=cut + +1; diff --git a/C4/Barcodes/ValueBuilder/incremental.pm b/C4/Barcodes/ValueBuilder/incremental.pm new file mode 100644 index 0000000000..068352c7c3 --- /dev/null +++ b/C4/Barcodes/ValueBuilder/incremental.pm @@ -0,0 +1,64 @@ +# +# Copyright 2008-2010 Foundations Bible College +# Parts copyright 2012 C & P Bibliography Services +# +# 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 3 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, see . + +package C4::Barcodes::ValueBuilder::incremental; + +use Modern::Perl; +use C4::Context; + +=head1 API + +=cut + +=head2 Functions + +=cut + +=head3 get_barcode + +This is a function for getting the next barcode + +=cut + +sub get_barcode { + my ($args) = @_; + my $nextnum; + # not the best, two catalogers could add the same barcode easily this way :/ + my $query = "select max(abs(barcode)) from items"; + my $sth = C4::Context->dbh->prepare($query); + $sth->execute(); + while (my ($count)= $sth->fetchrow_array) { + $nextnum = $count; + } + $nextnum++; + return $nextnum; +} + +=head1 Barcodes::ValueBuilder + +This module is intended as a shim to ease the eventual transition from +having all barcode-related code in the value builder plugin .pl file +to using C4::Barcodes. Since the shift will require a rather significant +amount of refactoring, this module will return value builder-formatted +results, at first by merely running the code that was formerly in the +barcodes.pl value builder, but later by using C4::Barcodes. + +=cut + +1; -- 2.11.0