Bug 17100: Do not display payments if patron has nothing to pay
[koha-ffzg.git] / members / summary-print.pl
index 7bed793..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,11 +46,6 @@ my $data = GetMember( 'borrowernumber' => $borrowernumber );
 
 my ( $total, $accts, $numaccts ) = GetMemberAccountRecords($borrowernumber);
 foreach my $accountline (@$accts) {
-    $accountline->{amount} = sprintf( '%.2f', $accountline->{amount} )
-        if ( $accountline->{amount} ) ;
-    $accountline->{amountoutstanding} = sprintf( '%.2f', $accountline->{amountoutstanding} )
-        if ( $accountline->{amountoutstanding} );
-
     if (   $accountline->{accounttype} ne 'F'
         && $accountline->{accounttype} ne 'FU' )
     {
@@ -55,25 +53,24 @@ foreach my $accountline (@$accts) {
     }
 }
 
-my $roadtype =
-  C4::Koha::GetAuthorisedValueByCode( 'ROADTYPE', $data->{streettype} );
-$roadtype = '' if ( ! $roadtype );
-
 our $totalprice = 0;
-my $total_format = '';
-$total_format = sprintf( "%.2f", $total ) if ($total);
+
+my $holds_rs = Koha::Holds->search(
+    { borrowernumber => $borrowernumber },
+);
 
 $template->param(
     %$data,
 
     borrowernumber => $borrowernumber,
-    address => $data->{'streetnumber'} . " $roadtype " . $data->{'address'},
 
     accounts => $accts,
-    totaldue => $total_format,
+    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;
@@ -109,4 +106,31 @@ sub build_issue_data {
     @{$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;
 }