Jonathan Druart
23dd6651f8
== Test plan == 1 - Have two patrons with userids and no cardnumber 2 - Note which of these has the higher borrower number 3 - Use the SIP cli emulator to connect and checkout a book to the patron with higher borrowernumber See example after 4 - Note the book may checkout to the wrong patron! 5 - Apply patch 6 - Checkout to both patrons via sip 7 - The patrons get the correct checkouts === SIP CLI emulator === ./misc/sip_cli_emulator.pl -a 127.0.0.1 -p 6001 -su term1 -sp term1 \ -l CPL --patron 23529001000463 -m checkout --item 39999000001259 translation: via the koha user term1, checkout item 39999000001259 to patron 23529001000463 Signed-off-by: Bouzid Fergani <bouzid.fergani@inlibro.com> Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net> Signed-off-by: Nick Clemens <nick@bywatersolutions.com> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
159 lines
5.7 KiB
Perl
159 lines
5.7 KiB
Perl
#
|
|
# An object to handle checkout status
|
|
#
|
|
|
|
package C4::SIP::ILS::Transaction::Checkout;
|
|
|
|
use warnings;
|
|
use strict;
|
|
|
|
use POSIX qw(strftime);
|
|
use C4::SIP::Sip qw(siplog);
|
|
use Data::Dumper;
|
|
use CGI qw ( -utf8 );
|
|
|
|
use C4::SIP::ILS::Transaction;
|
|
|
|
use C4::Context;
|
|
use C4::Circulation;
|
|
use C4::Members;
|
|
use C4::Reserves qw(ModReserveFill);
|
|
use C4::Debug;
|
|
use Koha::DateUtils;
|
|
|
|
use parent qw(C4::SIP::ILS::Transaction);
|
|
|
|
our $debug;
|
|
|
|
|
|
# Most fields are handled by the Transaction superclass
|
|
my %fields = (
|
|
security_inhibit => 0,
|
|
due => undef,
|
|
renew_ok => 0,
|
|
);
|
|
|
|
sub new {
|
|
my $class = shift;;
|
|
my $self = $class->SUPER::new();
|
|
foreach my $element (keys %fields) {
|
|
$self->{_permitted}->{$element} = $fields{$element};
|
|
}
|
|
@{$self}{keys %fields} = values %fields;
|
|
# $self->{'due'} = time() + (60*60*24*14); # two weeks hence
|
|
$debug and warn "new ILS::Transaction::Checkout : " . Dumper $self;
|
|
return bless $self, $class;
|
|
}
|
|
|
|
sub do_checkout {
|
|
my $self = shift;
|
|
siplog('LOG_DEBUG', "ILS::Transaction::Checkout performing checkout...");
|
|
my $shelf = $self->{item}->hold_shelf;
|
|
my $barcode = $self->{item}->id;
|
|
my $patron = Koha::Patrons->find($self->{patron}->{borrowernumber});
|
|
my $overridden_duedate; # usually passed as undef to AddIssue
|
|
$debug and warn "do_checkout borrower: . " . $patron->borrowernumber;
|
|
my ($issuingimpossible, $needsconfirmation) = _can_we_issue($patron, $barcode,
|
|
C4::Context->preference("AllowItemsOnHoldCheckoutSIP")
|
|
);
|
|
|
|
my $noerror=1; # If set to zero we block the issue
|
|
if (keys %{$issuingimpossible}) {
|
|
foreach (keys %{$issuingimpossible}) {
|
|
# do something here so we pass these errors
|
|
$self->screen_msg("Issue failed : $_");
|
|
$noerror = 0;
|
|
last;
|
|
}
|
|
} else {
|
|
foreach my $confirmation (keys %{$needsconfirmation}) {
|
|
if ($confirmation eq 'RENEW_ISSUE'){
|
|
$self->screen_msg("Item already checked out to you: renewing item.");
|
|
} elsif ($confirmation eq 'RESERVED' or $confirmation eq 'RESERVE_WAITING') {
|
|
my $x = $self->{item}->available($patron->borrowernumber);
|
|
if ($x) {
|
|
$self->screen_msg("Item was reserved for you.");
|
|
} else {
|
|
$self->screen_msg("Item is reserved for another patron upon return.");
|
|
$noerror = 0;
|
|
}
|
|
} elsif ($confirmation eq 'ISSUED_TO_ANOTHER') {
|
|
$self->screen_msg("Item already checked out to another patron. Please return item for check-in.");
|
|
$noerror = 0;
|
|
last;
|
|
} elsif ($confirmation eq 'DEBT') {
|
|
$self->screen_msg('Outstanding Fines block issue');
|
|
$noerror = 0;
|
|
last;
|
|
} elsif ($confirmation eq 'HIGHHOLDS') {
|
|
$overridden_duedate = $needsconfirmation->{$confirmation}->{returndate};
|
|
$self->screen_msg('Loan period reduced for high-demand item');
|
|
} elsif ($confirmation eq 'RENTALCHARGE') {
|
|
if ($self->{fee_ack} ne 'Y') {
|
|
$noerror = 0;
|
|
last;
|
|
}
|
|
} elsif ($confirmation eq 'PREVISSUE') {
|
|
$self->screen_msg("This item was previously checked out by you");
|
|
last;
|
|
} else {
|
|
# We've been returned a case other than those above
|
|
$self->screen_msg("Item cannot be issued: $confirmation");
|
|
$noerror = 0;
|
|
siplog('LOG_DEBUG', "Blocking checkout Reason:$confirmation");
|
|
last;
|
|
}
|
|
}
|
|
}
|
|
my $itemnumber = $self->{item}->{itemnumber};
|
|
foreach (@$shelf) {
|
|
$debug and warn sprintf( "shelf has (%s for %s). this is (%is, %s)", $_->{itemnumber}, $_->{borrowernumber}, $itemnumber, $patron->borrowernumber );
|
|
($_->{itemnumber} eq $itemnumber) or next; # skip it if not this item
|
|
($_->{borrowernumber} == $patron->borrowernumber) and last;
|
|
# if item was waiting for this patron, we're done. AddIssue takes care of the "W" hold.
|
|
$debug and warn "Item is on hold shelf for another patron.";
|
|
$self->screen_msg("Item is on hold shelf for another patron.");
|
|
$noerror = 0;
|
|
}
|
|
my ($fee, undef) = GetIssuingCharges($itemnumber, $patron->borrowernumber);
|
|
if ( $fee > 0 ) {
|
|
$self->{sip_fee_type} = '06';
|
|
$self->{fee_amount} = sprintf '%.2f', $fee;
|
|
if ($self->{fee_ack} eq 'N' ) {
|
|
$noerror = 0;
|
|
}
|
|
}
|
|
unless ($noerror) {
|
|
$debug and warn "cannot issue: " . Dumper($issuingimpossible) . "\n" . Dumper($needsconfirmation);
|
|
$self->ok(0);
|
|
return $self;
|
|
}
|
|
# can issue
|
|
$debug and warn sprintf("do_checkout: calling AddIssue(%s, %s, %s, 0)\n", $patron->borrowernumber, $barcode, $overridden_duedate)
|
|
. "w/ C4::Context->userenv: " . Dumper(C4::Context->userenv);
|
|
my $issue = AddIssue( $patron->unblessed, $barcode, $overridden_duedate, 0 );
|
|
$self->{due} = $self->duedatefromissue($issue, $itemnumber);
|
|
|
|
$self->ok(1);
|
|
return $self;
|
|
}
|
|
|
|
sub _can_we_issue {
|
|
my ( $patron, $barcode, $pref ) = @_;
|
|
|
|
my ( $issuingimpossible, $needsconfirmation, $alerts ) =
|
|
CanBookBeIssued( $patron, $barcode, undef, 0, $pref );
|
|
for my $href ( $issuingimpossible, $needsconfirmation ) {
|
|
|
|
# some data is returned using lc keys we only
|
|
foreach my $key ( keys %{$href} ) {
|
|
if ( $key =~ m/[^A-Z_]/ ) {
|
|
delete $href->{$key};
|
|
}
|
|
}
|
|
}
|
|
return ( $issuingimpossible, $needsconfirmation );
|
|
}
|
|
|
|
1;
|
|
__END__
|