# ILS.pm: Koha ILS interface module
#
-package ILS;
+package C4::SIP::ILS;
use warnings;
use strict;
use Sys::Syslog qw(syslog);
-
-use ILS::Item;
-use ILS::Patron;
-use ILS::Transaction;
-use ILS::Transaction::Checkout;
-use ILS::Transaction::Checkin;
-use ILS::Transaction::FeePayment;
-use ILS::Transaction::Hold;
-use ILS::Transaction::Renew;
-use ILS::Transaction::RenewAll;
+use Data::Dumper;
+
+use C4::SIP::ILS::Item;
+use C4::SIP::ILS::Patron;
+use C4::SIP::ILS::Transaction;
+use C4::SIP::ILS::Transaction::Checkout;
+use C4::SIP::ILS::Transaction::Checkin;
+use C4::SIP::ILS::Transaction::FeePayment;
+use C4::SIP::ILS::Transaction::Hold;
+use C4::SIP::ILS::Transaction::Renew;
+use C4::SIP::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) = @_;
my $type = ref($class) || $class;
my $self = {};
- use Data::Dumper;
$debug and warn "new ILS: INSTITUTION: " . Dumper($institution);
syslog("LOG_DEBUG", "new ILS '%s'", $institution->{id});
$self->{institution} = $institution;
sub find_patron {
my $self = shift;
$debug and warn "ILS: finding patron";
- return ILS::Patron->new(@_);
+ return C4::SIP::ILS::Patron->new(@_);
}
sub find_item {
my $self = shift;
$debug and warn "ILS: finding item";
- return ILS::Item->new(@_);
+ return C4::SIP::ILS::Item->new(@_);
}
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};
}
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
}
}
# the response.
#
sub checkout {
- my ($self, $patron_id, $item_id, $sc_renew) = @_;
+ my ($self, $patron_id, $item_id, $sc_renew, $fee_ack) = @_;
my ($patron, $item, $circ);
- $circ = new ILS::Transaction::Checkout;
+ $circ = C4::SIP::ILS::Transaction::Checkout->new();
# BEGIN TRANSACTION
- $circ->patron($patron = new ILS::Patron $patron_id);
- $circ->item($item = new ILS::Item $item_id);
+ $circ->patron($patron = C4::SIP::ILS::Patron->new( $patron_id));
+ $circ->item($item = C4::SIP::ILS::Item->new( $item_id));
+ if ($fee_ack) {
+ $circ->fee_ack($fee_ack);
+ }
if (!$patron) {
$circ->screen_msg("Invalid Patron");
# 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
+ } elsif ($item->{patron} && !_ci_cardnumber_cmp($item->{patron},$patron_id)) {
$circ->screen_msg("Item checked out to another patron");
} else {
$circ->do_checkout();
$debug and warn "circ is ok";
# If the item is already associated with this patron, then
# we're renewing it.
- $circ->renew_ok($item->{patron} && ($item->{patron} eq $patron_id));
+ $circ->renew_ok($item->{patron} && _ci_cardnumber_cmp($item->{patron}, $patron_id));
$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}}));
return $circ;
}
+sub _ci_cardnumber_cmp {
+ my ( $s1, $s2) = @_;
+ # As the database is case insensitive we need to normalize two strings
+ # before comparing them
+ return ( uc($s1) eq uc($s2) );
+}
+
+# wrapper which allows above to be called for testing
+
+sub test_cardnumber_compare {
+ my ($self, $str1, $str2) = @_;
+ return _ci_cardnumber_cmp($str1, $str2);
+}
+
sub checkin {
- my ($self, $item_id, $trans_date, $return_date,
- $current_loc, $item_props, $cancel) = @_;
- my ($patron, $item, $circ);
+ my ( $self, $item_id, $trans_date, $return_date, $current_loc, $item_props, $cancel, $checked_in_ok ) = @_;
+ my ( $patron, $item, $circ );
+
+ $circ = C4::SIP::ILS::Transaction::Checkin->new();
- $circ = new ILS::Transaction::Checkin;
# BEGIN TRANSACTION
- $circ->item($item = new ILS::Item $item_id);
-
- $circ->do_checkin();
- # 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}} ];
+ $circ->item( $item = C4::SIP::ILS::Item->new($item_id) );
+
+ if ($item) {
+ $circ->do_checkin( $current_loc, $return_date );
}
+ 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
+ # or it was not checked out but the checked_in_ok flag was set
+ $circ->ok( ( $checked_in_ok && $item ) || ( $item && $item->{patron} ) );
+ syslog("LOG_DEBUG", "C4::SIP::ILS::checkin - using checked_in_ok") if $checked_in_ok;
+
+ if ( !defined( $item->{patron} ) ) {
+ $circ->screen_msg("Item not checked out") unless $checked_in_ok;
+ syslog("LOG_DEBUG", "C4::SIP::ILS::checkin - item not checked out");
+ }
+ else {
+ if ( $circ->ok ) {
+ $circ->patron( $patron = C4::SIP::ILS::Patron->new( $item->{patron} ) );
+ delete $item->{patron};
+ delete $item->{due_date};
+ $patron->{items} = [ grep { $_ ne $item_id } @{ $patron->{items} } ];
+ }
+ }
+
# END TRANSACTION
return $circ;
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 = C4::SIP::ILS::Transaction::FeePayment->new();
- $patron = new ILS::Patron $patron_id;
$trans->transaction_id($trans_id);
- $trans->patron($patron);
+ my $patron;
+ $trans->patron($patron = C4::SIP::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;
$expiry_date, $pickup_location, $hold_type, $fee_ack) = @_;
my ($patron, $item);
- my $trans = new ILS::Transaction::Hold;
+ my $trans = C4::SIP::ILS::Transaction::Hold->new();
- $patron = new ILS::Patron $patron_id;
+ $patron = C4::SIP::ILS::Patron->new( $patron_id);
if (!$patron
|| (defined($patron_pwd) && !$patron->check_password($patron_pwd))) {
$trans->screen_msg("Invalid Patron.");
return $trans;
}
- unless ($item = new ILS::Item ($item_id || $title_id)) {
+ unless ($item = C4::SIP::ILS::Item->new($item_id || $title_id)) {
$trans->screen_msg("No such item.");
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;
my ($self, $patron_id, $patron_pwd, $item_id, $title_id) = @_;
my ($patron, $item, $hold);
- my $trans = new ILS::Transaction::Hold;
+ my $trans = C4::SIP::ILS::Transaction::Hold->new();
- $patron = new ILS::Patron $patron_id;
+ $patron = C4::SIP::ILS::Patron->new( $patron_id );
if (!$patron) {
$trans->screen_msg("Invalid patron barcode.");
return $trans;
return $trans;
}
- unless ($item = new ILS::Item ($item_id || $title_id)) {
+ unless ($item = C4::SIP::ILS::Item->new($item_id || $title_id)) {
$trans->screen_msg("No such item.");
return $trans;
}
my $hold;
my $trans;
- $trans = new ILS::Transaction::Hold;
+ $trans = C4::SIP::ILS::Transaction::Hold->new();
# BEGIN TRANSACTION
- $patron = new ILS::Patron $patron_id;
+ $patron = C4::SIP::ILS::Patron->new( $patron_id );
unless ($patron) {
$trans->screen_msg("Invalid patron barcode: '$patron_id'.");
return $trans;
# $trans->ok(1);
$trans->screen_msg("Hold updated.");
$trans->patron($patron);
- $trans->item(new ILS::Item $hold->{item_id});
+ $trans->item(C4::SIP::ILS::Item->new( $hold->{item_id}));
last;
}
}
my ($patron, $item);
my $trans;
- $trans = new ILS::Transaction::Renew;
- $trans->patron($patron = new ILS::Patron $patron_id);
+ $trans = C4::SIP::ILS::Transaction::Renew->new();
+ $trans->patron($patron = C4::SIP::ILS::Patron->new( $patron_id ));
if (!$patron) {
$trans->screen_msg("Invalid patron barcode.");
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;
+ $item = C4::SIP::ILS::Item->new( $item_id );
last;
}
}
$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;
my ($patron, $item_id);
my $trans;
- $trans = new ILS::Transaction::RenewAll;
+ $trans = C4::SIP::ILS::Transaction::RenewAll->new();
- $trans->patron($patron = new ILS::Patron $patron_id);
+ $trans->patron($patron = C4::SIP::ILS::Patron->new( $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)) {