Commit a0924c74 authored by Benjamin Rokseth's avatar Benjamin Rokseth Committed by Benjamin Rokseth
Browse files

koha: Add Deichman::Item->reservableItemsCount

parent a70e9e01
...@@ -11,6 +11,7 @@ use DateTime; ...@@ -11,6 +11,7 @@ use DateTime;
use DateTime::Duration; use DateTime::Duration;
use DateTime::Format::Strptime; use DateTime::Format::Strptime;
use Deichman::Item;
use Koha::Holds; use Koha::Holds;
use Koha::Items; use Koha::Items;
use Koha::Item; use Koha::Item;
...@@ -798,7 +799,6 @@ sub canItemBeRenewed { ...@@ -798,7 +799,6 @@ sub canItemBeRenewed {
if ($override) { if ($override) {
return $self; return $self;
} }
# Too few items to fill holds means item cannot be renewed # Too few items to fill holds means item cannot be renewed
if (not $self->canItemFillHold()) { if (not $self->canItemFillHold()) {
$self->{error} = Core::Exception::Circulation::RenewError->new("on_hold"); $self->{error} = Core::Exception::Circulation::RenewError->new("on_hold");
...@@ -867,6 +867,7 @@ sub canItemBeReturned { ...@@ -867,6 +867,7 @@ sub canItemBeReturned {
=head =head
Check if item can fill a pending hold Check if item can fill a pending hold
reservable means: reservable means:
- item is not on item level hold
- item not found (Waiting or in Transfer) - item not found (Waiting or in Transfer)
- item not lost, withdrawn - item not lost, withdrawn
- item notforloan not code > 0 - item notforloan not code > 0
...@@ -885,21 +886,28 @@ sub canItemFillHold { ...@@ -885,21 +886,28 @@ sub canItemFillHold {
# IndependentBranches # IndependentBranches
# canreservefromotherbranches # canreservefromotherbranches
# AllowHoldsOnDamagedItems # AllowHoldsOnDamagedItems
# my $reservableItems = Koha::Items->search({
my $reservableItems = Koha::Items->search({ # "me.biblionumber" => $self->{item}->biblionumber,
"me.biblionumber" => $self->{item}->biblionumber, # itemlost => 0,
itemlost => 0, # withdrawn => 0,
withdrawn => 0, # notforloan => { "<=" => 0 },
notforloan => { "<=" => 0 }, # "reserves.found" => { "!=" => undef },
"reserves.found" => { "!=" => undef }, # },
}, # { join => "reserves" });
{ join => "reserves" });
# if ($reservableItems->count < $self->getPendingHoldsByBiblio->count) {
if ($reservableItems->count < $self->getPendingHoldsByBiblio->count) { # return 0;
return 0; # } else {
} else { # return 1;
return 1; # }
} my $reservable;
try {
my $it = Deichman::Item->new()->Get($self->{item}->itemnumber);
$reservable = $it->reservableItemsCount() >= 1;
} catch {
warn $_;
};
return $reservable;
} }
=head =head
get soonest renewal date from date and circ rule get soonest renewal date from date and circ rule
......
...@@ -101,6 +101,33 @@ sub GetBiblioHolds { ...@@ -101,6 +101,33 @@ sub GetBiblioHolds {
return $self; return $self;
} }
sub reservableItemsCount {
my ($self) = @_;
return unless $self->{item};
my $dbh = $self->dbh;
my $q = "
SELECT available.total - reserves.total AS count
FROM
( SELECT SUM(1) AS total FROM items i
LEFT JOIN issues iss USING (itemnumber)
LEFT JOIN branchtransfers bt ON (bt.itemnumber = i.itemnumber AND bt.datearrived IS NULL)
LEFT JOIN borrowers b ON (b.borrowernumber=iss.borrowernumber)
WHERE i.biblionumber = ?
AND i.itemlost = 0 AND i.withdrawn = 0
AND i.notforloan <= 0
AND i.deleted_on IS NULL
AND iss.issue_id IS NULL
AND bt.itemnumber IS NULL
) 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;
}
sub MarkAsMaybeIPP { sub MarkAsMaybeIPP {
my ($self) = @_; my ($self) = @_;
my $dbh = $self->dbh; my $dbh = $self->dbh;
......
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