Adds Instant fine calculation at checkin

To Test:

Check out an Item, hourly items are best but any will do.  Make sure the item 
is overdue, and when you check the item in you should see a fine reflected that 
is correct for the amount of time it is overdue according to your smart rules.


>From e13e051ca6742a02c70bdbcba04136da4046ee83 Mon Sep 17 00:00:00 2001
From: Elliott Davis <[email protected]<mailto:[email protected]>>
Date: Thu, 29 Mar 2012 20:05:10 +0000
Subject: [PATCH 2/2] Adds instant fine calculation at checkin

---
 C4/Circulation.pm |   20 ++++++++++++++++++--
 1 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/C4/Circulation.pm b/C4/Circulation.pm
index 9c43f36..0adb8e3 100644
--- a/C4/Circulation.pm
+++ b/C4/Circulation.pm
@@ -36,6 +36,7 @@ use C4::Message;
 use C4::Debug;
 use C4::Branch; # GetBranches
 use C4::Log; # logaction
+use C4::Overdues qw(CalcFine UpdateFine);

 use Data::Dumper;
 use Koha::DateUtils;
@@ -1595,17 +1596,32 @@ sub AddReturn {

     # case of a return of document (deal with issues and holdingbranch)
     if ($doreturn) {
+ my $today = DateTime->now( time_zone => C4::Context->tz() );
+ my $datedue = $issue->{date_due};
         $borrower or warn "AddReturn without current borrower";
- my $circControlBranch;
+ my $circControlBranch;
         if ($dropbox) {
             # define circControlBranch only if dropbox mode is set
             # don't allow dropbox mode to create an invalid entry in issues 
(issuedate > today)
             # FIXME: check issuedate > returndate, factoring in holidays
             #$circControlBranch = _GetCircControlBranch($item,$borrower) 
unless ( $item->{'issuedate'} eq C4::Dates->today('iso') );;
             $circControlBranch = _GetCircControlBranch($item,$borrower);
+     $today->add(days => -1 );
+     $issue->{'overdue'} = DateTime->compare($issue->{'date_due'}, $today ) == 
-1 ? 1 : 0;
         }
-
         if ($borrowernumber) {
+     if($issue->{'overdue'}){
+ my ( $amount, $type, $daycounttotal ) = C4::Overdues::CalcFine( $item, 
$borrower->{categorycode},$branch, $datedue, $today );
+ my $type ||= q{};
+ print STDERR "\n\nAMOUNT: $amount";
+ if ( $amount > 0 ) {
+     C4::Overdues::UpdateFine(
+ $issue->{itemnumber},
+ $issue->{borrowernumber},
+ $amount, $type, output_pref($datedue)
+ );
+ }
+     }
             MarkIssueReturned($borrowernumber, $item->{'itemnumber'}, 
$circControlBranch, '', $borrower->{'privacy'});
             $messages->{'WasReturned'} = 1;    # FIXME is the "= 1" right?  
This could be the borrower hash.
         }
--
1.7.2.5

_______________________________________________
Koha-patches mailing list
[email protected]
http://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-patches
website : http://www.koha-community.org/
git : http://git.koha-community.org/
bugs : http://bugs.koha-community.org/

Reply via email to