From a66649cbe43576080c0774e3f0940ddaf821d5c9 Mon Sep 17 00:00:00 2001
From: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Date: Wed, 11 Mar 2020 13:01:52 +0100
Subject: [PATCH] Bug 24800: Handle inexistent return date on self checking

See bug 24800 comment 0 for a description of the problem.

We do not want the SIP server to crash if it receives a checkin request
with a return date that is not given.

The option this patch chose is to parse it only if provided.
---
 C4/SIP/ILS/Transaction/Checkin.pm | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/C4/SIP/ILS/Transaction/Checkin.pm b/C4/SIP/ILS/Transaction/Checkin.pm
index f0e8bbdf49..40dee0ccc5 100644
--- a/C4/SIP/ILS/Transaction/Checkin.pm
+++ b/C4/SIP/ILS/Transaction/Checkin.pm
@@ -56,20 +56,23 @@ sub do_checkin {
     }
     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 );
+    if ( $return_date ) {
+        $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 );
+        $return_date = dt_from_string($return_date);
+    }
 
     $debug and warn "do_checkin() calling AddReturn($barcode, $branch)";
-    my ($return, $messages, $issue, $borrower) = AddReturn($barcode, $branch, undef, dt_from_string($return_date));
+    my ($return, $messages, $issue, $borrower) = AddReturn($barcode, $branch, undef, $return_date);
 
     if ( $checked_in_ok ) {
         delete $messages->{NotIssued};
-- 
2.20.1