From 803b2461d00892ac2530378feacbeef06c056e1e 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 b8face6d22..cde3d92f8d 100755 --- a/cataloguing/additem.pl +++ b/cataloguing/additem.pl @@ -22,28 +22,30 @@ 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 Koha::SearchEngine::Indexer; -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; @@ -87,6 +89,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 { @@ -419,6 +449,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); @@ -527,6 +559,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) { @@ -627,6 +660,7 @@ if ($op eq "additem") { my ( $oldbiblionumber, $oldbibnum, $oldbibitemnum ) = AddItemFromMarc( $record, $biblionumber, { skip_record_index => 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 @@ -997,6 +1031,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 d4581936da..347099a2da 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt @@ -18,6 +18,9 @@ [% INCLUDE 'calendar.inc' %] [% INCLUDE 'str/cataloging_additem.inc' %] [% Asset.js("js/cataloging_additem.js") | $raw %] + @@ -230,6 +233,33 @@ +[% IF volumes.count && op != 'saveitem' %] +
+ Add to volume + +

+ + +

+ +

+ + + Required +

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