Bug 14591: (QA follow-up) Fix call to AddReturn for SIP
[koha.git] / C4 / SIP / ILS / Transaction / Checkin.pm
index bc1c433..0303a47 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,8 @@ sub do_checkin {
     my $self = shift;
     my $branch = shift;
     my $return_date = shift;
+    my $cv_triggers_alert = shift;
+
     if (!$branch) {
         $branch = 'SIP2';
     }
@@ -65,14 +68,16 @@ sub do_checkin {
                    . substr( $return_date, 16, 2 );
 
     $debug and warn "do_checkin() calling AddReturn($barcode, $branch)";
-    my ($return, $messages, $iteminformation, $borrower) = AddReturn($barcode, $branch, undef, undef, $return_date);
+    my ($return, $messages, $issue, $borrower) = AddReturn($barcode, $branch, undef, dt_from_string($return_date));
     $self->alert(!$return);
-    # ignoring messages: NotIssued, IsPermanent, WasLost, WasTransfered
+    # 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');
     }
@@ -80,19 +85,19 @@ sub do_checkin {
         $self->alert_type('99');
     }
     if ($messages->{Wrongbranch}) {
-        $self->destination_loc($messages->{Wrongbranch}->{Rightbranch});
+        $self->{item}->destination_loc($messages->{Wrongbranch}->{Rightbranch});
         $self->alert_type('04');            # send to other branch
     }
     if ($messages->{WrongTransfer}) {
-        $self->destination_loc($messages->{WrongTransfer});
+        $self->{item}->destination_loc($messages->{WrongTransfer});
         $self->alert_type('04');            # send to other branch
     }
     if ($messages->{NeedsTransfer}) {
-        $self->destination_loc($iteminformation->{homebranch});
+        $self->{item}->destination_loc($messages->{NeedsTransfer});
         $self->alert_type('04');            # send to other branch
     }
     if ($messages->{WasTransfered}) { # set into transit so tell unit
-        $self->destination_loc($iteminformation->{homebranch});
+        $self->{item}->destination_loc($issue->item->homebranch);
         $self->alert_type('04');            # send to other branch
     }
     if ($messages->{ResFound}) {
@@ -100,12 +105,12 @@ sub do_checkin {
         if ($branch eq $messages->{ResFound}->{branchcode}) {
             $self->alert_type('01');
             ModReserveAffect( $messages->{ResFound}->{itemnumber},
-                $messages->{ResFound}->{borrowernumber}, 0);
+                $messages->{ResFound}->{borrowernumber}, 0, $messages->{ResFound}->{reserve_id});
 
         } else {
             $self->alert_type('02');
             ModReserveAffect( $messages->{ResFound}->{itemnumber},
-                $messages->{ResFound}->{borrowernumber}, 1);
+                $messages->{ResFound}->{borrowernumber}, 1, $messages->{ResFound}->{reserve_id});
             ModItemTransfer( $messages->{ResFound}->{itemnumber},
                 $branch,
                 $messages->{ResFound}->{branchcode}
@@ -115,7 +120,14 @@ 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
+
+    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);
 }