| Lines 45-50
          use Koha::DateUtils;
      
      
        Link Here | 
        
          | 45 | use Koha::Calendar; | 45 | use Koha::Calendar; | 
        
          | 46 | use Koha::IssuingRules; | 46 | use Koha::IssuingRules; | 
        
          | 47 | use Koha::Items; | 47 | use Koha::Items; | 
            
              |  |  | 48 | use Koha::Checkouts; | 
            
              | 49 | use Koha::OldIssues; | 
        
          | 48 | use Koha::Patrons; | 50 | use Koha::Patrons; | 
        
          | 49 | use Koha::Patron::Debarments; | 51 | use Koha::Patron::Debarments; | 
        
          | 50 | use Koha::Database; | 52 | use Koha::Database; | 
  
    | Lines 1929-1949
          sub AddReturn {
      
      
        Link Here | 
        
          | 1929 |         } | 1931 |         } | 
        
          | 1930 |  | 1932 |  | 
        
          | 1931 |         if ($borrowernumber) { | 1933 |         if ($borrowernumber) { | 
            
              | 1932 |             if ( ( C4::Context->preference('CalculateFinesOnReturn') && $issue->{'overdue'} ) || $return_date ) { |  |  | 
            
              | 1933 |                 _CalculateAndUpdateFine( { issue => $issue, item => $item, borrower => $borrower, return_date => $return_date } ); | 
            
              | 1934 |             } | 
            
              | 1935 |  | 
        
          | 1936 |             eval { | 1934 |             eval { | 
        
          | 1937 |                 MarkIssueReturned( $borrowernumber, $item->{'itemnumber'}, | 1935 |                 MarkIssueReturned( $borrowernumber, $item->{'itemnumber'}, | 
        
          | 1938 |                     $circControlBranch, $return_date, $borrower->{'privacy'} ); | 1936 |                     $circControlBranch, $return_date, $borrower->{'privacy'} ); | 
        
          | 1939 |             }; | 1937 |             }; | 
          
            
              | 1940 |             if ( $@ ) { | 1938 |             unless ( $@ ) { | 
            
              | 1941 |                 $messages->{'Wrongbranch'} = { | 1939 |                 if ( ( C4::Context->preference('CalculateFinesOnReturn') && $issue->{'overdue'} ) || $return_date ) { | 
            
              | 1942 |                     Wrongbranch => $branch, | 1940 |                     _CalculateAndUpdateFine( { issue => $issue, item => $item, borrower => $borrower, return_date => $return_date } ); | 
            
              | 1943 |                     Rightbranch => $message | 1941 |                 } | 
            
              | 1944 |                 }; | 1942 |             } else { | 
            
              | 1945 |                 carp $@; | 1943 |                 carp "The checkin for the following issue failed, Please go to the about page, section 'data corrupted' to know how to fix this problem ($@)" . Dumper( $issue ); | 
            
              | 1946 |                 return ( 0, { WasReturned => 0 }, $issue, $borrower ); | 1944 |  | 
            
              |  |  | 1945 |                 return ( 0, { WasReturned => 0, DataCorrupted => 1 }, $issue, $borrower ); | 
        
          | 1947 |             } | 1946 |             } | 
        
          | 1948 |  | 1947 |  | 
        
          | 1949 |             # FIXME is the "= 1" right?  This could be the borrower hash. | 1948 |             # FIXME is the "= 1" right?  This could be the borrower hash. | 
  
    | Lines 2167-2187
          sub MarkIssueReturned {
      
      
        Link Here | 
        
          | 2167 |  | 2166 |  | 
        
          | 2168 |     # FIXME Improve the return value and handle it from callers | 2167 |     # FIXME Improve the return value and handle it from callers | 
        
          | 2169 |     $schema->txn_do(sub { | 2168 |     $schema->txn_do(sub { | 
            
              |  |  | 2169 |  | 
            
              | 2170 |         # Update the returndate | 
        
          | 2170 |         $dbh->do( $query, undef, @bind ); | 2171 |         $dbh->do( $query, undef, @bind ); | 
        
          | 2171 |  | 2172 |  | 
          
            
              | 2172 |         my $id_already_exists = $dbh->selectrow_array( | 2173 |         # Retrieve the issue | 
            
              | 2173 |             q|SELECT COUNT(*) FROM old_issues WHERE issue_id = ?|, | 2174 |         my $issue = Koha::Checkouts->find( $issue_id ); # FIXME should be fetched earlier | 
            
              | 2174 |             undef, $issue_id |  |  | 
            
              | 2175 |         ); | 
        
          | 2176 |  | 2175 |  | 
          
            
              | 2177 |         if ( $id_already_exists ) { | 2176 |         # Create the old_issues entry | 
            
              | 2178 |             my $new_issue_id = $dbh->selectrow_array(q|SELECT MAX(issue_id)+1 FROM old_issues|); | 2177 |         my $old_checkout = Koha::OldIssue->new($issue->unblessed)->store; | 
            
              | 2179 |             $dbh->do( |  |  | 
            
              | 2180 |                 q|UPDATE issues SET issue_id = ? WHERE issue_id = ?|, | 
            
              | 2181 |                 undef, $new_issue_id, $issue_id | 
            
              | 2182 |             ); | 
            
              | 2183 |             $issue_id = $new_issue_id; | 
            
              | 2184 |         } | 
        
          | 2185 |  | 2178 |  | 
        
          | 2186 |         $dbh->do(q|INSERT INTO old_issues SELECT * FROM issues WHERE issue_id = ?|, undef, $issue_id); | 2179 |         $dbh->do(q|INSERT INTO old_issues SELECT * FROM issues WHERE issue_id = ?|, undef, $issue_id); | 
        
          | 2187 |  | 2180 |  | 
  
    | Lines 2190-2196
          sub MarkIssueReturned {
      
      
        Link Here | 
        
          | 2190 |             $dbh->do(q|UPDATE old_issues SET borrowernumber=? WHERE issue_id = ?|, undef, $anonymouspatron, $issue_id); | 2183 |             $dbh->do(q|UPDATE old_issues SET borrowernumber=? WHERE issue_id = ?|, undef, $anonymouspatron, $issue_id); | 
        
          | 2191 |         } | 2184 |         } | 
        
          | 2192 |  | 2185 |  | 
          
            
              | 2193 |         $dbh->do(q|DELETE FROM issues WHERE issue_id = ?|, undef, $issue_id); | 2186 |         # And finally delete the issue | 
            
              |  |  | 2187 |         $issue->delete; | 
        
          | 2194 |  | 2188 |  | 
        
          | 2195 |         ModItem( { 'onloan' => undef }, undef, $itemnumber ); | 2189 |         ModItem( { 'onloan' => undef }, undef, $itemnumber ); | 
        
          | 2196 |  | 2190 |  |