From f83c7f86553641063725ff0b10d1b3d29a3506a9 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Tue, 8 Mar 2022 12:03:38 +0000 Subject: [PATCH] Bug 24857: Add ability to set item group when adding a new item During cataloging a user may wish to add an item to a group when creating a new item This patch also copies the group description to the enumchron field To test: 1 - Browse to details page for a record 2 - Create or ensure the record has item group(s) 3 - Click New->New item 4 - Note the bottom of the page has a form to attach to existing group, or create new 5 - Note when a group is selected the enumchron field is populated 6 - Confirm item is saved to group when saved Signed-off-by: Tomas Cohen Arazi --- cataloguing/additem.pl | 35 +++++++++++++++++++ .../prog/en/modules/cataloguing/additem.tt | 35 +++++++++++++++++++ .../prog/js/cataloging_additem.js | 27 ++++++++++++++ 3 files changed, 97 insertions(+) diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl index d1db1d15f9..7cf5c03660 100755 --- a/cataloguing/additem.pl +++ b/cataloguing/additem.pl @@ -39,6 +39,7 @@ use C4::Barcodes::ValueBuilder; 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; @@ -57,6 +58,34 @@ use List::MoreUtils qw( any uniq ); our $dbh = C4::Context->dbh; +sub add_item_to_item_group { + my ( $biblionumber, $itemnumber, $item_group, $item_group_description ) = @_; + + return unless $item_group; + + my $item_group_id; + if ( $item_group eq 'create' ) { + my $item_group = Koha::Biblio::ItemGroup->new( + { + biblionumber => $biblionumber, + description => $item_group_description, + } + )->store(); + + $item_group_id = $item_group->id; + } + else { + $item_group_id = $item_group; + } + + my $item_group_item = Koha::Biblio::ItemGroup::Item->new( + { + itemnumber => $itemnumber, + item_group_id => $item_group_id, + } + )->store(); +} + sub get_item_from_cookie { my ( $input ) = @_; @@ -102,6 +131,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'); our $frameworkcode = &GetFrameworkCode($biblionumber); @@ -206,6 +237,7 @@ if ($op eq "additem") { } else { $item->store->discard_changes; + add_item_to_item_group( $item->biblionumber, $item->biblioitemnumber, $volume, $volume_description ); # This is a bit tricky : if there is a cookie for the last created item and # we just added an item, the cookie value is not correct yet (it will be updated @@ -316,6 +348,7 @@ if ($op eq "additem") { { skip_record_index => 1 } ); $current_item->discard_changes; # Cannot chain discard_changes $current_item = $current_item->unblessed; + add_item_to_item_group( $item->biblionumber, $item->biblioitemnumber, $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 @@ -606,10 +639,12 @@ if( my $default_location = C4::Context->preference('NewItemsDefaultLocation') ) $location_field->{marc_value}->{value} ||= $default_location; } +my @ig = Koha::Biblio::ItemGroups->search({ biblio_id => $biblionumber })->as_list(); # what's the next op ? it's what we are not in : an add if we're editing, otherwise, and edit. $template->param( biblio => $biblio, items => \@items, + item_groups => \@ig, item_header_loop => \@header_value_loop, subfields => $subfields, itemnumber => $itemnumber, 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 aa02320f52..31eaf8e3bd 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt @@ -23,6 +23,9 @@ [% INCLUDE 'calendar.inc' %] [% INCLUDE 'str/cataloging_additem.inc' %] [% Asset.js("js/cataloging_additem.js") | $raw %] + @@ -159,6 +162,35 @@ [% END %] +[% IF item_groups.size && op != 'saveitem' && CAN_user_editcatalogue_manage_item_groups %] +
+ Add to item group + [% FOREACH ig IN item_groups %] + + [% END %] +

+ + +

+ +

+ + + Required +

+
+[% END %] +
[% IF op != 'saveitem' %] +[% MACRO jsinclude BLOCK %] +[% END %] + [% INCLUDE 'intranet-bottom.inc' %] diff --git a/koha-tmpl/intranet-tmpl/prog/js/cataloging_additem.js b/koha-tmpl/intranet-tmpl/prog/js/cataloging_additem.js index 0f9311b06f..840a9e45c7 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/cataloging_additem.js +++ b/koha-tmpl/intranet-tmpl/prog/js/cataloging_additem.js @@ -69,6 +69,33 @@ $(document).ready(function(){ multiCopyControl.toggle(); }); + // Add new item to an item group + if ( has_item_groups ) { + $('#item-group-add-or-create-form-description-block').hide(); + $('#item-group-add-or-create-form-no-add').attr('selected', 'selected' ); + + $('#item-group-add-or-create-form-select').on('change', function(){ + if ( $(this).val() == 'create' ) { + $('#item-group-add-or-create-form-description') + .addClass('required') + .attr( 'required', 'required' ); + $('#item-group-add-or-create-form-description-block').show(); + } else { + $('#item-group-add-or-create-form-description') + .removeClass('required') + .removeAttr('required'); + $('#item-group-add-or-create-form-description-block').hide(); + } + }); + } + + $('#item-group-add-or-create-form-select').on('change', function() { + if ( ! $('input.items-enumchron').val() ) { + let item_group_selector = '#item-group-' + $(this).val(); + let enumchron = $(item_group_selector).val(); + $('input.items-enumchron').val( enumchron ); + } + }); }); function Check(f) { -- 2.39.5