Lines 812-821
sub GetReserveStatus {
Link Here
|
812 |
|
812 |
|
813 |
($status, $reserve, $all_reserves) = &CheckReserves($itemnumber); |
813 |
($status, $reserve, $all_reserves) = &CheckReserves($itemnumber); |
814 |
($status, $reserve, $all_reserves) = &CheckReserves(undef, $barcode); |
814 |
($status, $reserve, $all_reserves) = &CheckReserves(undef, $barcode); |
|
|
815 |
($status, $reserve, $all_reserves) = &CheckReserves($itemnumber,undef,$lookahead); |
815 |
|
816 |
|
816 |
Find a book in the reserves. |
817 |
Find a book in the reserves. |
817 |
|
818 |
|
818 |
C<$itemnumber> is the book's item number. |
819 |
C<$itemnumber> is the book's item number. |
|
|
820 |
C<$lookahead> is the number of days to look in advance for future reserves. |
819 |
|
821 |
|
820 |
As I understand it, C<&CheckReserves> looks for the given item in the |
822 |
As I understand it, C<&CheckReserves> looks for the given item in the |
821 |
reserves. If it is found, that's a match, and C<$status> is set to |
823 |
reserves. If it is found, that's a match, and C<$status> is set to |
Lines 836-842
table in the Koha database.
Link Here
|
836 |
=cut |
838 |
=cut |
837 |
|
839 |
|
838 |
sub CheckReserves { |
840 |
sub CheckReserves { |
839 |
my ( $item, $barcode ) = @_; |
841 |
my ( $item, $barcode, $lookahead_days) = @_; |
840 |
my $dbh = C4::Context->dbh; |
842 |
my $dbh = C4::Context->dbh; |
841 |
my $sth; |
843 |
my $sth; |
842 |
my $select; |
844 |
my $select; |
Lines 883-889
sub CheckReserves {
Link Here
|
883 |
return ( '' ) if ( $notforloan_per_item > 0 ) or $notforloan_per_itemtype; |
885 |
return ( '' ) if ( $notforloan_per_item > 0 ) or $notforloan_per_itemtype; |
884 |
|
886 |
|
885 |
# Find this item in the reserves |
887 |
# Find this item in the reserves |
886 |
my @reserves = _Findgroupreserve( $bibitem, $biblio, $itemnumber ); |
888 |
my @reserves = _Findgroupreserve( $bibitem, $biblio, $itemnumber, $lookahead_days); |
887 |
|
889 |
|
888 |
# $priority and $highest are used to find the most important item |
890 |
# $priority and $highest are used to find the most important item |
889 |
# in the list returned by &_Findgroupreserve. (The lower $priority, |
891 |
# in the list returned by &_Findgroupreserve. (The lower $priority, |
Lines 1706-1716
sub _FixPriority {
Link Here
|
1706 |
|
1708 |
|
1707 |
=head2 _Findgroupreserve |
1709 |
=head2 _Findgroupreserve |
1708 |
|
1710 |
|
1709 |
@results = &_Findgroupreserve($biblioitemnumber, $biblionumber, $itemnumber); |
1711 |
@results = &_Findgroupreserve($biblioitemnumber, $biblionumber, $itemnumber, $lookahead); |
1710 |
|
1712 |
|
1711 |
Looks for an item-specific match first, then for a title-level match, returning the |
1713 |
Looks for an item-specific match first, then for a title-level match, returning the |
1712 |
first match found. If neither, then we look for a 3rd kind of match based on |
1714 |
first match found. If neither, then we look for a 3rd kind of match based on |
1713 |
reserve constraints. |
1715 |
reserve constraints. |
|
|
1716 |
Lookahead is the number of days to look in advance. |
1714 |
|
1717 |
|
1715 |
TODO: add more explanation about reserve constraints |
1718 |
TODO: add more explanation about reserve constraints |
1716 |
|
1719 |
|
Lines 1722-1728
C<biblioitemnumber>.
Link Here
|
1722 |
=cut |
1725 |
=cut |
1723 |
|
1726 |
|
1724 |
sub _Findgroupreserve { |
1727 |
sub _Findgroupreserve { |
1725 |
my ( $bibitem, $biblio, $itemnumber ) = @_; |
1728 |
my ( $bibitem, $biblio, $itemnumber, $lookahead) = @_; |
1726 |
my $dbh = C4::Context->dbh; |
1729 |
my $dbh = C4::Context->dbh; |
1727 |
|
1730 |
|
1728 |
# TODO: consolidate at least the SELECT portion of the first 2 queries to a common $select var. |
1731 |
# TODO: consolidate at least the SELECT portion of the first 2 queries to a common $select var. |
Lines 1747-1757
sub _Findgroupreserve {
Link Here
|
1747 |
AND priority > 0 |
1750 |
AND priority > 0 |
1748 |
AND item_level_request = 1 |
1751 |
AND item_level_request = 1 |
1749 |
AND itemnumber = ? |
1752 |
AND itemnumber = ? |
1750 |
AND reservedate <= CURRENT_DATE() |
1753 |
AND reservedate <= DATE_ADD(NOW(),INTERVAL ? DAY) |
1751 |
AND suspend = 0 |
1754 |
AND suspend = 0 |
1752 |
/; |
1755 |
/; |
1753 |
my $sth = $dbh->prepare($item_level_target_query); |
1756 |
my $sth = $dbh->prepare($item_level_target_query); |
1754 |
$sth->execute($itemnumber); |
1757 |
$sth->execute($itemnumber, $lookahead||0); |
1755 |
my @results; |
1758 |
my @results; |
1756 |
if ( my $data = $sth->fetchrow_hashref ) { |
1759 |
if ( my $data = $sth->fetchrow_hashref ) { |
1757 |
push( @results, $data ); |
1760 |
push( @results, $data ); |
Lines 1778-1788
sub _Findgroupreserve {
Link Here
|
1778 |
AND priority > 0 |
1781 |
AND priority > 0 |
1779 |
AND item_level_request = 0 |
1782 |
AND item_level_request = 0 |
1780 |
AND hold_fill_targets.itemnumber = ? |
1783 |
AND hold_fill_targets.itemnumber = ? |
1781 |
AND reservedate <= CURRENT_DATE() |
1784 |
AND reservedate <= DATE_ADD(NOW(),INTERVAL ? DAY) |
1782 |
AND suspend = 0 |
1785 |
AND suspend = 0 |
1783 |
/; |
1786 |
/; |
1784 |
$sth = $dbh->prepare($title_level_target_query); |
1787 |
$sth = $dbh->prepare($title_level_target_query); |
1785 |
$sth->execute($itemnumber); |
1788 |
$sth->execute($itemnumber, $lookahead||0); |
1786 |
@results = (); |
1789 |
@results = (); |
1787 |
if ( my $data = $sth->fetchrow_hashref ) { |
1790 |
if ( my $data = $sth->fetchrow_hashref ) { |
1788 |
push( @results, $data ); |
1791 |
push( @results, $data ); |
Lines 1810-1820
sub _Findgroupreserve {
Link Here
|
1810 |
AND reserves.reservedate = reserveconstraints.reservedate ) |
1813 |
AND reserves.reservedate = reserveconstraints.reservedate ) |
1811 |
OR reserves.constrainttype='a' ) |
1814 |
OR reserves.constrainttype='a' ) |
1812 |
AND (reserves.itemnumber IS NULL OR reserves.itemnumber = ?) |
1815 |
AND (reserves.itemnumber IS NULL OR reserves.itemnumber = ?) |
1813 |
AND reserves.reservedate <= CURRENT_DATE() |
1816 |
AND reserves.reservedate <= DATE_ADD(NOW(),INTERVAL ? DAY) |
1814 |
AND suspend = 0 |
1817 |
AND suspend = 0 |
1815 |
/; |
1818 |
/; |
1816 |
$sth = $dbh->prepare($query); |
1819 |
$sth = $dbh->prepare($query); |
1817 |
$sth->execute( $biblio, $bibitem, $itemnumber ); |
1820 |
$sth->execute( $biblio, $bibitem, $itemnumber, $lookahead||0); |
1818 |
@results = (); |
1821 |
@results = (); |
1819 |
while ( my $data = $sth->fetchrow_hashref ) { |
1822 |
while ( my $data = $sth->fetchrow_hashref ) { |
1820 |
push( @results, $data ); |
1823 |
push( @results, $data ); |