use Koha::Illrequests;
use Koha::Items;
use Koha::Patrons;
-use Koha::Patron::Debarments qw( DelUniqueDebarment GetDebarments );
+use Koha::Patron::Debarments qw( DelUniqueDebarment GetDebarments AddUniqueDebarment );
use Koha::Database;
use Koha::Libraries;
use Koha::Account::Lines;
my ($barcode, $filter) = @_;
my $branch = C4::Context::mybranch();
$filter = C4::Context->preference('itemBarcodeInputFilter') unless $filter;
- ($barcode) = Koha::Plugins->call_recursive('item_barcode_transform', $barcode );
+ Koha::Plugins->call('item_barcode_transform', \$barcode );
$filter or return $barcode; # ensure filter is defined, else return untouched barcode
if ($filter eq 'whitespace') {
$barcode =~ s/\s//g;
## check for high holds decreasing loan period
if ( C4::Context->preference('decreaseLoanHighHolds') ) {
- my $check = checkHighHolds( $item_unblessed, $patron_unblessed );
+ my $check = checkHighHolds( $item_object, $patron );
if ( $check->{exceeded} ) {
if ($override_high_holds) {
=cut
sub checkHighHolds {
- my ( $item, $borrower ) = @_;
- my $branchcode = _GetCircControlBranch( $item, $borrower );
- my $item_object = Koha::Items->find( $item->{itemnumber} );
+ my ( $item, $patron ) = @_;
+ my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed );
my $return_data = {
exceeded => 0,
due_date => undef,
};
- my $holds = Koha::Holds->search( { biblionumber => $item->{'biblionumber'} } );
+ my $holds = Koha::Holds->search( { biblionumber => $item->biblionumber } );
if ( $holds->count() ) {
$return_data->{outstanding} = $holds->count();
}
# Remove any items that are not holdable for this patron
- @items = grep { CanItemBeReserved( $borrower->{borrowernumber}, $_->itemnumber, undef, { ignore_found_holds => 1 } )->{status} eq 'OK' } @items;
+ @items = grep { CanItemBeReserved( $patron , $_, undef, { ignore_found_holds => 1 } )->{status} eq 'OK' } @items;
my $items_count = scalar @items;
my $issuedate = dt_from_string();
- my $itype = $item_object->effective_itemtype;
+ my $itype = $item->effective_itemtype;
my $daysmode = Koha::CirculationRules->get_effective_daysmode(
{
- categorycode => $borrower->{categorycode},
+ categorycode => $patron->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 $orig_due = C4::Circulation::CalcDateDue( $issuedate, $itype, $branchcode, $patron->unblessed );
my $rule = Koha::CirculationRules->get_effective_rule(
{
- categorycode => $borrower->{categorycode},
- itemtype => $item_object->effective_itemtype,
+ categorycode => $patron->categorycode,
+ itemtype => $item->effective_itemtype,
branchcode => $branchcode,
rule_name => 'decreaseloanholds',
}
if ($item_was_lost) {
$messages->{'WasLost'} = 1;
unless ( C4::Context->preference("BlockReturnOfLostItems") ) {
- $messages->{'LostItemFeeRefunded'} = $updated_item->{_refunded};
- $messages->{'LostItemFeeRestored'} = $updated_item->{_restored};
+ $messages->{'LostItemFeeRefunded'} = 1 if $updated_item->{_refunded};
+ $messages->{'LostItemFeeRestored'} = 1 if $updated_item->{_restored};
if ( $updated_item->{_charge} ) {
$issue //= Koha::Old::Checkouts->search(
branchcode => $branchcode,
issue => $issue
});
+ return ( 0, $auto_renew ) if $auto_renew =~ 'auto_too_soon' && $cron;
+ # cron wants 'too_soon' over 'on_reserve' for performance and to avoid
+ # extra notices being sent. Cron also implies no override
return ( 0, $auto_renew ) if $auto_renew =~ 'auto_account_expired';
return ( 0, $auto_renew ) if $auto_renew =~ 'auto_too_late';
return ( 0, $auto_renew ) if $auto_renew =~ 'auto_too_much_oweing';
next if IsItemOnHoldAndFound( $item->itemnumber );
while ( my $patron = $patrons->next ) {
next unless IsAvailableForItemLevelRequest($item, $patron);
- next unless CanItemBeReserved($patron->borrowernumber,$item->itemnumber,undef,{ignore_hold_counts=>1})->{status} eq 'OK';
+ next unless CanItemBeReserved($patron,$item,undef,{ignore_hold_counts=>1})->{status} eq 'OK';
push @reservable, $item->itemnumber;
if (@reservable >= @borrowernumbers) {
$resfound = 0;
}
}
}
- if( $cron ) { #The cron wants to return 'too_soon' over 'on_reserve'
- return ( 0, $auto_renew ) if $auto_renew =~ 'too_soon';#$auto_renew ne "no" && $auto_renew ne "ok";
- return ( 0, "on_reserve" ) if $resfound; # '' when no hold was found
- } else { # For other purposes we want 'on_reserve' before 'too_soon'
- return ( 0, "on_reserve" ) if $resfound; # '' when no hold was found
- return ( 0, $auto_renew ) if $auto_renew =~ 'too_soon';#$auto_renew ne "no" && $auto_renew ne "ok";
+
+ return ( 0, "on_reserve" ) if $resfound; # '' when no hold was found
+ return ( 0, $auto_renew ) if $auto_renew =~ 'too_soon';#$auto_renew ne "no" && $auto_renew ne "ok";
+ if ( GetSoonestRenewDate($borrowernumber, $itemnumber) > dt_from_string() ){
+ return (0, "too_soon") unless $override_limit;
}
return ( 0, "auto_renew" ) if $auto_renew eq "ok" && !$override_limit; # 0 if auto-renewal should not succeed
);
my $now = dt_from_string;
- return $now unless $issuing_rule;
if ( defined $issuing_rule->{norenewalbefore}
and $issuing_rule->{norenewalbefore} ne "" )
$soonestrenewal->truncate( to => 'day' );
}
return $soonestrenewal if $now < $soonestrenewal;
+ } elsif ( $itemissue->auto_renew && $patron->autorenew_checkouts ) {
+ # Checkouts with auto-renewing fall back to due date
+ my $soonestrenewal = dt_from_string( $itemissue->date_due );
+ if ( C4::Context->preference('NoRenewalBeforePrecision') eq 'date'
+ and $issuing_rule->{lengthunit} eq 'days' )
+ {
+ $soonestrenewal->truncate( to => 'day' );
+ }
+ return $soonestrenewal;
}
return $now;
}
branches => $branch,
};
+ # TODO: Currently, we need to pass an issue_id as identifier for old_issues, but still an itemnumber for issues.
+ # See C4::Letters:: _parseletter_sth
if( $type eq 'CHECKIN' ){
$tables->{old_issues} = $issue->issue_id;
} else {
my $branchcode = $params->{branchcode};
my $issue = $params->{issue};
+ return "no" unless $issue->auto_renew && $patron->autorenew_checkouts;
+
my $issuing_rule = Koha::CirculationRules->get_effective_rules(
{
categorycode => $patron->categorycode,
}
);
- if ( $issue->auto_renew && $patron->autorenew_checkouts ) {
-
- if ( $patron->category->effective_BlockExpiredPatronOpacActions and $patron->is_expired ) {
- return 'auto_account_expired';
- }
+ if ( $patron->category->effective_BlockExpiredPatronOpacActions and $patron->is_expired ) {
+ return 'auto_account_expired';
+ }
- if ( defined $issuing_rule->{no_auto_renewal_after}
- and $issuing_rule->{no_auto_renewal_after} ne "" ) {
- # Get issue_date and add no_auto_renewal_after
- # If this is greater than today, it's too late for renewal.
- my $maximum_renewal_date = dt_from_string($issue->issuedate, 'sql');
- $maximum_renewal_date->add(
- $issuing_rule->{lengthunit} => $issuing_rule->{no_auto_renewal_after}
- );
- my $now = dt_from_string;
- if ( $now >= $maximum_renewal_date ) {
- return "auto_too_late";
- }
+ if ( defined $issuing_rule->{no_auto_renewal_after}
+ and $issuing_rule->{no_auto_renewal_after} ne "" ) {
+ # Get issue_date and add no_auto_renewal_after
+ # If this is greater than today, it's too late for renewal.
+ my $maximum_renewal_date = dt_from_string($issue->issuedate, 'sql');
+ $maximum_renewal_date->add(
+ $issuing_rule->{lengthunit} => $issuing_rule->{no_auto_renewal_after}
+ );
+ my $now = dt_from_string;
+ if ( $now >= $maximum_renewal_date ) {
+ return "auto_too_late";
}
- if ( defined $issuing_rule->{no_auto_renewal_after_hard_limit}
- and $issuing_rule->{no_auto_renewal_after_hard_limit} ne "" ) {
- # If no_auto_renewal_after_hard_limit is >= today, it's also too late for renewal
- if ( dt_from_string >= dt_from_string( $issuing_rule->{no_auto_renewal_after_hard_limit} ) ) {
- return "auto_too_late";
- }
+ }
+ if ( defined $issuing_rule->{no_auto_renewal_after_hard_limit}
+ and $issuing_rule->{no_auto_renewal_after_hard_limit} ne "" ) {
+ # If no_auto_renewal_after_hard_limit is >= today, it's also too late for renewal
+ if ( dt_from_string >= dt_from_string( $issuing_rule->{no_auto_renewal_after_hard_limit} ) ) {
+ return "auto_too_late";
}
+ }
- if ( C4::Context->preference('OPACFineNoRenewalsBlockAutoRenew') ) {
- my $fine_no_renewals = C4::Context->preference("OPACFineNoRenewals");
- my $amountoutstanding =
- C4::Context->preference("OPACFineNoRenewalsIncludeCredit")
- ? $patron->account->balance
- : $patron->account->outstanding_debits->total_outstanding;
- if ( $amountoutstanding and $amountoutstanding > $fine_no_renewals ) {
- return "auto_too_much_oweing";
- }
+ if ( C4::Context->preference('OPACFineNoRenewalsBlockAutoRenew') ) {
+ my $fine_no_renewals = C4::Context->preference("OPACFineNoRenewals");
+ my $amountoutstanding =
+ C4::Context->preference("OPACFineNoRenewalsIncludeCredit")
+ ? $patron->account->balance
+ : $patron->account->outstanding_debits->total_outstanding;
+ if ( $amountoutstanding and $amountoutstanding > $fine_no_renewals ) {
+ return "auto_too_much_oweing";
}
}
if ( defined $issuing_rule->{norenewalbefore}
- and $issuing_rule->{norenewalbefore} ne "" )
- {
-
- # Calculate soonest renewal by subtracting 'No renewal before' from due date
- my $soonestrenewal = dt_from_string( $issue->date_due, 'sql' )->subtract(
- $issuing_rule->{lengthunit} => $issuing_rule->{norenewalbefore} );
-
- # Depending on syspref reset the exact time, only check the date
- if ( C4::Context->preference('NoRenewalBeforePrecision') eq 'date'
- and $issuing_rule->{lengthunit} eq 'days' )
- {
- $soonestrenewal->truncate( to => 'day' );
- }
-
- if ( $soonestrenewal > dt_from_string() )
- {
- return ($issue->auto_renew && $patron->autorenew_checkouts) ? "auto_too_soon" : "too_soon";
- }
- elsif ( $issue->auto_renew && $patron->autorenew_checkouts ) {
+ and $issuing_rule->{norenewalbefore} ne "" ) {
+ if ( GetSoonestRenewDate($patron->id, $item->id) > dt_from_string()) {
+ return "auto_too_soon";
+ } else {
return "ok";
}
}
# Fallback for automatic renewals:
# If norenewalbefore is undef, don't renew before due date.
- if ( $issue->auto_renew && $patron->autorenew_checkouts ) {
- my $now = dt_from_string;
- if ( $now >= dt_from_string( $issue->date_due, 'sql' ) ){
- return "ok";
- } else {
- return "auto_too_soon";
- }
+ my $now = dt_from_string;
+ if ( $now >= dt_from_string( $issue->date_due, 'sql' ) ){
+ return "ok";
+ } else {
+ return "auto_too_soon";
}
- return "no";
}
sub _item_denied_renewal {