to circulation.pl that differs from the barcode stored for the item.
For proper functioning of this filter, calling the function on the
correct barcode string (items.barcode) should return an unaltered barcode.
+Barcode is going to be automatically trimmed of leading/trailing whitespaces.
The optional $filter argument is to allow for testing or explicit
behavior that ignores the System Pref. Valid values are the same as the
#
sub barcodedecode {
my ($barcode, $filter) = @_;
+
+ return unless defined $barcode;
+
my $branch = C4::Context::mybranch();
+ $barcode =~ s/^\s+|\s+$//g;
$filter = C4::Context->preference('itemBarcodeInputFilter') unless $filter;
Koha::Plugins->call('item_barcode_transform', \$barcode );
$filter or return $barcode; # ensure filter is defined, else return untouched barcode
my $patron_unblessed = $patron->unblessed;
my $circ_library = Koha::Libraries->find( _GetCircControlBranch($item_unblessed, $patron_unblessed) );
- #
- # DUE DATE is OK ? -- should already have checked.
- #
- if ($duedate && ref $duedate ne 'DateTime') {
- $duedate = dt_from_string($duedate);
- }
- my $now = dt_from_string();
- unless ( $duedate ) {
- my $issuedate = $now->clone();
-
- $duedate = CalcDateDue( $issuedate, $effective_itemtype, $circ_library->branchcode, $patron_unblessed );
- # Offline circ calls AddIssue directly, doesn't run through here
- # So issuingimpossible should be ok.
+ my $now = dt_from_string();
+ $duedate ||= CalcDateDue( $now, $effective_itemtype, $circ_library->branchcode, $patron_unblessed );
+ if (DateTime->compare($duedate,$now) == -1 ) { # duedate cannot be before now
+ $needsconfirmation{INVALID_DATE} = output_pref($duedate);
}
my $fees = Koha::Charges::Fees->new(
}
);
- if ($duedate) {
- my $today = $now->clone();
- $today->truncate( to => 'minute');
- if (DateTime->compare($duedate,$today) == -1 ) { # duedate cannot be before now
- $needsconfirmation{INVALID_DATE} = output_pref($duedate);
- }
- } else {
- $issuingimpossible{INVALID_DATE} = output_pref($duedate);
- }
-
#
# BORROWER STATUS
#
my $orig_due = C4::Circulation::CalcDateDue( $issuedate, $itype, $branchcode, $patron->unblessed );
- my $rule = Koha::CirculationRules->get_effective_rule(
+ my $rule = Koha::CirculationRules->get_effective_rule_value(
{
categorycode => $patron->categorycode,
itemtype => $item->effective_itemtype,
);
my $duration;
- if ( defined($rule) && $rule->rule_value ne '' ){
+ if ( defined($rule) && $rule ne '' ){
# overrides decreaseLoanHighHoldsDuration syspref
- $duration = $rule->rule_value;
+ $duration = $rule;
} else {
$duration = C4::Context->preference('decreaseLoanHighHoldsDuration');
}
$datedue = CalcDateDue( $issuedate, $itype, $branchcode, $borrower );
}
+
+ # Check if we need to use an exact due date set by the ILL module
+ if ( C4::Context->preference('ILLModule') ) {
+ # Check if there is an ILL connected with the biblio of the item we are issuing
+ my $ill_request = Koha::Illrequests->search({
+ biblio_id => $item_object->biblionumber,
+ borrowernumber => $borrower->{'borrowernumber'},
+ completed => undef,
+ due_date => { '!=', undef },
+ })->next;
+
+ if ( $ill_request and length( $ill_request->due_date ) > 0 ) {
+ my $ill_dt = dt_from_string( $ill_request->due_date );
+ $ill_dt->set_hour(23);
+ $ill_dt->set_minute(59);
+ $datedue = $ill_dt;
+ }
+ }
+
$datedue->truncate( to => 'minute' );
my $patron = Koha::Patrons->find( $borrower );
# If automatic renewal wasn't selected while issuing, set the value according to the issuing rule.
unless ($auto_renew) {
- my $rule = Koha::CirculationRules->get_effective_rule(
+ my $rule = Koha::CirculationRules->get_effective_rule_value(
{
categorycode => $borrower->{categorycode},
itemtype => $item_object->effective_itemtype,
}
);
- $auto_renew = $rule->rule_value if $rule;
+ $auto_renew = $rule if defined $rule && $rule ne '';
}
my $issue_attributes = {
{
biblio_ids => [ $item_object->biblionumber ]
}
- );
+ ) if C4::Context->preference('RealTimeHoldsQueue');
}
}
return $issue;
(!defined $item->location && $update_loc_rules->{_ALL_} ne "")
) {
$messages->{'ItemLocationUpdated'} = { from => $item->location, to => $update_loc_rules->{_ALL_} };
- $item->location($update_loc_rules->{_ALL_})->store({ skip_record_index => 1, skip_holds_queue => 1});
+ $item->location($update_loc_rules->{_ALL_})->store({ log_action => 0, skip_record_index => 1, skip_holds_queue => 1});
}
}
else {
if ( $update_loc_rules->{$key} eq '_BLANK_') { $update_loc_rules->{$key} = '' ;}
if ( ($item->location eq $key && $item->location ne $update_loc_rules->{$key}) || ($key eq '_BLANK_' && $item->location eq '' && $update_loc_rules->{$key} ne '') ) {
$messages->{'ItemLocationUpdated'} = { from => $item->location, to => $update_loc_rules->{$key} };
- $item->location($update_loc_rules->{$key})->store({ skip_record_index => 1, skip_holds_queue => 1});
+ $item->location($update_loc_rules->{$key})->store({ log_action => 0, skip_record_index => 1, skip_holds_queue => 1});
last;
}
}
# the holdingbranch is updated if the document is returned to another location.
# this is always done regardless of whether the item was on loan or not
if ($item->holdingbranch ne $branch) {
- $item->holdingbranch($branch)->store({ skip_record_index => 1, skip_holds_queue => 1 });
+ $item->holdingbranch($branch)->store({ log_action => 0, skip_record_index => 1, skip_holds_queue => 1 });
}
my $item_was_lost = $item->itemlost;
}
}
+ # Check for bundle status
+ if ( $item->in_bundle ) {
+ my $host = $item->bundle_host;
+ $messages->{InBundle} = $host;
+ }
+
my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX });
$indexer->index_records( $item->biblionumber, "specialUpdate", "biblioserver" );
{
biblio_ids => [ $item->biblionumber ]
}
- );
+ ) if C4::Context->preference('RealTimeHoldsQueue');
}
return ( $doreturn, $messages, $issue, ( $patron ? $patron->unblessed : {} ));
);
return ( 0, "too_many" )
- if not $issuing_rule->{renewalsallowed} or $issuing_rule->{renewalsallowed} <= $issue->renewals;
+ if not $issuing_rule->{renewalsallowed} or $issuing_rule->{renewalsallowed} <= $issue->renewals_count;
return ( 0, "too_unseen" )
if C4::Context->preference('UnseenRenewals') &&
- $issuing_rule->{unseen_renewals_allowed} &&
+ looks_like_number($issuing_rule->{unseen_renewals_allowed}) &&
$issuing_rule->{unseen_renewals_allowed} <= $issue->unseen_renewals;
my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing');
rule_name => 'unseen_renewals_allowed'
}
);
- if (!$seen && $rule && $rule->rule_value) {
+ if (!$seen && $rule && looks_like_number($rule->rule_value)) {
$unseen_renewals++;
} else {
# If the renewal is seen, unseen should revert to 0
# Update the issues record to have the new due date, and a new count
# of how many times it has been renewed.
- my $renews = ( $issue->renewals || 0 ) + 1;
- my $sth = $dbh->prepare("UPDATE issues SET date_due = ?, renewals = ?, unseen_renewals = ?, lastreneweddate = ? WHERE issue_id = ?");
+ my $renews = ( $issue->renewals_count || 0 ) + 1;
+ my $sth = $dbh->prepare("UPDATE issues SET date_due = ?, renewals_count = ?, unseen_renewals = ?, lastreneweddate = ? WHERE issue_id = ?");
eval{
$sth->execute( $datedue->strftime('%Y-%m-%d %H:%M'), $renews, $unseen_renewals, $lastreneweddate, $issue->issue_id );
DelUniqueDebarment({ borrowernumber => $borrowernumber, type => 'OVERDUES' });
}
+ # Add renewal record
+ my $renewal = Koha::Checkouts::Renewal->new(
+ {
+ checkout_id => $issue->issue_id,
+ renewer_id => C4::Context->userenv ? C4::Context->userenv->{'number'} : undef,
+ seen => $seen,
+ interface => C4::Context->interface
+ }
+ )->store();
+
# Add the renewal to stats
C4::Stats::UpdateStats(
{
);
$sth->execute( $bornum, $itemno );
my $data = $sth->fetchrow_hashref;
- $renewcount = $data->{'renewals'} if $data->{'renewals'};
+ $renewcount = $data->{'renewals_count'} if $data->{'renewals_count'};
$unseencount = $data->{'unseen_renewals'} if $data->{'unseen_renewals'};
# $item and $borrower should be calculated
my $branchcode = _GetCircControlBranch($item->unblessed, $patron->unblessed);
my $loanlength =
GetLoanLength( $borrower->{'categorycode'}, $itemtype, $branch );
- my $length_key = ( $isrenewal and defined $loanlength->{renewalperiod} )
+ my $length_key = ( $isrenewal and defined $loanlength->{renewalperiod} and $loanlength->{renewalperiod} ne q{} )
? qq{renewalperiod}
: qq{issuelength};
$itemnumber,
$operation->{timestamp},
);
- $item->renewals(0);
+ $item->renewals_count(0);
$item->onloan(undef);
$item->store({ log_action => 0 });
return "Success.";