Bug 18423 - Add 'Add child' button to files, housebound, and deletemem pages
[koha.git] / members / printfeercpt.pl
1 #!/usr/bin/perl
2
3
4 #written 3rd May 2010 by kmkale@anantcorp.com adapted from boraccount.pl by chris@katipo.oc.nz
5 #script to print fee receipts
6
7
8 # Copyright Koustubha Kale
9 #
10 # This file is part of Koha.
11 #
12 # Koha is free software; you can redistribute it and/or modify it
13 # under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 3 of the License, or
15 # (at your option) any later version.
16 #
17 # Koha is distributed in the hope that it will be useful, but
18 # WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License
23 # along with Koha; if not, see <http://www.gnu.org/licenses>.
24
25 use strict;
26 use warnings;
27
28 use C4::Auth;
29 use C4::Output;
30 use CGI qw ( -utf8 );
31 use C4::Members;
32 use C4::Branch;
33 use C4::Accounts;
34 use Koha::DateUtils;
35 use Koha::Patron::Images;
36
37 my $input=new CGI;
38
39
40 my ($template, $loggedinuser, $cookie)
41     = get_template_and_user({template_name => "members/printfeercpt.tt",
42                             query => $input,
43                             type => "intranet",
44                             authnotrequired => 0,
45                             flagsrequired => {borrowers => 1, updatecharges => 'remaining_permissions'},
46                             debug => 1,
47                             });
48
49 my $borrowernumber=$input->param('borrowernumber');
50 my $action = $input->param('action') || '';
51 my $accountlines_id = $input->param('accountlines_id');
52
53 #get borrower details
54 my $data=GetMember('borrowernumber' => $borrowernumber);
55
56 if ( $action eq 'print' ) {
57 #  ReversePayment( $borrowernumber, $input->param('accountno') );
58 }
59
60 if ( $data->{'category_type'} eq 'C') {
61    my  ( $catcodes, $labels ) =  GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
62    my $cnt = scalar(@$catcodes);
63    $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
64    $template->param( 'catcode' =>    $catcodes->[0])  if $cnt == 1;
65 }
66
67 #get account details
68 my ($total,$accts,$numaccts)=GetMemberAccountRecords($borrowernumber);
69 my $totalcredit;
70 if($total <= 0){
71         $totalcredit = 1;
72 }
73 my @accountrows; # this is for the tmpl-loop
74
75 my $toggle;
76 for (my $i=0;$i<$numaccts;$i++){
77     next if ( $accts->[$i]{'accountlines_id'} ne $accountlines_id );
78     if($i%2){
79             $toggle = 0;
80     } else {
81             $toggle = 1;
82     }
83     $accts->[$i]{'toggle'} = $toggle;
84     $accts->[$i]{'amount'}+=0.00;
85     if($accts->[$i]{'amount'} <= 0){
86         $accts->[$i]{'amountcredit'} = 1;
87         $accts->[$i]{'amount'}*=-1.00;
88     }
89     $accts->[$i]{'amountoutstanding'}+=0.00;
90     if($accts->[$i]{'amountoutstanding'} <= 0){
91         $accts->[$i]{'amountoutstandingcredit'} = 1;
92     }
93
94     my %row = ( 'date'         => dt_from_string( $accts->[$i]{'date'} ),
95                 'amountcredit' => $accts->[$i]{'amountcredit'},
96                 'amountoutstandingcredit' => $accts->[$i]{'amountoutstandingcredit'},
97                 'toggle' => $accts->[$i]{'toggle'},
98                 'description'       => $accts->[$i]{'description'},
99                                 'itemnumber'       => $accts->[$i]{'itemnumber'},
100                                 'biblionumber'       => $accts->[$i]{'biblionumber'},
101                 'amount'            => sprintf("%.2f",$accts->[$i]{'amount'}),
102                 'amountoutstanding' => sprintf("%.2f",$accts->[$i]{'amountoutstanding'}),
103                 'accountno' => $accts->[$i]{'accountno'},
104                 accounttype => $accts->[$i]{accounttype},
105                 'note' => $accts->[$i]{'note'},
106                 );
107
108     if ($accts->[$i]{'accounttype'} ne 'F' && $accts->[$i]{'accounttype'} ne 'FU'){
109         $row{'printtitle'}=1;
110         $row{'title'} = $accts->[$i]{'title'};
111     }
112
113     push(@accountrows, \%row);
114 }
115
116 $template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' );
117
118 my $patron_image = Koha::Patron::Images->find($data->{borrowernumber});
119 $template->param( picture => 1 ) if $patron_image;
120
121 $template->param(
122     finesview           => 1,
123     firstname           => $data->{'firstname'},
124     surname             => $data->{'surname'},
125     borrowernumber      => $borrowernumber,
126     cardnumber          => $data->{'cardnumber'},
127     categorycode        => $data->{'categorycode'},
128     category_type       => $data->{'category_type'},
129  #   category_description => $data->{'description'},
130     categoryname                 => $data->{'description'},
131     address             => $data->{'address'},
132     address2            => $data->{'address2'},
133     city                => $data->{'city'},
134     zipcode             => $data->{'zipcode'},
135     country             => $data->{'country'},
136     phone               => $data->{'phone'},
137     email               => $data->{'email'},
138     branchcode          => $data->{'branchcode'},
139         branchname                      => GetBranchName($data->{'branchcode'}),
140     total               => sprintf("%.2f",$total),
141     totalcredit         => $totalcredit,
142         is_child        => ($data->{'category_type'} eq 'C'),
143     accounts            => \@accountrows );
144
145 output_html_with_http_headers $input, $cookie, $template->output;