Lines 1453-1459
sub AddIssue {
Link Here
|
1453 |
UpdateTotalIssues( $item_object->biblionumber, 1 ); |
1453 |
UpdateTotalIssues( $item_object->biblionumber, 1 ); |
1454 |
} |
1454 |
} |
1455 |
|
1455 |
|
1456 |
## If item was lost, it has now been found, reverse any list item charges if necessary. |
1456 |
## If item was lost, it has now been found, reverse any lost item charges if necessary. |
1457 |
if ( $item_object->itemlost ) { |
1457 |
if ( $item_object->itemlost ) { |
1458 |
my $refund = 1; |
1458 |
my $refund = 1; |
1459 |
my $no_refund_after_days = C4::Context->preference('NoRefundOnLostReturnedItemsAge'); |
1459 |
my $no_refund_after_days = C4::Context->preference('NoRefundOnLostReturnedItemsAge'); |
Lines 1467-1483
sub AddIssue {
Link Here
|
1467 |
$refund = 0 unless ( $lost_age_in_days < $no_refund_after_days ); |
1467 |
$refund = 0 unless ( $lost_age_in_days < $no_refund_after_days ); |
1468 |
} |
1468 |
} |
1469 |
|
1469 |
|
1470 |
if ( |
1470 |
my $lostreturn_policy = |
1471 |
$refund && Koha::CirculationRules->get_lostreturn_policy( |
1471 |
Koha::CirculationRules->get_lostreturn_policy( |
1472 |
{ |
1472 |
{ |
1473 |
return_branch => C4::Context->userenv->{branch}, |
1473 |
return_branch => C4::Context->userenv->{branch}, |
1474 |
item => $item_object |
1474 |
item => $item_object |
1475 |
} |
1475 |
} |
1476 |
) |
1476 |
); |
1477 |
) |
1477 |
|
1478 |
{ |
1478 |
if ($refund && $lostreturn_policy) { |
1479 |
_FixAccountForLostAndFound( $item_object->itemnumber, undef, |
1479 |
_FixAccountForLostAndFound( $item_object->itemnumber, undef, |
1480 |
$item_object->barcode ); |
1480 |
$item_object->barcode ); |
|
|
1481 |
|
1482 |
if ( $lostreturn_policy eq 'charge' ) { |
1483 |
$actualissue //= Koha::Old::Checkouts->search( |
1484 |
{ itemnumber => $item_unblessed->{itemnumber} }, |
1485 |
{ |
1486 |
order_by => { '-desc' => 'returndate' }, |
1487 |
rows => 1 |
1488 |
} |
1489 |
)->single; |
1490 |
|
1491 |
_CalculateAndUpdateFine( |
1492 |
{ |
1493 |
issue => $actualissue, |
1494 |
item => $item_unblessed, |
1495 |
borrower => $borrower |
1496 |
} |
1497 |
); |
1498 |
_FixOverduesOnReturn( $borrower->{borrowernumber}, |
1499 |
$item_object->itemnumber, undef, 'RENEWED' ); |
1500 |
} |
1501 |
elsif ( $lostreturn_policy eq 'restore' ) { |
1502 |
_RestoreOverdueForLostAndFound( |
1503 |
$borrower->{'borrowernumber'}, |
1504 |
$item_object->itemnumber |
1505 |
); |
1506 |
} |
1481 |
} |
1507 |
} |
1482 |
} |
1508 |
} |
1483 |
|
1509 |
|
Lines 2062-2080
sub AddReturn {
Link Here
|
2062 |
$refund = 0 unless ( $lost_age_in_days < $no_refund_after_days ); |
2088 |
$refund = 0 unless ( $lost_age_in_days < $no_refund_after_days ); |
2063 |
} |
2089 |
} |
2064 |
|
2090 |
|
2065 |
if ( |
2091 |
my $lostreturn_policy = |
2066 |
$refund && |
2092 |
Koha::CirculationRules->get_lostreturn_policy( |
2067 |
Koha::CirculationRules->get_lostreturn_policy( |
2093 |
{ |
2068 |
{ |
2094 |
return_branch => C4::Context->userenv->{branch}, |
2069 |
return_branch => C4::Context->userenv->{branch}, |
2095 |
item => $item |
2070 |
item => $item, |
2096 |
} |
2071 |
} |
2097 |
); |
2072 |
) |
2098 |
|
2073 |
) |
2099 |
if ($refund && $lostreturn_policy) { |
2074 |
{ |
|
|
2075 |
_FixAccountForLostAndFound( $item->itemnumber, |
2100 |
_FixAccountForLostAndFound( $item->itemnumber, |
2076 |
$borrowernumber, $barcode ); |
2101 |
$borrowernumber, $barcode ); |
2077 |
$messages->{'LostItemFeeRefunded'} = 1; |
2102 |
$messages->{'LostItemFeeRefunded'} = 1; |
|
|
2103 |
|
2104 |
if ( $lostreturn_policy eq 'charge' ) { |
2105 |
$issue //= Koha::Old::Checkouts->search( |
2106 |
{ itemnumber => $item->itemnumber }, |
2107 |
{ order_by => { '-desc' => 'returndate' }, rows => 1 } |
2108 |
)->single; |
2109 |
_CalculateAndUpdateFine( |
2110 |
{ |
2111 |
issue => $issue, |
2112 |
item => $item->unblessed, |
2113 |
borrower => $patron_unblessed, |
2114 |
return_date => $return_date |
2115 |
} |
2116 |
); |
2117 |
$messages->{'LostItemFeeCharged'} = 1; |
2118 |
} |
2119 |
elsif ( $lostreturn_policy eq 'restore' ) { |
2120 |
_RestoreOverdueForLostAndFound( $borrowernumber, |
2121 |
$item->itemnumber ); |
2122 |
$messages->{'LostItemFeeRestored'} = 1; |
2123 |
} |
2078 |
} |
2124 |
} |
2079 |
} |
2125 |
} |
2080 |
} |
2126 |
} |
Lines 2486-2499
sub _FixOverduesOnReturn {
Link Here
|
2486 |
if (C4::Context->preference("FinesLog")) { |
2532 |
if (C4::Context->preference("FinesLog")) { |
2487 |
&logaction("FINES", 'MODIFY',$borrowernumber,"Overdue forgiven: item $item"); |
2533 |
&logaction("FINES", 'MODIFY',$borrowernumber,"Overdue forgiven: item $item"); |
2488 |
} |
2534 |
} |
2489 |
|
|
|
2490 |
$accountline->status('FORGIVEN'); |
2491 |
$accountline->store(); |
2492 |
} else { |
2493 |
$accountline->status($status); |
2494 |
$accountline->store(); |
2495 |
|
2496 |
} |
2535 |
} |
|
|
2536 |
|
2537 |
$accountline->status($status); |
2538 |
return $accountline->store(); |
2497 |
} |
2539 |
} |
2498 |
); |
2540 |
); |
2499 |
|
2541 |
|
Lines 2589-2594
sub _FixAccountForLostAndFound {
Link Here
|
2589 |
return ($credit) ? $credit->id : undef; |
2631 |
return ($credit) ? $credit->id : undef; |
2590 |
} |
2632 |
} |
2591 |
|
2633 |
|
|
|
2634 |
=head2 _RestoreOverdueForLostAndFound |
2635 |
|
2636 |
&_RestoreOverdueForLostAndFound($borrowernumber, $itemnumber ); |
2637 |
|
2638 |
C<$borrowernumber> borrowernumber |
2639 |
|
2640 |
C<$itemnumber> itemnumber |
2641 |
|
2642 |
Internal function |
2643 |
|
2644 |
=cut |
2645 |
|
2646 |
sub _RestoreOverdueForLostAndFound { |
2647 |
my ( $borrowernumber, $item ) = @_; |
2648 |
|
2649 |
unless( $borrowernumber ) { |
2650 |
warn "_RestoreOverdueForLostAndFound() not supplied valid borrowernumber"; |
2651 |
return; |
2652 |
} |
2653 |
unless( $item ) { |
2654 |
warn "_RestoreOverdueForLostAndFound() not supplied valid itemnumber"; |
2655 |
return; |
2656 |
} |
2657 |
|
2658 |
my $schema = Koha::Database->schema; |
2659 |
|
2660 |
my $result = $schema->txn_do( |
2661 |
sub { |
2662 |
# check for lost overdue fine |
2663 |
my $accountlines = Koha::Account::Lines->search( |
2664 |
{ |
2665 |
borrowernumber => $borrowernumber, |
2666 |
itemnumber => $item, |
2667 |
debit_type_code => 'OVERDUE', |
2668 |
status => 'LOST' |
2669 |
}, |
2670 |
{ |
2671 |
order_by => { '-desc' => 'date' }, |
2672 |
rows => 1 |
2673 |
} |
2674 |
); |
2675 |
return 0 unless $accountlines->count; # no warning, there's just nothing to fix |
2676 |
|
2677 |
# Update status of fine |
2678 |
my $overdue = $accountlines->next; |
2679 |
$overdue->status('RETURNED')->store(); |
2680 |
|
2681 |
# Find related forgive credit |
2682 |
my $refunds = $overdue->credits( |
2683 |
{ |
2684 |
credit_type_code => 'FORGIVEN', |
2685 |
itemnumber => $item, |
2686 |
status => [ { '!=' => 'VOID' }, undef ] |
2687 |
}, |
2688 |
{ order_by => { '-desc' => 'date' }, rows => 1 } |
2689 |
); |
2690 |
return 0 unless $refunds->count; # no warning, there's just nothing to fix |
2691 |
|
2692 |
# Revert the forgive credit |
2693 |
my $refund = $refunds->next; |
2694 |
return $refund->void(); |
2695 |
} |
2696 |
); |
2697 |
|
2698 |
return $result; |
2699 |
} |
2700 |
|
2592 |
=head2 _GetCircControlBranch |
2701 |
=head2 _GetCircControlBranch |
2593 |
|
2702 |
|
2594 |
my $circ_control_branch = _GetCircControlBranch($iteminfos, $borrower); |
2703 |
my $circ_control_branch = _GetCircControlBranch($iteminfos, $borrower); |