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