From 5c44e684dd5b16a13710c0965ee0766de3d3da5d Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Mon, 29 Jun 2020 17:13:10 +0400 Subject: [PATCH] Bug 21395: Fix C4/Barcodes/ValueBuilder.pm $DEBUG variable was always set to 0, so it was useless --- C4/Barcodes/ValueBuilder.pm | 135 +++++++++++++++++------------------- 1 file changed, 64 insertions(+), 71 deletions(-) diff --git a/C4/Barcodes/ValueBuilder.pm b/C4/Barcodes/ValueBuilder.pm index 22f21a6214..cf5f80299e 100644 --- a/C4/Barcodes/ValueBuilder.pm +++ b/C4/Barcodes/ValueBuilder.pm @@ -18,93 +18,86 @@ # You should have received a copy of the GNU General Public License # along with Koha; if not, see . -{ - package C4::Barcodes::ValueBuilder::incremental; +package C4::Barcodes::ValueBuilder::incremental; - use Modern::Perl; - use C4::Context; - my $DEBUG = 0; +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; +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; } -{ - package C4::Barcodes::ValueBuilder::hbyymmincr; - use C4::Context; - my $DEBUG = 0; +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 - warn "Existing incremental number = $nextnum" if $DEBUG; +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'); } - $nextnum++; - $nextnum = sprintf("%0*d", "4",$nextnum); - $nextnum = $year . $month . $nextnum; - warn "New hbyymmincr Barcode = $nextnum" if $DEBUG; - 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 ( !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; + if (\$('#' + id).val() == '') { + \$('#' + id).val(form.field_value[fnum].value + '$nextnum'); } + "; + return $nextnum, $scr; } -{ - package C4::Barcodes::ValueBuilder::annual; - use C4::Context; - my $DEBUG = 0; - 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) { - warn "Examining Record: $count" if $DEBUG; - $nextnum = $count if $count; - } - $nextnum++; - $nextnum = sprintf("%0*d", "4",$nextnum); - $nextnum = "$args->{year}-$nextnum"; - return $nextnum; +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; + =head1 Barcodes::ValueBuilder -- 2.20.1