bug 7494: optional checkout-time fallback search for a book
authorMJ Ray <mjr@phonecoop.coop>
Thu, 28 Jun 2012 19:35:49 +0000 (20:35 +0100)
committerGalen Charlton <gmc@esilibrary.com>
Wed, 24 Jul 2013 15:12:38 +0000 (15:12 +0000)
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 <mjr@phonecoop.coop>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>

circ/circulation.pl
installer/data/mysql/sysprefs.sql
installer/data/mysql/updatedatabase.pl
koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref
koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt

index 5ca7574..825a144 100755 (executable)
@@ -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 ) {
index e3c0f3d..c8caee7 100644 (file)
@@ -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');
index ebb195c..0c095ea 100755 (executable)
@@ -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)
index c286ed1..2ae466a 100644 (file)
@@ -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:
index 290c4c3..dce5fcc 100644 (file)
@@ -469,12 +469,33 @@ function validate1(date) {
         [% END %]
 
         [% IF ( UNKNOWN_BARCODE ) %]
-            <li>The barcode was not found [% barcode |html %]</li>
+            <li>The barcode was not found [% barcode |html %]
            [% IF ( fast_cataloging ) %]
                [% IF ( CAN_user_editcatalogue_fast_cataloging ) %]
             <a href="/cgi-bin/koha/cataloguing/addbiblio.pl?frameworkcode=FA&amp;barcode=[% barcode |uri %]&amp;circborrowernumber=[% borrowernumber %]&amp;branch=[% branch %]&amp;duedatespec=[% duedatespec %]&amp;stickyduedate=[% stickyduedate %]">Fast cataloging</a>
                [% END %]
            [% END %]
+
+        [% IF ( FALLBACK ) %]
+            [% IF options %]
+                <br />The following items were found by searching:
+                [% FOREACH book IN options %]
+                    <br />
+                    <form method="post" action="/cgi-bin/koha/circ/circulation.pl" autocomplete="off">
+                        <input type="hidden" name="borrowernumber" value="[% borrowernumber %]" />
+                        <input type="hidden" name="duedatespec" value="[% duedatespec %]" />
+                        <input type="hidden" name="stickyduedate" value="[% stickyduedate %]" />
+                        <input type="hidden" name="branch" value="[% branch %]" />
+                        <input type="hidden" name="barcode" value="[% book.barcode %]" />
+                        <input type="submit" name="x" value="Check out [% book.barcode %]: [% book.title %]" />
+                    </form>
+                [% END %]
+            [% ELSE %]
+                <br />No items were found by searching.
+            [% END %]
+        [% END %]
+
+     </li>
         [% END %]
 
         [% IF ( NOT_FOR_LOAN ) %]