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 $itemno = $input->param('itemnumber');
92 my $account_type = $input->param('accounttype');
93 my $amount = $input->param('amountoutstanding');
94 my $payment_note = $input->param("payment_note");
95 WriteOffFee
( $borrowernumber, $accountlines_id, $itemno, $account_type, $amount, $branch, $payment_note );
99 if (/^pay_indiv_(\d+)$/) {
101 redirect_to_paycollect
( 'pay_individual', $line_no );
102 } elsif (/^wo_indiv_(\d+)$/) {
104 redirect_to_paycollect
( 'writeoff_individual', $line_no );
110 activeBorrowerRelationship
=> (C4
::Context
->preference('borrowerRelationship') ne ''),
111 RoutingSerials
=> C4
::Context
->preference('RoutingSerials'),
114 add_accounts_to_template
();
116 output_html_with_http_headers
$input, $cookie, $template->output;
118 sub add_accounts_to_template
{
120 my ( $total, undef, undef ) = GetMemberAccountRecords
($borrowernumber);
122 my @notify = NumberNotifyId
($borrowernumber);
124 my $notify_groups = [];
125 for my $notify_id (@notify) {
126 my ( $acct_total, $accountlines, undef ) =
127 GetBorNotifyAcctRecord
( $borrowernumber, $notify_id );
128 if ( @
{$accountlines} ) {
129 my $totalnotify = AmountNotify
( $notify_id, $borrowernumber );
131 { accountlines
=> $accountlines,
132 notify
=> $notify_id,
133 total
=> $totalnotify,
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{=};
156 my $value = $input->param($name_in);
157 if ( !defined $value ) {
158 $value = ( $money == 1 ) ?
0 : q{};
161 $s .= sprintf '%.2f', $value;
168 sub redirect_to_paycollect
{
169 my ( $action, $line_no ) = @_;
171 "/cgi-bin/koha/members/paycollect.pl?borrowernumber=$borrowernumber";
173 $redirect .= "$action=1";
174 $redirect .= get_for_redirect
( 'accounttype', "accounttype$line_no", 0 );
175 $redirect .= get_for_redirect
( 'amount', "amount$line_no", 1 );
177 get_for_redirect
( 'amountoutstanding', "amountoutstanding$line_no", 1 );
178 $redirect .= uri_escape_utf8
( get_for_redirect
( 'description', "description$line_no", 0 ) );
179 $redirect .= uri_escape_utf8
( get_for_redirect
( 'title', "title$line_no", 0 ) );
180 $redirect .= get_for_redirect
( 'itemnumber', "itemnumber$line_no", 0 );
181 $redirect .= get_for_redirect
( 'notify_id', "notify_id$line_no", 0 );
182 $redirect .= get_for_redirect
( 'notify_level', "notify_level$line_no", 0 );
183 $redirect .= get_for_redirect
( 'accountlines_id', "accountlines_id$line_no", 0 );
184 $redirect .= q{&} . 'payment_note' . q{=} . uri_escape_utf8
( $input->param("payment_note_$line_no") );
185 $redirect .= '&remote_user=';
187 return print $input->redirect($redirect);
192 my @wo_lines = grep { /^accountlines_id\d+$/ } @params;
196 my $accounttype = $input->param("accounttype$value");
198 # my $borrowernum = $input->param("borrowernumber$value");
199 my $itemno = $input->param("itemnumber$value");
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 WriteOffFee
( $borrowernumber, $accountlines_id, $itemno, $accounttype, $amount, $branch, $payment_note );
207 $borrowernumber = $input->param('borrowernumber');
208 print $input->redirect(
209 "/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber");
213 sub borrower_add_additional_fields
{
216 # some borrower info is not returned in the standard call despite being assumed
217 # in a number of templates. It should not be the business of this script but in lieu of
218 # a revised api here it is ...
219 if ( $b_ref->{category_type
} eq 'C' ) {
220 my $patron_categories = Koha
::Patron
::Categories
->search_limited({ category_type
=> 'A' }, {order_by
=> ['categorycode']});
221 $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
222 $template->param( 'catcode' => $patron_categories->next ) if $patron_categories->count == 1;
223 } elsif ( $b_ref->{category_type
} eq 'A' ) {
224 $b_ref->{adultborrower
} = 1;
227 if (C4
::Context
->preference('ExtendedPatronAttributes')) {
228 $b_ref->{extendedattributes
} = GetBorrowerAttributes
($borrowernumber);
230 ExtendedPatronAttributes
=> 1,
242 if (/^incl_par_(\d+)$/) {
244 push @lines_to_pay, $input->param("accountlines_id$index");
245 $amt += $input->param("amountoutstanding$index");
248 $amt = '&amt=' . $amt;
249 my $sel = '&selected=' . join ',', @lines_to_pay;
250 my $notes = '¬es=' . join("%0A", map { $input->param("payment_note_$_") } @lines_to_pay );
252 "/cgi-bin/koha/members/paycollect.pl?borrowernumber=$borrowernumber"
257 print $input->redirect($redirect);