Lines 751-760
sub GetReserveStatus {
Link Here
|
751 |
|
751 |
|
752 |
($status, $reserve, $all_reserves) = &CheckReserves($itemnumber); |
752 |
($status, $reserve, $all_reserves) = &CheckReserves($itemnumber); |
753 |
($status, $reserve, $all_reserves) = &CheckReserves(undef, $barcode); |
753 |
($status, $reserve, $all_reserves) = &CheckReserves(undef, $barcode); |
|
|
754 |
($status, $reserve, $all_reserves) = &CheckReserves($itemnumber,undef,$lookahead); |
754 |
|
755 |
|
755 |
Find a book in the reserves. |
756 |
Find a book in the reserves. |
756 |
|
757 |
|
757 |
C<$itemnumber> is the book's item number. |
758 |
C<$itemnumber> is the book's item number. |
|
|
759 |
C<$lookahead> is the number of days to look in advance for future reserves. |
758 |
|
760 |
|
759 |
As I understand it, C<&CheckReserves> looks for the given item in the |
761 |
As I understand it, C<&CheckReserves> looks for the given item in the |
760 |
reserves. If it is found, that's a match, and C<$status> is set to |
762 |
reserves. If it is found, that's a match, and C<$status> is set to |
Lines 775-781
table in the Koha database.
Link Here
|
775 |
=cut |
777 |
=cut |
776 |
|
778 |
|
777 |
sub CheckReserves { |
779 |
sub CheckReserves { |
778 |
my ( $item, $barcode ) = @_; |
780 |
my ( $item, $barcode, $lookahead_days) = @_; |
779 |
my $dbh = C4::Context->dbh; |
781 |
my $dbh = C4::Context->dbh; |
780 |
my $sth; |
782 |
my $sth; |
781 |
my $select; |
783 |
my $select; |
Lines 822-828
sub CheckReserves {
Link Here
|
822 |
return ( '' ) if ( $notforloan_per_item > 0 ) or $notforloan_per_itemtype; |
824 |
return ( '' ) if ( $notforloan_per_item > 0 ) or $notforloan_per_itemtype; |
823 |
|
825 |
|
824 |
# Find this item in the reserves |
826 |
# Find this item in the reserves |
825 |
my @reserves = _Findgroupreserve( $bibitem, $biblio, $itemnumber ); |
827 |
my @reserves = _Findgroupreserve( $bibitem, $biblio, $itemnumber, $lookahead_days); |
826 |
|
828 |
|
827 |
# $priority and $highest are used to find the most important item |
829 |
# $priority and $highest are used to find the most important item |
828 |
# in the list returned by &_Findgroupreserve. (The lower $priority, |
830 |
# in the list returned by &_Findgroupreserve. (The lower $priority, |
Lines 1704-1714
sub _FixPriority {
Link Here
|
1704 |
|
1706 |
|
1705 |
=head2 _Findgroupreserve |
1707 |
=head2 _Findgroupreserve |
1706 |
|
1708 |
|
1707 |
@results = &_Findgroupreserve($biblioitemnumber, $biblionumber, $itemnumber); |
1709 |
@results = &_Findgroupreserve($biblioitemnumber, $biblionumber, $itemnumber, $lookahead); |
1708 |
|
1710 |
|
1709 |
Looks for an item-specific match first, then for a title-level match, returning the |
1711 |
Looks for an item-specific match first, then for a title-level match, returning the |
1710 |
first match found. If neither, then we look for a 3rd kind of match based on |
1712 |
first match found. If neither, then we look for a 3rd kind of match based on |
1711 |
reserve constraints. |
1713 |
reserve constraints. |
|
|
1714 |
Lookahead is the number of days to look in advance. |
1712 |
|
1715 |
|
1713 |
TODO: add more explanation about reserve constraints |
1716 |
TODO: add more explanation about reserve constraints |
1714 |
|
1717 |
|
Lines 1720-1726
C<biblioitemnumber>.
Link Here
|
1720 |
=cut |
1723 |
=cut |
1721 |
|
1724 |
|
1722 |
sub _Findgroupreserve { |
1725 |
sub _Findgroupreserve { |
1723 |
my ( $bibitem, $biblio, $itemnumber ) = @_; |
1726 |
my ( $bibitem, $biblio, $itemnumber, $lookahead) = @_; |
1724 |
my $dbh = C4::Context->dbh; |
1727 |
my $dbh = C4::Context->dbh; |
1725 |
|
1728 |
|
1726 |
# TODO: consolidate at least the SELECT portion of the first 2 queries to a common $select var. |
1729 |
# TODO: consolidate at least the SELECT portion of the first 2 queries to a common $select var. |
Lines 1744-1754
sub _Findgroupreserve {
Link Here
|
1744 |
AND priority > 0 |
1747 |
AND priority > 0 |
1745 |
AND item_level_request = 1 |
1748 |
AND item_level_request = 1 |
1746 |
AND itemnumber = ? |
1749 |
AND itemnumber = ? |
1747 |
AND reservedate <= CURRENT_DATE() |
1750 |
AND reservedate <= DATE_ADD(NOW(),INTERVAL ? DAY) |
1748 |
AND suspend = 0 |
1751 |
AND suspend = 0 |
1749 |
/; |
1752 |
/; |
1750 |
my $sth = $dbh->prepare($item_level_target_query); |
1753 |
my $sth = $dbh->prepare($item_level_target_query); |
1751 |
$sth->execute($itemnumber); |
1754 |
$sth->execute($itemnumber, $lookahead||0); |
1752 |
my @results; |
1755 |
my @results; |
1753 |
if ( my $data = $sth->fetchrow_hashref ) { |
1756 |
if ( my $data = $sth->fetchrow_hashref ) { |
1754 |
push( @results, $data ); |
1757 |
push( @results, $data ); |
Lines 1775-1785
sub _Findgroupreserve {
Link Here
|
1775 |
AND priority > 0 |
1778 |
AND priority > 0 |
1776 |
AND item_level_request = 0 |
1779 |
AND item_level_request = 0 |
1777 |
AND hold_fill_targets.itemnumber = ? |
1780 |
AND hold_fill_targets.itemnumber = ? |
1778 |
AND reservedate <= CURRENT_DATE() |
1781 |
AND reservedate <= DATE_ADD(NOW(),INTERVAL ? DAY) |
1779 |
AND suspend = 0 |
1782 |
AND suspend = 0 |
1780 |
/; |
1783 |
/; |
1781 |
$sth = $dbh->prepare($title_level_target_query); |
1784 |
$sth = $dbh->prepare($title_level_target_query); |
1782 |
$sth->execute($itemnumber); |
1785 |
$sth->execute($itemnumber, $lookahead||0); |
1783 |
@results = (); |
1786 |
@results = (); |
1784 |
if ( my $data = $sth->fetchrow_hashref ) { |
1787 |
if ( my $data = $sth->fetchrow_hashref ) { |
1785 |
push( @results, $data ); |
1788 |
push( @results, $data ); |
Lines 1807-1817
sub _Findgroupreserve {
Link Here
|
1807 |
AND reserves.reservedate = reserveconstraints.reservedate ) |
1810 |
AND reserves.reservedate = reserveconstraints.reservedate ) |
1808 |
OR reserves.constrainttype='a' ) |
1811 |
OR reserves.constrainttype='a' ) |
1809 |
AND (reserves.itemnumber IS NULL OR reserves.itemnumber = ?) |
1812 |
AND (reserves.itemnumber IS NULL OR reserves.itemnumber = ?) |
1810 |
AND reserves.reservedate <= CURRENT_DATE() |
1813 |
AND reserves.reservedate <= DATE_ADD(NOW(),INTERVAL ? DAY) |
1811 |
AND suspend = 0 |
1814 |
AND suspend = 0 |
1812 |
/; |
1815 |
/; |
1813 |
$sth = $dbh->prepare($query); |
1816 |
$sth = $dbh->prepare($query); |
1814 |
$sth->execute( $biblio, $bibitem, $itemnumber ); |
1817 |
$sth->execute( $biblio, $bibitem, $itemnumber, $lookahead||0); |
1815 |
@results = (); |
1818 |
@results = (); |
1816 |
while ( my $data = $sth->fetchrow_hashref ) { |
1819 |
while ( my $data = $sth->fetchrow_hashref ) { |
1817 |
push( @results, $data ); |
1820 |
push( @results, $data ); |