Bug 10729: Add phrases configuration for ICU
[koha_fer] / C4 / SIP / ILS.pm
index 1a4fc54..e2089e8 100644 (file)
@@ -21,25 +21,25 @@ use ILS::Transaction::RenewAll;
 my $debug = 0;
 
 my %supports = (
-               'magnetic media'        => 1,
-               'security inhibit'      => 0,
-               'offline operation'     => 0,
-               "patron status request" => 1,
-               "checkout"              => 1,
-               "checkin"               => 1,
-               "block patron"          => 1,
-               "acs status"            => 1,
-               "login"                 => 1,
-               "patron information"    => 1,
-               "end patron session"    => 1,
-               "fee paid"              => 0,
-               "item information"      => 1,
-               "item status update"    => 0,
-               "patron enable"         => 1,
-               "hold"                  => 1,
-               "renew"                 => 1,
-               "renew all"             => 1,
-              );
+    'magnetic media'        => 1,
+    'security inhibit'      => 0,
+    'offline operation'     => 0,
+    "patron status request" => 1,
+    "checkout"              => 1,
+    "checkin"               => 1,
+    "block patron"          => 1,
+    "acs status"            => 1,
+    "login"                 => 1,
+    "patron information"    => 1,
+    "end patron session"    => 1,
+    "fee paid"              => 1,
+    "item information"      => 1,
+    "item status update"    => 0,
+    "patron enable"         => 1,
+    "hold"                  => 1,
+    "renew"                 => 1,
+    "renew all"             => 1,
+);
 
 sub new {
     my ($class, $institution) = @_;
@@ -66,6 +66,11 @@ sub find_item {
 
 sub institution {
     my $self = shift;
+    return $self->{institution}->{id};  # consider making this return the whole institution
+}
+
+sub institution_id {
+    my $self = shift;
     return $self->{institution}->{id};
 }
 
@@ -77,8 +82,8 @@ sub supports {
 sub check_inst_id {
     my ($self, $id, $whence) = @_;
     if ($id ne $self->{institution}->{id}) {
-       syslog("LOG_WARNING", "%s: received institution '%s', expected '%s'",
-              $whence, $id, $self->{institution}->{id});
+        syslog("LOG_WARNING", "%s: received institution '%s', expected '%s'", $whence, $id, $self->{institution}->{id});
+        # Just an FYI check, we don't expect the user to change location from that in SIPconfig.xml
     }
 }
 
@@ -86,33 +91,30 @@ sub to_bool {
     my $bool = shift;
     # If it's defined, and matches a true sort of string, or is
     # a non-zero number, then it's true.
-       #
-       # FIXME: this test is faulty
-       #       We're running under warnings and strict.
-       #       But if we don't match regexp, then we go ahead and numerical compare?
-       #       That means we'd generate a warning on 'FALSE' or ''.
-    return defined($bool) && (($bool =~ /true|y|yes/i) || $bool != 0);
+    defined($bool) or return;                   # false
+    ($bool =~ /true|y|yes/i) and return 1;      # true
+    return ($bool =~ /^\d+$/ and $bool != 0);   # true for non-zero numbers, false otherwise
 }
 
 sub checkout_ok {
     my $self = shift;
-    return (exists($self->{policy}->{checkout})
-           && to_bool($self->{policy}->{checkout}));
+    return (exists($self->{institution}->{policy}->{checkout})
+           && to_bool($self->{institution}->{policy}->{checkout}));
 }
 sub checkin_ok {
     my $self = shift;
-    return (exists($self->{policy}->{checkin})
-           && to_bool($self->{policy}->{checkin}));
+    return (exists($self->{institution}->{policy}->{checkin})
+           && to_bool($self->{institution}->{policy}->{checkin}));
 }
 sub status_update_ok {
     my $self = shift;
-    return (exists($self->{policy}->{status_update})
-           && to_bool($self->{policy}->{status_update}));
+    return (exists($self->{institution}->{policy}->{status_update})
+           && to_bool($self->{institution}->{policy}->{status_update}));
 }
 sub offline_ok {
     my $self = shift;
-    return (exists($self->{policy}->{offline})
-           && to_bool($self->{policy}->{offline}));
+    return (exists($self->{institution}->{policy}->{offline})
+           && to_bool($self->{institution}->{policy}->{offline}));
 }
 
 #
@@ -138,8 +140,9 @@ sub checkout {
                $circ->screen_msg("Patron Blocked");
     } elsif (!$item) {
                $circ->screen_msg("Invalid Item");
-    } elsif ($item->hold_queue && @{$item->hold_queue} && ! $item->barcode_is_borrowernumber($patron_id, $item->hold_queue->[0]->{borrowernumber})) {
-               $circ->screen_msg("Item on Hold for Another User");
+    # holds checked inside do_checkout
+    # } elsif ($item->hold_queue && @{$item->hold_queue} && ! $item->barcode_is_borrowernumber($patron_id, $item->hold_queue->[0]->{borrowernumber})) {
+       #       $circ->screen_msg("Item on Hold for Another User");
     } elsif ($item->{patron} && ($item->{patron} ne $patron_id)) {
        # I can't deal with this right now
                $circ->screen_msg("Item checked out to another patron");
@@ -154,7 +157,7 @@ sub checkout {
                        $item->{patron} = $patron_id;
                        $item->{due_date} = $circ->{due};
                        push(@{$patron->{items}}, $item_id);
-                       $circ->desensitize(!$item->magnetic);
+                       $circ->desensitize(!$item->magnetic_media);
 
                        syslog("LOG_DEBUG", "ILS::Checkout: patron %s has checked out %s",
                                $patron_id, join(', ', @{$patron->{items}}));
@@ -176,17 +179,27 @@ sub checkin {
     $circ = new ILS::Transaction::Checkin;
     # BEGIN TRANSACTION
     $circ->item($item = new ILS::Item $item_id);
-    
-    $circ->do_checkin();    
+
+    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;
@@ -205,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, $pay_type);
     $trans->ok(1);
 
     return $trans;
@@ -237,6 +254,10 @@ sub add_hold {
                return $trans;
        }
 
+    if ( $patron->holds_blocked_by_excessive_fees() ) {
+        $trans->screen_msg("Excessive fees blocking placement of hold.");
+    }
+
    if ($item->fee and $fee_ack ne 'Y') {
                $trans->screen_msg = "Fee required to place hold.";
                return $trans;
@@ -393,8 +414,12 @@ sub renew {
                my $j = 0;
                my $count = scalar @{$patron->{items}};
                foreach my $i (@{$patron->{items}}) {
-                       syslog("LOG_DEBUG", "checking item %s of %s: $item_id vs. %s", ++$j, $count, $i);
-                       if ($i eq $item_id) {
+            unless (defined $i->{barcode}) {    # FIXME: using data instead of objects may violate the abstraction layer
+                syslog("LOG_ERR", "No barcode for item %s of %s: $item_id", $j+1, $count);
+                next;
+            }
+            syslog("LOG_DEBUG", "checking item %s of %s: $item_id vs. %s", ++$j, $count, $i->{barcode});
+            if ($i->{barcode} eq $item_id) {
                                # We have it checked out
                                $item = new ILS::Item $item_id;
                                last;
@@ -405,26 +430,14 @@ sub renew {
     $trans->item($item);
 
     if (!defined($item)) {
-       # It's not checked out to $patron_id
-               $trans->screen_msg("Item not checked out to " . $patron->name);
-    } elsif (!$item->available($patron_id)) {
-               $trans->screen_msg("Item unavailable due to outstanding holds");
+               $trans->screen_msg("Item not checked out to " . $patron->name);     # not checked out to $patron_id
+        $trans->ok(0);
     } else {
-               $trans->renewal_ok(1);
-               $trans->desensitize(0); # It's already checked out
-               $trans->do_renew();
-               syslog("LOG_DEBUG", "done renew (%s): %s renews %s", $trans->renewal_ok(1),$patron_id,$item_id);
-
-#              if ($no_block eq 'Y') {
-#                      $item->{due_date} = $nb_due_date;
-#              } else {
-#                      $item->{due_date} = time + (14*24*60*60); # two weeks
-#              }
-#              if ($item_props) {
-#                      $item->{sip_item_properties} = $item_props;
-#              }
-#              $trans->ok(1);
-#              return $trans;
+        $trans->do_renew();
+        if ($trans->renewal_ok()) {
+            $item->{due_date} = $trans->{due};
+            $trans->desensitize(0);
+        }
     }
 
     return $trans;
@@ -439,11 +452,9 @@ sub renew_all {
 
     $trans->patron($patron = new ILS::Patron $patron_id);
     if (defined $patron) {
-       syslog("LOG_DEBUG", "ILS::renew_all: patron '%s': renew_ok: %s",
-              $patron->name, $patron->renew_ok);
+        syslog("LOG_DEBUG", "ILS::renew_all: patron '%s': renew_ok: %s", $patron->name, $patron->renew_ok);
     } else {
-       syslog("LOG_DEBUG", "ILS::renew_all: Invalid patron id: '%s'",
-              $patron_id);
+        syslog("LOG_DEBUG", "ILS::renew_all: Invalid patron id: '%s'", $patron_id);
     }
 
     if (!defined($patron)) {