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

(-)a/C4/Circulation.pm (-4 / +6 lines)
Lines 1724-1740 sub GetBranchItemRule { Link Here
1724
    my $result = {};
1724
    my $result = {};
1725
1725
1726
    my @attempts = (
1726
    my @attempts = (
1727
        ['SELECT holdallowed, returnbranch
1727
        ['SELECT holdallowed, returnbranch, hold_fulfillment_policy
1728
            FROM branch_item_rules
1728
            FROM branch_item_rules
1729
            WHERE branchcode = ?
1729
            WHERE branchcode = ?
1730
              AND itemtype = ?', $branchcode, $itemtype],
1730
              AND itemtype = ?', $branchcode, $itemtype],
1731
        ['SELECT holdallowed, returnbranch
1731
        ['SELECT holdallowed, returnbranch, hold_fulfillment_policy
1732
            FROM default_branch_circ_rules
1732
            FROM default_branch_circ_rules
1733
            WHERE branchcode = ?', $branchcode],
1733
            WHERE branchcode = ?', $branchcode],
1734
        ['SELECT holdallowed, returnbranch
1734
        ['SELECT holdallowed, returnbranch, hold_fulfillment_policy
1735
            FROM default_branch_item_rules
1735
            FROM default_branch_item_rules
1736
            WHERE itemtype = ?', $itemtype],
1736
            WHERE itemtype = ?', $itemtype],
1737
        ['SELECT holdallowed, returnbranch
1737
        ['SELECT holdallowed, returnbranch, hold_fulfillment_policy
1738
            FROM default_circ_rules'],
1738
            FROM default_circ_rules'],
1739
    );
1739
    );
1740
1740
Lines 1747-1757 sub GetBranchItemRule { Link Here
1747
        # defaults tables, we have to check that the key we want is set, not
1747
        # defaults tables, we have to check that the key we want is set, not
1748
        # just that a row was returned
1748
        # just that a row was returned
1749
        $result->{'holdallowed'}  = $search_result->{'holdallowed'}  unless ( defined $result->{'holdallowed'} );
1749
        $result->{'holdallowed'}  = $search_result->{'holdallowed'}  unless ( defined $result->{'holdallowed'} );
1750
        $result->{'hold_fulfillment_policy'} = $search_result->{'hold_fulfillment_policy'} unless ( defined $result->{'hold_fulfillment_policy'} );
1750
        $result->{'returnbranch'} = $search_result->{'returnbranch'} unless ( defined $result->{'returnbranch'} );
1751
        $result->{'returnbranch'} = $search_result->{'returnbranch'} unless ( defined $result->{'returnbranch'} );
1751
    }
1752
    }
1752
    
1753
    
1753
    # built-in default circulation rule
1754
    # built-in default circulation rule
1754
    $result->{'holdallowed'} = 2 unless ( defined $result->{'holdallowed'} );
1755
    $result->{'holdallowed'} = 2 unless ( defined $result->{'holdallowed'} );
1756
    $result->{'hold_fulfillment_policy'} = 'any' unless ( defined $result->{'hold_fulfillment_policy'} );
1755
    $result->{'returnbranch'} = 'homebranch' unless ( defined $result->{'returnbranch'} );
1757
    $result->{'returnbranch'} = 'homebranch' unless ( defined $result->{'returnbranch'} );
1756
1758
1757
    return $result;
1759
    return $result;
(-)a/C4/HoldsQueue.pm (-11 / +43 lines)
Lines 355-360 sub GetItemsAvailableToFillHoldRequestsForBib { Link Here
355
    return [ grep {
355
    return [ grep {
356
        my $rule = GetBranchItemRule($_->{homebranch}, $_->{itype});
356
        my $rule = GetBranchItemRule($_->{homebranch}, $_->{itype});
357
        $_->{holdallowed} = $rule->{holdallowed};
357
        $_->{holdallowed} = $rule->{holdallowed};
358
        $_->{hold_fulfillment_policy} = $rule->{hold_fulfillment_policy};
358
    } @items ];
359
    } @items ];
359
}
360
}
360
361
Lines 393-410 sub MapItemsToHoldRequests { Link Here
393
        # is this an item-level request?
394
        # is this an item-level request?
394
        if (defined($request->{itemnumber})) {
395
        if (defined($request->{itemnumber})) {
395
            # fill it if possible; if not skip it
396
            # fill it if possible; if not skip it
396
            if (exists $items_by_itemnumber{$request->{itemnumber}} and
397
            if (
397
                not exists $allocated_items{$request->{itemnumber}}) {
398
                    exists $items_by_itemnumber{ $request->{itemnumber} }
398
                $item_map{$request->{itemnumber}} = {
399
                and not exists $allocated_items{ $request->{itemnumber} }
400
                and ( # Don't fill item level holds that contravene the hold pickup policy at this time
401
                    ( $items_by_itemnumber{ $request->{itemnumber} }->{hold_fulfillment_policy} eq 'any' )
402
                    || ( $request->{branchcode} eq $items_by_itemnumber{ $request->{itemnumber} }->{ $items_by_itemnumber{ $request->{itemnumber} }->{hold_fulfillment_policy} }  )
403
                )
404
405
              )
406
            {
407
408
                $item_map{ $request->{itemnumber} } = {
399
                    borrowernumber => $request->{borrowernumber},
409
                    borrowernumber => $request->{borrowernumber},
400
                    biblionumber => $request->{biblionumber},
410
                    biblionumber   => $request->{biblionumber},
401
                    holdingbranch =>  $items_by_itemnumber{$request->{itemnumber}}->{holdingbranch},
411
                    holdingbranch  => $items_by_itemnumber{ $request->{itemnumber} }->{holdingbranch},
402
                    pickup_branch => $request->{branchcode} || $request->{borrowerbranch},
412
                    pickup_branch  => $request->{branchcode} || $request->{borrowerbranch},
403
                    item_level => 1,
413
                    item_level     => 1,
404
                    reservedate => $request->{reservedate},
414
                    reservedate    => $request->{reservedate},
405
                    reservenotes => $request->{reservenotes},
415
                    reservenotes   => $request->{reservenotes},
406
                };
416
                };
407
                $allocated_items{$request->{itemnumber}}++;
417
                $allocated_items{ $request->{itemnumber} }++;
408
                $num_items_remaining--;
418
                $num_items_remaining--;
409
            }
419
            }
410
        } else {
420
        } else {
Lines 437-443 sub MapItemsToHoldRequests { Link Here
437
        my $holding_branch_items = $items_by_branch{$pickup_branch};
447
        my $holding_branch_items = $items_by_branch{$pickup_branch};
438
        if ( $holding_branch_items ) {
448
        if ( $holding_branch_items ) {
439
            foreach my $item (@$holding_branch_items) {
449
            foreach my $item (@$holding_branch_items) {
440
                if ( $request->{borrowerbranch} eq $item->{homebranch} ) {
450
                if (
451
                    $request->{borrowerbranch} eq $item->{homebranch}
452
                    && ( ( $item->{hold_fulfillment_policy} eq 'any' ) # Don't fill item level holds that contravene the hold pickup policy at this time
453
                        || $request->{branchcode} eq $item->{ $item->{hold_fulfillment_policy} } )
454
                  )
455
                {
441
                    $itemnumber = $item->{itemnumber};
456
                    $itemnumber = $item->{itemnumber};
442
                    last;
457
                    last;
443
                }
458
                }
Lines 453-458 sub MapItemsToHoldRequests { Link Here
453
                foreach my $item (@$holding_branch_items) {
468
                foreach my $item (@$holding_branch_items) {
454
                    next if $request->{borrowerbranch} ne $item->{homebranch};
469
                    next if $request->{borrowerbranch} ne $item->{homebranch};
455
470
471
                    # Don't fill item level holds that contravene the hold pickup policy at this time
472
                    next unless $item->{hold_fulfillment_policy} eq 'any'
473
                        || $request->{branchcode} eq $item->{ $item->{hold_fulfillment_policy} };
474
456
                    $itemnumber = $item->{itemnumber};
475
                    $itemnumber = $item->{itemnumber};
457
                    last;
476
                    last;
458
                }
477
                }
Lines 481-486 sub MapItemsToHoldRequests { Link Here
481
                    next if $pickup_branch ne $item->{homebranch};
500
                    next if $pickup_branch ne $item->{homebranch};
482
                    next if ( $item->{holdallowed} == 1 && $item->{homebranch} ne $request->{borrowerbranch} );
501
                    next if ( $item->{holdallowed} == 1 && $item->{homebranch} ne $request->{borrowerbranch} );
483
502
503
                    # Don't fill item level holds that contravene the hold pickup policy at this time
504
                    next unless $item->{hold_fulfillment_policy} eq 'any'
505
                        || $request->{branchcode} eq $item->{ $item->{hold_fulfillment_policy} };
506
484
                    $itemnumber = $item->{itemnumber};
507
                    $itemnumber = $item->{itemnumber};
485
                    $holdingbranch = $branch;
508
                    $holdingbranch = $branch;
486
                    last PULL_BRANCHES;
509
                    last PULL_BRANCHES;
Lines 491-496 sub MapItemsToHoldRequests { Link Here
491
            unless ( $itemnumber ) {
514
            unless ( $itemnumber ) {
492
                foreach my $current_item ( @{ $items_by_branch{$holdingbranch} } ) {
515
                foreach my $current_item ( @{ $items_by_branch{$holdingbranch} } ) {
493
                    if ( $holdingbranch && ( $current_item->{holdallowed} == 2 || $request->{borrowerbranch} eq $current_item->{homebranch} ) ) {
516
                    if ( $holdingbranch && ( $current_item->{holdallowed} == 2 || $request->{borrowerbranch} eq $current_item->{homebranch} ) ) {
517
518
                        # Don't fill item level holds that contravene the hold pickup policy at this time
519
                        next unless $current_item->{hold_fulfillment_policy} eq 'any'
520
                            || $request->{branchcode} eq $current_item->{ $current_item->{hold_fulfillment_policy} };
521
494
                        $itemnumber = $current_item->{itemnumber};
522
                        $itemnumber = $current_item->{itemnumber};
495
                        last; # quit this loop as soon as we have a suitable item
523
                        last; # quit this loop as soon as we have a suitable item
496
                    }
524
                    }
Lines 507-512 sub MapItemsToHoldRequests { Link Here
507
                    foreach my $item (@$holding_branch_items) {
535
                    foreach my $item (@$holding_branch_items) {
508
                        next if ( $item->{holdallowed} == 1 && $item->{homebranch} ne $request->{borrowerbranch} );
536
                        next if ( $item->{holdallowed} == 1 && $item->{homebranch} ne $request->{borrowerbranch} );
509
537
538
                        # Don't fill item level holds that contravene the hold pickup policy at this time
539
                        next unless $item->{hold_fulfillment_policy} eq 'any'
540
                            || $request->{branchcode} eq $item->{ $item->{hold_fulfillment_policy} };
541
510
                        $itemnumber = $item->{itemnumber};
542
                        $itemnumber = $item->{itemnumber};
511
                        $holdingbranch = $branch;
543
                        $holdingbranch = $branch;
512
                        last PULL_BRANCHES2;
544
                        last PULL_BRANCHES2;
(-)a/C4/Reserves.pm (+1 lines)
Lines 952-957 sub CheckReserves { Link Here
952
                    my $branchitemrule = C4::Circulation::GetBranchItemRule($branch,$iteminfo->{'itype'});
952
                    my $branchitemrule = C4::Circulation::GetBranchItemRule($branch,$iteminfo->{'itype'});
953
                    next if ($branchitemrule->{'holdallowed'} == 0);
953
                    next if ($branchitemrule->{'holdallowed'} == 0);
954
                    next if (($branchitemrule->{'holdallowed'} == 1) && ($branch ne $borrowerinfo->{'branchcode'}));
954
                    next if (($branchitemrule->{'holdallowed'} == 1) && ($branch ne $borrowerinfo->{'branchcode'}));
955
                    next if ( ($branchitemrule->{hold_fulfillment_policy} ne 'any') && ($res->{branchcode} ne $iteminfo->{ $branchitemrule->{hold_fulfillment_policy} }) );
955
                    $priority = $res->{'priority'};
956
                    $priority = $res->{'priority'};
956
                    $highest  = $res;
957
                    $highest  = $res;
957
                    last if $local_hold_match;
958
                    last if $local_hold_match;
(-)a/admin/smart-rules.pl (-41 / +45 lines)
Lines 193-198 elsif ($op eq "set-branch-defaults") { Link Here
193
    my $maxissueqty   = $input->param('maxissueqty');
193
    my $maxissueqty   = $input->param('maxissueqty');
194
    my $maxonsiteissueqty = $input->param('maxonsiteissueqty');
194
    my $maxonsiteissueqty = $input->param('maxonsiteissueqty');
195
    my $holdallowed   = $input->param('holdallowed');
195
    my $holdallowed   = $input->param('holdallowed');
196
    my $hold_fulfillment_policy = $input->param('hold_fulfillment_policy');
196
    my $returnbranch  = $input->param('returnbranch');
197
    my $returnbranch  = $input->param('returnbranch');
197
    $maxissueqty =~ s/\s//g;
198
    $maxissueqty =~ s/\s//g;
198
    $maxissueqty = undef if $maxissueqty !~ /^\d+/;
199
    $maxissueqty = undef if $maxissueqty !~ /^\d+/;
Lines 205-238 elsif ($op eq "set-branch-defaults") { Link Here
205
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
206
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
206
                                        FROM default_circ_rules");
207
                                        FROM default_circ_rules");
207
        my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules
208
        my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules
208
                                        (maxissueqty, maxonsiteissueqty, holdallowed, returnbranch)
209
                                        (maxissueqty, maxonsiteissueqty, holdallowed, hold_fulfillment_policy, returnbranch)
209
                                        VALUES (?, ?, ?, ?)");
210
                                        VALUES (?, ?, ?, ?, ?)");
210
        my $sth_update = $dbh->prepare("UPDATE default_circ_rules
211
        my $sth_update = $dbh->prepare("UPDATE default_circ_rules
211
                                        SET maxissueqty = ?, maxonsiteissueqty = ?, holdallowed = ?, returnbranch = ?");
212
                                        SET maxissueqty = ?, maxonsiteissueqty = ?, holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?");
212
213
213
        $sth_search->execute();
214
        $sth_search->execute();
214
        my $res = $sth_search->fetchrow_hashref();
215
        my $res = $sth_search->fetchrow_hashref();
215
        if ($res->{total}) {
216
        if ($res->{total}) {
216
            $sth_update->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $returnbranch);
217
            $sth_update->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch);
217
        } else {
218
        } else {
218
            $sth_insert->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $returnbranch);
219
            $sth_insert->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch);
219
        }
220
        }
220
    } else {
221
    } else {
221
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
222
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
222
                                        FROM default_branch_circ_rules
223
                                        FROM default_branch_circ_rules
223
                                        WHERE branchcode = ?");
224
                                        WHERE branchcode = ?");
224
        my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules
225
        my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules
225
                                        (branchcode, maxissueqty, maxonsiteissueqty, holdallowed, returnbranch)
226
                                        (branchcode, maxissueqty, maxonsiteissueqty, holdallowed, hold_fulfillment_policy, returnbranch)
226
                                        VALUES (?, ?, ?, ?, ?)");
227
                                        VALUES (?, ?, ?, ?, ?, ?)");
227
        my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules
228
        my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules
228
                                        SET maxissueqty = ?, maxonsiteissueqty = ?, holdallowed = ?, returnbranch = ?
229
                                        SET maxissueqty = ?, maxonsiteissueqty = ?, holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?
229
                                        WHERE branchcode = ?");
230
                                        WHERE branchcode = ?");
230
        $sth_search->execute($branch);
231
        $sth_search->execute($branch);
231
        my $res = $sth_search->fetchrow_hashref();
232
        my $res = $sth_search->fetchrow_hashref();
232
        if ($res->{total}) {
233
        if ($res->{total}) {
233
            $sth_update->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $returnbranch, $branch);
234
            $sth_update->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch, $branch);
234
        } else {
235
        } else {
235
            $sth_insert->execute($branch, $maxissueqty, $maxonsiteissueqty, $holdallowed, $returnbranch);
236
            $sth_insert->execute($branch, $maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch);
236
        }
237
        }
237
    }
238
    }
238
}
239
}
Lines 340-348 elsif ($op eq "add-branch-cat") { Link Here
340
    }
341
    }
341
}
342
}
342
elsif ($op eq "add-branch-item") {
343
elsif ($op eq "add-branch-item") {
343
    my $itemtype  = $input->param('itemtype');
344
    my $itemtype                = $input->param('itemtype');
344
    my $holdallowed   = $input->param('holdallowed');
345
    my $holdallowed             = $input->param('holdallowed');
345
    my $returnbranch  = $input->param('returnbranch');
346
    my $hold_fulfillment_policy = $input->param('hold_fulfillment_policy');
347
    my $returnbranch            = $input->param('returnbranch');
348
346
    $holdallowed =~ s/\s//g;
349
    $holdallowed =~ s/\s//g;
347
    $holdallowed = undef if $holdallowed !~ /^\d+/;
350
    $holdallowed = undef if $holdallowed !~ /^\d+/;
348
351
Lines 351-384 elsif ($op eq "add-branch-item") { Link Here
351
            my $sth_search = $dbh->prepare("SELECT count(*) AS total
354
            my $sth_search = $dbh->prepare("SELECT count(*) AS total
352
                                            FROM default_circ_rules");
355
                                            FROM default_circ_rules");
353
            my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules
356
            my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules
354
                                            (holdallowed, returnbranch)
357
                                            (holdallowed, hold_fulfillment_policy, returnbranch)
355
                                            VALUES (?, ?)");
358
                                            VALUES (?, ?, ?)");
356
            my $sth_update = $dbh->prepare("UPDATE default_circ_rules
359
            my $sth_update = $dbh->prepare("UPDATE default_circ_rules
357
                                            SET holdallowed = ?, returnbranch = ?");
360
                                            SET holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?");
358
361
359
            $sth_search->execute();
362
            $sth_search->execute();
360
            my $res = $sth_search->fetchrow_hashref();
363
            my $res = $sth_search->fetchrow_hashref();
361
            if ($res->{total}) {
364
            if ($res->{total}) {
362
                $sth_update->execute($holdallowed, $returnbranch);
365
                $sth_update->execute($holdallowed, $hold_fulfillment_policy, $returnbranch);
363
            } else {
366
            } else {
364
                $sth_insert->execute($holdallowed, $returnbranch);
367
                $sth_insert->execute($holdallowed, $hold_fulfillment_policy, $returnbranch);
365
            }
368
            }
366
        } else {
369
        } else {
367
            my $sth_search = $dbh->prepare("SELECT count(*) AS total
370
            my $sth_search = $dbh->prepare("SELECT count(*) AS total
368
                                            FROM default_branch_item_rules
371
                                            FROM default_branch_item_rules
369
                                            WHERE itemtype = ?");
372
                                            WHERE itemtype = ?");
370
            my $sth_insert = $dbh->prepare("INSERT INTO default_branch_item_rules
373
            my $sth_insert = $dbh->prepare("INSERT INTO default_branch_item_rules
371
                                            (itemtype, holdallowed, returnbranch)
374
                                            (itemtype, holdallowed, hold_fulfillment_policy, returnbranch)
372
                                            VALUES (?, ?, ?)");
375
                                            VALUES (?, ?, ?, ?)");
373
            my $sth_update = $dbh->prepare("UPDATE default_branch_item_rules
376
            my $sth_update = $dbh->prepare("UPDATE default_branch_item_rules
374
                                            SET holdallowed = ?, returnbranch = ?
377
                                            SET holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?
375
                                            WHERE itemtype = ?");
378
                                            WHERE itemtype = ?");
376
            $sth_search->execute($itemtype);
379
            $sth_search->execute($itemtype);
377
            my $res = $sth_search->fetchrow_hashref();
380
            my $res = $sth_search->fetchrow_hashref();
378
            if ($res->{total}) {
381
            if ($res->{total}) {
379
                $sth_update->execute($holdallowed, $returnbranch, $itemtype);
382
                $sth_update->execute($holdallowed, $hold_fulfillment_policy, $returnbranch, $itemtype);
380
            } else {
383
            } else {
381
                $sth_insert->execute($itemtype, $holdallowed, $returnbranch);
384
                $sth_insert->execute($itemtype, $holdallowed, $hold_fulfillment_policy, $returnbranch);
382
            }
385
            }
383
        }
386
        }
384
    } elsif ($itemtype eq "*") {
387
    } elsif ($itemtype eq "*") {
Lines 386-402 elsif ($op eq "add-branch-item") { Link Here
386
                                        FROM default_branch_circ_rules
389
                                        FROM default_branch_circ_rules
387
                                        WHERE branchcode = ?");
390
                                        WHERE branchcode = ?");
388
        my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules
391
        my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules
389
                                        (branchcode, holdallowed, returnbranch)
392
                                        (branchcode, holdallowed, hold_fulfillment_policy, returnbranch)
390
                                        VALUES (?, ?, ?)");
393
                                        VALUES (?, ?, ?, ?)");
391
        my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules
394
        my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules
392
                                        SET holdallowed = ?, returnbranch = ?
395
                                        SET holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?
393
                                        WHERE branchcode = ?");
396
                                        WHERE branchcode = ?");
394
        $sth_search->execute($branch);
397
        $sth_search->execute($branch);
395
        my $res = $sth_search->fetchrow_hashref();
398
        my $res = $sth_search->fetchrow_hashref();
396
        if ($res->{total}) {
399
        if ($res->{total}) {
397
            $sth_update->execute($holdallowed, $returnbranch, $branch);
400
            $sth_update->execute($holdallowed, $hold_fulfillment_policy, $returnbranch, $branch);
398
        } else {
401
        } else {
399
            $sth_insert->execute($branch, $holdallowed, $returnbranch);
402
            $sth_insert->execute($branch, $holdallowed, $hold_fulfillment_policy, $returnbranch);
400
        }
403
        }
401
    } else {
404
    } else {
402
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
405
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
Lines 404-422 elsif ($op eq "add-branch-item") { Link Here
404
                                        WHERE branchcode = ?
407
                                        WHERE branchcode = ?
405
                                        AND   itemtype = ?");
408
                                        AND   itemtype = ?");
406
        my $sth_insert = $dbh->prepare("INSERT INTO branch_item_rules
409
        my $sth_insert = $dbh->prepare("INSERT INTO branch_item_rules
407
                                        (branchcode, itemtype, holdallowed, returnbranch)
410
                                        (branchcode, itemtype, holdallowed, hold_fulfillment_policy, returnbranch)
408
                                        VALUES (?, ?, ?, ?)");
411
                                        VALUES (?, ?, ?, ?, ?)");
409
        my $sth_update = $dbh->prepare("UPDATE branch_item_rules
412
        my $sth_update = $dbh->prepare("UPDATE branch_item_rules
410
                                        SET holdallowed = ?, returnbranch = ?
413
                                        SET holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?
411
                                        WHERE branchcode = ?
414
                                        WHERE branchcode = ?
412
                                        AND itemtype = ?");
415
                                        AND itemtype = ?");
413
416
414
        $sth_search->execute($branch, $itemtype);
417
        $sth_search->execute($branch, $itemtype);
415
        my $res = $sth_search->fetchrow_hashref();
418
        my $res = $sth_search->fetchrow_hashref();
416
        if ($res->{total}) {
419
        if ($res->{total}) {
417
            $sth_update->execute($holdallowed, $returnbranch, $branch, $itemtype);
420
            $sth_update->execute($holdallowed, $hold_fulfillment_policy, $returnbranch, $branch, $itemtype);
418
        } else {
421
        } else {
419
            $sth_insert->execute($branch, $itemtype, $holdallowed, $returnbranch);
422
            $sth_insert->execute($branch, $itemtype, $holdallowed, $hold_fulfillment_policy, $returnbranch);
420
        }
423
        }
421
    }
424
    }
422
}
425
}
Lines 549-556 my @sorted_branch_item_rules = sort { lc $a->{translated_description} cmp lc $b- Link Here
549
552
550
# note undef holdallowed so that template can deal with them
553
# note undef holdallowed so that template can deal with them
551
foreach my $entry (@sorted_branch_item_rules) {
554
foreach my $entry (@sorted_branch_item_rules) {
552
    $entry->{holdallowed_any} = 1 if($entry->{holdallowed} == 2);
555
    $entry->{holdallowed_any}  = 1 if ( $entry->{holdallowed} == 2 );
553
    $entry->{holdallowed_same} = 1 if($entry->{holdallowed} == 1);
556
    $entry->{holdallowed_same} = 1 if ( $entry->{holdallowed} == 1 );
554
}
557
}
555
558
556
$template->param(show_branch_cat_rule_form => 1);
559
$template->param(show_branch_cat_rule_form => 1);
Lines 576-587 if ($branch eq "*") { Link Here
576
my $defaults = $sth_defaults->fetchrow_hashref;
579
my $defaults = $sth_defaults->fetchrow_hashref;
577
580
578
if ($defaults) {
581
if ($defaults) {
579
    $template->param(default_holdallowed_none => 1) if($defaults->{holdallowed} == 0);
582
    $template->param( default_holdallowed_none => 1 ) if ( $defaults->{holdallowed} == 0 );
580
    $template->param(default_holdallowed_same => 1) if($defaults->{holdallowed} == 1);
583
    $template->param( default_holdallowed_same => 1 ) if ( $defaults->{holdallowed} == 1 );
581
    $template->param(default_holdallowed_any => 1) if($defaults->{holdallowed} == 2);
584
    $template->param( default_holdallowed_any  => 1 ) if ( $defaults->{holdallowed} == 2 );
582
    $template->param(default_maxissueqty => $defaults->{maxissueqty});
585
    $template->param( default_hold_fulfillment_policy => $defaults->{hold_fulfillment_policy} );
583
    $template->param(default_maxonsiteissueqty => $defaults->{maxonsiteissueqty});
586
    $template->param( default_maxissueqty      => $defaults->{maxissueqty} );
584
    $template->param(default_returnbranch => $defaults->{returnbranch});
587
    $template->param( default_maxonsiteissueqty => $defaults->{maxonsiteissueqty} );
588
    $template->param( default_returnbranch      => $defaults->{returnbranch} );
585
}
589
}
586
590
587
$template->param(default_rules => ($defaults ? 1 : 0));
591
$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 348-353 CREATE TABLE `branch_item_rules` ( -- information entered in the circulation and Link Here
348
  `branchcode` varchar(10) NOT NULL, -- the branch this rule is for (branches.branchcode)
348
  `branchcode` varchar(10) NOT NULL, -- the branch this rule is for (branches.branchcode)
349
  `itemtype` varchar(10) NOT NULL, -- the item type this rule applies to (items.itype)
349
  `itemtype` varchar(10) NOT NULL, -- the item type this rule applies to (items.itype)
350
  `holdallowed` tinyint(1) default NULL, -- the number of holds allowed
350
  `holdallowed` tinyint(1) default NULL, -- the number of holds allowed
351
  hold_fulfillment_policy ENUM('any', 'homebranch', 'holdingbranch') NOT NULL DEFAULT 'any', -- limit trapping of holds by branchcode
351
  `returnbranch` varchar(15) default NULL, -- the branch the item returns to (homebranch, holdingbranch, noreturn)
352
  `returnbranch` varchar(15) default NULL, -- the branch the item returns to (homebranch, holdingbranch, noreturn)
352
  PRIMARY KEY  (`itemtype`,`branchcode`),
353
  PRIMARY KEY  (`itemtype`,`branchcode`),
353
  KEY `branch_item_rules_ibfk_2` (`branchcode`),
354
  KEY `branch_item_rules_ibfk_2` (`branchcode`),
Lines 681-686 CREATE TABLE `default_branch_circ_rules` ( Link Here
681
  `maxissueqty` int(4) default NULL,
682
  `maxissueqty` int(4) default NULL,
682
  `maxonsiteissueqty` int(4) default NULL,
683
  `maxonsiteissueqty` int(4) default NULL,
683
  `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
684
  `returnbranch` varchar(15) default NULL,
686
  `returnbranch` varchar(15) default NULL,
685
  PRIMARY KEY (`branchcode`),
687
  PRIMARY KEY (`branchcode`),
686
  CONSTRAINT `default_branch_circ_rules_ibfk_1` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`)
688
  CONSTRAINT `default_branch_circ_rules_ibfk_1` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`)
Lines 694-699 DROP TABLE IF EXISTS `default_branch_item_rules`; Link Here
694
CREATE TABLE `default_branch_item_rules` (
696
CREATE TABLE `default_branch_item_rules` (
695
  `itemtype` varchar(10) NOT NULL,
697
  `itemtype` varchar(10) NOT NULL,
696
  `holdallowed` tinyint(1) default NULL,
698
  `holdallowed` tinyint(1) default NULL,
699
  hold_fulfillment_policy ENUM('any', 'homebranch', 'holdingbranch') NOT NULL DEFAULT 'any', -- limit trapping of holds by branchcode
697
  `returnbranch` varchar(15) default NULL,
700
  `returnbranch` varchar(15) default NULL,
698
  PRIMARY KEY  (`itemtype`),
701
  PRIMARY KEY  (`itemtype`),
699
  CONSTRAINT `default_branch_item_rules_ibfk_1` FOREIGN KEY (`itemtype`) REFERENCES `itemtypes` (`itemtype`)
702
  CONSTRAINT `default_branch_item_rules_ibfk_1` FOREIGN KEY (`itemtype`) REFERENCES `itemtypes` (`itemtype`)
Lines 710-715 CREATE TABLE `default_circ_rules` ( Link Here
710
    `maxissueqty` int(4) default NULL,
713
    `maxissueqty` int(4) default NULL,
711
    `maxonsiteissueqty` int(4) default NULL,
714
    `maxonsiteissueqty` int(4) default NULL,
712
    `holdallowed` int(1) default NULL,
715
    `holdallowed` int(1) default NULL,
716
    hold_fulfillment_policy ENUM('any', 'homebranch', 'holdingbranch') NOT NULL DEFAULT 'any', -- limit trapping of holds by branchcode
713
    `returnbranch` varchar(15) default NULL,
717
    `returnbranch` varchar(15) default NULL,
714
    PRIMARY KEY (`singleton`)
718
    PRIMARY KEY (`singleton`)
715
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
719
) 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 (-6 / +114 lines)
Lines 8-16 Link Here
8
8
9
use Modern::Perl;
9
use Modern::Perl;
10
10
11
use Test::More tests => 26;
11
use Test::More tests => 35;
12
use Data::Dumper;
12
use Data::Dumper;
13
13
14
14
use C4::Branch;
15
use C4::Branch;
15
use C4::Calendar;
16
use C4::Calendar;
16
use C4::Context;
17
use C4::Context;
Lines 51-57 my $TITLE = "Test Holds Queue XXX"; Link Here
51
my $borrower = $builder->build({
52
my $borrower = $builder->build({
52
    source => 'Borrower',
53
    source => 'Borrower',
53
    value => {
54
    value => {
54
        categorycode => 'S',
55
        branchcode => $library1->{branchcode},
55
        branchcode => $library1->{branchcode},
56
    }
56
    }
57
});
57
});
Lines 196-216 $library3 = $builder->build({ Link Here
196
my $borrower1 = $builder->build({
196
my $borrower1 = $builder->build({
197
    source => 'Borrower',
197
    source => 'Borrower',
198
    value => {
198
    value => {
199
        categorycode => 'S',
200
        branchcode => $branchcodes[0],
199
        branchcode => $branchcodes[0],
201
    },
200
    },
202
});
201
});
203
my $borrower2 = $builder->build({
202
my $borrower2 = $builder->build({
204
    source => 'Borrower',
203
    source => 'Borrower',
205
    value => {
204
    value => {
206
        categorycode => 'S',
207
        branchcode => $branchcodes[1],
205
        branchcode => $branchcodes[1],
208
    },
206
    },
209
});
207
});
210
my $borrower3 = $builder->build({
208
my $borrower3 = $builder->build({
211
    source => 'Borrower',
209
    source => 'Borrower',
212
    value => {
210
    value => {
213
        categorycode => 'S',
214
        branchcode => $branchcodes[2],
211
        branchcode => $branchcodes[2],
215
    },
212
    },
216
});
213
});
Lines 446-451 $holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice Link Here
446
is( @$holds_queue, 0, "Bug 15062 - Holds queue with Transport Cost Matrix will transfer item even if transfers disabled");
443
is( @$holds_queue, 0, "Bug 15062 - Holds queue with Transport Cost Matrix will transfer item even if transfers disabled");
447
# End Bug 15062
444
# End Bug 15062
448
445
446
# Test hold_fulfillment_policy
447
C4::Context->set_preference( "UseTransportCostMatrix", 0 );
448
$borrowernumber = $borrower3->{borrowernumber};
449
$library_A = $library1->{branchcode};
450
$library_B = $library2->{branchcode};
451
$library_C = $library3->{branchcode};
452
$dbh->do("DELETE FROM reserves");
453
$dbh->do("DELETE FROM issues");
454
$dbh->do("DELETE FROM items");
455
$dbh->do("DELETE FROM biblio");
456
$dbh->do("DELETE FROM biblioitems");
457
$dbh->do("DELETE FROM transport_cost");
458
$dbh->do("DELETE FROM tmp_holdsqueue");
459
$dbh->do("DELETE FROM hold_fill_targets");
460
$dbh->do("DELETE FROM default_branch_circ_rules");
461
$dbh->do("DELETE FROM default_branch_item_rules");
462
$dbh->do("DELETE FROM default_circ_rules");
463
$dbh->do("DELETE FROM branch_item_rules");
464
465
$dbh->do("INSERT INTO biblio (frameworkcode, author, title, datecreated) VALUES ('', 'Koha test', '$TITLE', '2011-02-01')");
466
467
$biblionumber = $dbh->selectrow_array("SELECT biblionumber FROM biblio WHERE title = '$TITLE'")
468
  or BAIL_OUT("Cannot find newly created biblio record");
469
470
$dbh->do("INSERT INTO biblioitems (biblionumber, marcxml, itemtype) VALUES ($biblionumber, '', '$itemtype')");
471
472
$biblioitemnumber =
473
  $dbh->selectrow_array("SELECT biblioitemnumber FROM biblioitems WHERE biblionumber = $biblionumber")
474
  or BAIL_OUT("Cannot find newly created biblioitems record");
475
476
$dbh->do("
477
    INSERT INTO items (biblionumber, biblioitemnumber, homebranch, holdingbranch, notforloan, damaged, itemlost, withdrawn, onloan, itype)
478
    VALUES ($biblionumber, $biblioitemnumber, '$library_A', '$library_B', 0, 0, 0, 0, NULL, '$itemtype')
479
");
480
481
# With hold_fulfillment_policy = homebranch, hold should only be picked up if pickup branch = homebranch
482
$dbh->do("DELETE FROM default_circ_rules");
483
$dbh->do("INSERT INTO default_circ_rules ( holdallowed, hold_fulfillment_policy ) VALUES ( 2, 'homebranch' )");
484
485
# Home branch matches pickup branch
486
$reserve_id = AddReserve( $library_A, $borrowernumber, $biblionumber, '', 1 );
487
C4::HoldsQueue::CreateQueue();
488
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
489
is( @$holds_queue, 1, "Hold where pickup branch matches home branch targeted" );
490
CancelReserve( { reserve_id => $reserve_id } );
491
492
# Holding branch matches pickup branch
493
$reserve_id = AddReserve( $library_B, $borrowernumber, $biblionumber, '', 1 );
494
C4::HoldsQueue::CreateQueue();
495
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
496
is( @$holds_queue, 0, "Hold where pickup ne home, pickup eq home not targeted" );
497
CancelReserve( { reserve_id => $reserve_id } );
498
499
# Neither branch matches pickup branch
500
$reserve_id = AddReserve( $library_C, $borrowernumber, $biblionumber, '', 1 );
501
C4::HoldsQueue::CreateQueue();
502
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
503
is( @$holds_queue, 0, "Hold where pickup ne home, pickup ne holding not targeted" );
504
CancelReserve( { reserve_id => $reserve_id } );
505
506
# With hold_fulfillment_policy = holdingbranch, hold should only be picked up if pickup branch = holdingbranch
507
$dbh->do("DELETE FROM default_circ_rules");
508
$dbh->do("INSERT INTO default_circ_rules ( holdallowed, hold_fulfillment_policy ) VALUES ( 2, 'holdingbranch' )");
509
510
# Home branch matches pickup branch
511
$reserve_id = AddReserve( $library_A, $borrowernumber, $biblionumber, '', 1 );
512
C4::HoldsQueue::CreateQueue();
513
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
514
is( @$holds_queue, 0, "Hold where pickup eq home, pickup ne holding not targeted" );
515
CancelReserve( { reserve_id => $reserve_id } );
516
517
# Holding branch matches pickup branch
518
$reserve_id = AddReserve( $library_B, $borrowernumber, $biblionumber, '', 1 );
519
C4::HoldsQueue::CreateQueue();
520
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
521
is( @$holds_queue, 1, "Hold where pickup ne home, pickup eq holding targeted" );
522
CancelReserve( { reserve_id => $reserve_id } );
523
524
# Neither branch matches pickup branch
525
$reserve_id = AddReserve( $library_C, $borrowernumber, $biblionumber, '', 1 );
526
C4::HoldsQueue::CreateQueue();
527
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
528
is( @$holds_queue, 0, "Hold where pickup ne home, pickup ne holding not targeted" );
529
CancelReserve( { reserve_id => $reserve_id } );
530
531
# With hold_fulfillment_policy = any, hold should be pikcup up reguardless of matching home or holding branch
532
$dbh->do("DELETE FROM default_circ_rules");
533
$dbh->do("INSERT INTO default_circ_rules ( holdallowed, hold_fulfillment_policy ) VALUES ( 2, 'any' )");
534
535
# Home branch matches pickup branch
536
$reserve_id = AddReserve( $library_A, $borrowernumber, $biblionumber, '', 1 );
537
C4::HoldsQueue::CreateQueue();
538
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
539
is( @$holds_queue, 1, "Hold where pickup eq home, pickup ne holding targeted" );
540
CancelReserve( { reserve_id => $reserve_id } );
541
542
# Holding branch matches pickup branch
543
$reserve_id = AddReserve( $library_B, $borrowernumber, $biblionumber, '', 1 );
544
C4::HoldsQueue::CreateQueue();
545
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
546
is( @$holds_queue, 1, "Hold where pickup ne home, pickup eq holding targeted" );
547
CancelReserve( { reserve_id => $reserve_id } );
548
549
# Neither branch matches pickup branch
550
$reserve_id = AddReserve( $library_C, $borrowernumber, $biblionumber, '', 1 );
551
C4::HoldsQueue::CreateQueue();
552
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
553
is( @$holds_queue, 1, "Hold where pickup ne home, pickup ne holding targeted" );
554
CancelReserve( { reserve_id => $reserve_id } );
555
556
# End testing hold_fulfillment_policy
557
449
# Cleanup
558
# Cleanup
450
$schema->storage->txn_rollback;
559
$schema->storage->txn_rollback;
451
560
452
- 

Return to bug 15532