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

(-)a/C4/Reserves.pm (-4 / +102 lines)
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
(-)a/circ/waitingreserves.pl (-1 / +3 lines)
Lines 80-87 $template->param( all_branches => 1 ) if $all_branches; Link Here
80
80
81
my (@reservloop, @overloop);
81
my (@reservloop, @overloop);
82
my ($reservcount, $overcount);
82
my ($reservcount, $overcount);
83
my @getreserves = $all_branches ? GetReservesForBranch() : GetReservesForBranch($default);
84
# get reserves for the branch we are logged into, or for all branches
83
# get reserves for the branch we are logged into, or for all branches
84
my @getreserves = $all_branches ? GetReservesForBranch() : GetReservesForBranch($default);
85
my $expiredReserves = $all_branches ? C4::Reserves::GetExpiredReserves() : C4::Reserves::GetExpiredReserves({branchcode => $default});
86
push @getreserves, @$expiredReserves;
85
87
86
my $today = DateTime->now();
88
my $today = DateTime->now();
87
foreach my $num (@getreserves) {
89
foreach my $num (@getreserves) {
(-)a/installer/data/mysql/atomicupdate/Bug10744ExpireReservesConflictHoldOverReport.pl (+36 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright Open Source Freedom Fighters
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use C4::Context;
21
use Koha::AtomicUpdater;
22
23
my $dbh = C4::Context->dbh();
24
my $atomicUpdater = Koha::AtomicUpdater->new();
25
26
unless($atomicUpdater->find('Bug10744')) {
27
28
    $dbh->do("ALTER TABLE reserves ADD `pickupexpired` DATE DEFAULT NULL AFTER `expirationdate`");
29
    $dbh->do("ALTER TABLE reserves ADD KEY `reserves_pickupexpired` (`pickupexpired`)");
30
    $dbh->do("ALTER TABLE old_reserves ADD `pickupexpired` DATE DEFAULT NULL AFTER `expirationdate`");
31
    $dbh->do("ALTER TABLE old_reserves ADD KEY `old_reserves_pickupexpired` (`pickupexpired`)");
32
33
    $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('PickupExpiredHoldsOverReportDuration','1',NULL,\"For how many days holds expired by the 'ExpireReservesMaxPickUpDelay'-syspref are visible in the 'Hold Over'-tab in /circ/waitingreserves.pl ?\",'Integer')");
34
35
    print "Upgrade done (Bug 10744 - ExpireReservesMaxPickUpDelay has minor workflow conflicts with hold(s) over report)\n";
36
}
(-)a/installer/data/mysql/kohastructure.sql (+4 lines)
Lines 1708-1713 CREATE TABLE `old_reserves` ( -- this table holds all holds/reserves that have b Link Here
1708
  `itemnumber` int(11) default NULL, -- foreign key from the items table defining the specific item the patron has placed on hold or the item this hold was filled with
1708
  `itemnumber` int(11) default NULL, -- foreign key from the items table defining the specific item the patron has placed on hold or the item this hold was filled with
1709
  `waitingdate` date default NULL, -- the date the item was marked as waiting for the patron at the library
1709
  `waitingdate` date default NULL, -- the date the item was marked as waiting for the patron at the library
1710
  `expirationdate` DATE DEFAULT NULL, -- the date the hold expires (usually the date entered by the patron to say they don't need the hold after a certain date)
1710
  `expirationdate` DATE DEFAULT NULL, -- the date the hold expires (usually the date entered by the patron to say they don't need the hold after a certain date)
1711
  `pickupexpired` DATE DEFAULT NULL, -- if hold has been waiting but it expired before it was picked up, the expiration date is set here
1711
  `lowestPriority` tinyint(1) NOT NULL, -- has this hold been pinned to the lowest priority in the holds queue (1 for yes, 0 for no)
1712
  `lowestPriority` tinyint(1) NOT NULL, -- has this hold been pinned to the lowest priority in the holds queue (1 for yes, 0 for no)
1712
  `suspend` BOOLEAN NOT NULL DEFAULT 0, -- in this hold suspended (1 for yes, 0 for no)
1713
  `suspend` BOOLEAN NOT NULL DEFAULT 0, -- in this hold suspended (1 for yes, 0 for no)
1713
  `suspend_until` DATETIME NULL DEFAULT NULL, -- the date this hold is suspended until (NULL for infinitely)
1714
  `suspend_until` DATETIME NULL DEFAULT NULL, -- the date this hold is suspended until (NULL for infinitely)
Lines 1716-1721 CREATE TABLE `old_reserves` ( -- this table holds all holds/reserves that have b Link Here
1716
  KEY `old_reserves_biblionumber` (`biblionumber`),
1717
  KEY `old_reserves_biblionumber` (`biblionumber`),
1717
  KEY `old_reserves_itemnumber` (`itemnumber`),
1718
  KEY `old_reserves_itemnumber` (`itemnumber`),
1718
  KEY `old_reserves_branchcode` (`branchcode`),
1719
  KEY `old_reserves_branchcode` (`branchcode`),
1720
  KEY `old_reserves_pickupexpired` (`pickupexpired`),
1719
  CONSTRAINT `old_reserves_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`)
1721
  CONSTRAINT `old_reserves_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`)
1720
    ON DELETE SET NULL ON UPDATE SET NULL,
1722
    ON DELETE SET NULL ON UPDATE SET NULL,
1721
  CONSTRAINT `old_reserves_ibfk_2` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`)
1723
  CONSTRAINT `old_reserves_ibfk_2` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`)
Lines 1942-1947 CREATE TABLE `reserves` ( -- information related to holds/reserves in Koha Link Here
1942
  `itemnumber` int(11) default NULL, -- foreign key from the items table defining the specific item the patron has placed on hold or the item this hold was filled with
1944
  `itemnumber` int(11) default NULL, -- foreign key from the items table defining the specific item the patron has placed on hold or the item this hold was filled with
1943
  `waitingdate` date default NULL, -- the date the item was marked as waiting for the patron at the library
1945
  `waitingdate` date default NULL, -- the date the item was marked as waiting for the patron at the library
1944
  `expirationdate` DATE DEFAULT NULL, -- the date the hold expires (usually the date entered by the patron to say they don't need the hold after a certain date)
1946
  `expirationdate` DATE DEFAULT NULL, -- the date the hold expires (usually the date entered by the patron to say they don't need the hold after a certain date)
1947
  `pickupexpired` DATE DEFAULT NULL, -- if hold has been waiting but it expired before it was picked up, the expiration date is set here
1945
  `lowestPriority` tinyint(1) NOT NULL,
1948
  `lowestPriority` tinyint(1) NOT NULL,
1946
  `suspend` BOOLEAN NOT NULL DEFAULT 0,
1949
  `suspend` BOOLEAN NOT NULL DEFAULT 0,
1947
  `suspend_until` DATETIME NULL DEFAULT NULL,
1950
  `suspend_until` DATETIME NULL DEFAULT NULL,
Lines 1951-1956 CREATE TABLE `reserves` ( -- information related to holds/reserves in Koha Link Here
1951
  KEY `biblionumber` (`biblionumber`),
1954
  KEY `biblionumber` (`biblionumber`),
1952
  KEY `itemnumber` (`itemnumber`),
1955
  KEY `itemnumber` (`itemnumber`),
1953
  KEY `branchcode` (`branchcode`),
1956
  KEY `branchcode` (`branchcode`),
1957
  KEY `reserves_pickupexpired` (`pickupexpired`),
1954
  CONSTRAINT `reserves_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
1958
  CONSTRAINT `reserves_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
1955
  CONSTRAINT `reserves_ibfk_2` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE,
1959
  CONSTRAINT `reserves_ibfk_2` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE,
1956
  CONSTRAINT `reserves_ibfk_3` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE CASCADE ON UPDATE CASCADE,
1960
  CONSTRAINT `reserves_ibfk_3` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE CASCADE ON UPDATE CASCADE,
(-)a/installer/data/mysql/sysprefs.sql (+1 lines)
Lines 118-123 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
118
('EnhancedMessagingPreferences','0','','If ON, allows patrons to select to receive additional messages about items due or nearly due.','YesNo'),
118
('EnhancedMessagingPreferences','0','','If ON, allows patrons to select to receive additional messages about items due or nearly due.','YesNo'),
119
('expandedSearchOption','0',NULL,'If ON, set advanced search to be expanded by default','YesNo'),
119
('expandedSearchOption','0',NULL,'If ON, set advanced search to be expanded by default','YesNo'),
120
('ExpireReservesMaxPickUpDelay','0','','Enabling this allows holds to expire automatically if they have not been picked by within the time period specified in ReservesMaxPickUpDelay','YesNo'),
120
('ExpireReservesMaxPickUpDelay','0','','Enabling this allows holds to expire automatically if they have not been picked by within the time period specified in ReservesMaxPickUpDelay','YesNo'),
121
('PickupExpiredHoldsOverReportDuration','1',NULL,"For how many days holds expired by the 'ExpireReservesMaxPickUpDelay'-syspref are visible in the 'Hold Over'-tab in /circ/waitingreserves.pl ?",'Integer'),
121
('ExpireReservesMaxPickUpDelayCharge','0',NULL,'If ExpireReservesMaxPickUpDelay is enabled, and this field has a non-zero value, than a borrower whose waiting hold has expired will be charged this amount.','free'),
122
('ExpireReservesMaxPickUpDelayCharge','0',NULL,'If ExpireReservesMaxPickUpDelay is enabled, and this field has a non-zero value, than a borrower whose waiting hold has expired will be charged this amount.','free'),
122
('ExtendedPatronAttributes','0',NULL,'Use extended patron IDs and attributes','YesNo'),
123
('ExtendedPatronAttributes','0',NULL,'Use extended patron IDs and attributes','YesNo'),
123
('FacetLabelTruncationLength','20',NULL,'Specify the facet max length in OPAC','Integer'),
124
('FacetLabelTruncationLength','20',NULL,'Specify the facet max length in OPAC','Integer'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref (+4 lines)
Lines 416-421 Circulation: Link Here
416
            - pref: ExpireReservesMaxPickUpDelayCharge
416
            - pref: ExpireReservesMaxPickUpDelayCharge
417
              class: currency
417
              class: currency
418
        -
418
        -
419
            - pref: PickupExpiredHoldsOverReportDuration
420
              class: integer
421
            - "For how many days holds expired by the 'ExpireReservesMaxPickUpDelay'-syspref are visible in the 'Hold Over'-tab in /circ/waitingreserves.pl ?"
422
        -
419
            - Satisfy holds from the libraries
423
            - Satisfy holds from the libraries
420
            - pref: StaticHoldsQueueWeight
424
            - pref: StaticHoldsQueueWeight
421
              class: multi
425
              class: multi
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/waitingreserves.tt (-2 / +2 lines)
Lines 90-96 Link Here
90
                <tr>
90
                <tr>
91
                    <td class="waitingdate"><span title="[% reserveloo.waitingdate %]">[% reserveloo.waitingdate | $KohaDates %]</span></td>
91
                    <td class="waitingdate"><span title="[% reserveloo.waitingdate %]">[% reserveloo.waitingdate | $KohaDates %]</span></td>
92
                    <td class="lastpickupdate">[% reserveloo.lastpickupdate %]</td>
92
                    <td class="lastpickupdate">[% reserveloo.lastpickupdate %]</td>
93
                    <td class="title">[% INCLUDE 'biblio-default-view.inc' biblionumber = reserveloo.biblionumber %]
93
                    <td class="resobjects">[% INCLUDE 'biblio-default-view.inc' biblionumber = reserveloo.biblionumber %]
94
                        [% reserveloo.title |html %] [% reserveloo.subtitle |html %]
94
                        [% reserveloo.title |html %] [% reserveloo.subtitle |html %]
95
                        </a>
95
                        </a>
96
                            &nbsp; (<b>[% reserveloo.itemtype %]</b>)
96
                            &nbsp; (<b>[% reserveloo.itemtype %]</b>)
Lines 152-158 Link Here
152
                    <tr>
152
                    <tr>
153
                        <td class="waitingdate"><p><span title="[% overloo.waitingdate %]">[% overloo.waitingdate | $KohaDates %]</span></p></td>
153
                        <td class="waitingdate"><p><span title="[% overloo.waitingdate %]">[% overloo.waitingdate | $KohaDates %]</span></p></td>
154
                        <td class="lastpickupdate">[% overloo.lastpickupdate %]</td>
154
                        <td class="lastpickupdate">[% overloo.lastpickupdate %]</td>
155
                        <td class="title">[% INCLUDE 'biblio-default-view.inc' biblionumber = overloo.biblionumber %][% overloo.title |html %] [% overloo.subtitle |html %]
155
                        <td class="resobjects">[% INCLUDE 'biblio-default-view.inc' biblionumber = overloo.biblionumber %][% overloo.title |html %] [% overloo.subtitle |html %]
156
                        </a>
156
                        </a>
157
                            [% UNLESS ( item_level_itypes ) %][% IF ( overloo.itemtype ) %]&nbsp; (<b>[% overloo.itemtype %]</b>)[% END %][% END %]
157
                            [% UNLESS ( item_level_itypes ) %][% IF ( overloo.itemtype ) %]&nbsp; (<b>[% overloo.itemtype %]</b>)[% END %][% END %]
158
                        <br />Barcode: [% overloo.barcode %]
158
                        <br />Barcode: [% overloo.barcode %]
(-)a/t/db_dependent/Circulation/Waitingreserves.t (-4 / +10 lines)
Lines 79-85 sub settingUpTestContext { Link Here
79
             branchcode  => 'CPL',
79
             branchcode  => 'CPL',
80
             waitingdate => DateTime->now(time_zone => C4::Context->tz())->subtract(days => 8)->iso8601(),
80
             waitingdate => DateTime->now(time_zone => C4::Context->tz())->subtract(days => 8)->iso8601(),
81
             reservenotes => 'expire2daysAgo',
81
             reservenotes => 'expire2daysAgo',
82
             row         => 3, #for the following tests, this hold should be on row 3 in the holds over -table
83
            },
82
            },
84
            {cardnumber  => '1A01',
83
            {cardnumber  => '1A01',
85
             isbn        => '987Kivi',
84
             isbn        => '987Kivi',
Lines 87-93 sub settingUpTestContext { Link Here
87
             branchcode  => 'CPL',
86
             branchcode  => 'CPL',
88
             waitingdate => DateTime->now(time_zone => C4::Context->tz())->subtract(days => 7)->iso8601(),
87
             waitingdate => DateTime->now(time_zone => C4::Context->tz())->subtract(days => 7)->iso8601(),
89
             reservenotes => 'expire1dayAgo1',
88
             reservenotes => 'expire1dayAgo1',
90
             row         => 1, #for the following tests, this hold should be on row 3 in the holds over -table
91
            },
89
            },
92
            {cardnumber  => '1A01',
90
            {cardnumber  => '1A01',
93
             isbn        => '987Kivi',
91
             isbn        => '987Kivi',
Lines 95-101 sub settingUpTestContext { Link Here
95
             branchcode  => 'CPL',
93
             branchcode  => 'CPL',
96
             waitingdate => DateTime->now(time_zone => C4::Context->tz())->subtract(days => 7)->iso8601(),
94
             waitingdate => DateTime->now(time_zone => C4::Context->tz())->subtract(days => 7)->iso8601(),
97
             reservenotes => 'expire1dayAgo2',
95
             reservenotes => 'expire1dayAgo2',
98
             row         => 2, #for the following tests, this hold should be on row 3 in the holds over -table
99
            },
96
            },
100
            {cardnumber  => '1A01',
97
            {cardnumber  => '1A01',
101
             isbn        => '987Kivi',
98
             isbn        => '987Kivi',
Lines 113-118 sub settingUpTestContext { Link Here
113
            },
110
            },
114
        ], undef, $testContext);
111
        ], undef, $testContext);
115
112
113
        C4::Reserves::CancelExpiredReserves();
114
116
        ok(1, "Test context set without crashing");
115
        ok(1, "Test context set without crashing");
117
116
118
    };
117
    };
Lines 128-141 subtest "Display expired waiting reserves" => \&displayExpiredWaitingReserves; Link Here
128
sub displayExpiredWaitingReserves {
127
sub displayExpiredWaitingReserves {
129
    eval { #run in a eval-block so we don't die without tearing down the test context
128
    eval { #run in a eval-block so we don't die without tearing down the test context
130
129
130
        my $expectedExpiredHoldsInOrder = [
131
            $holds->{expire2daysAgo},
132
            $holds->{expire1dayAgo1},
133
            $holds->{expire1dayAgo2},
134
        ];
135
131
        my $waitingreserves = t::lib::Page::Circulation::Waitingreserves->new();
136
        my $waitingreserves = t::lib::Page::Circulation::Waitingreserves->new();
132
        $waitingreserves->doPasswordLogin($borrowers->{'1A01'}->userid(), $password)
137
        $waitingreserves->doPasswordLogin($borrowers->{'1A01'}->userid(), $password)
133
            ->showHoldsOver()->assertHoldRowsVisible($holds)
138
            ->showHoldsOver()->assertHoldRowsVisible($expectedExpiredHoldsInOrder)
134
            ->doPasswordLogout();
139
            ->doPasswordLogout();
135
        $waitingreserves->quit();
140
        $waitingreserves->quit();
136
141
137
    };
142
    };
138
    if ($@) { #Catch all leaking errors and gracefully terminate.
143
    if ($@) { #Catch all leaking errors and gracefully terminate.
144
        ok(0, "Subtest crashed");
139
        warn $@;
145
        warn $@;
140
    }
146
    }
141
}
147
}
(-)a/t/db_dependent/Reserves/pickupExpiredHoldsOverReportDuration.t (-1 / +124 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# Copyright 2015 KohaSuomi
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
use Test::More;
22
use Try::Tiny;
23
use Scalar::Util qw(blessed);
24
25
use t::lib::TestObjects::ObjectFactory;
26
use t::lib::TestObjects::HoldFactory;
27
use t::lib::TestObjects::SystemPreferenceFactory;
28
use Koha::Calendar;
29
30
##Setting up the test context
31
my $testContext = {};
32
my $calendar = Koha::Calendar->new(branchcode => 'CPL');
33
$calendar->add_holiday( DateTime->now(time_zone => C4::Context->tz())->subtract(days => 2) ); #Day before yesterday is a holiday.
34
35
t::lib::TestObjects::SystemPreferenceFactory->createTestGroup([{preference => 'PickupExpiredHoldsOverReportDuration',
36
                                                                value => 2,
37
                                                               },
38
                                                               {preference => 'ExpireReservesMaxPickUpDelay',
39
                                                                value => 1,
40
                                                               },
41
                                                               {preference => 'ReservesMaxPickUpDelay',
42
                                                                value => 6,
43
                                                               },
44
                                                              ], undef, $testContext);
45
46
my $holds = t::lib::TestObjects::HoldFactory->createTestGroup([
47
            {cardnumber  => '1A01',
48
             isbn        => '987Kivi',
49
             barcode     => '1N01',
50
             branchcode  => 'CPL',
51
             waitingdate => DateTime->now(time_zone => C4::Context->tz())->subtract(days => 9)->iso8601(),
52
             reservenotes => 'expire3daysAgo',
53
            },
54
            {cardnumber  => '1A01',
55
             isbn        => '987Kivi',
56
             barcode     => '1N02',
57
             branchcode  => 'CPL',
58
             waitingdate => DateTime->now(time_zone => C4::Context->tz())->subtract(days => 8)->iso8601(),
59
             reservenotes => 'expire2daysAgo',
60
            },
61
            {cardnumber  => '1A02',
62
             isbn        => '987Kivi',
63
             barcode     => '1N03',
64
             branchcode  => 'CPL',
65
             waitingdate => DateTime->now(time_zone => C4::Context->tz())->subtract(days => 7)->iso8601(),
66
             reservenotes => 'expire1dayAgo1',
67
            },
68
            {cardnumber  => '1A03',
69
             isbn        => '987Kivi',
70
             barcode     => '1N04',
71
             branchcode  => 'CPL',
72
             waitingdate => DateTime->now(time_zone => C4::Context->tz())->subtract(days => 7)->iso8601(),
73
             reservenotes => 'expire1dayAgo2',
74
            },
75
            {cardnumber  => '1A04',
76
             isbn        => '987Kivi',
77
             barcode     => '1N05',
78
             branchcode  => 'CPL',
79
             waitingdate => DateTime->now(time_zone => C4::Context->tz())->subtract(days => 6)->iso8601(),
80
             reservenotes => 'expiresToday',
81
            },
82
            {cardnumber  => '1A05',
83
             isbn        => '987Kivi',
84
             barcode     => '1N06',
85
             branchcode  => 'CPL',
86
             waitingdate => DateTime->now(time_zone => C4::Context->tz())->subtract(days => 5)->iso8601(),
87
             reservenotes => 'expiresTomorrow',
88
            },
89
        ], undef, $testContext);
90
91
92
93
##Test context set, starting testing:
94
subtest "Expiring holds and getting old_reserves" => \&expiringHoldsAndOld_reserves;
95
sub expiringHoldsAndOld_reserves {
96
    eval { #run in a eval-block so we don't die without tearing down the test context
97
        C4::Reserves::CancelExpiredReserves();
98
        my $expiredReserves = C4::Reserves::GetExpiredReserves({branchcode => 'CPL'});
99
        ok($expiredReserves->[0]->{reserve_id} == $holds->{'expire2daysAgo'}->{reserve_id} &&
100
           $expiredReserves->[0]->{pickupexpired} eq DateTime->now(time_zone => C4::Context->tz())->subtract(days => 2)->ymd()
101
           , "Hold for Item 1N02 expired yesterday");
102
        ok($expiredReserves->[1]->{reserve_id} == $holds->{'expire1dayAgo1'}->{reserve_id} &&
103
           $expiredReserves->[1]->{pickupexpired} eq DateTime->now(time_zone => C4::Context->tz())->subtract(days => 1)->ymd()
104
           , "Hold for Item 1N03 expired today");
105
        ok($expiredReserves->[2]->{reserve_id} == $holds->{'expire1dayAgo2'}->{reserve_id} &&
106
           $expiredReserves->[2]->{pickupexpired} eq DateTime->now(time_zone => C4::Context->tz())->subtract(days => 1)->ymd()
107
           , "Hold for Item 1N04 expired today");
108
        is($expiredReserves->[3], undef,
109
           "Holds for Items 1N05 and 1N06 not expired.");
110
    };
111
    if ($@) { #Catch all leaking errors and gracefully terminate.
112
        warn $@;
113
        tearDown();
114
        exit 1;
115
    }
116
}
117
118
##All tests done, tear down test context
119
tearDown();
120
done_testing;
121
122
sub tearDown {
123
    t::lib::TestObjects::ObjectFactory->tearDownTestContext($testContext);
124
}

Return to bug 10744