From 84c2e7c1e5d0562da03253003c073b03a82c76dd Mon Sep 17 00:00:00 2001 From: MJ Ray Date: Thu, 28 Jun 2012 20:35:49 +0100 Subject: [PATCH] bug 7494: optional checkout-time fallback search for a book When issuing a book, some libraries want to issue by title or other details. This patch adds a systempreference and code that allows it. To test: 1) scan a patron card or enter a surname to start checking out; 2) enter title or other keywords; 3) the circulation screen should display a warning allowing to choose between copies. Signed-off-by: MJ Ray Signed-off-by: Kyle M Hall Signed-off-by: Jonathan Druart Signed-off-by: Galen Charlton --- circ/circulation.pl | 31 +++++++++++++++++++ installer/data/mysql/sysprefs.sql | 1 + installer/data/mysql/updatedatabase.pl | 9 ++++++ .../admin/preferences/circulation.pref | 6 ++++ .../prog/en/modules/circ/circulation.tt | 23 +++++++++++++- 5 files changed, 69 insertions(+), 1 deletion(-) diff --git a/circ/circulation.pl b/circ/circulation.pl index 5ca7574298..825a1446c7 100755 --- a/circ/circulation.pl +++ b/circ/circulation.pl @@ -5,6 +5,7 @@ # Copyright 2000-2002 Katipo Communications # copyright 2010 BibLibre # Copyright 2011 PTFS-Europe Ltd. +# Copyright 2012 software.coop and MJ Ray # # This file is part of Koha. # @@ -34,6 +35,8 @@ use C4::Circulation; use C4::Overdues qw/CheckBorrowerDebarred/; use C4::Members; use C4::Biblio; +use C4::Search; +use MARC::Record; use C4::Reserves; use C4::Context; use CGI::Session; @@ -291,6 +294,34 @@ if ($barcode) { $template->param( authvalcode_notforloan => C4::Koha::GetAuthValCode('items.notforloan', $getmessageiteminfo->{'frameworkcode'}), ); + # Fix for bug 7494: optional checkout-time fallback search for a book + + if ( $error->{'UNKNOWN_BARCODE'} + && C4::Context->preference("itemBarcodeFallbackSearch") ) + { + $template->param( FALLBACK => 1 ); + + my $query = "kw=" . $barcode; + my ( $searcherror, $results, $total_hits ) = SimpleSearch($query); + + # if multiple hits, offer options to librarian + if ( $total_hits > 0 ) { + my @options = (); + foreach my $hit ( @{$results} ) { + my $chosen = + TransformMarcToKoha( C4::Context->dbh, + MARC::Record->new_from_usmarc($hit) ); + + # offer all barcodes individually + foreach my $barcode ( sort split(/\s*\|\s*/, $chosen->{barcode}) ) { + my %chosen_single = %{$chosen}; + $chosen_single{barcode} = $barcode; + push( @options, \%chosen_single ); + } + } + $template->param( options => \@options ); + } + } delete $question->{'DEBT'} if ($debt_confirmed); foreach my $impossible ( keys %$error ) { diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index e3c0f3dc88..c8caee7af5 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -158,6 +158,7 @@ INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('numReturnedItemsToShow','20','Number of returned items to show on the check-in page',NULL,'Integer'); INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('finesMode','test','Choose the fines mode, \'off\', \'test\' (emails admin report) or \'production\' (accrue overdue fines). Requires accruefines cronjob.','off|test|production','Choice'); INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('itemBarcodeInputFilter','','If set, allows specification of a item barcode input filter','whitespace|T-prefix|cuecat|libsuite8|EAN13','Choice'); +INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('itemBarcodeFallbackSearch','','If set, uses scanned item barcodes as a catalogue search if not found as barcodes',NULL,'YesNo'); INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('singleBranchMode',0,'Operate in Single-branch mode, hide branch selection in the OPAC',NULL,'YesNo'); INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('URLLinkText','','Text to display as the link anchor in the OPAC',NULL,'free'); INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OPACViewOthersSuggestions',0,'If ON, allows all suggestions to be displayed in the OPAC',NULL,'YesNo'); diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index ebb195c1e3..0c095ea6a5 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -7058,6 +7058,15 @@ if ( CheckVersion($DBversion) ) { SetVersion($DBversion); } +$DBversion = "3.13.00.XXX"; +if ( CheckVersion($DBversion) ) { + $dbh->do( +"INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('itemBarcodeFallbackSearch','','If set, uses scanned item barcodes as a catalogue search if not found as barcodes',NULL,'YesNo')" + ); + print "Upgrade to $DBversion done (Bug 7494: Add itemBarcodeFallbackSearch syspref)\n"; + # SetVersion($DBversion); +} + =head1 FUNCTIONS =head2 TableExists($table) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref index c286ed19c0..2ae466a98e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref @@ -18,6 +18,12 @@ Circulation: libsuite8: Convert from Libsuite8 form EAN13: EAN-13 or zero-padded UPC-A from - scanned item barcodes. + - + - pref: itemBarcodeFallbackSearch + choices: + yes: "Enable" + no: "Don't enable" + - to use scanned item barcodes as a catalogue search if not found as barcodes. - - Sort previous checkouts on the circulation page from - pref: previousIssuesDefaultSortOrder diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt index 290c4c3de7..dce5fcc159 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt @@ -469,12 +469,33 @@ function validate1(date) { [% END %] [% IF ( UNKNOWN_BARCODE ) %] -
  • The barcode was not found [% barcode |html %]
  • +
  • The barcode was not found [% barcode |html %] [% IF ( fast_cataloging ) %] [% IF ( CAN_user_editcatalogue_fast_cataloging ) %] Fast cataloging [% END %] [% END %] + + [% IF ( FALLBACK ) %] + [% IF options %] +
    The following items were found by searching: + [% FOREACH book IN options %] +
    +
    + + + + + + +
    + [% END %] + [% ELSE %] +
    No items were found by searching. + [% END %] + [% END %] + +
  • [% END %] [% IF ( NOT_FOR_LOAN ) %] -- 2.39.5