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 {
}
-
-
# XXX by default, these should come from the config
sub checkout_ok {
return 1;
$xact->editor->commit;
syslog("LOG_DEBUG", "OpenILS::Checkout: " .
- "patron %s checke out %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 checke out %s FAILED, rolling back xact...", $patron_id, $item_id);
+ "patron %s checkout %s FAILED, rolling back xact...", $patron_id, $item_id);
}
return $xact;
-## 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) = @_;
#
# 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) = @_;
$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;
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 {
sub currency {
my $self = shift;
- return 'usd';
+ return 'USD';
}
}
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
sub new {
my $class = shift;
- use Data::Dumper;
- warn 'ARGS = ' . Dumper(\@_);
-
my $self = $class->SUPER::new(@_);
my $element;
my $self = shift;
syslog('LOG_DEBUG', "OpenILS: performing checkout...");
+ $self->ok(0);
+
my $args = {
barcode => $self->{item}->id,
patron_barcode => $self->{patron}->id
'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,
# 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;
}