Bug 10468: (followup) fix indentation
[koha.git] / members / summary-print.pl
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 3 of the License, or (at your option) any later
8 # version.
9 #
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License along
15 # with Koha; if not, write to the Free Software Foundation, Inc.,
16 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18 use Modern::Perl;
19
20 use CGI;
21
22 use C4::Auth;
23 use C4::Output;
24 use C4::Members;
25 use C4::Koha qw( getitemtypeinfo );
26 use C4::Circulation qw( GetIssuingCharges );
27 use C4::Reserves;
28 use C4::Items;
29 use Koha::Holds;
30
31 my $input          = CGI->new;
32 my $borrowernumber = $input->param('borrowernumber');
33
34 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
35     {
36         template_name   => "members/moremember-print.tt",
37         query           => $input,
38         type            => "intranet",
39         authnotrequired => 0,
40         flagsrequired   => { circulate => "circulate_remaining_permissions" },
41         debug           => 1,
42     }
43 );
44
45 my $data = GetMember( 'borrowernumber' => $borrowernumber );
46
47 my ( $total, $accts, $numaccts ) = GetMemberAccountRecords($borrowernumber);
48 foreach my $accountline (@$accts) {
49     $accountline->{amount} = sprintf( '%.2f', $accountline->{amount} )
50         if ( $accountline->{amount} ) ;
51     $accountline->{amountoutstanding} = sprintf( '%.2f', $accountline->{amountoutstanding} )
52         if ( $accountline->{amountoutstanding} );
53
54     if (   $accountline->{accounttype} ne 'F'
55         && $accountline->{accounttype} ne 'FU' )
56     {
57         $accountline->{printtitle} = 1;
58     }
59 }
60
61 my $roadtype =
62   C4::Koha::GetAuthorisedValueByCode( 'ROADTYPE', $data->{streettype} ) // '';
63 $roadtype = '' if ( ! $roadtype );
64
65 our $totalprice = 0;
66 my $total_format = '';
67 $total_format = sprintf( "%.2f", $total ) if ($total);
68
69 my $holds_rs = Koha::Holds->search(
70     { borrowernumber => $borrowernumber },
71 );
72
73 $template->param(
74     %$data,
75
76     borrowernumber => $borrowernumber,
77     address => $data->{'streetnumber'} . " $roadtype " . $data->{'address'},
78
79     accounts => $accts,
80     totaldue => $total_format,
81
82     issues     => build_issue_data( GetPendingIssues($borrowernumber) ),
83     totalprice => $totalprice,
84
85     reserves => build_reserve_data( $holds_rs ),
86 );
87
88 output_html_with_http_headers $input, $cookie, $template->output;
89
90 sub build_issue_data {
91     my $issues = shift;
92
93     my $return = [];
94
95     my $today = DateTime->now( time_zone => C4::Context->tz );
96     $today->truncate( to => 'day' );
97
98     foreach my $issue ( @{$issues} ) {
99
100         my %row = %{$issue};
101         $totalprice += $issue->{replacementprice}
102             if ( $issue->{replacementprice} );
103
104         #find the charge for an item
105         my ( $charge, $itemtype ) =
106           GetIssuingCharges( $issue->{itemnumber}, $borrowernumber );
107
108         my $itemtypeinfo = getitemtypeinfo($itemtype);
109         $row{'itemtype_description'} = $itemtypeinfo->{description};
110
111         $row{'charge'} = sprintf( "%.2f", $charge );
112
113         $row{date_due} = $row{date_due_sql};
114
115         push( @{$return}, \%row );
116     }
117
118     @{$return} = sort { $a->{date_due} eq $b->{date_due} } @{$return};
119
120     return $return;
121
122 }
123
124 sub build_reserve_data {
125     my $reserves = shift;
126
127     my $return = [];
128
129     my $today = DateTime->now( time_zone => C4::Context->tz );
130     $today->truncate( to => 'day' );
131
132     while ( my $reserve = $reserves->next() ) {
133
134         my $row = {
135             title          => $reserve->biblio()->title(),
136             author         => $reserve->biblio()->author(),
137             reservedate    => $reserve->reservedate(),
138             expirationdate => $reserve->expirationdate(),
139             waiting_at     => $reserve->branch()->branchname(),
140         };
141
142         push( @{$return}, $row );
143     }
144
145     @{$return} = sort { $a->{reservedate} <=> $b->{reservedate} } @{$return};
146
147     return $return;
148 }