| Lines 210-216
          sub debits {
      
      
        Link Here | 
        
          | 210 |  | 210 |  | 
        
          | 211 | =head3 void | 211 | =head3 void | 
        
          | 212 |  | 212 |  | 
          
            
              | 213 |   $payment_accountline->void(); | 213 |   $payment_accountline->void({ | 
            
              |  |  | 214 |       interface => $interface, | 
            
              | 215 |       [ staff_id => $staff_id, branch => $branchcode ] | 
            
              | 216 |   }); | 
        
          | 214 |  | 217 |  | 
        
          | 215 | Used to 'void' (or reverse) a payment/credit. It will roll back any offsets | 218 | Used to 'void' (or reverse) a payment/credit. It will roll back any offsets | 
        
          | 216 | created by the application of this credit upon any debits and mark the credit | 219 | created by the application of this credit upon any debits and mark the credit | 
  
    | Lines 219-235
          as 'void' by updating it's status to "VOID".
      
      
        Link Here | 
        
          | 219 | =cut | 222 | =cut | 
        
          | 220 |  | 223 |  | 
        
          | 221 | sub void { | 224 | sub void { | 
          
            
              | 222 |     my ($self) = @_; | 225 |     my ($self, $params) = @_; | 
            
              |  |  | 226 |  | 
            
              | 227 |     # Make sure it is a credit we are voiding | 
            
              | 228 |     unless ( $self->is_credit ) { | 
            
              | 229 |         Koha::Exceptions::Account::IsNotCredit->throw( | 
            
              | 230 |             error => 'Account line ' . $self->id . 'is not a credit' ); | 
            
              | 231 |     } | 
        
          | 223 |  | 232 |  | 
          
            
              | 224 |     # Make sure it is a payment we are voiding | 233 |     # Make sure it is not already voided | 
            
              | 225 |     return unless $self->amount < 0; | 234 |     if ( $self->status && $self->status eq 'VOID' ) { | 
            
              |  |  | 235 |         Koha::Exceptions::Account->throw( | 
            
              | 236 |             error => 'Account line ' . $self->id . 'is already void' ); | 
            
              | 237 |     } | 
            
              | 238 |  | 
            
              | 239 |     # Check for mandatory parameters | 
            
              | 240 |     my @mandatory = ( 'interface' ); | 
            
              | 241 |     for my $param (@mandatory) { | 
            
              | 242 |         unless ( defined( $params->{$param} ) ) { | 
            
              | 243 |             Koha::Exceptions::MissingParameter->throw( | 
            
              | 244 |                 error => "The $param parameter is mandatory" ); | 
            
              | 245 |         } | 
            
              | 246 |     } | 
            
              | 247 |  | 
            
              | 248 |     # More mandatory parameters | 
            
              | 249 |     if ( $params->{interface} eq 'intranet' ) { | 
            
              | 250 |         my @optional = ( 'staff_id', 'branch' ); | 
            
              | 251 |         for my $param (@optional) { | 
            
              | 252 |             unless ( defined( $params->{$param} ) ) { | 
            
              | 253 |                 Koha::Exceptions::MissingParameter->throw( error => | 
            
              | 254 | "The $param parameter is mandatory when interface is set to 'intranet'" | 
            
              | 255 |                 ); | 
            
              | 256 |             } | 
            
              | 257 |         } | 
            
              | 258 |     } | 
        
          | 226 |  | 259 |  | 
            
              |  |  | 260 |     # Find any applied offsets for the credit so we may reverse them | 
        
          | 227 |     my @account_offsets = | 261 |     my @account_offsets = | 
        
          | 228 |       Koha::Account::Offsets->search( | 262 |       Koha::Account::Offsets->search( | 
        
          | 229 |         { credit_id => $self->id, amount => { '<' => 0 }  } ); | 263 |         { credit_id => $self->id, amount => { '<' => 0 }  } ); | 
        
          | 230 |  | 264 |  | 
            
              |  |  | 265 |     my $void; | 
        
          | 231 |     $self->_result->result_source->schema->txn_do( | 266 |     $self->_result->result_source->schema->txn_do( | 
        
          | 232 |         sub { | 267 |         sub { | 
            
              |  |  | 268 |  | 
            
              | 269 |             # A 'void' is a 'debit' | 
            
              | 270 |             $void = Koha::Account::Line->new( | 
            
              | 271 |                 { | 
            
              | 272 |                     borrowernumber    => $self->borrowernumber, | 
            
              | 273 |                     date              => \'NOW()', | 
            
              | 274 |                     debit_type_code   => 'VOID', | 
            
              | 275 |                     amount            => $self->amount * -1, | 
            
              | 276 |                     amountoutstanding => $self->amount * -1, | 
            
              | 277 |                     manager_id        => $params->{staff_id}, | 
            
              | 278 |                     interface         => $params->{interface}, | 
            
              | 279 |                     branchcode        => $params->{branch}, | 
            
              | 280 |                 } | 
            
              | 281 |             )->store(); | 
            
              | 282 |  | 
            
              | 283 |             # Record the creation offset | 
            
              | 284 |             Koha::Account::Offset->new( | 
            
              | 285 |                 { | 
            
              | 286 |                     debit_id => $void->id, | 
            
              | 287 |                     type     => 'VOID', | 
            
              | 288 |                     amount   => $self->amount * -1 | 
            
              | 289 |                 } | 
            
              | 290 |             )->store(); | 
            
              | 291 |  | 
            
              | 292 |             # Reverse any applied payments | 
        
          | 233 |             foreach my $account_offset (@account_offsets) { | 293 |             foreach my $account_offset (@account_offsets) { | 
        
          | 234 |                 my $fee_paid = | 294 |                 my $fee_paid = | 
        
          | 235 |                   Koha::Account::Lines->find( $account_offset->debit_id ); | 295 |                   Koha::Account::Lines->find( $account_offset->debit_id ); | 
  
    | Lines 246-256
          sub void {
      
      
        Link Here | 
        
          | 246 |                         credit_id => $self->id, | 306 |                         credit_id => $self->id, | 
        
          | 247 |                         debit_id  => $fee_paid->id, | 307 |                         debit_id  => $fee_paid->id, | 
        
          | 248 |                         amount    => $amount_paid, | 308 |                         amount    => $amount_paid, | 
          
            
              | 249 |                         type      => 'Void Payment', | 309 |                         type      => 'VOID', | 
        
          | 250 |                     } | 310 |                     } | 
        
          | 251 |                 )->store(); | 311 |                 )->store(); | 
        
          | 252 |             } | 312 |             } | 
        
          | 253 |  | 313 |  | 
            
              |  |  | 314 |             # Link void to payment | 
            
              | 315 |             $self->set({ | 
            
              | 316 |                 amountoutstanding => $self->amount, | 
            
              | 317 |                 status => 'VOID' | 
            
              | 318 |             })->store(); | 
            
              | 319 |             $self->apply({ debits => [$void]}); | 
            
              | 320 |  | 
        
          | 254 |             if ( C4::Context->preference("FinesLog") ) { | 321 |             if ( C4::Context->preference("FinesLog") ) { | 
        
          | 255 |                 logaction( | 322 |                 logaction( | 
        
          | 256 |                     "FINES", 'VOID', | 323 |                     "FINES", 'VOID', | 
  
    | Lines 273-290
          sub void {
      
      
        Link Here | 
        
          | 273 |                     ) | 340 |                     ) | 
        
          | 274 |                 ); | 341 |                 ); | 
        
          | 275 |             } | 342 |             } | 
            
              | 276 |  |  |  | 
            
              | 277 |             $self->set( | 
            
              | 278 |                 { | 
            
              | 279 |                     status            => 'VOID', | 
            
              | 280 |                     amountoutstanding => 0, | 
            
              | 281 |                     amount            => 0, | 
            
              | 282 |                 } | 
            
              | 283 |             ); | 
            
              | 284 |             $self->store(); | 
        
          | 285 |         } | 343 |         } | 
        
          | 286 |     ); | 344 |     ); | 
        
          | 287 |  | 345 |  | 
            
              |  |  | 346 |     $void->discard_changes; | 
            
              | 347 |     return $void; | 
        
          | 288 | } | 348 | } | 
        
          | 289 |  | 349 |  | 
        
          | 290 | =head3 cancel | 350 | =head3 cancel |