From 353427a31ab07c4814843a7c7a27786042010148 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=utf8 Content-Transfer-Encoding: 8bit This enhancement adds the availability of an item to the item search results (i.e. shows if checked out or not). If checked out, shows due date in item search results. The due date column will also show when exporting results to a CSV file. To test: 1) Apply patch and restart services 2) Set up two items. Check out Item A to a borrower. Leave Item B as is not checked out, and not unavailable status. 3) Go to Search -> Item search. Scroll down and notice the Availability radio options - Ignore, and Checked out. 4) Leave the Ignore option selected and do a search so that both 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 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 Item B). Sponsored-by: Bibliotheksservice-Zentrum Baden-Württemberg (BSZ) Signed-off-by: Christian Stelzenmüller Signed-off-by: Jonathan Druart Signed-off-by: Fridolin Somers --- C4/Items.pm | 9 +++++++-- catalogue/itemsearch.pl | 19 ++++++++++++++++++- .../catalogue/itemsearch_item.csv.inc | 5 +++++ .../catalogue/itemsearch_item.json.inc | 3 +++ .../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 502ccb6793..5f68c914fd 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -1294,7 +1294,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:') ) { @@ -1355,6 +1355,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 ?", @@ -1387,7 +1392,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 354ea86ccb..e18524307c 100755 --- a/catalogue/itemsearch.pl +++ b/catalogue/itemsearch.pl @@ -62,7 +62,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 { @@ -185,6 +185,21 @@ if ( defined $format ) { } } + # 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', @@ -230,6 +245,8 @@ if ( defined $format ) { 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 3d23fdcd24..c4aa698c85 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.39.5