3 # Copyright 2016 ByWater Solutions
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
25 use C4
::Log
qw( logaction );
26 use C4
::Stats
qw( UpdateStats );
28 use Koha
::Account
::Line
;
29 use Koha
::Account
::Lines
;
30 use Koha
::DateUtils
qw( dt_from_string );
34 Koha::Accounts - Module for managing payments and fees for patrons
39 my ( $class, $params ) = @_;
41 Carp
::croak
("No patron id passed in!") unless $params->{patron_id
};
43 return bless( $params, $class );
48 This method allows payments to be made against feees
53 my ( $self, $params ) = @_;
55 my $amount = $params->{amount
};
56 my $sip = $params->{sip
};
57 my $note = $params->{note
} || q{};
59 my $userenv = C4
::Context
->userenv;
61 # We should remove accountno, it is no longer needed
62 my $last = Koha
::Account
::Lines
->search(
64 borrowernumber
=> $self->{patron_id
}
67 order_by
=> 'accountno'
70 my $accountno = $last ?
$last->accountno + 1 : 1;
72 my $manager_id = $userenv ?
$userenv->{number
} : 0;
74 my @outstanding_fines = Koha
::Account
::Lines
->search(
76 borrowernumber
=> $self->{patron_id
},
77 amountoutstanding
=> { '>' => 0 },
81 my $balance_remaining = $amount;
83 foreach my $fine (@outstanding_fines) {
85 $fine->amountoutstanding > $balance_remaining
87 : $fine->amountoutstanding;
89 my $old_amountoutstanding = $fine->amountoutstanding;
90 $fine->amountoutstanding( $old_amountoutstanding - $amount_to_pay );
93 if ( C4
::Context
->preference("FinesLog") ) {
99 action
=> 'fee_payment',
100 borrowernumber
=> $fine->borrowernumber,
101 old_amountoutstanding
=> $old_amountoutstanding,
102 new_amountoutstanding
=> $fine->amountoutstanding,
103 amount_paid
=> $amount_to_pay,
104 accountlines_id
=> $fine->id,
105 accountno
=> $fine->accountno,
106 manager_id
=> $manager_id,
111 push( @fines_paid, $fine->id );
114 $balance_remaining = $balance_remaining - $amount_to_pay;
115 last unless $balance_remaining > 0;
118 my $account_type = defined($sip) ?
"Pay$sip" : 'Pay';
120 my $payment = Koha
::Account
::Line
->new(
122 borrowernumber
=> $self->{patron_id
},
123 accountno
=> $accountno,
124 date
=> dt_from_string
(),
125 amount
=> 0 - $amount,
127 accounttype
=> $account_type,
128 amountoutstanding
=> 0 - $balance_remaining,
129 manager_id
=> $manager_id,
134 my $branch = $userenv ?
$userenv->{'branch'} : undef;
140 borrowernumber
=> $self->{patron_id
},
141 accountno
=> $accountno,
145 if ( C4
::Context
->preference("FinesLog") ) {
151 action
=> 'create_payment',
152 borrowernumber
=> $self->{patron_id
},
153 accountno
=> $accountno,
154 amount
=> 0 - $amount,
155 amountoutstanding
=> 0 - $balance_remaining,
156 accounttype
=> 'Pay',
157 accountlines_paid
=> \
@fines_paid,
158 manager_id
=> $manager_id,
169 Kyle M Hall <kyle.m.hall@gmail.com>