diff --git a/Koha/Plugin/Com/ByWaterSolutions/ItemMessages.pm b/Koha/Plugin/Com/ByWaterSolutions/ItemMessages.pm index c1bbc0c..37f85eb 100644 --- a/Koha/Plugin/Com/ByWaterSolutions/ItemMessages.pm +++ b/Koha/Plugin/Com/ByWaterSolutions/ItemMessages.pm @@ -154,6 +154,7 @@ sub tool_step2 { my $template = $self->get_template({ file => 'tool-step2.tt' }); my $uploadbarcodes = $cgi->upload('uploadbarcodes'); + my $barcodelist = $cgi->param('barcodelist'); my @barcodes; my @uploadedbarcodes; @@ -165,7 +166,7 @@ sub tool_step2 { push @uploadedbarcodes, grep { /\S/ } split( /[$split_chars]/, $barcode ); } } else { - warn 'NO UPLOADED BARCODES'; + push @uploadedbarcodes, split(/\s\n/, scalar $cgi->param('barcodelist') ); } for my $barcode (@uploadedbarcodes) { @@ -192,7 +193,8 @@ sub tool_step2 { itemnumber => $item->itemnumber, barcode => $item->barcode, title => $biblio->title, - messages => [], # Placeholder for item_messages.message + biblio => $biblio, + messages => [], # Placeholder for item_messages.message type => '', # Placeholder for item_messages.type }; } @@ -240,28 +242,128 @@ sub tool_step3 { my @itemnumbers = $cgi->param('itemnumber'); my $action = $cgi->param('action'); my $type = $cgi->param('type'); + my $delete_type = $cgi->param('delete_type'); my $dbh = C4::Context->dbh; my @updated_items; + my @old_messages; - if ( $action eq 'update' ) { + if ( $action eq 'update_all') { + my $new_message = $cgi->param('new_message_all'); + my $new_type = $cgi->param('new_type_all'); + + my $placeholders = join(',', ('?') x scalar(@itemnumbers)); + + my $fetch_query = qq{ + SELECT itemnumber, message, type + FROM item_messages + WHERE itemnumber IN ($placeholders) + }; + my $fetch_sth = $dbh->prepare($fetch_query); + $fetch_sth->execute(@itemnumbers); + + while (my $row = $fetch_sth->fetchrow_hashref) { + push @old_messages, { + itemnumber => $row->{itemnumber}, + old_message => $row->{message}, + old_type => $row->{type}, + }; + } + $fetch_sth->finish; + + my $delete_query = qq{ + DELETE FROM item_messages + WHERE itemnumber IN ( $placeholders ) + }; + + my $delete_sth = $dbh->prepare($delete_query); + $delete_sth->execute(@itemnumbers); + + my $query = qq{ + INSERT INTO item_messages (itemnumber, message, type) + VALUES (?, ?, ?) + }; + + my $sth = $dbh->prepare($query); + foreach my $itemnumber (@itemnumbers) { + $sth->execute($itemnumber, $new_message, $new_type); + } + + $sth->finish; + + my $select_query = qq{ + SELECT im.item_message_id, im.itemnumber, im.message AS message, im.type, + i.barcode, b.title + FROM item_messages im + JOIN items i ON im.itemnumber = i.itemnumber + LEFT JOIN biblio b ON i.biblionumber = b.biblionumber + WHERE im.itemnumber IN ($placeholders) + }; + + my $select_sth = $dbh->prepare($select_query); + $select_sth->execute(@itemnumbers); + + while (my $row = $select_sth->fetchrow_hashref) { + next unless $row; + push @updated_items, { + item_message_id => $row->{item_message_id}, + itemnumber => $row->{itemnumber}, + barcode => $row->{barcode}, + title => $row->{title}, + message => $row->{message}, + type => $row->{type}, + }; + } + $select_sth->finish; + } elsif ( $action eq 'update' ) { my $new_message = $cgi->param('new_message'); + my $new_type = $cgi->param('new_type'); - unless ($type) { - warn "No type provided!"; + unless ($new_type && $new_message ) { + warn "No message or message type provided!"; return; } my $placeholders = join(',', ('?') x scalar(@itemnumbers)); - my $query = qq{ - UPDATE item_messages - SET message = ? + + my $fetch_query = qq{ + SELECT itemnumber, message, type + FROM item_messages WHERE type = ? - AND item_message_id IN ( $placeholders ) + AND itemnumber IN ($placeholders) + }; + my $fetch_sth = $dbh->prepare($fetch_query); + $fetch_sth->execute($new_type, @itemnumbers); + + while (my $row = $fetch_sth->fetchrow_hashref) { + push @old_messages, { + itemnumber => $row->{itemnumber}, + old_message => $row->{message}, + old_type => $row->{type}, + }; + } + $fetch_sth->finish; + + my $delete_query = qq{ + DELETE FROM item_messages + WHERE type = ? + AND itemnumber IN ( $placeholders ) + }; + + my $delete_sth = $dbh->prepare($delete_query); + $delete_sth->execute($new_type, @itemnumbers); + + my $query = qq{ + INSERT INTO item_messages (itemnumber, message, type) + VALUES (?, ?, ?) }; my $sth = $dbh->prepare($query); - $sth->execute($new_message, $type, @itemnumbers); + foreach my $itemnumber (@itemnumbers) { + $sth->execute($itemnumber, $new_message, $new_type); + } + $sth->finish; + my $select_query = qq{ SELECT im.item_message_id, im.itemnumber, im.message AS message, im.type, i.barcode, b.title @@ -269,11 +371,11 @@ sub tool_step3 { JOIN items i ON im.itemnumber = i.itemnumber LEFT JOIN biblio b ON i.biblionumber = b.biblionumber WHERE im.type = ? - AND im.item_message_id IN ($placeholders) + AND im.itemnumber IN ($placeholders) }; my $select_sth = $dbh->prepare($select_query); - $select_sth->execute($type, @itemnumbers); + $select_sth->execute($new_type, @itemnumbers); while (my $row = $select_sth->fetchrow_hashref) { next unless $row; @@ -286,7 +388,6 @@ sub tool_step3 { type => $row->{type}, }; } - $select_sth->finish; } elsif ( $action eq 'delete' ) { @@ -296,41 +397,50 @@ sub tool_step3 { } my $placeholders = join(',', ('?') x scalar(@itemnumbers)); - - my $select_query = qq{ - SELECT im.item_message_id, im.itemnumber, im.message AS old_message, im.type, - i.barcode, b.title - FROM item_messages im - JOIN items i ON im.itemnumber = i.itemnumber - LEFT JOIN biblio b ON i.biblionumber = b.biblionumber - WHERE im.type = ? - AND im.item_message_id IN ($placeholders) - }; - my $select_sth = $dbh->prepare($select_query); - $select_sth->execute($type, @itemnumbers); - - while (my $row = $select_sth->fetchrow_hashref) { - next unless $row; - - push @updated_items, { - item_message_id => $row->{item_message_id}, - itemnumber => $row->{itemnumber}, - barcode => $row->{barcode}, - title => $row->{title}, - message => $row->{message}, - type => $row->{type}, + my $select_query = qq{ + SELECT im.item_message_id, im.itemnumber, im.message AS old_message, im.type AS old_type, + i.barcode, b.title + FROM item_messages im + JOIN items i ON im.itemnumber = i.itemnumber + LEFT JOIN biblio b ON i.biblionumber = b.biblionumber + WHERE im.type = ? + AND i.itemnumber IN ($placeholders) }; - } - $select_sth->finish; + + my $select_sth = $dbh->prepare($select_query); + $select_sth->execute($delete_type, @itemnumbers); + + while (my $row = $select_sth->fetchrow_hashref) { + next unless $row; + + push @updated_items, { + item_message_id => $row->{item_message_id}, + itemnumber => $row->{itemnumber}, + barcode => $row->{barcode}, + title => $row->{title}, + old_message => $row->{old_message}, + old_type => $row->{old_type}, + }; + } + + $select_sth->finish; my $query = qq{ DELETE FROM item_messages WHERE type = ? - AND item_message_id IN ( $placeholders ) + AND itemnumber IN ( $placeholders ) }; my $sth = $dbh->prepare($query); - $sth->execute($type, @itemnumbers); + $sth->execute($delete_type, @itemnumbers); + } + + if ( $action eq 'update' || $action eq 'update_all' ) { + foreach my $updated_item (@updated_items) { + my ($old_data) = grep { $_->{itemnumber} == $updated_item->{itemnumber} } @old_messages; + $updated_item->{old_message} = $old_data->{old_message} // 'No Previous Message'; + $updated_item->{old_type} = $old_data->{old_type} // 'No Previous Type'; + } } my $count = scalar @updated_items; diff --git a/Koha/Plugin/Com/ByWaterSolutions/ItemMessages/tool-step1.tt b/Koha/Plugin/Com/ByWaterSolutions/ItemMessages/tool-step1.tt index f6ea166..7f2b7cf 100644 --- a/Koha/Plugin/Com/ByWaterSolutions/ItemMessages/tool-step1.tt +++ b/Koha/Plugin/Com/ByWaterSolutions/ItemMessages/tool-step1.tt @@ -53,6 +53,15 @@ +
+ Or scan items one by one +
    +
  1. + + +
  2. +
+
diff --git a/Koha/Plugin/Com/ByWaterSolutions/ItemMessages/tool-step2.tt b/Koha/Plugin/Com/ByWaterSolutions/ItemMessages/tool-step2.tt index 2d18ed9..3fc1b67 100644 --- a/Koha/Plugin/Com/ByWaterSolutions/ItemMessages/tool-step2.tt +++ b/Koha/Plugin/Com/ByWaterSolutions/ItemMessages/tool-step2.tt @@ -13,11 +13,18 @@ [% t("Koha") | html %] [% END %] [% INCLUDE 'doc-head-close.inc' %] + + [% INCLUDE 'header.inc' %] [% PROCESS 'about-team.inc' %] + [% WRAPPER 'sub-header.inc' %] [% WRAPPER breadcrumbs %] [% IF blocking_error %] @@ -35,7 +42,7 @@ [% END #/ WRAPPER breadcrumbs %] [% END #/ WRAPPER sub-header.inc %] -
+

Update item messages

Scanned items:

@@ -53,8 +60,9 @@ [% FOREACH item IN scanned_items %] [% IF item.messages.size > 0 %] [% FOREACH message IN item.messages %] + [% item.biblionumber %] - [% item.title | html %] + [% INCLUDE 'biblio-title.inc' biblio=item.biblio link=1 %] [% item.barcode | html %] [% message.message | html %] [% message.type | html %] @@ -62,7 +70,7 @@ [% END %] [% ELSE %] - [% item.title | html %] + [% INCLUDE 'biblio-title.inc' biblio=item.biblio link=1 %] [% item.barcode | html %] @@ -72,59 +80,124 @@
-
-

Bulk update item messages by type:

- -
- [% FOREACH av IN AuthorisedValues.Get('ITEM_MESSAGE_TYPE' ) %] - [% SET type_options = av.lib_opac.split('\|') %] -
- - [% INCLUDE 'csrf-token.inc' %] - - - [% FOREACH item IN scanned_items %] - [% FOREACH message IN item.messages %] - - [% END %] +
+
+
    +
  1. + + Replace all +
  2. +
  3. + + - - [% IF type_options.size > 1 %] - - [% ELSE %] - + +
  4. +
  5. + + +
    This will REPLACE all scanned item's messages and types regardless of current item message or type.
    +
  6. +
+
+
+
+
+
    +
  1. + + Replace all with type of: + -
-
- - -
- - -
- [% END %] -
-
+ + +
  • + + +
  • + +
    + +
    +
    +
      +
    1. + + Delete all with type of: + +
    2. +
    +
    +
    +
    + +
    +
    - + diff --git a/Koha/Plugin/Com/ByWaterSolutions/ItemMessages/tool-step3.tt b/Koha/Plugin/Com/ByWaterSolutions/ItemMessages/tool-step3.tt index 3d5c59b..9786187 100644 --- a/Koha/Plugin/Com/ByWaterSolutions/ItemMessages/tool-step3.tt +++ b/Koha/Plugin/Com/ByWaterSolutions/ItemMessages/tool-step3.tt @@ -35,7 +35,7 @@ [% END #/ WRAPPER sub-header.inc %]
    - [% IF action == 'update' %] + [% IF action == 'update' || action == 'update_all' %]

    [% updated_count %] item messages were successfully updated!

    [% ELSE %]

    [% updated_count %] item messages were successfully deleted!

    @@ -45,8 +45,10 @@ Title Barcode + Old message New message - Type + Old type + New type @@ -54,12 +56,18 @@ [% item.title | html %] [% item.barcode | html %] - [% IF action == 'update' %] + [% item.old_message | html %] + [% IF action == 'update' || action == 'update_all' %] [% item.message | html %] [% ELSE %] deleted [% END %] - [% item.type | html %] + [% item.old_type | html %] + [% IF action == 'update' || action == 'update_all' %] + [% item.type | html %] + [% ELSE %] + deleted + [% END %] [% END %]