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

(-)a/C4/HoldsQueue.pm (+5 lines)
Lines 26-31 use C4::Context; Link Here
26
use C4::Circulation qw( GetBranchItemRule );
26
use C4::Circulation qw( GetBranchItemRule );
27
use Koha::DateUtils qw( dt_from_string );
27
use Koha::DateUtils qw( dt_from_string );
28
use Koha::Hold::HoldsQueueItems;
28
use Koha::Hold::HoldsQueueItems;
29
use Koha::HoldGroup;
29
use Koha::Items;
30
use Koha::Items;
30
use Koha::Libraries;
31
use Koha::Libraries;
31
use Koha::Logger;
32
use Koha::Logger;
Lines 250-255 that have one or more unfilled hold requests. Link Here
250
sub GetBibsWithPendingHoldRequests {
251
sub GetBibsWithPendingHoldRequests {
251
    my $dbh = C4::Context->dbh;
252
    my $dbh = C4::Context->dbh;
252
253
254
    my $skip_non_target_holds_query     = Koha::HoldGroup::skip_non_target_holds_query('sql');
255
    my $skip_non_target_holds_query_sql = $skip_non_target_holds_query ? " $skip_non_target_holds_query" : '';
256
253
    my $bib_query = "SELECT DISTINCT biblionumber
257
    my $bib_query = "SELECT DISTINCT biblionumber
254
                     FROM reserves
258
                     FROM reserves
255
                     WHERE found IS NULL
259
                     WHERE found IS NULL
Lines 257-262 sub GetBibsWithPendingHoldRequests { Link Here
257
                     AND reservedate <= CURRENT_DATE()
261
                     AND reservedate <= CURRENT_DATE()
258
                     AND suspend = 0
262
                     AND suspend = 0
259
                     AND reserve_id NOT IN (SELECT reserve_id FROM hold_fill_targets)
263
                     AND reserve_id NOT IN (SELECT reserve_id FROM hold_fill_targets)
264
                     $skip_non_target_holds_query_sql
260
                     ";
265
                     ";
261
    my $sth = $dbh->prepare($bib_query);
266
    my $sth = $dbh->prepare($bib_query);
262
267
(-)a/C4/Reserves.pm (-10 / +12 lines)
Lines 40-45 use Koha::CirculationRules; Link Here
40
use Koha::Database;
40
use Koha::Database;
41
use Koha::DateUtils qw( dt_from_string output_pref );
41
use Koha::DateUtils qw( dt_from_string output_pref );
42
use Koha::Holds;
42
use Koha::Holds;
43
use Koha::HoldGroup;
43
use Koha::ItemTypes;
44
use Koha::ItemTypes;
44
use Koha::Items;
45
use Koha::Items;
45
use Koha::Libraries;
46
use Koha::Libraries;
Lines 1244-1249 sub ModReserveAffect { Link Here
1244
1245
1245
    if ($transferToDo) {
1246
    if ($transferToDo) {
1246
        $hold->set_transfer();
1247
        $hold->set_transfer();
1248
        $hold->set_as_hold_group_target();
1247
    } elsif ( C4::Context->preference('HoldsNeedProcessingSIP')
1249
    } elsif ( C4::Context->preference('HoldsNeedProcessingSIP')
1248
        && C4::Context->interface eq 'sip'
1250
        && C4::Context->interface eq 'sip'
1249
        && !$already_on_shelf )
1251
        && !$already_on_shelf )
Lines 1257-1270 sub ModReserveAffect { Link Here
1257
        my $transfer = $hold->item->get_transfer;
1259
        my $transfer = $hold->item->get_transfer;
1258
        $transfer->receive if $transfer;
1260
        $transfer->receive if $transfer;
1259
1261
1260
        # if this hold was part of a group, cancel other holds in the group
1262
        $hold->set_as_hold_group_target();
1261
        if ( $hold->hold_group_id ) {
1262
            my @holds = $hold->hold_group->holds->as_list;
1263
            foreach my $h (@holds) {
1264
                push @reserve_ids, $h->reserve_id;
1265
                $h->cancel unless $h->reserve_id == $hold->reserve_id;
1266
            }
1267
        }
1268
    }
1263
    }
1269
1264
1270
    _koha_notify_hold_changed($hold) if $notify_library;
1265
    _koha_notify_hold_changed($hold) if $notify_library;
Lines 1753-1758 sub _Findgroupreserve { Link Here
1753
    my ( $biblionumber, $itemnumber, $lookahead, $ignore_borrowers ) = @_;
1748
    my ( $biblionumber, $itemnumber, $lookahead, $ignore_borrowers ) = @_;
1754
    my $dbh = C4::Context->dbh;
1749
    my $dbh = C4::Context->dbh;
1755
1750
1751
    my $skip_non_target_holds_query     = Koha::HoldGroup::skip_non_target_holds_query('sql');
1752
    my $skip_non_target_holds_query_sql = $skip_non_target_holds_query ? " $skip_non_target_holds_query" : '';
1753
1756
    # check for targeted match form the holds queue
1754
    # check for targeted match form the holds queue
1757
    my $hold_target_query = qq{
1755
    my $hold_target_query = qq{
1758
        SELECT reserves.biblionumber        AS biblionumber,
1756
        SELECT reserves.biblionumber        AS biblionumber,
Lines 1769-1775 sub _Findgroupreserve { Link Here
1769
               reserves.reserve_id          AS reserve_id,
1767
               reserves.reserve_id          AS reserve_id,
1770
               reserves.itemtype            AS itemtype,
1768
               reserves.itemtype            AS itemtype,
1771
               reserves.non_priority        AS non_priority,
1769
               reserves.non_priority        AS non_priority,
1772
               reserves.item_group_id           AS item_group_id
1770
               reserves.item_group_id       AS item_group_id,
1771
               reserves.hold_group_id       AS hold_group_id
1773
        FROM reserves
1772
        FROM reserves
1774
        JOIN biblioitems USING (biblionumber)
1773
        JOIN biblioitems USING (biblionumber)
1775
        JOIN hold_fill_targets USING (reserve_id)
1774
        JOIN hold_fill_targets USING (reserve_id)
Lines 1778-1783 sub _Findgroupreserve { Link Here
1778
        AND hold_fill_targets.itemnumber = ?
1777
        AND hold_fill_targets.itemnumber = ?
1779
        AND reservedate <= DATE_ADD(NOW(),INTERVAL ? DAY)
1778
        AND reservedate <= DATE_ADD(NOW(),INTERVAL ? DAY)
1780
        AND suspend = 0
1779
        AND suspend = 0
1780
        $skip_non_target_holds_query_sql
1781
        ORDER BY priority
1781
        ORDER BY priority
1782
    };
1782
    };
1783
    my $sth = $dbh->prepare($hold_target_query);
1783
    my $sth = $dbh->prepare($hold_target_query);
Lines 1804-1815 sub _Findgroupreserve { Link Here
1804
               reserves.reserve_id                 AS reserve_id,
1804
               reserves.reserve_id                 AS reserve_id,
1805
               reserves.itemtype                   AS itemtype,
1805
               reserves.itemtype                   AS itemtype,
1806
               reserves.non_priority               AS non_priority,
1806
               reserves.non_priority               AS non_priority,
1807
               reserves.item_group_id              AS item_group_id
1807
               reserves.item_group_id              AS item_group_id,
1808
               reserves.hold_group_id              AS hold_group_id
1808
        FROM reserves
1809
        FROM reserves
1809
        WHERE reserves.biblionumber = ?
1810
        WHERE reserves.biblionumber = ?
1810
          AND (reserves.itemnumber IS NULL OR reserves.itemnumber = ?)
1811
          AND (reserves.itemnumber IS NULL OR reserves.itemnumber = ?)
1811
          AND reserves.reservedate <= DATE_ADD(NOW(),INTERVAL ? DAY)
1812
          AND reserves.reservedate <= DATE_ADD(NOW(),INTERVAL ? DAY)
1812
          AND suspend = 0
1813
          AND suspend = 0
1814
          $skip_non_target_holds_query_sql
1813
          ORDER BY priority
1815
          ORDER BY priority
1814
    };
1816
    };
1815
    $sth = $dbh->prepare($query);
1817
    $sth = $dbh->prepare($query);
(-)a/Koha/Hold.pm (+19 lines)
Lines 200-205 sub cleanup_hold_group { Link Here
200
    }
200
    }
201
}
201
}
202
202
203
=head3 set_as_hold_group_target
204
205
$self->set_as_hold_group_target;
206
207
Sets this hold and its' hold group's target
208
209
=cut
210
211
sub set_as_hold_group_target {
212
    my ($self) = @_;
213
214
    if ( $self->hold_group && !$self->hold_group->target_hold_id && C4::Context->preference("DisplayAddHoldGroups") ) {
215
        $self->_result->create_related(
216
            'hold_group_target_hold',
217
            { hold_group_id => $self->hold_group->hold_group_id }
218
        );
219
    }
220
}
221
203
=head3 is_hold_group_target
222
=head3 is_hold_group_target
204
223
205
$self->is_hold_group_target;
224
$self->is_hold_group_target;
(-)a/Koha/HoldGroup.pm (+35 lines)
Lines 94-99 sub target_hold_id { Link Here
94
    return $self->_result->hold_group_target_hold->reserve_id;
94
    return $self->_result->hold_group_target_hold->reserve_id;
95
}
95
}
96
96
97
=head3 skip_non_target_holds_query
98
99
    $where{'me.hold_group_id'} = Koha::HoldGroup::skip_non_target_holds_query('dbix')
100
101
Static method, returns the query part be added if DisplayAddHoldGroups
102
Accepts a $query_type of 'dbix' or 'sql' and returns the respective query
103
The query is designed to skip non target holds that are part of a hold group which already has a hold target
104
105
=cut
106
107
sub skip_non_target_holds_query {
108
    my ($query_type) = @_;
109
110
    return unless C4::Context->preference('DisplayAddHoldGroups');
111
112
    my $query_types = {
113
        'dbix' => [
114
            -or => { '=' => undef },
115
            [
116
                -and => { '!=' => undef },
117
                {
118
                    -not_in => \
119
                        'SELECT hold_group_id FROM hold_group_target_holds WHERE reserve_id IS NOT NULL AND hold_group_id IS NOT NULL'
120
                }
121
            ]
122
        ],
123
        'sql' =>
124
            'AND (hold_group_id IS NULL OR hold_group_id IS NOT NULL AND reserves.hold_group_id NOT IN (SELECT hold_group_id FROM hold_group_target_holds WHERE reserve_id IS NOT NULL AND hold_group_id IS NOT NULL))'
125
    };
126
127
    return unless $query_type && exists $query_types->{$query_type};
128
129
    return $query_types->{$query_type};
130
}
131
97
=head3 _type
132
=head3 _type
98
133
99
=cut
134
=cut
(-)a/circ/pendingreserves.pl (-2 / +9 lines)
Lines 31-36 use C4::Items; Link Here
31
use Koha::Biblios;
31
use Koha::Biblios;
32
use Koha::DateUtils qw( dt_from_string );
32
use Koha::DateUtils qw( dt_from_string );
33
use Koha::Holds;
33
use Koha::Holds;
34
use Koha::HoldGroup;
34
use DateTime::Duration;
35
use DateTime::Duration;
35
36
36
my $input          = CGI->new;
37
my $input          = CGI->new;
Lines 182-187 if ( C4::Context->only_my_library() ) { Link Here
182
    $where{'me.branchcode'} = C4::Context->userenv->{'branch'};
183
    $where{'me.branchcode'} = C4::Context->userenv->{'branch'};
183
}
184
}
184
185
186
my $skip_non_target_holds_query = Koha::HoldGroup::skip_non_target_holds_query('dbix');
187
$where{'me.hold_group_id'} = $skip_non_target_holds_query if $skip_non_target_holds_query;
188
185
# get all distinct unfulfilled reserves
189
# get all distinct unfulfilled reserves
186
my $holds = Koha::Holds->search(
190
my $holds = Koha::Holds->search(
187
    {%where},
191
    {%where},
Lines 200-206 if ( $holds->count ) { Link Here
200
# patrons count per biblio
204
# patrons count per biblio
201
my $patrons_count = {
205
my $patrons_count = {
202
    map { $_->{biblionumber} => $_->{patrons_count} } @{ Koha::Holds->search(
206
    map { $_->{biblionumber} => $_->{patrons_count} } @{ Koha::Holds->search(
203
            { 'suspend' => 0, 'found' => undef },
207
            {
208
                'suspend' => 0,
209
                'found'   => undef,
210
                $skip_non_target_holds_query ? ( 'hold_group_id' => $skip_non_target_holds_query ) : ()
211
            },
204
            {
212
            {
205
                select   => [ 'biblionumber', { count => { distinct => 'borrowernumber' } } ],
213
                select   => [ 'biblionumber', { count => { distinct => 'borrowernumber' } } ],
206
                as       => [qw( biblionumber patrons_count )],
214
                as       => [qw( biblionumber patrons_count )],
207
- 

Return to bug 40529