|
Lines 435-453
This function return 1 if an item can be issued by this borrower.
Link Here
|
| 435 |
|
435 |
|
| 436 |
=cut |
436 |
=cut |
| 437 |
|
437 |
|
| 438 |
sub CanItemBeReserved{ |
438 |
sub CanItemBeReserved { |
| 439 |
my ($borrowernumber, $itemnumber) = @_; |
439 |
my ( $borrowernumber, $itemnumber ) = @_; |
| 440 |
|
440 |
|
| 441 |
my $dbh = C4::Context->dbh; |
441 |
my $dbh = C4::Context->dbh; |
| 442 |
my $allowedreserves = 0; |
442 |
my $allowedreserves = 0; |
| 443 |
|
443 |
|
| 444 |
my $controlbranch = C4::Context->preference('ReservesControlBranch'); |
444 |
my $controlbranch = C4::Context->preference('ReservesControlBranch'); |
| 445 |
my $itype = C4::Context->preference('item-level_itypes') ? "itype" : "itemtype"; |
445 |
my $itype = |
|
|
446 |
C4::Context->preference('item-level_itypes') ? "itype" : "itemtype"; |
| 446 |
|
447 |
|
| 447 |
# we retrieve borrowers and items informations # |
448 |
# we retrieve borrowers and items informations # |
| 448 |
my $item = GetItem($itemnumber); |
449 |
my $item = GetItem($itemnumber); |
| 449 |
my $borrower = C4::Members::GetMember('borrowernumber'=>$borrowernumber); |
450 |
my $borrower = |
| 450 |
|
451 |
C4::Members::GetMember( 'borrowernumber' => $borrowernumber ); |
| 451 |
|
452 |
|
| 452 |
# Before we check too see if the borrower has exceed the |
453 |
# Before we check too see if the borrower has exceed the |
| 453 |
# maximum number of holds allowed for this itemtype, |
454 |
# maximum number of holds allowed for this itemtype, |
|
Lines 475-541
sub CanItemBeReserved{
Link Here
|
| 475 |
# If we've gotten this far, the holds policy does not prevent the patron |
476 |
# If we've gotten this far, the holds policy does not prevent the patron |
| 476 |
# from placing this hold. We now need to see if the patron has exceeded |
477 |
# from placing this hold. We now need to see if the patron has exceeded |
| 477 |
# the maximum number of holds allowed for this itemtype based on the patrons |
478 |
# the maximum number of holds allowed for this itemtype based on the patrons |
| 478 |
my $sth = $dbh->prepare("SELECT categorycode, itemtype, branchcode, reservesallowed |
479 |
my $sth = $dbh->prepare(q{ |
| 479 |
FROM issuingrules |
480 |
SELECT categorycode, itemtype, branchcode, reservesallowed |
| 480 |
WHERE (categorycode in (?,'*') ) |
481 |
FROM issuingrules |
| 481 |
AND (itemtype IN (?,'*')) |
482 |
WHERE (categorycode in (?,'*') ) |
| 482 |
AND (branchcode IN (?,'*')) |
483 |
AND (itemtype IN (?,'*')) |
| 483 |
ORDER BY |
484 |
AND (branchcode IN (?,'*')) |
| 484 |
categorycode DESC, |
485 |
ORDER BY |
| 485 |
itemtype DESC, |
486 |
categorycode DESC, |
| 486 |
branchcode DESC;" |
487 |
itemtype DESC, |
| 487 |
); |
488 |
branchcode DESC; |
| 488 |
|
489 |
}); |
| 489 |
my $querycount ="SELECT |
490 |
|
| 490 |
count(*) as count |
491 |
my $querycount = q{ |
| 491 |
FROM reserves |
492 |
SELECT count(*) as count |
| 492 |
LEFT JOIN items USING (itemnumber) |
493 |
FROM reserves |
| 493 |
LEFT JOIN biblioitems ON (reserves.biblionumber=biblioitems.biblionumber) |
494 |
LEFT JOIN items USING (itemnumber) |
| 494 |
LEFT JOIN borrowers USING (borrowernumber) |
495 |
LEFT JOIN biblioitems USING (biblionumber) |
| 495 |
WHERE borrowernumber = ? |
496 |
LEFT JOIN borrowers USING (borrowernumber) |
| 496 |
"; |
497 |
WHERE borrowernumber = ? |
| 497 |
|
498 |
}; |
| 498 |
|
499 |
|
| 499 |
my $itemtype = $item->{$itype}; |
500 |
my $itemtype = $item->{$itype}; |
| 500 |
my $categorycode = $borrower->{categorycode}; |
501 |
my $categorycode = $borrower->{categorycode}; |
| 501 |
my $branchcode = ""; |
502 |
my $branchcode = ""; |
| 502 |
my $branchfield = "reserves.branchcode"; |
503 |
my $branchfield = "reserves.branchcode"; |
| 503 |
|
504 |
|
| 504 |
if( $controlbranch eq "ItemHomeLibrary" ){ |
505 |
if ( $controlbranch eq "ItemHomeLibrary" ) { |
| 505 |
$branchfield = "items.homebranch"; |
506 |
$branchfield = "items.homebranch"; |
| 506 |
$branchcode = $item->{homebranch}; |
507 |
$branchcode = $item->{homebranch}; |
| 507 |
}elsif( $controlbranch eq "PatronLibrary" ){ |
508 |
} |
|
|
509 |
elsif ( $controlbranch eq "PatronLibrary" ) { |
| 508 |
$branchfield = "borrowers.branchcode"; |
510 |
$branchfield = "borrowers.branchcode"; |
| 509 |
$branchcode = $borrower->{branchcode}; |
511 |
$branchcode = $borrower->{branchcode}; |
| 510 |
} |
512 |
} |
| 511 |
|
513 |
|
| 512 |
# we retrieve rights |
514 |
# we retrieve rights |
| 513 |
$sth->execute($categorycode, $itemtype, $branchcode); |
515 |
$sth->execute( $categorycode, $itemtype, $branchcode ); |
| 514 |
if(my $rights = $sth->fetchrow_hashref()){ |
516 |
if ( my $rights = $sth->fetchrow_hashref() ) { |
| 515 |
$itemtype = $rights->{itemtype}; |
517 |
$itemtype = $rights->{itemtype}; |
| 516 |
$allowedreserves = $rights->{reservesallowed}; |
518 |
$allowedreserves = $rights->{reservesallowed}; |
| 517 |
}else{ |
519 |
} |
|
|
520 |
else { |
| 518 |
$itemtype = '*'; |
521 |
$itemtype = '*'; |
| 519 |
} |
522 |
} |
| 520 |
|
523 |
|
| 521 |
# we retrieve count |
524 |
# we retrieve count |
| 522 |
|
525 |
|
| 523 |
$querycount .= "AND $branchfield = ?"; |
526 |
$querycount .= "AND $branchfield = ?"; |
| 524 |
|
527 |
|
| 525 |
$querycount .= " AND $itype = ?" if ($itemtype ne "*"); |
528 |
$querycount .= " AND $itype = ?" if ( $itemtype ne "*" ); |
| 526 |
my $sthcount = $dbh->prepare($querycount); |
529 |
my $sthcount = $dbh->prepare($querycount); |
| 527 |
|
530 |
|
| 528 |
if($itemtype eq "*"){ |
531 |
if ( $itemtype eq "*" ) { |
| 529 |
$sthcount->execute($borrowernumber, $branchcode); |
532 |
$sthcount->execute( $borrowernumber, $branchcode ); |
| 530 |
}else{ |
|
|
| 531 |
$sthcount->execute($borrowernumber, $branchcode, $itemtype); |
| 532 |
} |
533 |
} |
| 533 |
|
534 |
else { |
|
|
535 |
$sthcount->execute( $borrowernumber, $branchcode, $itemtype ); |
| 536 |
} |
| 537 |
|
| 534 |
my $reservecount = "0"; |
538 |
my $reservecount = "0"; |
| 535 |
if(my $rowcount = $sthcount->fetchrow_hashref()){ |
539 |
if ( my $rowcount = $sthcount->fetchrow_hashref() ) { |
| 536 |
$reservecount = $rowcount->{count}; |
540 |
$reservecount = $rowcount->{count}; |
| 537 |
} |
541 |
} |
| 538 |
|
542 |
|
| 539 |
# we check if it's ok or not |
543 |
# we check if it's ok or not |
| 540 |
if( $reservecount >= $allowedreserves ){ |
544 |
if( $reservecount >= $allowedreserves ){ |
| 541 |
return 0; |
545 |
return 0; |
| 542 |
- |
|
|