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

(-)a/C4/Letters.pm (-10 lines)
Lines 868-884 sub _parseletter { Link Here
868
    }
868
    }
869
869
870
    if ( $table eq 'reserves' && $values->{'waitingdate'} ) {
870
    if ( $table eq 'reserves' && $values->{'waitingdate'} ) {
871
        my @waitingdate = split /-/, $values->{'waitingdate'};
872
873
        $values->{'expirationdate'} = '';
874
        if ( C4::Context->preference('ReservesMaxPickUpDelay') ) {
875
            my $dt = dt_from_string();
876
            $dt->add( days => C4::Context->preference('ReservesMaxPickUpDelay') );
877
            $values->{'expirationdate'} = output_pref( { dt => $dt, dateonly => 1 } );
878
        }
879
880
        $values->{'waitingdate'} = output_pref({ dt => dt_from_string( $values->{'waitingdate'} ), dateonly => 1 });
871
        $values->{'waitingdate'} = output_pref({ dt => dt_from_string( $values->{'waitingdate'} ), dateonly => 1 });
881
882
    }
872
    }
883
873
884
    if ($letter->{content} && $letter->{content} =~ /<<today>>/) {
874
    if ($letter->{content} && $letter->{content} =~ /<<today>>/) {
(-)a/C4/Reserves.pm (-1 / +3 lines)
Lines 784-790 sub GetReservesForBranch { Link Here
784
    my $dbh = C4::Context->dbh;
784
    my $dbh = C4::Context->dbh;
785
785
786
    my $query = "
786
    my $query = "
787
        SELECT reserve_id,borrowernumber,reservedate,itemnumber,waitingdate
787
        SELECT reserve_id,borrowernumber,reservedate,itemnumber,waitingdate, expirationdate
788
        FROM   reserves
788
        FROM   reserves
789
        WHERE   priority='0'
789
        WHERE   priority='0'
790
        AND found='W'
790
        AND found='W'
Lines 1003-1008 Cancels all reserves with an expiration date from before today. Link Here
1003
=cut
1003
=cut
1004
1004
1005
sub CancelExpiredReserves {
1005
sub CancelExpiredReserves {
1006
    return unless C4::Context->preference("ExpireReservesMaxPickUpDelay");
1007
1006
    my $today = dt_from_string();
1008
    my $today = dt_from_string();
1007
    my $cancel_on_holidays = C4::Context->preference('ExpireReservesOnHolidays');
1009
    my $cancel_on_holidays = C4::Context->preference('ExpireReservesOnHolidays');
1008
1010
(-)a/Koha/Calendar.pm (+2 lines)
Lines 301-306 sub days_forward { Link Here
301
    my $start_dt = shift;
301
    my $start_dt = shift;
302
    my $num_days = shift;
302
    my $num_days = shift;
303
303
304
    return $start_dt unless $num_days > 0;
305
304
    my $base_dt = $start_dt->clone();
306
    my $base_dt = $start_dt->clone();
305
307
306
    while ($num_days--) {
308
    while ($num_days--) {
(-)a/Koha/Hold.pm (-16 / +14 lines)
Lines 132-155 sub set_waiting { Link Here
132
        $requested_expiration = dt_from_string($self->expirationdate);
132
        $requested_expiration = dt_from_string($self->expirationdate);
133
    }
133
    }
134
134
135
    if ( C4::Context->preference("ExpireReservesMaxPickUpDelay") ) {
135
    my $max_pickup_delay = C4::Context->preference("ReservesMaxPickUpDelay");
136
        my $max_pickup_delay = C4::Context->preference("ReservesMaxPickUpDelay");
136
    my $cancel_on_holidays = C4::Context->preference('ExpireReservesOnHolidays');
137
        my $cancel_on_holidays = C4::Context->preference('ExpireReservesOnHolidays');
137
    my $calendar = Koha::Calendar->new( branchcode => $self->branchcode );
138
        my $calendar = Koha::Calendar->new( branchcode => $self->branchcode );
138
139
139
    my $expirationdate = $today->clone;
140
        my $expirationdate = $today->clone;
140
    $expirationdate->add(days => $max_pickup_delay);
141
        $expirationdate->add(days => $max_pickup_delay);
141
142
142
    if ( C4::Context->preference("ExcludeHolidaysFromMaxPickUpDelay") ) {
143
        if ( C4::Context->preference("ExcludeHolidaysFromMaxPickUpDelay") ) {
143
        $expirationdate = $calendar->days_forward( dt_from_string($self->waitingdate), $max_pickup_delay );
144
            $expirationdate = $calendar->days_forward( dt_from_string($self->waitingdate), $max_pickup_delay );
145
        }
146
147
        # If patron's requested expiration date is prior to the
148
        # calculated one, we keep the patron's one.
149
        my $cmp = $requested_expiration ? DateTime->compare($requested_expiration, $expirationdate) : 0;
150
        $values->{expirationdate} = $cmp == -1 ? $requested_expiration->ymd : $expirationdate->ymd;
151
    }
144
    }
152
145
146
    # If patron's requested expiration date is prior to the
147
    # calculated one, we keep the patron's one.
148
    my $cmp = $requested_expiration ? DateTime->compare($requested_expiration, $expirationdate) : 0;
149
    $values->{expirationdate} = $cmp == -1 ? $requested_expiration->ymd : $expirationdate->ymd;
150
153
    $self->set($values)->store();
151
    $self->set($values)->store();
154
152
155
    return $self;
153
    return $self;
(-)a/circ/waitingreserves.pl (-7 / +2 lines)
Lines 86-92 my @getreserves = $all_branches ? GetReservesForBranch() : GetReservesForBranch( Link Here
86
86
87
my $today = Date_to_Days(&Today);
87
my $today = Date_to_Days(&Today);
88
my $max_pickup_delay = C4::Context->preference('ReservesMaxPickUpDelay');
88
my $max_pickup_delay = C4::Context->preference('ReservesMaxPickUpDelay');
89
$max_pickup_delay-- if C4::Context->preference('ExpireReservesMaxPickUpDelay');
90
89
91
foreach my $num (@getreserves) {
90
foreach my $num (@getreserves) {
92
    next unless ($num->{'waitingdate'} && $num->{'waitingdate'} ne '0000-00-00');
91
    next unless ($num->{'waitingdate'} && $num->{'waitingdate'} ne '0000-00-00');
Lines 107-118 foreach my $num (@getreserves) { Link Here
107
    my $getborrower = GetMember(borrowernumber => $num->{'borrowernumber'});
106
    my $getborrower = GetMember(borrowernumber => $num->{'borrowernumber'});
108
    my $itemtypeinfo = getitemtypeinfo( $gettitle->{'itemtype'} );  # using the fixed up itype/itemtype
107
    my $itemtypeinfo = getitemtypeinfo( $gettitle->{'itemtype'} );  # using the fixed up itype/itemtype
109
    $getreserv{'waitingdate'} = $num->{'waitingdate'};
108
    $getreserv{'waitingdate'} = $num->{'waitingdate'};
110
    my ( $waiting_year, $waiting_month, $waiting_day ) = split (/-/, $num->{'waitingdate'});
109
    my ( $expire_year, $expire_month, $expire_day ) = split (/-/, $num->{'expirationdate'});
111
110
    my $calcDate = Date_to_Days( $expire_year, $expire_month, $expire_day );
112
    ( $waiting_year, $waiting_month, $waiting_day ) =
113
      Add_Delta_Days( $waiting_year, $waiting_month, $waiting_day,
114
        $max_pickup_delay);
115
    my $calcDate = Date_to_Days( $waiting_year, $waiting_month, $waiting_day );
116
111
117
    $getreserv{'itemtype'}       = $itemtypeinfo->{'description'};
112
    $getreserv{'itemtype'}       = $itemtypeinfo->{'description'};
118
    $getreserv{'title'}          = $gettitle->{'title'};
113
    $getreserv{'title'}          = $gettitle->{'title'};
(-)a/installer/data/mysql/atomicupdate/bug_12063-define_expirationdate_for_waitting_reserves.perl (+30 lines)
Line 0 Link Here
1
use C4::Context;
2
3
use Koha::Holds;
4
use Koha::DateUtils;
5
use Koha::Calendar;
6
7
my $waiting_holds = Koha::Holds->search({ found => 'W', priority => 0 });
8
while ( my $hold = $waiting_holds->next ) {
9
10
    my $requested_expiration;
11
    if ($hold->expirationdate) {
12
        $requested_expiration = dt_from_string($hold->expirationdate);
13
    }
14
15
    if ( my $waitingdate = dt_from_string($hold->waitingdate) ) {
16
        my $max_pickup_delay = C4::Context->preference("ReservesMaxPickUpDelay");
17
        my $cancel_on_holidays = C4::Context->preference('ExpireReservesOnHolidays');
18
        my $calendar = Koha::Calendar->new( branchcode => $hold->branchcode );
19
20
        my $expirationdate = $waitingdate->clone;
21
        $expirationdate->add(days => $max_pickup_delay);
22
23
        if ( C4::Context->preference("ExcludeHolidaysFromMaxPickUpDelay") ) {
24
            $expirationdate = $calendar->days_forward( dt_from_string($hold->waitingdate), $max_pickup_delay );
25
        }
26
27
        my $cmp = $requested_expiration ? DateTime->compare($requested_expiration, $expirationdate) : 0;
28
        $hold->expirationdate($cmp == -1 ? $requested_expiration->ymd : $expirationdate->ymd)->store;
29
    }
30
}
(-)a/t/db_dependent/Calendar.t (-1 / +69 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Test::More tests => 5;
21
use t::lib::TestBuilder;
22
23
use DateTime;
24
use Koha::Caches;
25
use Koha::DateUtils;
26
27
use_ok('Koha::Calendar');
28
29
my $schema  = Koha::Database->new->schema;
30
$schema->storage->txn_begin;
31
32
my $today = dt_from_string();
33
my $holiday_dt = $today->clone;
34
$holiday_dt->add(days => 15);
35
36
Koha::Caches->get_instance()->flush_all();
37
38
my $builder = t::lib::TestBuilder->new();
39
my $holiday = $builder->build({
40
    source => 'SpecialHoliday',
41
    value => {
42
        branchcode => 'LIB1',
43
        day => $holiday_dt->day,
44
        month => $holiday_dt->month,
45
        year => $holiday_dt->year,
46
        title => 'My holiday',
47
        isexception => 0
48
    },
49
});
50
51
my $calendar = Koha::Calendar->new( branchcode => 'LIB1');
52
my $forwarded_dt = $calendar->days_forward($today, 10);
53
54
my $expected = $today->clone;
55
$expected->add(days => 10);
56
is($forwarded_dt->ymd, $expected->ymd, 'With no holiday on the perioddays_forward should add 10 days');
57
58
$forwarded_dt = $calendar->days_forward($today, 20);
59
60
$expected->add(days => 11);
61
is($forwarded_dt->ymd, $expected->ymd, 'With holiday on the perioddays_forward should add 20 days + 1 day for holiday');
62
63
$forwarded_dt = $calendar->days_forward($today, 0);
64
is($forwarded_dt->ymd, $today->ymd, '0 day should return start dt');
65
66
$forwarded_dt = $calendar->days_forward($today, -2);
67
is($forwarded_dt->ymd, $today->ymd, 'negative day should return start dt');
68
69
$schema->storage->txn_rollback();

Return to bug 12063