| Lines 64-69
          Koha::Account->new( { patron_id => $borrowernumber } )->pay(
      
      
        Link Here | 
        
          | 64 |         lines       => $lines, # Arrayref of Koha::Account::Line objects to pay | 64 |         lines       => $lines, # Arrayref of Koha::Account::Line objects to pay | 
        
          | 65 |         credit_type => $type,  # credit_type_code code | 65 |         credit_type => $type,  # credit_type_code code | 
        
          | 66 |         offset_type => $offset_type,    # offset type code | 66 |         offset_type => $offset_type,    # offset type code | 
            
              |  |  | 67 |         item_id     => $itemnumber,     # pass the itemnumber if this is a credit pertianing to a specific item (i.e LOST_FOUND) | 
        
          | 67 |     } | 68 |     } | 
        
          | 68 | ); | 69 | ); | 
        
          | 69 |  | 70 |  | 
  
    | Lines 82-90
          sub pay {
      
      
        Link Here | 
        
          | 82 |     my $credit_type   = $params->{credit_type}; | 83 |     my $credit_type   = $params->{credit_type}; | 
        
          | 83 |     my $offset_type   = $params->{offset_type} || $type eq 'WRITEOFF' ? 'Writeoff' : 'Payment'; | 84 |     my $offset_type   = $params->{offset_type} || $type eq 'WRITEOFF' ? 'Writeoff' : 'Payment'; | 
        
          | 84 |     my $cash_register = $params->{cash_register}; | 85 |     my $cash_register = $params->{cash_register}; | 
            
              |  |  | 86 |     my $item_id       = $params->{item_id}; | 
        
          | 85 |  | 87 |  | 
        
          | 86 |     my $userenv = C4::Context->userenv; | 88 |     my $userenv = C4::Context->userenv; | 
        
          | 87 |  | 89 |  | 
            
              |  |  | 90 |     $credit_type ||= | 
            
              | 91 |       $type eq 'WRITEOFF' | 
            
              | 92 |       ? 'WRITEOFF' | 
            
              | 93 |       : 'PAYMENT'; | 
            
              | 94 |  | 
        
          | 88 |     my $patron = Koha::Patrons->find( $self->{patron_id} ); | 95 |     my $patron = Koha::Patrons->find( $self->{patron_id} ); | 
        
          | 89 |  | 96 |  | 
        
          | 90 |     my $manager_id = $userenv ? $userenv->{number} : 0; | 97 |     my $manager_id = $userenv ? $userenv->{number} : 0; | 
  
    | Lines 115-126
          sub pay {
      
      
        Link Here | 
        
          | 115 |         $balance_remaining = $balance_remaining - $amount_to_pay; | 122 |         $balance_remaining = $balance_remaining - $amount_to_pay; | 
        
          | 116 |  | 123 |  | 
        
          | 117 |         # Same logic exists in Koha::Account::Line::apply | 124 |         # Same logic exists in Koha::Account::Line::apply | 
          
            
              | 118 |         if (   $new_amountoutstanding == 0 | 125 |         if ( C4::Context->preference('MarkLostItemsAsReturned') =~ m|onpayment| | 
            
              | 119 |             && $fine->itemnumber |  |  | 
        
          | 120 |             && $fine->debit_type_code | 126 |             && $fine->debit_type_code | 
          
            
              | 121 |             && ( $fine->debit_type_code eq 'LOST' ) ) | 127 |             && $fine->debit_type_code eq 'LOST' | 
            
              |  |  | 128 |             && $new_amountoutstanding == 0 | 
            
              | 129 |             && $fine->itemnumber | 
            
              | 130 |             && !(  $credit_type eq 'LOST_FOUND' | 
            
              | 131 |                 && $item_id == $fine->itemnumber ) ) | 
        
          | 122 |         { | 132 |         { | 
          
            
              | 123 |             C4::Circulation::ReturnLostItem( $self->{patron_id}, $fine->itemnumber ); | 133 |             C4::Circulation::ReturnLostItem( $self->{patron_id}, | 
            
              |  |  | 134 |                 $fine->itemnumber ); | 
        
          | 124 |         } | 135 |         } | 
        
          | 125 |  | 136 |  | 
        
          | 126 |         my $account_offset = Koha::Account::Offset->new( | 137 |         my $account_offset = Koha::Account::Offset->new( | 
  
    | Lines 174-185
          sub pay {
      
      
        Link Here | 
        
          | 174 |         $fine->amountoutstanding( $old_amountoutstanding - $amount_to_pay ); | 185 |         $fine->amountoutstanding( $old_amountoutstanding - $amount_to_pay ); | 
        
          | 175 |         $fine->store(); | 186 |         $fine->store(); | 
        
          | 176 |  | 187 |  | 
          
            
              | 177 |         if (   $fine->amountoutstanding == 0 | 188 |         if ( C4::Context->preference('MarkLostItemsAsReturned') =~ m|onpayment| | 
            
              | 178 |             && $fine->itemnumber |  |  | 
        
          | 179 |             && $fine->debit_type_code | 189 |             && $fine->debit_type_code | 
          
            
              | 180 |             && ( $fine->debit_type_code eq 'LOST' ) ) | 190 |             && $fine->debit_type_code eq 'LOST' | 
            
              |  |  | 191 |             && $fine->amountoutstanding == 0 | 
            
              | 192 |             && $fine->itemnumber | 
            
              | 193 |             && !(  $credit_type eq 'LOST_FOUND' | 
            
              | 194 |                 && $item_id == $fine->itemnumber ) ) | 
        
          | 181 |         { | 195 |         { | 
          
            
              | 182 |             C4::Circulation::ReturnLostItem( $self->{patron_id}, $fine->itemnumber ); | 196 |             C4::Circulation::ReturnLostItem( $self->{patron_id}, | 
            
              |  |  | 197 |                 $fine->itemnumber ); | 
        
          | 183 |         } | 198 |         } | 
        
          | 184 |  | 199 |  | 
        
          | 185 |         my $account_offset = Koha::Account::Offset->new( | 200 |         my $account_offset = Koha::Account::Offset->new( | 
  
    | Lines 216-226
          sub pay {
      
      
        Link Here | 
        
          | 216 |         last unless $balance_remaining > 0; | 231 |         last unless $balance_remaining > 0; | 
        
          | 217 |     } | 232 |     } | 
        
          | 218 |  | 233 |  | 
            
              | 219 |     $credit_type ||= |  |  | 
            
              | 220 |       $type eq 'WRITEOFF' | 
            
              | 221 |       ? 'WRITEOFF' | 
            
              | 222 |       : 'PAYMENT'; | 
            
              | 223 |  | 
        
          | 224 |     $description ||= $type eq 'WRITEOFF' ? 'Writeoff' : q{}; | 234 |     $description ||= $type eq 'WRITEOFF' ? 'Writeoff' : q{}; | 
        
          | 225 |  | 235 |  | 
        
          | 226 |     my $payment = Koha::Account::Line->new( | 236 |     my $payment = Koha::Account::Line->new( | 
  
    | Lines 237-242
          sub pay {
      
      
        Link Here | 
        
          | 237 |             branchcode        => $library_id, | 247 |             branchcode        => $library_id, | 
        
          | 238 |             register_id       => $cash_register, | 248 |             register_id       => $cash_register, | 
        
          | 239 |             note              => $note, | 249 |             note              => $note, | 
            
              |  |  | 250 |             itemnumber        => $item_id, | 
        
          | 240 |         } | 251 |         } | 
        
          | 241 |     )->store(); | 252 |     )->store(); | 
        
          | 242 |  | 253 |  | 
            
              | 243 | -  |  |  |