Bug 22564: Remove references to 'Rep' accounttype
[koha-equinox.git] / C4 / Circulation.pm
index e01ddd9..c93ee3d 100644 (file)
@@ -886,11 +886,15 @@ sub CanBookBeIssued {
             $issuingimpossible{RETURN_IMPOSSIBLE} = 1;
             $issuingimpossible{branch_to_return} = $message;
         } else {
+            if ( C4::Context->preference('AutoReturnCheckedOutItems') ) {
+                $alerts{RETURNED_FROM_ANOTHER} = { patron => $patron };
+            } else {
             $needsconfirmation{ISSUED_TO_ANOTHER} = 1;
             $needsconfirmation{issued_firstname} = $patron->firstname;
             $needsconfirmation{issued_surname} = $patron->surname;
             $needsconfirmation{issued_cardnumber} = $patron->cardnumber;
             $needsconfirmation{issued_borrowernumber} = $patron->borrowernumber;
+            }
         }
     }
 
@@ -2329,10 +2333,8 @@ sub _FixOverduesOnReturn {
         {
             borrowernumber => $borrowernumber,
             itemnumber     => $item,
-            -or            => [
-                accounttype => 'FU',
-                accounttype => 'O',
-            ],
+            accounttype    => 'OVERDUE',
+            status         => 'UNRETURNED'
         }
     )->next();
     return 0 unless $accountline;    # no warning, there's just nothing to fix
@@ -2340,7 +2342,7 @@ sub _FixOverduesOnReturn {
     if ($exemptfine) {
         my $amountoutstanding = $accountline->amountoutstanding;
 
-        $accountline->accounttype('FFOR');
+        $accountline->status('FORGIVEN');
         $accountline->amountoutstanding(0);
 
         Koha::Account::Offset->new(
@@ -2355,7 +2357,7 @@ sub _FixOverduesOnReturn {
             &logaction("FINES", 'MODIFY',$borrowernumber,"Overdue forgiven: item $item");
         }
     } else {
-        $accountline->accounttype('F');
+        $accountline->status('RETURNED');
     }
 
     return $accountline->store();
@@ -2382,10 +2384,10 @@ sub _FixAccountForLostAndReturned {
     my $accountlines = Koha::Account::Lines->search(
         {
             itemnumber  => $itemnumber,
-            accounttype => { -in => [ 'L', 'Rep', 'W' ] },
+            accounttype => { -in => [ 'L', 'W' ] },
         },
         {
-            order_by => { -desc => [ 'date' ] }
+            order_by => { -desc => [ 'date', 'accountlines_id' ] }
         }
     );
 
@@ -2419,6 +2421,7 @@ sub _FixAccountForLostAndReturned {
             {   amount      => $credit_total,
                 description => 'Item Returned ' . $item_id,
                 type        => 'lost_item_return',
+                interface   => C4::Context->interface,
                 library_id  => $branchcode
             }
         );
@@ -2844,7 +2847,7 @@ sub AddRenewal {
         $datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ?
                                         dt_from_string( $issue->date_due, 'sql' ) :
                                         DateTime->now( time_zone => C4::Context->tz());
-        $datedue =  CalcDateDue($datedue, $itemtype, $circ_library, $patron_unblessed, 'is a renewal');
+        $datedue =  CalcDateDue($datedue, $itemtype, $circ_library->branchcode, $patron_unblessed, 'is a renewal');
     }
 
     my $fees = Koha::Charges::Fees->new(
@@ -3221,8 +3224,9 @@ sub AddIssuingCharge {
             amount      => $charge,
             description => $description,
             note        => undef,
-            user_id     => C4::Context->userenv ? C4::Context->userenv->{'number'} : 0,
+            user_id     => C4::Context->userenv ? C4::Context->userenv->{'number'} : undef,
             library_id  => C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef,
+            interface   => C4::Context->interface,
             type        => 'rent',
             item_id     => $checkout->itemnumber,
             issue_id    => $checkout->issue_id,
@@ -3681,7 +3685,7 @@ sub LostItem{
         defined($fix) or warn "_FixOverduesOnReturn($borrowernumber, $itemnumber...) failed!";  # zero is OK, check defined
 
         if (C4::Context->preference('WhenLostChargeReplacementFee')){
-            C4::Accounts::chargelostitem($borrowernumber, $itemnumber, $issues->{'replacementprice'}, "Lost Item $issues->{'title'} $issues->{'barcode'} $issues->{'itemcallnumber'}");
+            C4::Accounts::chargelostitem($borrowernumber, $itemnumber, $issues->{'replacementprice'}, "$issues->{'title'} $issues->{'barcode'} $issues->{'itemcallnumber'}");
             #FIXME : Should probably have a way to distinguish this from an item that really was returned.
             #warn " $issues->{'borrowernumber'}  /  $itemnumber ";
         }
@@ -3813,7 +3817,13 @@ sub ProcessOfflinePayment {
 
     my $patron = Koha::Patrons->find({ cardnumber => $operation->{cardnumber} });
 
-    $patron->account->pay({ amount => $operation->{amount}, library_id => $operation->{branchcode} });
+    $patron->account->pay(
+        {
+            amount     => $operation->{amount},
+            library_id => $operation->{branchcode},
+            interface  => 'koc'
+        }
+    );
 
     return "Success.";
 }