From 43000d334ccd1a9a289504d7dd78a910c979d3f1 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Fri, 21 Aug 2015 11:44:55 +0200 Subject: [PATCH] Bug 14702: Fix GetReserveFee Content-Type: text/plain; charset=utf-8 The code in this sub of Reserves is unneeded and erroneous. The old code checked via biblioitems if there still was an item not issued and if so, it checked reserves: if there was no no hold yet for the biblio, the reserve fee went to zero. (Strange !) So only the second hold would trigger a charge. (But Koha does NOT allow that second hold at this time!) So it actually does nothing! This can/should be drastically simplified: We only call GetReserveFee from AddReserve. So there is an item free and it is possible to place a hold. Since it is currently not possible to place a second hold, and even if it was, we just charge our hold fee from patron categories! NOTE: It somehow seems a bit odd to have hold fee in the patron categories. Maybe it should be added to itemtypes (on another report)? This is a fix that changes behavior! A follow-up will print a warning for libraries upgrading. Test plan: [1] Add a hold for a patron without hold fee. Check the patron account if there is no charge for the new hold. [2] Add a hold for a ptron with hold fee. Check account again. --- C4/Reserves.pm | 100 +++++++++++--------------------------------------------- 1 file changed, 19 insertions(+), 81 deletions(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 10579d9..9799410 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -156,9 +156,6 @@ sub AddReserve { $bibitems, $priority, $resdate, $expdate, $notes, $title, $checkitem, $found ) = @_; - my $fee = - GetReserveFee($borrowernumber, $biblionumber, - $bibitems ); my $dbh = C4::Context->dbh; $resdate = format_date_in_iso( $resdate ) if ( $resdate ); $resdate = C4::Dates->today( 'iso' ) unless ( $resdate ); @@ -178,9 +175,9 @@ sub AddReserve { $waitingdate = $resdate; } - #eval { # updates take place here - if ( $fee > 0 ) { + my $fee = GetReserveFee( $borrowernumber ); + if ( $fee ) { my $nextacctno = &getnextacctno( $borrowernumber ); my $query = qq{ INSERT INTO accountlines @@ -652,91 +649,32 @@ sub GetOtherReserves { =head2 GetReserveFee - $fee = GetReserveFee($borrowernumber,$biblionumber,$biblionumber); + $fee = GetReserveFee( $borrowernumber ); -Calculate the fee for a reserve + Calculate the fee for a reserve. Returns undef if no fee is found. + + NOTE: This code is simplified on bug 14702. The old checks were unneeded + and erroneous. This routine is called at the moment of adding a reserve, + we just need to pass the hold fee. =cut sub GetReserveFee { - my ($borrowernumber, $biblionumber, $bibitems ) = @_; - - #check for issues; - my $dbh = C4::Context->dbh; + my ( $borrowernumber ) = @_; + my $dbh = C4::Context->dbh; my $query = qq{ - SELECT * FROM borrowers - LEFT JOIN categories ON borrowers.categorycode = categories.categorycode - WHERE borrowernumber = ? +SELECT reservefee +FROM borrowers +LEFT JOIN categories ON borrowers.categorycode = categories.categorycode +WHERE borrowernumber = ? }; - my $sth = $dbh->prepare($query); - $sth->execute($borrowernumber); + my $sth = $dbh->prepare( $query ); + $sth->execute( $borrowernumber ); my $data = $sth->fetchrow_hashref; - my $fee = $data->{'reservefee'}; - my $cntitems = @- > $bibitems; - - if ( $fee > 0 ) { - - # check for items on issue - # first find biblioitem records - my @biblioitems; - my $sth1 = $dbh->prepare( - "SELECT * FROM biblio LEFT JOIN biblioitems on biblio.biblionumber = biblioitems.biblionumber - WHERE (biblio.biblionumber = ?)" - ); - $sth1->execute($biblionumber); - while ( my $data1 = $sth1->fetchrow_hashref ) { - my $found = 0; - my $x = 0; - while ( $x < $cntitems ) { - if ( @$bibitems->{'biblioitemnumber'} == - $data->{'biblioitemnumber'} ) - { - $found = 1; - } - $x++; - } - - if ( $found == 0 ) { - push @biblioitems, $data1; - } - } - my $cntitemsfound = @biblioitems; - my $issues = 0; - my $x = 0; - my $allissued = 1; - while ( $x < $cntitemsfound ) { - my $bitdata = $biblioitems[$x]; - my $sth2 = $dbh->prepare( - "SELECT * FROM items - WHERE biblioitemnumber = ?" - ); - $sth2->execute( $bitdata->{'biblioitemnumber'} ); - while ( my $itdata = $sth2->fetchrow_hashref ) { - my $sth3 = $dbh->prepare( - "SELECT * FROM issues - WHERE itemnumber = ?" - ); - $sth3->execute( $itdata->{'itemnumber'} ); - if ( my $isdata = $sth3->fetchrow_hashref ) { - } - else { - $allissued = 0; - } - } - $x++; - } - if ( $allissued == 0 ) { - my $rsth = - $dbh->prepare("SELECT * FROM reserves WHERE biblionumber = ?"); - $rsth->execute($biblionumber); - if ( my $rdata = $rsth->fetchrow_hashref ) { - } - else { - $fee = 0; - } - } + if( $data && $data->{'reservefee'} > 0 ) { + return $data->{'reservefee'}; } - return $fee; + return; } =head2 GetReservesToBranch -- 1.7.10.4