$needsconfirmation{'resborrowernumber'} = $patron->borrowernumber;
$needsconfirmation{'resbranchcode'} = $res->{branchcode};
$needsconfirmation{'reswaitingdate'} = $res->{'waitingdate'};
+ $needsconfirmation{'reserve_id'} = $res->{reserve_id};
}
elsif ( $restype eq "Reserved" ) {
# The item is on reserve for someone else.
$needsconfirmation{'resborrowernumber'} = $patron->borrowernumber;
$needsconfirmation{'resbranchcode'} = $patron->branchcode;
$needsconfirmation{'resreservedate'} = $res->{reservedate};
+ $needsconfirmation{'reserve_id'} = $res->{reserve_id};
}
}
}
}
# Remove any items that are not holdable for this patron
- @items = grep { CanItemBeReserved( $borrower->{borrowernumber}, $_->itemnumber )->{status} eq 'OK' } @items;
+ @items = grep { CanItemBeReserved( $borrower->{borrowernumber}, $_->itemnumber, undef, { ignore_found_holds => 1 } )->{status} eq 'OK' } @items;
my $items_count = scalar @items;
my $issuedate = dt_from_string();
- my $calendar = Koha::Calendar->new( branchcode => $branchcode );
-
my $itype = $item_object->effective_itemtype;
+ my $daysmode = Koha::CirculationRules->get_effective_daysmode(
+ {
+ categorycode => $borrower->{categorycode},
+ itemtype => $itype,
+ branchcode => $branchcode,
+ }
+ );
+ my $calendar = Koha::Calendar->new( branchcode => $branchcode, days_mode => $daysmode );
+
my $orig_due = C4::Circulation::CalcDateDue( $issuedate, $itype, $branchcode, $borrower );
my $decreaseLoanHighHoldsDuration = C4::Context->preference('decreaseLoanHighHoldsDuration');
## If item was lost, it has now been found, reverse any list item charges if necessary.
if ( $item_object->itemlost ) {
+ my $refund = 1;
+ my $no_refund_after_days = C4::Context->preference('NoRefundOnLostReturnedItemsAge');
+ if ($no_refund_after_days) {
+ my $today = dt_from_string();
+ my $lost_age_in_days =
+ dt_from_string( $item_object->itemlost_on )
+ ->delta_days($today)
+ ->in_units('days');
+
+ $refund = 0 unless ( $lost_age_in_days < $no_refund_after_days );
+ }
+
if (
- Koha::RefundLostItemFeeRules->should_refund(
+ $refund
+ && Koha::RefundLostItemFeeRules->should_refund(
{
- current_branch => C4::Context->userenv->{branch},
- item_home_branch => $item_object->homebranch,
+ current_branch => C4::Context->userenv->{branch},
+ item_home_branch => $item_object->homebranch,
item_holding_branch => $item_object->holdingbranch,
}
)
"UPDATE branchtransfers SET datearrived = now() WHERE itemnumber= ? AND datearrived IS NULL"
);
$sth->execute( $item->itemnumber );
- # if we have a reservation with valid transfer, we can set it's status to 'W'
- C4::Reserves::ModReserveStatus($item->itemnumber, 'W');
} else {
$messages->{'WrongTransfer'} = $tobranch;
$messages->{'WrongTransferItem'} = $item->itemnumber;
if ( $item->itemlost ) {
$messages->{'WasLost'} = 1;
unless ( C4::Context->preference("BlockReturnOfLostItems") ) {
+ my $refund = 1;
+ my $no_refund_after_days = C4::Context->preference('NoRefundOnLostReturnedItemsAge');
+ if ($no_refund_after_days) {
+ my $today = dt_from_string();
+ my $lost_age_in_days =
+ dt_from_string( $item->itemlost_on )
+ ->delta_days($today)
+ ->in_units('days');
+
+ $refund = 0 unless ( $lost_age_in_days < $no_refund_after_days );
+ }
+
if (
+ $refund &&
Koha::RefundLostItemFeeRules->should_refund(
{
current_branch => C4::Context->userenv->{branch},
# fix up the overdues in accounts...
if ($borrowernumber) {
my $fix = _FixOverduesOnReturn( $borrowernumber, $item->itemnumber, $exemptfine, 'RETURNED' );
- defined($fix) or warn "_FixOverduesOnReturn($borrowernumber, $item->itemnumber...) failed!"; # zero is OK, check defined
+ defined($fix) or warn "_FixOverduesOnReturn($borrowernumber, ".$item->itemnumber."...) failed!"; # zero is OK, check defined
- if ( $issue and $issue->is_overdue ) {
+ if ( $issue and $issue->is_overdue($return_date) ) {
# fix fine days
my ($debardate,$reminder) = _debar_user_on_return( $patron_unblessed, $item->unblessed, dt_from_string($issue->date_due), $return_date );
if ($reminder){
type => $stat_type,
itemnumber => $itemnumber,
itemtype => $itemtype,
+ location => $item->location,
borrowernumber => $borrowernumber,
ccode => $item->ccode,
});
if C4::Context->preference("ReturnLog");
}
- # Remove any OVERDUES related debarment if the borrower has no overdues
- if ( $borrowernumber
- && $patron->debarred
- && C4::Context->preference('AutoRemoveOverduesRestrictions')
- && !Koha::Patrons->find( $borrowernumber )->has_overdues
- && @{ GetDebarments({ borrowernumber => $borrowernumber, type => 'OVERDUES' }) }
- ) {
- DelUniqueDebarment({ borrowernumber => $borrowernumber, type => 'OVERDUES' });
- }
-
# Check if this item belongs to a biblio record that is attached to an
# ILL request, if it is we need to update the ILL request's status
if (C4::Context->preference('CirculateILL')) {
# FIXME Improve the return value and handle it from callers
$schema->txn_do(sub {
+ my $patron = Koha::Patrons->find( $borrowernumber );
+
# Update the returndate value
if ( $returndate ) {
$issue->returndate( $returndate )->store->discard_changes; # update and refetch
if ( C4::Context->preference('StoreLastBorrower') ) {
my $item = Koha::Items->find( $itemnumber );
- my $patron = Koha::Patrons->find( $borrowernumber );
$item->last_returned_by( $patron );
}
+
+ # Remove any OVERDUES related debarment if the borrower has no overdues
+ if ( C4::Context->preference('AutoRemoveOverduesRestrictions')
+ && $patron->debarred
+ && !$patron->has_overdues
+ && @{ GetDebarments({ borrowernumber => $borrowernumber, type => 'OVERDUES' }) }
+ ) {
+ DelUniqueDebarment({ borrowernumber => $borrowernumber, type => 'OVERDUES' });
+ }
+
});
return $issue_id;
return 0 unless $accountlines->count; # no warning, there's just nothing to fix
my $accountline = $accountlines->next;
- if ($exemptfine) {
- my $amountoutstanding = $accountline->amountoutstanding;
-
- return if $amountoutstanding <= 0;
+ my $payments = $accountline->credits;
+ my $amountoutstanding = $accountline->amountoutstanding;
+ if ( $accountline->amount == 0 && $payments->count == 0 ) {
+ $accountline->delete;
+ } elsif ($exemptfine && ($amountoutstanding != 0)) {
my $account = Koha::Account->new({patron_id => $borrowernumber});
my $credit = $account->add_credit(
{
$credit->apply({ debits => [ $accountline ], offset_type => 'Forgiven' });
- $accountline->status('FORGIVEN');
-
if (C4::Context->preference("FinesLog")) {
&logaction("FINES", 'MODIFY',$borrowernumber,"Overdue forgiven: item $item");
}
+
+ $accountline->status('FORGIVEN');
+ $accountline->store();
} else {
$accountline->status($status);
- }
+ $accountline->store();
- return $accountline->store();
+ }
}
);
$newdatedue = CalcDateDue($startdate,$itemtype,$branchcode,$borrower);
this function calculates the due date given the start date and configured circulation rules,
-checking against the holidays calendar as per the 'useDaysMode' syspref.
+checking against the holidays calendar as per the daysmode circulation rule.
C<$startdate> = DateTime object representing start date of loan period (assumed to be today)
C<$itemtype> = itemtype code of item in question
C<$branch> = location whose calendar to use
}
+ my $daysmode = Koha::CirculationRules->get_effective_daysmode(
+ {
+ categorycode => $borrower->{categorycode},
+ itemtype => $itemtype,
+ branchcode => $branch,
+ }
+ );
+
# calculate the datedue as normal
- if ( C4::Context->preference('useDaysMode') eq 'Days' )
+ if ( $daysmode eq 'Days' )
{ # ignoring calendar
if ( $loanlength->{lengthunit} eq 'hours' ) {
$datedue->add( hours => $loanlength->{$length_key} );
else { # days
$dur = DateTime::Duration->new( days => $loanlength->{$length_key});
}
- my $calendar = Koha::Calendar->new( branchcode => $branch );
+ my $calendar = Koha::Calendar->new( branchcode => $branch, days_mode => $daysmode );
$datedue = $calendar->addDate( $datedue, $dur, $loanlength->{lengthunit} );
if ($loanlength->{lengthunit} eq 'days') {
$datedue->set_hour(23);
$datedue = $expiry_dt->clone->set_time_zone( C4::Context->tz );
}
}
- if ( C4::Context->preference('useDaysMode') ne 'Days' ) {
- my $calendar = Koha::Calendar->new( branchcode => $branch );
+ if ( $daysmode ne 'Days' ) {
+ my $calendar = Koha::Calendar->new( branchcode => $branch, days_mode => $daysmode );
if ( $calendar->is_holiday($datedue) ) {
# Don't return on a closed day
$datedue = $calendar->prev_open_days( $datedue, 1 );