|
Lines 409-422
See CanItemBeReserved() for possible return values.
Link Here
|
| 409 |
|
409 |
|
| 410 |
=cut |
410 |
=cut |
| 411 |
|
411 |
|
| 412 |
sub CanBookBeReserved{ |
412 |
sub CanBookBeReserved { |
| 413 |
my ($borrowernumber, $biblionumber) = @_; |
413 |
my ( $borrowernumber, $biblionumber ) = @_; |
| 414 |
|
414 |
|
| 415 |
my $items = GetItemnumbersForBiblio($biblionumber); |
415 |
my $items = GetItemnumbersForBiblio($biblionumber); |
|
|
416 |
|
| 416 |
#get items linked via host records |
417 |
#get items linked via host records |
| 417 |
my @hostitems = get_hostitemnumbers_of($biblionumber); |
418 |
my @hostitems = get_hostitemnumbers_of($biblionumber); |
| 418 |
if (@hostitems){ |
419 |
if (@hostitems) { |
| 419 |
push (@$items,@hostitems); |
420 |
push( @$items, @hostitems ); |
| 420 |
} |
421 |
} |
| 421 |
|
422 |
|
| 422 |
my $canReserve; |
423 |
my $canReserve; |
|
Lines 441-470
sub CanBookBeReserved{
Link Here
|
| 441 |
|
442 |
|
| 442 |
=cut |
443 |
=cut |
| 443 |
|
444 |
|
| 444 |
sub CanItemBeReserved{ |
445 |
sub CanItemBeReserved { |
| 445 |
my ($borrowernumber, $itemnumber) = @_; |
446 |
my ( $borrowernumber, $itemnumber ) = @_; |
| 446 |
|
447 |
|
| 447 |
my $dbh = C4::Context->dbh; |
448 |
my $dbh = C4::Context->dbh; |
| 448 |
my $ruleitemtype; # itemtype of the matching issuing rule |
449 |
my $ruleitemtype; # itemtype of the matching issuing rule |
| 449 |
my $allowedreserves = 0; |
450 |
my $allowedreserves = 0; |
| 450 |
|
451 |
|
| 451 |
# we retrieve borrowers and items informations # |
452 |
# we retrieve borrowers and items informations # |
| 452 |
# item->{itype} will come for biblioitems if necessery |
453 |
# item->{itype} will come for biblioitems if necessery |
| 453 |
my $item = GetItem($itemnumber); |
454 |
my $item = GetItem($itemnumber); |
| 454 |
my $biblioData = C4::Biblio::GetBiblioData( $item->{biblionumber} ); |
455 |
my $biblioData = C4::Biblio::GetBiblioData( $item->{biblionumber} ); |
| 455 |
my $borrower = C4::Members::GetMember('borrowernumber'=>$borrowernumber); |
456 |
my $borrower = C4::Members::GetMember( 'borrowernumber' => $borrowernumber ); |
| 456 |
|
457 |
|
| 457 |
# If an item is damaged and we don't allow holds on damaged items, we can stop right here |
458 |
# If an item is damaged and we don't allow holds on damaged items, we can stop right here |
| 458 |
return 'damaged' if ( $item->{damaged} && !C4::Context->preference('AllowHoldsOnDamagedItems') ); |
459 |
return 'damaged' if ( $item->{damaged} && !C4::Context->preference('AllowHoldsOnDamagedItems') ); |
| 459 |
|
460 |
|
| 460 |
#Check for the age restriction |
461 |
#Check for the age restriction |
| 461 |
my ($ageRestriction, $daysToAgeRestriction) = C4::Circulation::GetAgeRestriction( $biblioData->{agerestriction}, $borrower ); |
462 |
my ( $ageRestriction, $daysToAgeRestriction ) = |
|
|
463 |
C4::Circulation::GetAgeRestriction( $biblioData->{agerestriction}, $borrower ); |
| 462 |
return 'ageRestricted' if $daysToAgeRestriction && $daysToAgeRestriction > 0; |
464 |
return 'ageRestricted' if $daysToAgeRestriction && $daysToAgeRestriction > 0; |
| 463 |
|
465 |
|
| 464 |
my $controlbranch = C4::Context->preference('ReservesControlBranch'); |
466 |
my $controlbranch = C4::Context->preference('ReservesControlBranch'); |
| 465 |
|
467 |
|
| 466 |
# we retrieve user rights on this itemtype and branchcode |
468 |
# we retrieve user rights on this itemtype and branchcode |
| 467 |
my $sth = $dbh->prepare("SELECT categorycode, itemtype, branchcode, reservesallowed |
469 |
my $sth = $dbh->prepare( |
|
|
470 |
"SELECT categorycode, itemtype, branchcode, reservesallowed |
| 468 |
FROM issuingrules |
471 |
FROM issuingrules |
| 469 |
WHERE (categorycode in (?,'*') ) |
472 |
WHERE (categorycode in (?,'*') ) |
| 470 |
AND (itemtype IN (?,'*')) |
473 |
AND (itemtype IN (?,'*')) |
|
Lines 473-481
sub CanItemBeReserved{
Link Here
|
| 473 |
categorycode DESC, |
476 |
categorycode DESC, |
| 474 |
itemtype DESC, |
477 |
itemtype DESC, |
| 475 |
branchcode DESC;" |
478 |
branchcode DESC;" |
| 476 |
); |
479 |
); |
| 477 |
|
480 |
|
| 478 |
my $querycount ="SELECT |
481 |
my $querycount = "SELECT |
| 479 |
count(*) as count |
482 |
count(*) as count |
| 480 |
FROM reserves |
483 |
FROM reserves |
| 481 |
LEFT JOIN items USING (itemnumber) |
484 |
LEFT JOIN items USING (itemnumber) |
|
Lines 483-514
sub CanItemBeReserved{
Link Here
|
| 483 |
LEFT JOIN borrowers USING (borrowernumber) |
486 |
LEFT JOIN borrowers USING (borrowernumber) |
| 484 |
WHERE borrowernumber = ? |
487 |
WHERE borrowernumber = ? |
| 485 |
"; |
488 |
"; |
| 486 |
|
|
|
| 487 |
|
| 488 |
my $branchcode = ""; |
| 489 |
my $branchfield = "reserves.branchcode"; |
| 490 |
|
489 |
|
| 491 |
if( $controlbranch eq "ItemHomeLibrary" ){ |
490 |
my $branchcode = ""; |
|
|
491 |
my $branchfield = "reserves.branchcode"; |
| 492 |
|
| 493 |
if ( $controlbranch eq "ItemHomeLibrary" ) { |
| 492 |
$branchfield = "items.homebranch"; |
494 |
$branchfield = "items.homebranch"; |
| 493 |
$branchcode = $item->{homebranch}; |
495 |
$branchcode = $item->{homebranch}; |
| 494 |
}elsif( $controlbranch eq "PatronLibrary" ){ |
496 |
} |
|
|
497 |
elsif ( $controlbranch eq "PatronLibrary" ) { |
| 495 |
$branchfield = "borrowers.branchcode"; |
498 |
$branchfield = "borrowers.branchcode"; |
| 496 |
$branchcode = $borrower->{branchcode}; |
499 |
$branchcode = $borrower->{branchcode}; |
| 497 |
} |
500 |
} |
| 498 |
|
501 |
|
| 499 |
# we retrieve rights |
502 |
# we retrieve rights |
| 500 |
$sth->execute($borrower->{'categorycode'}, $item->{'itype'}, $branchcode); |
503 |
$sth->execute( $borrower->{'categorycode'}, $item->{'itype'}, $branchcode ); |
| 501 |
if(my $rights = $sth->fetchrow_hashref()){ |
504 |
if ( my $rights = $sth->fetchrow_hashref() ) { |
| 502 |
$ruleitemtype = $rights->{itemtype}; |
505 |
$ruleitemtype = $rights->{itemtype}; |
| 503 |
$allowedreserves = $rights->{reservesallowed}; |
506 |
$allowedreserves = $rights->{reservesallowed}; |
| 504 |
}else{ |
507 |
} |
|
|
508 |
else { |
| 505 |
$ruleitemtype = '*'; |
509 |
$ruleitemtype = '*'; |
| 506 |
} |
510 |
} |
| 507 |
|
511 |
|
| 508 |
# we retrieve count |
512 |
# we retrieve count |
| 509 |
|
513 |
|
| 510 |
$querycount .= "AND $branchfield = ?"; |
514 |
$querycount .= "AND $branchfield = ?"; |
| 511 |
|
515 |
|
| 512 |
# If using item-level itypes, fall back to the record |
516 |
# If using item-level itypes, fall back to the record |
| 513 |
# level itemtype if the hold has no associated item |
517 |
# level itemtype if the hold has no associated item |
| 514 |
$querycount .= |
518 |
$querycount .= |
|
Lines 518-543
sub CanItemBeReserved{
Link Here
|
| 518 |
if ( $ruleitemtype ne "*" ); |
522 |
if ( $ruleitemtype ne "*" ); |
| 519 |
|
523 |
|
| 520 |
my $sthcount = $dbh->prepare($querycount); |
524 |
my $sthcount = $dbh->prepare($querycount); |
| 521 |
|
525 |
|
| 522 |
if($ruleitemtype eq "*"){ |
526 |
if ( $ruleitemtype eq "*" ) { |
| 523 |
$sthcount->execute($borrowernumber, $branchcode); |
527 |
$sthcount->execute( $borrowernumber, $branchcode ); |
| 524 |
}else{ |
528 |
} |
| 525 |
$sthcount->execute($borrowernumber, $branchcode, $ruleitemtype); |
529 |
else { |
|
|
530 |
$sthcount->execute( $borrowernumber, $branchcode, $ruleitemtype ); |
| 526 |
} |
531 |
} |
| 527 |
|
532 |
|
| 528 |
my $reservecount = "0"; |
533 |
my $reservecount = "0"; |
| 529 |
if(my $rowcount = $sthcount->fetchrow_hashref()){ |
534 |
if ( my $rowcount = $sthcount->fetchrow_hashref() ) { |
| 530 |
$reservecount = $rowcount->{count}; |
535 |
$reservecount = $rowcount->{count}; |
| 531 |
} |
536 |
} |
|
|
537 |
|
| 532 |
# we check if it's ok or not |
538 |
# we check if it's ok or not |
| 533 |
if( $reservecount >= $allowedreserves ){ |
539 |
if ( $reservecount >= $allowedreserves ) { |
| 534 |
return 'tooManyReserves'; |
540 |
return 'tooManyReserves'; |
| 535 |
} |
541 |
} |
| 536 |
|
542 |
|
| 537 |
my $circ_control_branch = C4::Circulation::_GetCircControlBranch($item, |
543 |
my $circ_control_branch = C4::Circulation::_GetCircControlBranch( $item, $borrower ); |
| 538 |
$borrower); |
544 |
my $branchitemrule = C4::Circulation::GetBranchItemRule( $circ_control_branch, $item->{itype} ); |
| 539 |
my $branchitemrule = C4::Circulation::GetBranchItemRule($circ_control_branch, |
|
|
| 540 |
$item->{itype}); |
| 541 |
|
545 |
|
| 542 |
if ( $branchitemrule->{holdallowed} == 0 ) { |
546 |
if ( $branchitemrule->{holdallowed} == 0 ) { |
| 543 |
return 'notReservable'; |
547 |
return 'notReservable'; |
|
Lines 546-552
sub CanItemBeReserved{
Link Here
|
| 546 |
if ( $branchitemrule->{holdallowed} == 1 |
550 |
if ( $branchitemrule->{holdallowed} == 1 |
| 547 |
&& $borrower->{branchcode} ne $item->{homebranch} ) |
551 |
&& $borrower->{branchcode} ne $item->{homebranch} ) |
| 548 |
{ |
552 |
{ |
| 549 |
return 'cannotReserveFromOtherBranches'; |
553 |
return 'cannotReserveFromOtherBranches'; |
| 550 |
} |
554 |
} |
| 551 |
|
555 |
|
| 552 |
# If reservecount is ok, we check item branch if IndependentBranches is ON |
556 |
# If reservecount is ok, we check item branch if IndependentBranches is ON |
|
Lines 555-561
sub CanItemBeReserved{
Link Here
|
| 555 |
and !C4::Context->preference('canreservefromotherbranches') ) |
559 |
and !C4::Context->preference('canreservefromotherbranches') ) |
| 556 |
{ |
560 |
{ |
| 557 |
my $itembranch = $item->{homebranch}; |
561 |
my $itembranch = $item->{homebranch}; |
| 558 |
if ($itembranch ne $borrower->{branchcode}) { |
562 |
if ( $itembranch ne $borrower->{branchcode} ) { |
| 559 |
return 'cannotReserveFromOtherBranches'; |
563 |
return 'cannotReserveFromOtherBranches'; |
| 560 |
} |
564 |
} |
| 561 |
} |
565 |
} |
| 562 |
- |
|
|