|
Lines 353-395
sub chargelostitem{
Link Here
|
| 353 |
# a charge has been added |
353 |
# a charge has been added |
| 354 |
# FIXME : if no replacement price, borrower just doesn't get charged? |
354 |
# FIXME : if no replacement price, borrower just doesn't get charged? |
| 355 |
my $dbh = C4::Context->dbh(); |
355 |
my $dbh = C4::Context->dbh(); |
| 356 |
my ($borrowernumber, $itemnumber, $amount, $description) = @_; |
356 |
my ($issues, $description) = @_; |
| 357 |
|
357 |
my $borrowernumber = $issues->{'borrowernumber'}; |
|
|
358 |
my $itemnumber = $issues->{'itemnumber'}; |
| 359 |
my $replacementprice = $issues->{'replacementprice'}; |
| 360 |
my $defaultreplacecost = $issues->{'defaultreplacecost'}; |
| 361 |
my $processfee = $issues->{'processfee'}; |
| 362 |
my $usedefaultreplacementcost = C4::Context->preference("useDefaultReplacementCost"); |
| 363 |
my $processingfeenote = C4::Context->preference("ProcessingFeeNote"); |
| 364 |
|
| 365 |
if ($usedefaultreplacementcost && $replacementprice == 0){ |
| 366 |
$replacementprice = $defaultreplacecost; |
| 367 |
} |
| 358 |
# first make sure the borrower hasn't already been charged for this item |
368 |
# first make sure the borrower hasn't already been charged for this item |
| 359 |
my $sth1=$dbh->prepare("SELECT * from accountlines |
369 |
my $sth1=$dbh->prepare("SELECT * from accountlines |
| 360 |
WHERE borrowernumber=? AND itemnumber=? and accounttype='L'"); |
370 |
WHERE borrowernumber=? AND itemnumber=? and accounttype='L'"); |
| 361 |
$sth1->execute($borrowernumber,$itemnumber); |
371 |
$sth1->execute($borrowernumber,$itemnumber); |
| 362 |
my $existing_charge_hashref=$sth1->fetchrow_hashref(); |
372 |
my $existing_charge_hashref=$sth1->fetchrow_hashref(); |
| 363 |
|
|
|
| 364 |
# OK, they haven't |
373 |
# OK, they haven't |
|
|
374 |
my $accountline; |
| 365 |
unless ($existing_charge_hashref) { |
375 |
unless ($existing_charge_hashref) { |
| 366 |
my $manager_id = 0; |
|
|
| 367 |
$manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; |
| 368 |
# This item is on issue ... add replacement cost to the borrower's record and mark it returned |
| 369 |
# Note that we add this to the account even if there's no replacement price, allowing some other |
| 370 |
# process (or person) to update it, since we don't handle any defaults for replacement prices. |
| 371 |
my $accountno = getnextacctno($borrowernumber); |
| 372 |
my $sth2=$dbh->prepare("INSERT INTO accountlines |
| 373 |
(borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,itemnumber,manager_id) |
| 374 |
VALUES (?,?,now(),?,?,'L',?,?,?)"); |
| 375 |
$sth2->execute($borrowernumber,$accountno,$amount, |
| 376 |
$description,$amount,$itemnumber,$manager_id); |
| 377 |
|
376 |
|
| 378 |
if ( C4::Context->preference("FinesLog") ) { |
377 |
#add processing fee |
| 379 |
logaction("FINES", 'CREATE', $borrowernumber, Dumper({ |
378 |
if ($processfee > 0){ |
| 380 |
action => 'create_fee', |
379 |
$accountline = _insert_accontlines($borrowernumber, $processfee, $description, $itemnumber, $processingfeenote, 'PF'); |
| 381 |
borrowernumber => $borrowernumber, |
380 |
} |
| 382 |
accountno => $accountno, |
381 |
#add replace cost |
| 383 |
amount => $amount, |
382 |
if ($replacementprice > 0){ |
| 384 |
amountoutstanding => $amount, |
383 |
$accountline = _insert_accontlines($borrowernumber, $replacementprice, $description, $itemnumber, undef, 'L'); |
| 385 |
description => $description, |
|
|
| 386 |
accounttype => 'L', |
| 387 |
itemnumber => $itemnumber, |
| 388 |
manager_id => $manager_id, |
| 389 |
})); |
| 390 |
} |
384 |
} |
|
|
385 |
} |
| 386 |
return $accountline; |
| 387 |
} |
| 391 |
|
388 |
|
|
|
389 |
sub _insert_accontlines { |
| 390 |
my ($borrowernumber, $amount, $description, $itemnumber, $note, $accounttype) = @_; |
| 391 |
my $manager_id = 0; |
| 392 |
$manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; |
| 393 |
my $accountno = getnextacctno($borrowernumber); |
| 394 |
my $dbh = C4::Context->dbh(); |
| 395 |
my $sth2=$dbh->prepare("INSERT INTO accountlines |
| 396 |
(borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,itemnumber,manager_id, note) |
| 397 |
VALUES (?,?,now(),?,?,?,?,?,?,?)"); |
| 398 |
$sth2->execute($borrowernumber,$accountno,$amount, |
| 399 |
$description,$accounttype, $amount,$itemnumber,$manager_id,$note); |
| 400 |
|
| 401 |
if ( C4::Context->preference("FinesLog") ) { |
| 402 |
logaction("FINES", 'CREATE', $borrowernumber, Dumper({ |
| 403 |
action => 'create_fee', |
| 404 |
borrowernumber => $borrowernumber, |
| 405 |
accountno => $accountno, |
| 406 |
amount => $amount, |
| 407 |
amountoutstanding => $amount, |
| 408 |
description => $description, |
| 409 |
accounttype => $accounttype, |
| 410 |
itemnumber => $itemnumber, |
| 411 |
manager_id => $manager_id, |
| 412 |
})); |
| 392 |
} |
413 |
} |
|
|
414 |
return $accountno; |
| 393 |
} |
415 |
} |
| 394 |
|
416 |
|
| 395 |
=head2 manualinvoice |
417 |
=head2 manualinvoice |
|
Lines 473-481
sub manualinvoice {
Link Here
|
| 473 |
} |
495 |
} |
| 474 |
|
496 |
|
| 475 |
sub getcharges { |
497 |
sub getcharges { |
| 476 |
my ( $borrowerno, $timestamp, $accountno ) = @_; |
498 |
my ( $borrowerno, $accountno ) = @_; |
| 477 |
my $dbh = C4::Context->dbh; |
499 |
my $dbh = C4::Context->dbh; |
| 478 |
my $timestamp2 = $timestamp - 1; |
|
|
| 479 |
my $query = ""; |
500 |
my $query = ""; |
| 480 |
my $sth = $dbh->prepare( |
501 |
my $sth = $dbh->prepare( |
| 481 |
"SELECT * FROM accountlines WHERE borrowernumber=? AND accountno = ?" |
502 |
"SELECT * FROM accountlines WHERE borrowernumber=? AND accountno = ?" |