Bug 28606: Remove $DEBUG and $ENV{DEBUG}
[srvgit] / C4 / SIP / ILS / Transaction / FeePayment.pm
index 9cedce5..7748b1a 100644 (file)
@@ -25,8 +25,6 @@ use Koha::Account::Lines;
 
 use parent qw(C4::SIP::ILS::Transaction);
 
-our $debug = 0;
-
 my %fields = ();
 
 sub new {
@@ -42,45 +40,60 @@ sub new {
 }
 
 sub pay {
-    my $self           = shift;
-    my $borrowernumber = shift;
-    my $amt            = shift;
-    my $sip_type       = shift;
-    my $fee_id         = shift;
-    my $is_writeoff    = shift;
-
-    my $type = $is_writeoff ? 'writeoff' : undef;
+    my $self                 = shift;
+    my $borrowernumber       = shift;
+    my $amt                  = shift;
+    my $sip_type             = shift;
+    my $fee_id               = shift;
+    my $is_writeoff          = shift;
+    my $disallow_overpayment = shift;
+    my $register_id          = shift;
 
-    warn("RECORD:$borrowernumber::$amt");
+    my $type = $is_writeoff ? 'WRITEOFF' : 'PAYMENT';
 
     my $account = Koha::Account->new( { patron_id => $borrowernumber } );
 
+    if ($disallow_overpayment) {
+        return { ok => 0 } if $account->balance < $amt;
+    }
+
     if ($fee_id) {
         my $fee = Koha::Account::Lines->find($fee_id);
-        if ( $fee && $fee->amountoutstanding == $amt ) {
-            $account->pay(
+        if ( $fee ) {
+            my $pay_response = $account->pay(
                 {
-                    amount => $amt,
-                    sip    => $sip_type,
-                    type   => $type,
-                    lines  => [$fee],
+                    amount       => $amt,
+                    type         => $type,
+                    payment_type => 'SIP' . $sip_type,
+                    lines        => [$fee],
+                    interface    => C4::Context->interface
                 }
             );
-            return 1;
+            return {
+                ok           => 1,
+                pay_response => $pay_response
+            };
         }
         else {
-            return 0;
+            return {
+                ok => 0
+            };
         }
     }
     else {
-        $account->pay(
+        my $pay_response = $account->pay(
             {
-                amount => $amt,
-                sip    => $sip_type,
-                type   => $type,
+                amount        => $amt,
+                type          => $type,
+                payment_type  => 'SIP' . $sip_type,
+                interface     => C4::Context->interface,
+                cash_register => $register_id
             }
         );
-        return 1;
+        return {
+            ok           => 1,
+            pay_response => $pay_response
+        };
     }
 }