Lines 936-948
sub CheckReserves {
Link Here
|
936 |
|
936 |
|
937 |
=head2 CancelExpiredReserves |
937 |
=head2 CancelExpiredReserves |
938 |
|
938 |
|
939 |
CancelExpiredReserves(); |
939 |
CancelExpiredReserves(); #Brief |
|
|
940 |
my $verboseLog = CancelExpiredReserves(2); #Verbose level 2 |
940 |
|
941 |
|
941 |
Cancels all reserves with an expiration date from before today. |
942 |
Cancels all reserves with an expiration date from before today. |
942 |
|
943 |
|
|
|
944 |
@PARAM1 Integer, to define the verbosity level. 0 or undef to be brief. |
945 |
Supported values, 0,1,2,3. |
946 |
RETURNS String, the verbose output. Returns the output instead of printing it to |
947 |
make it possible to run this module from a CGI-script. |
948 |
|
943 |
=cut |
949 |
=cut |
944 |
|
950 |
|
945 |
sub CancelExpiredReserves { |
951 |
sub CancelExpiredReserves { |
|
|
952 |
my $verbose = shift; |
953 |
my @sb; #Efficiently collect verbose output here. |
954 |
my %usedCalendars; #Collect all used calendars here so they can be logged if verbose enough |
946 |
|
955 |
|
947 |
# Cancel reserves that have passed their expiration date. |
956 |
# Cancel reserves that have passed their expiration date. |
948 |
my $dbh = C4::Context->dbh; |
957 |
my $dbh = C4::Context->dbh; |
Lines 953-962
sub CancelExpiredReserves {
Link Here
|
953 |
" ); |
962 |
" ); |
954 |
$sth->execute(); |
963 |
$sth->execute(); |
955 |
|
964 |
|
|
|
965 |
push @sb, "##Checking reserve expirationdates\n". |
966 |
"reserve_id|borrowernumber|expirationdate|\n" if $verbose; |
967 |
|
956 |
while ( my $res = $sth->fetchrow_hashref() ) { |
968 |
while ( my $res = $sth->fetchrow_hashref() ) { |
957 |
CancelReserve({ reserve_id => $res->{'reserve_id'} }); |
969 |
CancelReserve({ reserve_id => $res->{'reserve_id'} }); |
|
|
970 |
push @sb, printReserve($res,'tab',['reserve_id','borrowernumber','expirationdate'])." expired.\n" if $verbose; |
958 |
} |
971 |
} |
959 |
|
972 |
|
960 |
# Cancel reserves that have been waiting too long |
973 |
# Cancel reserves that have been waiting too long |
961 |
if ( C4::Context->preference("ExpireReservesMaxPickUpDelay") ) { |
974 |
if ( C4::Context->preference("ExpireReservesMaxPickUpDelay") ) { |
962 |
my $max_pickup_delay = C4::Context->preference("ReservesMaxPickUpDelay"); |
975 |
my $max_pickup_delay = C4::Context->preference("ReservesMaxPickUpDelay"); |
Lines 968-973
sub CancelExpiredReserves {
Link Here
|
968 |
|
981 |
|
969 |
my $today = DateTime->now( time_zone => C4::Context->tz() ); |
982 |
my $today = DateTime->now( time_zone => C4::Context->tz() ); |
970 |
|
983 |
|
|
|
984 |
push @sb, "##Removing holds waiting too long\n##using today=$today, ReservesMaxPickUpDelay=$max_pickup_delay, ExpireReservesMaxPickUpDelayCharge=$charge\n". |
985 |
"reserve_id|borrowernumber|branchcode|waitingdate|lastpickupdate|resolution\n" if $verbose; |
986 |
|
971 |
while (my $res = $sth->fetchrow_hashref ) { |
987 |
while (my $res = $sth->fetchrow_hashref ) { |
972 |
my $expiration = _reserve_last_pickup_date( $res ); |
988 |
my $expiration = _reserve_last_pickup_date( $res ); |
973 |
if ( $today > $expiration ) { |
989 |
if ( $today > $expiration ) { |
Lines 975-984
sub CancelExpiredReserves {
Link Here
|
975 |
manualinvoice($res->{'borrowernumber'}, $res->{'itemnumber'}, 'Hold waiting too long', 'F', $charge); |
991 |
manualinvoice($res->{'borrowernumber'}, $res->{'itemnumber'}, 'Hold waiting too long', 'F', $charge); |
976 |
} |
992 |
} |
977 |
CancelReserve({ reserve_id => $res->{'reserve_id'} }); |
993 |
CancelReserve({ reserve_id => $res->{'reserve_id'} }); |
|
|
994 |
push @sb, printReserve($res,'tab',['reserve_id','borrowernumber','branchcode','waitingdate']).sprintf("% 14s",substr($expiration,0,10))."| past lastpickupdate.\n" if $verbose; |
995 |
} |
996 |
elsif($verbose > 1) { |
997 |
push @sb, printReserve($res,'tab',['reserve_id','borrowernumber','branchcode','waitingdate']).sprintf("% 14s",substr($expiration,0,10))."| still waiting.\n" if $verbose > 1; |
978 |
} |
998 |
} |
|
|
999 |
$usedCalendars{ $res->{branchcode} } = Koha::Calendar->new( branchcode => $res->{branchcode} ) if ( $verbose > 2 && not(exists($usedCalendars{$res->{branchcode}})) ); |
979 |
} |
1000 |
} |
980 |
} |
|
|
981 |
|
1001 |
|
|
|
1002 |
#Log the used calendars. |
1003 |
if ($verbose > 2) { |
1004 |
push @sb, "##Dumping used Calendars\n"; |
1005 |
foreach my $branchcode (sort keys %usedCalendars) { |
1006 |
my $calendar = $usedCalendars{$branchcode}; |
1007 |
push @sb, "<< $branchcode >>\n"; |
1008 |
push @sb, $calendar->printMe()."\n"; |
1009 |
} |
1010 |
} |
1011 |
|
1012 |
} |
1013 |
return join('',@sb) if $verbose; |
982 |
} |
1014 |
} |
983 |
|
1015 |
|
984 |
=head2 AutoUnsuspendReserves |
1016 |
=head2 AutoUnsuspendReserves |
Lines 2346-2351
sub CalculatePriority {
Link Here
|
2346 |
return @row ? $row[0]+1 : 1; |
2378 |
return @row ? $row[0]+1 : 1; |
2347 |
} |
2379 |
} |
2348 |
|
2380 |
|
|
|
2381 |
=head printReserve |
2382 |
|
2383 |
my $text = C4::Reserves::printReserve( $reserve, 'tab', ['reserve_id','borrowernumber','waitingdate', ...] ); |
2384 |
assert($text, " 1| 1017466| 2014-11-06| ..."); |
2385 |
|
2386 |
Gets a textual representation of a koha.reserves -row. |
2387 |
|
2388 |
@PARAM1 koha.reserves-row |
2389 |
@PARAM2 String, type of formatting, currently supported are 'tab' to print tabular output. |
2390 |
Defaults the column width to the key length. |
2391 |
@PARAM3 Array of columns, the desired reserves-columns to output in the given order. |
2392 |
RETURNS String, depending on the type of formatting. |
2393 |
|
2394 |
=cut |
2395 |
|
2396 |
sub printReserve { |
2397 |
my ($reserve, $format, $keys) = @_; |
2398 |
my @sb; |
2399 |
|
2400 |
if ($format eq 'tab') { |
2401 |
foreach my $key (@$keys) { |
2402 |
my $l = length $key; |
2403 |
push @sb, sprintf('% '.$l.'s', $reserve->{$key}).'|'; |
2404 |
} |
2405 |
return join('',@sb); |
2406 |
} |
2407 |
} |
2408 |
|
2349 |
=head1 AUTHOR |
2409 |
=head1 AUTHOR |
2350 |
|
2410 |
|
2351 |
Koha Development Team <http://koha-community.org/> |
2411 |
Koha Development Team <http://koha-community.org/> |