View | Details | Raw Unified | Return to bug 12063
Collapse All | Expand All

(-)a/C4/Reserves.pm (-5 / +44 lines)
Lines 38-43 use C4::Branch qw( GetBranchDetail ); Link Here
38
use C4::Dates qw( format_date_in_iso );
38
use C4::Dates qw( format_date_in_iso );
39
39
40
use Koha::DateUtils;
40
use Koha::DateUtils;
41
use Koha::Calendar;
42
43
use DateTime;
41
44
42
use List::MoreUtils qw( firstidx );
45
use List::MoreUtils qw( firstidx );
43
46
Lines 981-995 sub CancelExpiredReserves { Link Here
981
        my $charge = C4::Context->preference("ExpireReservesMaxPickUpDelayCharge");
984
        my $charge = C4::Context->preference("ExpireReservesMaxPickUpDelayCharge");
982
985
983
        my $query = "SELECT * FROM reserves WHERE TO_DAYS( NOW() ) - TO_DAYS( waitingdate ) > ? AND found = 'W' AND priority = 0";
986
        my $query = "SELECT * FROM reserves WHERE TO_DAYS( NOW() ) - TO_DAYS( waitingdate ) > ? AND found = 'W' AND priority = 0";
987
988
	my $today = DateTime->now( time_zone => C4::Context->tz() );
989
984
        $sth = $dbh->prepare( $query );
990
        $sth = $dbh->prepare( $query );
985
        $sth->execute( $max_pickup_delay );
991
        $sth->execute( $max_pickup_delay );
986
992
987
        while (my $res = $sth->fetchrow_hashref ) {
993
        while (my $res = $sth->fetchrow_hashref ) {
988
            if ( $charge ) {
989
                manualinvoice($res->{'borrowernumber'}, $res->{'itemnumber'}, 'Hold waiting too long', 'F', $charge);
990
            }
991
994
992
            CancelReserve({ reserve_id => $res->{'reserve_id'} });
995
	    my $calendar = Koha::Calendar->new( branchcode => $res->{branchcode} );
996
	    my $expiration = $calendar->days_forward( $res->{waitingdate}, $max_pickup_delay );
997
998
	    if ( $today > $expiration ) {
999
		if ( $charge ) {
1000
		    manualinvoice($res->{'borrowernumber'}, $res->{'itemnumber'}, 'Hold waiting too long', 'F', $charge);
1001
		}
1002
		CancelReserve({ reserve_id => $res->{'reserve_id'} });
1003
	    }
993
        }
1004
        }
994
    }
1005
    }
995
1006
Lines 1871-1876 sub _Findgroupreserve { Link Here
1871
    return @results;
1882
    return @results;
1872
}
1883
}
1873
1884
1885
=head2 _reserve_last_pickup_date
1886
1887
 my $last_dt = _reserve_last_pickup_date($reserve);
1888
1889
Returns the DateTime for the last pickup date for reserve.
1890
1891
=cut
1892
1893
sub _reserve_last_pickup_date {
1894
    my ($reserve) = @_;
1895
1896
    my $startdate = $reserve->{waitingdate} ? dt_from_string($reserve->{waitingdate}) : DateTime->now( time_zone => C4::Context->tz() );
1897
    my $calendar = Koha::Calendar->new( branchcode => $reserve->{branchcode} );
1898
    my $expiration = $calendar->days_forward( $startdate, C4::Context->preference('ReservesMaxPickUpDelay') );
1899
1900
    return $expiration;
1901
}
1902
1903
1874
=head2 _koha_notify_reserve
1904
=head2 _koha_notify_reserve
1875
1905
1876
  _koha_notify_reserve( $itemnumber, $borrowernumber, $biblionumber );
1906
  _koha_notify_reserve( $itemnumber, $borrowernumber, $biblionumber );
Lines 1910-1915 sub _koha_notify_reserve { Link Here
1910
1940
1911
    my $admin_email_address = $branch_details->{'branchemail'} || C4::Context->preference('KohaAdminEmailAddress');
1941
    my $admin_email_address = $branch_details->{'branchemail'} || C4::Context->preference('KohaAdminEmailAddress');
1912
1942
1943
    my $expiration = _reserve_last_pickup_date($reserve);
1944
1913
    my %letter_params = (
1945
    my %letter_params = (
1914
        module => 'reserves',
1946
        module => 'reserves',
1915
        branchcode => $reserve->{branchcode},
1947
        branchcode => $reserve->{branchcode},
Lines 1920-1926 sub _koha_notify_reserve { Link Here
1920
            'reserves'  => $reserve,
1952
            'reserves'  => $reserve,
1921
            'items', $reserve->{'itemnumber'},
1953
            'items', $reserve->{'itemnumber'},
1922
        },
1954
        },
1923
        substitute => { today => C4::Dates->new()->output() },
1955
        substitute => {
1956
	    'lastpickupdate' => C4::Dates->new($expiration->ymd(), 'iso')->output()
1957
	},
1924
    );
1958
    );
1925
1959
1926
1960
Lines 2223-2228 sub ReserveSlip { Link Here
2223
    }) or return;
2257
    }) or return;
2224
    my $reserve = GetReserveInfo($reserve_id) or return;
2258
    my $reserve = GetReserveInfo($reserve_id) or return;
2225
2259
2260
    my $expiration = _reserve_last_pickup_date($reserve);
2261
2226
    return  C4::Letters::GetPreparedLetter (
2262
    return  C4::Letters::GetPreparedLetter (
2227
        module => 'circulation',
2263
        module => 'circulation',
2228
        letter_code => 'RESERVESLIP',
2264
        letter_code => 'RESERVESLIP',
Lines 2234-2239 sub ReserveSlip { Link Here
2234
            'biblio'      => $reserve->{biblionumber},
2270
            'biblio'      => $reserve->{biblionumber},
2235
            'items'       => $reserve->{itemnumber},
2271
            'items'       => $reserve->{itemnumber},
2236
        },
2272
        },
2273
        substitute => {
2274
	    'lastpickupdate' => C4::Dates->new($expiration->ymd(), 'iso')->output()
2275
	},
2237
    );
2276
    );
2238
}
2277
}
2239
2278
(-)a/Koha/Calendar.pm (+19 lines)
Lines 267-272 sub prev_open_day { Link Here
267
    return $base_date;
267
    return $base_date;
268
}
268
}
269
269
270
sub days_forward {
271
    my $self     = shift;
272
    my $start_dt = shift;
273
    my $num_days = shift;
274
275
    my $base_dt = $start_dt->clone();
276
277
    while ($num_days--) { $base_dt = $self->next_open_day($base_dt); }
278
279
    return $base_dt;
280
}
281
270
sub days_between {
282
sub days_between {
271
    my $self     = shift;
283
    my $self     = shift;
272
    my $start_dt = shift;
284
    my $start_dt = shift;
Lines 434-439 $yesno = $calendar->is_holiday($dt); Link Here
434
passed a DateTime object returns 1 if it is a closed day
446
passed a DateTime object returns 1 if it is a closed day
435
0 if not according to the calendar
447
0 if not according to the calendar
436
448
449
=head2 days_forward
450
451
$due_dt = $calendar->days_forward($start_dt, $num_days);
452
453
Passed a DateTime object and a positive number of days, returns the DateTime when
454
$num_days non-holiday days (including the current day) have been skipped.
455
437
=head2 days_between
456
=head2 days_between
438
457
439
$duration = $calendar->days_between($start_dt, $end_dt);
458
$duration = $calendar->days_between($start_dt, $end_dt);
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref (-2 / +1 lines)
Lines 398-404 Circulation: Link Here
398
            - Mark a hold as problematic if it has been waiting for more than
398
            - Mark a hold as problematic if it has been waiting for more than
399
            - pref: ReservesMaxPickUpDelay
399
            - pref: ReservesMaxPickUpDelay
400
              class: integer
400
              class: integer
401
            - days.
401
            - non-holiday days.
402
        -
402
        -
403
            - pref: ExpireReservesMaxPickUpDelay
403
            - pref: ExpireReservesMaxPickUpDelay
404
              choices:
404
              choices:
405
- 

Return to bug 12063