Bug 18349: SCO - Do not trust the confirmed flag
[koha.git] / members / printfeercpt.pl
blobc92dbd67bf8afdcd9e3ad6324980ce5df9cf9866
1 #!/usr/bin/perl
4 #written 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 CGI qw ( -utf8 );
31 use C4::Members;
32 use C4::Accounts;
33 use Koha::DateUtils;
34 use Koha::Patron::Images;
35 use Koha::Patron::Categories;
37 my $input=new CGI;
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 });
49 my $borrowernumber=$input->param('borrowernumber');
50 my $action = $input->param('action') || '';
51 my $accountlines_id = $input->param('accountlines_id');
53 #get borrower details
54 my $data=GetMember('borrowernumber' => $borrowernumber);
56 if ( $action eq 'print' ) {
57 # ReversePayment( $borrowernumber, $input->param('accountno') );
60 if ( $data->{'category_type'} eq 'C') {
61 my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
62 $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
63 $template->param( 'catcode' => $patron_categories->next ) if $patron_categories->count == 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;
93 my %row = ( 'date' => dt_from_string( $accts->[$i]{'date'} ),
94 'amountcredit' => $accts->[$i]{'amountcredit'},
95 'amountoutstandingcredit' => $accts->[$i]{'amountoutstandingcredit'},
96 'toggle' => $accts->[$i]{'toggle'},
97 'description' => $accts->[$i]{'description'},
98 'itemnumber' => $accts->[$i]{'itemnumber'},
99 'biblionumber' => $accts->[$i]{'biblionumber'},
100 'amount' => sprintf("%.2f",$accts->[$i]{'amount'}),
101 'amountoutstanding' => sprintf("%.2f",$accts->[$i]{'amountoutstanding'}),
102 'accountno' => $accts->[$i]{'accountno'},
103 accounttype => $accts->[$i]{accounttype},
104 'note' => $accts->[$i]{'note'},
107 if ($accts->[$i]{'accounttype'} ne 'F' && $accts->[$i]{'accounttype'} ne 'FU'){
108 $row{'printtitle'}=1;
109 $row{'title'} = $accts->[$i]{'title'};
112 push(@accountrows, \%row);
115 $template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' );
117 my $patron_image = Koha::Patron::Images->find($data->{borrowernumber});
118 $template->param( picture => 1 ) if $patron_image;
120 $template->param(
121 finesview => 1,
122 firstname => $data->{'firstname'},
123 surname => $data->{'surname'},
124 borrowernumber => $borrowernumber,
125 cardnumber => $data->{'cardnumber'},
126 categorycode => $data->{'categorycode'},
127 category_type => $data->{'category_type'},
128 # category_description => $data->{'description'},
129 categoryname => $data->{'description'},
130 address => $data->{'address'},
131 address2 => $data->{'address2'},
132 city => $data->{'city'},
133 zipcode => $data->{'zipcode'},
134 country => $data->{'country'},
135 phone => $data->{'phone'},
136 email => $data->{'email'},
137 branchcode => $data->{'branchcode'},
138 total => sprintf("%.2f",$total),
139 totalcredit => $totalcredit,
140 is_child => ($data->{'category_type'} eq 'C'),
141 accounts => \@accountrows );
143 output_html_with_http_headers $input, $cookie, $template->output;