|
Lines 414-419
sub CanItemBeReserved {
Link Here
|
| 414 |
my $patron = Koha::Patrons->find( $borrowernumber ); |
414 |
my $patron = Koha::Patrons->find( $borrowernumber ); |
| 415 |
my $borrower = $patron->unblessed; |
415 |
my $borrower = $patron->unblessed; |
| 416 |
|
416 |
|
|
|
417 |
# We check item branch if IndependentBranches is ON |
| 418 |
# and canreservefromotherbranches is OFF |
| 419 |
if ( C4::Context->preference('IndependentBranches') |
| 420 |
and !C4::Context->preference('canreservefromotherbranches') ) |
| 421 |
{ |
| 422 |
if ( $item->homebranch ne $patron->branchcode ) { |
| 423 |
return { status => 'cannotReserveFromOtherBranches' }; |
| 424 |
} |
| 425 |
} |
| 426 |
|
| 417 |
# If an item is damaged and we don't allow holds on damaged items, we can stop right here |
427 |
# If an item is damaged and we don't allow holds on damaged items, we can stop right here |
| 418 |
return { status =>'damaged' } |
428 |
return { status =>'damaged' } |
| 419 |
if ( $item->damaged |
429 |
if ( $item->damaged |
|
Lines 439-463
sub CanItemBeReserved {
Link Here
|
| 439 |
|
449 |
|
| 440 |
my $controlbranch = C4::Context->preference('ReservesControlBranch'); |
450 |
my $controlbranch = C4::Context->preference('ReservesControlBranch'); |
| 441 |
|
451 |
|
| 442 |
my $querycount = q{ |
452 |
my $reserves_control_branch; |
| 443 |
SELECT count(*) AS count |
|
|
| 444 |
FROM reserves |
| 445 |
LEFT JOIN items USING (itemnumber) |
| 446 |
LEFT JOIN biblioitems ON (reserves.biblionumber=biblioitems.biblionumber) |
| 447 |
LEFT JOIN borrowers USING (borrowernumber) |
| 448 |
WHERE borrowernumber = ? |
| 449 |
}; |
| 450 |
|
| 451 |
my $branchcode = ""; |
| 452 |
my $branchfield = "reserves.branchcode"; |
453 |
my $branchfield = "reserves.branchcode"; |
| 453 |
|
454 |
|
| 454 |
if ( $controlbranch eq "ItemHomeLibrary" ) { |
455 |
if ( $controlbranch eq "ItemHomeLibrary" ) { |
| 455 |
$branchfield = "items.homebranch"; |
456 |
$branchfield = "items.homebranch"; |
| 456 |
$branchcode = $item->homebranch; |
457 |
$reserves_control_branch = $item->homebranch; |
| 457 |
} |
458 |
} |
| 458 |
elsif ( $controlbranch eq "PatronLibrary" ) { |
459 |
elsif ( $controlbranch eq "PatronLibrary" ) { |
| 459 |
$branchfield = "borrowers.branchcode"; |
460 |
$branchfield = "borrowers.branchcode"; |
| 460 |
$branchcode = $borrower->{branchcode}; |
461 |
$reserves_control_branch = $borrower->{branchcode}; |
| 461 |
} |
462 |
} |
| 462 |
|
463 |
|
| 463 |
# we retrieve rights |
464 |
# we retrieve rights |
|
Lines 465-471
sub CanItemBeReserved {
Link Here
|
| 465 |
my $reservesallowed = Koha::CirculationRules->get_effective_rule({ |
466 |
my $reservesallowed = Koha::CirculationRules->get_effective_rule({ |
| 466 |
itemtype => $item->effective_itemtype, |
467 |
itemtype => $item->effective_itemtype, |
| 467 |
categorycode => $borrower->{categorycode}, |
468 |
categorycode => $borrower->{categorycode}, |
| 468 |
branchcode => $branchcode, |
469 |
branchcode => $reserves_control_branch, |
| 469 |
rule_name => 'reservesallowed', |
470 |
rule_name => 'reservesallowed', |
| 470 |
}) |
471 |
}) |
| 471 |
) { |
472 |
) { |
|
Lines 479-559
sub CanItemBeReserved {
Link Here
|
| 479 |
my $rights = Koha::CirculationRules->get_effective_rules({ |
480 |
my $rights = Koha::CirculationRules->get_effective_rules({ |
| 480 |
categorycode => $borrower->{'categorycode'}, |
481 |
categorycode => $borrower->{'categorycode'}, |
| 481 |
itemtype => $item->effective_itemtype, |
482 |
itemtype => $item->effective_itemtype, |
| 482 |
branchcode => $branchcode, |
483 |
branchcode => $reserves_control_branch, |
| 483 |
rules => ['holds_per_record','holds_per_day'] |
484 |
rules => ['holds_per_record','holds_per_day'] |
| 484 |
}); |
485 |
}); |
| 485 |
my $holds_per_record = $rights->{holds_per_record} // 1; |
486 |
my $holds_per_record = $rights->{holds_per_record} // 1; |
| 486 |
my $holds_per_day = $rights->{holds_per_day}; |
487 |
my $holds_per_day = $rights->{holds_per_day}; |
| 487 |
|
488 |
|
| 488 |
my $search_params = { |
|
|
| 489 |
borrowernumber => $borrowernumber, |
| 490 |
biblionumber => $item->biblionumber, |
| 491 |
}; |
| 492 |
$search_params->{found} = undef if $params->{ignore_found_holds}; |
| 493 |
|
| 494 |
my $holds = Koha::Holds->search($search_params); |
| 495 |
if ( defined $holds_per_record && $holds_per_record ne '' ){ |
489 |
if ( defined $holds_per_record && $holds_per_record ne '' ){ |
| 496 |
if ( $holds_per_record == 0 ) { |
490 |
if ( $holds_per_record == 0 ) { |
| 497 |
return { status => "noReservesAllowed" }; |
491 |
return { status => "noReservesAllowed" }; |
| 498 |
} |
492 |
} |
| 499 |
if ( !$params->{ignore_hold_counts} && $holds->count() >= $holds_per_record ) { |
493 |
if ( !$params->{ignore_hold_counts} ) { |
| 500 |
return { status => "tooManyHoldsForThisRecord", limit => $holds_per_record }; |
494 |
my $search_params = { |
|
|
495 |
borrowernumber => $borrowernumber, |
| 496 |
biblionumber => $item->biblionumber, |
| 497 |
}; |
| 498 |
$search_params->{found} = undef if $params->{ignore_found_holds}; |
| 499 |
my $holds = Koha::Holds->search($search_params); |
| 500 |
return { status => "tooManyHoldsForThisRecord", limit => $holds_per_record } if $holds->count() >= $holds_per_record; |
| 501 |
} |
501 |
} |
| 502 |
} |
502 |
} |
| 503 |
|
503 |
|
| 504 |
my $today_holds = Koha::Holds->search({ |
504 |
if (!$params->{ignore_hold_counts} && defined $holds_per_day && $holds_per_day ne '') |
| 505 |
borrowernumber => $borrowernumber, |
|
|
| 506 |
reservedate => dt_from_string->date |
| 507 |
}); |
| 508 |
|
| 509 |
if (!$params->{ignore_hold_counts} && defined $holds_per_day && $holds_per_day ne '' |
| 510 |
&& $today_holds->count() >= $holds_per_day ) |
| 511 |
{ |
505 |
{ |
| 512 |
return { status => 'tooManyReservesToday', limit => $holds_per_day }; |
506 |
my $today_holds = Koha::Holds->search({ |
|
|
507 |
borrowernumber => $borrowernumber, |
| 508 |
reservedate => dt_from_string->date |
| 509 |
}); |
| 510 |
return { status => 'tooManyReservesToday', limit => $holds_per_day } if $today_holds->count() >= $holds_per_day; |
| 513 |
} |
511 |
} |
| 514 |
|
512 |
|
| 515 |
# we retrieve count |
513 |
# we check if it's ok or not |
| 516 |
|
514 |
if ( defined $allowedreserves && $allowedreserves ne '' ){ |
| 517 |
$querycount .= "AND ( $branchfield = ? OR $branchfield IS NULL )"; |
515 |
if( $allowedreserves == 0 ){ |
| 518 |
|
516 |
return { status => 'noReservesAllowed' }; |
| 519 |
# If using item-level itypes, fall back to the record |
|
|
| 520 |
# level itemtype if the hold has no associated item |
| 521 |
if ( defined $ruleitemtype ) { |
| 522 |
if ( C4::Context->preference('item-level_itypes') ) { |
| 523 |
$querycount .= q{ |
| 524 |
AND ( COALESCE( items.itype, biblioitems.itemtype ) = ? |
| 525 |
OR reserves.itemtype = ? ) |
| 526 |
}; |
| 527 |
} |
517 |
} |
| 528 |
else { |
518 |
if ( !$params->{ignore_hold_counts} ) { |
| 529 |
$querycount .= q{ |
519 |
# we retrieve count |
| 530 |
AND ( biblioitems.itemtype = ? |
520 |
my $querycount = q{ |
| 531 |
OR reserves.itemtype = ? ) |
521 |
SELECT count(*) AS count |
|
|
522 |
FROM reserves |
| 523 |
LEFT JOIN items USING (itemnumber) |
| 524 |
LEFT JOIN biblioitems ON (reserves.biblionumber=biblioitems.biblionumber) |
| 525 |
LEFT JOIN borrowers USING (borrowernumber) |
| 526 |
WHERE borrowernumber = ? |
| 532 |
}; |
527 |
}; |
| 533 |
} |
528 |
$querycount .= "AND ( $branchfield = ? OR $branchfield IS NULL )"; |
| 534 |
} |
|
|
| 535 |
|
529 |
|
| 536 |
my $sthcount = $dbh->prepare($querycount); |
530 |
# If using item-level itypes, fall back to the record |
|
|
531 |
# level itemtype if the hold has no associated item |
| 532 |
$querycount .= |
| 533 |
C4::Context->preference('item-level_itypes') |
| 534 |
? " AND ( COALESCE( items.itype, biblioitems.itemtype ) = ? OR reserves.itemtype = ? )" |
| 535 |
: " AND ( biblioitems.itemtype = ? OR reserves.itemtype = ? )" |
| 536 |
if defined $ruleitemtype; |
| 537 |
|
537 |
|
| 538 |
if ( defined $ruleitemtype ) { |
538 |
my $sthcount = $dbh->prepare($querycount); |
| 539 |
$sthcount->execute( $borrowernumber, $branchcode, $ruleitemtype, $ruleitemtype ); |
|
|
| 540 |
} |
| 541 |
else { |
| 542 |
$sthcount->execute( $borrowernumber, $branchcode ); |
| 543 |
} |
| 544 |
|
539 |
|
| 545 |
my $reservecount = "0"; |
540 |
if ( defined $ruleitemtype ) { |
| 546 |
if ( my $rowcount = $sthcount->fetchrow_hashref() ) { |
541 |
$sthcount->execute( $borrowernumber, $reserves_control_branch, $ruleitemtype, $ruleitemtype ); |
| 547 |
$reservecount = $rowcount->{count}; |
542 |
} |
| 548 |
} |
543 |
else { |
|
|
544 |
$sthcount->execute( $borrowernumber, $reserves_control_branch ); |
| 545 |
} |
| 549 |
|
546 |
|
| 550 |
# we check if it's ok or not |
547 |
my $reservecount = "0"; |
| 551 |
if ( defined $allowedreserves && $allowedreserves ne '' ){ |
548 |
if ( my $rowcount = $sthcount->fetchrow_hashref() ) { |
| 552 |
if( $allowedreserves == 0 ){ |
549 |
$reservecount = $rowcount->{count}; |
| 553 |
return { status => 'noReservesAllowed' }; |
550 |
} |
| 554 |
} |
551 |
|
| 555 |
if ( !$params->{ignore_hold_counts} && $reservecount >= $allowedreserves ) { |
552 |
return { status => 'tooManyReserves', limit => $allowedreserves } if $reservecount >= $allowedreserves; |
| 556 |
return { status => 'tooManyReserves', limit => $allowedreserves }; |
|
|
| 557 |
} |
553 |
} |
| 558 |
} |
554 |
} |
| 559 |
|
555 |
|
|
Lines 561-567
sub CanItemBeReserved {
Link Here
|
| 561 |
my $rule = Koha::CirculationRules->get_effective_rule( |
557 |
my $rule = Koha::CirculationRules->get_effective_rule( |
| 562 |
{ |
558 |
{ |
| 563 |
categorycode => $borrower->{categorycode}, |
559 |
categorycode => $borrower->{categorycode}, |
| 564 |
branchcode => $branchcode, |
560 |
branchcode => $reserves_control_branch, |
| 565 |
rule_name => 'max_holds', |
561 |
rule_name => 'max_holds', |
| 566 |
} |
562 |
} |
| 567 |
); |
563 |
); |
|
Lines 575-582
sub CanItemBeReserved {
Link Here
|
| 575 |
return { status => 'tooManyReserves', limit => $rule->rule_value} if $total_holds_count >= $rule->rule_value; |
571 |
return { status => 'tooManyReserves', limit => $rule->rule_value} if $total_holds_count >= $rule->rule_value; |
| 576 |
} |
572 |
} |
| 577 |
|
573 |
|
| 578 |
my $reserves_control_branch = |
|
|
| 579 |
GetReservesControlBranch( $item->unblessed(), $borrower ); |
| 580 |
my $branchitemrule = |
574 |
my $branchitemrule = |
| 581 |
C4::Circulation::GetBranchItemRule( $reserves_control_branch, $item->effective_itemtype ); |
575 |
C4::Circulation::GetBranchItemRule( $reserves_control_branch, $item->effective_itemtype ); |
| 582 |
|
576 |
|
|
Lines 597-612
sub CanItemBeReserved {
Link Here
|
| 597 |
} |
591 |
} |
| 598 |
} |
592 |
} |
| 599 |
|
593 |
|
| 600 |
# If reservecount is ok, we check item branch if IndependentBranches is ON |
|
|
| 601 |
# and canreservefromotherbranches is OFF |
| 602 |
if ( C4::Context->preference('IndependentBranches') |
| 603 |
and !C4::Context->preference('canreservefromotherbranches') ) |
| 604 |
{ |
| 605 |
if ( $item->homebranch ne $borrower->{branchcode} ) { |
| 606 |
return { status => 'cannotReserveFromOtherBranches' }; |
| 607 |
} |
| 608 |
} |
| 609 |
|
| 610 |
if ($pickup_branchcode) { |
594 |
if ($pickup_branchcode) { |
| 611 |
my $destination = Koha::Libraries->find({ |
595 |
my $destination = Koha::Libraries->find({ |
| 612 |
branchcode => $pickup_branchcode, |
596 |
branchcode => $pickup_branchcode, |
| 613 |
- |
|
|