3 # Copyright 2000-2002 Katipo Communications
4 # Copyright 2010 BibLibre
5 # Copyright 2010,2011 PTFS-Europe Ltd
7 # This file is part of Koha.
9 # Koha is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
14 # Koha is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with Koha; if not, see <http://www.gnu.org/licenses>.
24 written 11/1/2000 by chris@katipo.oc.nz
25 part of the koha library system, script to facilitate paying off fines
42 use C4
::Members
::Attributes
qw(GetBorrowerAttributes);
44 use Koha
::Patron
::Images
;
46 use Koha
::Patron
::Categories
;
49 our $input = CGI
->new;
51 my $updatecharges_permissions = $input->param('woall') ?
'writeoff' : 'remaining_permissions';
52 our ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
53 { template_name
=> 'members/pay.tt',
57 flagsrequired
=> { borrowers
=> 1, updatecharges
=> $updatecharges_permissions },
62 my @names = $input->param;
64 our $borrowernumber = $input->param('borrowernumber');
65 if ( !$borrowernumber ) {
66 $borrowernumber = $input->param('borrowernumber0');
69 # get borrower details
70 my $patron = Koha
::Patrons
->find( $borrowernumber );
72 print $input->redirect("/cgi-bin/koha/circ/circulation.pl?borrowernumber=$borrowernumber");
75 my $category = $patron->category;
76 our $borrower = $patron->unblessed;
77 $borrower->{description
} = $category->description;
78 $borrower->{category_type
} = $category->category_type;
79 our $user = $input->remote_user;
82 our $branch = C4
::Context
->userenv->{'branch'};
84 my $writeoff_item = $input->param('confirm_writeoff');
85 my $paycollect = $input->param('paycollect');
87 print $input->redirect(
88 "/cgi-bin/koha/members/paycollect.pl?borrowernumber=$borrowernumber");
90 my $payselected = $input->param('payselected');
95 my $writeoff_all = $input->param('woall'); # writeoff all fines
98 } elsif ($writeoff_item) {
99 my $accountlines_id = $input->param('accountlines_id');
100 my $amount = $input->param('amountoutstanding');
101 my $payment_note = $input->param("payment_note");
103 Koha
::Account
->new( { patron_id
=> $borrowernumber } )->pay(
106 lines
=> [ scalar Koha
::Account
::Lines
->find($accountlines_id) ],
108 note
=> $payment_note,
109 library_id
=> $branch,
115 if (/^pay_indiv_(\d+)$/) {
117 redirect_to_paycollect
( 'pay_individual', $line_no );
118 } elsif (/^wo_indiv_(\d+)$/) {
120 redirect_to_paycollect
( 'writeoff_individual', $line_no );
126 RoutingSerials
=> C4
::Context
->preference('RoutingSerials'),
129 add_accounts_to_template
();
131 output_html_with_http_headers
$input, $cookie, $template->output;
133 sub add_accounts_to_template
{
135 my ( $total, undef, undef ) = GetMemberAccountRecords
($borrowernumber);
137 borrower_add_additional_fields
($borrower);
139 $template->param(%$borrower);
141 my $patron_image = Koha
::Patron
::Images
->find($borrower->{borrowernumber
});
142 $template->param( picture
=> 1 ) if $patron_image;
144 accounts
=> $accounts,
145 borrower
=> $borrower,
146 categoryname
=> $borrower->{'description'},
153 sub get_for_redirect
{
154 my ( $name, $name_in, $money ) = @_;
155 my $s = q{&} . $name . q{=};
157 if (defined $input->param($name_in)) {
158 $value = uri_escape_utf8
( scalar $input->param($name_in) );
160 if ( !defined $value ) {
161 $value = ( $money == 1 ) ?
0 : q{};
164 $s .= sprintf '%.2f', $value;
171 sub redirect_to_paycollect
{
172 my ( $action, $line_no ) = @_;
174 "/cgi-bin/koha/members/paycollect.pl?borrowernumber=$borrowernumber";
176 $redirect .= "$action=1";
177 $redirect .= get_for_redirect
( 'accounttype', "accounttype$line_no", 0 );
178 $redirect .= get_for_redirect
( 'amount', "amount$line_no", 1 );
180 get_for_redirect
( 'amountoutstanding', "amountoutstanding$line_no", 1 );
181 $redirect .= get_for_redirect
( 'description', "description$line_no", 0 );
182 $redirect .= get_for_redirect
( 'title', "title$line_no", 0 );
183 $redirect .= get_for_redirect
( 'itemnumber', "itemnumber$line_no", 0 );
184 $redirect .= get_for_redirect
( 'accountlines_id', "accountlines_id$line_no", 0 );
185 $redirect .= q{&} . 'payment_note' . q{=} . uri_escape_utf8
( scalar $input->param("payment_note_$line_no") );
186 $redirect .= '&remote_user=';
188 return print $input->redirect($redirect);
193 my @wo_lines = grep { /^accountlines_id\d+$/ } @params;
195 my $borrowernumber = $input->param('borrowernumber');
200 my $amount = $input->param("amountoutstanding$value");
201 my $accountlines_id = $input->param("accountlines_id$value");
202 my $payment_note = $input->param("payment_note_$value");
203 Koha
::Account
->new( { patron_id
=> $borrowernumber } )->pay(
206 lines
=> [ scalar Koha
::Account
::Lines
->find($accountlines_id) ],
208 note
=> $payment_note,
209 library_id
=> $branch,
215 print $input->redirect("/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber");
219 sub borrower_add_additional_fields
{
222 # some borrower info is not returned in the standard call despite being assumed
223 # in a number of templates. It should not be the business of this script but in lieu of
224 # a revised api here it is ...
225 if ( $b_ref->{category_type
} eq 'C' ) {
226 my $patron_categories = Koha
::Patron
::Categories
->search_limited({ category_type
=> 'A' }, {order_by
=> ['categorycode']});
227 $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
228 $template->param( 'catcode' => $patron_categories->next ) if $patron_categories->count == 1;
229 } elsif ( $b_ref->{category_type
} eq 'A' || $b_ref->{category_type
} eq 'I' ) {
230 $b_ref->{adultborrower
} = 1;
233 if (C4
::Context
->preference('ExtendedPatronAttributes')) {
234 $b_ref->{extendedattributes
} = GetBorrowerAttributes
($borrowernumber);
236 ExtendedPatronAttributes
=> 1,
248 if (/^incl_par_(\d+)$/) {
250 push @lines_to_pay, scalar $input->param("accountlines_id$index");
251 $amt += $input->param("amountoutstanding$index");
254 $amt = '&amt=' . $amt;
255 my $sel = '&selected=' . join ',', @lines_to_pay;
256 my $notes = '¬es=' . join("%0A", map { scalar $input->param("payment_note_$_") } @lines_to_pay );
258 "/cgi-bin/koha/members/paycollect.pl?borrowernumber=$borrowernumber"
263 print $input->redirect($redirect);