Bug 7143: [QA Follow-up] Handling tabs
[koha.git] / opac / opac-user.pl
index 0087a6a..04a94c0 100755 (executable)
@@ -33,11 +33,12 @@ use C4::Output;
 use C4::Biblio;
 use C4::Items;
 use C4::Letters;
-use C4::Branch; # GetBranches
 use Koha::DateUtils;
 use Koha::Holds;
 use Koha::Database;
 use Koha::Patron::Messages;
+use Koha::Patron::Discharge;
+use Koha::Patrons;
 
 use constant ATTRIBUTE_SHOW_BARCODE => 'SHOW_BCODE';
 
@@ -84,7 +85,7 @@ if (!$borrowernumber) {
 }
 
 # get borrower information ....
-my ( $borr ) = GetMemberDetails( $borrowernumber );
+my ( $borr ) = GetMember( borrowernumber => $borrowernumber );
 
 my (  $today_year,   $today_month,   $today_day) = Today();
 my ($warning_year, $warning_month, $warning_day) = split /-/, $borr->{'dateexpiry'};
@@ -98,6 +99,13 @@ if ($debar) {
     if ( $debar ne "9999-12-31" ) {
         $borr->{'userdebarreddate'} = $debar;
     }
+    # FIXME looks like $available is not needed
+    # If a patron is discharged he has a validated discharge available
+    my $available = Koha::Patron::Discharge::count({
+        borrowernumber => $borrowernumber,
+        validated      => 1,
+    });
+    $template->param( 'discharge_available' => $available && Koha::Patron::Discharge::is_discharged({borrowernumber => $borrowernumber}) );
 }
 
 if ( $userdebarred || $borr->{'gonenoaddress'} || $borr->{'lost'} ) {
@@ -105,10 +113,11 @@ if ( $userdebarred || $borr->{'gonenoaddress'} || $borr->{'lost'} ) {
     $canrenew = 0;
 }
 
-if ( $borr->{'amountoutstanding'} > 5 ) {
+my ( $amountoutstanding ) = GetMemberAccountRecords($borrowernumber);
+if ( $amountoutstanding > 5 ) {
     $borr->{'amountoverfive'} = 1;
 }
-if ( 5 >= $borr->{'amountoutstanding'} && $borr->{'amountoutstanding'} > 0 ) {
+if ( 5 >= $amountoutstanding && $amountoutstanding > 0 ) {
     $borr->{'amountoverzero'} = 1;
 }
 my $no_renewal_amt = C4::Context->preference( 'OPACFineNoRenewals' );
@@ -116,19 +125,19 @@ $no_renewal_amt = undef unless looks_like_number( $no_renewal_amt );
 
 if (   C4::Context->preference('OpacRenewalAllowed')
     && defined($no_renewal_amt)
-    && $borr->{amountoutstanding} > $no_renewal_amt )
+    && $amountoutstanding > $no_renewal_amt )
 {
     $borr->{'flagged'} = 1;
     $canrenew = 0;
     $template->param(
         renewal_blocked_fines => $no_renewal_amt,
-        renewal_blocked_fines_amountoutstanding => $borr->{amountoutstanding},
+        renewal_blocked_fines_amountoutstanding => $amountoutstanding,
     );
 }
 
-if ( $borr->{'amountoutstanding'} < 0 ) {
+if ( $amountoutstanding < 0 ) {
     $borr->{'amountlessthanzero'} = 1;
-    $borr->{'amountoutstanding'} = -1 * ( $borr->{'amountoutstanding'} );
+    $amountoutstanding = -1 * ( $amountoutstanding );
 }
 
 # Warningdate is the date that the warning starts appearing
@@ -150,6 +159,7 @@ if ( $borr->{'dateexpiry'} && C4::Context->preference('NotifyBorrowerDeparture')
 my $renew_error = $query->param('renew_error');
 
 $template->param(   BORROWER_INFO     => $borr,
+                    amountoutstanding => $amountoutstanding,
                     borrowernumber    => $borrowernumber,
                     patron_flagged    => $borr->{flagged},
                     OPACMySummaryHTML => (C4::Context->preference("OPACMySummaryHTML")) ? 1 : 0,
@@ -204,6 +214,7 @@ if ($issues){
             $issue->{'norenew_overdue'} = 1 if $renewerror eq 'overdue';
             $issue->{'auto_renew'}     = 1 if $renewerror eq 'auto_renew';
             $issue->{'auto_too_soon'}  = 1 if $renewerror eq 'auto_too_soon';
+            $issue->{'auto_too_late'}  = 1 if $renewerror eq 'auto_too_late';
 
             if ( $renewerror eq 'too_soon' ) {
                 $issue->{'too_soon'}         = 1;
@@ -264,24 +275,6 @@ if ($show_barcode) {
 }
 $template->param( show_barcode => 1 ) if $show_barcode;
 
-# load the branches
-my $branches = GetBranches();
-my @branch_loop;
-for my $branch_hash ( sort keys %{$branches} ) {
-    my $selected;
-    if ( C4::Context->preference('SearchMyLibraryFirst') ) {
-        $selected =
-          ( C4::Context->userenv
-              && ( $branch_hash eq C4::Context->userenv->{branch} ) );
-    }
-    push @branch_loop,
-      { value      => "branch: $branch_hash",
-        branchname => $branches->{$branch_hash}->{'branchname'},
-        selected   => $selected,
-      };
-}
-$template->param( branchloop => \@branch_loop );
-
 # now the reserved items....
 my $reserves = Koha::Holds->search( { borrowernumber => $borrowernumber } );
 
@@ -319,16 +312,6 @@ my $patron_messages = Koha::Patron::Messages->search(
         message_type => 'B',
     }
 );
-if ( $patron_messages->count ) {
-    $template->param( bor_messages => 1 );
-}
-
-if ( $borr->{'opacnote'} ) {
-  $template->param( 
-    bor_messages => 1,
-    opacnote => $borr->{'opacnote'},
-  );
-}
 
 if (   C4::Context->preference('AllowPatronToSetCheckoutsVisibilityForGuarantor')
     || C4::Context->preference('AllowStaffToSetCheckoutsVisibilityForGuarantor') )
@@ -345,8 +328,9 @@ if (   C4::Context->preference('AllowPatronToSetCheckoutsVisibilityForGuarantor'
 }
 
 $template->param(
-    borrower                 => $borr,
+    borrower                 => Koha::Patrons->find($borrowernumber),
     patron_messages          => $patron_messages,
+    opacnote                 => $borr->{opacnote},
     patronupdate             => $patronupdate,
     OpacRenewalAllowed       => C4::Context->preference("OpacRenewalAllowed"),
     userview                 => 1,