Bug 23057: Update do_checkin
[koha-equinox.git] / C4 / SIP / ILS / Transaction / Checkin.pm
index a35009f..eed26c1 100644 (file)
@@ -12,9 +12,10 @@ use strict;
 use C4::SIP::ILS::Transaction;
 
 use C4::Circulation;
-use C4::Reserves qw( ModReserveAffect );
-use C4::Items qw( ModItemTransfer );
 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);
 
@@ -47,6 +48,9 @@ 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';
     }
@@ -65,9 +69,13 @@ sub do_checkin {
                    . substr( $return_date, 16, 2 );
 
     $debug and warn "do_checkin() calling AddReturn($barcode, $branch)";
-    my ($return, $messages, $issue, $borrower) = AddReturn($barcode, $branch, undef, undef, $return_date);
-    $self->alert(!$return);
-    # ignoring messages: NotIssued, WasLost, WasTransfered
+    my ($return, $messages, $issue, $borrower) = AddReturn($barcode, $branch, undef, dt_from_string($return_date));
+
+    if ( $checked_in_ok ) {
+        delete $messages->{NotIssued};
+        delete $messages->{LocalUse};
+        $return = 1 unless keys %$messages;
+    }
 
     # biblionumber, biblioitemnumber, itemnumber
     # borrowernumber, reservedate, branchcode
@@ -81,6 +89,9 @@ sub do_checkin {
     if ($messages->{withdrawn}) {
         $self->alert_type('99');
     }
+    if ($messages->{ReturnOfLostItemBlocked}) {
+        $self->alert_type('99');
+    }
     if ($messages->{Wrongbranch}) {
         $self->{item}->destination_loc($messages->{Wrongbranch}->{Rightbranch});
         $self->alert_type('04');            # send to other branch
@@ -117,8 +128,18 @@ sub do_checkin {
         $self->{item}->hold_patron_id( $messages->{ResFound}->{borrowernumber} );
         $self->{item}->destination_loc( $messages->{ResFound}->{branchcode} );
     }
-    $self->alert(1) if defined $self->alert_type;  # alert_type could be "00", hypothetically
+    # ignoring messages: NotIssued, WasLost, WasTransfered
+
+    if ($cv_triggers_alert) {
+        $self->alert( defined $self->alert_type ); # Overwrites existing alert value, should set to 0 if there is no alert type
+    }
+    else {
+        $self->alert( !$return || defined $self->alert_type );
+    }
+
     $self->ok($return);
+
+    return { messages => $messages };
 }
 
 sub resensitize {