From 7f8bb91beb94c45cec72845d8d63d90f24070b46 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 Signed-off-by: Andrew Fuerste-Henry Signed-off-by: Rebecca Coert --- cataloguing/additem.pl | 61 +++++++++++++++---- .../prog/en/modules/cataloguing/additem.tt | 30 +++++++++ .../prog/js/cataloging_additem.js | 20 ++++++ 3 files changed, 98 insertions(+), 13 deletions(-) diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl index a2aea9b6ee..e55d926abc 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 { @@ -408,6 +438,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); @@ -516,6 +548,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) { @@ -616,6 +649,7 @@ if ($op eq "additem") { my ( $oldbiblionumber, $oldbibnum, $oldbibitemnum ) = AddItemFromMarc( $record, $biblionumber, { skip_modzebra_update => 1 } ); 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 @@ -976,6 +1010,7 @@ foreach my $tag ( keys %{$tagslib}){ # 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 9e506c72ca..cf2e442693 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt @@ -19,6 +19,9 @@ [% INCLUDE 'calendar.inc' %] [% INCLUDE 'str/cataloging_additem.inc' %] [% Asset.js("js/cataloging_additem.js") | $raw %] + @@ -231,6 +234,33 @@ +[% IF volumes.count && op != 'saveitem' %] +
+ Add to volume + +

+ + +

+ +

+ + + Required +

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