Koha/C4/SIP/ILS/Transaction/Checkin.pm
David Cook 97af85525f
Bug 23057: If checked_in_ok is set and item is not checked out, alert flag is supressed for *any* reason
This patch fixes a bug from Bug 15221 and hopefully also makes it so that the alert flag
is suppressed when checked_in_ok is set and an item is not checked out.

To test:

0) Create patron in web interface with a cardnumber and userid of "staff" with a password
that matches the account in SIPconfig.xml. Also set their branch to CPL
(also matching SIPconfig.xml).
1) Create an item with a barcode of 'test'
2) Choose a patron to check out to and record their borrowernumber

In one terminal:
3) cd to your git directory (e.g. /home/koha/koha)
4) perl ./C4/SIP/SIPServer.pm ~/koha-dev/etc/SIPconfig.xml

In another terminal:
5) cd to your git directory (e.g. /home/koha/koha)
6) perl ./misc/sip_cli_emulator.pl -l CPL -su staff -sp <password> --port=6001 --address=localhost --item test -m checkin --patron <borrowernumber>
NOTE: You need to replace <borrowernumber> with the borrowernumber from Step 2, and <password> with the password from Step 0.

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Matha Fuerst <mfuerst@hmcpl.org>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
2019-07-16 14:39:49 +01:00

160 lines
4.8 KiB
Perl

#
# An object to handle checkin status
#
package C4::SIP::ILS::Transaction::Checkin;
use warnings;
use strict;
# use POSIX qw(strftime);
use C4::SIP::ILS::Transaction;
use C4::Circulation;
use C4::Debug;
use C4::Items qw( ModItemTransfer );
use C4::Reserves qw( ModReserveAffect );
use Koha::DateUtils qw( dt_from_string );
use parent qw(C4::SIP::ILS::Transaction);
my %fields = (
magnetic => 0,
sort_bin => undef,
collection_code => undef,
# 3M extensions:
call_number => undef,
destination_loc => undef,
alert_type => undef, # 00,01,02,03,04 or 99
hold_patron_id => undef,
hold_patron_name => "",
hold => undef,
);
sub new {
my $class = shift;
my $self = $class->SUPER::new(); # start with an ILS::Transaction object
foreach (keys %fields) {
$self->{_permitted}->{$_} = $fields{$_}; # overlaying _permitted
}
@{$self}{keys %fields} = values %fields; # copying defaults into object
return bless $self, $class;
}
sub do_checkin {
my $self = shift;
my $branch = shift;
my $return_date = shift;
my $cv_triggers_alert = shift;
my $checked_in_ok = shift;
if (!$branch) {
$branch = 'SIP2';
}
my $barcode = $self->{item}->id;
$return_date = substr( $return_date, 0, 4 )
. '-'
. substr( $return_date, 4, 2 )
. '-'
. substr( $return_date, 6, 2 )
. q{ }
. substr( $return_date, 12, 2 )
. ':'
. substr( $return_date, 14, 2 )
. ':'
. substr( $return_date, 16, 2 );
$debug and warn "do_checkin() calling AddReturn($barcode, $branch)";
my ($return, $messages, $issue, $borrower) = AddReturn($barcode, $branch, undef, dt_from_string($return_date));
if ($checked_in_ok){
$debug and warn 'not raising alert when AddReturn() does not return a value for $return due to $checked_in_ok being set to true';
}
else {
$self->alert(!$return);
}
# ignoring messages: NotIssued, WasLost, WasTransfered
# biblionumber, biblioitemnumber, itemnumber
# borrowernumber, reservedate, branchcode
# cancellationdate, found, reservenotes, priority, timestamp
if( $messages->{DataCorrupted} ) {
$self->alert_type('98');
}
if ($messages->{BadBarcode}) {
$self->alert_type('99');
}
if ($messages->{withdrawn}) {
$self->alert_type('99');
}
if ($messages->{Wrongbranch}) {
$self->{item}->destination_loc($messages->{Wrongbranch}->{Rightbranch});
$self->alert_type('04'); # send to other branch
}
if ($messages->{WrongTransfer}) {
$self->{item}->destination_loc($messages->{WrongTransfer});
$self->alert_type('04'); # send to other branch
}
if ($messages->{NeedsTransfer}) {
$self->{item}->destination_loc($messages->{NeedsTransfer});
$self->alert_type('04'); # send to other branch
}
if ($messages->{WasTransfered}) { # set into transit so tell unit
$self->{item}->destination_loc($issue->item->homebranch);
$self->alert_type('04'); # send to other branch
}
if ($messages->{ResFound}) {
$self->hold($messages->{ResFound});
if ($branch eq $messages->{ResFound}->{branchcode}) {
$self->alert_type('01');
ModReserveAffect( $messages->{ResFound}->{itemnumber},
$messages->{ResFound}->{borrowernumber}, 0, $messages->{ResFound}->{reserve_id});
} else {
$self->alert_type('02');
ModReserveAffect( $messages->{ResFound}->{itemnumber},
$messages->{ResFound}->{borrowernumber}, 1, $messages->{ResFound}->{reserve_id});
ModItemTransfer( $messages->{ResFound}->{itemnumber},
$branch,
$messages->{ResFound}->{branchcode}
);
}
$self->{item}->hold_patron_id( $messages->{ResFound}->{borrowernumber} );
$self->{item}->destination_loc( $messages->{ResFound}->{branchcode} );
}
my $alert = defined $self->alert_type;
if ( $cv_triggers_alert ) {
$self->alert($alert); # Overwrites existing alert value, should set to 0 if there is no alert type
} else {
$self->alert($alert) if $alert; # Doesn't affect alert value unless an alert type is set
}
$self->ok($return);
return { messages => $messages };
}
sub resensitize {
my $self = shift;
unless ($self->{item}) {
warn "resensitize(): no item found in object to resensitize";
return;
}
return !$self->{item}->magnetic_media;
}
sub patron_id {
my $self = shift;
unless ($self->{patron}) {
warn "patron_id(): no patron found in object";
return;
}
return $self->{patron}->id;
}
1;