Lines 1530-1535
sub AddIssue {
Link Here
|
1530 |
UpdateTotalIssues( $item_object->biblionumber, 1 ); |
1530 |
UpdateTotalIssues( $item_object->biblionumber, 1 ); |
1531 |
} |
1531 |
} |
1532 |
|
1532 |
|
|
|
1533 |
# Record if item was lost |
1534 |
my $was_lost = $item_object->itemlost; |
1535 |
|
1533 |
$item_object->issues( ( $item_object->issues || 0 ) + 1); |
1536 |
$item_object->issues( ( $item_object->issues || 0 ) + 1); |
1534 |
$item_object->holdingbranch(C4::Context->userenv->{'branch'}); |
1537 |
$item_object->holdingbranch(C4::Context->userenv->{'branch'}); |
1535 |
$item_object->itemlost(0); |
1538 |
$item_object->itemlost(0); |
Lines 1538-1543
sub AddIssue {
Link Here
|
1538 |
$item_object->datelastseen( dt_from_string()->ymd() ); |
1541 |
$item_object->datelastseen( dt_from_string()->ymd() ); |
1539 |
$item_object->store({log_action => 0}); |
1542 |
$item_object->store({log_action => 0}); |
1540 |
|
1543 |
|
|
|
1544 |
# If the item was lost, it has now been found, restore/charge the overdue if necessary |
1545 |
if ($was_lost) { |
1546 |
my $lostreturn_policy = |
1547 |
Koha::CirculationRules->get_lostreturn_policy( |
1548 |
{ |
1549 |
return_branch => C4::Context->userenv->{branch}, |
1550 |
item => $item_object |
1551 |
} |
1552 |
); |
1553 |
|
1554 |
if ($lostreturn_policy) { |
1555 |
if ( $lostreturn_policy eq 'charge' ) { |
1556 |
$actualissue //= Koha::Old::Checkouts->search( |
1557 |
{ itemnumber => $item_unblessed->{itemnumber} }, |
1558 |
{ |
1559 |
order_by => { '-desc' => 'returndate' }, |
1560 |
rows => 1 |
1561 |
} |
1562 |
)->single; |
1563 |
unless ( exists( $borrower->{branchcode} ) ) { |
1564 |
my $patron = $actualissue->patron; |
1565 |
$borrower = $patron->unblessed; |
1566 |
} |
1567 |
_CalculateAndUpdateFine( |
1568 |
{ |
1569 |
issue => $actualissue, |
1570 |
item => $item_unblessed, |
1571 |
borrower => $borrower, |
1572 |
return_date => $issuedate |
1573 |
} |
1574 |
); |
1575 |
_FixOverduesOnReturn( $borrower->{borrowernumber}, |
1576 |
$item_object->itemnumber, undef, 'RENEWED' ); |
1577 |
} |
1578 |
elsif ( $lostreturn_policy eq 'restore' ) { |
1579 |
_RestoreOverdueForLostAndFound( |
1580 |
$item_object->itemnumber ); |
1581 |
} |
1582 |
|
1583 |
if ( C4::Context->preference('AccountAutoReconcile') ) { |
1584 |
$account->reconcile_balance; |
1585 |
} |
1586 |
} |
1587 |
|
1588 |
} |
1589 |
|
1541 |
# If it costs to borrow this book, charge it to the patron's account. |
1590 |
# If it costs to borrow this book, charge it to the patron's account. |
1542 |
my ( $charge, $itemtype ) = GetIssuingCharges( $item_object->itemnumber, $borrower->{'borrowernumber'} ); |
1591 |
my ( $charge, $itemtype ) = GetIssuingCharges( $item_object->itemnumber, $borrower->{'borrowernumber'} ); |
1543 |
if ( $charge && $charge > 0 ) { |
1592 |
if ( $charge && $charge > 0 ) { |
Lines 2048-2053
sub AddReturn {
Link Here
|
2048 |
$messages->{'WasLost'} = 1; |
2097 |
$messages->{'WasLost'} = 1; |
2049 |
unless ( C4::Context->preference("BlockReturnOfLostItems") ) { |
2098 |
unless ( C4::Context->preference("BlockReturnOfLostItems") ) { |
2050 |
$messages->{'LostItemFeeRefunded'} = $updated_item->{_refunded}; |
2099 |
$messages->{'LostItemFeeRefunded'} = $updated_item->{_refunded}; |
|
|
2100 |
|
2101 |
my $lostreturn_policy = |
2102 |
Koha::CirculationRules->get_lostreturn_policy( |
2103 |
{ |
2104 |
return_branch => C4::Context->userenv->{branch}, |
2105 |
item => $updated_item |
2106 |
} |
2107 |
); |
2108 |
|
2109 |
if ($lostreturn_policy) { |
2110 |
if ( $lostreturn_policy eq 'charge' ) { |
2111 |
$issue //= Koha::Old::Checkouts->search( |
2112 |
{ itemnumber => $item->itemnumber }, |
2113 |
{ order_by => { '-desc' => 'returndate' }, rows => 1 } |
2114 |
)->single; |
2115 |
unless (exists($patron_unblessed->{branchcode})) { |
2116 |
my $patron = $issue->patron; |
2117 |
$patron_unblessed = $patron->unblessed; |
2118 |
} |
2119 |
_CalculateAndUpdateFine( |
2120 |
{ |
2121 |
issue => $issue, |
2122 |
item => $item->unblessed, |
2123 |
borrower => $patron_unblessed, |
2124 |
return_date => $return_date |
2125 |
} |
2126 |
); |
2127 |
_FixOverduesOnReturn( $patron_unblessed->{borrowernumber}, |
2128 |
$item->itemnumber, undef, 'RETURNED' ); |
2129 |
$messages->{'LostItemFeeCharged'} = 1; |
2130 |
} |
2131 |
elsif ( $lostreturn_policy eq 'restore' ) { |
2132 |
_RestoreOverdueForLostAndFound( $item->itemnumber ); |
2133 |
$messages->{'LostItemFeeRestored'} = 1; |
2134 |
} |
2135 |
} |
2051 |
} |
2136 |
} |
2052 |
} |
2137 |
} |
2053 |
|
2138 |
|
Lines 2477-2482
sub _FixOverduesOnReturn {
Link Here
|
2477 |
my $amountoutstanding = $accountline->amountoutstanding; |
2562 |
my $amountoutstanding = $accountline->amountoutstanding; |
2478 |
if ( $accountline->amount == 0 && $payments->count == 0 ) { |
2563 |
if ( $accountline->amount == 0 && $payments->count == 0 ) { |
2479 |
$accountline->delete; |
2564 |
$accountline->delete; |
|
|
2565 |
return 0; # no warning, we've just removed a zero value fine (backdated return) |
2480 |
} elsif ($exemptfine && ($amountoutstanding != 0)) { |
2566 |
} elsif ($exemptfine && ($amountoutstanding != 0)) { |
2481 |
my $account = Koha::Account->new({patron_id => $borrowernumber}); |
2567 |
my $account = Koha::Account->new({patron_id => $borrowernumber}); |
2482 |
my $credit = $account->add_credit( |
2568 |
my $credit = $account->add_credit( |
Lines 2495-2508
sub _FixOverduesOnReturn {
Link Here
|
2495 |
if (C4::Context->preference("FinesLog")) { |
2581 |
if (C4::Context->preference("FinesLog")) { |
2496 |
&logaction("FINES", 'MODIFY',$borrowernumber,"Overdue forgiven: item $item"); |
2582 |
&logaction("FINES", 'MODIFY',$borrowernumber,"Overdue forgiven: item $item"); |
2497 |
} |
2583 |
} |
|
|
2584 |
} |
2498 |
|
2585 |
|
2499 |
$accountline->status('FORGIVEN'); |
2586 |
$accountline->status($status); |
2500 |
$accountline->store(); |
2587 |
return $accountline->store(); |
2501 |
} else { |
2588 |
} |
2502 |
$accountline->status($status); |
2589 |
); |
2503 |
$accountline->store(); |
|
|
2504 |
|
2590 |
|
2505 |
} |
2591 |
return $result; |
|
|
2592 |
} |
2593 |
|
2594 |
=head2 _RestoreOverdueForLostAndFound |
2595 |
|
2596 |
&_RestoreOverdueForLostAndFound( $itemnumber ); |
2597 |
|
2598 |
C<$itemnumber> itemnumber |
2599 |
|
2600 |
Internal function |
2601 |
|
2602 |
=cut |
2603 |
|
2604 |
sub _RestoreOverdueForLostAndFound { |
2605 |
my ( $item ) = @_; |
2606 |
|
2607 |
unless( $item ) { |
2608 |
warn "_RestoreOverdueForLostAndFound() not supplied valid itemnumber"; |
2609 |
return; |
2610 |
} |
2611 |
|
2612 |
my $schema = Koha::Database->schema; |
2613 |
|
2614 |
my $result = $schema->txn_do( |
2615 |
sub { |
2616 |
# check for lost overdue fine |
2617 |
my $accountlines = Koha::Account::Lines->search( |
2618 |
{ |
2619 |
itemnumber => $item, |
2620 |
debit_type_code => 'OVERDUE', |
2621 |
status => 'LOST' |
2622 |
}, |
2623 |
{ |
2624 |
order_by => { '-desc' => 'date' }, |
2625 |
rows => 1 |
2626 |
} |
2627 |
); |
2628 |
return 0 unless $accountlines->count; # no warning, there's just nothing to fix |
2629 |
|
2630 |
# Update status of fine |
2631 |
my $overdue = $accountlines->next; |
2632 |
$overdue->status('RETURNED')->store(); |
2633 |
|
2634 |
# Find related forgive credit |
2635 |
my $refunds = $overdue->credits( |
2636 |
{ |
2637 |
credit_type_code => 'FORGIVEN', |
2638 |
itemnumber => $item, |
2639 |
status => [ { '!=' => 'VOID' }, undef ] |
2640 |
}, |
2641 |
{ order_by => { '-desc' => 'date' }, rows => 1 } |
2642 |
); |
2643 |
return 0 unless $refunds->count; # no warning, there's just nothing to fix |
2644 |
|
2645 |
# Revert the forgive credit |
2646 |
my $refund = $refunds->next; |
2647 |
return $refund->void(); |
2506 |
} |
2648 |
} |
2507 |
); |
2649 |
); |
2508 |
|
2650 |
|