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
45 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
46 { template_name => 'members/pay.tmpl',
50 flagsrequired => { borrowers => 1, updatecharges => 1 },
58 my @names = $input->param;
60 my $borrowernumber = $input->param('borrowernumber');
61 if ( !$borrowernumber ) {
62 $borrowernumber = $input->param('borrowernumber0');
65 # get borrower details
66 my $borrower = GetMember( borrowernumber => $borrowernumber );
67 my $user = $input->remote_user;
70 my $branches = GetBranches();
71 my $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 $accountno = $input->param('accountno');
89 my $itemno = $input->param('itemnumber');
90 my $account_type = $input->param('accounttype');
91 my $amount = $input->param('amount');
92 writeoff( $accountno, $itemno, $account_type, $amount );
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 add_accounts_to_template();
107 output_html_with_http_headers $input, $cookie, $template->output;
110 my ( $accountnum, $itemnum, $accounttype, $amount ) = @_;
112 # if no item is attached to fine, make sure to store it as a NULL
115 $writeoff_sth->execute( $accountnum, $borrowernumber );
117 my $acct = getnextacctno($borrowernumber);
118 $add_writeoff_sth->execute( $borrowernumber, $acct, $itemnum, $amount );
120 UpdateStats( $branch, 'writeoff', $amount, q{}, q{}, q{}, $borrowernumber );
125 sub add_accounts_to_template {
127 my ( $total, undef, undef ) = GetMemberAccountRecords($borrowernumber);
129 my @notify = NumberNotifyId($borrowernumber);
131 my $notify_groups = [];
132 for my $notify_id (@notify) {
133 my ( $acct_total, $accountlines, undef ) =
134 GetBorNotifyAcctRecord( $borrowernumber, $notify_id );
135 if ( @{$accountlines} ) {
136 my $totalnotify = AmountNotify( $notify_id, $borrowernumber );
138 { accountlines => $accountlines,
139 notify => $notify_id,
140 total => $totalnotify,
144 borrower_add_additional_fields($borrower);
146 accounts => $accounts,
147 borrower => $borrower,
154 sub get_for_redirect {
155 my ( $name, $name_in, $money ) = @_;
156 my $s = q{&} . $name . q{=};
157 my $value = $input->param($name_in);
158 if ( !defined $value ) {
159 $value = ( $money == 1 ) ? 0 : q{};
162 $s .= sprintf '%.2f', $value;
169 sub redirect_to_paycollect {
170 my ( $action, $line_no ) = @_;
172 "/cgi-bin/koha/members/paycollect.pl?borrowernumber=$borrowernumber";
174 $redirect .= "$action=1";
175 $redirect .= get_for_redirect( 'accounttype', "accounttype$line_no", 0 );
176 $redirect .= get_for_redirect( 'amount', "amount$line_no", 1 );
178 get_for_redirect( 'amountoutstanding', "amountoutstanding$line_no", 1 );
179 $redirect .= get_for_redirect( 'accountno', "accountno$line_no", 0 );
180 $redirect .= get_for_redirect( 'description', "description$line_no", 0 );
181 $redirect .= get_for_redirect( 'title', "title$line_no", 0 );
182 $redirect .= get_for_redirect( 'itemnumber', "itemnumber$line_no", 0 );
183 $redirect .= get_for_redirect( 'notify_id', "notify_id$line_no", 0 );
184 $redirect .= get_for_redirect( 'notify_level', "notify_level$line_no", 0 );
185 $redirect .= '&remote_user=';
187 return print $input->redirect($redirect);
192 my @wo_lines = grep { /^accountno\d+$/ } @params;
196 my $accounttype = $input->param("accounttype$value");
198 # my $borrowernum = $input->param("borrowernumber$value");
199 my $itemno = $input->param("itemnumber$value");
200 my $amount = $input->param("amount$value");
201 my $accountno = $input->param("accountno$value");
202 writeoff( $accountno, $itemno, $accounttype, $amount );
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 ( $catcodes, $labels ) =
220 GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
221 if ( @{$catcodes} ) {
222 if ( @{$catcodes} > 1 ) {
223 $b_ref->{CATCODE_MULTI} = 1;
224 } elsif ( @{$catcodes} == 1 ) {
225 $b_ref->{catcode} = $catcodes->[0];
228 } elsif ( $b_ref->{category_type} eq 'A' ) {
229 $b_ref->{adultborrower} = 1;
231 my ( $picture, $dberror ) = GetPatronImage( $b_ref->{cardnumber} );
233 $b_ref->{has_picture} = 1;
236 $b_ref->{branchname} = GetBranchName( $b_ref->{branchcode} );
245 if (/^incl_par_(\d+)$/) {
247 push @lines_to_pay, $input->param("accountno$index");
248 $amt += $input->param("amountoutstanding$index");
251 $amt = '&amt=' . $amt;
252 my $sel = '&selected=' . join ',', @lines_to_pay;
254 "/cgi-bin/koha/members/paycollect.pl?borrowernumber=$borrowernumber"
258 print $input->redirect($redirect);
262 sub get_writeoff_sth {
264 # lets prepare these statement handles only once
268 my $dbh = C4::Context->dbh;
270 # Do we need to validate accounttype
271 my $sql = 'Update accountlines set amountoutstanding=0 '
272 . 'WHERE accountno=? and borrowernumber=?';
273 $writeoff_sth = $dbh->prepare($sql);
275 q{insert into accountlines (borrowernumber,accountno,itemnumber,date,amount,description,accounttype)}
276 . q{values (?,?,?,now(),?,'Writeoff','W')};
277 $add_writeoff_sth = $dbh->prepare($insert);