Add fine amount to display on circ pages.
[koha.git] / circ / circulation.pl
index 9708d09..28d0685 100755 (executable)
@@ -92,6 +92,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user (
         flagsrequired   => { circulate => 1 },
     }
 );
+
 my $branches = GetBranches();
 
 my $printers = GetPrinters();
@@ -120,9 +121,6 @@ $printer = C4::Context->userenv->{'branchprinter'};
 my $barcode        = $query->param('barcode') || '';
 
 $barcode = barcodedecode($barcode) if( $barcode && C4::Context->preference('itemBarcodeInputFilter'));
-my $year           = $query->param('year');
-my $month          = $query->param('month');
-my $day            = $query->param('day');
 my $stickyduedate  = $query->param('stickyduedate');
 my $duedatespec    = $query->param('duedatespec');
 my $issueconfirmed = $query->param('issueconfirmed');
@@ -130,6 +128,7 @@ my $cancelreserve  = $query->param('cancelreserve');
 my $organisation   = $query->param('organisations');
 my $print          = $query->param('print');
 my $newexpiry      = $query->param('dateexpiry');
+my $debt_confirmed = $query->param('debt_confirmed') || 0; # Don't show the debt error dialog twice
 
 #set up cookie.....
 # my $branchcookie;
@@ -261,6 +260,8 @@ if ($barcode) {
   my ( $error, $question ) =
     CanBookBeIssued( $borrower, $barcode, $datedue , $inprocess );
   my $noerror = $invalidduedate ? 0 : 1;
+
+  delete $question->{'DEBT'} if ($debt_confirmed);
   foreach my $impossible ( keys %$error ) {
             $template->param(
                 $impossible => $$error{$impossible},
@@ -386,12 +387,12 @@ if ($borrowernumber) {
             my $getbibtype = getitemtypeinfo( $getbibinfo->{'itemtype'} );  # fixme - we should have item-level reserves here ?
             $getreserv{color}           = 'inwait';
             $getreserv{title}           = $getbibinfo->{'title'};
-            $getreserv{waitingposition} = $num_res->{'priority'};
             $getreserv{nottransfered}   = 0;
             $getreserv{itemtype}        = $getbibtype->{'description'};
             $getreserv{author}          = $getbibinfo->{'author'};
           $getreserv{biblionumber}    = $num_res->{'biblionumber'};
         }
+        $getreserv{waitingposition} = $num_res->{'priority'};
         push( @reservloop, \%getreserv );
 
 #         if we have a reserve waiting, initiate waitingreserveloop
@@ -425,64 +426,58 @@ my $issued_itemtypes_flags;            #hashref that stores flags
 my @issued_itemtypes_count_loop;
 
 if ($borrower) {
-
 # get each issue of the borrower & separate them in todayissues & previous issues
     my ($countissues,$issueslist) = GetPendingIssues($borrower->{'borrowernumber'});
 
     # split in 2 arrays for today & previous
     foreach my $it ( @$issueslist ) {
         # set itemtype per item-level_itype syspref - FIXME this is an ugly hack
-        $it->{'itemtype'} = (C4::Context->preference('item-level_itypes')) ? $it->{'itype'} : $it->{'itemtype'};
+        $it->{'itemtype'} = ( C4::Context->preference( 'item-level_itypes' ) ) ? $it->{'itype'} : $it->{'itemtype'};
 
-        my $issuedate = $it->{'issuedate'};
-        $issuedate =~ s/-//g;
-        $issuedate = substr( $issuedate, 0, 8 );
-    ($it->{'charge'}, $it->{'itemtype_charge'}) = GetIssuingCharges(
+        ($it->{'charge'}, $it->{'itemtype_charge'}) = GetIssuingCharges(
             $it->{'itemnumber'}, $borrower->{'borrowernumber'}
-    );
-    $it->{'charge'} = sprintf("%.2f", $it->{'charge'});
+        );
+        $it->{'charge'} = sprintf("%.2f", $it->{'charge'});
         my $can_renew_error;
         ($it->{'can_renew'}, $can_renew_error) = CanBookBeRenewed( 
             $borrower->{'borrowernumber'},$it->{'itemnumber'}
-    );
+        );
         $it->{"renew_error_${can_renew_error}"} = 1 if defined $can_renew_error;
-    my ($restype, $reserves) = CheckReserves($it->{'itemnumber'});
-    ($restype) and $it->{'can_renew'} = 0;
+        my ( $restype, $reserves ) = CheckReserves( $it->{'itemnumber'} );
+        ( $restype ) and $it->{'can_renew'} = 0;
 
-    $it->{'dd'} = format_date($it->{'date_due'});
-        my $datedue = $it->{'date_due'};
-        $datedue =~ s/-//g;
-    $it->{'od'} = ($datedue < $todaysdate) ? 1 : 0 ;
+        $it->{'dd'} = format_date($it->{'date_due'});
+        $it->{'od'} = ( $it->{'date_due'} lt $todaysdate ) ? 1 : 0 ;
         ($it->{'author'} eq '') and $it->{'author'} = ' ';
         $it->{'renew_failed'} = $renew_failed[$it->{'itemnumber'}];
         # ADDED BY JF: NEW ITEMTYPE COUNT DISPLAY
         $issued_itemtypes_count->{ $it->{'itemtype'} }++;
 
-        if ( $todaysdate == $issuedate ) {
+        if ( $todaysdate eq $it->{'issuedate'} or $todaysdate eq $it->{'lastreneweddate'} ) {
             push @todaysissues, $it;
         } else {
             push @previousissues, $it;
         }
     }
-  if (C4::Context->preference("todaysIssuesDefaultSortOrder") eq 'asc'){
-    @todaysissues   = sort { $a->{'timestamp'} cmp $b->{'timestamp'} } @todaysissues;
-  }
-  else {
-    @todaysissues   = sort { $b->{'timestamp'} cmp $a->{'timestamp'} } @todaysissues;
-  }
-  if (C4::Context->preference("previousIssuesDefaultSortOrder") eq 'asc'){
-    @previousissues = sort { $a->{'date_due' } cmp $b->{'date_due' } } @previousissues;
-  }
-  else {
-    @previousissues = sort { $b->{'date_due' } cmp $a->{'date_due' } } @previousissues;
-  }
+    if ( C4::Context->preference( "todaysIssuesDefaultSortOrder" ) eq 'asc' ) {
+        @todaysissues   = sort { $a->{'timestamp'} cmp $b->{'timestamp'} } @todaysissues;
+    }
+    else {
+        @todaysissues   = sort { $b->{'timestamp'} cmp $a->{'timestamp'} } @todaysissues;
+    }
+    if ( C4::Context->preference( "previousIssuesDefaultSortOrder" ) eq 'asc' ){
+        @previousissues = sort { $a->{'date_due'} cmp $b->{'date_due'} } @previousissues;
+    }
+    else {
+        @previousissues = sort { $b->{'date_due'} cmp $a->{'date_due'} } @previousissues;
+    }
     my $i = 1;
-  foreach my $book (@todaysissues) {
-        $book->{'togglecolor'} = (++$i % 2) ? 0 : 1 ;
+    foreach my $book ( @todaysissues ) {
+        $book->{'togglecolor'} = ( ++$i % 2 ) ? 0 : 1 ;
     }
     $i = 1;
-  foreach my $book (@previousissues) {
-        $book->{'togglecolor'} = (++$i % 2) ? 0 : 1 ;
+    foreach my $book ( @previousissues ) {
+        $book->{'togglecolor'} = ( ++$i % 2 ) ? 0 : 1 ;
     }
 }
 
@@ -528,10 +523,7 @@ my %labels;
 my $CGIselectborrower;
 if ($borrowerslist) {
     foreach (
-        sort {
-                lc $a->{'surname'}
-              . lc $a->{'firstname'} cmp lc $b->{'surname'}
-              . lc $b->{'firstname'}
+        sort {(lc $a->{'surname'} cmp lc $b->{'surname'} ?lc $a->{'surname'} cmp lc $b->{'surname'}:lc $a->{'firstname'} cmp lc $b->{'firstname'})
         } @$borrowerslist
       )
     {
@@ -576,6 +568,7 @@ foreach $flag ( sort keys %$flags ) {
             $template->param(
                 charges    => 'true',
                 chargesmsg => $flags->{'CHARGES'}->{'message'},
+                chargesamount => $flags->{'CHARGES'}->{'amount'},
                 charges_is_blocker => 1
             );
         }
@@ -591,7 +584,8 @@ foreach $flag ( sort keys %$flags ) {
             $template->param(
                 charges    => 'true',
                 flagged    => 1,
-                chargesmsg => $flags->{'CHARGES'}->{'message'}
+                chargesmsg => $flags->{'CHARGES'}->{'message'},
+                chargesamount => $flags->{'CHARGES'}->{'amount'},
             );
         }
         if ( $flag eq 'CREDITS' ) {
@@ -634,6 +628,13 @@ foreach $flag ( sort keys %$flags ) {
 my $amountold = $borrower->{flags}->{'CHARGES'}->{'message'} || 0;
 my @temp = split( /\$/, $amountold );
 
+    if ( $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") ) {
@@ -671,13 +672,14 @@ $template->param(
     dateexpiry        => format_date($newexpiry),
     expiry            => format_date($borrower->{'dateexpiry'}),
     categorycode      => $borrower->{'categorycode'},
-    categoryname      => $borrowercategory->{description},
+    categoryname      => $borrower->{description},
     address           => $borrower->{'address'},
     address2          => $borrower->{'address2'},
     email             => $borrower->{'email'},
     emailpro          => $borrower->{'emailpro'},
     borrowernotes     => $borrower->{'borrowernotes'},
     city              => $borrower->{'city'},
+    zipcode          => $borrower->{'zipcode'},
     phone             => $borrower->{'phone'} || $borrower->{'mobile'},
     cardnumber        => $borrower->{'cardnumber'},
     amountold         => $amountold,
@@ -711,9 +713,10 @@ $template->param( picture => 1 ) if $picture;
 
 
 $template->param(
+    debt_confirmed           => $debt_confirmed,
     SpecifyDueDate           => C4::Context->preference("SpecifyDueDate"),
     CircAutocompl            => C4::Context->preference("CircAutocompl"),
-       dateformat            => C4::Context->preference("dateformat"),
+    dateformat               => C4::Context->preference("dateformat"),
     DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
 );
 output_html_with_http_headers $query, $cookie, $template->output;