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

(-)a/C4/Reserves.pm (-4 / +78 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({branchcode => 'CPL',
798
                                                            from => DateTime->new(...),
799
                                                            to   => DateTime->now(),
800
                                                        });
801
802
@RETURNS ARRAYRef of expired reserves from the given duration. Defaults to this day.
803
=cut
804
805
sub GetExpiredReserves {
806
    my ($params) = @_;
807
    my $branchcode = $params->{branchcode};
808
    if ($params->{from}) {
809
        unless (blessed($params->{from}) && $params->{from}->isa('DateTime')) {
810
            Koha::Exception::BadParameter->throw(error => "GetExpiredReserves():> Parameter 'from' is not a DateTime-object or undef!");
811
        }
812
    }
813
    if ($params->{to}) {
814
        unless (blessed($params->{from}) && $params->{from}->isa('DateTime')) {
815
            Koha::Exception::BadParameter->throw(error => "GetExpiredReserves():> Parameter 'from' is not a DateTime-object or undef!");
816
        }
817
    }
818
819
    my $fromDate   = $params->{from} || DateTime->now(time_zone => C4::Context->tz())->subtract(days => 1);
820
    my $toDate     = $params->{to}   || DateTime->now(time_zone => C4::Context->tz());
821
822
    my $dbh = C4::Context->dbh;
823
824
    my @params = ($fromDate->ymd(), $toDate->ymd());
825
    my $query = "
826
        SELECT *
827
        FROM   old_reserves 
828
        WHERE   priority='0'
829
        AND pickupexpired BETWEEN ? AND ?
830
    ";
831
    if ( $branchcode ) {
832
        push @params, $branchcode;
833
        $query .= " AND branchcode=? ";
834
    }
835
    $query .= "ORDER BY waitingdate" ;
836
837
    my $sth = $dbh->prepare($query);
838
    $sth->execute(@params);
839
840
    my $data = $sth->fetchall_arrayref({});
841
    return ($data);
842
}
843
794
=head2 GetReserveStatus
844
=head2 GetReserveStatus
795
845
796
  $reservestatus = GetReserveStatus($itemnumber, $biblionumber);
846
  $reservestatus = GetReserveStatus($itemnumber, $biblionumber);
Lines 1021-1027 sub CancelExpiredReserves { Link Here
1021
                if ( $charge ) {
1071
                if ( $charge ) {
1022
                    manualinvoice($res->{'borrowernumber'}, $res->{'itemnumber'}, 'Hold waiting too long', 'F', $charge);
1072
                    manualinvoice($res->{'borrowernumber'}, $res->{'itemnumber'}, 'Hold waiting too long', 'F', $charge);
1023
                }
1073
                }
1024
                CancelReserve({ reserve_id => $res->{'reserve_id'} });
1074
                CancelReserve({ reserve_id => $res->{'reserve_id'},
1075
                                pickupexpired => $expiration,
1076
                            });
1025
                push @sb, printReserve($res,'tab',['reserve_id','borrowernumber','branchcode','waitingdate']).sprintf("% 14s",substr($expiration,0,10))."| past lastpickupdate.\n" if $verbose;
1077
                push @sb, printReserve($res,'tab',['reserve_id','borrowernumber','branchcode','waitingdate']).sprintf("% 14s",substr($expiration,0,10))."| past lastpickupdate.\n" if $verbose;
1026
            }
1078
            }
1027
            elsif($verbose > 1) {
1079
            elsif($verbose > 1) {
Lines 1064-1070 sub AutoUnsuspendReserves { Link Here
1064
1116
1065
=head2 CancelReserve
1117
=head2 CancelReserve
1066
1118
1067
  CancelReserve({ reserve_id => $reserve_id, [ biblionumber => $biblionumber, borrowernumber => $borrrowernumber, itemnumber => $itemnumber ] });
1119
  CancelReserve({ reserve_id => $reserve_id,
1120
                  [ biblionumber => $biblionumber,
1121
                    borrowernumber => $borrrowernumber,
1122
                    itemnumber => $itemnumber ],
1123
                  pickupexpired => DateTime->new(year => 2015, ...), #If the reserve was waiting for pickup, set the date the pickup wait period expired.
1124
                });
1068
1125
1069
Cancels a reserve.
1126
Cancels a reserve.
1070
1127
Lines 1074-1079 sub CancelReserve { Link Here
1074
    my ( $params ) = @_;
1131
    my ( $params ) = @_;
1075
1132
1076
    my $reserve_id = $params->{'reserve_id'};
1133
    my $reserve_id = $params->{'reserve_id'};
1134
    my $pickupexpired = $params->{pickupexpired};
1135
    if ($pickupexpired) {
1136
        unless (blessed($pickupexpired) && $pickupexpired->isa('DateTime')) {
1137
            Koha::Exception::BadParameter->throw(error => "CancelReserve():> Parameter 'pickupexpired' is not a DateTime-object or undef!");
1138
        }
1139
    }
1140
1077
    $reserve_id = GetReserveId( $params ) unless ( $reserve_id );
1141
    $reserve_id = GetReserveId( $params ) unless ( $reserve_id );
1078
1142
1079
    return unless ( $reserve_id );
1143
    return unless ( $reserve_id );
Lines 1082-1096 sub CancelReserve { Link Here
1082
1146
1083
    my $reserve = GetReserve( $reserve_id );
1147
    my $reserve = GetReserve( $reserve_id );
1084
1148
1149
    my @params;
1085
    my $query = "
1150
    my $query = "
1086
        UPDATE reserves
1151
        UPDATE reserves
1087
        SET    cancellationdate = now(),
1152
        SET    cancellationdate = DATE(NOW()),
1088
               found            = Null,
1153
               found            = Null,
1154
    ";
1155
    if ($pickupexpired) {
1156
        push @params, $pickupexpired->ymd();
1157
        $query .= "
1158
               pickupexpired    = ?,
1159
        ";
1160
    }
1161
    push @params, $reserve_id;
1162
    $query .= "
1089
               priority         = 0
1163
               priority         = 0
1090
        WHERE  reserve_id = ?
1164
        WHERE  reserve_id = ?
1091
    ";
1165
    ";
1092
    my $sth = $dbh->prepare($query);
1166
    my $sth = $dbh->prepare($query);
1093
    $sth->execute( $reserve_id );
1167
    $sth->execute( @params );
1094
1168
1095
    $query = "
1169
    $query = "
1096
        INSERT INTO old_reserves
1170
        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 (+34 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
    print "Upgrade done (Bug 10744 - ExpireReservesMaxPickUpDelay has minor workflow conflicts with hold(s) over report)\n";
34
}
(-)a/installer/data/mysql/kohastructure.sql (-1 / +4 lines)
Lines 1706-1711 CREATE TABLE `old_reserves` ( -- this table holds all holds/reserves that have b Link Here
1706
  `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
1706
  `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
1707
  `waitingdate` date default NULL, -- the date the item was marked as waiting for the patron at the library
1707
  `waitingdate` date default NULL, -- the date the item was marked as waiting for the patron at the library
1708
  `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)
1708
  `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)
1709
  `pickupexpired` DATE DEFAULT NULL, -- if hold has been waiting but it expired before it was picked up, the expiration date is set here
1709
  `lowestPriority` tinyint(1) NOT NULL, -- has this hold been pinned to the lowest priority in the holds queue (1 for yes, 0 for no)
1710
  `lowestPriority` tinyint(1) NOT NULL, -- has this hold been pinned to the lowest priority in the holds queue (1 for yes, 0 for no)
1710
  `suspend` BOOLEAN NOT NULL DEFAULT 0, -- in this hold suspended (1 for yes, 0 for no)
1711
  `suspend` BOOLEAN NOT NULL DEFAULT 0, -- in this hold suspended (1 for yes, 0 for no)
1711
  `suspend_until` DATETIME NULL DEFAULT NULL, -- the date this hold is suspended until (NULL for infinitely)
1712
  `suspend_until` DATETIME NULL DEFAULT NULL, -- the date this hold is suspended until (NULL for infinitely)
Lines 1714-1719 CREATE TABLE `old_reserves` ( -- this table holds all holds/reserves that have b Link Here
1714
  KEY `old_reserves_biblionumber` (`biblionumber`),
1715
  KEY `old_reserves_biblionumber` (`biblionumber`),
1715
  KEY `old_reserves_itemnumber` (`itemnumber`),
1716
  KEY `old_reserves_itemnumber` (`itemnumber`),
1716
  KEY `old_reserves_branchcode` (`branchcode`),
1717
  KEY `old_reserves_branchcode` (`branchcode`),
1718
  KEY `old_reserves_pickupexpired` (`pickupexpired`),
1717
  CONSTRAINT `old_reserves_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`)
1719
  CONSTRAINT `old_reserves_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`)
1718
    ON DELETE SET NULL ON UPDATE SET NULL,
1720
    ON DELETE SET NULL ON UPDATE SET NULL,
1719
  CONSTRAINT `old_reserves_ibfk_2` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`)
1721
  CONSTRAINT `old_reserves_ibfk_2` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`)
Lines 1940-1945 CREATE TABLE `reserves` ( -- information related to holds/reserves in Koha Link Here
1940
  `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
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
1941
  `waitingdate` date default NULL, -- the date the item was marked as waiting for the patron at the library
1943
  `waitingdate` date default NULL, -- the date the item was marked as waiting for the patron at the library
1942
  `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)
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)
1945
  `pickupexpired` DATE DEFAULT NULL, -- if hold has been waiting but it expired before it was picked up, the expiration date is set here
1943
  `lowestPriority` tinyint(1) NOT NULL,
1946
  `lowestPriority` tinyint(1) NOT NULL,
1944
  `suspend` BOOLEAN NOT NULL DEFAULT 0,
1947
  `suspend` BOOLEAN NOT NULL DEFAULT 0,
1945
  `suspend_until` DATETIME NULL DEFAULT NULL,
1948
  `suspend_until` DATETIME NULL DEFAULT NULL,
Lines 1949-1954 CREATE TABLE `reserves` ( -- information related to holds/reserves in Koha Link Here
1949
  KEY `biblionumber` (`biblionumber`),
1952
  KEY `biblionumber` (`biblionumber`),
1950
  KEY `itemnumber` (`itemnumber`),
1953
  KEY `itemnumber` (`itemnumber`),
1951
  KEY `branchcode` (`branchcode`),
1954
  KEY `branchcode` (`branchcode`),
1955
  KEY `reserves_pickupexpired` (`pickupexpired`),
1952
  CONSTRAINT `reserves_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
1956
  CONSTRAINT `reserves_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
1953
  CONSTRAINT `reserves_ibfk_2` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE,
1957
  CONSTRAINT `reserves_ibfk_2` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE,
1954
  CONSTRAINT `reserves_ibfk_3` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE CASCADE ON UPDATE CASCADE,
1958
  CONSTRAINT `reserves_ibfk_3` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE CASCADE ON UPDATE CASCADE,
1955
- 

Return to bug 10744