4 #written 11/1/2000 by chris@katipo.oc.nz
5 #script to display borrowers account details
8 # Copyright 2000-2002 Katipo Communications
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>.
33 use Koha
::Cash
::Registers
;
35 use Koha
::Patron
::Categories
;
42 my ($template, $loggedinuser, $cookie) = get_template_and_user
(
44 template_name
=> "members/boraccount.tt",
47 flagsrequired
=> { borrowers
=> 'edit_borrowers',
48 updatecharges
=> 'remaining_permissions'},
53 my $schema = Koha
::Database
->new->schema;
54 my $borrowernumber = $input->param('borrowernumber');
55 my $payment_id = $input->param('payment_id');
56 my $change_given = $input->param('change_given');
57 my $action = $input->param('action') || '';
58 my @renew_results = $input->param('renew_result');
60 my $logged_in_user = Koha
::Patrons
->find( $loggedinuser );
61 my $library_id = C4
::Context
->userenv->{'branch'};
62 my $patron = Koha
::Patrons
->find( $borrowernumber );
64 print $input->redirect("/cgi-bin/koha/circ/circulation.pl?borrowernumber=$borrowernumber");
68 output_and_exit_if_error
( $input, $cookie, $template, { module
=> 'members', logged_in_user
=> $logged_in_user, current_patron
=> $patron } );
70 my $registerid = $input->param('registerid');
72 if ( $action eq 'void' ) {
73 my $payment_id = scalar $input->param('accountlines_id');
74 my $payment = Koha
::Account
::Lines
->find( $payment_id );
78 if ( $action eq 'payout' ) {
79 my $payment_id = scalar $input->param('accountlines_id');
80 my $payment = Koha
::Account
::Lines
->find($payment_id);
81 my $amount = scalar $input->param('amount');
82 my $transaction_type = scalar $input->param('transaction_type');
85 my $payout = $payment->payout(
87 payout_type
=> $transaction_type,
88 branch
=> $library_id,
89 staff_id
=> $logged_in_user->id,
90 cash_register
=> $registerid,
91 interface
=> 'intranet',
99 if ( $action eq 'refund' ) {
100 my $charge_id = scalar $input->param('accountlines_id');
101 my $charge = Koha
::Account
::Lines
->find($charge_id);
102 my $amount = scalar $input->param('amount');
103 my $transaction_type = scalar $input->param('transaction_type');
107 my $refund = $charge->reduce(
109 reduction_type
=> 'REFUND',
110 branch
=> $library_id,
111 staff_id
=> $logged_in_user->id,
112 interface
=> 'intranet',
116 unless ( $transaction_type eq 'AC' ) {
117 my $payout = $refund->payout(
119 payout_type
=> $transaction_type,
120 branch
=> $library_id,
121 staff_id
=> $logged_in_user->id,
122 cash_register
=> $registerid,
123 interface
=> 'intranet',
132 if ( $action eq 'discount' ) {
133 my $charge_id = scalar $input->param('accountlines_id');
134 my $charge = Koha
::Account
::Lines
->find($charge_id);
135 my $amount = scalar $input->param('amount');
139 my $discount = $charge->reduce(
141 reduction_type
=> 'DISCOUNT',
142 branch
=> $library_id,
143 staff_id
=> $logged_in_user->id,
144 interface
=> 'intranet',
153 my $total = $patron->account->balance;
155 my @accountlines = Koha
::Account
::Lines
->search(
156 { borrowernumber
=> $patron->borrowernumber },
157 { order_by
=> { -desc
=> 'accountlines_id' } }
165 # Populate an arrayref with everything we need to display any
166 # renew errors that occurred based on what we were passed
167 my $renew_results_display = [];
168 foreach my $renew_result(@renew_results) {
169 my ($itemnumber, $success, $info) = split(/,/, $renew_result);
170 my $item = Koha
::Items
->find($itemnumber);
172 $info = uri_unescape
($info);
174 push @
{$renew_results_display}, {
181 my $csrf_token = Koha
::Token
->new->generate_csrf({
182 session_id
=> scalar $input->cookie('CGISESSID'),
188 total
=> sprintf("%.2f",$total),
189 totalcredit
=> $totalcredit,
190 accounts
=> \
@accountlines,
191 payment_id
=> $payment_id,
192 change_given
=> $change_given,
193 renew_results
=> $renew_results_display,
194 csrf_token
=> $csrf_token,
197 output_html_with_http_headers
$input, $cookie, $template->output;