Bug 20568: API keys management in interface
[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 Modern::Perl;
26
27 use C4::Auth;
28 use C4::Output;
29 use CGI qw ( -utf8 );
30 use C4::Members;
31 use C4::Accounts;
32 use Koha::Account::Lines;
33 use Koha::DateUtils;
34 use Koha::Patrons;
35 use Koha::Patron::Categories;
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 => 'edit_borrowers', 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 my $logged_in_user = Koha::Patrons->find( $loggedinuser ) or die "Not logged in";
54 my $patron         = Koha::Patrons->find( $borrowernumber );
55 output_and_exit_if_error( $input, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } );
56
57 if ( $action eq 'print' ) {
58 #  ReversePayment( $borrowernumber, $input->param('accountno') );
59 }
60
61 if ( $patron->is_child ) {
62     my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
63     $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
64     $template->param( 'catcode' => $patron_categories->next->categorycde )  if $patron_categories->count == 1;
65 }
66
67 #get account details
68 my $total = $patron->account->balance;
69
70 # FIXME This whole stuff is ugly and should be rewritten
71 # FIXME We should pass the $accts iterator to the template and do this formatting part there
72 my $accountline = Koha::Account::Lines->find($accountlines_id)->unblessed;
73 my $totalcredit;
74 if($total <= 0){
75         $totalcredit = 1;
76 }
77
78 $accountline->{'amount'} += 0.00;
79 if ( $accountline->{'amount'} <= 0 ) {
80     $accountline->{'amountcredit'} = 1;
81     $accountline->{'amount'} *= -1.00;
82 }
83 $accountline->{'amountoutstanding'} += 0.00;
84 if ( $accountline->{'amountoutstanding'} <= 0 ) {
85     $accountline->{'amountoutstandingcredit'} = 1;
86 }
87
88 my %row = (
89     'date'                    => dt_from_string( $accountline->{'date'} ),
90     'amountcredit'            => $accountline->{'amountcredit'},
91     'amountoutstandingcredit' => $accountline->{'amountoutstandingcredit'},
92     'description'             => $accountline->{'description'},
93     'amount'                  => sprintf( "%.2f", $accountline->{'amount'} ),
94     'amountoutstanding' =>
95       sprintf( "%.2f", $accountline->{'amountoutstanding'} ),
96     'accountno' => $accountline->{'accountno'},
97     accounttype => $accountline->{accounttype},
98     'note'      => $accountline->{'note'},
99 );
100
101
102 $template->param(
103     patron               => $patron,
104     finesview           => 1,
105     total               => sprintf("%.2f",$total),
106     totalcredit         => $totalcredit,
107     accounts            => [$accountline], # FIXME There is always only 1 row!
108 );
109
110 output_html_with_http_headers $input, $cookie, $template->output;