use strict;
#use warnings; FIXME - Bug 2505
use DateTime;
+use POSIX qw( floor );
use Koha::DateUtils;
use C4::Context;
use C4::Stats;
my $override_high_holds = $params->{override_high_holds} || 0;
my $item = GetItem(undef, $barcode );
+ # MANDATORY CHECKS - unless item exists, nothing else matters
+ unless ( $item ) {
+ $issuingimpossible{UNKNOWN_BARCODE} = 1;
+ }
+ return ( \%issuingimpossible, \%needsconfirmation ) if %issuingimpossible;
+
my $issue = Koha::Checkouts->find( { itemnumber => $item->{itemnumber} } );
- my $biblioitem = GetBiblioItemData($item->{biblioitemnumber});
+ my $biblio = Koha::Biblios->find( $item->{biblionumber} );
+ my $biblioitem = $biblio->biblioitem;
my $effective_itemtype = $item->{itype}; # GetItem deals with that
my $dbh = C4::Context->dbh;
my $patron_unblessed = $patron->unblessed;
- # MANDATORY CHECKS - unless item exists, nothing else matters
- unless ( $item->{barcode} ) {
- $issuingimpossible{UNKNOWN_BARCODE} = 1;
- }
- return ( \%issuingimpossible, \%needsconfirmation ) if %issuingimpossible;
-
#
# DUE DATE is OK ? -- should already have checked.
#
if (C4::Context->preference('item-level_itypes')){
# this should probably be a subroutine
my $sth = $dbh->prepare("SELECT notforloan FROM itemtypes WHERE itemtype = ?");
- $sth->execute($item->{'itemtype'});
+ $sth->execute($effective_itemtype);
my $notforloan=$sth->fetchrow_hashref();
if ($notforloan->{'notforloan'}) {
if (!C4::Context->preference("AllowNotForLoanOverride")) {
}
}
}
- elsif ($biblioitem->{'notforloan'} == 1){
- if (!C4::Context->preference("AllowNotForLoanOverride")) {
- $issuingimpossible{NOT_FOR_LOAN} = 1;
- $issuingimpossible{itemtype_notforloan} = $effective_itemtype;
- } else {
- $needsconfirmation{NOT_FOR_LOAN_FORCING} = 1;
- $needsconfirmation{itemtype_notforloan} = $effective_itemtype;
+ else {
+ my $itemtype = Koha::ItemTypes->find($biblioitem->itemtype);
+ if ( $itemtype and $itemtype->notforloan == 1){
+ if (!C4::Context->preference("AllowNotForLoanOverride")) {
+ $issuingimpossible{NOT_FOR_LOAN} = 1;
+ $issuingimpossible{itemtype_notforloan} = $effective_itemtype;
+ } else {
+ $needsconfirmation{NOT_FOR_LOAN_FORCING} = 1;
+ $needsconfirmation{itemtype_notforloan} = $effective_itemtype;
+ }
}
}
}
}
## CHECK AGE RESTRICTION
- my $agerestriction = $biblioitem->{'agerestriction'};
+ my $agerestriction = $biblioitem->agerestriction;
my ($restriction_age, $daysToAgeRestriction) = GetAgeRestriction( $agerestriction, $patron->unblessed );
if ( $daysToAgeRestriction && $daysToAgeRestriction > 0 ) {
if ( C4::Context->preference('AgeRestrictionOverride') ) {
}
# Remove any items that are not holdable for this patron
- @items = grep { CanItemBeReserved( $borrower->{borrowernumber}, $_->itemnumber ) eq 'OK' } @items;
+ @items = grep { CanItemBeReserved( $borrower->{borrowernumber}, $_->itemnumber )->{status} eq 'OK' } @items;
my $items_count = scalar @items;
AddReturn( $item->{'barcode'}, C4::Context->userenv->{'branch'} );
}
- MoveReserve( $item->{'itemnumber'}, $borrower->{'borrowernumber'}, $cancelreserve );
+ C4::Reserves::MoveReserve( $item->{'itemnumber'}, $borrower->{'borrowernumber'}, $cancelreserve );
# Starting process for transfer job (checking transfert and validate it if we have one)
my ($datesent) = GetTransfers( $item->{'itemnumber'} );
datelastborrowed => DateTime->now( time_zone => C4::Context->tz() )->ymd(),
},
$item->{'biblionumber'},
- $item->{'itemnumber'}
+ $item->{'itemnumber'},
+ { log_action => 0 }
);
ModDateLastSeen( $item->{'itemnumber'} );
# If it costs to borrow this book, charge it to the patron's account.
my ( $charge, $itemtype ) = GetIssuingCharges( $item->{'itemnumber'}, $borrower->{'borrowernumber'} );
if ( $charge > 0 ) {
- AddIssuingCharge( $item->{'itemnumber'}, $borrower->{'borrowernumber'}, $charge );
+ AddIssuingCharge( $issue, $charge );
$item->{'charge'} = $charge;
}
. Dumper($issue->unblessed) . "\n";
} else {
$messages->{'NotIssued'} = $barcode;
+ ModItem({ onloan => undef }, $item->{biblionumber}, $item->{itemnumber}) if defined $item->{onloan};
# even though item is not on loan, it may still be transferred; therefore, get current branch info
$doreturn = 0;
# No issue, no borrowernumber. ONLY if $doreturn, *might* you have a $borrower later.
$item->{location} = $item->{permanent_location};
}
- ModItem( $item, $item->{'biblionumber'}, $item->{'itemnumber'} );
+ ModItem( $item, $item->{'biblionumber'}, $item->{'itemnumber'}, { log_action => 0 } );
}
# full item data, but no borrowernumber or checkout info (no issue)
foreach my $key ( keys %$rules ) {
if ( $item->{notforloan} eq $key ) {
$messages->{'NotForLoanStatusUpdated'} = { from => $item->{notforloan}, to => $rules->{$key} };
- ModItem( { notforloan => $rules->{$key} }, undef, $itemnumber );
+ ModItem( { notforloan => $rules->{$key} }, undef, $itemnumber, { log_action => 0 } );
last;
}
}
}
- ModItem({ onloan => undef }, $item->{biblionumber}, $item->{'itemnumber'});
+ ModItem( { onloan => undef }, $item->{biblionumber}, $item->{itemnumber}, { log_action => 0 } );
}
# the holdingbranch is updated if the document is returned to another location.
UpdateHoldingbranch($branch, $item->{'itemnumber'});
$item->{'holdingbranch'} = $branch; # update item data holdingbranch too
}
- ModDateLastSeen( $item->{'itemnumber'} );
+
+ my $leave_item_lost = C4::Context->preference("BlockReturnOfLostItems") ? 1 : 0;
+ ModDateLastSeen( $item->{itemnumber}, $leave_item_lost );
# check if we have a transfer for this document
my ($datesent,$frombranch,$tobranch) = GetTransfers( $item->{'itemnumber'} );
if ( $issue and $issue->is_overdue ) {
# fix fine days
+ $today = dt_from_string($return_date) if $return_date;
$today = $dropboxdate if $dropbox;
my ($debardate,$reminder) = _debar_user_on_return( $patron_unblessed, $item, dt_from_string($issue->date_due), $today );
if ($reminder){
# And finally delete the issue
$issue->delete;
- ModItem( { 'onloan' => undef }, undef, $itemnumber );
+ ModItem( { 'onloan' => undef }, undef, $itemnumber, { log_action => 0 } );
if ( C4::Context->preference('StoreLastBorrower') ) {
my $item = Koha::Items->find( $itemnumber );
}
}
- my $new_debar_dt =
- $return_date->clone()->add_duration( $suspension_days );
+ if ( $issuing_rule->suspension_chargeperiod > 1 ) {
+ # No need to / 1 and do not consider / 0
+ $suspension_days = DateTime::Duration->new(
+ days => floor( $suspension_days->in_units('days') / $issuing_rule->suspension_chargeperiod )
+ );
+ }
+
+ my $new_debar_dt;
+ # Use the calendar or not to calculate the debarment date
+ if ( C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed' ) {
+ my $calendar = Koha::Calendar->new(
+ branchcode => $branchcode,
+ days_mode => 'Calendar'
+ );
+ $new_debar_dt = $calendar->addDate( $return_date, $suspension_days );
+ }
+ else {
+ $new_debar_dt = $return_date->clone()->add_duration($suspension_days);
+ }
Koha::Patron::Debarments::AddUniqueDebarment({
borrowernumber => $borrower->{borrowernumber},
description => "Item Returned " . $item_id,
account_type => 'CR',
offset_type => 'Lost Item Return',
- accounlines => [$accountline],
+ lines => [$accountline],
}
);
- ModItem( { paidfor => '' }, undef, $itemnumber );
+ ModItem( { paidfor => '' }, undef, $itemnumber, { log_action => 0 } );
return $credit_id;
}
# Update the renewal count on the item, and tell zebra to reindex
$renews = $item->{renewals} + 1;
- ModItem({ renewals => $renews, onloan => $datedue->strftime('%Y-%m-%d %H:%M')}, $item->{biblionumber}, $itemnumber);
+ ModItem( { renewals => $renews, onloan => $datedue->strftime('%Y-%m-%d %H:%M')}, $item->{biblionumber}, $itemnumber, { log_action => 0 } );
# Charge a new rental fee, if applicable?
my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber );
=head2 AddIssuingCharge
- &AddIssuingCharge( $itemno, $borrowernumber, $charge )
+ &AddIssuingCharge( $checkout, $charge )
=cut
sub AddIssuingCharge {
- my ( $itemnumber, $borrowernumber, $charge ) = @_;
+ my ( $checkout, $charge ) = @_;
- my $nextaccntno = getnextacctno($borrowernumber);
+ # FIXME What if checkout does not exist?
+
+ my $nextaccntno = getnextacctno($checkout->borrowernumber);
my $manager_id = 0;
$manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
my $accountline = Koha::Account::Line->new(
{
- borrowernumber => $borrowernumber,
- itemnumber => $itemnumber,
+ borrowernumber => $checkout->borrowernumber,
+ itemnumber => $checkout->itemnumber,
+ issue_id => $checkout->issue_id,
accountno => $nextaccntno,
amount => $charge,
amountoutstanding => $charge,
Code is either an itemtype or collection doe depending on the pref BranchTransferLimitsType
+Deprecated in favor of Koha::Item::Transfer::Limits->find/search and
+Koha::Item->can_be_transferred.
+
=cut
sub IsBranchTransferAllowed {
$code is either itemtype or collection code depending on what the pref BranchTransferLimitsType is set to.
+Deprecated in favor of Koha::Item::Transfer::Limit->new.
+
=cut
sub CreateBranchTransferLimit {
number of limits deleted, 0e0 if no limits were deleted, or undef if
no arguments are supplied.
+Deprecated in favor of Koha::Item::Transfer::Limits->search({
+ fromBranch => $fromBranch
+ })->delete.
+
=cut
sub DeleteBranchTransferLimits {
sub LostItem{
- my ($itemnumber, $mark_returned) = @_;
+ my ($itemnumber, $mark_lost_from, $force_mark_returned) = @_;
- $mark_returned //= C4::Context->preference('MarkLostItemsAsReturned');
+ unless ( $mark_lost_from ) {
+ # Temporary check to avoid regressions
+ die q|LostItem called without $mark_lost_from, check the API.|;
+ }
+
+ my $mark_returned;
+ if ( $force_mark_returned ) {
+ $mark_returned = 1;
+ } else {
+ my $pref = C4::Context->preference('MarkLostItemsAsReturned') // q{};
+ $mark_returned = ( $pref =~ m|$mark_lost_from| );
+ }
my $dbh = C4::Context->dbh();
my $sth=$dbh->prepare("SELECT issues.*,items.*,biblio.title
ModItem(
{ renewals => 0, onloan => undef },
$issue->{'biblionumber'},
- $itemnumber
+ $itemnumber,
+ { log_action => 0 }
);
return "Success.";
} else {