From e40a836b1a7c5d972a296234b6d11d09db80bc2d Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Fri, 5 Feb 2021 16:01:54 +1300 Subject: [PATCH] Bug 17748: Show due date and availability in item search results MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This enhancement adds the availability of an item to the item search results (i.e. shows if checked out, available on the shelf, or not available for checkout for some other reason). If checked out, also shows due date in item search results. Both the new availability and due date columns will also show when exporting results to a CSV file. To test: 1) Apply patch and restart services 2) Set up three items. Check out Item A to a borrower. Set Item B to some damaged, notforloan, withdrawn etc status so that it is considered not available. Leave Item C as is, not checked out, and not unavailable status. 3) Go to Search -> Item search. Scroll down and notice the Availability radio options - Ignore, Checked out, and Available. 4) Leave the Ignore option selected and do a search so that all three items show. 5) Confirm the availability and due date columns are showing at the right end of the table. Confirm Item A says Checked out and has a due date. Confirm Item B says Not available. Confirm Item C says available. 6) Export all result to CSV. Confirm the results show in the CSV file as expected. 7) Go to edit your search. Select the 'Checked out' radio option for Availability and submit the search. Confirm only Item A shows in the results (not Items B and C). 8) Go to edit your search. Select the 'Available' radio option for Availability and submit the search. Confirm only Item B shows in the results (not Items A and C). Sponsored-by: Bibliotheksservice-Zentrum Baden-Württemberg (BSZ) --- C4/Items.pm | 9 +++++++-- catalogue/itemsearch.pl | 19 ++++++++++++++++++- .../en/includes/catalogue/itemsearch_item.csv.inc | 5 +++++ .../en/includes/catalogue/itemsearch_item.json.inc | 3 +++ .../en/includes/csv_headers/catalogue/itemsearch.tt | 4 ++++ .../prog/en/modules/catalogue/itemsearch.tt | 16 ++++++++++++++++ 6 files changed, 53 insertions(+), 3 deletions(-) diff --git a/C4/Items.pm b/C4/Items.pm index aecf96af1f..e442e7ec58 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -1350,7 +1350,7 @@ sub _SearchItems_build_where_fragment { my @columns = Koha::Database->new()->schema()->resultset('Item')->result_source->columns; push @columns, Koha::Database->new()->schema()->resultset('Biblio')->result_source->columns; push @columns, Koha::Database->new()->schema()->resultset('Biblioitem')->result_source->columns; - my @operators = qw(= != > < >= <= like); + my @operators = qw(= != > < >= <= is like); push @operators, 'not like'; my $field = $filter->{field} // q{}; if ( (0 < grep { $_ eq $field } @columns) or (substr($field, 0, 5) eq 'marc:') ) { @@ -1411,6 +1411,11 @@ sub _SearchItems_build_where_fragment { str => "$column $op (" . join (',', ('?') x @$query) . ")", args => $query, }; + } elsif ( $op eq 'is' ) { + $where_fragment = { + str => "$column $op $query", + args => [], + }; } else { $where_fragment = { str => "$column $op ?", @@ -1443,7 +1448,7 @@ A filter has the following keys: =item * query: the value to search in this column -=item * operator: comparison operator. Can be one of = != > < >= <= like 'not like' +=item * operator: comparison operator. Can be one of = != > < >= <= like 'not like' is =back diff --git a/catalogue/itemsearch.pl b/catalogue/itemsearch.pl index f5f66fe349..310e42c26b 100755 --- a/catalogue/itemsearch.pl +++ b/catalogue/itemsearch.pl @@ -63,7 +63,7 @@ if (defined $format and $format eq 'json') { push @f, $columns[$i]; push @c, 'and'; - if ( grep { $_ eq $columns[$i] } qw( ccode homebranch holdingbranch location itype notforloan itemlost ) ) { + if ( grep { $_ eq $columns[$i] } qw( ccode homebranch holdingbranch location itype notforloan itemlost onloan ) ) { push @q, "$word"; push @op, '='; } else { @@ -186,6 +186,21 @@ if (scalar keys %params > 0) { } } + # null/is not null parameters + foreach my $p (qw( onloan )) { + my $v = $cgi->param($p) // ''; + my $f = { + field => $p, + operator => "is", + }; + if ( $v eq 'IS NOT NULL' ) { + $f->{query} = "not null"; + } elsif ( $v eq 'IS NULL' ) { + $f->{query} = "null"; + } + push @{ $filter->{filters} }, $f unless ( $v eq "" ); + } + if (my $itemcallnumber_from = scalar $cgi->param('itemcallnumber_from')) { push @{ $filter->{filters} }, { field => 'itemcallnumber', @@ -231,6 +246,8 @@ if (scalar keys %params > 0) { my $biblio = Koha::Biblios->find( $item->{biblionumber} ); $item->{biblio} = $biblio; $item->{biblioitem} = $biblio->biblioitem->unblessed; + my $checkout = Koha::Checkouts->find({ itemnumber => $item->{itemnumber} }); + $item->{checkout} = $checkout; } } diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/catalogue/itemsearch_item.csv.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/catalogue/itemsearch_item.csv.inc index 739c145cb5..705e2716a2 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/catalogue/itemsearch_item.csv.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/catalogue/itemsearch_item.csv.inc @@ -1,6 +1,7 @@ [%- USE raw -%] [%- USE Branches -%] [%- USE Koha -%] +[%- USE KohaDates -%] [%- USE ItemTypes -%] [%- USE AuthorisedValues -%] [%- SET biblio = item.biblio -%] @@ -35,3 +36,7 @@ "[% AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.withdrawn', authorised_value => item.withdrawn ) || "" | replace('"', '""') | $raw %]" [%- delimiter | $raw -%] "[% (item.issues || 0) | $raw %]" +[%- delimiter | $raw -%] +"[% IF item.onloan %]Checked out[% ELSIF item.withdrawn || item.damaged || item.notforloan || item.itemlost %]Not available[% ELSE %]Available[% END %]" +[%- delimiter | $raw -%] +"[% IF item.checkout %][% item.checkout.date_due | $KohaDates | $raw %][% END %]" diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/catalogue/itemsearch_item.json.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/catalogue/itemsearch_item.json.inc index 1933950c07..e0b28ee2ab 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/catalogue/itemsearch_item.json.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/catalogue/itemsearch_item.json.inc @@ -1,5 +1,6 @@ [%- USE Branches -%] [%- USE Koha -%] +[%- USE KohaDates -%] [%- USE To -%] [%- USE ItemTypes -%] [%- USE AuthorisedValues -%] @@ -28,6 +29,8 @@ "[% AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.itemlost', authorised_value => item.itemlost ) || "" | html %]", "[% AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.withdrawn', authorised_value => item.withdrawn ) || "" | html %]", "[% (item.issues || 0) | html %]", + "[% IF item.onloan %]Checked out[% ELSIF item.withdrawn || item.damaged || item.notforloan || item.itemlost %]Not available[% ELSE %]Available[% END %]", + "[% IF item.checkout %][% item.checkout.date_due | $KohaDates | html %][% END %]", "[% FILTER escape_quotes ~%]
[%~ END %]" diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/csv_headers/catalogue/itemsearch.tt b/koha-tmpl/intranet-tmpl/prog/en/includes/csv_headers/catalogue/itemsearch.tt index eccba14468..2902fc5df2 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/csv_headers/catalogue/itemsearch.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/csv_headers/catalogue/itemsearch.tt @@ -31,4 +31,8 @@ "Withdrawn status" [%- delimiter | $raw -%] "Checkouts" +[%- delimiter | $raw -%] +"Availability" +[%- delimiter | $raw -%] +"Due date" [%- END -%] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/itemsearch.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/itemsearch.tt index 532fc71a59..1b5340fba4 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/itemsearch.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/itemsearch.tt @@ -173,6 +173,7 @@

Item search

+

Go to advanced search

@@ -203,6 +204,15 @@ [% IF withdrawns.size %] [% INCLUDE form_field_select name="withdrawn" options = withdrawns empty_option = "All statuses" %] [% END %] +
+ + + + + + + +
[% INCLUDE form_field_select_text %] @@ -326,6 +336,8 @@ + ' ' + _("Lost status") + '' + ' ' + _("Withdrawn status") + '' + ' ' + _("Checkouts") + '' + + ' ' + _("Availability") + '' + + ' ' + _("Due date") + '' + ' ' + ' ' var table = '' @@ -482,6 +494,8 @@ { 'sName': 'itemlost' }, { 'sName': 'withdrawn' }, { 'sName': 'issues' }, + { 'sName': 'availability' }, + { 'sName': 'duedate' }, { 'sName': 'actions', 'bSortable': false } ], "sPaginationType": "full_numbers", @@ -529,6 +543,8 @@ null, [% END %] { 'type': 'text' }, + { 'type': 'text' }, + { 'type': 'text' }, null ] }); -- 2.11.0