|
Lines 415-433
This function return 1 if an item can be issued by this borrower.
Link Here
|
| 415 |
|
415 |
|
| 416 |
=cut |
416 |
=cut |
| 417 |
|
417 |
|
| 418 |
sub CanItemBeReserved{ |
418 |
sub CanItemBeReserved { |
| 419 |
my ($borrowernumber, $itemnumber) = @_; |
419 |
my ( $borrowernumber, $itemnumber ) = @_; |
| 420 |
|
420 |
|
| 421 |
my $dbh = C4::Context->dbh; |
421 |
my $dbh = C4::Context->dbh; |
| 422 |
my $allowedreserves = 0; |
422 |
my $allowedreserves = 0; |
| 423 |
|
423 |
|
| 424 |
my $controlbranch = C4::Context->preference('ReservesControlBranch'); |
424 |
my $controlbranch = C4::Context->preference('ReservesControlBranch'); |
| 425 |
my $itype = C4::Context->preference('item-level_itypes') ? "itype" : "itemtype"; |
425 |
my $itype = |
|
|
426 |
C4::Context->preference('item-level_itypes') ? "itype" : "itemtype"; |
| 426 |
|
427 |
|
| 427 |
# we retrieve borrowers and items informations # |
428 |
# we retrieve borrowers and items informations # |
| 428 |
my $item = GetItem($itemnumber); |
429 |
my $item = GetItem($itemnumber); |
| 429 |
my $borrower = C4::Members::GetMember('borrowernumber'=>$borrowernumber); |
430 |
my $borrower = |
| 430 |
|
431 |
C4::Members::GetMember( 'borrowernumber' => $borrowernumber ); |
| 431 |
|
432 |
|
| 432 |
# Before we check too see if the borrower has exceed the |
433 |
# Before we check too see if the borrower has exceed the |
| 433 |
# maximum number of holds allowed for this itemtype, |
434 |
# maximum number of holds allowed for this itemtype, |
|
Lines 455-525
sub CanItemBeReserved{
Link Here
|
| 455 |
# If we've gotten this far, the holds policy does not prevent the patron |
456 |
# If we've gotten this far, the holds policy does not prevent the patron |
| 456 |
# from placing this hold. We now need to see if the patron has exceeded |
457 |
# from placing this hold. We now need to see if the patron has exceeded |
| 457 |
# the maximum number of holds allowed for this itemtype based on the patrons |
458 |
# the maximum number of holds allowed for this itemtype based on the patrons |
| 458 |
my $sth = $dbh->prepare("SELECT categorycode, itemtype, branchcode, reservesallowed |
459 |
my $sth = $dbh->prepare(q{ |
| 459 |
FROM issuingrules |
460 |
SELECT categorycode, itemtype, branchcode, reservesallowed |
| 460 |
WHERE (categorycode in (?,'*') ) |
461 |
FROM issuingrules |
| 461 |
AND (itemtype IN (?,'*')) |
462 |
WHERE (categorycode in (?,'*') ) |
| 462 |
AND (branchcode IN (?,'*')) |
463 |
AND (itemtype IN (?,'*')) |
| 463 |
ORDER BY |
464 |
AND (branchcode IN (?,'*')) |
| 464 |
categorycode DESC, |
465 |
ORDER BY |
| 465 |
itemtype DESC, |
466 |
categorycode DESC, |
| 466 |
branchcode DESC;" |
467 |
itemtype DESC, |
| 467 |
); |
468 |
branchcode DESC; |
| 468 |
|
469 |
}); |
| 469 |
my $querycount ="SELECT |
470 |
|
| 470 |
count(*) as count |
471 |
my $querycount = q{ |
| 471 |
FROM reserves |
472 |
SELECT count(*) as count |
| 472 |
LEFT JOIN items USING (itemnumber) |
473 |
FROM reserves |
| 473 |
LEFT JOIN biblioitems ON (reserves.biblionumber=biblioitems.biblionumber) |
474 |
LEFT JOIN items USING (itemnumber) |
| 474 |
LEFT JOIN borrowers USING (borrowernumber) |
475 |
LEFT JOIN biblioitems USING (biblionumber) |
| 475 |
WHERE borrowernumber = ? |
476 |
LEFT JOIN borrowers USING (borrowernumber) |
| 476 |
"; |
477 |
WHERE borrowernumber = ? |
| 477 |
|
478 |
}; |
| 478 |
|
479 |
|
| 479 |
my $itemtype = $item->{$itype}; |
480 |
my $itemtype = $item->{$itype}; |
| 480 |
my $categorycode = $borrower->{categorycode}; |
481 |
my $categorycode = $borrower->{categorycode}; |
| 481 |
my $branchcode = ""; |
482 |
my $branchcode = ""; |
| 482 |
my $branchfield = "reserves.branchcode"; |
483 |
my $branchfield = "reserves.branchcode"; |
| 483 |
|
484 |
|
| 484 |
if( $controlbranch eq "ItemHomeLibrary" ){ |
485 |
if ( $controlbranch eq "ItemHomeLibrary" ) { |
| 485 |
$branchfield = "items.homebranch"; |
486 |
$branchfield = "items.homebranch"; |
| 486 |
$branchcode = $item->{homebranch}; |
487 |
$branchcode = $item->{homebranch}; |
| 487 |
}elsif( $controlbranch eq "PatronLibrary" ){ |
488 |
} |
|
|
489 |
elsif ( $controlbranch eq "PatronLibrary" ) { |
| 488 |
$branchfield = "borrowers.branchcode"; |
490 |
$branchfield = "borrowers.branchcode"; |
| 489 |
$branchcode = $borrower->{branchcode}; |
491 |
$branchcode = $borrower->{branchcode}; |
| 490 |
} |
492 |
} |
| 491 |
|
493 |
|
| 492 |
# we retrieve rights |
494 |
# we retrieve rights |
| 493 |
$sth->execute($categorycode, $itemtype, $branchcode); |
495 |
$sth->execute( $categorycode, $itemtype, $branchcode ); |
| 494 |
if(my $rights = $sth->fetchrow_hashref()){ |
496 |
if ( my $rights = $sth->fetchrow_hashref() ) { |
| 495 |
$itemtype = $rights->{itemtype}; |
497 |
$itemtype = $rights->{itemtype}; |
| 496 |
$allowedreserves = $rights->{reservesallowed}; |
498 |
$allowedreserves = $rights->{reservesallowed}; |
| 497 |
}else{ |
499 |
} |
|
|
500 |
else { |
| 498 |
$itemtype = '*'; |
501 |
$itemtype = '*'; |
| 499 |
} |
502 |
} |
| 500 |
|
503 |
|
| 501 |
# we retrieve count |
504 |
# we retrieve count |
| 502 |
|
505 |
|
| 503 |
$querycount .= "AND $branchfield = ?"; |
506 |
$querycount .= "AND $branchfield = ?"; |
| 504 |
|
507 |
|
| 505 |
$querycount .= " AND $itype = ?" if ($itemtype ne "*"); |
508 |
$querycount .= " AND $itype = ?" if ( $itemtype ne "*" ); |
| 506 |
my $sthcount = $dbh->prepare($querycount); |
509 |
my $sthcount = $dbh->prepare($querycount); |
| 507 |
|
510 |
|
| 508 |
if($itemtype eq "*"){ |
511 |
if ( $itemtype eq "*" ) { |
| 509 |
$sthcount->execute($borrowernumber, $branchcode); |
512 |
$sthcount->execute( $borrowernumber, $branchcode ); |
| 510 |
}else{ |
|
|
| 511 |
$sthcount->execute($borrowernumber, $branchcode, $itemtype); |
| 512 |
} |
513 |
} |
| 513 |
|
514 |
else { |
|
|
515 |
$sthcount->execute( $borrowernumber, $branchcode, $itemtype ); |
| 516 |
} |
| 517 |
|
| 514 |
my $reservecount = "0"; |
518 |
my $reservecount = "0"; |
| 515 |
if(my $rowcount = $sthcount->fetchrow_hashref()){ |
519 |
if ( my $rowcount = $sthcount->fetchrow_hashref() ) { |
| 516 |
$reservecount = $rowcount->{count}; |
520 |
$reservecount = $rowcount->{count}; |
| 517 |
} |
521 |
} |
| 518 |
|
522 |
|
| 519 |
# we check if it's ok or not |
523 |
# we check if it's ok or not |
| 520 |
if( $reservecount < $allowedreserves ){ |
524 |
if ( $reservecount < $allowedreserves ) { |
| 521 |
return 1; |
525 |
return 1; |
| 522 |
}else{ |
526 |
} |
|
|
527 |
else { |
| 523 |
return 0; |
528 |
return 0; |
| 524 |
} |
529 |
} |
| 525 |
} |
530 |
} |
| 526 |
- |
|
|