Bug 11182: remove spurious logged warnings in circulation
[koha_fer] / circ / circulation.pl
index 7ca62f2..70f89d3 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.
 #
@@ -31,13 +32,15 @@ use C4::Dates qw/format_date/;
 use C4::Branch; # GetBranches
 use C4::Koha;   # GetPrinter
 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;
 use C4::Members::Attributes qw(GetBorrowerAttributes);
+use Koha::Borrower::Debarments qw(GetDebarments IsDebarred);
 use Koha::DateUtils;
 
 use Date::Calc qw(
@@ -130,7 +133,6 @@ my $stickyduedate  = $query->param('stickyduedate') || $session->param('stickydu
 my $duedatespec    = $query->param('duedatespec')   || $session->param('stickyduedate');
 my $issueconfirmed = $query->param('issueconfirmed');
 my $cancelreserve  = $query->param('cancelreserve');
-my $organisation   = $query->param('organisations');
 my $print          = $query->param('print') || q{};
 my $debt_confirmed = $query->param('debt_confirmed') || 0; # Don't show the debt error dialog twice
 my $charges        = $query->param('charges') || q{};
@@ -263,12 +265,15 @@ if ($borrowernumber) {
         finetotal    => $fines
     );
 
-    my $debar = CheckBorrowerDebarred($borrowernumber);
-    if ($debar) {
-        $template->param( 'userdebarred'    => 1 );
-        $template->param( 'debarredcomment' => $borrower->{debarredcomment} );
-        if ( $debar ne "9999-12-31" ) {
-            $template->param( 'userdebarreddate' => C4::Dates::format_date($debar) );
+    if ( IsDebarred($borrowernumber) ) {
+        $template->param(
+            'userdebarred'    => $borrower->{debarred},
+            'debarredcomment' => $borrower->{debarredcomment},
+        );
+
+        if ( $borrower->{debarred} ne "9999-12-31" ) {
+            $template->param( 'userdebarreddate' =>
+                  C4::Dates::format_date( $borrower->{debarred} ) );
         }
     }
 
@@ -291,6 +296,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,
+                    C4::Search::new_record_from_zebra('biblioserver',$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 ) {
@@ -359,8 +392,9 @@ if ($borrowernumber) {
         $getreserv{nottransfered} = 0;
 
         $getreserv{reservedate}    = format_date( $num_res->{'reservedate'} );
-        $getreserv{reservenumber}  = $num_res->{'reservenumber'};
+        $getreserv{reserve_id}  = $num_res->{'reserve_id'};
         $getreserv{title}          = $getiteminfo->{'title'};
+        $getreserv{subtitle}       = GetRecordValue('subtitle', GetMarcBiblio($getiteminfo->{biblionumber}), GetFrameworkCode($getiteminfo->{biblionumber}));
         $getreserv{itemtype}       = $itemtypeinfo->{'description'};
         $getreserv{author}         = $getiteminfo->{'author'};
         $getreserv{barcodereserv}  = $getiteminfo->{'barcode'};
@@ -400,12 +434,14 @@ if ($borrowernumber) {
 
             $getreserv{color}           = 'inwait';
             $getreserv{title}           = $getbibinfo->{'title'};
+            $getreserv{subtitle}        = GetRecordValue('subtitle', GetMarcBiblio($num_res->{biblionumber}), GetFrameworkCode($num_res->{biblionumber}));
             $getreserv{nottransfered}   = 0;
             $getreserv{itemtype}        = $itemtypeinfo->{'description'};
             $getreserv{author}          = $getbibinfo->{'author'};
             $getreserv{biblionumber}    = $num_res->{'biblionumber'};
         }
         $getreserv{waitingposition} = $num_res->{'priority'};
+        $getreserv{expirationdate} = $num_res->{'expirationdate'};
         push( @reservloop, \%getreserv );
 
 #         if we have a reserve waiting, initiate waitingreserveloop
@@ -464,11 +500,13 @@ sub build_issue_data {
         $totalprice += $it->{'replacementprice'} || 0;
         $it->{'itemtype'} = $itemtypeinfo->{'description'};
         $it->{'itemtype_image'} = $itemtypeinfo->{'imageurl'};
+        $it->{'dd_sort'} = $it->{'date_due'};
         $it->{'dd'} = output_pref($it->{'date_due'});
+        $it->{'displaydate_sort'} = $it->{'issuedate'};
         $it->{'displaydate'} = output_pref($it->{'issuedate'});
         #$it->{'od'} = ( $it->{'date_due'} lt $todaysdate ) ? 1 : 0 ;
         $it->{'od'} = $it->{'overdue'};
-        $it->{'author'} ||= ' ';
+        $it->{'subtitle'} = GetRecordValue('subtitle', GetMarcBiblio($it->{biblionumber}), GetFrameworkCode($it->{biblionumber}));
         $it->{'renew_failed'} = $renew_failed{$it->{'itemnumber'}};
         $it->{'return_failed'} = $return_failed{$it->{'barcode'}};
 
@@ -478,6 +516,13 @@ sub build_issue_data {
         } else {
             (!$relatives) ? push @previousissues, $it : push @relprevissues, $it;
         }
+        ($it->{'renewcount'},$it->{'renewsallowed'},$it->{'renewsleft'}) = C4::Circulation::GetRenewCount($it->{'borrowernumber'},$it->{'itemnumber'}); #Add renewal count to item data display
+
+        $it->{'soonestrenewdate'} = output_pref(
+            C4::Circulation::GetSoonestRenewDate(
+                $it->{borrowernumber}, $it->{itemnumber}
+            )
+        );
     }
 }
 
@@ -615,32 +660,13 @@ $amountold =~ s/^.*\$//;    # remove upto the $, if any
 
 my ( $total, $accts, $numaccts) = GetMemberAccountRecords( $borrowernumber );
 
-if ( $borrower->{'category_type'} eq 'C') {
+if ( $borrowernumber && $borrower->{'category_type'} eq 'C') {
     my  ( $catcodes, $labels ) =  GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
     my $cnt = scalar(@$catcodes);
     $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
     $template->param( 'catcode' =>    $catcodes->[0])  if $cnt == 1;
 }
 
-my $CGIorganisations;
-my $member_of_institution;
-if ( C4::Context->preference("memberofinstitution") ) {
-    my $organisations = get_institutions();
-    my @orgs;
-    my %org_labels;
-    foreach my $organisation ( keys %$organisations ) {
-        push @orgs, $organisation;
-        $org_labels{$organisation} = $organisations->{$organisation}->{'surname'};
-    }
-    $member_of_institution = 1;
-    $CGIorganisations      = CGI::popup_menu(
-        -id     => 'organisations',
-        -name   => 'organisations',
-        -labels => \%org_labels,
-        -values => \@orgs,
-    );
-}
-
 my $lib_messages_loop = GetMessages( $borrowernumber, 'L', $branch );
 if($lib_messages_loop){ $template->param(flagged => 1 ); }
 
@@ -650,7 +676,7 @@ if($bor_messages_loop){ $template->param(flagged => 1 ); }
 # Computes full borrower address
 my @fulladdress;
 push @fulladdress, $borrower->{'streetnumber'} if ( $borrower->{'streetnumber'} );
-push @fulladdress, &GetRoadTypeDetails( $borrower->{'streettype'} ) if ( $borrower->{'streettype'} );
+push @fulladdress, C4::Koha::GetAuthorisedValueByCode( 'ROADTYPE', $borrower->{'streettype'} ) if ( $borrower->{'streettype'} );
 push @fulladdress, $borrower->{'address'} if ( $borrower->{'address'} );
 
 my $fast_cataloging = 0;
@@ -711,9 +737,7 @@ $template->param(
     relprevissues              => \@relprevissues,
     displayrelissues           => $displayrelissues,
     inprocess         => $inprocess,
-    memberofinstution => $member_of_institution,
-    CGIorganisations  => $CGIorganisations,
-    is_child          => ($borrower->{'category_type'} eq 'C'),
+    is_child          => ($borrowernumber && $borrower->{'category_type'} eq 'C'),
     circview => 1,
     soundon           => C4::Context->preference("SoundOn"),
     fast_cataloging   => $fast_cataloging,
@@ -721,6 +745,7 @@ $template->param(
     activeBorrowerRelationship => (C4::Context->preference('borrowerRelationship') ne ''),
     SuspendHoldsIntranet => C4::Context->preference('SuspendHoldsIntranet'),
     AutoResumeSuspendedHolds => C4::Context->preference('AutoResumeSuspendedHolds'),
+    RoutingSerials => C4::Context->preference('RoutingSerials'),
 );
 
 # save stickyduedate to session
@@ -728,7 +753,7 @@ if ($stickyduedate) {
     $session->param( 'stickyduedate', $duedatespec );
 }
 
-my ($picture, $dberror) = GetPatronImage($borrower->{'cardnumber'});
+my ($picture, $dberror) = GetPatronImage($borrower->{'borrowernumber'});
 $template->param( picture => 1 ) if $picture;
 
 # get authorised values with type of BOR_NOTES
@@ -739,10 +764,11 @@ $template->param(
     debt_confirmed            => $debt_confirmed,
     SpecifyDueDate            => $duedatespec_allow,
     CircAutocompl             => C4::Context->preference("CircAutocompl"),
-       AllowRenewalLimitOverride => C4::Context->preference("AllowRenewalLimitOverride"),
+    AllowRenewalLimitOverride => C4::Context->preference("AllowRenewalLimitOverride"),
     export_remove_fields      => C4::Context->preference("ExportRemoveFields"),
     export_with_csv_profile   => C4::Context->preference("ExportWithCsvProfile"),
     canned_bor_notes_loop     => $canned_notes,
+    debarments                => GetDebarments({ borrowernumber => $borrowernumber }),
 );
 
 output_html_with_http_headers $query, $cookie, $template->output;