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
42 use C4
::Members
::Attributes
qw(GetBorrowerAttributes);
44 our $input = CGI
->new;
46 our ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
47 { template_name
=> 'members/pay.tmpl',
51 flagsrequired
=> { borrowers
=> 1, updatecharges
=> 1 },
56 my @names = $input->param;
58 our $borrowernumber = $input->param('borrowernumber');
59 if ( !$borrowernumber ) {
60 $borrowernumber = $input->param('borrowernumber0');
63 # get borrower details
64 our $borrower = GetMember
( borrowernumber
=> $borrowernumber );
65 our $user = $input->remote_user;
68 my $branches = GetBranches
();
69 our $branch = GetBranch
( $input, $branches );
71 my $writeoff_item = $input->param('confirm_writeoff');
72 my $paycollect = $input->param('paycollect');
74 print $input->redirect(
75 "/cgi-bin/koha/members/paycollect.pl?borrowernumber=$borrowernumber");
77 my $payselected = $input->param('payselected');
82 my $writeoff_all = $input->param('woall'); # writeoff all fines
85 } elsif ($writeoff_item) {
86 my $accountlines_id = $input->param('accountlines_id');
87 my $itemno = $input->param('itemnumber');
88 my $account_type = $input->param('accounttype');
89 my $amount = $input->param('amountoutstanding');
90 WriteOffFee
( $borrowernumber, $accountlines_id, $itemno, $account_type, $amount );
94 if (/^pay_indiv_(\d+)$/) {
96 redirect_to_paycollect
( 'pay_individual', $line_no );
97 } elsif (/^wo_indiv_(\d+)$/) {
99 redirect_to_paycollect
( 'writeoff_individual', $line_no );
104 activeBorrowerRelationship
=> (C4
::Context
->preference('borrowerRelationship') ne ''),
105 RoutingSerials
=> C4
::Context
->preference('RoutingSerials'),
108 add_accounts_to_template
();
110 output_html_with_http_headers
$input, $cookie, $template->output;
112 sub add_accounts_to_template
{
114 my ( $total, undef, undef ) = GetMemberAccountRecords
($borrowernumber);
116 my @notify = NumberNotifyId
($borrowernumber);
118 my $notify_groups = [];
119 for my $notify_id (@notify) {
120 my ( $acct_total, $accountlines, undef ) =
121 GetBorNotifyAcctRecord
( $borrowernumber, $notify_id );
122 if ( @
{$accountlines} ) {
123 my $totalnotify = AmountNotify
( $notify_id, $borrowernumber );
125 { accountlines
=> $accountlines,
126 notify
=> $notify_id,
127 total
=> $totalnotify,
131 borrower_add_additional_fields
($borrower);
133 accounts
=> $accounts,
134 borrower
=> $borrower,
141 sub get_for_redirect
{
142 my ( $name, $name_in, $money ) = @_;
143 my $s = q{&} . $name . q{=};
144 my $value = $input->param($name_in);
145 if ( !defined $value ) {
146 $value = ( $money == 1 ) ?
0 : q{};
149 $s .= sprintf '%.2f', $value;
156 sub redirect_to_paycollect
{
157 my ( $action, $line_no ) = @_;
159 "/cgi-bin/koha/members/paycollect.pl?borrowernumber=$borrowernumber";
161 $redirect .= "$action=1";
162 $redirect .= get_for_redirect
( 'accounttype', "accounttype$line_no", 0 );
163 $redirect .= get_for_redirect
( 'amount', "amount$line_no", 1 );
165 get_for_redirect
( 'amountoutstanding', "amountoutstanding$line_no", 1 );
166 $redirect .= get_for_redirect
( 'accountno', "accountno$line_no", 0 );
167 $redirect .= get_for_redirect
( 'description', "description$line_no", 0 );
168 $redirect .= get_for_redirect
( 'title', "title$line_no", 0 );
169 $redirect .= get_for_redirect
( 'itemnumber', "itemnumber$line_no", 0 );
170 $redirect .= get_for_redirect
( 'notify_id', "notify_id$line_no", 0 );
171 $redirect .= get_for_redirect
( 'notify_level', "notify_level$line_no", 0 );
172 $redirect .= get_for_redirect
( 'accountlines_id', "accountlines_id$line_no", 0 );
173 $redirect .= '&remote_user=';
175 return print $input->redirect($redirect);
180 my @wo_lines = grep { /^accountno\d+$/ } @params;
184 my $accounttype = $input->param("accounttype$value");
186 # my $borrowernum = $input->param("borrowernumber$value");
187 my $itemno = $input->param("itemnumber$value");
188 my $amount = $input->param("amountoutstanding$value");
189 my $accountno = $input->param("accountno$value");
190 my $accountlines_id = $input->param("accountlines_id$value");
191 WriteOffFee
( $borrowernumber, $accountlines_id, $itemno, $accounttype, $amount );
195 $borrowernumber = $input->param('borrowernumber');
196 print $input->redirect(
197 "/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber");
201 sub borrower_add_additional_fields
{
204 # some borrower info is not returned in the standard call despite being assumed
205 # in a number of templates. It should not be the business of this script but in lieu of
206 # a revised api here it is ...
207 if ( $b_ref->{category_type
} eq 'C' ) {
208 my ( $catcodes, $labels ) =
209 GetborCatFromCatType
( 'A', 'WHERE category_type = ?' );
210 if ( @
{$catcodes} ) {
211 if ( @
{$catcodes} > 1 ) {
212 $b_ref->{CATCODE_MULTI
} = 1;
213 } elsif ( @
{$catcodes} == 1 ) {
214 $b_ref->{catcode
} = $catcodes->[0];
217 } elsif ( $b_ref->{category_type
} eq 'A' ) {
218 $b_ref->{adultborrower
} = 1;
220 my ( $picture, $dberror ) = GetPatronImage
( $b_ref->{cardnumber
} );
222 $b_ref->{has_picture
} = 1;
225 if (C4
::Context
->preference('ExtendedPatronAttributes')) {
226 $b_ref->{extendedattributes
} = GetBorrowerAttributes
($borrowernumber);
228 ExtendedPatronAttributes
=> 1,
232 $b_ref->{branchname
} = GetBranchName
( $b_ref->{branchcode
} );
241 if (/^incl_par_(\d+)$/) {
243 push @lines_to_pay, $input->param("accountno$index");
244 $amt += $input->param("amountoutstanding$index");
247 $amt = '&amt=' . $amt;
248 my $sel = '&selected=' . join ',', @lines_to_pay;
250 "/cgi-bin/koha/members/paycollect.pl?borrowernumber=$borrowernumber"
254 print $input->redirect($redirect);