Lines 43-48
use Koha::Calendar;
Link Here
|
43 |
use DateTime; |
43 |
use DateTime; |
44 |
|
44 |
|
45 |
use List::MoreUtils qw( firstidx ); |
45 |
use List::MoreUtils qw( firstidx ); |
|
|
46 |
use Scalar::Util qw(blessed); |
46 |
|
47 |
|
47 |
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
48 |
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
48 |
|
49 |
|
Lines 791-796
sub GetReservesForBranch {
Link Here
|
791 |
return (@transreserv); |
792 |
return (@transreserv); |
792 |
} |
793 |
} |
793 |
|
794 |
|
|
|
795 |
=head GetExpiredReserves |
796 |
|
797 |
my $expiredReserves = C4::Reserves::GetExpiredReserves( |
798 |
{branchcode => 'CPL', |
799 |
from => DateTime->new(...), #DateTime or undef |
800 |
#defaults to 'PickupExpiredHoldsOverReportDuration' days ago. |
801 |
#respects Koha::Calendar for the given branch, skipping closed days. |
802 |
to => DateTime->now(), #DateTime or undef |
803 |
#defaults to now() |
804 |
}); |
805 |
|
806 |
@RETURNS ARRAYRef of expired reserves from the given duration. |
807 |
=cut |
808 |
|
809 |
sub GetExpiredReserves { |
810 |
my ($params) = @_; |
811 |
|
812 |
my $pickupExpiredHoldsOverReportDuration = C4::Context->preference('PickupExpiredHoldsOverReportDuration'); |
813 |
return [] unless $pickupExpiredHoldsOverReportDuration; |
814 |
|
815 |
my $branchcode = $params->{branchcode}; |
816 |
if ($params->{from}) { |
817 |
unless (blessed($params->{from}) && $params->{from}->isa('DateTime')) { |
818 |
Koha::Exception::BadParameter->throw(error => "GetExpiredReserves():> Parameter 'from' is not a DateTime-object or undef!"); |
819 |
} |
820 |
} |
821 |
if ($params->{to}) { |
822 |
unless (blessed($params->{from}) && $params->{from}->isa('DateTime')) { |
823 |
Koha::Exception::BadParameter->throw(error => "GetExpiredReserves():> Parameter 'from' is not a DateTime-object or undef!"); |
824 |
} |
825 |
} |
826 |
|
827 |
#Calculate the days for which we get the expired reserves. |
828 |
my $fromDate = $params->{from}; |
829 |
my $toDate = $params->{to} || DateTime->now(time_zone => C4::Context->tz()); |
830 |
unless ($fromDate) { |
831 |
$fromDate = DateTime->now( time_zone => C4::Context->tz() ); |
832 |
|
833 |
#Look for previous open days |
834 |
if ($branchcode) { |
835 |
my $calendar = Koha::Calendar->new( branchcode => $branchcode ); |
836 |
foreach my $i (1..$pickupExpiredHoldsOverReportDuration) { |
837 |
$fromDate = $calendar->prev_open_day($fromDate); |
838 |
} |
839 |
} |
840 |
#If no branch has been specified we cannot use a calendar, so simply just go back in time. |
841 |
else { |
842 |
$fromDate = DateTime->now(time_zone => C4::Context->tz())->subtract(days => $pickupExpiredHoldsOverReportDuration); |
843 |
} |
844 |
} |
845 |
|
846 |
my $dbh = C4::Context->dbh; |
847 |
|
848 |
my @params = ($fromDate->ymd(), $toDate->ymd()); |
849 |
my $query = " |
850 |
SELECT * |
851 |
FROM old_reserves |
852 |
WHERE priority='0' |
853 |
AND pickupexpired BETWEEN ? AND ? |
854 |
"; |
855 |
if ( $branchcode ) { |
856 |
push @params, $branchcode; |
857 |
$query .= " AND branchcode=? "; |
858 |
} |
859 |
$query .= "ORDER BY waitingdate" ; |
860 |
|
861 |
my $sth = $dbh->prepare($query); |
862 |
$sth->execute(@params); |
863 |
|
864 |
my $data = $sth->fetchall_arrayref({}); |
865 |
return ($data) ? $data : []; |
866 |
} |
867 |
|
794 |
=head2 GetReserveStatus |
868 |
=head2 GetReserveStatus |
795 |
|
869 |
|
796 |
$reservestatus = GetReserveStatus($itemnumber, $biblionumber); |
870 |
$reservestatus = GetReserveStatus($itemnumber, $biblionumber); |
Lines 1021-1027
sub CancelExpiredReserves {
Link Here
|
1021 |
if ( $charge ) { |
1095 |
if ( $charge ) { |
1022 |
manualinvoice($res->{'borrowernumber'}, $res->{'itemnumber'}, 'Hold waiting too long', 'F', $charge); |
1096 |
manualinvoice($res->{'borrowernumber'}, $res->{'itemnumber'}, 'Hold waiting too long', 'F', $charge); |
1023 |
} |
1097 |
} |
1024 |
CancelReserve({ reserve_id => $res->{'reserve_id'} }); |
1098 |
CancelReserve({ reserve_id => $res->{'reserve_id'}, |
|
|
1099 |
pickupexpired => $expiration, |
1100 |
}); |
1025 |
push @sb, printReserve($res,'tab',['reserve_id','borrowernumber','branchcode','waitingdate']).sprintf("% 14s",substr($expiration,0,10))."| past lastpickupdate.\n" if $verbose; |
1101 |
push @sb, printReserve($res,'tab',['reserve_id','borrowernumber','branchcode','waitingdate']).sprintf("% 14s",substr($expiration,0,10))."| past lastpickupdate.\n" if $verbose; |
1026 |
} |
1102 |
} |
1027 |
elsif($verbose > 1) { |
1103 |
elsif($verbose > 1) { |
Lines 1064-1070
sub AutoUnsuspendReserves {
Link Here
|
1064 |
|
1140 |
|
1065 |
=head2 CancelReserve |
1141 |
=head2 CancelReserve |
1066 |
|
1142 |
|
1067 |
CancelReserve({ reserve_id => $reserve_id, [ biblionumber => $biblionumber, borrowernumber => $borrrowernumber, itemnumber => $itemnumber ] }); |
1143 |
CancelReserve({ reserve_id => $reserve_id, |
|
|
1144 |
[ biblionumber => $biblionumber, |
1145 |
borrowernumber => $borrrowernumber, |
1146 |
itemnumber => $itemnumber ], |
1147 |
pickupexpired => DateTime->new(year => 2015, ...), #If the reserve was waiting for pickup, set the date the pickup wait period expired. |
1148 |
}); |
1068 |
|
1149 |
|
1069 |
Cancels a reserve. |
1150 |
Cancels a reserve. |
1070 |
|
1151 |
|
Lines 1074-1079
sub CancelReserve {
Link Here
|
1074 |
my ( $params ) = @_; |
1155 |
my ( $params ) = @_; |
1075 |
|
1156 |
|
1076 |
my $reserve_id = $params->{'reserve_id'}; |
1157 |
my $reserve_id = $params->{'reserve_id'}; |
|
|
1158 |
my $pickupexpired = $params->{pickupexpired}; |
1159 |
if ($pickupexpired) { |
1160 |
unless (blessed($pickupexpired) && $pickupexpired->isa('DateTime')) { |
1161 |
Koha::Exception::BadParameter->throw(error => "CancelReserve():> Parameter 'pickupexpired' is not a DateTime-object or undef!"); |
1162 |
} |
1163 |
} |
1164 |
|
1077 |
$reserve_id = GetReserveId( $params ) unless ( $reserve_id ); |
1165 |
$reserve_id = GetReserveId( $params ) unless ( $reserve_id ); |
1078 |
|
1166 |
|
1079 |
return unless ( $reserve_id ); |
1167 |
return unless ( $reserve_id ); |
Lines 1082-1096
sub CancelReserve {
Link Here
|
1082 |
|
1170 |
|
1083 |
my $reserve = GetReserve( $reserve_id ); |
1171 |
my $reserve = GetReserve( $reserve_id ); |
1084 |
|
1172 |
|
|
|
1173 |
my @params; |
1085 |
my $query = " |
1174 |
my $query = " |
1086 |
UPDATE reserves |
1175 |
UPDATE reserves |
1087 |
SET cancellationdate = now(), |
1176 |
SET cancellationdate = DATE(NOW()), |
1088 |
found = Null, |
1177 |
found = Null, |
|
|
1178 |
"; |
1179 |
if ($pickupexpired) { |
1180 |
push @params, $pickupexpired->ymd(); |
1181 |
$query .= " |
1182 |
pickupexpired = ?, |
1183 |
"; |
1184 |
} |
1185 |
push @params, $reserve_id; |
1186 |
$query .= " |
1089 |
priority = 0 |
1187 |
priority = 0 |
1090 |
WHERE reserve_id = ? |
1188 |
WHERE reserve_id = ? |
1091 |
"; |
1189 |
"; |
1092 |
my $sth = $dbh->prepare($query); |
1190 |
my $sth = $dbh->prepare($query); |
1093 |
$sth->execute( $reserve_id ); |
1191 |
$sth->execute( @params ); |
1094 |
|
1192 |
|
1095 |
$query = " |
1193 |
$query = " |
1096 |
INSERT INTO old_reserves |
1194 |
INSERT INTO old_reserves |