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 $accountno = $input->param('accountno');
87 my $itemno = $input->param('itemnumber');
88 my $account_type = $input->param('accounttype');
89 my $amount = $input->param('amountoutstanding');
90 WriteOffFee( $borrowernumber, $accountno, $itemno, $account_type, $amount, $branch );
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 );
103 $template->param( activeBorrowerRelationship => (C4::Context->preference('borrowerRelationship') ne '') );
105 add_accounts_to_template();
107 output_html_with_http_headers $input, $cookie, $template->output;
110 sub add_accounts_to_template {
112 my ( $total, undef, undef ) = GetMemberAccountRecords($borrowernumber);
114 my @notify = NumberNotifyId($borrowernumber);
116 my $notify_groups = [];
117 for my $notify_id (@notify) {
118 my ( $acct_total, $accountlines, undef ) =
119 GetBorNotifyAcctRecord( $borrowernumber, $notify_id );
120 if ( @{$accountlines} ) {
121 my $totalnotify = AmountNotify( $notify_id, $borrowernumber );
123 { accountlines => $accountlines,
124 notify => $notify_id,
125 total => $totalnotify,
129 borrower_add_additional_fields($borrower);
131 accounts => $accounts,
132 borrower => $borrower,
139 sub get_for_redirect {
140 my ( $name, $name_in, $money ) = @_;
141 my $s = q{&} . $name . q{=};
142 my $value = $input->param($name_in);
143 if ( !defined $value ) {
144 $value = ( $money == 1 ) ? 0 : q{};
147 $s .= sprintf '%.2f', $value;
154 sub redirect_to_paycollect {
155 my ( $action, $line_no ) = @_;
157 "/cgi-bin/koha/members/paycollect.pl?borrowernumber=$borrowernumber";
159 $redirect .= "$action=1";
160 $redirect .= get_for_redirect( 'accounttype', "accounttype$line_no", 0 );
161 $redirect .= get_for_redirect( 'amount', "amount$line_no", 1 );
163 get_for_redirect( 'amountoutstanding', "amountoutstanding$line_no", 1 );
164 $redirect .= get_for_redirect( 'accountno', "accountno$line_no", 0 );
165 $redirect .= get_for_redirect( 'description', "description$line_no", 0 );
166 $redirect .= get_for_redirect( 'title', "title$line_no", 0 );
167 $redirect .= get_for_redirect( 'itemnumber', "itemnumber$line_no", 0 );
168 $redirect .= get_for_redirect( 'notify_id', "notify_id$line_no", 0 );
169 $redirect .= get_for_redirect( 'notify_level', "notify_level$line_no", 0 );
170 $redirect .= '&remote_user=';
172 return print $input->redirect($redirect);
177 my @wo_lines = grep { /^accountno\d+$/ } @params;
181 my $accounttype = $input->param("accounttype$value");
183 # my $borrowernum = $input->param("borrowernumber$value");
184 my $itemno = $input->param("itemnumber$value");
185 my $amount = $input->param("amountoutstanding$value");
186 my $accountno = $input->param("accountno$value");
187 WriteOffFee( $borrowernumber, $accountno, $itemno, $accounttype, $amount, $branch );
191 $borrowernumber = $input->param('borrowernumber');
192 print $input->redirect(
193 "/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber");
197 sub borrower_add_additional_fields {
200 # some borrower info is not returned in the standard call despite being assumed
201 # in a number of templates. It should not be the business of this script but in lieu of
202 # a revised api here it is ...
203 if ( $b_ref->{category_type} eq 'C' ) {
204 my ( $catcodes, $labels ) =
205 GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
206 if ( @{$catcodes} ) {
207 if ( @{$catcodes} > 1 ) {
208 $b_ref->{CATCODE_MULTI} = 1;
209 } elsif ( @{$catcodes} == 1 ) {
210 $b_ref->{catcode} = $catcodes->[0];
213 } elsif ( $b_ref->{category_type} eq 'A' ) {
214 $b_ref->{adultborrower} = 1;
216 my ( $picture, $dberror ) = GetPatronImage( $b_ref->{cardnumber} );
218 $b_ref->{has_picture} = 1;
221 if (C4::Context->preference('ExtendedPatronAttributes')) {
222 $b_ref->{extendedattributes} = GetBorrowerAttributes($borrowernumber);
224 ExtendedPatronAttributes => 1,
228 $b_ref->{branchname} = GetBranchName( $b_ref->{branchcode} );
237 if (/^incl_par_(\d+)$/) {
239 push @lines_to_pay, $input->param("accountno$index");
240 $amt += $input->param("amountoutstanding$index");
243 $amt = '&amt=' . $amt;
244 my $sel = '&selected=' . join ',', @lines_to_pay;
246 "/cgi-bin/koha/members/paycollect.pl?borrowernumber=$borrowernumber"
250 print $input->redirect($redirect);