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;
47 our $input = CGI->new;
49 my $updatecharges_permissions = $input->param('woall') ? 'writeoff' : 'remaining_permissions';
50 our ( $template, $loggedinuser, $cookie ) = get_template_and_user(
51 { template_name => 'members/pay.tt',
55 flagsrequired => { borrowers => 1, updatecharges => $updatecharges_permissions },
60 my @names = $input->param;
62 our $borrowernumber = $input->param('borrowernumber');
63 if ( !$borrowernumber ) {
64 $borrowernumber = $input->param('borrowernumber0');
67 # get borrower details
68 our $borrower = GetMember( borrowernumber => $borrowernumber );
69 our $user = $input->remote_user;
72 our $branch = C4::Context->userenv->{'branch'};
74 my $writeoff_item = $input->param('confirm_writeoff');
75 my $paycollect = $input->param('paycollect');
77 print $input->redirect(
78 "/cgi-bin/koha/members/paycollect.pl?borrowernumber=$borrowernumber");
80 my $payselected = $input->param('payselected');
85 my $writeoff_all = $input->param('woall'); # writeoff all fines
88 } elsif ($writeoff_item) {
89 my $accountlines_id = $input->param('accountlines_id');
90 my $itemno = $input->param('itemnumber');
91 my $account_type = $input->param('accounttype');
92 my $amount = $input->param('amountoutstanding');
93 my $payment_note = $input->param("payment_note");
94 WriteOffFee( $borrowernumber, $accountlines_id, $itemno, $account_type, $amount, $branch, $payment_note );
98 if (/^pay_indiv_(\d+)$/) {
100 redirect_to_paycollect( 'pay_individual', $line_no );
101 } elsif (/^wo_indiv_(\d+)$/) {
103 redirect_to_paycollect( 'writeoff_individual', $line_no );
109 activeBorrowerRelationship => (C4::Context->preference('borrowerRelationship') ne ''),
110 RoutingSerials => C4::Context->preference('RoutingSerials'),
113 add_accounts_to_template();
115 output_html_with_http_headers $input, $cookie, $template->output;
117 sub add_accounts_to_template {
119 my ( $total, undef, undef ) = GetMemberAccountRecords($borrowernumber);
121 my @notify = NumberNotifyId($borrowernumber);
123 my $notify_groups = [];
124 for my $notify_id (@notify) {
125 my ( $acct_total, $accountlines, undef ) =
126 GetBorNotifyAcctRecord( $borrowernumber, $notify_id );
127 if ( @{$accountlines} ) {
128 my $totalnotify = AmountNotify( $notify_id, $borrowernumber );
130 { accountlines => $accountlines,
131 notify => $notify_id,
132 total => $totalnotify,
136 borrower_add_additional_fields($borrower);
138 $template->param(%$borrower);
140 my $patron_image = Koha::Patron::Images->find($borrower->{borrowernumber});
141 $template->param( picture => 1 ) if $patron_image;
143 accounts => $accounts,
144 borrower => $borrower,
145 categoryname => $borrower->{'description'},
152 sub get_for_redirect {
153 my ( $name, $name_in, $money ) = @_;
154 my $s = q{&} . $name . q{=};
155 my $value = $input->param($name_in);
156 if ( !defined $value ) {
157 $value = ( $money == 1 ) ? 0 : q{};
160 $s .= sprintf '%.2f', $value;
167 sub redirect_to_paycollect {
168 my ( $action, $line_no ) = @_;
170 "/cgi-bin/koha/members/paycollect.pl?borrowernumber=$borrowernumber";
172 $redirect .= "$action=1";
173 $redirect .= get_for_redirect( 'accounttype', "accounttype$line_no", 0 );
174 $redirect .= get_for_redirect( 'amount', "amount$line_no", 1 );
176 get_for_redirect( 'amountoutstanding', "amountoutstanding$line_no", 1 );
177 $redirect .= get_for_redirect( 'description', "description$line_no", 0 );
178 $redirect .= get_for_redirect( 'title', "title$line_no", 0 );
179 $redirect .= get_for_redirect( 'itemnumber', "itemnumber$line_no", 0 );
180 $redirect .= get_for_redirect( 'notify_id', "notify_id$line_no", 0 );
181 $redirect .= get_for_redirect( 'notify_level', "notify_level$line_no", 0 );
182 $redirect .= get_for_redirect( 'accountlines_id', "accountlines_id$line_no", 0 );
183 $redirect .= q{&} . 'payment_note' . q{=} . uri_escape_utf8( $input->param("payment_note_$line_no") );
184 $redirect .= '&remote_user=';
186 return print $input->redirect($redirect);
191 my @wo_lines = grep { /^accountlines_id\d+$/ } @params;
195 my $accounttype = $input->param("accounttype$value");
197 # my $borrowernum = $input->param("borrowernumber$value");
198 my $itemno = $input->param("itemnumber$value");
199 my $amount = $input->param("amountoutstanding$value");
200 my $accountlines_id = $input->param("accountlines_id$value");
201 my $payment_note = $input->param("payment_note_$value");
202 WriteOffFee( $borrowernumber, $accountlines_id, $itemno, $accounttype, $amount, $branch, $payment_note );
206 $borrowernumber = $input->param('borrowernumber');
207 print $input->redirect(
208 "/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber");
212 sub borrower_add_additional_fields {
215 # some borrower info is not returned in the standard call despite being assumed
216 # in a number of templates. It should not be the business of this script but in lieu of
217 # a revised api here it is ...
218 if ( $b_ref->{category_type} eq 'C' ) {
219 my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
220 $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
221 $template->param( 'catcode' => $patron_categories->next ) if $patron_categories->count == 1;
222 } elsif ( $b_ref->{category_type} eq 'A' ) {
223 $b_ref->{adultborrower} = 1;
226 if (C4::Context->preference('ExtendedPatronAttributes')) {
227 $b_ref->{extendedattributes} = GetBorrowerAttributes($borrowernumber);
229 ExtendedPatronAttributes => 1,
241 if (/^incl_par_(\d+)$/) {
243 push @lines_to_pay, $input->param("accountlines_id$index");
244 $amt += $input->param("amountoutstanding$index");
247 $amt = '&amt=' . $amt;
248 my $sel = '&selected=' . join ',', @lines_to_pay;
249 my $notes = '¬es=' . join("%0A", map { $input->param("payment_note_$_") } @lines_to_pay );
251 "/cgi-bin/koha/members/paycollect.pl?borrowernumber=$borrowernumber"
256 print $input->redirect($redirect);