Lines 438-445
This function return 1 if an item can be issued by this borrower.
Link Here
|
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 |
my $multi_holds_allowed_same = 0; |
444 |
my $multi_holds_allowed_diff = 0; |
443 |
|
445 |
|
444 |
my $controlbranch = C4::Context->preference('ReservesControlBranch'); |
446 |
my $controlbranch = C4::Context->preference('ReservesControlBranch'); |
445 |
my $itype = C4::Context->preference('item-level_itypes') ? "itype" : "itemtype"; |
447 |
my $itype = C4::Context->preference('item-level_itypes') ? "itype" : "itemtype"; |
Lines 448-474
sub CanItemBeReserved{
Link Here
|
448 |
my $item = GetItem($itemnumber); |
450 |
my $item = GetItem($itemnumber); |
449 |
my $borrower = C4::Members::GetMember('borrowernumber'=>$borrowernumber); |
451 |
my $borrower = C4::Members::GetMember('borrowernumber'=>$borrowernumber); |
450 |
|
452 |
|
451 |
# we retrieve user rights on this itemtype and branchcode |
453 |
my $querycount = " |
452 |
my $sth = $dbh->prepare("SELECT categorycode, itemtype, branchcode, reservesallowed |
454 |
SELECT count(*) AS count |
453 |
FROM issuingrules |
455 |
FROM reserves |
454 |
WHERE (categorycode in (?,'*') ) |
456 |
LEFT JOIN items USING (itemnumber) |
455 |
AND (itemtype IN (?,'*')) |
457 |
LEFT JOIN biblioitems ON (reserves.biblionumber=biblioitems.biblionumber) |
456 |
AND (branchcode IN (?,'*')) |
458 |
LEFT JOIN borrowers USING (borrowernumber) |
457 |
ORDER BY |
459 |
WHERE borrowernumber = ? |
458 |
categorycode DESC, |
460 |
"; |
459 |
itemtype DESC, |
|
|
460 |
branchcode DESC;" |
461 |
); |
462 |
|
463 |
my $querycount ="SELECT |
464 |
count(*) as count |
465 |
FROM reserves |
466 |
LEFT JOIN items USING (itemnumber) |
467 |
LEFT JOIN biblioitems ON (reserves.biblionumber=biblioitems.biblionumber) |
468 |
LEFT JOIN borrowers USING (borrowernumber) |
469 |
WHERE borrowernumber = ? |
470 |
"; |
471 |
|
472 |
|
461 |
|
473 |
my $itemtype = $item->{$itype}; |
462 |
my $itemtype = $item->{$itype}; |
474 |
my $categorycode = $borrower->{categorycode}; |
463 |
my $categorycode = $borrower->{categorycode}; |
Lines 484-497
sub CanItemBeReserved{
Link Here
|
484 |
} |
473 |
} |
485 |
|
474 |
|
486 |
# we retrieve rights |
475 |
# we retrieve rights |
487 |
$sth->execute($categorycode, $itemtype, $branchcode); |
476 |
my $rights = C4::Circulation::GetIssuingRule( $categorycode, $itemtype, $branchcode ); |
488 |
if(my $rights = $sth->fetchrow_hashref()){ |
477 |
if ( defined $rights ) { |
489 |
$itemtype = $rights->{itemtype}; |
478 |
$itemtype = $rights->{itemtype}; |
490 |
$allowedreserves = $rights->{reservesallowed}; |
479 |
$allowedreserves = $rights->{reservesallowed}; |
491 |
}else{ |
480 |
}else{ |
492 |
$itemtype = '*'; |
481 |
$itemtype = '*'; |
493 |
} |
482 |
} |
494 |
|
483 |
|
|
|
484 |
my $multi_holds_same = GetMultiHoldsCountSameEnum( |
485 |
borrowernumber => $borrowernumber, |
486 |
itemnumber => $itemnumber |
487 |
); |
488 |
|
495 |
# we retrieve count |
489 |
# we retrieve count |
496 |
|
490 |
|
497 |
$querycount .= "AND $branchfield = ?"; |
491 |
$querycount .= "AND $branchfield = ?"; |
Lines 511-520
sub CanItemBeReserved{
Link Here
|
511 |
} |
505 |
} |
512 |
|
506 |
|
513 |
# we check if it's ok or not |
507 |
# we check if it's ok or not |
514 |
if( $reservecount < $allowedreserves ){ |
508 |
if( $reservecount >= $allowedreserves ){ ## too many reserves |
515 |
return 1; |
|
|
516 |
}else{ |
517 |
return 0; |
509 |
return 0; |
|
|
510 |
}else{ |
511 |
return 1; |
518 |
} |
512 |
} |
519 |
} |
513 |
} |
520 |
#-------------------------------------------------------------------------------- |
514 |
#-------------------------------------------------------------------------------- |
Lines 2025-2030
sub ReserveSlip {
Link Here
|
2025 |
); |
2019 |
); |
2026 |
} |
2020 |
} |
2027 |
|
2021 |
|
|
|
2022 |
=head2 GetMultiHoldsCountSameEnum |
2023 |
|
2024 |
my $count = GetMultiHoldsCountSameEnum( |
2025 |
borrowernumber => $borrowernumber, |
2026 |
itemnumber => $itemnumber, |
2027 |
) |
2028 |
|
2029 |
This function returns the number of holds a borrower has placed |
2030 |
on specific items with the same enumchron field as the given |
2031 |
item, on the same bibliographic record. |
2032 |
|
2033 |
=cut |
2034 |
|
2035 |
sub GetMultiHoldsCountSameEnum { |
2036 |
my %params = @_; |
2037 |
my $borrowernumber = $params{'borrowernumber'}; |
2038 |
my $itemnumber = $params{'itemnumber'}; |
2039 |
|
2040 |
return unless ( $borrowernumber && $itemnumber ); |
2041 |
|
2042 |
my $dbh = C4::Context->dbh; |
2043 |
my $query = " |
2044 |
SELECT COUNT(*) AS count FROM reserves |
2045 |
LEFT JOIN items ON ( reserves.itemnumber = items.itemnumber ) |
2046 |
"; |
2047 |
} |
2048 |
|
2028 |
=head1 AUTHOR |
2049 |
=head1 AUTHOR |
2029 |
|
2050 |
|
2030 |
Koha Development Team <http://koha-community.org/> |
2051 |
Koha Development Team <http://koha-community.org/> |