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 under the
10 # terms of the GNU General Public License as published by the Free Software
11 # Foundation; either version 2 of the License, or (at your option) any later
14 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License along
19 # with Koha; if not, write to the Free Software Foundation, Inc.,
20 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 written 11/1/2000 by chris@katipo.oc.nz
25 part of the koha library system, script to facilitate paying off fines
43 use C4
::Members
::Attributes
qw(GetBorrowerAttributes);
45 our $input = CGI
->new;
47 our ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
48 { template_name
=> 'members/pay.tmpl',
52 flagsrequired
=> { borrowers
=> 1, updatecharges
=> 1 },
57 my @names = $input->param;
59 our $borrowernumber = $input->param('borrowernumber');
60 if ( !$borrowernumber ) {
61 $borrowernumber = $input->param('borrowernumber0');
64 # get borrower details
65 our $borrower = GetMember
( borrowernumber
=> $borrowernumber );
66 our $user = $input->remote_user;
69 my $branches = GetBranches
();
70 our $branch = GetBranch
( $input, $branches );
72 my $writeoff_item = $input->param('confirm_writeoff');
73 my $paycollect = $input->param('paycollect');
75 print $input->redirect(
76 "/cgi-bin/koha/members/paycollect.pl?borrowernumber=$borrowernumber");
78 my $payselected = $input->param('payselected');
83 my $writeoff_all = $input->param('woall'); # writeoff all fines
86 } elsif ($writeoff_item) {
87 my $accountlines_id = $input->param('accountlines_id');
88 my $itemno = $input->param('itemnumber');
89 my $account_type = $input->param('accounttype');
90 my $amount = $input->param('amountoutstanding');
91 my $payment_note = $input->param("payment_note");
92 WriteOffFee
( $borrowernumber, $accountlines_id, $itemno, $account_type, $amount, $branch, $payment_note );
96 if (/^pay_indiv_(\d+)$/) {
98 redirect_to_paycollect
( 'pay_individual', $line_no );
99 } elsif (/^wo_indiv_(\d+)$/) {
101 redirect_to_paycollect
( 'writeoff_individual', $line_no );
106 activeBorrowerRelationship
=> (C4
::Context
->preference('borrowerRelationship') ne ''),
107 RoutingSerials
=> C4
::Context
->preference('RoutingSerials'),
110 add_accounts_to_template
();
112 output_html_with_http_headers
$input, $cookie, $template->output;
114 sub add_accounts_to_template
{
116 my ( $total, undef, undef ) = GetMemberAccountRecords
($borrowernumber);
118 my @notify = NumberNotifyId
($borrowernumber);
120 my $notify_groups = [];
121 for my $notify_id (@notify) {
122 my ( $acct_total, $accountlines, undef ) =
123 GetBorNotifyAcctRecord
( $borrowernumber, $notify_id );
124 if ( @
{$accountlines} ) {
125 my $totalnotify = AmountNotify
( $notify_id, $borrowernumber );
127 { accountlines
=> $accountlines,
128 notify
=> $notify_id,
129 total
=> $totalnotify,
133 borrower_add_additional_fields
($borrower);
135 accounts
=> $accounts,
136 borrower
=> $borrower,
143 sub get_for_redirect
{
144 my ( $name, $name_in, $money ) = @_;
145 my $s = q{&} . $name . q{=};
146 my $value = $input->param($name_in);
147 if ( !defined $value ) {
148 $value = ( $money == 1 ) ?
0 : q{};
151 $s .= sprintf '%.2f', $value;
158 sub redirect_to_paycollect
{
159 my ( $action, $line_no ) = @_;
161 "/cgi-bin/koha/members/paycollect.pl?borrowernumber=$borrowernumber";
163 $redirect .= "$action=1";
164 $redirect .= get_for_redirect
( 'accounttype', "accounttype$line_no", 0 );
165 $redirect .= get_for_redirect
( 'amount', "amount$line_no", 1 );
167 get_for_redirect
( 'amountoutstanding', "amountoutstanding$line_no", 1 );
168 $redirect .= get_for_redirect
( 'accountno', "accountno$line_no", 0 );
169 $redirect .= get_for_redirect
( 'title', "title$line_no", 0 );
170 $redirect .= get_for_redirect
( 'itemnumber', "itemnumber$line_no", 0 );
171 $redirect .= get_for_redirect
( 'notify_id', "notify_id$line_no", 0 );
172 $redirect .= get_for_redirect
( 'notify_level', "notify_level$line_no", 0 );
173 $redirect .= get_for_redirect
( 'accountlines_id', "accountlines_id$line_no", 0 );
174 $redirect .= q{&} . 'payment_note' . q{=} . uri_escape
( $input->param("payment_note_$line_no") );
175 $redirect .= '&remote_user=';
177 return print $input->redirect($redirect);
182 my @wo_lines = grep { /^accountno\d+$/ } @params;
186 my $accounttype = $input->param("accounttype$value");
188 # my $borrowernum = $input->param("borrowernumber$value");
189 my $itemno = $input->param("itemnumber$value");
190 my $amount = $input->param("amountoutstanding$value");
191 my $accountno = $input->param("accountno$value");
192 my $accountlines_id = $input->param("accountlines_id$value");
193 my $payment_note = $input->param("payment_note_$value");
194 WriteOffFee
( $borrowernumber, $accountlines_id, $itemno, $accounttype, $amount, $branch, $payment_note );
198 $borrowernumber = $input->param('borrowernumber');
199 print $input->redirect(
200 "/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber");
204 sub borrower_add_additional_fields
{
207 # some borrower info is not returned in the standard call despite being assumed
208 # in a number of templates. It should not be the business of this script but in lieu of
209 # a revised api here it is ...
210 if ( $b_ref->{category_type
} eq 'C' ) {
211 my ( $catcodes, $labels ) =
212 GetborCatFromCatType
( 'A', 'WHERE category_type = ?' );
213 if ( @
{$catcodes} ) {
214 if ( @
{$catcodes} > 1 ) {
215 $b_ref->{CATCODE_MULTI
} = 1;
216 } elsif ( @
{$catcodes} == 1 ) {
217 $b_ref->{catcode
} = $catcodes->[0];
220 } elsif ( $b_ref->{category_type
} eq 'A' ) {
221 $b_ref->{adultborrower
} = 1;
223 my ( $picture, $dberror ) = GetPatronImage
( $b_ref->{borrowernumber
} );
225 $b_ref->{has_picture
} = 1;
228 if (C4
::Context
->preference('ExtendedPatronAttributes')) {
229 $b_ref->{extendedattributes
} = GetBorrowerAttributes
($borrowernumber);
231 ExtendedPatronAttributes
=> 1,
235 $b_ref->{branchname
} = GetBranchName
( $b_ref->{branchcode
} );
244 if (/^incl_par_(\d+)$/) {
246 push @lines_to_pay, $input->param("accountno$index");
247 $amt += $input->param("amountoutstanding$index");
250 $amt = '&amt=' . $amt;
251 my $sel = '&selected=' . join ',', @lines_to_pay;
252 my $notes = '¬es=' . join("%0A", map { $input->param("payment_note_$_") } @lines_to_pay );
254 "/cgi-bin/koha/members/paycollect.pl?borrowernumber=$borrowernumber"
259 print $input->redirect($redirect);