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

(-)a/C4/Circulation.pm (-4 / +6 lines)
Lines 1725-1741 sub GetBranchItemRule { Link Here
1725
    my $result = {};
1725
    my $result = {};
1726
1726
1727
    my @attempts = (
1727
    my @attempts = (
1728
        ['SELECT holdallowed, returnbranch
1728
        ['SELECT holdallowed, returnbranch, hold_fulfillment_policy
1729
            FROM branch_item_rules
1729
            FROM branch_item_rules
1730
            WHERE branchcode = ?
1730
            WHERE branchcode = ?
1731
              AND itemtype = ?', $branchcode, $itemtype],
1731
              AND itemtype = ?', $branchcode, $itemtype],
1732
        ['SELECT holdallowed, returnbranch
1732
        ['SELECT holdallowed, returnbranch, hold_fulfillment_policy
1733
            FROM default_branch_circ_rules
1733
            FROM default_branch_circ_rules
1734
            WHERE branchcode = ?', $branchcode],
1734
            WHERE branchcode = ?', $branchcode],
1735
        ['SELECT holdallowed, returnbranch
1735
        ['SELECT holdallowed, returnbranch, hold_fulfillment_policy
1736
            FROM default_branch_item_rules
1736
            FROM default_branch_item_rules
1737
            WHERE itemtype = ?', $itemtype],
1737
            WHERE itemtype = ?', $itemtype],
1738
        ['SELECT holdallowed, returnbranch
1738
        ['SELECT holdallowed, returnbranch, hold_fulfillment_policy
1739
            FROM default_circ_rules'],
1739
            FROM default_circ_rules'],
1740
    );
1740
    );
1741
1741
Lines 1748-1758 sub GetBranchItemRule { Link Here
1748
        # defaults tables, we have to check that the key we want is set, not
1748
        # defaults tables, we have to check that the key we want is set, not
1749
        # just that a row was returned
1749
        # just that a row was returned
1750
        $result->{'holdallowed'}  = $search_result->{'holdallowed'}  unless ( defined $result->{'holdallowed'} );
1750
        $result->{'holdallowed'}  = $search_result->{'holdallowed'}  unless ( defined $result->{'holdallowed'} );
1751
        $result->{'hold_fulfillment_policy'} = $search_result->{'hold_fulfillment_policy'} unless ( defined $result->{'hold_fulfillment_policy'} );
1751
        $result->{'returnbranch'} = $search_result->{'returnbranch'} unless ( defined $result->{'returnbranch'} );
1752
        $result->{'returnbranch'} = $search_result->{'returnbranch'} unless ( defined $result->{'returnbranch'} );
1752
    }
1753
    }
1753
    
1754
    
1754
    # built-in default circulation rule
1755
    # built-in default circulation rule
1755
    $result->{'holdallowed'} = 2 unless ( defined $result->{'holdallowed'} );
1756
    $result->{'holdallowed'} = 2 unless ( defined $result->{'holdallowed'} );
1757
    $result->{'hold_fulfillment_policy'} = 'any' unless ( defined $result->{'hold_fulfillment_policy'} );
1756
    $result->{'returnbranch'} = 'homebranch' unless ( defined $result->{'returnbranch'} );
1758
    $result->{'returnbranch'} = 'homebranch' unless ( defined $result->{'returnbranch'} );
1757
1759
1758
    return $result;
1760
    return $result;
(-)a/C4/HoldsQueue.pm (-11 / +43 lines)
Lines 356-361 sub GetItemsAvailableToFillHoldRequestsForBib { Link Here
356
    return [ grep {
356
    return [ grep {
357
        my $rule = GetBranchItemRule($_->{homebranch}, $_->{itype});
357
        my $rule = GetBranchItemRule($_->{homebranch}, $_->{itype});
358
        $_->{holdallowed} = $rule->{holdallowed};
358
        $_->{holdallowed} = $rule->{holdallowed};
359
        $_->{hold_fulfillment_policy} = $rule->{hold_fulfillment_policy};
359
    } @items ];
360
    } @items ];
360
}
361
}
361
362
Lines 394-411 sub MapItemsToHoldRequests { Link Here
394
        # is this an item-level request?
395
        # is this an item-level request?
395
        if (defined($request->{itemnumber})) {
396
        if (defined($request->{itemnumber})) {
396
            # fill it if possible; if not skip it
397
            # fill it if possible; if not skip it
397
            if (exists $items_by_itemnumber{$request->{itemnumber}} and
398
            if (
398
                not exists $allocated_items{$request->{itemnumber}}) {
399
                    exists $items_by_itemnumber{ $request->{itemnumber} }
399
                $item_map{$request->{itemnumber}} = {
400
                and not exists $allocated_items{ $request->{itemnumber} }
401
                and ( # Don't fill item level holds that contravene the hold pickup policy at this time
402
                    ( $items_by_itemnumber{ $request->{itemnumber} }->{hold_fulfillment_policy} eq 'any' )
403
                    || ( $request->{branchcode} eq $items_by_itemnumber{ $request->{itemnumber} }->{ $items_by_itemnumber{ $request->{itemnumber} }->{hold_fulfillment_policy} }  )
404
                )
405
406
              )
407
            {
408
409
                $item_map{ $request->{itemnumber} } = {
400
                    borrowernumber => $request->{borrowernumber},
410
                    borrowernumber => $request->{borrowernumber},
401
                    biblionumber => $request->{biblionumber},
411
                    biblionumber   => $request->{biblionumber},
402
                    holdingbranch =>  $items_by_itemnumber{$request->{itemnumber}}->{holdingbranch},
412
                    holdingbranch  => $items_by_itemnumber{ $request->{itemnumber} }->{holdingbranch},
403
                    pickup_branch => $request->{branchcode} || $request->{borrowerbranch},
413
                    pickup_branch  => $request->{branchcode} || $request->{borrowerbranch},
404
                    item_level => 1,
414
                    item_level     => 1,
405
                    reservedate => $request->{reservedate},
415
                    reservedate    => $request->{reservedate},
406
                    reservenotes => $request->{reservenotes},
416
                    reservenotes   => $request->{reservenotes},
407
                };
417
                };
408
                $allocated_items{$request->{itemnumber}}++;
418
                $allocated_items{ $request->{itemnumber} }++;
409
                $num_items_remaining--;
419
                $num_items_remaining--;
410
            }
420
            }
411
        } else {
421
        } else {
Lines 438-444 sub MapItemsToHoldRequests { Link Here
438
        my $holding_branch_items = $items_by_branch{$pickup_branch};
448
        my $holding_branch_items = $items_by_branch{$pickup_branch};
439
        if ( $holding_branch_items ) {
449
        if ( $holding_branch_items ) {
440
            foreach my $item (@$holding_branch_items) {
450
            foreach my $item (@$holding_branch_items) {
441
                if ( $request->{borrowerbranch} eq $item->{homebranch} ) {
451
                if (
452
                    $request->{borrowerbranch} eq $item->{homebranch}
453
                    && ( ( $item->{hold_fulfillment_policy} eq 'any' ) # Don't fill item level holds that contravene the hold pickup policy at this time
454
                        || $request->{branchcode} eq $item->{ $item->{hold_fulfillment_policy} } )
455
                  )
456
                {
442
                    $itemnumber = $item->{itemnumber};
457
                    $itemnumber = $item->{itemnumber};
443
                    last;
458
                    last;
444
                }
459
                }
Lines 454-459 sub MapItemsToHoldRequests { Link Here
454
                foreach my $item (@$holding_branch_items) {
469
                foreach my $item (@$holding_branch_items) {
455
                    next if $request->{borrowerbranch} ne $item->{homebranch};
470
                    next if $request->{borrowerbranch} ne $item->{homebranch};
456
471
472
                    # Don't fill item level holds that contravene the hold pickup policy at this time
473
                    next unless $item->{hold_fulfillment_policy} eq 'any'
474
                        || $request->{branchcode} eq $item->{ $item->{hold_fulfillment_policy} };
475
457
                    $itemnumber = $item->{itemnumber};
476
                    $itemnumber = $item->{itemnumber};
458
                    last;
477
                    last;
459
                }
478
                }
Lines 482-487 sub MapItemsToHoldRequests { Link Here
482
                    next if $pickup_branch ne $item->{homebranch};
501
                    next if $pickup_branch ne $item->{homebranch};
483
                    next if ( $item->{holdallowed} == 1 && $item->{homebranch} ne $request->{borrowerbranch} );
502
                    next if ( $item->{holdallowed} == 1 && $item->{homebranch} ne $request->{borrowerbranch} );
484
503
504
                    # Don't fill item level holds that contravene the hold pickup policy at this time
505
                    next unless $item->{hold_fulfillment_policy} eq 'any'
506
                        || $request->{branchcode} eq $item->{ $item->{hold_fulfillment_policy} };
507
485
                    $itemnumber = $item->{itemnumber};
508
                    $itemnumber = $item->{itemnumber};
486
                    $holdingbranch = $branch;
509
                    $holdingbranch = $branch;
487
                    last PULL_BRANCHES;
510
                    last PULL_BRANCHES;
Lines 492-497 sub MapItemsToHoldRequests { Link Here
492
            unless ( $itemnumber ) {
515
            unless ( $itemnumber ) {
493
                foreach my $current_item ( @{ $items_by_branch{$holdingbranch} } ) {
516
                foreach my $current_item ( @{ $items_by_branch{$holdingbranch} } ) {
494
                    if ( $holdingbranch && ( $current_item->{holdallowed} == 2 || $request->{borrowerbranch} eq $current_item->{homebranch} ) ) {
517
                    if ( $holdingbranch && ( $current_item->{holdallowed} == 2 || $request->{borrowerbranch} eq $current_item->{homebranch} ) ) {
518
519
                        # Don't fill item level holds that contravene the hold pickup policy at this time
520
                        next unless $current_item->{hold_fulfillment_policy} eq 'any'
521
                            || $request->{branchcode} eq $current_item->{ $current_item->{hold_fulfillment_policy} };
522
495
                        $itemnumber = $current_item->{itemnumber};
523
                        $itemnumber = $current_item->{itemnumber};
496
                        last; # quit this loop as soon as we have a suitable item
524
                        last; # quit this loop as soon as we have a suitable item
497
                    }
525
                    }
Lines 508-513 sub MapItemsToHoldRequests { Link Here
508
                    foreach my $item (@$holding_branch_items) {
536
                    foreach my $item (@$holding_branch_items) {
509
                        next if ( $item->{holdallowed} == 1 && $item->{homebranch} ne $request->{borrowerbranch} );
537
                        next if ( $item->{holdallowed} == 1 && $item->{homebranch} ne $request->{borrowerbranch} );
510
538
539
                        # Don't fill item level holds that contravene the hold pickup policy at this time
540
                        next unless $item->{hold_fulfillment_policy} eq 'any'
541
                            || $request->{branchcode} eq $item->{ $item->{hold_fulfillment_policy} };
542
511
                        $itemnumber = $item->{itemnumber};
543
                        $itemnumber = $item->{itemnumber};
512
                        $holdingbranch = $branch;
544
                        $holdingbranch = $branch;
513
                        last PULL_BRANCHES2;
545
                        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 192-197 elsif ($op eq "set-branch-defaults") { Link Here
192
    my $maxissueqty   = $input->param('maxissueqty');
192
    my $maxissueqty   = $input->param('maxissueqty');
193
    my $maxonsiteissueqty = $input->param('maxonsiteissueqty');
193
    my $maxonsiteissueqty = $input->param('maxonsiteissueqty');
194
    my $holdallowed   = $input->param('holdallowed');
194
    my $holdallowed   = $input->param('holdallowed');
195
    my $hold_fulfillment_policy = $input->param('hold_fulfillment_policy');
195
    my $returnbranch  = $input->param('returnbranch');
196
    my $returnbranch  = $input->param('returnbranch');
196
    $maxissueqty =~ s/\s//g;
197
    $maxissueqty =~ s/\s//g;
197
    $maxissueqty = undef if $maxissueqty !~ /^\d+/;
198
    $maxissueqty = undef if $maxissueqty !~ /^\d+/;
Lines 204-237 elsif ($op eq "set-branch-defaults") { Link Here
204
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
205
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
205
                                        FROM default_circ_rules");
206
                                        FROM default_circ_rules");
206
        my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules
207
        my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules
207
                                        (maxissueqty, maxonsiteissueqty, holdallowed, returnbranch)
208
                                        (maxissueqty, maxonsiteissueqty, holdallowed, hold_fulfillment_policy, returnbranch)
208
                                        VALUES (?, ?, ?, ?)");
209
                                        VALUES (?, ?, ?, ?, ?)");
209
        my $sth_update = $dbh->prepare("UPDATE default_circ_rules
210
        my $sth_update = $dbh->prepare("UPDATE default_circ_rules
210
                                        SET maxissueqty = ?, maxonsiteissueqty = ?, holdallowed = ?, returnbranch = ?");
211
                                        SET maxissueqty = ?, maxonsiteissueqty = ?, holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?");
211
212
212
        $sth_search->execute();
213
        $sth_search->execute();
213
        my $res = $sth_search->fetchrow_hashref();
214
        my $res = $sth_search->fetchrow_hashref();
214
        if ($res->{total}) {
215
        if ($res->{total}) {
215
            $sth_update->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $returnbranch);
216
            $sth_update->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch);
216
        } else {
217
        } else {
217
            $sth_insert->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $returnbranch);
218
            $sth_insert->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch);
218
        }
219
        }
219
    } else {
220
    } else {
220
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
221
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
221
                                        FROM default_branch_circ_rules
222
                                        FROM default_branch_circ_rules
222
                                        WHERE branchcode = ?");
223
                                        WHERE branchcode = ?");
223
        my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules
224
        my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules
224
                                        (branchcode, maxissueqty, maxonsiteissueqty, holdallowed, returnbranch)
225
                                        (branchcode, maxissueqty, maxonsiteissueqty, holdallowed, hold_fulfillment_policy, returnbranch)
225
                                        VALUES (?, ?, ?, ?, ?)");
226
                                        VALUES (?, ?, ?, ?, ?, ?)");
226
        my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules
227
        my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules
227
                                        SET maxissueqty = ?, maxonsiteissueqty = ?, holdallowed = ?, returnbranch = ?
228
                                        SET maxissueqty = ?, maxonsiteissueqty = ?, holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?
228
                                        WHERE branchcode = ?");
229
                                        WHERE branchcode = ?");
229
        $sth_search->execute($branch);
230
        $sth_search->execute($branch);
230
        my $res = $sth_search->fetchrow_hashref();
231
        my $res = $sth_search->fetchrow_hashref();
231
        if ($res->{total}) {
232
        if ($res->{total}) {
232
            $sth_update->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $returnbranch, $branch);
233
            $sth_update->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch, $branch);
233
        } else {
234
        } else {
234
            $sth_insert->execute($branch, $maxissueqty, $maxonsiteissueqty, $holdallowed, $returnbranch);
235
            $sth_insert->execute($branch, $maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch);
235
        }
236
        }
236
    }
237
    }
237
}
238
}
Lines 339-347 elsif ($op eq "add-branch-cat") { Link Here
339
    }
340
    }
340
}
341
}
341
elsif ($op eq "add-branch-item") {
342
elsif ($op eq "add-branch-item") {
342
    my $itemtype  = $input->param('itemtype');
343
    my $itemtype                = $input->param('itemtype');
343
    my $holdallowed   = $input->param('holdallowed');
344
    my $holdallowed             = $input->param('holdallowed');
344
    my $returnbranch  = $input->param('returnbranch');
345
    my $hold_fulfillment_policy = $input->param('hold_fulfillment_policy');
346
    my $returnbranch            = $input->param('returnbranch');
347
345
    $holdallowed =~ s/\s//g;
348
    $holdallowed =~ s/\s//g;
346
    $holdallowed = undef if $holdallowed !~ /^\d+/;
349
    $holdallowed = undef if $holdallowed !~ /^\d+/;
347
350
Lines 350-383 elsif ($op eq "add-branch-item") { Link Here
350
            my $sth_search = $dbh->prepare("SELECT count(*) AS total
353
            my $sth_search = $dbh->prepare("SELECT count(*) AS total
351
                                            FROM default_circ_rules");
354
                                            FROM default_circ_rules");
352
            my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules
355
            my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules
353
                                            (holdallowed, returnbranch)
356
                                            (holdallowed, hold_fulfillment_policy, returnbranch)
354
                                            VALUES (?, ?)");
357
                                            VALUES (?, ?, ?)");
355
            my $sth_update = $dbh->prepare("UPDATE default_circ_rules
358
            my $sth_update = $dbh->prepare("UPDATE default_circ_rules
356
                                            SET holdallowed = ?, returnbranch = ?");
359
                                            SET holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?");
357
360
358
            $sth_search->execute();
361
            $sth_search->execute();
359
            my $res = $sth_search->fetchrow_hashref();
362
            my $res = $sth_search->fetchrow_hashref();
360
            if ($res->{total}) {
363
            if ($res->{total}) {
361
                $sth_update->execute($holdallowed, $returnbranch);
364
                $sth_update->execute($holdallowed, $hold_fulfillment_policy, $returnbranch);
362
            } else {
365
            } else {
363
                $sth_insert->execute($holdallowed, $returnbranch);
366
                $sth_insert->execute($holdallowed, $hold_fulfillment_policy, $returnbranch);
364
            }
367
            }
365
        } else {
368
        } else {
366
            my $sth_search = $dbh->prepare("SELECT count(*) AS total
369
            my $sth_search = $dbh->prepare("SELECT count(*) AS total
367
                                            FROM default_branch_item_rules
370
                                            FROM default_branch_item_rules
368
                                            WHERE itemtype = ?");
371
                                            WHERE itemtype = ?");
369
            my $sth_insert = $dbh->prepare("INSERT INTO default_branch_item_rules
372
            my $sth_insert = $dbh->prepare("INSERT INTO default_branch_item_rules
370
                                            (itemtype, holdallowed, returnbranch)
373
                                            (itemtype, holdallowed, hold_fulfillment_policy, returnbranch)
371
                                            VALUES (?, ?, ?)");
374
                                            VALUES (?, ?, ?, ?)");
372
            my $sth_update = $dbh->prepare("UPDATE default_branch_item_rules
375
            my $sth_update = $dbh->prepare("UPDATE default_branch_item_rules
373
                                            SET holdallowed = ?, returnbranch = ?
376
                                            SET holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?
374
                                            WHERE itemtype = ?");
377
                                            WHERE itemtype = ?");
375
            $sth_search->execute($itemtype);
378
            $sth_search->execute($itemtype);
376
            my $res = $sth_search->fetchrow_hashref();
379
            my $res = $sth_search->fetchrow_hashref();
377
            if ($res->{total}) {
380
            if ($res->{total}) {
378
                $sth_update->execute($holdallowed, $returnbranch, $itemtype);
381
                $sth_update->execute($holdallowed, $hold_fulfillment_policy, $returnbranch, $itemtype);
379
            } else {
382
            } else {
380
                $sth_insert->execute($itemtype, $holdallowed, $returnbranch);
383
                $sth_insert->execute($itemtype, $holdallowed, $hold_fulfillment_policy, $returnbranch);
381
            }
384
            }
382
        }
385
        }
383
    } elsif ($itemtype eq "*") {
386
    } elsif ($itemtype eq "*") {
Lines 385-401 elsif ($op eq "add-branch-item") { Link Here
385
                                        FROM default_branch_circ_rules
388
                                        FROM default_branch_circ_rules
386
                                        WHERE branchcode = ?");
389
                                        WHERE branchcode = ?");
387
        my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules
390
        my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules
388
                                        (branchcode, holdallowed, returnbranch)
391
                                        (branchcode, holdallowed, hold_fulfillment_policy, returnbranch)
389
                                        VALUES (?, ?, ?)");
392
                                        VALUES (?, ?, ?, ?)");
390
        my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules
393
        my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules
391
                                        SET holdallowed = ?, returnbranch = ?
394
                                        SET holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?
392
                                        WHERE branchcode = ?");
395
                                        WHERE branchcode = ?");
393
        $sth_search->execute($branch);
396
        $sth_search->execute($branch);
394
        my $res = $sth_search->fetchrow_hashref();
397
        my $res = $sth_search->fetchrow_hashref();
395
        if ($res->{total}) {
398
        if ($res->{total}) {
396
            $sth_update->execute($holdallowed, $returnbranch, $branch);
399
            $sth_update->execute($holdallowed, $hold_fulfillment_policy, $returnbranch, $branch);
397
        } else {
400
        } else {
398
            $sth_insert->execute($branch, $holdallowed, $returnbranch);
401
            $sth_insert->execute($branch, $holdallowed, $hold_fulfillment_policy, $returnbranch);
399
        }
402
        }
400
    } else {
403
    } else {
401
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
404
        my $sth_search = $dbh->prepare("SELECT count(*) AS total
Lines 403-421 elsif ($op eq "add-branch-item") { Link Here
403
                                        WHERE branchcode = ?
406
                                        WHERE branchcode = ?
404
                                        AND   itemtype = ?");
407
                                        AND   itemtype = ?");
405
        my $sth_insert = $dbh->prepare("INSERT INTO branch_item_rules
408
        my $sth_insert = $dbh->prepare("INSERT INTO branch_item_rules
406
                                        (branchcode, itemtype, holdallowed, returnbranch)
409
                                        (branchcode, itemtype, holdallowed, hold_fulfillment_policy, returnbranch)
407
                                        VALUES (?, ?, ?, ?)");
410
                                        VALUES (?, ?, ?, ?, ?)");
408
        my $sth_update = $dbh->prepare("UPDATE branch_item_rules
411
        my $sth_update = $dbh->prepare("UPDATE branch_item_rules
409
                                        SET holdallowed = ?, returnbranch = ?
412
                                        SET holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?
410
                                        WHERE branchcode = ?
413
                                        WHERE branchcode = ?
411
                                        AND itemtype = ?");
414
                                        AND itemtype = ?");
412
415
413
        $sth_search->execute($branch, $itemtype);
416
        $sth_search->execute($branch, $itemtype);
414
        my $res = $sth_search->fetchrow_hashref();
417
        my $res = $sth_search->fetchrow_hashref();
415
        if ($res->{total}) {
418
        if ($res->{total}) {
416
            $sth_update->execute($holdallowed, $returnbranch, $branch, $itemtype);
419
            $sth_update->execute($holdallowed, $hold_fulfillment_policy, $returnbranch, $branch, $itemtype);
417
        } else {
420
        } else {
418
            $sth_insert->execute($branch, $itemtype, $holdallowed, $returnbranch);
421
            $sth_insert->execute($branch, $itemtype, $holdallowed, $hold_fulfillment_policy, $returnbranch);
419
        }
422
        }
420
    }
423
    }
421
}
424
}
Lines 548-555 my @sorted_branch_item_rules = sort { lc $a->{translated_description} cmp lc $b- Link Here
548
551
549
# note undef holdallowed so that template can deal with them
552
# note undef holdallowed so that template can deal with them
550
foreach my $entry (@sorted_branch_item_rules) {
553
foreach my $entry (@sorted_branch_item_rules) {
551
    $entry->{holdallowed_any} = 1 if($entry->{holdallowed} == 2);
554
    $entry->{holdallowed_any}  = 1 if ( $entry->{holdallowed} == 2 );
552
    $entry->{holdallowed_same} = 1 if($entry->{holdallowed} == 1);
555
    $entry->{holdallowed_same} = 1 if ( $entry->{holdallowed} == 1 );
553
}
556
}
554
557
555
$template->param(show_branch_cat_rule_form => 1);
558
$template->param(show_branch_cat_rule_form => 1);
Lines 575-586 if ($branch eq "*") { Link Here
575
my $defaults = $sth_defaults->fetchrow_hashref;
578
my $defaults = $sth_defaults->fetchrow_hashref;
576
579
577
if ($defaults) {
580
if ($defaults) {
578
    $template->param(default_holdallowed_none => 1) if($defaults->{holdallowed} == 0);
581
    $template->param( default_holdallowed_none => 1 ) if ( $defaults->{holdallowed} == 0 );
579
    $template->param(default_holdallowed_same => 1) if($defaults->{holdallowed} == 1);
582
    $template->param( default_holdallowed_same => 1 ) if ( $defaults->{holdallowed} == 1 );
580
    $template->param(default_holdallowed_any => 1) if($defaults->{holdallowed} == 2);
583
    $template->param( default_holdallowed_any  => 1 ) if ( $defaults->{holdallowed} == 2 );
581
    $template->param(default_maxissueqty => $defaults->{maxissueqty});
584
    $template->param( default_hold_fulfillment_policy => $defaults->{hold_fulfillment_policy} );
582
    $template->param(default_maxonsiteissueqty => $defaults->{maxonsiteissueqty});
585
    $template->param( default_maxissueqty      => $defaults->{maxissueqty} );
583
    $template->param(default_returnbranch => $defaults->{returnbranch});
586
    $template->param( default_maxonsiteissueqty => $defaults->{maxonsiteissueqty} );
587
    $template->param( default_returnbranch      => $defaults->{returnbranch} );
584
}
588
}
585
589
586
$template->param(default_rules => ($defaults ? 1 : 0));
590
$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 350-355 CREATE TABLE `branch_item_rules` ( -- information entered in the circulation and Link Here
350
  `branchcode` varchar(10) NOT NULL, -- the branch this rule is for (branches.branchcode)
350
  `branchcode` varchar(10) NOT NULL, -- the branch this rule is for (branches.branchcode)
351
  `itemtype` varchar(10) NOT NULL, -- the item type this rule applies to (items.itype)
351
  `itemtype` varchar(10) NOT NULL, -- the item type this rule applies to (items.itype)
352
  `holdallowed` tinyint(1) default NULL, -- the number of holds allowed
352
  `holdallowed` tinyint(1) default NULL, -- the number of holds allowed
353
  hold_fulfillment_policy ENUM('any', 'homebranch', 'holdingbranch') NOT NULL DEFAULT 'any', -- limit trapping of holds by branchcode
353
  `returnbranch` varchar(15) default NULL, -- the branch the item returns to (homebranch, holdingbranch, noreturn)
354
  `returnbranch` varchar(15) default NULL, -- the branch the item returns to (homebranch, holdingbranch, noreturn)
354
  PRIMARY KEY  (`itemtype`,`branchcode`),
355
  PRIMARY KEY  (`itemtype`,`branchcode`),
355
  KEY `branch_item_rules_ibfk_2` (`branchcode`),
356
  KEY `branch_item_rules_ibfk_2` (`branchcode`),
Lines 683-688 CREATE TABLE `default_branch_circ_rules` ( Link Here
683
  `maxissueqty` int(4) default NULL,
684
  `maxissueqty` int(4) default NULL,
684
  `maxonsiteissueqty` int(4) default NULL,
685
  `maxonsiteissueqty` int(4) default NULL,
685
  `holdallowed` tinyint(1) default NULL,
686
  `holdallowed` tinyint(1) default NULL,
687
  hold_fulfillment_policy ENUM('any', 'homebranch', 'holdingbranch') NOT NULL DEFAULT 'any', -- limit trapping of holds by branchcode
686
  `returnbranch` varchar(15) default NULL,
688
  `returnbranch` varchar(15) default NULL,
687
  PRIMARY KEY (`branchcode`),
689
  PRIMARY KEY (`branchcode`),
688
  CONSTRAINT `default_branch_circ_rules_ibfk_1` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`)
690
  CONSTRAINT `default_branch_circ_rules_ibfk_1` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`)
Lines 696-701 DROP TABLE IF EXISTS `default_branch_item_rules`; Link Here
696
CREATE TABLE `default_branch_item_rules` (
698
CREATE TABLE `default_branch_item_rules` (
697
  `itemtype` varchar(10) NOT NULL,
699
  `itemtype` varchar(10) NOT NULL,
698
  `holdallowed` tinyint(1) default NULL,
700
  `holdallowed` tinyint(1) default NULL,
701
  hold_fulfillment_policy ENUM('any', 'homebranch', 'holdingbranch') NOT NULL DEFAULT 'any', -- limit trapping of holds by branchcode
699
  `returnbranch` varchar(15) default NULL,
702
  `returnbranch` varchar(15) default NULL,
700
  PRIMARY KEY  (`itemtype`),
703
  PRIMARY KEY  (`itemtype`),
701
  CONSTRAINT `default_branch_item_rules_ibfk_1` FOREIGN KEY (`itemtype`) REFERENCES `itemtypes` (`itemtype`)
704
  CONSTRAINT `default_branch_item_rules_ibfk_1` FOREIGN KEY (`itemtype`) REFERENCES `itemtypes` (`itemtype`)
Lines 712-717 CREATE TABLE `default_circ_rules` ( Link Here
712
    `maxissueqty` int(4) default NULL,
715
    `maxissueqty` int(4) default NULL,
713
    `maxonsiteissueqty` int(4) default NULL,
716
    `maxonsiteissueqty` int(4) default NULL,
714
    `holdallowed` int(1) default NULL,
717
    `holdallowed` int(1) default NULL,
718
    hold_fulfillment_policy ENUM('any', 'homebranch', 'holdingbranch') NOT NULL DEFAULT 'any', -- limit trapping of holds by branchcode
715
    `returnbranch` varchar(15) default NULL,
719
    `returnbranch` varchar(15) default NULL,
716
    PRIMARY KEY (`singleton`)
720
    PRIMARY KEY (`singleton`)
717
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
721
) 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