Bug 8150 [SIGNED-OFF] Remove obsoleted navigation bar in circ history
[koha.git] / circ / circulation.pl
index 378956e..c89abff 100755 (executable)
@@ -4,6 +4,7 @@
 
 # Copyright 2000-2002 Katipo Communications
 # copyright 2010 BibLibre
+# Copyright 2011 PTFS-Europe Ltd.
 #
 # This file is part of Koha.
 #
@@ -21,7 +22,7 @@
 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
 use strict;
-#use warnings; FIXME - Bug 2505
+use warnings;
 use CGI;
 use C4::Output;
 use C4::Print;
@@ -30,12 +31,14 @@ 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::Reserves;
 use C4::Context;
 use CGI::Session;
 use C4::Members::Attributes qw(GetBorrowerAttributes);
+use Koha::DateUtils;
 
 use Date::Calc qw(
   Today
@@ -91,7 +94,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user (
 my $branches = GetBranches();
 
 my @failedrenews = $query->param('failedrenew');    # expected to be itemnumbers 
-my %renew_failed;
+our %renew_failed;
 for (@failedrenews) { $renew_failed{$_} = 1; }
 
 my $findborrower = $query->param('findborrower');
@@ -144,14 +147,9 @@ my $duedatespec_allow = C4::Context->preference('SpecifyDueDate');
 if($duedatespec_allow){
     if ($duedatespec) {
         if ($duedatespec =~ C4::Dates->regexp('syspref')) {
-            my $tempdate = C4::Dates->new($duedatespec);
-#           if ($tempdate and $tempdate->output('iso') gt C4::Dates->new()->output('iso')) {
-#               # i.e., it has to be later than today/now
-                $datedue = $tempdate;
-#           } else {
-#               $invalidduedate = 1;
-#               $template->param(IMPOSSIBLE=>1, INVALID_DATE=>$duedatespec);
-#           }
+                $datedue = dt_from_string($duedatespec);
+                $datedue->set_hour(23);
+                $datedue->set_minute(59);
         } else {
             $invalidduedate = 1;
             $template->param(IMPOSSIBLE=>1, INVALID_DATE=>$duedatespec);
@@ -159,7 +157,7 @@ if($duedatespec_allow){
     }
 }
 
-my $todaysdate = C4::Dates->new->output('iso');
+our $todaysdate = C4::Dates->new->output('iso');
 
 # check and see if we should print
 if ( $barcode eq '' && $print eq 'maybe' ) {
@@ -175,7 +173,10 @@ if ( $barcode eq '' && $query->param('charges') eq 'yes' ) {
 }
 
 if ( $print eq 'yes' && $borrowernumber ne '' ) {
-    printslip( $borrowernumber );
+    if ( C4::Context->boolean_preference('printcirculationslips') ) {
+        my $letter = IssueSlip($branch, $borrowernumber, "QUICK");
+        NetworkPrint($letter->{content});
+    }
     $query->param( 'borrowernumber', '' );
     $borrowernumber = '';
 }
@@ -260,6 +261,16 @@ if ($borrowernumber) {
         issuecount   => $issue,
         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) );
+        }
+    }
+
 }
 
 #
@@ -285,6 +296,7 @@ if ($barcode) {
         unless($issueconfirmed){
             #  Get the item title for more information
             my $getmessageiteminfo  = GetBiblioFromItemNumber(undef,$barcode);
+           $template->{VARS}->{'additional_materials'} = $getmessageiteminfo->{'materials'};
             $template->param( itemhomebranch => $getmessageiteminfo->{'homebranch'} );
 
             # pass needsconfirmation to template if issuing is possible and user hasn't yet confirmed.
@@ -346,6 +358,8 @@ if ($borrowernumber) {
         $getreserv{itemcallnumber} = $getiteminfo->{'itemcallnumber'};
         $getreserv{biblionumber}   = $getiteminfo->{'biblionumber'};
         $getreserv{waitingat}      = GetBranchName( $num_res->{'branchcode'} );
+        $getreserv{suspend}        = $num_res->{'suspend'};
+        $getreserv{suspend_until}  = $num_res->{'suspend_until'};
         #         check if we have a waiting status for reservations
         if ( $num_res->{'found'} eq 'W' ) {
             $getreserv{color}   = 'reserved';
@@ -403,13 +417,13 @@ if ($borrowernumber) {
 # make the issued books table.
 my $todaysissues = '';
 my $previssues   = '';
-my @todaysissues;
-my @previousissues;
-my @relissues;
-my @relprevissues;
+our @todaysissues;
+our @previousissues;
+our @relissues;
+our @relprevissues;
 my $displayrelissues;
 
-my $totalprice = 0;
+our $totalprice = 0;
 
 sub build_issue_data {
     my $issueslist = shift;
@@ -430,7 +444,7 @@ sub build_issue_data {
             $it->{'borrowernumber'},$it->{'itemnumber'}
         );
         $it->{"renew_error_${can_renew_error}"} = 1 if defined $can_renew_error;
-        my ( $restype, $reserves ) = CheckReserves( $it->{'itemnumber'} );
+        my ( $restype, $reserves, undef ) = CheckReserves( $it->{'itemnumber'} );
         $it->{'can_renew'} = $can_renew;
         $it->{'can_confirm'} = !$can_renew && !$restype;
         $it->{'renew_error'} = $restype;
@@ -440,9 +454,10 @@ sub build_issue_data {
         $totalprice += $it->{'replacementprice'};
         $it->{'itemtype'} = $itemtypeinfo->{'description'};
         $it->{'itemtype_image'} = $itemtypeinfo->{'imageurl'};
-        $it->{'dd'} = format_date($it->{'date_due'});
-        $it->{'displaydate'} = format_date($it->{'issuedate'});
-        $it->{'od'} = ( $it->{'date_due'} lt $todaysdate ) ? 1 : 0 ;
+        $it->{'dd'} = output_pref($it->{'date_due'});
+        $it->{'displaydate'} = output_pref($it->{'issuedate'});
+        #$it->{'od'} = ( $it->{'date_due'} lt $todaysdate ) ? 1 : 0 ;
+        $it->{'od'} = $it->{'overdue'};
         ($it->{'author'} eq '') and $it->{'author'} = ' ';
         $it->{'renew_failed'} = $renew_failed{$it->{'itemnumber'}};
 
@@ -499,7 +514,7 @@ if ($borrowerslist) {
     {
         push @values, $_->{'borrowernumber'};
         $labels{ $_->{'borrowernumber'} } =
-"$_->{'surname'}, $_->{'firstname'} ... ($_->{'cardnumber'} - $_->{'categorycode'}) ...  $_->{'address'} ";
+"$_->{'surname'}, $_->{'firstname'} ... ($_->{'cardnumber'} - $_->{'categorycode'} - $_->{'branchcode'}) ...  $_->{'address'} ";
     }
     $CGIselectborrower = CGI::scrolling_list(
         -name     => 'borrowernumber',
@@ -692,6 +707,8 @@ $template->param(
     circview => 1,
     soundon           => C4::Context->preference("SoundOn"),
     fast_cataloging   => $fast_cataloging,
+    CircAutoPrintQuickSlip   => C4::Context->preference("CircAutoPrintQuickSlip"),
+       activeBorrowerRelationship => (C4::Context->preference('borrowerRelationship') ne ''),
 );
 
 # save stickyduedate to session
@@ -715,4 +732,7 @@ $template->param(
     DHTMLcalendar_dateformat  => C4::Dates->DHTMLcalendar(),
     canned_bor_notes_loop     => $canned_notes,
 );
+
+$template->param( AutoResumeSuspendedHolds => C4::Context->preference('AutoResumeSuspendedHolds') );
+
 output_html_with_http_headers $query, $cookie, $template->output;