- # Look in the issues table for this item, lent to this borrower,
- # and not yet returned.
- my %branch = (
- 'ItemHomeLibrary' => 'items.homebranch',
- 'PickupLibrary' => 'items.holdingbranch',
- 'PatronLibrary' => 'borrowers.branchcode'
- );
- my $controlbranch = $branch{C4::Context->preference('CircControl')};
- my $itype = C4::Context->preference('item-level_itypes') ? 'items.itype' : 'biblioitems.itemtype';
-
- my $sthcount = $dbh->prepare("
- SELECT
- borrowers.categorycode, biblioitems.itemtype, issues.renewals, renewalsallowed, $controlbranch
- FROM issuingrules,
- issues
- LEFT JOIN items USING (itemnumber)
- LEFT JOIN borrowers USING (borrowernumber)
- LEFT JOIN biblioitems USING (biblioitemnumber)
-
- WHERE
- (issuingrules.categorycode = borrowers.categorycode OR issuingrules.categorycode = '*')
- AND
- (issuingrules.itemtype = $itype OR issuingrules.itemtype = '*')
- AND
- (issuingrules.branchcode = $controlbranch OR issuingrules.branchcode = '*')
- AND
- borrowernumber = ?
- AND
- itemnumber = ?
- ORDER BY
- issuingrules.categorycode desc,
- issuingrules.itemtype desc,
- issuingrules.branchcode desc
- LIMIT 1;
- ");
-
- $sthcount->execute( $borrowernumber, $itemnumber );
- if ( my $data1 = $sthcount->fetchrow_hashref ) {
-
- if ( ( $data1->{renewalsallowed} && $data1->{renewalsallowed} > $data1->{renewals} ) || $override_limit ) {
- $renewokay = 1;
- }
- else {
- $error="too_many";
- }
-
- my ( $resfound, $resrec, undef ) = C4::Reserves::CheckReserves($itemnumber);
- if ($resfound) {
- $renewokay = 0;
- $error="on_reserve"
- }