From a5df5fab0af0545047821dc5466b28223369422d Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Wed, 26 Feb 2020 13:20:45 -0500 Subject: [PATCH] Bug 24857: Add ability to attach newly cataloged items to a volume --- cataloguing/additem.pl | 61 +++++++++++++++---- .../prog/en/modules/cataloguing/additem.tt | 30 +++++++++ .../prog/js/cataloging_additem.js | 21 +++++++ 3 files changed, 99 insertions(+), 13 deletions(-) diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl index ec27c1a426..730477fdf2 100755 --- a/cataloguing/additem.pl +++ b/cataloguing/additem.pl @@ -22,27 +22,29 @@ use Modern::Perl; use CGI qw ( -utf8 ); +use List::MoreUtils qw/any/; +use MARC::File::XML; +use Storable qw(thaw freeze); +use URI::Escape; + use C4::Auth; -use C4::Output; use C4::Biblio; -use C4::Items; -use C4::Context; use C4::Circulation; -use C4::Koha; use C4::ClassSource; +use C4::Context; +use C4::Items; +use C4::Koha; +use C4::Members; +use C4::Output; +use C4::Search; + +use Koha::Biblio::Volume::Items; +use Koha::Biblio::Volumes; use Koha::DateUtils; -use Koha::Items; use Koha::ItemTypes; +use Koha::Items; use Koha::Libraries; use Koha::Patrons; -use List::MoreUtils qw/any/; -use C4::Search; -use Storable qw(thaw freeze); -use URI::Escape; -use C4::Members; - -use MARC::File::XML; -use URI::Escape; our $dbh = C4::Context->dbh; @@ -86,6 +88,34 @@ sub set_item_default_location { $item->store; } +sub add_item_to_volume { + my ( $biblionumber, $itemnumber, $volume, $volume_description ) = @_; + + return unless $volume; + + my $volume_id; + if ( $volume eq 'create' ) { + my $volume = Koha::Biblio::Volume->new( + { + biblionumber => $biblionumber, + description => $volume_description, + } + )->store(); + + $volume_id = $volume->id; + } + else { + $volume_id = $volume; + } + + my $volume_item = Koha::Biblio::Volume::Item->new( + { + itemnumber => $itemnumber, + volume_id => $volume_id, + } + )->store(); +} + # NOTE: This code is subject to change in the future with the implemenation of ajax based autobarcode code # NOTE: 'incremental' is the ONLY autoBarcode option available to those not using javascript sub _increment_barcode { @@ -390,6 +420,8 @@ my $fa_barcode = $input->param('barcode'); my $fa_branch = $input->param('branch'); my $fa_stickyduedate = $input->param('stickyduedate'); my $fa_duedatespec = $input->param('duedatespec'); +my $volume = $input->param('volume'); +my $volume_description = $input->param('volume_description'); my $frameworkcode = &GetFrameworkCode($biblionumber); @@ -499,6 +531,7 @@ if ($op eq "additem") { unless ($exist_itemnumber) { my ( $oldbiblionumber, $oldbibnum, $oldbibitemnum ) = AddItemFromMarc( $record, $biblionumber ); set_item_default_location($oldbibitemnum); + add_item_to_volume( $oldbiblionumber, $oldbibitemnum, $volume, $volume_description ); # Pushing the last created item cookie back if ($prefillitem && defined $record) { @@ -598,6 +631,7 @@ if ($op eq "additem") { if (!$exist_itemnumber) { my ($oldbiblionumber,$oldbibnum,$oldbibitemnum) = AddItemFromMarc($record,$biblionumber); set_item_default_location($oldbibitemnum); + add_item_to_volume( $oldbiblionumber, $oldbibitemnum, $volume, $volume_description ); # We count the item only if it was really added # That way, all items are added, even if there was some already existing barcodes @@ -953,6 +987,7 @@ my $item = Koha::Items->find($itemnumber); # We certainly want to fetch it earli # what's the next op ? it's what we are not in : an add if we're editing, otherwise, and edit. $template->param( + volumes => scalar Koha::Biblio::Volumes->search({ biblionumber => $biblionumber }), biblionumber => $biblionumber, title => $oldrecord->{title}, author => $oldrecord->{author}, diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt index 9862aa4b8d..32524af0d7 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt @@ -15,6 +15,9 @@ [% INCLUDE 'calendar.inc' %] [% INCLUDE 'str/cataloging_additem.inc' %] [% Asset.js("js/cataloging_additem.js") | $raw %] + @@ -213,6 +216,33 @@ +[% IF volumes.count && op != 'saveitem' %] +
+ Add to volume + +

+ + +

+ +

+ + + Required +

+
+[% END %] +
[% IF op != 'saveitem' %]