From 583d20caa6f478e7e25c200d89df064455b938a4 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 Signed-off-by: Tomas Cohen Arazi Signed-off-by: Martin Renvoize --- cataloguing/additem.pl | 34 +++++++++++++++++++ .../prog/en/modules/cataloguing/additem.tt | 30 ++++++++++++++++ .../prog/js/cataloging_additem.js | 20 +++++++++++ 3 files changed, 84 insertions(+) diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl index e099215256..62e6c8ecb9 100755 --- a/cataloguing/additem.pl +++ b/cataloguing/additem.pl @@ -43,6 +43,7 @@ use C4::ClassSource qw( GetClassSources GetClassSource ); use Koha::DateUtils qw( dt_from_string ); use Koha::Items; use Koha::ItemTypes; +use Koha::Items; use Koha::Libraries; use Koha::Patrons; use Koha::SearchEngine::Indexer; @@ -84,6 +85,34 @@ sub get_item_from_barcode { return($result); } +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 { @@ -423,6 +452,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); @@ -529,6 +560,7 @@ if ($op eq "additem") { # if barcode exists, don't create, but report The problem. unless ($exist_itemnumber) { my ( $oldbiblionumber, $oldbibnum, $oldbibitemnum ) = AddItemFromMarc( $record, $biblionumber ); + add_item_to_volume( $oldbiblionumber, $oldbibitemnum, $volume, $volume_description ); # Pushing the last created item cookie back if ($prefillitem && defined $record) { @@ -628,6 +660,7 @@ if ($op eq "additem") { if (!$exist_itemnumber) { my ( $oldbiblionumber, $oldbibnum, $oldbibitemnum ) = AddItemFromMarc( $record, $biblionumber, { skip_record_index => 1 } ); + 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 @@ -998,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 bfecf0016c..94bc96352e 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 %] + @@ -238,6 +241,33 @@ +[% IF volumes.count && op != 'saveitem' %] +
+ Add to volume + +

+ + +

+ +

+ + + Required +

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