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);
43 use Koha
::Patron
::Images
;
45 use Koha
::Patron
::Categories
;
48 our $input = CGI
->new;
50 my $updatecharges_permissions = $input->param('woall') ?
'writeoff' : 'remaining_permissions';
51 our ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
52 { template_name
=> 'members/pay.tt',
56 flagsrequired
=> { borrowers
=> 1, updatecharges
=> $updatecharges_permissions },
61 my @names = $input->param;
63 our $borrowernumber = $input->param('borrowernumber');
64 if ( !$borrowernumber ) {
65 $borrowernumber = $input->param('borrowernumber0');
68 # get borrower details
69 our $borrower = GetMember
( borrowernumber
=> $borrowernumber );
70 our $user = $input->remote_user;
73 our $branch = C4
::Context
->userenv->{'branch'};
75 my $writeoff_item = $input->param('confirm_writeoff');
76 my $paycollect = $input->param('paycollect');
78 print $input->redirect(
79 "/cgi-bin/koha/members/paycollect.pl?borrowernumber=$borrowernumber");
81 my $payselected = $input->param('payselected');
86 my $writeoff_all = $input->param('woall'); # writeoff all fines
89 } elsif ($writeoff_item) {
90 my $accountlines_id = $input->param('accountlines_id');
91 my $amount = $input->param('amountoutstanding');
92 my $payment_note = $input->param("payment_note");
94 Koha
::Account
->new( { patron_id
=> $borrowernumber } )->pay(
97 lines
=> [Koha
::Account
::Lines
->find($accountlines_id)],
99 note
=> $payment_note,
100 library_id
=> $branch,
106 if (/^pay_indiv_(\d+)$/) {
108 redirect_to_paycollect
( 'pay_individual', $line_no );
109 } elsif (/^wo_indiv_(\d+)$/) {
111 redirect_to_paycollect
( 'writeoff_individual', $line_no );
117 RoutingSerials
=> C4
::Context
->preference('RoutingSerials'),
120 add_accounts_to_template
();
122 output_html_with_http_headers
$input, $cookie, $template->output;
124 sub add_accounts_to_template
{
126 my ( $total, undef, undef ) = GetMemberAccountRecords
($borrowernumber);
128 my @notify = NumberNotifyId
($borrowernumber);
130 my $notify_groups = [];
131 for my $notify_id (@notify) {
132 my ( $acct_total, $accountlines, undef ) =
133 GetBorNotifyAcctRecord
( $borrowernumber, $notify_id );
134 if ( @
{$accountlines} ) {
135 my $totalnotify = AmountNotify
( $notify_id, $borrowernumber );
137 { accountlines
=> $accountlines,
138 notify
=> $notify_id,
139 total
=> $totalnotify,
143 borrower_add_additional_fields
($borrower);
145 $template->param(%$borrower);
147 my $patron_image = Koha
::Patron
::Images
->find($borrower->{borrowernumber
});
148 $template->param( picture
=> 1 ) if $patron_image;
150 accounts
=> $accounts,
151 borrower
=> $borrower,
152 categoryname
=> $borrower->{'description'},
159 sub get_for_redirect
{
160 my ( $name, $name_in, $money ) = @_;
161 my $s = q{&} . $name . q{=};
162 my $value = uri_escape_utf8
( $input->param($name_in) );
163 if ( !defined $value ) {
164 $value = ( $money == 1 ) ?
0 : q{};
167 $s .= sprintf '%.2f', $value;
174 sub redirect_to_paycollect
{
175 my ( $action, $line_no ) = @_;
177 "/cgi-bin/koha/members/paycollect.pl?borrowernumber=$borrowernumber";
179 $redirect .= "$action=1";
180 $redirect .= get_for_redirect
( 'accounttype', "accounttype$line_no", 0 );
181 $redirect .= get_for_redirect
( 'amount', "amount$line_no", 1 );
183 get_for_redirect
( 'amountoutstanding', "amountoutstanding$line_no", 1 );
184 $redirect .= get_for_redirect
( 'description', "description$line_no", 0 );
185 $redirect .= get_for_redirect
( 'title', "title$line_no", 0 );
186 $redirect .= get_for_redirect
( 'itemnumber', "itemnumber$line_no", 0 );
187 $redirect .= get_for_redirect
( 'notify_id', "notify_id$line_no", 0 );
188 $redirect .= get_for_redirect
( 'notify_level', "notify_level$line_no", 0 );
189 $redirect .= get_for_redirect
( 'accountlines_id', "accountlines_id$line_no", 0 );
190 $redirect .= q{&} . 'payment_note' . q{=} . uri_escape_utf8
( $input->param("payment_note_$line_no") );
191 $redirect .= '&remote_user=';
193 return print $input->redirect($redirect);
198 my @wo_lines = grep { /^accountlines_id\d+$/ } @params;
200 my $borrowernumber = $input->param('borrowernumber');
205 my $amount = $input->param("amountoutstanding$value");
206 my $accountlines_id = $input->param("accountlines_id$value");
207 my $payment_note = $input->param("payment_note_$value");
208 Koha
::Account
->new( { patron_id
=> $borrowernumber } )->pay(
211 lines
=> [ Koha
::Account
::Lines
->find($accountlines_id) ],
213 note
=> $payment_note,
214 library_id
=> $branch,
220 print $input->redirect("/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber");
224 sub borrower_add_additional_fields
{
227 # some borrower info is not returned in the standard call despite being assumed
228 # in a number of templates. It should not be the business of this script but in lieu of
229 # a revised api here it is ...
230 if ( $b_ref->{category_type
} eq 'C' ) {
231 my $patron_categories = Koha
::Patron
::Categories
->search_limited({ category_type
=> 'A' }, {order_by
=> ['categorycode']});
232 $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
233 $template->param( 'catcode' => $patron_categories->next ) if $patron_categories->count == 1;
234 } elsif ( $b_ref->{category_type
} eq 'A' || $b_ref->{category_type
} eq 'I' ) {
235 $b_ref->{adultborrower
} = 1;
238 if (C4
::Context
->preference('ExtendedPatronAttributes')) {
239 $b_ref->{extendedattributes
} = GetBorrowerAttributes
($borrowernumber);
241 ExtendedPatronAttributes
=> 1,
253 if (/^incl_par_(\d+)$/) {
255 push @lines_to_pay, $input->param("accountlines_id$index");
256 $amt += $input->param("amountoutstanding$index");
259 $amt = '&amt=' . $amt;
260 my $sel = '&selected=' . join ',', @lines_to_pay;
261 my $notes = '¬es=' . join("%0A", map { $input->param("payment_note_$_") } @lines_to_pay );
263 "/cgi-bin/koha/members/paycollect.pl?borrowernumber=$borrowernumber"
268 print $input->redirect($redirect);