Bug 14048: Hook new rules into C4::Circulation
authorTomas Cohen Arazi <tomascohen@theke.io>
Fri, 3 Jun 2016 14:26:42 +0000 (11:26 -0300)
committerJesse Weaver <jweaver@bywatersolutions.com>
Thu, 7 Jul 2016 16:37:01 +0000 (10:37 -0600)
This patch makes AddIssue and AddReturn use the new implementation

The behaviour should respect the specification.

Sponsored-by: DoverNet
Sponsored-by: South-East Kansas Library System
Sponsored-by: SWITCH Library Consortium
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Jason Robb <jrobb@sekls.org>
Signed-off-by: Jennifer Schmidt <jschmidt@switchinc.org>
Signed-off-by: Margaret Thrasher <p.thrasher@dover.nh.gov>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Jesse Weaver <jweaver@bywatersolutions.com>
C4/Circulation.pm

index 2cb0930..7ceac6b 100644 (file)
@@ -53,6 +53,8 @@ use Koha::Patron::Debarments;
 use Koha::Database;
 use Koha::Libraries;
 use Koha::Holds;
+use Koha::RefundLostItemFeeRule;
+use Koha::RefundLostItemFeeRules;
 use Carp;
 use List::MoreUtils qw( uniq );
 use Scalar::Util qw( looks_like_number );
@@ -1450,12 +1452,17 @@ sub AddIssue {
                 UpdateTotalIssues( $item->{'biblionumber'}, 1 );
             }
 
-            ## If item was lost, it has now been found, reverse any list item charges if necessary.
-            if ( $item->{'itemlost'} ) {
-                if ( C4::Context->preference('RefundLostItemFeeOnReturn') ) {
-                    _FixAccountForLostAndReturned( $item->{'itemnumber'}, undef, $item->{'barcode'} );
-                }
+        ## If item was lost, it has now been found, reverse any list item charges if necessary.
+        if ( $item->{'itemlost'} ) {
+            if ( Koha::RefundLostItemFeeRules->should_refund(
+                    current_branch => C4::Context->userenv->{ branch },
+                    patron_branch  => $borrower->{ branchcode },
+                    item_home_branch => $item->{ homebranch },
+                    item_holding_branch => $item->{ holdingbranch }
+                 ) ) {
+                _FixAccountForLostAndReturned( $item->{'itemnumber'}, undef, $item->{'barcode'} );
             }
+        }
 
             ModItem(
                 {
@@ -2131,9 +2138,16 @@ sub AddReturn {
     if ( $item->{'itemlost'} ) {
         $messages->{'WasLost'} = 1;
 
-        if ( C4::Context->preference('RefundLostItemFeeOnReturn' ) ) {
-            _FixAccountForLostAndReturned($item->{'itemnumber'}, $borrowernumber, $barcode);    # can tolerate undef $borrowernumber
-            $messages->{'LostItemFeeRefunded'} = 1;
+        if ( $item->{'itemlost'} ) {
+            if ( Koha::RefundLostItemFeeRules->should_refund(
+                    current_branch => C4::Context->userenv->{ branch },
+                    patron_branch  => $borrower->{ branchcode },
+                    item_home_branch => $item->{ homebranch },
+                    item_holding_branch => $item->{ holdingbranch }
+                 ) ) {
+                _FixAccountForLostAndReturned( $item->{'itemnumber'}, $borrowernumber, $barcode );
+                $messages->{'LostItemFeeRefunded'} = 1;
+            }
         }
     }