Lines 1508-1513
sub AddIssue {
Link Here
|
1508 |
UpdateTotalIssues( $item_object->biblionumber, 1 ); |
1508 |
UpdateTotalIssues( $item_object->biblionumber, 1 ); |
1509 |
} |
1509 |
} |
1510 |
|
1510 |
|
|
|
1511 |
# Record if item was lost |
1512 |
my $was_lost = $item_object->itemlost; |
1513 |
|
1511 |
$item_object->issues( ( $item_object->issues || 0 ) + 1); |
1514 |
$item_object->issues( ( $item_object->issues || 0 ) + 1); |
1512 |
$item_object->holdingbranch(C4::Context->userenv->{'branch'}); |
1515 |
$item_object->holdingbranch(C4::Context->userenv->{'branch'}); |
1513 |
$item_object->itemlost(0); |
1516 |
$item_object->itemlost(0); |
Lines 1516-1521
sub AddIssue {
Link Here
|
1516 |
$item_object->store({log_action => 0}); |
1519 |
$item_object->store({log_action => 0}); |
1517 |
ModDateLastSeen( $item_object->itemnumber ); |
1520 |
ModDateLastSeen( $item_object->itemnumber ); |
1518 |
|
1521 |
|
|
|
1522 |
# If the item was lost, it has now been found, restore/charge the overdue if necessary |
1523 |
if ($was_lost) { |
1524 |
my $lostreturn_policy = |
1525 |
Koha::CirculationRules->get_lostreturn_policy( |
1526 |
{ |
1527 |
return_branch => C4::Context->userenv->{branch}, |
1528 |
item => $item_object |
1529 |
} |
1530 |
); |
1531 |
|
1532 |
if ($lostreturn_policy) { |
1533 |
if ( $lostreturn_policy eq 'charge' ) { |
1534 |
$actualissue //= Koha::Old::Checkouts->search( |
1535 |
{ itemnumber => $item_unblessed->{itemnumber} }, |
1536 |
{ |
1537 |
order_by => { '-desc' => 'returndate' }, |
1538 |
rows => 1 |
1539 |
} |
1540 |
)->single; |
1541 |
unless ( exists( $borrower->{branchcode} ) ) { |
1542 |
my $patron = $issue->patron; |
1543 |
$borrower = $patron->unblessed; |
1544 |
} |
1545 |
_CalculateAndUpdateFine( |
1546 |
{ |
1547 |
issue => $actualissue, |
1548 |
item => $item_unblessed, |
1549 |
borrower => $borrower, |
1550 |
return_date => $issuedate |
1551 |
} |
1552 |
); |
1553 |
_FixOverduesOnReturn( $borrower->{borrowernumber}, |
1554 |
$item_object->itemnumber, undef, 'RENEWED' ); |
1555 |
} |
1556 |
elsif ( $lostreturn_policy eq 'restore' ) { |
1557 |
_RestoreOverdueForLostAndFound( |
1558 |
$item_object->itemnumber ); |
1559 |
} |
1560 |
} |
1561 |
|
1562 |
} |
1563 |
|
1519 |
# If it costs to borrow this book, charge it to the patron's account. |
1564 |
# If it costs to borrow this book, charge it to the patron's account. |
1520 |
my ( $charge, $itemtype ) = GetIssuingCharges( $item_object->itemnumber, $borrower->{'borrowernumber'} ); |
1565 |
my ( $charge, $itemtype ) = GetIssuingCharges( $item_object->itemnumber, $borrower->{'borrowernumber'} ); |
1521 |
if ( $charge && $charge > 0 ) { |
1566 |
if ( $charge && $charge > 0 ) { |
Lines 2021-2026
sub AddReturn {
Link Here
|
2021 |
$messages->{'WasLost'} = 1; |
2066 |
$messages->{'WasLost'} = 1; |
2022 |
unless ( C4::Context->preference("BlockReturnOfLostItems") ) { |
2067 |
unless ( C4::Context->preference("BlockReturnOfLostItems") ) { |
2023 |
$messages->{'LostItemFeeRefunded'} = $updated_item->{_refunded}; |
2068 |
$messages->{'LostItemFeeRefunded'} = $updated_item->{_refunded}; |
|
|
2069 |
|
2070 |
my $lostreturn_policy = |
2071 |
Koha::CirculationRules->get_lostreturn_policy( |
2072 |
{ |
2073 |
return_branch => C4::Context->userenv->{branch}, |
2074 |
item => $updated_item |
2075 |
} |
2076 |
); |
2077 |
|
2078 |
if ($lostreturn_policy) { |
2079 |
if ( $lostreturn_policy eq 'charge' ) { |
2080 |
$issue //= Koha::Old::Checkouts->search( |
2081 |
{ itemnumber => $item->itemnumber }, |
2082 |
{ order_by => { '-desc' => 'returndate' }, rows => 1 } |
2083 |
)->single; |
2084 |
unless (exists($patron_unblessed->{branchcode})) { |
2085 |
my $patron = $issue->patron; |
2086 |
$patron_unblessed = $patron->unblessed; |
2087 |
} |
2088 |
_CalculateAndUpdateFine( |
2089 |
{ |
2090 |
issue => $issue, |
2091 |
item => $item->unblessed, |
2092 |
borrower => $patron_unblessed, |
2093 |
return_date => $return_date |
2094 |
} |
2095 |
); |
2096 |
_FixOverduesOnReturn( $patron_unblessed->{borrowernumber}, |
2097 |
$item->itemnumber, undef, 'RETURNED' ); |
2098 |
$messages->{'LostItemFeeCharged'} = 1; |
2099 |
} |
2100 |
elsif ( $lostreturn_policy eq 'restore' ) { |
2101 |
_RestoreOverdueForLostAndFound( $item->itemnumber ); |
2102 |
$messages->{'LostItemFeeRestored'} = 1; |
2103 |
} |
2104 |
} |
2024 |
} |
2105 |
} |
2025 |
} |
2106 |
} |
2026 |
|
2107 |
|
Lines 2444-2449
sub _FixOverduesOnReturn {
Link Here
|
2444 |
my $amountoutstanding = $accountline->amountoutstanding; |
2525 |
my $amountoutstanding = $accountline->amountoutstanding; |
2445 |
if ( $accountline->amount == 0 && $payments->count == 0 ) { |
2526 |
if ( $accountline->amount == 0 && $payments->count == 0 ) { |
2446 |
$accountline->delete; |
2527 |
$accountline->delete; |
|
|
2528 |
return 0; # no warning, we've just removed a zero value fine (backdated return) |
2447 |
} elsif ($exemptfine && ($amountoutstanding != 0)) { |
2529 |
} elsif ($exemptfine && ($amountoutstanding != 0)) { |
2448 |
my $account = Koha::Account->new({patron_id => $borrowernumber}); |
2530 |
my $account = Koha::Account->new({patron_id => $borrowernumber}); |
2449 |
my $credit = $account->add_credit( |
2531 |
my $credit = $account->add_credit( |
Lines 2462-2475
sub _FixOverduesOnReturn {
Link Here
|
2462 |
if (C4::Context->preference("FinesLog")) { |
2544 |
if (C4::Context->preference("FinesLog")) { |
2463 |
&logaction("FINES", 'MODIFY',$borrowernumber,"Overdue forgiven: item $item"); |
2545 |
&logaction("FINES", 'MODIFY',$borrowernumber,"Overdue forgiven: item $item"); |
2464 |
} |
2546 |
} |
|
|
2547 |
} |
2465 |
|
2548 |
|
2466 |
$accountline->status('FORGIVEN'); |
2549 |
$accountline->status($status); |
2467 |
$accountline->store(); |
2550 |
return $accountline->store(); |
2468 |
} else { |
2551 |
} |
2469 |
$accountline->status($status); |
2552 |
); |
2470 |
$accountline->store(); |
|
|
2471 |
|
2553 |
|
2472 |
} |
2554 |
return $result; |
|
|
2555 |
} |
2556 |
|
2557 |
=head2 _RestoreOverdueForLostAndFound |
2558 |
|
2559 |
&_RestoreOverdueForLostAndFound( $itemnumber ); |
2560 |
|
2561 |
C<$itemnumber> itemnumber |
2562 |
|
2563 |
Internal function |
2564 |
|
2565 |
=cut |
2566 |
|
2567 |
sub _RestoreOverdueForLostAndFound { |
2568 |
my ( $item ) = @_; |
2569 |
|
2570 |
unless( $item ) { |
2571 |
warn "_RestoreOverdueForLostAndFound() not supplied valid itemnumber"; |
2572 |
return; |
2573 |
} |
2574 |
|
2575 |
my $schema = Koha::Database->schema; |
2576 |
|
2577 |
my $result = $schema->txn_do( |
2578 |
sub { |
2579 |
# check for lost overdue fine |
2580 |
my $accountlines = Koha::Account::Lines->search( |
2581 |
{ |
2582 |
itemnumber => $item, |
2583 |
debit_type_code => 'OVERDUE', |
2584 |
status => 'LOST' |
2585 |
}, |
2586 |
{ |
2587 |
order_by => { '-desc' => 'date' }, |
2588 |
rows => 1 |
2589 |
} |
2590 |
); |
2591 |
return 0 unless $accountlines->count; # no warning, there's just nothing to fix |
2592 |
|
2593 |
# Update status of fine |
2594 |
my $overdue = $accountlines->next; |
2595 |
$overdue->status('RETURNED')->store(); |
2596 |
|
2597 |
# Find related forgive credit |
2598 |
my $refunds = $overdue->credits( |
2599 |
{ |
2600 |
credit_type_code => 'FORGIVEN', |
2601 |
itemnumber => $item, |
2602 |
status => [ { '!=' => 'VOID' }, undef ] |
2603 |
}, |
2604 |
{ order_by => { '-desc' => 'date' }, rows => 1 } |
2605 |
); |
2606 |
return 0 unless $refunds->count; # no warning, there's just nothing to fix |
2607 |
|
2608 |
# Revert the forgive credit |
2609 |
my $refund = $refunds->next; |
2610 |
return $refund->void(); |
2473 |
} |
2611 |
} |
2474 |
); |
2612 |
); |
2475 |
|
2613 |
|