Lines 26-32
use C4::Members;
Link Here
|
26 |
use C4::Circulation qw(ReturnLostItem); |
26 |
use C4::Circulation qw(ReturnLostItem); |
27 |
use C4::Log qw(logaction); |
27 |
use C4::Log qw(logaction); |
28 |
use Koha::Account; |
28 |
use Koha::Account; |
|
|
29 |
use Koha::Account::Line; |
29 |
use Koha::Account::Lines; |
30 |
use Koha::Account::Lines; |
|
|
31 |
use Koha::Account::Offset; |
30 |
|
32 |
|
31 |
use Data::Dumper qw(Dumper); |
33 |
use Data::Dumper qw(Dumper); |
32 |
|
34 |
|
Lines 118-150
EOT
Link Here
|
118 |
|
120 |
|
119 |
=cut |
121 |
=cut |
120 |
|
122 |
|
|
|
123 |
=head2 chargelostitem |
124 |
|
125 |
In a default install of Koha the following lost values are set |
126 |
1 = Lost |
127 |
2 = Long overdue |
128 |
3 = Lost and paid for |
129 |
|
130 |
FIXME: itemlost should be set to 3 after payment is made, should be a warning to the interface that a charge has been added |
131 |
FIXME : if no replacement price, borrower just doesn't get charged? |
132 |
|
133 |
=cut |
134 |
|
121 |
sub chargelostitem{ |
135 |
sub chargelostitem{ |
122 |
# lost ==1 Lost, lost==2 longoverdue, lost==3 lost and paid for |
|
|
123 |
# FIXME: itemlost should be set to 3 after payment is made, should be a warning to the interface that |
124 |
# a charge has been added |
125 |
# FIXME : if no replacement price, borrower just doesn't get charged? |
126 |
my $dbh = C4::Context->dbh(); |
136 |
my $dbh = C4::Context->dbh(); |
127 |
my ($borrowernumber, $itemnumber, $amount, $description) = @_; |
137 |
my ($borrowernumber, $itemnumber, $amount, $description) = @_; |
128 |
|
138 |
|
129 |
# first make sure the borrower hasn't already been charged for this item |
139 |
# first make sure the borrower hasn't already been charged for this item |
130 |
my $sth1=$dbh->prepare("SELECT * from accountlines |
140 |
my $existing_charges = Koha::Account::Lines->search( |
131 |
WHERE borrowernumber=? AND itemnumber=? and accounttype='L'"); |
141 |
{ |
132 |
$sth1->execute($borrowernumber,$itemnumber); |
142 |
borrowernumber => $borrowernumber, |
133 |
my $existing_charge_hashref=$sth1->fetchrow_hashref(); |
143 |
itemnumber => $itemnumber, |
|
|
144 |
accounttype => 'L', |
145 |
} |
146 |
)->count(); |
134 |
|
147 |
|
135 |
# OK, they haven't |
148 |
# OK, they haven't |
136 |
unless ($existing_charge_hashref) { |
149 |
unless ($existing_charges) { |
137 |
my $manager_id = 0; |
150 |
my $manager_id = 0; |
138 |
$manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; |
151 |
$manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; |
139 |
# This item is on issue ... add replacement cost to the borrower's record and mark it returned |
152 |
# This item is on issue ... add replacement cost to the borrower's record and mark it returned |
140 |
# Note that we add this to the account even if there's no replacement price, allowing some other |
153 |
# Note that we add this to the account even if there's no replacement price, allowing some other |
141 |
# process (or person) to update it, since we don't handle any defaults for replacement prices. |
154 |
# process (or person) to update it, since we don't handle any defaults for replacement prices. |
142 |
my $accountno = getnextacctno($borrowernumber); |
155 |
my $accountno = getnextacctno($borrowernumber); |
143 |
my $sth2=$dbh->prepare("INSERT INTO accountlines |
156 |
|
144 |
(borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,itemnumber,manager_id) |
157 |
my $accountline = Koha::Account::Line->new( |
145 |
VALUES (?,?,now(),?,?,'L',?,?,?)"); |
158 |
{ |
146 |
$sth2->execute($borrowernumber,$accountno,$amount, |
159 |
borrowernumber => $borrowernumber, |
147 |
$description,$amount,$itemnumber,$manager_id); |
160 |
accountno => $accountno, |
|
|
161 |
date => \'NOW()', |
162 |
amount => $amount, |
163 |
description => $description, |
164 |
accounttype => 'L', |
165 |
amountoutstanding => $amount, |
166 |
itemnumber => $itemnumber, |
167 |
manager_id => $manager_id, |
168 |
} |
169 |
)->store(); |
170 |
|
171 |
my $account_offset = Koha::Account::Offset->new( |
172 |
{ |
173 |
debit_id => $accountline->id, |
174 |
type => 'Lost Item', |
175 |
amount => $amount, |
176 |
} |
177 |
)->store(); |
148 |
|
178 |
|
149 |
if ( C4::Context->preference("FinesLog") ) { |
179 |
if ( C4::Context->preference("FinesLog") ) { |
150 |
logaction("FINES", 'CREATE', $borrowernumber, Dumper({ |
180 |
logaction("FINES", 'CREATE', $borrowernumber, Dumper({ |
Lines 208-228
sub manualinvoice {
Link Here
|
208 |
$notifyid = 1; |
238 |
$notifyid = 1; |
209 |
} |
239 |
} |
210 |
|
240 |
|
211 |
if ( $itemnum ) { |
241 |
my $accountline = Koha::Account::Line->new( |
212 |
$desc .= ' ' . $itemnum; |
242 |
{ |
213 |
my $sth = $dbh->prepare( |
243 |
borrowernumber => $borrowernumber, |
214 |
'INSERT INTO accountlines |
244 |
accountno => $accountno, |
215 |
(borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding, itemnumber,notify_id, note, manager_id) |
245 |
date => \'NOW()', |
216 |
VALUES (?, ?, now(), ?,?, ?,?,?,?,?,?)'); |
246 |
amount => $amount, |
217 |
$sth->execute($borrowernumber, $accountno, $amount, $desc, $type, $amountleft, $itemnum,$notifyid, $note, $manager_id) || return $sth->errstr; |
247 |
description => $desc, |
218 |
} else { |
248 |
accounttype => $type, |
219 |
my $sth=$dbh->prepare("INSERT INTO accountlines |
249 |
amountoutstanding => $amountleft, |
220 |
(borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding,notify_id, note, manager_id) |
250 |
itemnumber => $itemnum || undef, |
221 |
VALUES (?, ?, now(), ?, ?, ?, ?,?,?,?)" |
251 |
notify_id => $notifyid, |
222 |
); |
252 |
note => $note, |
223 |
$sth->execute( $borrowernumber, $accountno, $amount, $desc, $type, |
253 |
manager_id => $manager_id, |
224 |
$amountleft, $notifyid, $note, $manager_id ); |
254 |
} |
225 |
} |
255 |
)->store(); |
|
|
256 |
|
257 |
my $account_offset = Koha::Account::Offset->new( |
258 |
{ |
259 |
debit_id => $accountline->id, |
260 |
type => 'Manual Debit', |
261 |
amount => $amount, |
262 |
} |
263 |
)->store(); |
226 |
|
264 |
|
227 |
if ( C4::Context->preference("FinesLog") ) { |
265 |
if ( C4::Context->preference("FinesLog") ) { |
228 |
logaction("FINES", 'CREATE',$borrowernumber,Dumper({ |
266 |
logaction("FINES", 'CREATE',$borrowernumber,Dumper({ |
Lines 308-352
sub getrefunds {
Link Here
|
308 |
return (@results); |
346 |
return (@results); |
309 |
} |
347 |
} |
310 |
|
348 |
|
|
|
349 |
#FIXME: ReversePayment should be replaced with a Void Payment feature |
311 |
sub ReversePayment { |
350 |
sub ReversePayment { |
312 |
my ( $accountlines_id ) = @_; |
351 |
my ($accountlines_id) = @_; |
313 |
my $dbh = C4::Context->dbh; |
352 |
my $dbh = C4::Context->dbh; |
314 |
|
353 |
|
315 |
my $sth = $dbh->prepare('SELECT * FROM accountlines WHERE accountlines_id = ?'); |
354 |
my $accountline = Koha::Account::Lines->find($accountlines_id); |
316 |
$sth->execute( $accountlines_id ); |
355 |
my $amount_outstanding = $accountline->amountoutstanding; |
317 |
my $row = $sth->fetchrow_hashref(); |
356 |
|
318 |
my $amount_outstanding = $row->{'amountoutstanding'}; |
357 |
my $new_amountoutstanding = |
319 |
|
358 |
$amount_outstanding <= 0 ? $accountline->amount * -1 : 0; |
320 |
if ( $amount_outstanding <= 0 ) { |
359 |
|
321 |
$sth = $dbh->prepare('UPDATE accountlines SET amountoutstanding = amount * -1, description = CONCAT( description, " Reversed -" ) WHERE accountlines_id = ?'); |
360 |
$accountline->description( $accountline->description . " Reversed -" ); |
322 |
$sth->execute( $accountlines_id ); |
361 |
$accountline->amountoutstanding($new_amountoutstanding); |
323 |
} else { |
362 |
$accountline->store(); |
324 |
$sth = $dbh->prepare('UPDATE accountlines SET amountoutstanding = 0, description = CONCAT( description, " Reversed -" ) WHERE accountlines_id = ?'); |
363 |
|
325 |
$sth->execute( $accountlines_id ); |
364 |
my $account_offset = Koha::Account::Offset->new( |
326 |
} |
365 |
{ |
|
|
366 |
credit_id => $accountline->id, |
367 |
type => 'Reverse Payment', |
368 |
amount => $amount_outstanding - $new_amountoutstanding, |
369 |
} |
370 |
)->store(); |
327 |
|
371 |
|
328 |
if ( C4::Context->preference("FinesLog") ) { |
372 |
if ( C4::Context->preference("FinesLog") ) { |
329 |
my $manager_id = 0; |
373 |
my $manager_id = 0; |
330 |
$manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; |
374 |
$manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; |
331 |
|
375 |
|
332 |
if ( $amount_outstanding <= 0 ) { |
376 |
logaction( |
333 |
$row->{'amountoutstanding'} *= -1; |
377 |
"FINES", 'MODIFY', |
334 |
} else { |
378 |
$accountline->borrowernumber, |
335 |
$row->{'amountoutstanding'} = '0'; |
379 |
Dumper( |
336 |
} |
380 |
{ |
337 |
$row->{'description'} .= ' Reversed -'; |
381 |
action => 'reverse_fee_payment', |
338 |
logaction("FINES", 'MODIFY', $row->{'borrowernumber'}, Dumper({ |
382 |
borrowernumber => $accountline->borrowernumber, |
339 |
action => 'reverse_fee_payment', |
383 |
old_amountoutstanding => $amount_outstanding, |
340 |
borrowernumber => $row->{'borrowernumber'}, |
384 |
new_amountoutstanding => $new_amountoutstanding, |
341 |
old_amountoutstanding => $row->{'amountoutstanding'}, |
385 |
, |
342 |
new_amountoutstanding => 0 - $amount_outstanding,, |
386 |
accountlines_id => $accountline->id, |
343 |
accountlines_id => $row->{'accountlines_id'}, |
387 |
accountno => $accountline->accountno, |
344 |
accountno => $row->{'accountno'}, |
388 |
manager_id => $manager_id, |
345 |
manager_id => $manager_id, |
389 |
} |
346 |
})); |
390 |
) |
347 |
|
391 |
); |
348 |
} |
392 |
} |
349 |
|
|
|
350 |
} |
393 |
} |
351 |
|
394 |
|
352 |
=head2 purge_zero_balance_fees |
395 |
=head2 purge_zero_balance_fees |