Lines 1453-1471
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 |
if ( |
1458 |
my $lostreturn_policy = |
1459 |
Koha::CirculationRules->get_lostreturn_policy( |
1459 |
Koha::CirculationRules->get_lostreturn_policy( |
1460 |
{ |
1460 |
{ |
1461 |
return_branch => C4::Context->userenv->{branch}, |
1461 |
return_branch => C4::Context->userenv->{branch}, |
1462 |
item => $item_object |
1462 |
item => $item_object |
1463 |
} |
1463 |
} |
1464 |
) |
1464 |
); |
1465 |
) |
1465 |
|
1466 |
{ |
1466 |
if ($lostreturn_policy) { |
1467 |
_FixAccountForLostAndFound( $item_object->itemnumber, undef, |
1467 |
_FixAccountForLostAndFound( $item_object->itemnumber, undef, |
1468 |
$item_object->barcode ); |
1468 |
$item_object->barcode ); |
|
|
1469 |
|
1470 |
if ( $lostreturn_policy eq 'charge' ) { |
1471 |
$actualissue //= Koha::Old::Checkouts->search( |
1472 |
{ itemnumber => $item_unblessed->{itemnumber} }, |
1473 |
{ |
1474 |
order_by => { '-desc' => 'returndate' }, |
1475 |
rows => 1 |
1476 |
} |
1477 |
)->single; |
1478 |
|
1479 |
_CalculateAndUpdateFine( |
1480 |
{ |
1481 |
issue => $actualissue, |
1482 |
item => $item_unblessed, |
1483 |
borrower => $borrower |
1484 |
} |
1485 |
); |
1486 |
_FixOverduesOnReturn( $borrower->{borrowernumber}, |
1487 |
$item_object->itemnumber, undef, 'RENEWED' ); |
1488 |
} |
1489 |
elsif ( $lostreturn_policy eq 'restore' ) { |
1490 |
_RestoreOverdueForLostAndFound( |
1491 |
$borrower->{'borrowernumber'}, |
1492 |
$item_object->itemnumber |
1493 |
); |
1494 |
} |
1469 |
} |
1495 |
} |
1470 |
} |
1496 |
} |
1471 |
|
1497 |
|
Lines 2038-2055
sub AddReturn {
Link Here
|
2038 |
if ( $item->itemlost ) { |
2064 |
if ( $item->itemlost ) { |
2039 |
$messages->{'WasLost'} = 1; |
2065 |
$messages->{'WasLost'} = 1; |
2040 |
unless ( C4::Context->preference("BlockReturnOfLostItems") ) { |
2066 |
unless ( C4::Context->preference("BlockReturnOfLostItems") ) { |
2041 |
if ( |
2067 |
my $lostreturn_policy = |
2042 |
Koha::CirculationRules->get_lostreturn_policy( |
2068 |
Koha::CirculationRules->get_lostreturn_policy( |
2043 |
{ |
2069 |
{ |
2044 |
return_branch => C4::Context->userenv->{branch}, |
2070 |
return_branch => C4::Context->userenv->{branch}, |
2045 |
item => $item, |
2071 |
item => $item |
2046 |
} |
2072 |
} |
2047 |
) |
2073 |
); |
2048 |
) |
2074 |
|
2049 |
{ |
2075 |
if ($lostreturn_policy) { |
2050 |
_FixAccountForLostAndFound( $item->itemnumber, |
2076 |
_FixAccountForLostAndFound( $item->itemnumber, |
2051 |
$borrowernumber, $barcode ); |
2077 |
$borrowernumber, $barcode ); |
2052 |
$messages->{'LostItemFeeRefunded'} = 1; |
2078 |
$messages->{'LostItemFeeRefunded'} = 1; |
|
|
2079 |
|
2080 |
if ( $lostreturn_policy eq 'charge' ) { |
2081 |
$issue //= Koha::Old::Checkouts->search( |
2082 |
{ itemnumber => $item->itemnumber }, |
2083 |
{ order_by => { '-desc' => 'returndate' }, rows => 1 } |
2084 |
)->single; |
2085 |
_CalculateAndUpdateFine( |
2086 |
{ |
2087 |
issue => $issue, |
2088 |
item => $item->unblessed, |
2089 |
borrower => $patron_unblessed, |
2090 |
return_date => $return_date |
2091 |
} |
2092 |
); |
2093 |
$messages->{'LostItemFeeCharged'} = 1; |
2094 |
} |
2095 |
elsif ( $lostreturn_policy eq 'restore' ) { |
2096 |
_RestoreOverdueForLostAndFound( $borrowernumber, |
2097 |
$item->itemnumber ); |
2098 |
$messages->{'LostItemFeeRestored'} = 1; |
2099 |
} |
2053 |
} |
2100 |
} |
2054 |
} |
2101 |
} |
2055 |
} |
2102 |
} |
Lines 2454-2468
sub _FixOverduesOnReturn {
Link Here
|
2454 |
|
2501 |
|
2455 |
$credit->apply({ debits => [ $accountline ], offset_type => 'Forgiven' }); |
2502 |
$credit->apply({ debits => [ $accountline ], offset_type => 'Forgiven' }); |
2456 |
|
2503 |
|
2457 |
$accountline->status('FORGIVEN'); |
|
|
2458 |
|
2459 |
if (C4::Context->preference("FinesLog")) { |
2504 |
if (C4::Context->preference("FinesLog")) { |
2460 |
&logaction("FINES", 'MODIFY',$borrowernumber,"Overdue forgiven: item $item"); |
2505 |
&logaction("FINES", 'MODIFY',$borrowernumber,"Overdue forgiven: item $item"); |
2461 |
} |
2506 |
} |
2462 |
} else { |
|
|
2463 |
$accountline->status($status); |
2464 |
} |
2507 |
} |
2465 |
|
2508 |
|
|
|
2509 |
$accountline->status($status); |
2466 |
return $accountline->store(); |
2510 |
return $accountline->store(); |
2467 |
} |
2511 |
} |
2468 |
); |
2512 |
); |
Lines 2559-2564
sub _FixAccountForLostAndFound {
Link Here
|
2559 |
return ($credit) ? $credit->id : undef; |
2603 |
return ($credit) ? $credit->id : undef; |
2560 |
} |
2604 |
} |
2561 |
|
2605 |
|
|
|
2606 |
=head2 _RestoreOverdueForLostAndFound |
2607 |
|
2608 |
&_RestoreOverdueForLostAndFound($borrowernumber, $itemnumber ); |
2609 |
|
2610 |
C<$borrowernumber> borrowernumber |
2611 |
|
2612 |
C<$itemnumber> itemnumber |
2613 |
|
2614 |
Internal function |
2615 |
|
2616 |
=cut |
2617 |
|
2618 |
sub _RestoreOverdueForLostAndFound { |
2619 |
my ( $borrowernumber, $item ) = @_; |
2620 |
|
2621 |
unless( $borrowernumber ) { |
2622 |
warn "_RestoreOverdueForLostAndFound() not supplied valid borrowernumber"; |
2623 |
return; |
2624 |
} |
2625 |
unless( $item ) { |
2626 |
warn "_RestoreOverdueForLostAndFound() not supplied valid itemnumber"; |
2627 |
return; |
2628 |
} |
2629 |
|
2630 |
my $schema = Koha::Database->schema; |
2631 |
|
2632 |
my $result = $schema->txn_do( |
2633 |
sub { |
2634 |
# check for lost overdue fine |
2635 |
my $accountlines = Koha::Account::Lines->search( |
2636 |
{ |
2637 |
borrowernumber => $borrowernumber, |
2638 |
itemnumber => $item, |
2639 |
debit_type_code => 'OVERDUE', |
2640 |
status => 'LOST' |
2641 |
}, |
2642 |
{ |
2643 |
order_by => { '-desc' => 'date' }, |
2644 |
rows => 1 |
2645 |
} |
2646 |
); |
2647 |
return 0 unless $accountlines->count; # no warning, there's just nothing to fix |
2648 |
|
2649 |
# Update status of fine |
2650 |
my $overdue = $accountlines->next; |
2651 |
$overdue->status('RETURNED')->store(); |
2652 |
|
2653 |
# Find related forgive credit |
2654 |
my $refunds = $overdue->credits( |
2655 |
{ |
2656 |
credit_type_code => 'FORGIVEN', |
2657 |
itemnumber => $item, |
2658 |
status => [ { '!=' => 'VOID' }, undef ] |
2659 |
}, |
2660 |
{ order_by => { '-desc' => 'date' }, rows => 1 } |
2661 |
); |
2662 |
return 0 unless $refunds->count; # no warning, there's just nothing to fix |
2663 |
|
2664 |
# Revert the forgive credit |
2665 |
my $refund = $refunds->next; |
2666 |
return $refund->void(); |
2667 |
} |
2668 |
); |
2669 |
|
2670 |
return $result; |
2671 |
} |
2672 |
|
2562 |
=head2 _GetCircControlBranch |
2673 |
=head2 _GetCircControlBranch |
2563 |
|
2674 |
|
2564 |
my $circ_control_branch = _GetCircControlBranch($iteminfos, $borrower); |
2675 |
my $circ_control_branch = _GetCircControlBranch($iteminfos, $borrower); |