Commit 7e886a7b authored by Benjamin Rokseth's avatar Benjamin Rokseth
Browse files

koha: make canItemFillHold check reservability and disallow certain item types

parent 9db4d965
......@@ -131,7 +131,7 @@ sub Checkin {
# HOLDS?
my $hold = $self->getPendingHold();
if ($hold) {
if ($hold and $self->canItemFillHold()) {
if ($hold->branchcode ne $self->{library}->branchcode) {
$self->{messages}->{NeedsTransfer} = $hold->branchcode;
}
......@@ -888,31 +888,19 @@ sub canItemBeReturned {
=cut
sub canItemFillHold {
my $self = shift;
# PREFS
# AllowRenewalIfOtherItemsAvailable
# item-level_itypes
# IndependentBranches
# canreservefromotherbranches
# AllowHoldsOnDamagedItems
# my $reservableItems = Koha::Items->search({
# "me.biblionumber" => $self->{item}->biblionumber,
# itemlost => 0,
# withdrawn => 0,
# notforloan => { "<=" => 0 },
# "reserves.found" => { "!=" => undef },
# },
# { join => "reserves" });
return $self->getPendingHoldsByBiblio->count > 0;
#my $reservable;
#try {
# my $it = Deichman::Item->new()->Get($self->{item}->itemnumber);
# $reservable = $it->reservableItemsCount() >= 1;
#} catch {
# warn $_;
#};
#return $reservable;
if ($self->{item}->itype =~ /10DLAAN|DAGSLAAN|TOUKESLAAN|UKESLAAN/) {
return;
}
my $reservable;
try {
my $it = Deichman::Item->new()->Get($self->{item}->itemnumber);
my ($available, $reserves) = $it->reservableItems();
$reservable = $available >= $reserves;
} catch {
warn $_;
};
return $reservable;
}
=head
get soonest renewal date from date and circ rule
......
......@@ -101,12 +101,12 @@ sub GetBiblioHolds {
return $self;
}
sub reservableItemsCount {
sub reservableItems {
my ($self) = @_;
return unless $self->{item};
my $dbh = $self->dbh;
my $q = "
SELECT available.total - reserves.total AS count
SELECT available.total AS available, reserves.total AS reserves
FROM
( SELECT SUM(1) AS total FROM items i
LEFT JOIN issues iss USING (itemnumber)
......@@ -118,14 +118,15 @@ sub reservableItemsCount {
AND i.deleted_on IS NULL
AND iss.issue_id IS NULL
AND bt.itemnumber IS NULL
AND i.itype NOT IN ('10DLAAN', 'DAGSLAAN', 'TOUKESLAAN', 'UKESLAAN')
) available
JOIN
( SELECT COALESCE(SUM(1), 0) AS total FROM reserves WHERE biblionumber = ? ) reserves
";
my $sth = $dbh->prepare($q);
$sth->execute($self->{item}->{biblionumber}, $self->{item}->{biblionumber}) or Deichman::Exception::Item->throw($dbh->errstr);
my ($count) = $sth->fetchrow_array();
return $count;
my ($available, $reserves) = $sth->fetchrow_array();
return ($available, $reserves);
}
sub MarkAsMaybeIPP {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment