From 50f97aed63e5a07ff45ac5ea84f46dafea3ed74e Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Fri, 6 Nov 2015 13:20:56 -0500 Subject: [PATCH] Bug 14390 - On renewal, the last fine is not marked as accounttype 'F' when item is checked in. Test Plan: 1) Find an overdue checkout with a fine 2) Renew item, note fine is not closed out (Account type F) 3) Apply this patch 4) Find another overdue checkout with a fine 5) Renew item, note fine is now correctly closed out 6) Backdate a checkout to be already overdue ( but not have a fine since fines.pl hasn't run yet ) 7) Renew item, note a closed out fine is created Signed-off-by: Sean Minkel --- C4/Circulation.pm | 129 ++++++++++++++++++++++++++++++----------------------- 1 files changed, 73 insertions(+), 56 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 18cc9d5..3fdb4a2 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -1911,39 +1911,7 @@ sub AddReturn { if ($borrowernumber) { if ( ( C4::Context->preference('CalculateFinesOnReturn') && $issue->{'overdue'} ) || $return_date ) { - # we only need to calculate and change the fines if we want to do that on return - # Should be on for hourly loans - my $control = C4::Context->preference('CircControl'); - my $control_branchcode = - ( $control eq 'ItemHomeLibrary' ) ? $item->{homebranch} - : ( $control eq 'PatronLibrary' ) ? $borrower->{branchcode} - : $issue->{branchcode}; - - my $date_returned = - $return_date ? dt_from_string($return_date) : $today; - - my ( $amount, $type, $unitcounttotal ) = - C4::Overdues::CalcFine( $item, $borrower->{categorycode}, - $control_branchcode, $datedue, $date_returned ); - - $type ||= q{}; - - if ( C4::Context->preference('finesMode') eq 'production' ) { - if ( $amount > 0 ) { - C4::Overdues::UpdateFine( $issue->{itemnumber}, - $issue->{borrowernumber}, - $amount, $type, output_pref($datedue) ); - } - elsif ($return_date) { - - # Backdated returns may have fines that shouldn't exist, - # so in this case, we need to drop those fines to 0 - - C4::Overdues::UpdateFine( $issue->{itemnumber}, - $issue->{borrowernumber}, - 0, $type, output_pref($datedue) ); - } - } + _CalculateAndUpdateFine( { issue => $issue, item => $item, borrower => $borrower, return_date => $return_date } ); } eval { @@ -2873,10 +2841,7 @@ sub AddRenewal { my $dbh = C4::Context->dbh; # Find the issues record for this book - my $sth = - $dbh->prepare("SELECT * FROM issues WHERE itemnumber = ?"); - $sth->execute( $itemnumber ); - my $issuedata = $sth->fetchrow_hashref; + my $issuedata = GetItemIssue($itemnumber); return unless ( $issuedata ); @@ -2887,12 +2852,18 @@ sub AddRenewal { return; } + my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber ) or return; + + if ( C4::Context->preference('CalculateFinesOnReturn') && $issuedata->{overdue} ) { + _CalculateAndUpdateFine( { issue => $issuedata, item => $item, borrower => $borrower } ); + } + _FixOverduesOnReturn( $borrowernumber, $itemnumber ); + # If the due date wasn't specified, calculate it by adding the # book's loan length to today's date or the current due date # based on the value of the RenewalPeriodBase syspref. unless ($datedue) { - my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber ) or return; my $itemtype = (C4::Context->preference('item-level_itypes')) ? $biblio->{'itype'} : $biblio->{'itemtype'}; $datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ? @@ -2904,7 +2875,7 @@ sub AddRenewal { # Update the issues record to have the new due date, and a new count # of how many times it has been renewed. my $renews = $issuedata->{'renewals'} + 1; - $sth = $dbh->prepare("UPDATE issues SET date_due = ?, renewals = ?, lastreneweddate = ? + my $sth = $dbh->prepare("UPDATE issues SET date_due = ?, renewals = ?, lastreneweddate = ? WHERE borrowernumber=? AND itemnumber=?" ); @@ -2934,23 +2905,25 @@ sub AddRenewal { } # Send a renewal slip according to checkout alert preferencei - if ( C4::Context->preference('RenewalSendNotice') eq '1') { - my $borrower = C4::Members::GetMemberDetails( $borrowernumber, 0 ); - my $circulation_alert = 'C4::ItemCirculationAlertPreference'; - my %conditions = ( - branchcode => $branch, - categorycode => $borrower->{categorycode}, - item_type => $item->{itype}, - notification => 'CHECKOUT', - ); - if ($circulation_alert->is_enabled_for(\%conditions)) { - SendCirculationAlert({ - type => 'RENEWAL', - item => $item, - borrower => $borrower, - branch => $branch, - }); - } + if ( C4::Context->preference('RenewalSendNotice') eq '1' ) { + $borrower = C4::Members::GetMemberDetails( $borrowernumber, 0 ); + my $circulation_alert = 'C4::ItemCirculationAlertPreference'; + my %conditions = ( + branchcode => $branch, + categorycode => $borrower->{categorycode}, + item_type => $item->{itype}, + notification => 'CHECKOUT', + ); + if ( $circulation_alert->is_enabled_for( \%conditions ) ) { + SendCirculationAlert( + { + type => 'RENEWAL', + item => $item, + borrower => $borrower, + branch => $branch, + } + ); + } } # Remove any OVERDUES related debarment if the borrower has no overdues @@ -4095,6 +4068,50 @@ sub GetTopIssues { return @$rows; } +sub _CalculateAndUpdateFine { + my ($params) = @_; + + my $borrower = $params->{borrower}; + my $item = $params->{item}; + my $issue = $params->{issue}; + my $return_date = $params->{return_date}; + + unless ($borrower) { carp "No borrower passed in!" && return; } + unless ($item) { carp "No item passed in!" && return; } + unless ($issue) { carp "No issue passed in!" && return; } + + my $datedue = $issue->{date_due}; + + # we only need to calculate and change the fines if we want to do that on return + # Should be on for hourly loans + my $control = C4::Context->preference('CircControl'); + my $control_branchcode = + ( $control eq 'ItemHomeLibrary' ) ? $item->{homebranch} + : ( $control eq 'PatronLibrary' ) ? $borrower->{branchcode} + : $issue->{branchcode}; + + my $date_returned = $return_date ? dt_from_string($return_date) : dt_from_string(); + + my ( $amount, $type, $unitcounttotal ) = + C4::Overdues::CalcFine( $item, $borrower->{categorycode}, $control_branchcode, $datedue, $date_returned ); + + $type ||= q{}; + + if ( C4::Context->preference('finesMode') eq 'production' ) { + if ( $amount > 0 ) { + C4::Overdues::UpdateFine( $issue->{itemnumber}, $issue->{borrowernumber}, + $amount, $type, output_pref($datedue) ); + } + elsif ($return_date) { + + # Backdated returns may have fines that shouldn't exist, + # so in this case, we need to drop those fines to 0 + + C4::Overdues::UpdateFine( $issue->{itemnumber}, $issue->{borrowernumber}, 0, $type, output_pref($datedue) ); + } + } +} + __END__ =head1 AUTHOR -- 1.7.2.5