|
Lines 120-126
BEGIN {
Link Here
|
| 120 |
&CanItemBeReserved |
120 |
&CanItemBeReserved |
| 121 |
&CanReserveBeCanceledFromOpac |
121 |
&CanReserveBeCanceledFromOpac |
| 122 |
&CancelExpiredReserves |
122 |
&CancelExpiredReserves |
| 123 |
|
|
|
| 124 |
&AutoUnsuspendReserves |
123 |
&AutoUnsuspendReserves |
| 125 |
|
124 |
|
| 126 |
&IsAvailableForItemLevelRequest |
125 |
&IsAvailableForItemLevelRequest |
|
Lines 194-205
sub AddReserve {
Link Here
|
| 194 |
|
193 |
|
| 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. |
194 |
#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. |
| 196 |
my $reserve = {borrowernumber => $borrowernumber, waitingdate => $waitingdate, branchcode => $branch}; |
195 |
my $reserve = {borrowernumber => $borrowernumber, waitingdate => $waitingdate, branchcode => $branch}; |
| 197 |
$lastpickupdate = GetLastPickupDate( $reserve, $item ); |
196 |
my $patron = Koha::Patrons->find( {borrowernumber => $borrowernumber} ); |
|
|
197 |
$lastpickupdate = GetLastPickupDate( $reserve, $item, $patron ); |
| 198 |
} |
198 |
} |
| 199 |
|
|
|
| 200 |
# Don't add itemtype limit if specific item is selected |
199 |
# Don't add itemtype limit if specific item is selected |
| 201 |
$itemtype = undef if $checkitem; |
200 |
$itemtype = undef if $checkitem; |
| 202 |
|
|
|
| 203 |
# updates take place here |
201 |
# updates take place here |
| 204 |
my $hold = Koha::Hold->new( |
202 |
my $hold = Koha::Hold->new( |
| 205 |
{ |
203 |
{ |
|
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 666-671
sub GetReserveStatus {
Link Here
|
| 666 |
return ''; # empty string here will remove need for checking undef, or less log lines |
663 |
return ''; # empty string here will remove need for checking undef, or less log lines |
| 667 |
} |
664 |
} |
| 668 |
|
665 |
|
|
|
666 |
|
| 667 |
=head2 GetLastPickupDate |
| 668 |
|
| 669 |
my $lastpickupdate = GetLastPickupDate($reserve, $item); |
| 670 |
my $lastpickupdate = GetLastPickupDate($reserve, $item, $borrower); |
| 671 |
my $lastpickupdate = GetLastPickupDate(undef, $item); |
| 672 |
|
| 673 |
Gets the last pickup date from the issuingrules for the given reserves-row and sets the |
| 674 |
$reserve->{lastpickupdate}.-value. |
| 675 |
|
| 676 |
If the reserves-row is not passed, function tries to figure it out from the item-row. |
| 677 |
Calculating the last pickup date respects Calendar holidays and skips to the next open day. |
| 678 |
If the issuingrule's holdspickupwait is 0 or less, means that the lastpickupdate-feature |
| 679 |
is disabled for this kind of material. |
| 680 |
|
| 681 |
@PARAM1 koha.reserves-row |
| 682 |
@PARAM2 koha.items-row, If the reserve is not given, an item must be given to be |
| 683 |
able to find a reservation |
| 684 |
@PARAM3 koha.borrowers-row, OPTIONAL |
| 685 |
RETURNS DateTime, depicting the last pickup date. |
| 686 |
OR undef if there is an error or if the issuingrules disable this feature for this material. |
| 687 |
|
| 688 |
=cut |
| 689 |
|
| 690 |
sub GetLastPickupDate { |
| 691 |
my ($reserve, $item, $borrower) = @_; |
| 692 |
##Verify parameters |
| 693 |
if ( not defined $reserve and not defined $item ) { |
| 694 |
warn "C4::Reserves::GetMaxPickupDate(), is called without a reserve and an item"; |
| 695 |
return; |
| 696 |
} |
| 697 |
if ( defined $reserve and not defined $item ) { |
| 698 |
$item = C4::Items::GetItem( $reserve->{itemnumber} ); |
| 699 |
} |
| 700 |
|
| 701 |
unless ( defined $borrower) { |
| 702 |
my $borrower = Koha::Patrons->find( $reserve->{borrowernumber} ); |
| 703 |
$borrower = $borrower->unblessed; |
| 704 |
} |
| 705 |
|
| 706 |
unless ( defined $reserve ) { |
| 707 |
my $reserve = GetReservesFromItemnumber( $item->{itemnumber} ); |
| 708 |
} |
| 709 |
my $date = $reserve->{waitingdate}; |
| 710 |
unless ( $date ) { #It is possible that a reserve is just caught and it doesn't have a waitingdate yet. |
| 711 |
$date = DateTime->now( time_zone => C4::Context->tz() ); #So default to NOW() |
| 712 |
} |
| 713 |
else { |
| 714 |
$date = (ref $reserve->{waitingdate} eq 'DateTime') ? $reserve->{waitingdate} : dt_from_string($reserve->{waitingdate}); |
| 715 |
} |
| 716 |
##Get churning the LastPickupDate |
| 717 |
|
| 718 |
# Get the controlbranch |
| 719 |
my $controlbranch = GetReservesControlBranch( $item, $borrower ); |
| 720 |
my $hbr = C4::Context->preference('HomeOrHoldingBranch') || "homebranch"; |
| 721 |
my $branchcode = "*"; |
| 722 |
if ( $controlbranch eq "ItemHomeLibrary" ) { |
| 723 |
$branchcode = $item->{$hbr}; |
| 724 |
} elsif ( $controlbranch eq "PatronLibrary" ) { |
| 725 |
$branchcode = $borrower->branchcode; |
| 726 |
} |
| 727 |
warn 'getlastpickup'; |
| 728 |
warn $branchcode; |
| 729 |
warn $borrower->{'categorycode'}; |
| 730 |
warn $item->{itype}; |
| 731 |
my $issuingrule = Koha::IssuingRules->get_effective_issuing_rule({ |
| 732 |
branchcode => $branchcode, |
| 733 |
categorycode => $borrower->{'categorycode'}, |
| 734 |
itemtype => $item->{itype}, |
| 735 |
}); |
| 736 |
|
| 737 |
my $reservebranch; |
| 738 |
if ($reserve->{'branchcode'}) { |
| 739 |
$reservebranch = $reserve->{'branchcode'}; |
| 740 |
} else { |
| 741 |
$reservebranch = $reserve->branchcode; |
| 742 |
} |
| 743 |
if ( defined($issuingrule) && defined $issuingrule->holdspickupwait && $issuingrule->holdspickupwait > 0 ) { #If holdspickupwait is <= 0, it means this feature is disabled for this type of material. |
| 744 |
$date->add( days => $issuingrule->holdspickupwait ); |
| 745 |
my $calendar = Koha::Calendar->new( branchcode => $reservebranch ); |
| 746 |
my $is_holiday = $calendar->is_holiday( $date ); |
| 747 |
while ( $is_holiday ) { |
| 748 |
$date->add( days => 1 ); |
| 749 |
$is_holiday = $calendar->is_holiday( $date ); |
| 750 |
} |
| 751 |
$reserve->{lastpickupdate} = $date->ymd(); |
| 752 |
return $date; |
| 753 |
} |
| 754 |
#Without explicitly setting the return value undef, the lastpickupdate-column is |
| 755 |
# set as 0000-00-00 instead of NULL in DBD::MySQL. |
| 756 |
#This causes this hold to always expire any lastpickupdate check, |
| 757 |
## effectively canceling it as soon as cancel_expired_holds.pl is ran. |
| 758 |
##This is exactly the opposite of disabling the autoexpire feature. |
| 759 |
##So please let me explicitly return undef, because Perl cant always handle everything. |
| 760 |
delete $reserve->{lastpickupdate}; |
| 761 |
return undef; |
| 762 |
} |
| 763 |
|
| 669 |
=head2 CheckReserves |
764 |
=head2 CheckReserves |
| 670 |
|
765 |
|
| 671 |
($status, $matched_reserve, $possible_reserves) = &CheckReserves($itemnumber); |
766 |
($status, $matched_reserve, $possible_reserves) = &CheckReserves($itemnumber); |
|
Lines 1011-1017
sub ModReserveFill {
Link Here
|
| 1011 |
|
1106 |
|
| 1012 |
=head2 ModReserveStatus |
1107 |
=head2 ModReserveStatus |
| 1013 |
|
1108 |
|
| 1014 |
&ModReserveStatus($itemnumber, $newstatus); |
1109 |
&ModReserveStatus($itemnumber, $newstatus, $holdtype); |
| 1015 |
|
1110 |
|
| 1016 |
Update the reserve status for the active (priority=0) reserve. |
1111 |
Update the reserve status for the active (priority=0) reserve. |
| 1017 |
|
1112 |
|
|
Lines 1022-1033
$newstatus is the new status.
Link Here
|
| 1022 |
=cut |
1117 |
=cut |
| 1023 |
|
1118 |
|
| 1024 |
sub ModReserveStatus { |
1119 |
sub ModReserveStatus { |
| 1025 |
|
|
|
| 1026 |
#first : check if we have a reservation for this item . |
1120 |
#first : check if we have a reservation for this item . |
| 1027 |
my ($itemnumber, $newstatus) = @_; |
1121 |
my ($itemnumber, $newstatus) = @_; |
| 1028 |
my $dbh = C4::Context->dbh; |
1122 |
my $dbh = C4::Context->dbh; |
| 1029 |
|
1123 |
|
| 1030 |
my $now = dt_from_string; |
1124 |
my $now = dt_from_string; |
|
|
1125 |
|
| 1031 |
my $reserve = $dbh->selectrow_hashref(q{ |
1126 |
my $reserve = $dbh->selectrow_hashref(q{ |
| 1032 |
SELECT * |
1127 |
SELECT * |
| 1033 |
FROM reserves |
1128 |
FROM reserves |
|
Lines 1035-1044
sub ModReserveStatus {
Link Here
|
| 1035 |
AND found IS NULL |
1130 |
AND found IS NULL |
| 1036 |
AND priority = 0 |
1131 |
AND priority = 0 |
| 1037 |
}, {}, $itemnumber); |
1132 |
}, {}, $itemnumber); |
| 1038 |
return unless $reserve; |
|
|
| 1039 |
|
1133 |
|
| 1040 |
my $lastpickupdate = GetLastPickupDate( $reserve ); |
1134 |
return unless $reserve; |
|
|
1135 |
my $borrower = Koha::Patrons->find( $reserve->{borrowernumber} ); |
| 1136 |
$borrower = $borrower->unblessed; |
| 1137 |
my $item = C4::Items::GetItem( $reserve->{itemnumber} ); |
| 1041 |
|
1138 |
|
|
|
1139 |
my $lastpickupdate = GetLastPickupDate( $reserve, $item, $borrower ); |
| 1042 |
my $query = q{ |
1140 |
my $query = q{ |
| 1043 |
UPDATE reserves |
1141 |
UPDATE reserves |
| 1044 |
SET found = ?, |
1142 |
SET found = ?, |
|
Lines 1100-1105
sub ModReserveAffect {
Link Here
|
| 1100 |
$hold->itemnumber($itemnumber); |
1198 |
$hold->itemnumber($itemnumber); |
| 1101 |
$hold->set_waiting($transferToDo); |
1199 |
$hold->set_waiting($transferToDo); |
| 1102 |
|
1200 |
|
|
|
1201 |
my $item = C4::Items::GetItem( $itemnumber ); |
| 1202 |
my $borrower = Koha::Patrons->find( $borrowernumber ); |
| 1203 |
$borrower = $borrower->unblessed; |
| 1204 |
my $lastpickupdate = GetLastPickupDate( $hold, $item, $borrower ); |
| 1205 |
warn $lastpickupdate; |
| 1206 |
my $query = " |
| 1207 |
UPDATE reserves |
| 1208 |
SET lastpickupdate = ? |
| 1209 |
WHERE borrowernumber = ? |
| 1210 |
AND itemnumber = ? |
| 1211 |
"; |
| 1212 |
$sth = $dbh->prepare($query); |
| 1213 |
$sth->execute( $lastpickupdate, $borrowernumber,$itemnumber); |
| 1214 |
|
| 1103 |
_koha_notify_reserve( $hold->reserve_id ) |
1215 |
_koha_notify_reserve( $hold->reserve_id ) |
| 1104 |
if ( !$transferToDo && !$already_on_shelf ); |
1216 |
if ( !$transferToDo && !$already_on_shelf ); |
| 1105 |
|
1217 |
|
|
Lines 2057-2063
sub ReserveSlip {
Link Here
|
| 2057 |
|
2169 |
|
| 2058 |
return unless $hold; |
2170 |
return unless $hold; |
| 2059 |
my $reserve = $hold->unblessed; |
2171 |
my $reserve = $hold->unblessed; |
| 2060 |
|
2172 |
warn Dumper($reserve); |
| 2061 |
return C4::Letters::GetPreparedLetter ( |
2173 |
return C4::Letters::GetPreparedLetter ( |
| 2062 |
module => 'circulation', |
2174 |
module => 'circulation', |
| 2063 |
letter_code => 'HOLD_SLIP', |
2175 |
letter_code => 'HOLD_SLIP', |