Merge branch 'bug_9332' into 3.12-master
[koha_fer] / C4 / SIP / ILS.pm
index f57bbd0..5d59850 100644 (file)
@@ -32,7 +32,7 @@ my %supports = (
     "login"                 => 1,
     "patron information"    => 1,
     "end patron session"    => 1,
-    "fee paid"              => 0,
+    "fee paid"              => 1,
     "item information"      => 1,
     "item status update"    => 0,
     "patron enable"         => 1,
@@ -180,16 +180,26 @@ sub checkin {
     # BEGIN TRANSACTION
     $circ->item($item = new ILS::Item $item_id);
 
-    $circ->do_checkin($current_loc, $return_date);
+    if ($item) {
+        $circ->do_checkin($current_loc);
+    } else {
+        $circ->alert(1);
+        $circ->alert_type(99);
+        $circ->screen_msg('Invalid Item');
+    }
        # It's ok to check it in if it exists, and if it was checked out
        $circ->ok($item && $item->{patron});
 
-    if ($circ->ok) {
-               $circ->patron($patron = new ILS::Patron $item->{patron});
-               delete $item->{patron};
-               delete $item->{due_date};
-               $patron->{items} = [ grep {$_ ne $item_id} @{$patron->{items}} ];
-    }
+       if (!defined($item->{patron})) {
+               $circ->screen_msg("Item not checked out");
+       } else {
+               if ($circ->ok) {
+                       $circ->patron($patron = new ILS::Patron $item->{patron});
+                       delete $item->{patron};
+                       delete $item->{due_date};
+                       $patron->{items} = [ grep {$_ ne $item_id} @{$patron->{items}} ];
+               }
+       }
     # END TRANSACTION
 
     return $circ;
@@ -208,14 +218,18 @@ sub pay_fee {
     my ($self, $patron_id, $patron_pwd, $fee_amt, $fee_type,
        $pay_type, $fee_id, $trans_id, $currency) = @_;
     my $trans;
-    my $patron;
 
-#    $trans = new ILS::Transaction::FeePayment;
+    $trans = ILS::Transaction::FeePayment->new();
 
-    $patron = new ILS::Patron $patron_id;
 
     $trans->transaction_id($trans_id);
-    $trans->patron($patron);
+    my $patron;
+    $trans->patron($patron = ILS::Patron->new($patron_id));
+    if (!$patron) {
+        $trans->screen_msg('Invalid patron barcode.');
+        return $trans;
+    }
+    $trans->pay($patron->{borrowernumber},$fee_amt);
     $trans->ok(1);
 
     return $trans;
@@ -414,17 +428,12 @@ sub renew {
     if (!defined($item)) {
                $trans->screen_msg("Item not checked out to " . $patron->name);     # not checked out to $patron_id
         $trans->ok(0);
-    } elsif (!$item->available($patron_id)) {
-               $trans->screen_msg("Item unavailable due to outstanding holds");
-        $trans->ok(0);
     } else {
-               $trans->renewal_ok(1);
-               $trans->desensitize(0); # It's already checked out
-               $trans->do_renew();
-               syslog("LOG_DEBUG", "done renew (ok:%s): %s renews %s", $trans->renewal_ok, $patron_id, $item_id);
-
-#              $item->{due_date} = $nb_due_date if $no_block eq 'Y';
-#              $item->{sip_item_properties} = $item_props if $item_props;
+        $trans->do_renew();
+        if ($trans->renewal_ok()) {
+            $item->{due_date} = $trans->{due};
+            $trans->desensitize(0);
+        }
     }
 
     return $trans;