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