Bug 17100: Do not display payments if patron has nothing to pay
[koha-ffzg.git] / members / summary-print.pl
index 4530e14..82b1ca2 100755 (executable)
@@ -24,6 +24,9 @@ use C4::Output;
 use C4::Members;
 use C4::Koha qw( getitemtypeinfo );
 use C4::Circulation qw( GetIssuingCharges );
+use C4::Reserves;
+use C4::Items;
+use Koha::Holds;
 
 my $input          = CGI->new;
 my $borrowernumber = $input->param('borrowernumber');
@@ -43,10 +46,6 @@ my $data = GetMember( 'borrowernumber' => $borrowernumber );
 
 my ( $total, $accts, $numaccts ) = GetMemberAccountRecords($borrowernumber);
 foreach my $accountline (@$accts) {
-    $accountline->{amount} = sprintf '%.2f', $accountline->{amount};
-    $accountline->{amountoutstanding} = sprintf '%.2f',
-      $accountline->{amountoutstanding};
-
     if (   $accountline->{accounttype} ne 'F'
         && $accountline->{accounttype} ne 'FU' )
     {
@@ -54,21 +53,24 @@ foreach my $accountline (@$accts) {
     }
 }
 
-my $roadtype =
-  C4::Koha::GetAuthorisedValueByCode( 'ROADTYPE', $data->{streettype} );
-
 our $totalprice = 0;
+
+my $holds_rs = Koha::Holds->search(
+    { borrowernumber => $borrowernumber },
+);
+
 $template->param(
     %$data,
 
     borrowernumber => $borrowernumber,
-    address => $data->{'streetnumber'} . " $roadtype " . $data->{'address'},
 
     accounts => $accts,
-    totaldue => sprintf( "%.2f", $total ),
+    totaldue => $total,
 
     issues     => build_issue_data( GetPendingIssues($borrowernumber) ),
     totalprice => $totalprice,
+
+    reserves => build_reserve_data( $holds_rs ),
 );
 
 output_html_with_http_headers $input, $cookie, $template->output;
@@ -84,7 +86,8 @@ sub build_issue_data {
     foreach my $issue ( @{$issues} ) {
 
         my %row = %{$issue};
-        $totalprice += $issue->{replacementprice};
+        $totalprice += $issue->{replacementprice}
+            if ( $issue->{replacementprice} );
 
         #find the charge for an item
         my ( $charge, $itemtype ) =
@@ -100,7 +103,34 @@ sub build_issue_data {
         push( @{$return}, \%row );
     }
 
-    @{$return} = sort { $a->{date_due} <=> $b->{date_due} } @{$return};
+    @{$return} = sort { $a->{date_due} eq $b->{date_due} } @{$return};
+
+    return $return;
+
+}
+
+sub build_reserve_data {
+    my $reserves = shift;
+
+    my $return = [];
+
+    my $today = DateTime->now( time_zone => C4::Context->tz );
+    $today->truncate( to => 'day' );
+
+    while ( my $reserve = $reserves->next() ) {
+
+        my $row = {
+            title          => $reserve->biblio()->title(),
+            author         => $reserve->biblio()->author(),
+            reservedate    => $reserve->reservedate(),
+            expirationdate => $reserve->expirationdate(),
+            waiting_at     => $reserve->branch()->branchname(),
+        };
+
+        push( @{$return}, $row );
+    }
+
+    @{$return} = sort { $a->{reservedate} <=> $b->{reservedate} } @{$return};
 
     return $return;
 }