Merge branch 'bug_7368' into 3.14-master
[koha.git] / members / printinvoice.pl
1 #!/usr/bin/perl
2
3
4 #writen 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 under the
13 # terms of the GNU General Public License as published by the Free Software
14 # Foundation; either version 2 of the License, or (at your option) any later
15 # version.
16 #
17 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
18 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
19 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License along
22 # with Koha; if not, write to the Free Software Foundation, Inc.,
23 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24
25 use strict;
26 use warnings;
27
28 use C4::Auth;
29 use C4::Output;
30 use C4::Dates qw/format_date/;
31 use CGI;
32 use C4::Members;
33 use C4::Branch;
34 use C4::Accounts;
35
36 my $input=new CGI;
37
38
39 my ($template, $loggedinuser, $cookie)
40     = get_template_and_user({template_name => "members/printinvoice.tmpl",
41                             query => $input,
42                             type => "intranet",
43                             authnotrequired => 0,
44                             flagsrequired => {borrowers => 1, updatecharges => 1},
45                             debug => 1,
46                             });
47
48 my $borrowernumber=$input->param('borrowernumber');
49 my $action = $input->param('action') || '';
50 my $accountno = $input->param('accountno');
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]{'accountno'} ne $accountno);
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     }
88     $accts->[$i]{'amountoutstanding'}+=0.00;
89     if($accts->[$i]{'amountoutstanding'} <= 0){
90         $accts->[$i]{'amountoutstandingcredit'} = 1;
91     }
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                 'payment' => ( $accts->[$i]{'accounttype'} eq 'Pay' ),
103
104                 );
105
106     if ($accts->[$i]{'accounttype'} ne 'F' && $accts->[$i]{'accounttype'} ne 'FU'){
107         $row{'printtitle'}=1;
108         $row{'title'} = $accts->[$i]{'title'};
109     }
110
111     push(@accountrows, \%row);
112 }
113
114 $template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' );
115
116 my ($picture, $dberror) = GetPatronImage($data->{'cardnumber'});
117 $template->param( picture => 1 ) if $picture;
118
119 $template->param(
120     finesview           => 1,
121     firstname           => $data->{'firstname'},
122     surname             => $data->{'surname'},
123     borrowernumber      => $borrowernumber,
124     cardnumber          => $data->{'cardnumber'},
125     categorycode        => $data->{'categorycode'},
126     category_type       => $data->{'category_type'},
127  #   category_description => $data->{'description'},
128     categoryname                 => $data->{'description'},
129     address             => $data->{'address'},
130     address2            => $data->{'address2'},
131     city                => $data->{'city'},
132     zipcode             => $data->{'zipcode'},
133     country             => $data->{'country'},
134     phone               => $data->{'phone'},
135     email               => $data->{'email'},
136     branchcode          => $data->{'branchcode'},
137         branchname                      => GetBranchName($data->{'branchcode'}),
138     total               => sprintf("%.2f",$total),
139     totalcredit         => $totalcredit,
140         is_child        => ($data->{'category_type'} eq 'C'),
141     accounts            => \@accountrows );
142
143 output_html_with_http_headers $input, $cookie, $template->output;