Lines 672-689
sub GetReserveFee {
Link Here
|
672 |
my $borquery = qq{ |
672 |
my $borquery = qq{ |
673 |
SELECT reservefee FROM borrowers LEFT JOIN categories ON borrowers.categorycode = categories.categorycode WHERE borrowernumber = ? |
673 |
SELECT reservefee FROM borrowers LEFT JOIN categories ON borrowers.categorycode = categories.categorycode WHERE borrowernumber = ? |
674 |
}; |
674 |
}; |
|
|
675 |
my $issue_qry = qq{ |
676 |
SELECT COUNT(*) FROM items |
677 |
LEFT JOIN issues USING (itemnumber) |
678 |
WHERE items.biblionumber=? AND issues.issue_id IS NULL |
679 |
}; |
680 |
my $holds_qry = qq{ |
681 |
SELECT COUNT(*) FROM reserves WHERE biblionumber=? AND borrowernumber<>? |
682 |
}; |
675 |
|
683 |
|
676 |
my $dbh = C4::Context->dbh; |
684 |
my $dbh = C4::Context->dbh; |
677 |
my ( $fee ) = $dbh->selectrow_array( $borquery, undef, ($borrowernumber) ); |
685 |
my ( $fee ) = $dbh->selectrow_array( $borquery, undef, ($borrowernumber) ); |
678 |
if( $fee && $fee > 0 ) { |
686 |
if( $fee && $fee > 0 ) { |
679 |
# This is a reconstruction of the old code: |
687 |
# This is a reconstruction of the old code: |
680 |
# Calculate number of items, items issued and holds |
688 |
# Compare number of items with items issued, and optionally check holds |
681 |
my ( $cnt1 ) = $dbh->selectrow_array( "SELECT COUNT(*) FROM items WHERE biblionumber=?", undef, ( $biblionumber ) ); |
|
|
682 |
my ( $cnt2 ) = $dbh->selectrow_array( "SELECT COUNT(*) FROM issues LEFT JOIN items USING (itemnumber) WHERE biblionumber=?", undef, ( $biblionumber )); |
683 |
my ( $cnt3 ) = $dbh->selectrow_array( "SELECT COUNT(*) FROM reserves WHERE biblionumber=? AND borrowernumber<>?", undef, ( $biblionumber, $borrowernumber ) ); |
684 |
# If not all items are issued and there are no holds: charge no fee |
689 |
# If not all items are issued and there are no holds: charge no fee |
685 |
# NOTE: Lost, damaged, not-for-loan, etc. are just ignored here |
690 |
# NOTE: Lost, damaged, not-for-loan, etc. are just ignored here |
686 |
$fee = 0 if $cnt1 - $cnt2 > 0 && $cnt3 == 0; |
691 |
my ( $notissued, $reserved ); |
|
|
692 |
( $notissued ) = $dbh->selectrow_array( $issue_qry, undef, |
693 |
( $biblionumber ) ); |
694 |
if( $notissued ) { |
695 |
( $reserved ) = $dbh->selectrow_array( $holds_qry, undef, |
696 |
( $biblionumber, $borrowernumber ) ); |
697 |
$fee = 0 if $reserved == 0; |
698 |
} |
687 |
} |
699 |
} |
688 |
return $fee; |
700 |
return $fee; |
689 |
} |
701 |
} |
690 |
- |
|
|