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 |
_CalculateAndUpdateFine( |
1472 |
{ |
1473 |
issue => $issue, |
1474 |
item => $item_unblessed, |
1475 |
borrower => $borrower |
1476 |
} |
1477 |
); |
1478 |
_FixOverduesOnReturn( $borrower->{borrowernumber}, |
1479 |
$item_object->itemnumber, undef, 'RENEWED' ); |
1480 |
} |
1481 |
elsif ( $lostreturn_policy eq 'restore' ) { |
1482 |
_RestoreOverdueForLostAndFound( $item_object->itemnumber, |
1483 |
$borrower->{'borrowernumber'} ); |
1484 |
} |
1469 |
} |
1485 |
} |
1470 |
} |
1486 |
} |
1471 |
|
1487 |
|
Lines 2038-2055
sub AddReturn {
Link Here
|
2038 |
if ( $item->itemlost ) { |
2054 |
if ( $item->itemlost ) { |
2039 |
$messages->{'WasLost'} = 1; |
2055 |
$messages->{'WasLost'} = 1; |
2040 |
unless ( C4::Context->preference("BlockReturnOfLostItems") ) { |
2056 |
unless ( C4::Context->preference("BlockReturnOfLostItems") ) { |
2041 |
if ( |
2057 |
my $lostreturn_policy = |
2042 |
Koha::CirculationRules->get_lostreturn_policy( |
2058 |
Koha::CirculationRules->get_lostreturn_policy( |
2043 |
{ |
2059 |
{ |
2044 |
return_branch => C4::Context->userenv->{branch}, |
2060 |
return_branch => C4::Context->userenv->{branch}, |
2045 |
item => $item, |
2061 |
item => $item |
2046 |
} |
2062 |
} |
2047 |
) |
2063 |
); |
2048 |
) |
2064 |
|
2049 |
{ |
2065 |
if ($lostreturn_policy) { |
2050 |
_FixAccountForLostAndFound( $item->itemnumber, |
2066 |
_FixAccountForLostAndFound( $item->itemnumber, |
2051 |
$borrowernumber, $barcode ); |
2067 |
$borrowernumber, $barcode ); |
2052 |
$messages->{'LostItemFeeRefunded'} = 1; |
2068 |
$messages->{'LostItemFeeRefunded'} = 1; |
|
|
2069 |
|
2070 |
if ( $lostreturn_policy eq 'charge' ) { |
2071 |
_CalculateAndUpdateFine( |
2072 |
{ |
2073 |
issue => $issue, |
2074 |
item => $item->unblessed, |
2075 |
borrower => $patron_unblessed, |
2076 |
return_date => $return_date |
2077 |
} |
2078 |
); |
2079 |
$messages->{'LostItemFeeCharged'} = 1; |
2080 |
} |
2081 |
elsif ( $lostreturn_policy eq 'restore' ) { |
2082 |
_RestoreOverdueForLostAndFound( $item->itemnumber, |
2083 |
$borrowernumber ); |
2084 |
$messages->{'LostItemFeeRestored'} = 1; |
2085 |
} |
2053 |
} |
2086 |
} |
2054 |
} |
2087 |
} |
2055 |
} |
2088 |
} |
Lines 2454-2468
sub _FixOverduesOnReturn {
Link Here
|
2454 |
|
2487 |
|
2455 |
$credit->apply({ debits => [ $accountline ], offset_type => 'Forgiven' }); |
2488 |
$credit->apply({ debits => [ $accountline ], offset_type => 'Forgiven' }); |
2456 |
|
2489 |
|
2457 |
$accountline->status('FORGIVEN'); |
|
|
2458 |
|
2459 |
if (C4::Context->preference("FinesLog")) { |
2490 |
if (C4::Context->preference("FinesLog")) { |
2460 |
&logaction("FINES", 'MODIFY',$borrowernumber,"Overdue forgiven: item $item"); |
2491 |
&logaction("FINES", 'MODIFY',$borrowernumber,"Overdue forgiven: item $item"); |
2461 |
} |
2492 |
} |
2462 |
} else { |
|
|
2463 |
$accountline->status($status); |
2464 |
} |
2493 |
} |
2465 |
|
2494 |
|
|
|
2495 |
$accountline->status($status); |
2466 |
return $accountline->store(); |
2496 |
return $accountline->store(); |
2467 |
} |
2497 |
} |
2468 |
); |
2498 |
); |
Lines 2559-2564
sub _FixAccountForLostAndFound {
Link Here
|
2559 |
return ($credit) ? $credit->id : undef; |
2589 |
return ($credit) ? $credit->id : undef; |
2560 |
} |
2590 |
} |
2561 |
|
2591 |
|
|
|
2592 |
=head2 _RestoreOverdueForLostAndFound |
2593 |
|
2594 |
&_RestoreOverdueForLostAndFound($borrowernumber, $itemnumber ); |
2595 |
|
2596 |
C<$borrowernumber> borrowernumber |
2597 |
|
2598 |
C<$itemnumber> itemnumber |
2599 |
|
2600 |
Internal function |
2601 |
|
2602 |
=cut |
2603 |
|
2604 |
sub _RestoreOverdueForLostAndFound { |
2605 |
my ( $borrowernumber, $item ) = @_; |
2606 |
|
2607 |
unless( $borrowernumber ) { |
2608 |
warn "_RestoreOverdueForLostAndFound() not supplied valid borrowernumber"; |
2609 |
return; |
2610 |
} |
2611 |
unless( $item ) { |
2612 |
warn "_RestoreOverdueForLostAndFound() not supplied valid itemnumber"; |
2613 |
return; |
2614 |
} |
2615 |
|
2616 |
my $schema = Koha::Database->schema; |
2617 |
|
2618 |
my $result = $schema->txn_do( |
2619 |
sub { |
2620 |
# check for lost overdue fine |
2621 |
my $accountlines = Koha::Account::Lines->search( |
2622 |
{ |
2623 |
borrowernumber => $borrowernumber, |
2624 |
itemnumber => $item, |
2625 |
debit_type_code => 'OVERDUE', |
2626 |
status => 'LOST' |
2627 |
}, |
2628 |
{ |
2629 |
order_by => { '-desc' => 'date' }, |
2630 |
rows => 1 |
2631 |
} |
2632 |
); |
2633 |
return 0 unless $accountlines->count; # no warning, there's just nothing to fix |
2634 |
|
2635 |
# Update status of fine |
2636 |
my $overdue = $accountlines->next; |
2637 |
$overdue->status('RETURNED')->store(); |
2638 |
|
2639 |
# Find related forgive credit |
2640 |
my $refunds = $overdue->credits( |
2641 |
{ |
2642 |
credit_type_code => 'FORGIVEN', |
2643 |
itemnumber => $item, |
2644 |
status => [ { '!=' => 'VOID' }, undef ] |
2645 |
}, |
2646 |
{ order_by => { '-desc' => 'date' }, rows => 1 } |
2647 |
); |
2648 |
return 0 unless $refunds->count; # no warning, there's just nothing to fix |
2649 |
|
2650 |
# Revert the forgive credit |
2651 |
my $refund = $refunds->next; |
2652 |
return $refund->void(); |
2653 |
} |
2654 |
); |
2655 |
|
2656 |
return $result; |
2657 |
} |
2658 |
|
2562 |
=head2 _GetCircControlBranch |
2659 |
=head2 _GetCircControlBranch |
2563 |
|
2660 |
|
2564 |
my $circ_control_branch = _GetCircControlBranch($iteminfos, $borrower); |
2661 |
my $circ_control_branch = _GetCircControlBranch($iteminfos, $borrower); |