Bug 14030: (RM followup) fix copypasta blooper
[koha.git] / members / printfeercpt.pl
blob8ffc49ff7c073c2f846fdd955a4739054dfcbd89
1 #!/usr/bin/perl
4 #writen 3rd May 2010 by kmkale@anantcorp.com adapted from boraccount.pl by chris@katipo.oc.nz
5 #script to print fee receipts
8 # Copyright Koustubha Kale
10 # This file is part of Koha.
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.
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.
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>.
25 use strict;
26 use warnings;
28 use C4::Auth;
29 use C4::Output;
30 use C4::Dates qw/format_date/;
31 use CGI qw ( -utf8 );
32 use C4::Members;
33 use C4::Branch;
34 use C4::Accounts;
36 my $input=new CGI;
39 my ($template, $loggedinuser, $cookie)
40 = get_template_and_user({template_name => "members/printfeercpt.tt",
41 query => $input,
42 type => "intranet",
43 authnotrequired => 0,
44 flagsrequired => {borrowers => 1, updatecharges => 'remaining_permissions'},
45 debug => 1,
46 });
48 my $borrowernumber=$input->param('borrowernumber');
49 my $action = $input->param('action') || '';
50 my $accountlines_id = $input->param('accountlines_id');
52 #get borrower details
53 my $data=GetMember('borrowernumber' => $borrowernumber);
55 if ( $action eq 'print' ) {
56 # ReversePayment( $borrowernumber, $input->param('accountno') );
59 if ( $data->{'category_type'} eq 'C') {
60 my ( $catcodes, $labels ) = GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
61 my $cnt = scalar(@$catcodes);
62 $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
63 $template->param( 'catcode' => $catcodes->[0]) if $cnt == 1;
66 #get account details
67 my ($total,$accts,$numaccts)=GetMemberAccountRecords($borrowernumber);
68 my $totalcredit;
69 if($total <= 0){
70 $totalcredit = 1;
72 my @accountrows; # this is for the tmpl-loop
74 my $toggle;
75 for (my $i=0;$i<$numaccts;$i++){
76 next if ( $accts->[$i]{'accountlines_id'} ne $accountlines_id );
77 if($i%2){
78 $toggle = 0;
79 } else {
80 $toggle = 1;
82 $accts->[$i]{'toggle'} = $toggle;
83 $accts->[$i]{'amount'}+=0.00;
84 if($accts->[$i]{'amount'} <= 0){
85 $accts->[$i]{'amountcredit'} = 1;
86 $accts->[$i]{'amount'}*=-1.00;
88 $accts->[$i]{'amountoutstanding'}+=0.00;
89 if($accts->[$i]{'amountoutstanding'} <= 0){
90 $accts->[$i]{'amountoutstandingcredit'} = 1;
92 my %row = ( 'date' => format_date($accts->[$i]{'date'}),
93 'amountcredit' => $accts->[$i]{'amountcredit'},
94 'amountoutstandingcredit' => $accts->[$i]{'amountoutstandingcredit'},
95 'toggle' => $accts->[$i]{'toggle'},
96 'description' => $accts->[$i]{'description'},
97 'itemnumber' => $accts->[$i]{'itemnumber'},
98 'biblionumber' => $accts->[$i]{'biblionumber'},
99 'amount' => sprintf("%.2f",$accts->[$i]{'amount'}),
100 'amountoutstanding' => sprintf("%.2f",$accts->[$i]{'amountoutstanding'}),
101 'accountno' => $accts->[$i]{'accountno'},
102 accounttype => $accts->[$i]{accounttype},
105 if ($accts->[$i]{'accounttype'} ne 'F' && $accts->[$i]{'accounttype'} ne 'FU'){
106 $row{'printtitle'}=1;
107 $row{'title'} = $accts->[$i]{'title'};
110 push(@accountrows, \%row);
113 $template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' );
115 my ($picture, $dberror) = GetPatronImage($data->{'borrowernumber'});
116 $template->param( picture => 1 ) if $picture;
118 $template->param(
119 finesview => 1,
120 firstname => $data->{'firstname'},
121 surname => $data->{'surname'},
122 borrowernumber => $borrowernumber,
123 cardnumber => $data->{'cardnumber'},
124 categorycode => $data->{'categorycode'},
125 category_type => $data->{'category_type'},
126 # category_description => $data->{'description'},
127 categoryname => $data->{'description'},
128 address => $data->{'address'},
129 address2 => $data->{'address2'},
130 city => $data->{'city'},
131 zipcode => $data->{'zipcode'},
132 country => $data->{'country'},
133 phone => $data->{'phone'},
134 email => $data->{'email'},
135 branchcode => $data->{'branchcode'},
136 branchname => GetBranchName($data->{'branchcode'}),
137 total => sprintf("%.2f",$total),
138 totalcredit => $totalcredit,
139 is_child => ($data->{'category_type'} eq 'C'),
140 accounts => \@accountrows );
142 output_html_with_http_headers $input, $cookie, $template->output;