| 
      
            Lines 1909-1916
          sub AddReturn {
      
      
        Link Here
      
     | 
  
        
          | 1909 | 
           | 
          1909 | 
           | 
        
        
          | 1910 | 
                  if ($patron) { | 
          1910 | 
                  if ($patron) { | 
        
        
          | 1911 | 
                      eval { | 
          1911 | 
                      eval { | 
        
          
            
              | 1912 | 
                              MarkIssueReturned( $borrowernumber, $item->{'itemnumber'}, | 
              1912 | 
                              if ( $dropbox ) { | 
            
            
              | 1913 | 
                                  $circControlBranch, $return_date, $patron->privacy );  | 
              1913 | 
                                  MarkIssueReturned( $borrowernumber, $item->{'itemnumber'}, | 
            
            
               | 
               | 
              1914 | 
                                      $dropboxdate, $patron->privacy );  | 
            
            
              | 1915 | 
                              }  | 
            
            
              | 1916 | 
                              else { | 
            
            
              | 1917 | 
                                  MarkIssueReturned( $borrowernumber, $item->{'itemnumber'}, | 
            
            
              | 1918 | 
                                      $return_date, $patron->privacy );  | 
            
            
              | 1919 | 
                              }  | 
            
        
          | 1914 | 
                      };  | 
          1920 | 
                      };  | 
        
        
          | 1915 | 
                      unless ( $@ ) { | 
          1921 | 
                      unless ( $@ ) { | 
        
        
          | 1916 | 
                          if ( ( C4::Context->preference('CalculateFinesOnReturn') && $is_overdue ) || $return_date ) { | 
          1922 | 
                          if ( ( C4::Context->preference('CalculateFinesOnReturn') && $is_overdue ) || $return_date ) { | 
        
  
    | 
      
            Lines 2087-2115
          sub AddReturn {
      
      
        Link Here
      
     | 
  
        
          | 2087 | 
           | 
          2093 | 
           | 
        
        
          | 2088 | 
          =head2 MarkIssueReturned  | 
          2094 | 
          =head2 MarkIssueReturned  | 
        
        
          | 2089 | 
           | 
          2095 | 
           | 
        
          
            
              | 2090 | 
                MarkIssueReturned($borrowernumber, $itemnumber, $dropbox_branch, $returndate, $privacy);  | 
              2096 | 
                MarkIssueReturned($borrowernumber, $itemnumber, $returndate, $privacy);  | 
            
        
          | 2091 | 
           | 
          2097 | 
           | 
        
        
          | 2092 | 
          Unconditionally marks an issue as being returned by  | 
          2098 | 
          Unconditionally marks an issue as being returned by  | 
        
        
          | 2093 | 
          moving the C<issues> row to C<old_issues> and  | 
          2099 | 
          moving the C<issues> row to C<old_issues> and  | 
        
          
            
              | 2094 | 
              setting C<returndate> to the current date, or  | 
              2100 | 
              setting C<returndate> to the current date.  | 
            
            
              | 2095 | 
              the last non-holiday date of the branccode specified in  | 
               | 
               | 
            
            
              | 2096 | 
              C<dropbox_branch> .  Assumes you've already checked that   | 
            
            
              | 2097 | 
              it's safe to do this, i.e. last non-holiday > issuedate.  | 
            
        
          | 2098 | 
           | 
          2101 | 
           | 
        
        
          | 2099 | 
          if C<$returndate> is specified (in iso format), it is used as the date  | 
          2102 | 
          if C<$returndate> is specified (in iso format), it is used as the date  | 
        
          
            
              | 2100 | 
              of the return. It is ignored when a dropbox_branch is passed in.  | 
              2103 | 
              of the return.  | 
            
        
          | 2101 | 
           | 
          2104 | 
           | 
        
        
          | 2102 | 
          C<$privacy> contains the privacy parameter. If the patron has set privacy to 2,  | 
          2105 | 
          C<$privacy> contains the privacy parameter. If the patron has set privacy to 2,  | 
        
        
          | 2103 | 
          the old_issue is immediately anonymised  | 
          2106 | 
          the old_issue is immediately anonymised  | 
        
        
          | 2104 | 
           | 
          2107 | 
           | 
        
        
          | 2105 | 
          Ideally, this function would be internal to C<C4::Circulation>,  | 
          2108 | 
          Ideally, this function would be internal to C<C4::Circulation>,  | 
        
          
            
              | 2106 | 
              not exported, but it is currently needed by one   | 
              2109 | 
              not exported, but it is currently used in misc/cronjobs/longoverdue.pl.  | 
            
            
              | 2107 | 
              routine in C<C4::Accounts>.  | 
               | 
               | 
            
        
          | 2108 | 
           | 
          2110 | 
           | 
        
        
          | 2109 | 
          =cut  | 
          2111 | 
          =cut  | 
        
        
          | 2110 | 
           | 
          2112 | 
           | 
        
        
          | 2111 | 
          sub MarkIssueReturned { | 
          2113 | 
          sub MarkIssueReturned { | 
        
          
            
              | 2112 | 
                  my ( $borrowernumber, $itemnumber, $dropbox_branch, $returndate, $privacy ) = @_;  | 
              2114 | 
                  my ( $borrowernumber, $itemnumber, $returndate, $privacy ) = @_;  | 
            
        
          | 2113 | 
           | 
          2115 | 
           | 
        
        
          | 2114 | 
           | 
          2116 | 
           | 
        
        
          | 2115 | 
              # Retrieve the issue  | 
          2117 | 
              # Retrieve the issue  | 
        
  
    | 
      
            Lines 2126-2166
          sub MarkIssueReturned {
      
      
        Link Here
      
     | 
  
        
          | 2126 | 
                  die "Fatal error: the patron ($borrowernumber) has requested their circulation history be anonymized on check-in, but the AnonymousPatron system preference is empty or not set correctly."  | 
          2128 | 
                  die "Fatal error: the patron ($borrowernumber) has requested their circulation history be anonymized on check-in, but the AnonymousPatron system preference is empty or not set correctly."  | 
        
        
          | 2127 | 
                      unless Koha::Patrons->find( $anonymouspatron );  | 
          2129 | 
                      unless Koha::Patrons->find( $anonymouspatron );  | 
        
        
          | 2128 | 
              }  | 
          2130 | 
              }  | 
        
            
              | 2129 | 
                  my $database = Koha::Database->new();  | 
               | 
               | 
            
            
              | 2130 | 
                  my $schema   = $database->schema;  | 
            
            
              | 2131 | 
                  my $dbh   = C4::Context->dbh;  | 
            
        
          | 2132 | 
           | 
          2131 | 
           | 
        
          
            
              | 2133 | 
                  my $query = 'UPDATE issues SET returndate=';  | 
              2132 | 
                  my $schema   = Koha::Database->schema;  | 
            
            
              | 2134 | 
                  my @bind;  | 
               | 
               | 
            
            
              | 2135 | 
                  if ($dropbox_branch) { | 
            
            
              | 2136 | 
                      my $calendar = Koha::Calendar->new( branchcode => $dropbox_branch );  | 
            
            
              | 2137 | 
                      my $dropboxdate = $calendar->addDate( DateTime->now( time_zone => C4::Context->tz), -1 );  | 
            
            
              | 2138 | 
                      $query .= ' ? ';  | 
            
            
              | 2139 | 
                      push @bind, $dropboxdate->strftime('%Y-%m-%d %H:%M'); | 
            
            
              | 2140 | 
                  } elsif ($returndate) { | 
            
            
              | 2141 | 
                      $query .= ' ? ';  | 
            
            
              | 2142 | 
                      push @bind, $returndate;  | 
            
            
              | 2143 | 
                  } else { | 
            
            
              | 2144 | 
                      $query .= ' now() ';  | 
            
            
              | 2145 | 
                  }  | 
            
            
              | 2146 | 
                  $query .= ' WHERE issue_id = ?';  | 
            
            
              | 2147 | 
                  push @bind, $issue_id;  | 
            
        
          | 2148 | 
           | 
          2133 | 
           | 
        
        
          | 2149 | 
              # FIXME Improve the return value and handle it from callers  | 
          2134 | 
              # FIXME Improve the return value and handle it from callers  | 
        
        
          | 2150 | 
              $schema->txn_do(sub { | 
          2135 | 
              $schema->txn_do(sub { | 
        
        
          | 2151 | 
           | 
          2136 | 
           | 
        
          
            
              | 2152 | 
                      # Update the returndate  | 
              2137 | 
                      # Update the returndate value  | 
            
            
              | 2153 | 
                      $dbh->do( $query, undef, @bind );  | 
              2138 | 
                      if ( $returndate ) { | 
            
            
              | 2154 | 
               | 
              2139 | 
                          $issue->update({ returndate => $returndate })->discard_changes; # update and refetch | 
            
            
              | 2155 | 
                      # We just updated the returndate, so we need to refetch $issue  | 
              2140 | 
                      }  | 
            
            
              | 2156 | 
                      $issue->discard_changes;  | 
              2141 | 
                      else { | 
            
            
               | 
               | 
              2142 | 
                          $issue->update({ returndate => \'NOW()' })->discard_changes; # update and refetch | 
            
            
              | 2143 | 
                      }  | 
            
        
          | 2157 | 
           | 
          2144 | 
           | 
        
        
          | 2158 | 
                  # Create the old_issues entry  | 
          2145 | 
                  # Create the old_issues entry  | 
        
        
          | 2159 | 
                  my $old_checkout = Koha::Old::Checkout->new($issue->unblessed)->store;  | 
          2146 | 
                  my $old_checkout = Koha::Old::Checkout->new($issue->unblessed)->store;  | 
        
        
          | 2160 | 
           | 
          2147 | 
           | 
        
        
          | 2161 | 
                  # anonymise patron checkout immediately if $privacy set to 2 and AnonymousPatron is set to a valid borrowernumber  | 
          2148 | 
                  # anonymise patron checkout immediately if $privacy set to 2 and AnonymousPatron is set to a valid borrowernumber  | 
        
        
          | 2162 | 
                  if ( $privacy == 2) { | 
          2149 | 
                  if ( $privacy == 2) { | 
        
          
            
              | 2163 | 
                          $dbh->do(q|UPDATE old_issues SET borrowernumber=? WHERE issue_id = ?|, undef, $anonymouspatron, $old_checkout->issue_id);  | 
              2150 | 
                          $old_checkout->update({ borrowernumber => $anonymouspatron }); | 
            
        
          | 2164 | 
                  }  | 
          2151 | 
                  }  | 
        
        
          | 2165 | 
           | 
          2152 | 
           | 
        
        
          | 2166 | 
                  # And finally delete the issue  | 
          2153 | 
                  # And finally delete the issue  | 
        
  
    | 
      
            Lines 3700-3706
          sub LostItem{
      
      
        Link Here
      
     | 
  
        
          | 3700 | 
                      #warn " $issues->{'borrowernumber'}  /  $itemnumber "; | 
          3687 | 
                      #warn " $issues->{'borrowernumber'}  /  $itemnumber "; | 
        
        
          | 3701 | 
                  }  | 
          3688 | 
                  }  | 
        
        
          | 3702 | 
           | 
          3689 | 
           | 
        
          
            
              | 3703 | 
                      MarkIssueReturned($borrowernumber,$itemnumber,undef,undef,$patron->privacy) if $mark_returned;  | 
              3690 | 
                      MarkIssueReturned($borrowernumber,$itemnumber,undef,$patron->privacy) if $mark_returned;  | 
            
        
          | 3704 | 
              }  | 
          3691 | 
              }  | 
        
        
          | 3705 | 
           | 
          3692 | 
           | 
        
        
          | 3706 | 
              #When item is marked lost automatically cancel its outstanding transfers and set items holdingbranch to the transfer source branch (frombranch)  | 
          3693 | 
              #When item is marked lost automatically cancel its outstanding transfers and set items holdingbranch to the transfer source branch (frombranch)  | 
        
  
    | 
      
            Lines 3771-3777
          sub ProcessOfflineReturn {
      
      
        Link Here
      
     | 
  
        
          | 3771 | 
                      MarkIssueReturned(  | 
          3758 | 
                      MarkIssueReturned(  | 
        
        
          | 3772 | 
                          $issue->{borrowernumber}, | 
          3759 | 
                          $issue->{borrowernumber}, | 
        
        
          | 3773 | 
                          $itemnumber,  | 
          3760 | 
                          $itemnumber,  | 
        
            
              | 3774 | 
                              undef,  | 
               | 
               | 
            
        
          | 3775 | 
                          $operation->{timestamp}, | 
          3761 | 
                          $operation->{timestamp}, | 
        
        
          | 3776 | 
                      );  | 
          3762 | 
                      );  | 
        
        
          | 3777 | 
                      ModItem(  | 
          3763 | 
                      ModItem(  | 
        
  
    | 
      
            Lines 3806-3812
          sub ProcessOfflineIssue {
      
      
        Link Here
      
     | 
  
        
          | 3806 | 
                      MarkIssueReturned(  | 
          3792 | 
                      MarkIssueReturned(  | 
        
        
          | 3807 | 
                          $issue->{borrowernumber}, | 
          3793 | 
                          $issue->{borrowernumber}, | 
        
        
          | 3808 | 
                          $itemnumber,  | 
          3794 | 
                          $itemnumber,  | 
        
            
              | 3809 | 
                              undef,  | 
               | 
               | 
            
        
          | 3810 | 
                          $operation->{timestamp}, | 
          3795 | 
                          $operation->{timestamp}, | 
        
        
          | 3811 | 
                      );  | 
          3796 | 
                      );  | 
        
        
          | 3812 | 
                  }  | 
          3797 | 
                  }  |