X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=labels%2Flabel-edit-batch.pl;h=c5e8f5cd30d4bfe75b6729afd891b2570df5dd38;hb=a8a9c7b7fd75bda5fb9b1ced2cc9600a289b0fa6;hp=fbcfe0a2775252c213b99ca3f266a5bb7091f9d5;hpb=aef1dd15fbe37a8a9c30ba4b38f7ecd6c1fea54d;p=koha_ffzg diff --git a/labels/label-edit-batch.pl b/labels/label-edit-batch.pl index fbcfe0a277..c5e8f5cd30 100755 --- a/labels/label-edit-batch.pl +++ b/labels/label-edit-batch.pl @@ -5,36 +5,35 @@ # # 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 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. +# 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. +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . use strict; use warnings; use vars qw($debug); -use CGI; +use CGI qw ( -utf8 ); use C4::Auth qw(get_template_and_user); use C4::Output qw(output_html_with_http_headers); -use C4::Branch qw(get_branch_code_from_name); -use C4::Items qw(GetItemnumberFromBarcode); -use C4::Creators 1.000000; -use C4::Labels 1.000000; +use C4::Items qw(GetItem GetItemnumberFromBarcode); +use C4::Creators; +use C4::Labels; my $cgi = new CGI; my ( $template, $loggedinuser, $cookie ) = get_template_and_user( { - template_name => "labels/label-edit-batch.tmpl", + template_name => "labels/label-edit-batch.tt", query => $cgi, type => "intranet", authnotrequired => 0, @@ -58,11 +57,12 @@ my $display_columns = [ {_label_number => {label => 'Label Number', link_field my $op = $cgi->param('op') || 'edit'; my @label_ids; my @item_numbers; -my $barcode; -my $batch_id = $cgi->param('element_id') || $cgi->param('batch_id') || undef; +my $number_list; +my $number_type = $cgi->param('number_type') || "barcode"; +my $batch_id = $cgi->param('element_id') || $cgi->param('batch_id') || 0; @label_ids = $cgi->param('label_id') if $cgi->param('label_id'); @item_numbers = $cgi->param('item_number') if $cgi->param('item_number'); -$barcode = $cgi->param('barcode') if $cgi->param('barcode'); +$number_list = $cgi->param('number_list') if $cgi->param('number_list'); my $branch_code = C4::Context->userenv->{'branch'}; @@ -81,21 +81,27 @@ elsif ($op eq 'delete') { $errstr = "batch $batch_id was not deleted." if $err; } elsif ($op eq 'add') { - if ($barcode) { - my @barcodes = split /\n/, $barcode; # $barcode is effectively passed in as a separated list - foreach my $number (@barcodes) { + if ($number_list) { + my @numbers_list = split /\n/, $number_list; # Entries are effectively passed in as a separated list + foreach my $number (@numbers_list) { $number =~ s/\r$//; # strip any naughty return chars - if (my $item_number = GetItemnumberFromBarcode($number)) { # we must test in case an invalid barcode is passed in; we effectively disgard them atm - push @item_numbers, $item_number; + if( $number_type eq "itemnumber" && GetItem($number) ) { + push @item_numbers, $number; + } + elsif ($number_type eq "barcode" ) { # we must test in case an invalid barcode is passed in; we effectively disgard them atm + if( my $item_number = GetItemnumberFromBarcode($number) ){ + push @item_numbers, $item_number; + } } } } - $batch = C4::Labels::Batch->retrieve(batch_id => $batch_id); - $batch = C4::Labels::Batch->new(branch_code => $branch_code) if $batch == -2; + if ($batch_id != 0) {$batch = C4::Labels::Batch->retrieve(batch_id => $batch_id);} + if ($batch_id == 0 || $batch == -2) {$batch = C4::Labels::Batch->new(branch_code => $branch_code);} if ($branch_code){ foreach my $item_number (@item_numbers) { $err = $batch->add_item($item_number); } + $batch_id = $batch->get_attr('batch_id') if $batch_id == 0; #update batch_id if we added to a new batch $errstr = "item(s) not added to batch $batch_id." if $err; } else {