Bug 18394: Add an option to item search to export a barcodes file
[koha.git] / members / summary-print.pl
blob14df30f9f8150ad065e5a1b4ebee4ed4625c2669
1 #!/usr/bin/perl
3 # This file is part of Koha.
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.
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.
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.
18 use Modern::Perl;
20 use CGI;
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;
31 my $input = CGI->new;
32 my $borrowernumber = $input->param('borrowernumber');
34 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
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,
45 my $data = GetMember( 'borrowernumber' => $borrowernumber );
47 my ( $total, $accts, $numaccts ) = GetMemberAccountRecords($borrowernumber);
48 foreach my $accountline (@$accts) {
49 if ( $accountline->{accounttype} ne 'F'
50 && $accountline->{accounttype} ne 'FU' )
52 $accountline->{printtitle} = 1;
56 our $totalprice = 0;
58 my $holds_rs = Koha::Holds->search(
59 { borrowernumber => $borrowernumber },
62 $template->param(
63 %$data,
65 borrowernumber => $borrowernumber,
67 accounts => $accts,
68 totaldue => $total,
70 issues => build_issue_data( $borrowernumber ),
71 totalprice => $totalprice,
73 reserves => build_reserve_data( $holds_rs ),
76 output_html_with_http_headers $input, $cookie, $template->output;
78 sub build_issue_data {
79 my ( $borrowernumber ) = @_;
80 my $issues = GetPendingIssues( $borrowernumber );
82 my $return = [];
84 my $today = DateTime->now( time_zone => C4::Context->tz );
85 $today->truncate( to => 'day' );
87 foreach my $issue ( @{$issues} ) {
89 my %row = %{$issue};
90 $totalprice += $issue->{replacementprice}
91 if ( $issue->{replacementprice} );
93 #find the charge for an item
94 my ( $charge, $itemtype ) =
95 GetIssuingCharges( $issue->{itemnumber}, $borrowernumber );
97 my $itemtypeinfo = getitemtypeinfo($itemtype);
98 $row{'itemtype_description'} = $itemtypeinfo->{description};
100 $row{'charge'} = sprintf( "%.2f", $charge );
102 $row{date_due} = $row{date_due_sql};
104 push( @{$return}, \%row );
107 @{$return} = sort { $a->{date_due} eq $b->{date_due} } @{$return};
109 return $return;
113 sub build_reserve_data {
114 my $reserves = shift;
116 my $return = [];
118 my $today = DateTime->now( time_zone => C4::Context->tz );
119 $today->truncate( to => 'day' );
121 while ( my $reserve = $reserves->next() ) {
123 my $row = {
124 title => $reserve->biblio()->title(),
125 author => $reserve->biblio()->author(),
126 reservedate => $reserve->reservedate(),
127 expirationdate => $reserve->expirationdate(),
128 waiting_at => $reserve->branch()->branchname(),
131 push( @{$return}, $row );
134 @{$return} = sort { $a->{reservedate} <=> $b->{reservedate} } @{$return};
136 return $return;