getting closer, still needs much love
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 14 Jul 2006 15:31:54 +0000 (15:31 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 14 Jul 2006 15:31:54 +0000 (15:31 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@5005 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/SIP.pm
Open-ILS/src/perlmods/OpenILS/SIP/Item.pm
Open-ILS/src/perlmods/OpenILS/SIP/Patron.pm
Open-ILS/src/perlmods/OpenILS/SIP/Transaction.pm
Open-ILS/src/perlmods/OpenILS/SIP/Transaction/Checkin.pm
Open-ILS/src/perlmods/OpenILS/SIP/Transaction/Checkout.pm

index 91beb5e..53b767b 100644 (file)
@@ -12,27 +12,26 @@ use OpenILS::SIP::Patron;
 use OpenILS::SIP::Transaction;
 use OpenILS::SIP::Transaction::Checkout;
 use OpenILS::SIP::Transaction::Checkin;
-use OpenILS::SIP::Transaction::FeePayment;
-use OpenILS::SIP::Transaction::Hold;
+#use OpenILS::SIP::Transaction::FeePayment;
+#use OpenILS::SIP::Transaction::Hold;
 use OpenILS::SIP::Transaction::Renew;
-use OpenILS::SIP::Transaction::RenewAll;
+#use OpenILS::SIP::Transaction::RenewAll;
 
 
 use OpenSRF::System;
 use OpenILS::Utils::Fieldmapper;
 use OpenSRF::Utils::SettingsClient;
 use OpenILS::Application::AppUtils;
+my $U = 'OpenILS::Application::AppUtils';
 
 use Digest::MD5 qw(md5_hex);
 
-my $U = 'OpenILS::Application::AppUtils';
-
 # PUT ME IN THE CONFIG XXX
 my %supports = (
-               'magnetic media' => 1,
-               'security inhibit' => 0,
-               'offline operation' => 0
-               );
+       'magnetic media'                => 1,
+       'security inhibit'      => 0,
+       'offline operation'     => 0
+       );
 
 
 sub new {
@@ -129,8 +128,6 @@ sub check_inst_id {
 }
 
 
-
-
 # XXX by default, these should come from the config
 sub checkout_ok {
     return 1;
@@ -201,13 +198,13 @@ sub checkout {
 
                $xact->editor->commit;
                syslog("LOG_DEBUG", "OpenILS::Checkout: " .
-                       "patron %s checkout %s succeeded", $patron_id, $item_id);
+                       "patron %s checkout %s succeeded", $patron_id, $item_id);
 
        } else {
 
                $xact->editor->xact_rollback;
                syslog("LOG_DEBUG", "OpenILS::Checkout: " .
-                       "patron %s checkout %s FAILED, rolling back xact...", $patron_id, $item_id);
+                       "patron %s checkout %s FAILED, rolling back xact...", $patron_id, $item_id);
        }
 
        return $xact;
@@ -249,15 +246,13 @@ sub checkin {
 
 
 
-## If the ILS caches patron information, this lets it free
-## it up
-#sub end_patron_session {
-#    my ($self, $patron_id) = @_;
-#
-#    # success?, screen_msg, print_line
-#    return (1, 'Thank you for using OpenILS!', '');
-#}
-#
+## If the ILS caches patron information, this lets it free it up
+sub end_patron_session {
+    my ($self, $patron_id) = @_;
+    return (1, 'Thank you for using OpenILS!', '');
+}
+
+
 #sub pay_fee {
 #    my ($self, $patron_id, $patron_pwd, $fee_amt, $fee_type,
 #      $pay_type, $fee_id, $trans_id, $currency) = @_;
@@ -433,73 +428,59 @@ sub checkin {
 #
 #    return $trans;
 #}
-#
-#sub renew {
-#    my ($self, $patron_id, $patron_pwd, $item_id, $title_id,
-#      $no_block, $nb_due_date, $third_party,
-#      $item_props, $fee_ack) = @_;
-#    my ($patron, $item);
-#    my $trans;
-#
-#    $trans = new ILS::Transaction::Renew;
-#
-#    $trans->patron($patron = new ILS::Patron $patron_id);
-#    if (!$patron) {
-#      $trans->screen_msg("Invalid patron barcode.");
-#
-#      return $trans;
-#    } elsif (!$patron->renew_ok) {
-#
-#      $trans->screen_msg("Renewals not allowed.");
-#
-#      return $trans;
-#    }
-#
-#    if (defined($title_id)) {
-#      # renewing a title, rather than an item (sort of)
-#      # This is gross, but in a real ILS it would be better
-#      foreach my $i (@{$patron->{items}}) {
-#          $item = new ILS::Item $i;
-#          last if ($title_id eq $item->title_id);
-#          $item = undef;
-#      }
-#    } else {
-#      foreach my $i (@{$patron->{items}}) {
-#          if ($i == $item_id) {
-#              # We have it checked out
-#              $item = new ILS::Item $item_id;
-#              last;
-#          }
-#      }
-#    }
-#
-#    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 has outstanding holds");
-#    } else {
-#      $trans->item($item);
-#      $trans->renewal_ok(1);
-#
-#      $trans->desensitize(0); # It's already checked out
-#
-#      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);
-#      $trans->renewal_ok(1);
-#
-#      return $trans;
-#    }
-#
-#    return $trans;
-#}
+
+
+sub renew {
+       my ($self, $patron_id, $patron_pwd, $item_id, $title_id,
+               $no_block, $nb_due_date, $third_party, $item_props, $fee_ack) = @_;
+
+       my $trans = OpenILS::SIP::Transaction::Renew->new( authtoken => $self->{authtoken} );
+       $trans->patron(OpenILS::SIP::Patron->new($patron_id));
+       $trans->item(OpenILS::SIP::Item->new($item_id));
+
+       if(!$trans->patron) {
+               $trans->screen_msg("Invalid patron barcode.");
+               $trans->ok(0);
+               return $trans;
+       }
+
+       if(!$trans->patron->renew_ok) {
+               $trans->screen_msg("Renewals not allowed.");
+               $trans->ok(0);
+               return $trans;
+       }
+
+       if(!$trans->item) {
+               if( $title_id ) {
+                       $trans->screen_msg("Item Id renewal not supported.");
+               } else {
+                       $trans->screen_msg("Invalid item barcode.");
+               }
+               $trans->ok(0);
+               return $trans;
+       }
+
+       if(!$trans->item->{patron} or 
+                       $trans->item->{patron} ne $patron_id) {
+               $trans->screen_msg("Item not checked out to " . $trans->patron->name);
+               $trans->ok(0);
+               return $trans;
+       }
+
+       # Perform the renewal
+       $trans->do_renew();
+
+       $trans->desensitize(0); # It's already checked out
+       $trans->item->{due_date} = $nb_due_date if $no_block eq 'Y';
+       $trans->item->{sip_item_properties} = $item_props if $item_props;
+
+       return $trans;
+}
+
+
+
+
+
 #
 #sub renew_all {
 #    my ($self, $patron_id, $patron_pwd, $fee_ack) = @_;
index f7e02be..199bda1 100644 (file)
@@ -70,8 +70,11 @@ sub new {
                        ]
                );
 
-               $self->{patron} = $user->card->barcode if $user;
+               my $bc = ($user) ? $user->card->barcode : "";
+               $self->{patron} = $bc;
                $self->{patron_object} = $user;
+
+               syslog('LOG_DEBUG', "Open circulation exists on $item_id : user = $bc");
        }
 
        $self->{id}                     = $item_id;
index 6487830..418316d 100644 (file)
@@ -79,7 +79,8 @@ sub new {
        $self->{id}                     = $patron_id;
        $self->{editor} = $e;
 
-       syslog("LOG_DEBUG", "new OpenILS Patron(%s): found patron '%s'", $patron_id);
+       syslog("LOG_DEBUG", "new OpenILS Patron(%s): found patron : barred=%s, card:active=%s", 
+               $patron_id, $self->{user}->barred, $self->{user}->card->active );
 
        bless $self, $type;
        return $self;
@@ -149,14 +150,13 @@ sub language {
 sub charge_ok {
     my $self = shift;
         my $u = $self->{user};
-        return ($u->barred ne 't') and ($u->card->active ne 'f');
+        return (($u->barred eq 'f') and ($u->card->active eq 't'));
 }
 
 # How much more detail do we need to check here?
 sub renew_ok {
     my $self = shift;
-        my $u = $self->{user};
-        return ($u->barred ne 'f') and ($u->card->active ne 'f');
+        return $self->charge_ok;
 }
 
 sub recall_ok {
@@ -189,7 +189,7 @@ sub check_password {
 
 sub currency {
        my $self = shift;
-       return 'usd';
+       return 'USD';
 }
 
 
@@ -369,9 +369,45 @@ sub unavail_holds {
 }
 
 sub block {
-    my ($self, $card_retained, $blocked_card_msg) = @_;
-        # Mark the card as inactive, set patron alert
-    return $self;
+       my ($self, $card_retained, $blocked_card_msg) = @_;
+
+       my $u = $self->{user};
+       my $e = $self->{editor};
+
+       syslog('LOG_INFO', "Blocking user %s", $u->card->barcode );
+
+#      $self->{editor} = $e = 
+#              OpenILS::Utils::CStoreEditor->new(xact =>1) unless $e->{xact};
+
+       if(!$e->{xact}) { $e->reset; $e->{xact} = 1; }
+
+       return $self if $u->card->active eq 'f';
+
+       $u->card->active('f');
+       if( ! $e->update_actor_card($u->card) ) {
+               syslog('LOG_ERR', "Block card update failed: %s", $e->event->{textcode});
+               $e->xact_rollback;
+               return $self;
+       }
+
+       # retrieve the un-fleshed user object for update
+       $u = $e->retrieve_actor_user($u->id);
+       my $note = $u->alert_message || "";
+       $note = "CARD BLOCKED BY SELF-CHECK MACHINE\n$note"; # XXX Config option
+
+       $u->alert_message($note);
+
+       if( ! $e->update_actor_user($u) ) {
+               syslog('LOG_ERR', "Block: patron alert update failed: %s", $e->event->{textcode});
+               $e->xact_rollback;
+               return $self;
+       }
+
+       # stay in synch
+       $self->{user}->alert_message( $note );
+
+       $e->finish; # commits and resets
+       return $self;
 }
 
 # Testing purposes only
index 6aabd43..1d76939 100644 (file)
@@ -79,15 +79,7 @@ our $AUTOLOAD;
 sub new {
     my( $class, %args ) = @_;
 
-       use Data::Dumper;
-       warn 'ARGS = ' .  Dumper(\@_);
-
-       warn "AUTH = " . $args{authtoken} . "\n";
-
-    my $self = {
-               _permitted => \%fields,
-               %fields,
-    };
+    my $self = { _permitted => \%fields, %fields };
 
        bless $self, $class;
        $self->authtoken($args{authtoken});
index e349879..5744046 100644 (file)
@@ -51,16 +51,17 @@ sub do_checkin {
                'open-ils.circ.checkin', 
                $self->{authtoken}, { barcode => $self->{item}->id } );
 
-
-       my $circ = $resp->{payload}->{circ};
-
-       if(!$circ) {
-               warn 'CHECKIN: ' . Dumper($resp) . "\n";
+       if( my $code = $U->event_code($resp) ) {
+               my $txt = $resp->{textcode};
+               syslog('LOG_INFO', "Checkin failed with event $code : $txt");
                $self->ok(0);
                return 0;
        }
 
-       $self->{item}->{patron} = $self->editor->search_actor_card(
+       my $circ = $resp->{payload}->{circ};
+
+       $self->{item}->{patron} = 
+               $self->editor->search_actor_card(
                { usr => $circ->usr, active => 't' } )->[0]->barcode;
 
        $self->ok(1);
index 0cefd22..b7b5c06 100644 (file)
@@ -29,9 +29,6 @@ my %fields = (
 sub new {
         my $class = shift;
 
-        use Data::Dumper;
-        warn 'ARGS = ' .  Dumper(\@_);
-
     my $self = $class->SUPER::new(@_);
 
     my $element;
@@ -55,6 +52,8 @@ sub do_checkout {
        my $self = shift;
        syslog('LOG_DEBUG', "OpenILS: performing checkout...");
 
+       $self->ok(0); 
+
        my $args = { 
                barcode => $self->{item}->id, 
                patron_barcode => $self->{patron}->id
@@ -65,17 +64,31 @@ sub do_checkout {
                'open-ils.circ.checkout.permit', 
                $self->{authtoken}, $args );
 
+       if( ref($resp) eq 'ARRAY' ) {
+               my @e;
+               push( @e, $_->{textcode} ) for @$resp;
+               syslog('LOG_INFO', "Checkout permit failed with events: @e");
+               return 0;
+       }
+
+       if( my $code = $U->event_code($resp) ) {
+               my $txt = $resp->{textcode};
+               syslog('LOG_INFO', "Checkout permit failed with event $code : $txt");
+               return 0; 
+       }
+
        my $key;
 
-       if( ref($resp) eq 'HASH' and $key = $resp->{payload} ) {
+       if( $key = $resp->{payload} ) {
                syslog('LOG_INFO', "OpenILS: circ permit key => $key");
 
        } else {
-               syslog('LOG_INFO', "OpenILS: Circ permit failed :\n" . Dumper($resp) );
-               $self->ok(0);
+               syslog('LOG_WARN', "OpenILS: Circ permit failed :\n" . Dumper($resp) );
                return 0;
        }
 
+       # Now do the actual checkout
+
        $args = { 
                permit_key              => $key, 
                patron_barcode => $self->{patron}->id, 
@@ -88,18 +101,19 @@ sub do_checkout {
 
        # XXX Check for events
        if( $resp ) {
-               syslog('LOG_INFO', "OpenILS: Checkout succeeded");
-               my $evt = $resp->{ilsevent};
-               my $circ = $resp->{payload}->{circ};
 
-               if(!$circ or $evt ne 0) { 
-                       $self->ok(0); 
-                       warn 'CHECKOUT RESPONSE: ' .  Dumper($resp) . "\n";
+               if( my $code = $U->event_code($resp) ) {
+                       my $txt = $resp->{textcode};
+                       syslog('LOG_INFO', "Checkout failed with event $code : $txt");
                        return 0; 
                }
 
+               syslog('LOG_INFO', "OpenILS: Checkout succeeded");
+
+               my $circ = $resp->{payload}->{circ};
                $self->{'due'} = $circ->due_date;
                $self->ok(1);
+
                return 1;
        }