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 my $updatecharges_permissions = $input->param('woall') ?
'writeoff' : 'remaining_permissions';
48 our ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
49 { template_name
=> 'members/pay.tt',
53 flagsrequired
=> { borrowers
=> 1, updatecharges
=> $updatecharges_permissions },
58 my @names = $input->param;
60 our $borrowernumber = $input->param('borrowernumber');
61 if ( !$borrowernumber ) {
62 $borrowernumber = $input->param('borrowernumber0');
65 # get borrower details
66 our $borrower = GetMember
( borrowernumber
=> $borrowernumber );
67 our $user = $input->remote_user;
70 my $branches = GetBranches
();
71 our $branch = GetBranch
( $input, $branches );
73 my $writeoff_item = $input->param('confirm_writeoff');
74 my $paycollect = $input->param('paycollect');
76 print $input->redirect(
77 "/cgi-bin/koha/members/paycollect.pl?borrowernumber=$borrowernumber");
79 my $payselected = $input->param('payselected');
84 my $writeoff_all = $input->param('woall'); # writeoff all fines
87 } elsif ($writeoff_item) {
88 my $accountlines_id = $input->param('accountlines_id');
89 my $itemno = $input->param('itemnumber');
90 my $account_type = $input->param('accounttype');
91 my $amount = $input->param('amountoutstanding');
92 my $payment_note = $input->param("payment_note");
93 WriteOffFee
( $borrowernumber, $accountlines_id, $itemno, $account_type, $amount, $branch, $payment_note );
97 if (/^pay_indiv_(\d+)$/) {
99 redirect_to_paycollect
( 'pay_individual', $line_no );
100 } elsif (/^wo_indiv_(\d+)$/) {
102 redirect_to_paycollect
( 'writeoff_individual', $line_no );
108 activeBorrowerRelationship
=> (C4
::Context
->preference('borrowerRelationship') ne ''),
109 RoutingSerials
=> C4
::Context
->preference('RoutingSerials'),
112 add_accounts_to_template
();
114 output_html_with_http_headers
$input, $cookie, $template->output;
116 sub add_accounts_to_template
{
118 my ( $total, undef, undef ) = GetMemberAccountRecords
($borrowernumber);
120 my @notify = NumberNotifyId
($borrowernumber);
122 my $notify_groups = [];
123 for my $notify_id (@notify) {
124 my ( $acct_total, $accountlines, undef ) =
125 GetBorNotifyAcctRecord
( $borrowernumber, $notify_id );
126 if ( @
{$accountlines} ) {
127 my $totalnotify = AmountNotify
( $notify_id, $borrowernumber );
129 { accountlines
=> $accountlines,
130 notify
=> $notify_id,
131 total
=> $totalnotify,
135 borrower_add_additional_fields
($borrower);
137 accounts
=> $accounts,
138 borrower
=> $borrower,
145 sub get_for_redirect
{
146 my ( $name, $name_in, $money ) = @_;
147 my $s = q{&} . $name . q{=};
148 my $value = $input->param($name_in);
149 if ( !defined $value ) {
150 $value = ( $money == 1 ) ?
0 : q{};
153 $s .= sprintf '%.2f', $value;
160 sub redirect_to_paycollect
{
161 my ( $action, $line_no ) = @_;
163 "/cgi-bin/koha/members/paycollect.pl?borrowernumber=$borrowernumber";
165 $redirect .= "$action=1";
166 $redirect .= get_for_redirect
( 'accounttype', "accounttype$line_no", 0 );
167 $redirect .= get_for_redirect
( 'amount', "amount$line_no", 1 );
169 get_for_redirect
( 'amountoutstanding', "amountoutstanding$line_no", 1 );
170 $redirect .= get_for_redirect
( 'accountno', "accountno$line_no", 0 );
171 $redirect .= get_for_redirect
( 'title', "title$line_no", 0 );
172 $redirect .= get_for_redirect
( 'itemnumber', "itemnumber$line_no", 0 );
173 $redirect .= get_for_redirect
( 'notify_id', "notify_id$line_no", 0 );
174 $redirect .= get_for_redirect
( 'notify_level', "notify_level$line_no", 0 );
175 $redirect .= get_for_redirect
( 'accountlines_id', "accountlines_id$line_no", 0 );
176 $redirect .= q{&} . 'payment_note' . q{=} . uri_escape
( $input->param("payment_note_$line_no") );
177 $redirect .= '&remote_user=';
179 return print $input->redirect($redirect);
184 my @wo_lines = grep { /^accountno\d+$/ } @params;
188 my $accounttype = $input->param("accounttype$value");
190 # my $borrowernum = $input->param("borrowernumber$value");
191 my $itemno = $input->param("itemnumber$value");
192 my $amount = $input->param("amountoutstanding$value");
193 my $accountno = $input->param("accountno$value");
194 my $accountlines_id = $input->param("accountlines_id$value");
195 my $payment_note = $input->param("payment_note_$value");
196 WriteOffFee
( $borrowernumber, $accountlines_id, $itemno, $accounttype, $amount, $branch, $payment_note );
200 $borrowernumber = $input->param('borrowernumber');
201 print $input->redirect(
202 "/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber");
206 sub borrower_add_additional_fields
{
209 # some borrower info is not returned in the standard call despite being assumed
210 # in a number of templates. It should not be the business of this script but in lieu of
211 # a revised api here it is ...
212 if ( $b_ref->{category_type
} eq 'C' ) {
213 my ( $catcodes, $labels ) =
214 GetborCatFromCatType
( 'A', 'WHERE category_type = ?' );
215 if ( @
{$catcodes} ) {
216 if ( @
{$catcodes} > 1 ) {
217 $b_ref->{CATCODE_MULTI
} = 1;
218 } elsif ( @
{$catcodes} == 1 ) {
219 $b_ref->{catcode
} = $catcodes->[0];
222 } elsif ( $b_ref->{category_type
} eq 'A' ) {
223 $b_ref->{adultborrower
} = 1;
225 my ( $picture, $dberror ) = GetPatronImage
( $b_ref->{borrowernumber
} );
227 $b_ref->{has_picture
} = 1;
230 # Computes full borrower address
231 my $roadtype = C4
::Koha
::GetAuthorisedValueByCode
( 'ROADTYPE', $borrower->{streettype
} );
232 $b_ref->{address
} = $borrower->{'streetnumber'} . " $roadtype " . $borrower->{'address'};
234 if (C4
::Context
->preference('ExtendedPatronAttributes')) {
235 $b_ref->{extendedattributes
} = GetBorrowerAttributes
($borrowernumber);
237 ExtendedPatronAttributes
=> 1,
241 $b_ref->{branchname
} = GetBranchName
( $b_ref->{branchcode
} );
250 if (/^incl_par_(\d+)$/) {
252 push @lines_to_pay, $input->param("accountno$index");
253 $amt += $input->param("amountoutstanding$index");
256 $amt = '&amt=' . $amt;
257 my $sel = '&selected=' . join ',', @lines_to_pay;
258 my $notes = '¬es=' . join("%0A", map { $input->param("payment_note_$_") } @lines_to_pay );
260 "/cgi-bin/koha/members/paycollect.pl?borrowernumber=$borrowernumber"
265 print $input->redirect($redirect);