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 $add_writeoff_sth;
48 our ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
49 { template_name
=> 'members/pay.tmpl',
53 flagsrequired
=> { borrowers
=> 1, updatecharges
=> 1 },
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 WriteOffFee
( $borrowernumber, $accountlines_id, $itemno, $account_type, $amount, $branch );
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 );
105 $template->param( activeBorrowerRelationship
=> (C4
::Context
->preference('borrowerRelationship') ne '') );
107 add_accounts_to_template
();
109 output_html_with_http_headers
$input, $cookie, $template->output;
112 my ( $accountlines_id, $itemnum, $accounttype, $amount ) = @_;
114 $manager_id = C4
::Context
->userenv->{'number'} if C4
::Context
->userenv;
116 # if no item is attached to fine, make sure to store it as a NULL
119 $writeoff_sth->execute( $accountlines_id );
121 my $acct = getnextacctno
($borrowernumber);
122 $add_writeoff_sth->execute( $borrowernumber, $acct, $itemnum, $amount, $manager_id );
124 UpdateStats
( $branch, 'writeoff', $amount, q{}, q{}, q{}, $borrowernumber );
129 sub add_accounts_to_template
{
131 my ( $total, undef, undef ) = GetMemberAccountRecords
($borrowernumber);
133 my @notify = NumberNotifyId
($borrowernumber);
135 my $notify_groups = [];
136 for my $notify_id (@notify) {
137 my ( $acct_total, $accountlines, undef ) =
138 GetBorNotifyAcctRecord
( $borrowernumber, $notify_id );
139 if ( @
{$accountlines} ) {
140 my $totalnotify = AmountNotify
( $notify_id, $borrowernumber );
142 { accountlines
=> $accountlines,
143 notify
=> $notify_id,
144 total
=> $totalnotify,
148 borrower_add_additional_fields
($borrower);
150 accounts
=> $accounts,
151 borrower
=> $borrower,
158 sub get_for_redirect
{
159 my ( $name, $name_in, $money ) = @_;
160 my $s = q{&} . $name . q{=};
161 my $value = $input->param($name_in);
162 if ( !defined $value ) {
163 $value = ( $money == 1 ) ?
0 : q{};
166 $s .= sprintf '%.2f', $value;
173 sub redirect_to_paycollect
{
174 my ( $action, $line_no ) = @_;
176 "/cgi-bin/koha/members/paycollect.pl?borrowernumber=$borrowernumber";
178 $redirect .= "$action=1";
179 $redirect .= get_for_redirect
( 'accounttype', "accounttype$line_no", 0 );
180 $redirect .= get_for_redirect
( 'amount', "amount$line_no", 1 );
182 get_for_redirect
( 'amountoutstanding', "amountoutstanding$line_no", 1 );
183 $redirect .= get_for_redirect
( 'accountno', "accountno$line_no", 0 );
184 $redirect .= get_for_redirect
( 'description', "description$line_no", 0 );
185 $redirect .= get_for_redirect
( 'title', "title$line_no", 0 );
186 $redirect .= get_for_redirect
( 'itemnumber', "itemnumber$line_no", 0 );
187 $redirect .= get_for_redirect
( 'notify_id', "notify_id$line_no", 0 );
188 $redirect .= get_for_redirect
( 'notify_level', "notify_level$line_no", 0 );
189 $redirect .= get_for_redirect
( 'accountlines_id', "accountlines_id$line_no", 0 );
190 $redirect .= '&remote_user=';
192 return print $input->redirect($redirect);
197 my @wo_lines = grep { /^accountno\d+$/ } @params;
201 my $accounttype = $input->param("accounttype$value");
203 # my $borrowernum = $input->param("borrowernumber$value");
204 my $itemno = $input->param("itemnumber$value");
205 my $amount = $input->param("amountoutstanding$value");
206 my $accountno = $input->param("accountno$value");
207 my $accountlines_id = $input->param("accountlines_id$value");
208 WriteOffFee
( $borrowernumber, $accountlines_id, $itemno, $accounttype, $amount, $branch );
212 $borrowernumber = $input->param('borrowernumber');
213 print $input->redirect(
214 "/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber");
218 sub borrower_add_additional_fields
{
221 # some borrower info is not returned in the standard call despite being assumed
222 # in a number of templates. It should not be the business of this script but in lieu of
223 # a revised api here it is ...
224 if ( $b_ref->{category_type
} eq 'C' ) {
225 my ( $catcodes, $labels ) =
226 GetborCatFromCatType
( 'A', 'WHERE category_type = ?' );
227 if ( @
{$catcodes} ) {
228 if ( @
{$catcodes} > 1 ) {
229 $b_ref->{CATCODE_MULTI
} = 1;
230 } elsif ( @
{$catcodes} == 1 ) {
231 $b_ref->{catcode
} = $catcodes->[0];
234 } elsif ( $b_ref->{category_type
} eq 'A' ) {
235 $b_ref->{adultborrower
} = 1;
237 my ( $picture, $dberror ) = GetPatronImage
( $b_ref->{cardnumber
} );
239 $b_ref->{has_picture
} = 1;
242 if (C4
::Context
->preference('ExtendedPatronAttributes')) {
243 $b_ref->{extendedattributes
} = GetBorrowerAttributes
($borrowernumber);
245 ExtendedPatronAttributes
=> 1,
249 $b_ref->{branchname
} = GetBranchName
( $b_ref->{branchcode
} );
258 if (/^incl_par_(\d+)$/) {
260 push @lines_to_pay, $input->param("accountno$index");
261 $amt += $input->param("amountoutstanding$index");
264 $amt = '&amt=' . $amt;
265 my $sel = '&selected=' . join ',', @lines_to_pay;
267 "/cgi-bin/koha/members/paycollect.pl?borrowernumber=$borrowernumber"
271 print $input->redirect($redirect);
275 sub get_writeoff_sth
{
277 # lets prepare these statement handles only once
281 my $dbh = C4
::Context
->dbh;
283 # Do we need to validate accounttype
284 my $sql = 'Update accountlines set amountoutstanding=0 '
285 . 'WHERE accountlines_id=?';
286 $writeoff_sth = $dbh->prepare($sql);
288 q{insert into accountlines (borrowernumber,accountno,itemnumber,date,amount,description,accounttype,manager_id)}
289 . q{values (?,?,?,now(),?,'Writeoff','W',?)};
290 $add_writeoff_sth = $dbh->prepare($insert);