From 3ad6c3e47a2810314df0eb1646f4975988c852cc 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 --- circ/circulation.pl | 31 ++++++++++++++++++++ installer/data/mysql/sysprefs.sql | 1 + installer/data/mysql/updatedatabase.pl | 11 +++++++ .../en/modules/admin/preferences/circulation.pref | 6 ++++ .../prog/en/modules/circ/circulation.tt | 26 +++++++++++++++- 5 files changed, 73 insertions(+), 2 deletions(-) diff --git a/circ/circulation.pl b/circ/circulation.pl index 91fd1a2..12a294a 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; @@ -287,6 +290,34 @@ if ($barcode) { $template->param( alert => $alerts ); + # 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 ) { $template->param( diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index 0cc5a54..aa944ae 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -160,6 +160,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 39e4bde..19464f6 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -6181,6 +6181,17 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) { SetVersion ($DBversion); } +$DBversion = "3.09.00.XXX"; +if (C4::Context->preference("Version") < TransformToNum($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 (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 c188d80..a4c385f 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 @@ -19,6 +19,12 @@ Circulation: 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 choices: 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 c860ed6..cacb843 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt @@ -453,12 +453,34 @@ function validate1(date) { [% END %] [% IF ( UNKNOWN_BARCODE ) %] -
  • The barcode was not found [% barcode %]
  • +
  • The barcode "[% barcode %]" was not found. + [% IF ( fast_cataloging ) %] [% IF ( CAN_user_editcatalogue_fast_cataloging ) %] - 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 ) %] -- 1.7.2.5