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

(-)a/C4/Circulation.pm (-4 / +6 lines)
Lines 1675-1691 sub GetBranchItemRule { Link Here
1675
    my $result = {};
1675
    my $result = {};
1676
1676
1677
    my @attempts = (
1677
    my @attempts = (
1678
        ['SELECT holdallowed, returnbranch
1678
        ['SELECT holdallowed, returnbranch, hold_fulfillment_policy
1679
            FROM branch_item_rules
1679
            FROM branch_item_rules
1680
            WHERE branchcode = ?
1680
            WHERE branchcode = ?
1681
              AND itemtype = ?', $branchcode, $itemtype],
1681
              AND itemtype = ?', $branchcode, $itemtype],
1682
        ['SELECT holdallowed, returnbranch
1682
        ['SELECT holdallowed, returnbranch, hold_fulfillment_policy
1683
            FROM default_branch_circ_rules
1683
            FROM default_branch_circ_rules
1684
            WHERE branchcode = ?', $branchcode],
1684
            WHERE branchcode = ?', $branchcode],
1685
        ['SELECT holdallowed, returnbranch
1685
        ['SELECT holdallowed, returnbranch, hold_fulfillment_policy
1686
            FROM default_branch_item_rules
1686
            FROM default_branch_item_rules
1687
            WHERE itemtype = ?', $itemtype],
1687
            WHERE itemtype = ?', $itemtype],
1688
        ['SELECT holdallowed, returnbranch
1688
        ['SELECT holdallowed, returnbranch, hold_fulfillment_policy
1689
            FROM default_circ_rules'],
1689
            FROM default_circ_rules'],
1690
    );
1690
    );
1691
1691
Lines 1698-1708 sub GetBranchItemRule { Link Here
1698
        # defaults tables, we have to check that the key we want is set, not
1698
        # defaults tables, we have to check that the key we want is set, not
1699
        # just that a row was returned
1699
        # just that a row was returned
1700
        $result->{'holdallowed'}  = $search_result->{'holdallowed'}  unless ( defined $result->{'holdallowed'} );
1700
        $result->{'holdallowed'}  = $search_result->{'holdallowed'}  unless ( defined $result->{'holdallowed'} );
1701
        $result->{'hold_fulfillment_policy'} = $search_result->{'hold_fulfillment_policy'} unless ( defined $result->{'hold_fulfillment_policy'} );
1701
        $result->{'returnbranch'} = $search_result->{'returnbranch'} unless ( defined $result->{'returnbranch'} );
1702
        $result->{'returnbranch'} = $search_result->{'returnbranch'} unless ( defined $result->{'returnbranch'} );
1702
    }
1703
    }
1703
    
1704
    
1704
    # built-in default circulation rule
1705
    # built-in default circulation rule
1705
    $result->{'holdallowed'} = 2 unless ( defined $result->{'holdallowed'} );
1706
    $result->{'holdallowed'} = 2 unless ( defined $result->{'holdallowed'} );
1707
    $result->{'hold_fulfillment_policy'} = 'any' unless ( defined $result->{'hold_fulfillment_policy'} );
1706
    $result->{'returnbranch'} = 'homebranch' unless ( defined $result->{'returnbranch'} );
1708
    $result->{'returnbranch'} = 'homebranch' unless ( defined $result->{'returnbranch'} );
1707
1709
1708
    return $result;
1710
    return $result;
(-)a/C4/HoldsQueue.pm (-11 / +43 lines)
Lines 343-348 sub GetItemsAvailableToFillHoldRequestsForBib { Link Here
343
    return [ grep {
343
    return [ grep {
344
        my $rule = GetBranchItemRule($_->{homebranch}, $_->{itype});
344
        my $rule = GetBranchItemRule($_->{homebranch}, $_->{itype});
345
        $_->{holdallowed} = $rule->{holdallowed};
345
        $_->{holdallowed} = $rule->{holdallowed};
346
        $_->{hold_fulfillment_policy} = $rule->{hold_fulfillment_policy};
346
    } @items ];
347
    } @items ];
347
}
348
}
348
349
Lines 381-398 sub MapItemsToHoldRequests { Link Here
381
        # is this an item-level request?
382
        # is this an item-level request?
382
        if (defined($request->{itemnumber})) {
383
        if (defined($request->{itemnumber})) {
383
            # fill it if possible; if not skip it
384
            # fill it if possible; if not skip it
384
            if (exists $items_by_itemnumber{$request->{itemnumber}} and
385
            if (
385
                not exists $allocated_items{$request->{itemnumber}}) {
386
                    exists $items_by_itemnumber{ $request->{itemnumber} }
386
                $item_map{$request->{itemnumber}} = {
387
                and not exists $allocated_items{ $request->{itemnumber} }
388
                and ( # Don't fill item level holds that contravene the hold pickup policy at this time
389
                    ( $items_by_itemnumber{ $request->{itemnumber} }->{hold_fulfillment_policy} eq 'any' )
390
                    || ( $request->{branchcode} eq $items_by_itemnumber{ $request->{itemnumber} }->{ $items_by_itemnumber{ $request->{itemnumber} }->{hold_fulfillment_policy} }  )
391
                )
392
393
              )
394
            {
395
396
                $item_map{ $request->{itemnumber} } = {
387
                    borrowernumber => $request->{borrowernumber},
397
                    borrowernumber => $request->{borrowernumber},
388
                    biblionumber => $request->{biblionumber},
398
                    biblionumber   => $request->{biblionumber},
389
                    holdingbranch =>  $items_by_itemnumber{$request->{itemnumber}}->{holdingbranch},
399
                    holdingbranch  => $items_by_itemnumber{ $request->{itemnumber} }->{holdingbranch},
390
                    pickup_branch => $request->{branchcode} || $request->{borrowerbranch},
400
                    pickup_branch  => $request->{branchcode} || $request->{borrowerbranch},
391
                    item_level => 1,
401
                    item_level     => 1,
392
                    reservedate => $request->{reservedate},
402
                    reservedate    => $request->{reservedate},
393
                    reservenotes => $request->{reservenotes},
403
                    reservenotes   => $request->{reservenotes},
394
                };
404
                };
395
                $allocated_items{$request->{itemnumber}}++;
405
                $allocated_items{ $request->{itemnumber} }++;
396
                $num_items_remaining--;
406
                $num_items_remaining--;
397
            }
407
            }
398
        } else {
408
        } else {
Lines 425-431 sub MapItemsToHoldRequests { Link Here
425
        my $holding_branch_items = $items_by_branch{$pickup_branch};
435
        my $holding_branch_items = $items_by_branch{$pickup_branch};
426
        if ( $holding_branch_items ) {
436
        if ( $holding_branch_items ) {
427
            foreach my $item (@$holding_branch_items) {
437
            foreach my $item (@$holding_branch_items) {
428
                if ( $request->{borrowerbranch} eq $item->{homebranch} ) {
438
                if (
439
                    $request->{borrowerbranch} eq $item->{homebranch}
440
                    && ( ( $item->{hold_fulfillment_policy} eq 'any' ) # Don't fill item level holds that contravene the hold pickup policy at this time
441
                        || $request->{branchcode} eq $item->{ $item->{hold_fulfillment_policy} } )
442
                  )
443
                {
429
                    $itemnumber = $item->{itemnumber};
444
                    $itemnumber = $item->{itemnumber};
430
                    last;
445
                    last;
431
                }
446
                }
Lines 441-446 sub MapItemsToHoldRequests { Link Here
441
                foreach my $item (@$holding_branch_items) {
456
                foreach my $item (@$holding_branch_items) {
442
                    next if $request->{borrowerbranch} ne $item->{homebranch};
457
                    next if $request->{borrowerbranch} ne $item->{homebranch};
443
458
459
                    # Don't fill item level holds that contravene the hold pickup policy at this time
460
                    next unless $item->{hold_fulfillment_policy} eq 'any'
461
                        || $request->{branchcode} eq $item->{ $item->{hold_fulfillment_policy} };
462
444
                    $itemnumber = $item->{itemnumber};
463
                    $itemnumber = $item->{itemnumber};
445
                    last;
464
                    last;
446
                }
465
                }
Lines 469-474 sub MapItemsToHoldRequests { Link Here
469
                    next if $pickup_branch ne $item->{homebranch};
488
                    next if $pickup_branch ne $item->{homebranch};
470
                    next if ( $item->{holdallowed} == 1 && $item->{homebranch} ne $request->{borrowerbranch} );
489
                    next if ( $item->{holdallowed} == 1 && $item->{homebranch} ne $request->{borrowerbranch} );
471
490
491
                    # Don't fill item level holds that contravene the hold pickup policy at this time
492
                    next unless $item->{hold_fulfillment_policy} eq 'any'
493
                        || $request->{branchcode} eq $item->{ $item->{hold_fulfillment_policy} };
494
472
                    $itemnumber = $item->{itemnumber};
495
                    $itemnumber = $item->{itemnumber};
473
                    $holdingbranch = $branch;
496
                    $holdingbranch = $branch;
474
                    last PULL_BRANCHES;
497
                    last PULL_BRANCHES;
Lines 479-484 sub MapItemsToHoldRequests { Link Here
479
            unless ( $itemnumber ) {
502
            unless ( $itemnumber ) {
480
                foreach my $current_item ( @{ $items_by_branch{$holdingbranch} } ) {
503
                foreach my $current_item ( @{ $items_by_branch{$holdingbranch} } ) {
481
                    if ( $holdingbranch && ( $current_item->{holdallowed} == 2 || $request->{borrowerbranch} eq $current_item->{homebranch} ) ) {
504
                    if ( $holdingbranch && ( $current_item->{holdallowed} == 2 || $request->{borrowerbranch} eq $current_item->{homebranch} ) ) {
505
506
                        # Don't fill item level holds that contravene the hold pickup policy at this time
507
                        next unless $current_item->{hold_fulfillment_policy} eq 'any'
508
                            || $request->{branchcode} eq $current_item->{ $current_item->{hold_fulfillment_policy} };
509
482
                        $itemnumber = $current_item->{itemnumber};
510
                        $itemnumber = $current_item->{itemnumber};
483
                        last; # quit this loop as soon as we have a suitable item
511
                        last; # quit this loop as soon as we have a suitable item
484
                    }
512
                    }
Lines 495-500 sub MapItemsToHoldRequests { Link Here
495
                    foreach my $item (@$holding_branch_items) {
523
                    foreach my $item (@$holding_branch_items) {
496
                        next if ( $item->{holdallowed} == 1 && $item->{homebranch} ne $request->{borrowerbranch} );
524
                        next if ( $item->{holdallowed} == 1 && $item->{homebranch} ne $request->{borrowerbranch} );
497
525
526
                        # Don't fill item level holds that contravene the hold pickup policy at this time
527
                        next unless $item->{hold_fulfillment_policy} eq 'any'
528
                            || $request->{branchcode} eq $item->{ $item->{hold_fulfillment_policy} };
529
498
                        $itemnumber = $item->{itemnumber};
530
                        $itemnumber = $item->{itemnumber};
499
                        $holdingbranch = $branch;
531
                        $holdingbranch = $branch;
500
                        last PULL_BRANCHES2;
532
                        last PULL_BRANCHES2;
(-)a/C4/Reserves.pm (+1 lines)
Lines 954-959 sub CheckReserves { Link Here
954
                    my $branchitemrule = C4::Circulation::GetBranchItemRule($branch,$iteminfo->{'itype'});
954
                    my $branchitemrule = C4::Circulation::GetBranchItemRule($branch,$iteminfo->{'itype'});
955
                    next if ($branchitemrule->{'holdallowed'} == 0);
955
                    next if ($branchitemrule->{'holdallowed'} == 0);
956
                    next if (($branchitemrule->{'holdallowed'} == 1) && ($branch ne $borrowerinfo->{'branchcode'}));
956
                    next if (($branchitemrule->{'holdallowed'} == 1) && ($branch ne $borrowerinfo->{'branchcode'}));
957
                    next if ( ($branchitemrule->{hold_fulfillment_policy} ne 'any') && ($res->{branchcode} ne $iteminfo->{ $branchitemrule->{hold_fulfillment_policy} }) );
957
                    $priority = $res->{'priority'};
958
                    $priority = $res->{'priority'};
958
                    $highest  = $res;
959
                    $highest  = $res;
959
                    last if $local_hold_match;
960
                    last if $local_hold_match;
(-)a/admin/smart-rules.pl (-41 / +45 lines)
Lines 189-194 elsif ($op eq "set-branch-defaults") { Link Here
189
    my $maxissueqty   = $input->param('maxissueqty');
189
    my $maxissueqty   = $input->param('maxissueqty');
190
    my $maxonsiteissueqty = $input->param('maxonsiteissueqty');
190
    my $maxonsiteissueqty = $input->param('maxonsiteissueqty');
191
    my $holdallowed   = $input->param('holdallowed');
191
    my $holdallowed   = $input->param('holdallowed');
192
    my $hold_fulfillment_policy = $input->param('hold_fulfillment_policy');
192
    my $returnbranch  = $input->param('returnbranch');
193
    my $returnbranch  = $input->param('returnbranch');
193
    $maxissueqty =~ s/\s//g;
194
    $maxissueqty =~ s/\s//g;
194
    $maxissueqty = undef if $maxissueqty !~ /^\d+/;
195
    $maxissueqty = undef if $maxissueqty !~ /^\d+/;
Lines 201-234 elsif ($op eq "set-branch-defaults") { Link Here
201
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
202
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
202
                                        FROM default_circ_rules");
203
                                        FROM default_circ_rules");
203
        my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules
204
        my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules
204
                                        (maxissueqty, maxonsiteissueqty, holdallowed, returnbranch)
205
                                        (maxissueqty, maxonsiteissueqty, holdallowed, hold_fulfillment_policy, returnbranch)
205
                                        VALUES (?, ?, ?, ?)");
206
                                        VALUES (?, ?, ?, ?, ?)");
206
        my $sth_update = $dbh->prepare("UPDATE default_circ_rules
207
        my $sth_update = $dbh->prepare("UPDATE default_circ_rules
207
                                        SET maxissueqty = ?, maxonsiteissueqty = ?, holdallowed = ?, returnbranch = ?");
208
                                        SET maxissueqty = ?, maxonsiteissueqty = ?, holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?");
208
209
209
        $sth_search->execute();
210
        $sth_search->execute();
210
        my $res = $sth_search->fetchrow_hashref();
211
        my $res = $sth_search->fetchrow_hashref();
211
        if ($res->{total}) {
212
        if ($res->{total}) {
212
            $sth_update->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $returnbranch);
213
            $sth_update->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch);
213
        } else {
214
        } else {
214
            $sth_insert->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $returnbranch);
215
            $sth_insert->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch);
215
        }
216
        }
216
    } else {
217
    } else {
217
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
218
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
218
                                        FROM default_branch_circ_rules
219
                                        FROM default_branch_circ_rules
219
                                        WHERE branchcode = ?");
220
                                        WHERE branchcode = ?");
220
        my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules
221
        my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules
221
                                        (branchcode, maxissueqty, maxonsiteissueqty, holdallowed, returnbranch)
222
                                        (branchcode, maxissueqty, maxonsiteissueqty, holdallowed, hold_fulfillment_policy, returnbranch)
222
                                        VALUES (?, ?, ?, ?, ?)");
223
                                        VALUES (?, ?, ?, ?, ?, ?)");
223
        my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules
224
        my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules
224
                                        SET maxissueqty = ?, maxonsiteissueqty = ?, holdallowed = ?, returnbranch = ?
225
                                        SET maxissueqty = ?, maxonsiteissueqty = ?, holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?
225
                                        WHERE branchcode = ?");
226
                                        WHERE branchcode = ?");
226
        $sth_search->execute($branch);
227
        $sth_search->execute($branch);
227
        my $res = $sth_search->fetchrow_hashref();
228
        my $res = $sth_search->fetchrow_hashref();
228
        if ($res->{total}) {
229
        if ($res->{total}) {
229
            $sth_update->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $returnbranch, $branch);
230
            $sth_update->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch, $branch);
230
        } else {
231
        } else {
231
            $sth_insert->execute($branch, $maxissueqty, $maxonsiteissueqty, $holdallowed, $returnbranch);
232
            $sth_insert->execute($branch, $maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch);
232
        }
233
        }
233
    }
234
    }
234
}
235
}
Lines 336-344 elsif ($op eq "add-branch-cat") { Link Here
336
    }
337
    }
337
}
338
}
338
elsif ($op eq "add-branch-item") {
339
elsif ($op eq "add-branch-item") {
339
    my $itemtype  = $input->param('itemtype');
340
    my $itemtype                = $input->param('itemtype');
340
    my $holdallowed   = $input->param('holdallowed');
341
    my $holdallowed             = $input->param('holdallowed');
341
    my $returnbranch  = $input->param('returnbranch');
342
    my $hold_fulfillment_policy = $input->param('hold_fulfillment_policy');
343
    my $returnbranch            = $input->param('returnbranch');
344
342
    $holdallowed =~ s/\s//g;
345
    $holdallowed =~ s/\s//g;
343
    $holdallowed = undef if $holdallowed !~ /^\d+/;
346
    $holdallowed = undef if $holdallowed !~ /^\d+/;
344
347
Lines 347-380 elsif ($op eq "add-branch-item") { Link Here
347
            my $sth_search = $dbh->prepare("SELECT count(*) AS total
350
            my $sth_search = $dbh->prepare("SELECT count(*) AS total
348
                                            FROM default_circ_rules");
351
                                            FROM default_circ_rules");
349
            my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules
352
            my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules
350
                                            (holdallowed, returnbranch)
353
                                            (holdallowed, hold_fulfillment_policy, returnbranch)
351
                                            VALUES (?, ?)");
354
                                            VALUES (?, ?, ?)");
352
            my $sth_update = $dbh->prepare("UPDATE default_circ_rules
355
            my $sth_update = $dbh->prepare("UPDATE default_circ_rules
353
                                            SET holdallowed = ?, returnbranch = ?");
356
                                            SET holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?");
354
357
355
            $sth_search->execute();
358
            $sth_search->execute();
356
            my $res = $sth_search->fetchrow_hashref();
359
            my $res = $sth_search->fetchrow_hashref();
357
            if ($res->{total}) {
360
            if ($res->{total}) {
358
                $sth_update->execute($holdallowed, $returnbranch);
361
                $sth_update->execute($holdallowed, $hold_fulfillment_policy, $returnbranch);
359
            } else {
362
            } else {
360
                $sth_insert->execute($holdallowed, $returnbranch);
363
                $sth_insert->execute($holdallowed, $hold_fulfillment_policy, $returnbranch);
361
            }
364
            }
362
        } else {
365
        } else {
363
            my $sth_search = $dbh->prepare("SELECT count(*) AS total
366
            my $sth_search = $dbh->prepare("SELECT count(*) AS total
364
                                            FROM default_branch_item_rules
367
                                            FROM default_branch_item_rules
365
                                            WHERE itemtype = ?");
368
                                            WHERE itemtype = ?");
366
            my $sth_insert = $dbh->prepare("INSERT INTO default_branch_item_rules
369
            my $sth_insert = $dbh->prepare("INSERT INTO default_branch_item_rules
367
                                            (itemtype, holdallowed, returnbranch)
370
                                            (itemtype, holdallowed, hold_fulfillment_policy, returnbranch)
368
                                            VALUES (?, ?, ?)");
371
                                            VALUES (?, ?, ?, ?)");
369
            my $sth_update = $dbh->prepare("UPDATE default_branch_item_rules
372
            my $sth_update = $dbh->prepare("UPDATE default_branch_item_rules
370
                                            SET holdallowed = ?, returnbranch = ?
373
                                            SET holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?
371
                                            WHERE itemtype = ?");
374
                                            WHERE itemtype = ?");
372
            $sth_search->execute($itemtype);
375
            $sth_search->execute($itemtype);
373
            my $res = $sth_search->fetchrow_hashref();
376
            my $res = $sth_search->fetchrow_hashref();
374
            if ($res->{total}) {
377
            if ($res->{total}) {
375
                $sth_update->execute($holdallowed, $returnbranch, $itemtype);
378
                $sth_update->execute($holdallowed, $hold_fulfillment_policy, $returnbranch, $itemtype);
376
            } else {
379
            } else {
377
                $sth_insert->execute($itemtype, $holdallowed, $returnbranch);
380
                $sth_insert->execute($itemtype, $holdallowed, $hold_fulfillment_policy, $returnbranch);
378
            }
381
            }
379
        }
382
        }
380
    } elsif ($itemtype eq "*") {
383
    } elsif ($itemtype eq "*") {
Lines 382-398 elsif ($op eq "add-branch-item") { Link Here
382
                                        FROM default_branch_circ_rules
385
                                        FROM default_branch_circ_rules
383
                                        WHERE branchcode = ?");
386
                                        WHERE branchcode = ?");
384
        my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules
387
        my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules
385
                                        (branchcode, holdallowed, returnbranch)
388
                                        (branchcode, holdallowed, hold_fulfillment_policy, returnbranch)
386
                                        VALUES (?, ?, ?)");
389
                                        VALUES (?, ?, ?, ?)");
387
        my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules
390
        my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules
388
                                        SET holdallowed = ?, returnbranch = ?
391
                                        SET holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?
389
                                        WHERE branchcode = ?");
392
                                        WHERE branchcode = ?");
390
        $sth_search->execute($branch);
393
        $sth_search->execute($branch);
391
        my $res = $sth_search->fetchrow_hashref();
394
        my $res = $sth_search->fetchrow_hashref();
392
        if ($res->{total}) {
395
        if ($res->{total}) {
393
            $sth_update->execute($holdallowed, $returnbranch, $branch);
396
            $sth_update->execute($holdallowed, $hold_fulfillment_policy, $returnbranch, $branch);
394
        } else {
397
        } else {
395
            $sth_insert->execute($branch, $holdallowed, $returnbranch);
398
            $sth_insert->execute($branch, $holdallowed, $hold_fulfillment_policy, $returnbranch);
396
        }
399
        }
397
    } else {
400
    } else {
398
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
401
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
Lines 400-418 elsif ($op eq "add-branch-item") { Link Here
400
                                        WHERE branchcode = ?
403
                                        WHERE branchcode = ?
401
                                        AND   itemtype = ?");
404
                                        AND   itemtype = ?");
402
        my $sth_insert = $dbh->prepare("INSERT INTO branch_item_rules
405
        my $sth_insert = $dbh->prepare("INSERT INTO branch_item_rules
403
                                        (branchcode, itemtype, holdallowed, returnbranch)
406
                                        (branchcode, itemtype, holdallowed, hold_fulfillment_policy, returnbranch)
404
                                        VALUES (?, ?, ?, ?)");
407
                                        VALUES (?, ?, ?, ?, ?)");
405
        my $sth_update = $dbh->prepare("UPDATE branch_item_rules
408
        my $sth_update = $dbh->prepare("UPDATE branch_item_rules
406
                                        SET holdallowed = ?, returnbranch = ?
409
                                        SET holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?
407
                                        WHERE branchcode = ?
410
                                        WHERE branchcode = ?
408
                                        AND itemtype = ?");
411
                                        AND itemtype = ?");
409
412
410
        $sth_search->execute($branch, $itemtype);
413
        $sth_search->execute($branch, $itemtype);
411
        my $res = $sth_search->fetchrow_hashref();
414
        my $res = $sth_search->fetchrow_hashref();
412
        if ($res->{total}) {
415
        if ($res->{total}) {
413
            $sth_update->execute($holdallowed, $returnbranch, $branch, $itemtype);
416
            $sth_update->execute($holdallowed, $hold_fulfillment_policy, $returnbranch, $branch, $itemtype);
414
        } else {
417
        } else {
415
            $sth_insert->execute($branch, $itemtype, $holdallowed, $returnbranch);
418
            $sth_insert->execute($branch, $itemtype, $holdallowed, $hold_fulfillment_policy, $returnbranch);
416
        }
419
        }
417
    }
420
    }
418
}
421
}
Lines 536-543 my @sorted_branch_item_rules = sort { $a->{'humanitemtype'} cmp $b->{'humanitemt Link Here
536
539
537
# note undef holdallowed so that template can deal with them
540
# note undef holdallowed so that template can deal with them
538
foreach my $entry (@sorted_branch_item_rules) {
541
foreach my $entry (@sorted_branch_item_rules) {
539
    $entry->{holdallowed_any} = 1 if($entry->{holdallowed} == 2);
542
    $entry->{holdallowed_any}  = 1 if ( $entry->{holdallowed} == 2 );
540
    $entry->{holdallowed_same} = 1 if($entry->{holdallowed} == 1);
543
    $entry->{holdallowed_same} = 1 if ( $entry->{holdallowed} == 1 );
541
}
544
}
542
545
543
$template->param(show_branch_cat_rule_form => 1);
546
$template->param(show_branch_cat_rule_form => 1);
Lines 563-574 if ($branch eq "*") { Link Here
563
my $defaults = $sth_defaults->fetchrow_hashref;
566
my $defaults = $sth_defaults->fetchrow_hashref;
564
567
565
if ($defaults) {
568
if ($defaults) {
566
    $template->param(default_holdallowed_none => 1) if($defaults->{holdallowed} == 0);
569
    $template->param( default_holdallowed_none => 1 ) if ( $defaults->{holdallowed} == 0 );
567
    $template->param(default_holdallowed_same => 1) if($defaults->{holdallowed} == 1);
570
    $template->param( default_holdallowed_same => 1 ) if ( $defaults->{holdallowed} == 1 );
568
    $template->param(default_holdallowed_any => 1) if($defaults->{holdallowed} == 2);
571
    $template->param( default_holdallowed_any  => 1 ) if ( $defaults->{holdallowed} == 2 );
569
    $template->param(default_maxissueqty => $defaults->{maxissueqty});
572
    $template->param( default_hold_fulfillment_policy => $defaults->{hold_fulfillment_policy} );
570
    $template->param(default_maxonsiteissueqty => $defaults->{maxonsiteissueqty});
573
    $template->param( default_maxissueqty      => $defaults->{maxissueqty} );
571
    $template->param(default_returnbranch => $defaults->{returnbranch});
574
    $template->param( default_maxonsiteissueqty => $defaults->{maxonsiteissueqty} );
575
    $template->param( default_returnbranch      => $defaults->{returnbranch} );
572
}
576
}
573
577
574
$template->param(default_rules => ($defaults ? 1 : 0));
578
$template->param(default_rules => ($defaults ? 1 : 0));
(-)a/installer/data/mysql/atomicupdate/hold_fulfillment_policy.sql (+4 lines)
Line 0 Link Here
1
ALTER TABLE branch_item_rules         ADD COLUMN hold_fulfillment_policy ENUM('any', 'homebranch', 'holdingbranch') NOT NULL DEFAULT 'any' AFTER holdallowed;
2
ALTER TABLE default_branch_circ_rules ADD COLUMN hold_fulfillment_policy ENUM('any', 'homebranch', 'holdingbranch') NOT NULL DEFAULT 'any' AFTER holdallowed;
3
ALTER TABLE default_branch_item_rules ADD COLUMN hold_fulfillment_policy ENUM('any', 'homebranch', 'holdingbranch') NOT NULL DEFAULT 'any' AFTER holdallowed;
4
ALTER TABLE default_circ_rules        ADD COLUMN hold_fulfillment_policy ENUM('any', 'homebranch', 'holdingbranch') NOT NULL DEFAULT 'any' AFTER holdallowed;
(-)a/installer/data/mysql/kohastructure.sql (+4 lines)
Lines 347-352 CREATE TABLE `branch_item_rules` ( -- information entered in the circulation and Link Here
347
  `branchcode` varchar(10) NOT NULL, -- the branch this rule is for (branches.branchcode)
347
  `branchcode` varchar(10) NOT NULL, -- the branch this rule is for (branches.branchcode)
348
  `itemtype` varchar(10) NOT NULL, -- the item type this rule applies to (items.itype)
348
  `itemtype` varchar(10) NOT NULL, -- the item type this rule applies to (items.itype)
349
  `holdallowed` tinyint(1) default NULL, -- the number of holds allowed
349
  `holdallowed` tinyint(1) default NULL, -- the number of holds allowed
350
  hold_fulfillment_policy ENUM('any', 'homebranch', 'holdingbranch') NOT NULL DEFAULT 'any', -- limit trapping of holds by branchcode
350
  `returnbranch` varchar(15) default NULL, -- the branch the item returns to (homebranch, holdingbranch, noreturn)
351
  `returnbranch` varchar(15) default NULL, -- the branch the item returns to (homebranch, holdingbranch, noreturn)
351
  PRIMARY KEY  (`itemtype`,`branchcode`),
352
  PRIMARY KEY  (`itemtype`,`branchcode`),
352
  KEY `branch_item_rules_ibfk_2` (`branchcode`),
353
  KEY `branch_item_rules_ibfk_2` (`branchcode`),
Lines 667-672 CREATE TABLE `default_branch_circ_rules` ( Link Here
667
  `maxissueqty` int(4) default NULL,
668
  `maxissueqty` int(4) default NULL,
668
  `maxonsiteissueqty` int(4) default NULL,
669
  `maxonsiteissueqty` int(4) default NULL,
669
  `holdallowed` tinyint(1) default NULL,
670
  `holdallowed` tinyint(1) default NULL,
671
  hold_fulfillment_policy ENUM('any', 'homebranch', 'holdingbranch') NOT NULL DEFAULT 'any', -- limit trapping of holds by branchcode
670
  `returnbranch` varchar(15) default NULL,
672
  `returnbranch` varchar(15) default NULL,
671
  PRIMARY KEY (`branchcode`),
673
  PRIMARY KEY (`branchcode`),
672
  CONSTRAINT `default_branch_circ_rules_ibfk_1` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`)
674
  CONSTRAINT `default_branch_circ_rules_ibfk_1` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`)
Lines 680-685 DROP TABLE IF EXISTS `default_branch_item_rules`; Link Here
680
CREATE TABLE `default_branch_item_rules` (
682
CREATE TABLE `default_branch_item_rules` (
681
  `itemtype` varchar(10) NOT NULL,
683
  `itemtype` varchar(10) NOT NULL,
682
  `holdallowed` tinyint(1) default NULL,
684
  `holdallowed` tinyint(1) default NULL,
685
  hold_fulfillment_policy ENUM('any', 'homebranch', 'holdingbranch') NOT NULL DEFAULT 'any', -- limit trapping of holds by branchcode
683
  `returnbranch` varchar(15) default NULL,
686
  `returnbranch` varchar(15) default NULL,
684
  PRIMARY KEY  (`itemtype`),
687
  PRIMARY KEY  (`itemtype`),
685
  CONSTRAINT `default_branch_item_rules_ibfk_1` FOREIGN KEY (`itemtype`) REFERENCES `itemtypes` (`itemtype`)
688
  CONSTRAINT `default_branch_item_rules_ibfk_1` FOREIGN KEY (`itemtype`) REFERENCES `itemtypes` (`itemtype`)
Lines 696-701 CREATE TABLE `default_circ_rules` ( Link Here
696
    `maxissueqty` int(4) default NULL,
699
    `maxissueqty` int(4) default NULL,
697
    `maxonsiteissueqty` int(4) default NULL,
700
    `maxonsiteissueqty` int(4) default NULL,
698
    `holdallowed` int(1) default NULL,
701
    `holdallowed` int(1) default NULL,
702
    hold_fulfillment_policy ENUM('any', 'homebranch', 'holdingbranch') NOT NULL DEFAULT 'any', -- limit trapping of holds by branchcode
699
    `returnbranch` varchar(15) default NULL,
703
    `returnbranch` varchar(15) default NULL,
700
    PRIMARY KEY (`singleton`)
704
    PRIMARY KEY (`singleton`)
701
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
705
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt (+58 lines)
Lines 379-384 for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde Link Here
379
                    <th>Total current checkouts allowed</th>
379
                    <th>Total current checkouts allowed</th>
380
                    <th>Total current on-site checkouts allowed</th>
380
                    <th>Total current on-site checkouts allowed</th>
381
                    <th>Hold policy</th>
381
                    <th>Hold policy</th>
382
                    <th>Hold pickup library match</th>
382
                    <th>Return policy</th>
383
                    <th>Return policy</th>
383
                    <th>&nbsp;</th>
384
                    <th>&nbsp;</th>
384
                    <th>&nbsp;</th>
385
                    <th>&nbsp;</th>
Lines 413-418 for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde Link Here
413
                        </select>
414
                        </select>
414
                    </td>
415
                    </td>
415
                    <td>
416
                    <td>
417
                        <select name="hold_fulfillment_policy">
418
                            [% IF default_hold_fulfillment_policy == 'any' %]
419
                                <option value="any" selected="selected">
420
                                    any library
421
                                </option>
422
                            [% ELSE %]
423
                                <option value="any">
424
                                    any library
425
                                </option>
426
                            [% END %]
427
428
                            [% IF default_hold_fulfillment_policy == 'homebranch' %]
429
                                <option value="homebranch" selected="selected">
430
                                    item's home library
431
                                </option>
432
                            [% ELSE %]
433
                                <option value="homebranch">
434
                                    item's home library
435
                                </option>
436
                            [% END %]
437
438
                            [% IF default_hold_fulfillment_policy == 'holdingbranch' %]
439
                                <option value="holdingbranch" selected="selected">
440
                                    item's holding library
441
                                </option>
442
                            [% ELSE %]
443
                                <option value="holdingbranch">
444
                                    item's holding library
445
                                </option>
446
                            [% END %]
447
                        </select>
448
                    </td>
449
                    <td>
416
                        <select name="returnbranch">
450
                        <select name="returnbranch">
417
                            [% IF ( default_returnbranch == 'homebranch' ) %]
451
                            [% IF ( default_returnbranch == 'homebranch' ) %]
418
                            <option value="homebranch" selected="selected">
452
                            <option value="homebranch" selected="selected">
Lines 536-541 for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde Link Here
536
                <tr>
570
                <tr>
537
                    <th>Item type</th>
571
                    <th>Item type</th>
538
                    <th>Hold policy</th>
572
                    <th>Hold policy</th>
573
                    <th>Hold pickup library match</th>
539
                    <th>Return policy</th>
574
                    <th>Return policy</th>
540
                    <th>&nbsp;</th>
575
                    <th>&nbsp;</th>
541
                </tr>
576
                </tr>
Lines 559-564 for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde Link Here
559
                                No holds allowed
594
                                No holds allowed
560
                            [% END %]
595
                            [% END %]
561
                        </td>
596
                        </td>
597
                        <td>[% IF ( branch_item_rule_loo.hold_fulfillment_policy == 'any' ) %]
598
                                any library
599
                            [% ELSIF ( branch_item_rule_loo.hold_fulfillment_policy == 'homebranch' ) %]
600
                                item's home library
601
                            [% ELSIF ( branch_item_rule_loo.hold_fulfillment_policy == 'holdingbranch' ) %]
602
                                item's holding library
603
                            [% END %]
604
                        </td>
562
                        <td>[% IF ( branch_item_rule_loo.returnbranch == 'homebranch' ) %]
605
                        <td>[% IF ( branch_item_rule_loo.returnbranch == 'homebranch' ) %]
563
                                Item returns home
606
                                Item returns home
564
                            [% ELSIF ( branch_item_rule_loo.returnbranch == 'holdingbranch' ) %]
607
                            [% ELSIF ( branch_item_rule_loo.returnbranch == 'holdingbranch' ) %]
Lines 590-595 for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde Link Here
590
                        </select>
633
                        </select>
591
                    </td>
634
                    </td>
592
                    <td>
635
                    <td>
636
                        <select name="hold_fulfillment_policy">
637
                            <option value="any">
638
                                any library
639
                            </option>
640
641
                            <option value="homebranch">
642
                                item's home library
643
                            </option>
644
645
                            <option value="holdingbranch">
646
                                item's holding library
647
                            </option>
648
                        </select>
649
                    </td>
650
                    <td>
593
                        <select name="returnbranch">
651
                        <select name="returnbranch">
594
                            <option value="homebranch">Item returns home</option>
652
                            <option value="homebranch">Item returns home</option>
595
                            <option value="holdingbranch">Item returns to issuing library</option>
653
                            <option value="holdingbranch">Item returns to issuing library</option>
(-)a/t/db_dependent/Holds/HoldFulfillmentPolicy.t (+152 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
5
use C4::Context;
6
7
use Test::More tests => 10;
8
9
use t::lib::TestBuilder;
10
11
BEGIN {
12
    use FindBin;
13
    use lib $FindBin::Bin;
14
    use_ok('C4::Reserves');
15
}
16
17
my $schema = Koha::Database->schema;
18
$schema->storage->txn_begin;
19
my $dbh = C4::Context->dbh;
20
21
my $builder = t::lib::TestBuilder->new;
22
23
my $library1 = $builder->build({
24
    source => 'Branch',
25
});
26
my $library2 = $builder->build({
27
    source => 'Branch',
28
});
29
my $library3 = $builder->build({
30
    source => 'Branch',
31
});
32
33
my $bib_title = "Test Title";
34
35
my $borrower = $builder->build({
36
    source => 'Borrower',
37
    value => {
38
        categorycode => 'S',
39
        branchcode => $library1->{branchcode},
40
    }
41
});
42
43
# Test hold_fulfillment_policy
44
my ( $itemtype ) = @{ $dbh->selectrow_arrayref("SELECT itemtype FROM itemtypes LIMIT 1") };
45
my $borrowernumber = $borrower->{borrowernumber};
46
my $library_A = $library1->{branchcode};
47
my $library_B = $library2->{branchcode};
48
my $library_C = $library3->{branchcode};
49
$dbh->do("DELETE FROM reserves");
50
$dbh->do("DELETE FROM issues");
51
$dbh->do("DELETE FROM items");
52
$dbh->do("DELETE FROM biblio");
53
$dbh->do("DELETE FROM biblioitems");
54
$dbh->do("DELETE FROM transport_cost");
55
$dbh->do("DELETE FROM tmp_holdsqueue");
56
$dbh->do("DELETE FROM hold_fill_targets");
57
$dbh->do("DELETE FROM default_branch_circ_rules");
58
$dbh->do("DELETE FROM default_branch_item_rules");
59
$dbh->do("DELETE FROM default_circ_rules");
60
$dbh->do("DELETE FROM branch_item_rules");
61
62
$dbh->do("INSERT INTO biblio (frameworkcode, author, title, datecreated) VALUES ('', 'Koha test', '$bib_title', '2011-02-01')");
63
64
my $biblionumber = $dbh->selectrow_array("SELECT biblionumber FROM biblio WHERE title = '$bib_title'")
65
  or BAIL_OUT("Cannot find newly created biblio record");
66
67
$dbh->do("INSERT INTO biblioitems (biblionumber, marcxml, itemtype) VALUES ($biblionumber, '', '$itemtype')");
68
69
my $biblioitemnumber =
70
  $dbh->selectrow_array("SELECT biblioitemnumber FROM biblioitems WHERE biblionumber = $biblionumber")
71
  or BAIL_OUT("Cannot find newly created biblioitems record");
72
73
$dbh->do("
74
    INSERT INTO items (biblionumber, biblioitemnumber, homebranch, holdingbranch, notforloan, damaged, itemlost, withdrawn, onloan, itype)
75
    VALUES ($biblionumber, $biblioitemnumber, '$library_A', '$library_B', 0, 0, 0, 0, NULL, '$itemtype')
76
");
77
78
my $itemnumber =
79
  $dbh->selectrow_array("SELECT itemnumber FROM items WHERE biblionumber = $biblionumber")
80
  or BAIL_OUT("Cannot find newly created item");
81
82
# With hold_fulfillment_policy = homebranch, hold should only be picked up if pickup branch = homebranch
83
$dbh->do("DELETE FROM default_circ_rules");
84
$dbh->do("INSERT INTO default_circ_rules ( holdallowed, hold_fulfillment_policy ) VALUES ( 2, 'homebranch' )");
85
86
my $holds_queue;
87
# Home branch matches pickup branch
88
my $reserve_id = AddReserve( $library_A, $borrowernumber, $biblionumber, '', 1 );
89
my ( $status ) = CheckReserves($itemnumber);
90
is( $status, 'Reserved', "Hold where pickup branch matches home branch targeted" );
91
CancelReserve( { reserve_id => $reserve_id } );
92
93
# Holding branch matches pickup branch
94
$reserve_id = AddReserve( $library_B, $borrowernumber, $biblionumber, '', 1 );
95
( $status ) = CheckReserves($itemnumber);
96
is($status, q{}, "Hold where pickup ne home, pickup eq home not targeted" );
97
CancelReserve( { reserve_id => $reserve_id } );
98
99
# Neither branch matches pickup branch
100
$reserve_id = AddReserve( $library_C, $borrowernumber, $biblionumber, '', 1 );
101
( $status ) = CheckReserves($itemnumber);
102
is( $status, q{}, "Hold where pickup ne home, pickup ne holding not targeted" );
103
CancelReserve( { reserve_id => $reserve_id } );
104
105
# With hold_fulfillment_policy = holdingbranch, hold should only be picked up if pickup branch = holdingbranch
106
$dbh->do("DELETE FROM default_circ_rules");
107
$dbh->do("INSERT INTO default_circ_rules ( holdallowed, hold_fulfillment_policy ) VALUES ( 2, 'holdingbranch' )");
108
109
# Home branch matches pickup branch
110
$reserve_id = AddReserve( $library_A, $borrowernumber, $biblionumber, '', 1 );
111
( $status ) = CheckReserves($itemnumber);
112
is( $status, q{}, "Hold where pickup eq home, pickup ne holding not targeted" );
113
CancelReserve( { reserve_id => $reserve_id } );
114
115
# Holding branch matches pickup branch
116
$reserve_id = AddReserve( $library_B, $borrowernumber, $biblionumber, '', 1 );
117
( $status ) = CheckReserves($itemnumber);
118
is( $status, 'Reserved', "Hold where pickup ne home, pickup eq holding targeted" );
119
CancelReserve( { reserve_id => $reserve_id } );
120
121
# Neither branch matches pickup branch
122
$reserve_id = AddReserve( $library_C, $borrowernumber, $biblionumber, '', 1 );
123
( $status ) = CheckReserves($itemnumber);
124
is( $status, q{}, "Hold where pickup ne home, pickup ne holding not targeted" );
125
CancelReserve( { reserve_id => $reserve_id } );
126
127
# With hold_fulfillment_policy = any, hold should be pikcup up reguardless of matching home or holding branch
128
$dbh->do("DELETE FROM default_circ_rules");
129
$dbh->do("INSERT INTO default_circ_rules ( holdallowed, hold_fulfillment_policy ) VALUES ( 2, 'any' )");
130
131
# Home branch matches pickup branch
132
$reserve_id = AddReserve( $library_A, $borrowernumber, $biblionumber, '', 1 );
133
( $status ) = CheckReserves($itemnumber);
134
is( $status, 'Reserved', "Hold where pickup eq home, pickup ne holding targeted" );
135
CancelReserve( { reserve_id => $reserve_id } );
136
137
# Holding branch matches pickup branch
138
$reserve_id = AddReserve( $library_B, $borrowernumber, $biblionumber, '', 1 );
139
( $status ) = CheckReserves($itemnumber);
140
is( $status, 'Reserved', "Hold where pickup ne home, pickup eq holding targeted" );
141
CancelReserve( { reserve_id => $reserve_id } );
142
143
# Neither branch matches pickup branch
144
$reserve_id = AddReserve( $library_C, $borrowernumber, $biblionumber, '', 1 );
145
( $status ) = CheckReserves($itemnumber);
146
is( $status, 'Reserved', "Hold where pickup ne home, pickup ne holding targeted" );
147
CancelReserve( { reserve_id => $reserve_id } );
148
149
# End testing hold_fulfillment_policy
150
151
# Cleanup
152
$schema->storage->txn_rollback;
(-)a/t/db_dependent/HoldsQueue.t (-2 / +114 lines)
Lines 12-18 use C4::Context; Link Here
12
12
13
use Data::Dumper;
13
use Data::Dumper;
14
14
15
use Test::More tests => 23;
15
use Test::More tests => 32;
16
16
17
use C4::Branch;
17
use C4::Branch;
18
use C4::ItemType;
18
use C4::ItemType;
Lines 412-417 $holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice Link Here
412
is( @$holds_queue, 0, "Bug 15062 - Holds queue with Transport Cost Matrix will transfer item even if transfers disabled");
412
is( @$holds_queue, 0, "Bug 15062 - Holds queue with Transport Cost Matrix will transfer item even if transfers disabled");
413
# End Bug 15062
413
# End Bug 15062
414
414
415
# Test hold_fulfillment_policy
416
C4::Context->set_preference( "UseTransportCostMatrix", 0 );
417
$itemtype = $item_types[0]->{itemtype};
418
$borrowernumber = $borrower3->{borrowernumber};
419
$library_A = $library1->{branchcode};
420
$library_B = $library2->{branchcode};
421
$library_C = $library3->{branchcode};
422
$dbh->do("DELETE FROM reserves");
423
$dbh->do("DELETE FROM issues");
424
$dbh->do("DELETE FROM items");
425
$dbh->do("DELETE FROM biblio");
426
$dbh->do("DELETE FROM biblioitems");
427
$dbh->do("DELETE FROM transport_cost");
428
$dbh->do("DELETE FROM tmp_holdsqueue");
429
$dbh->do("DELETE FROM hold_fill_targets");
430
$dbh->do("DELETE FROM default_branch_circ_rules");
431
$dbh->do("DELETE FROM default_branch_item_rules");
432
$dbh->do("DELETE FROM default_circ_rules");
433
$dbh->do("DELETE FROM branch_item_rules");
434
435
$dbh->do("INSERT INTO biblio (frameworkcode, author, title, datecreated) VALUES ('', 'Koha test', '$TITLE', '2011-02-01')");
436
437
$biblionumber = $dbh->selectrow_array("SELECT biblionumber FROM biblio WHERE title = '$TITLE'")
438
  or BAIL_OUT("Cannot find newly created biblio record");
439
440
$dbh->do("INSERT INTO biblioitems (biblionumber, marcxml, itemtype) VALUES ($biblionumber, '', '$itemtype')");
441
442
$biblioitemnumber =
443
  $dbh->selectrow_array("SELECT biblioitemnumber FROM biblioitems WHERE biblionumber = $biblionumber")
444
  or BAIL_OUT("Cannot find newly created biblioitems record");
445
446
$dbh->do("
447
    INSERT INTO items (biblionumber, biblioitemnumber, homebranch, holdingbranch, notforloan, damaged, itemlost, withdrawn, onloan, itype)
448
    VALUES ($biblionumber, $biblioitemnumber, '$library_A', '$library_B', 0, 0, 0, 0, NULL, '$itemtype')
449
");
450
451
# With hold_fulfillment_policy = homebranch, hold should only be picked up if pickup branch = homebranch
452
$dbh->do("DELETE FROM default_circ_rules");
453
$dbh->do("INSERT INTO default_circ_rules ( holdallowed, hold_fulfillment_policy ) VALUES ( 2, 'homebranch' )");
454
455
# Home branch matches pickup branch
456
$reserve_id = AddReserve( $library_A, $borrowernumber, $biblionumber, '', 1 );
457
C4::HoldsQueue::CreateQueue();
458
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
459
is( @$holds_queue, 1, "Hold where pickup branch matches home branch targeted" );
460
CancelReserve( { reserve_id => $reserve_id } );
461
462
# Holding branch matches pickup branch
463
$reserve_id = AddReserve( $library_B, $borrowernumber, $biblionumber, '', 1 );
464
C4::HoldsQueue::CreateQueue();
465
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
466
is( @$holds_queue, 0, "Hold where pickup ne home, pickup eq home not targeted" );
467
CancelReserve( { reserve_id => $reserve_id } );
468
469
# Neither branch matches pickup branch
470
$reserve_id = AddReserve( $library_C, $borrowernumber, $biblionumber, '', 1 );
471
C4::HoldsQueue::CreateQueue();
472
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
473
is( @$holds_queue, 0, "Hold where pickup ne home, pickup ne holding not targeted" );
474
CancelReserve( { reserve_id => $reserve_id } );
475
476
# With hold_fulfillment_policy = holdingbranch, hold should only be picked up if pickup branch = holdingbranch
477
$dbh->do("DELETE FROM default_circ_rules");
478
$dbh->do("INSERT INTO default_circ_rules ( holdallowed, hold_fulfillment_policy ) VALUES ( 2, 'holdingbranch' )");
479
480
# Home branch matches pickup branch
481
$reserve_id = AddReserve( $library_A, $borrowernumber, $biblionumber, '', 1 );
482
C4::HoldsQueue::CreateQueue();
483
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
484
is( @$holds_queue, 0, "Hold where pickup eq home, pickup ne holding not targeted" );
485
CancelReserve( { reserve_id => $reserve_id } );
486
487
# Holding branch matches pickup branch
488
$reserve_id = AddReserve( $library_B, $borrowernumber, $biblionumber, '', 1 );
489
C4::HoldsQueue::CreateQueue();
490
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
491
is( @$holds_queue, 1, "Hold where pickup ne home, pickup eq holding targeted" );
492
CancelReserve( { reserve_id => $reserve_id } );
493
494
# Neither branch matches pickup branch
495
$reserve_id = AddReserve( $library_C, $borrowernumber, $biblionumber, '', 1 );
496
C4::HoldsQueue::CreateQueue();
497
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
498
is( @$holds_queue, 0, "Hold where pickup ne home, pickup ne holding not targeted" );
499
CancelReserve( { reserve_id => $reserve_id } );
500
501
# With hold_fulfillment_policy = any, hold should be pikcup up reguardless of matching home or holding branch
502
$dbh->do("DELETE FROM default_circ_rules");
503
$dbh->do("INSERT INTO default_circ_rules ( holdallowed, hold_fulfillment_policy ) VALUES ( 2, 'any' )");
504
505
# Home branch matches pickup branch
506
$reserve_id = AddReserve( $library_A, $borrowernumber, $biblionumber, '', 1 );
507
C4::HoldsQueue::CreateQueue();
508
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
509
is( @$holds_queue, 1, "Hold where pickup eq home, pickup ne holding targeted" );
510
CancelReserve( { reserve_id => $reserve_id } );
511
512
# Holding branch matches pickup branch
513
$reserve_id = AddReserve( $library_B, $borrowernumber, $biblionumber, '', 1 );
514
C4::HoldsQueue::CreateQueue();
515
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
516
is( @$holds_queue, 1, "Hold where pickup ne home, pickup eq holding targeted" );
517
CancelReserve( { reserve_id => $reserve_id } );
518
519
# Neither branch matches pickup branch
520
$reserve_id = AddReserve( $library_C, $borrowernumber, $biblionumber, '', 1 );
521
C4::HoldsQueue::CreateQueue();
522
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
523
is( @$holds_queue, 1, "Hold where pickup ne home, pickup ne holding targeted" );
524
CancelReserve( { reserve_id => $reserve_id } );
525
526
# End testing hold_fulfillment_policy
527
415
# Cleanup
528
# Cleanup
416
$schema->storage->txn_rollback;
529
$schema->storage->txn_rollback;
417
530
418
- 

Return to bug 15532