|
Lines 429-436
This function return 1 if an item can be issued by this borrower.
Link Here
|
| 429 |
sub CanItemBeReserved{ |
429 |
sub CanItemBeReserved{ |
| 430 |
my ($borrowernumber, $itemnumber) = @_; |
430 |
my ($borrowernumber, $itemnumber) = @_; |
| 431 |
|
431 |
|
| 432 |
my $dbh = C4::Context->dbh; |
432 |
my $dbh = C4::Context->dbh; |
| 433 |
my $allowedreserves = 0; |
433 |
my $allowedreserves = 0; |
|
|
434 |
my $multi_holds_allowed_same = 0; |
| 435 |
my $multi_holds_allowed_diff = 0; |
| 434 |
|
436 |
|
| 435 |
my $controlbranch = C4::Context->preference('ReservesControlBranch'); |
437 |
my $controlbranch = C4::Context->preference('ReservesControlBranch'); |
| 436 |
my $itype = C4::Context->preference('item-level_itypes') ? "itype" : "itemtype"; |
438 |
my $itype = C4::Context->preference('item-level_itypes') ? "itype" : "itemtype"; |
|
Lines 439-465
sub CanItemBeReserved{
Link Here
|
| 439 |
my $item = GetItem($itemnumber); |
441 |
my $item = GetItem($itemnumber); |
| 440 |
my $borrower = C4::Members::GetMember('borrowernumber'=>$borrowernumber); |
442 |
my $borrower = C4::Members::GetMember('borrowernumber'=>$borrowernumber); |
| 441 |
|
443 |
|
| 442 |
# we retrieve user rights on this itemtype and branchcode |
444 |
my $querycount = " |
| 443 |
my $sth = $dbh->prepare("SELECT categorycode, itemtype, branchcode, reservesallowed |
445 |
SELECT count(*) AS count |
| 444 |
FROM issuingrules |
446 |
FROM reserves |
| 445 |
WHERE (categorycode in (?,'*') ) |
447 |
LEFT JOIN items USING (itemnumber) |
| 446 |
AND (itemtype IN (?,'*')) |
448 |
LEFT JOIN biblioitems ON (reserves.biblionumber=biblioitems.biblionumber) |
| 447 |
AND (branchcode IN (?,'*')) |
449 |
LEFT JOIN borrowers USING (borrowernumber) |
| 448 |
ORDER BY |
450 |
WHERE borrowernumber = ? |
| 449 |
categorycode DESC, |
451 |
"; |
| 450 |
itemtype DESC, |
|
|
| 451 |
branchcode DESC;" |
| 452 |
); |
| 453 |
|
| 454 |
my $querycount ="SELECT |
| 455 |
count(*) as count |
| 456 |
FROM reserves |
| 457 |
LEFT JOIN items USING (itemnumber) |
| 458 |
LEFT JOIN biblioitems ON (reserves.biblionumber=biblioitems.biblionumber) |
| 459 |
LEFT JOIN borrowers USING (borrowernumber) |
| 460 |
WHERE borrowernumber = ? |
| 461 |
"; |
| 462 |
|
| 463 |
|
452 |
|
| 464 |
my $itemtype = $item->{$itype}; |
453 |
my $itemtype = $item->{$itype}; |
| 465 |
my $categorycode = $borrower->{categorycode}; |
454 |
my $categorycode = $borrower->{categorycode}; |
|
Lines 475-488
sub CanItemBeReserved{
Link Here
|
| 475 |
} |
464 |
} |
| 476 |
|
465 |
|
| 477 |
# we retrieve rights |
466 |
# we retrieve rights |
| 478 |
$sth->execute($categorycode, $itemtype, $branchcode); |
467 |
my $rights = C4::Circulation::GetIssuingRule( $categorycode, $itemtype, $branchcode ); |
| 479 |
if(my $rights = $sth->fetchrow_hashref()){ |
468 |
if ( defined $rights ) { |
| 480 |
$itemtype = $rights->{itemtype}; |
469 |
$itemtype = $rights->{itemtype}; |
| 481 |
$allowedreserves = $rights->{reservesallowed}; |
470 |
$allowedreserves = $rights->{reservesallowed}; |
| 482 |
}else{ |
471 |
}else{ |
| 483 |
$itemtype = '*'; |
472 |
$itemtype = '*'; |
| 484 |
} |
473 |
} |
| 485 |
|
474 |
|
|
|
475 |
my $multi_holds_same = GetMultiHoldsCountSameEnum( |
| 476 |
borrowernumber => $borrowernumber, |
| 477 |
itemnumber => $itemnumber |
| 478 |
); |
| 479 |
|
| 486 |
# we retrieve count |
480 |
# we retrieve count |
| 487 |
|
481 |
|
| 488 |
$querycount .= "AND $branchfield = ?"; |
482 |
$querycount .= "AND $branchfield = ?"; |
|
Lines 502-511
sub CanItemBeReserved{
Link Here
|
| 502 |
} |
496 |
} |
| 503 |
|
497 |
|
| 504 |
# we check if it's ok or not |
498 |
# we check if it's ok or not |
| 505 |
if( $reservecount < $allowedreserves ){ |
499 |
if( $reservecount >= $allowedreserves ){ ## too many reserves |
| 506 |
return 1; |
|
|
| 507 |
}else{ |
| 508 |
return 0; |
500 |
return 0; |
|
|
501 |
}else{ |
| 502 |
return 1; |
| 509 |
} |
503 |
} |
| 510 |
} |
504 |
} |
| 511 |
#-------------------------------------------------------------------------------- |
505 |
#-------------------------------------------------------------------------------- |
|
Lines 1893-1898
sub ReserveSlip {
Link Here
|
| 1893 |
); |
1887 |
); |
| 1894 |
} |
1888 |
} |
| 1895 |
|
1889 |
|
|
|
1890 |
=head2 GetMultiHoldsCountSameEnum |
| 1891 |
|
| 1892 |
my $count = GetMultiHoldsCountSameEnum( |
| 1893 |
borrowernumber => $borrowernumber, |
| 1894 |
itemnumber => $itemnumber, |
| 1895 |
) |
| 1896 |
|
| 1897 |
This function returns the number of holds a borrower has placed |
| 1898 |
on specific items with the same enumchron field as the given |
| 1899 |
item, on the same bibliographic record. |
| 1900 |
|
| 1901 |
=cut |
| 1902 |
|
| 1903 |
sub GetMultiHoldsCountSameEnum { |
| 1904 |
my %params = @_; |
| 1905 |
my $borrowernumber = $params{'borrowernumber'}; |
| 1906 |
my $itemnumber = $params{'itemnumber'}; |
| 1907 |
|
| 1908 |
return unless ( $borrowernumber && $itemnumber ); |
| 1909 |
|
| 1910 |
my $dbh = C4::Context->dbh; |
| 1911 |
my $query = " |
| 1912 |
SELECT COUNT(*) AS count FROM reserves |
| 1913 |
LEFT JOIN items ON ( reserves.itemnumber = items.itemnumber ) |
| 1914 |
"; |
| 1915 |
} |
| 1916 |
|
| 1896 |
=head1 AUTHOR |
1917 |
=head1 AUTHOR |
| 1897 |
|
1918 |
|
| 1898 |
Koha Development Team <http://koha-community.org/> |
1919 |
Koha Development Team <http://koha-community.org/> |