Bug 22534: (RM follow-up) Remove errant hidden file
[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
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
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::Circulation qw( GetIssuingCharges );
26 use C4::Reserves;
27 use C4::Items;
28 use Koha::DateUtils;
29 use Koha::Holds;
30 use Koha::ItemTypes;
31 use Koha::Patrons;
32
33 my $input          = CGI->new;
34 my $borrowernumber = $input->param('borrowernumber');
35
36 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
37     {
38         template_name   => "members/moremember-print.tt",
39         query           => $input,
40         type            => "intranet",
41         authnotrequired => 0,
42         flagsrequired   => { circulate => "circulate_remaining_permissions" },
43         debug           => 1,
44     }
45 );
46
47 my $logged_in_user = Koha::Patrons->find( $loggedinuser );
48 my $patron         = Koha::Patrons->find( $borrowernumber );
49 output_and_exit_if_error( $input, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } );
50
51 my $total = $patron->account->balance;
52 my $accts = Koha::Account::Lines->search(
53     { borrowernumber => $patron->borrowernumber, amountoutstanding => { '!=' => 0 } },
54     { order_by       => { -desc => 'accountlines_id' } }
55 );
56
57 our $totalprice = 0;
58
59 my $holds_rs = Koha::Holds->search(
60     { borrowernumber => $borrowernumber },
61 );
62
63 $template->param(
64     patron => $patron,
65
66     accounts => $accts,
67     totaldue => $total,
68
69     issues     => build_issue_data( $borrowernumber ),
70     totalprice => $totalprice,
71
72     reserves => build_reserve_data( $holds_rs ),
73 );
74
75 output_html_with_http_headers $input, $cookie, $template->output;
76
77 sub build_issue_data {
78     my ( $borrowernumber ) = @_;
79     my $patron = Koha::Patrons->find( $borrowernumber );
80     return unless $patron;
81
82     my $pending_checkouts = $patron->pending_checkouts->search( {},
83         { order_by => [ { -desc => 'date_due' }, { -asc => 'issue_id' } ] } );
84
85     my @checkouts;
86
87     while ( my $c = $pending_checkouts->next ) {
88         my $checkout = $c->unblessed_all_relateds;
89
90         $totalprice += $checkout->{replacementprice}
91             if $checkout->{replacementprice};
92
93         #find the charge for an item
94         my ( $charge, $itemtype ) =
95           GetIssuingCharges( $checkout->{itemnumber}, $borrowernumber );
96
97         $checkout->{charge} = $charge;
98
99         $checkout->{overdue} = $c->is_overdue;
100
101         push @checkouts, $checkout;
102     }
103
104     return \@checkouts;
105
106 }
107
108 sub build_reserve_data {
109     my $reserves = shift;
110
111     my $return = [];
112
113     my $today = dt_from_string();
114     $today->truncate( to => 'day' );
115
116     while ( my $reserve = $reserves->next() ) {
117
118         my $row = {
119             title          => $reserve->biblio()->title(),
120             author         => $reserve->biblio()->author(),
121             reservedate    => $reserve->reservedate(),
122             expirationdate => $reserve->expirationdate(),
123             waiting_at     => $reserve->branch()->branchname(),
124         };
125
126         push( @{$return}, $row );
127     }
128
129     @{$return} = sort { $a->{reservedate} <=> $b->{reservedate} } @{$return};
130
131     return $return;
132 }