|
Lines 121-127
BEGIN {
Link Here
|
| 121 |
&CanItemBeReserved |
121 |
&CanItemBeReserved |
| 122 |
&CanReserveBeCanceledFromOpac |
122 |
&CanReserveBeCanceledFromOpac |
| 123 |
&CancelExpiredReserves |
123 |
&CancelExpiredReserves |
| 124 |
|
|
|
| 125 |
&AutoUnsuspendReserves |
124 |
&AutoUnsuspendReserves |
| 126 |
|
125 |
|
| 127 |
&IsAvailableForItemLevelRequest |
126 |
&IsAvailableForItemLevelRequest |
|
Lines 195-206
sub AddReserve {
Link Here
|
| 195 |
|
194 |
|
| 196 |
#The reserve-object doesn't exist yet in DB, so we must supply what information we have to GetLastPickupDate() so it can do it's work. |
195 |
#The reserve-object doesn't exist yet in DB, so we must supply what information we have to GetLastPickupDate() so it can do it's work. |
| 197 |
my $reserve = {borrowernumber => $borrowernumber, waitingdate => $waitingdate, branchcode => $branch}; |
196 |
my $reserve = {borrowernumber => $borrowernumber, waitingdate => $waitingdate, branchcode => $branch}; |
| 198 |
$lastpickupdate = GetLastPickupDate( $reserve, $item ); |
197 |
my $patron = Koha::Patrons->find( {borrowernumber => $borrowernumber} ); |
|
|
198 |
$lastpickupdate = GetLastPickupDate( $reserve, $item, $patron ); |
| 199 |
} |
199 |
} |
| 200 |
|
|
|
| 201 |
# Don't add itemtype limit if specific item is selected |
200 |
# Don't add itemtype limit if specific item is selected |
| 202 |
$itemtype = undef if $checkitem; |
201 |
$itemtype = undef if $checkitem; |
| 203 |
|
|
|
| 204 |
# updates take place here |
202 |
# updates take place here |
| 205 |
my $hold = Koha::Hold->new( |
203 |
my $hold = Koha::Hold->new( |
| 206 |
{ |
204 |
{ |
|
Lines 219-225
sub AddReserve {
Link Here
|
| 219 |
} |
217 |
} |
| 220 |
)->store(); |
218 |
)->store(); |
| 221 |
$hold->set_waiting() if $found eq 'W'; |
219 |
$hold->set_waiting() if $found eq 'W'; |
| 222 |
|
|
|
| 223 |
logaction( 'HOLDS', 'CREATE', $hold->id, Dumper($hold->unblessed) ) |
220 |
logaction( 'HOLDS', 'CREATE', $hold->id, Dumper($hold->unblessed) ) |
| 224 |
if C4::Context->preference('HoldsLog'); |
221 |
if C4::Context->preference('HoldsLog'); |
| 225 |
|
222 |
|
|
Lines 647-652
sub GetReserveStatus {
Link Here
|
| 647 |
return ''; # empty string here will remove need for checking undef, or less log lines |
644 |
return ''; # empty string here will remove need for checking undef, or less log lines |
| 648 |
} |
645 |
} |
| 649 |
|
646 |
|
|
|
647 |
|
| 648 |
=head2 GetLastPickupDate |
| 649 |
|
| 650 |
my $lastpickupdate = GetLastPickupDate($reserve, $item); |
| 651 |
my $lastpickupdate = GetLastPickupDate($reserve, $item, $borrower); |
| 652 |
my $lastpickupdate = GetLastPickupDate(undef, $item); |
| 653 |
|
| 654 |
Gets the last pickup date from the issuingrules for the given reserves-row and sets the |
| 655 |
$reserve->{lastpickupdate}.-value. |
| 656 |
|
| 657 |
If the reserves-row is not passed, function tries to figure it out from the item-row. |
| 658 |
Calculating the last pickup date respects Calendar holidays and skips to the next open day. |
| 659 |
If the issuingrule's holdspickupwait is 0 or less, means that the lastpickupdate-feature |
| 660 |
is disabled for this kind of material. |
| 661 |
|
| 662 |
@PARAM1 koha.reserves-row |
| 663 |
@PARAM2 koha.items-row, If the reserve is not given, an item must be given to be |
| 664 |
able to find a reservation |
| 665 |
@PARAM3 koha.borrowers-row, OPTIONAL |
| 666 |
RETURNS DateTime, depicting the last pickup date. |
| 667 |
OR undef if there is an error or if the issuingrules disable this feature for this material. |
| 668 |
|
| 669 |
=cut |
| 670 |
|
| 671 |
sub GetLastPickupDate { |
| 672 |
my ($reserve, $item, $borrower) = @_; |
| 673 |
##Verify parameters |
| 674 |
if ( not defined $reserve and not defined $item ) { |
| 675 |
warn "C4::Reserves::GetMaxPickupDate(), is called without a reserve and an item"; |
| 676 |
return; |
| 677 |
} |
| 678 |
if ( defined $reserve and not defined $item ) { |
| 679 |
$item = C4::Items::GetItem( $reserve->{itemnumber} ); |
| 680 |
} |
| 681 |
|
| 682 |
unless ( defined $borrower) { |
| 683 |
my $borrower = Koha::Patrons->find( $reserve->{borrowernumber} ); |
| 684 |
$borrower = $borrower->unblessed; |
| 685 |
} |
| 686 |
|
| 687 |
unless ( defined $reserve ) { |
| 688 |
my $reserve = GetReservesFromItemnumber( $item->{itemnumber} ); |
| 689 |
} |
| 690 |
my $date = $reserve->{waitingdate}; |
| 691 |
unless ( $date ) { #It is possible that a reserve is just caught and it doesn't have a waitingdate yet. |
| 692 |
$date = DateTime->now( time_zone => C4::Context->tz() ); #So default to NOW() |
| 693 |
} |
| 694 |
else { |
| 695 |
$date = (ref $reserve->{waitingdate} eq 'DateTime') ? $reserve->{waitingdate} : dt_from_string($reserve->{waitingdate}); |
| 696 |
} |
| 697 |
##Get churning the LastPickupDate |
| 698 |
|
| 699 |
# Get the controlbranch |
| 700 |
my $controlbranch = GetReservesControlBranch( $item, $borrower ); |
| 701 |
my $hbr = C4::Context->preference('HomeOrHoldingBranch') || "homebranch"; |
| 702 |
my $branchcode = "*"; |
| 703 |
if ( $controlbranch eq "ItemHomeLibrary" ) { |
| 704 |
$branchcode = $item->{$hbr}; |
| 705 |
} elsif ( $controlbranch eq "PatronLibrary" ) { |
| 706 |
$branchcode = $borrower->branchcode; |
| 707 |
} |
| 708 |
warn 'getlastpickup'; |
| 709 |
warn $branchcode; |
| 710 |
warn $borrower->{'categorycode'}; |
| 711 |
warn $item->{itype}; |
| 712 |
my $issuingrule = Koha::IssuingRules->get_effective_issuing_rule({ |
| 713 |
branchcode => $branchcode, |
| 714 |
categorycode => $borrower->{'categorycode'}, |
| 715 |
itemtype => $item->{itype}, |
| 716 |
}); |
| 717 |
|
| 718 |
my $reservebranch; |
| 719 |
if ($reserve->{'branchcode'}) { |
| 720 |
$reservebranch = $reserve->{'branchcode'}; |
| 721 |
} else { |
| 722 |
$reservebranch = $reserve->branchcode; |
| 723 |
} |
| 724 |
if ( defined($issuingrule) && defined $issuingrule->holdspickupwait && $issuingrule->holdspickupwait > 0 ) { #If holdspickupwait is <= 0, it means this feature is disabled for this type of material. |
| 725 |
$date->add( days => $issuingrule->holdspickupwait ); |
| 726 |
my $calendar = Koha::Calendar->new( branchcode => $reservebranch ); |
| 727 |
my $is_holiday = $calendar->is_holiday( $date ); |
| 728 |
while ( $is_holiday ) { |
| 729 |
$date->add( days => 1 ); |
| 730 |
$is_holiday = $calendar->is_holiday( $date ); |
| 731 |
} |
| 732 |
$reserve->{lastpickupdate} = $date->ymd(); |
| 733 |
return $date; |
| 734 |
} |
| 735 |
#Without explicitly setting the return value undef, the lastpickupdate-column is |
| 736 |
# set as 0000-00-00 instead of NULL in DBD::MySQL. |
| 737 |
#This causes this hold to always expire any lastpickupdate check, |
| 738 |
## effectively canceling it as soon as cancel_expired_holds.pl is ran. |
| 739 |
##This is exactly the opposite of disabling the autoexpire feature. |
| 740 |
##So please let me explicitly return undef, because Perl cant always handle everything. |
| 741 |
delete $reserve->{lastpickupdate}; |
| 742 |
return undef; |
| 743 |
} |
| 744 |
|
| 650 |
=head2 CheckReserves |
745 |
=head2 CheckReserves |
| 651 |
|
746 |
|
| 652 |
($status, $reserve, $all_reserves) = &CheckReserves($itemnumber); |
747 |
($status, $reserve, $all_reserves) = &CheckReserves($itemnumber); |
|
Lines 993-999
sub ModReserveFill {
Link Here
|
| 993 |
|
1088 |
|
| 994 |
=head2 ModReserveStatus |
1089 |
=head2 ModReserveStatus |
| 995 |
|
1090 |
|
| 996 |
&ModReserveStatus($itemnumber, $newstatus); |
1091 |
&ModReserveStatus($itemnumber, $newstatus, $holdtype); |
| 997 |
|
1092 |
|
| 998 |
Update the reserve status for the active (priority=0) reserve. |
1093 |
Update the reserve status for the active (priority=0) reserve. |
| 999 |
|
1094 |
|
|
Lines 1004-1015
$newstatus is the new status.
Link Here
|
| 1004 |
=cut |
1099 |
=cut |
| 1005 |
|
1100 |
|
| 1006 |
sub ModReserveStatus { |
1101 |
sub ModReserveStatus { |
| 1007 |
|
|
|
| 1008 |
#first : check if we have a reservation for this item . |
1102 |
#first : check if we have a reservation for this item . |
| 1009 |
my ($itemnumber, $newstatus) = @_; |
1103 |
my ($itemnumber, $newstatus) = @_; |
| 1010 |
my $dbh = C4::Context->dbh; |
1104 |
my $dbh = C4::Context->dbh; |
| 1011 |
|
1105 |
|
| 1012 |
my $now = dt_from_string; |
1106 |
my $now = dt_from_string; |
|
|
1107 |
|
| 1013 |
my $reserve = $dbh->selectrow_hashref(q{ |
1108 |
my $reserve = $dbh->selectrow_hashref(q{ |
| 1014 |
SELECT * |
1109 |
SELECT * |
| 1015 |
FROM reserves |
1110 |
FROM reserves |
|
Lines 1017-1026
sub ModReserveStatus {
Link Here
|
| 1017 |
AND found IS NULL |
1112 |
AND found IS NULL |
| 1018 |
AND priority = 0 |
1113 |
AND priority = 0 |
| 1019 |
}, {}, $itemnumber); |
1114 |
}, {}, $itemnumber); |
| 1020 |
return unless $reserve; |
|
|
| 1021 |
|
1115 |
|
| 1022 |
my $lastpickupdate = GetLastPickupDate( $reserve ); |
1116 |
return unless $reserve; |
|
|
1117 |
my $borrower = Koha::Patrons->find( $reserve->{borrowernumber} ); |
| 1118 |
$borrower = $borrower->unblessed; |
| 1119 |
my $item = C4::Items::GetItem( $reserve->{itemnumber} ); |
| 1023 |
|
1120 |
|
|
|
1121 |
my $lastpickupdate = GetLastPickupDate( $reserve, $item, $borrower ); |
| 1024 |
my $query = q{ |
1122 |
my $query = q{ |
| 1025 |
UPDATE reserves |
1123 |
UPDATE reserves |
| 1026 |
SET found = ?, |
1124 |
SET found = ?, |
|
Lines 1086-1091
sub ModReserveAffect {
Link Here
|
| 1086 |
|
1184 |
|
| 1087 |
_FixPriority( { biblionumber => $biblionumber } ); |
1185 |
_FixPriority( { biblionumber => $biblionumber } ); |
| 1088 |
|
1186 |
|
|
|
1187 |
my $item = C4::Items::GetItem( $itemnumber ); |
| 1188 |
my $borrower = Koha::Patrons->find( $borrowernumber ); |
| 1189 |
$borrower = $borrower->unblessed; |
| 1190 |
my $lastpickupdate = GetLastPickupDate( $hold, $item, $borrower ); |
| 1191 |
warn $lastpickupdate; |
| 1192 |
my $query = " |
| 1193 |
UPDATE reserves |
| 1194 |
SET lastpickupdate = ? |
| 1195 |
WHERE borrowernumber = ? |
| 1196 |
AND itemnumber = ? |
| 1197 |
"; |
| 1198 |
$sth = $dbh->prepare($query); |
| 1199 |
$sth->execute( $lastpickupdate, $borrowernumber,$itemnumber); |
| 1200 |
|
| 1089 |
if ( C4::Context->preference("ReturnToShelvingCart") ) { |
1201 |
if ( C4::Context->preference("ReturnToShelvingCart") ) { |
| 1090 |
CartToShelf($itemnumber); |
1202 |
CartToShelf($itemnumber); |
| 1091 |
} |
1203 |
} |