| 
      
            Lines 175-181
          subtest 'is_credit() and is_debit() tests' => sub {
      
      
        Link Here
      
     | 
  
        
          | 175 | 
           | 
          175 | 
           | 
        
        
          | 176 | 
          subtest 'apply() tests' => sub { | 
          176 | 
          subtest 'apply() tests' => sub { | 
        
        
          | 177 | 
           | 
          177 | 
           | 
        
          
            
              | 178 | 
                  plan tests => 26;  | 
              178 | 
                  plan tests => 30;  | 
            
        
          | 179 | 
           | 
          179 | 
           | 
        
        
          | 180 | 
              $schema->storage->txn_begin;  | 
          180 | 
              $schema->storage->txn_begin;  | 
        
        
          | 181 | 
           | 
          181 | 
           | 
        
  
    | 
      
            Lines 208-217
          subtest 'apply() tests' => sub {
      
      
        Link Here
      
     | 
  
        
          | 208 | 
              $debit_1->discard_changes;  | 
          208 | 
              $debit_1->discard_changes;  | 
        
        
          | 209 | 
           | 
          209 | 
           | 
        
        
          | 210 | 
              my $debits = Koha::Account::Lines->search({ accountlines_id => $debit_1->id }); | 
          210 | 
              my $debits = Koha::Account::Lines->search({ accountlines_id => $debit_1->id }); | 
        
          
            
              | 211 | 
                  my $remaining_credit = $credit->apply( { debits => [ $debits->as_list ], offset_type => 'Manual Credit' } ); | 
              211 | 
                  $credit = $credit->apply( { debits => [ $debits->as_list ], offset_type => 'Manual Credit' } ); | 
            
            
              | 212 | 
                  is( $remaining_credit * 1, 90, 'Remaining credit is correctly calculated' );  | 
              212 | 
                  is( ref($credit), 'Koha::Account::Line', '->apply returns the updated Koha::Account::Line credit object');  | 
            
            
              | 213 | 
                  $credit->discard_changes;  | 
              213 | 
                  is( $credit->amountoutstanding * -1, 90, 'Remaining credit is correctly calculated' );  | 
            
            
              | 214 | 
                  is( $credit->amountoutstanding * -1, $remaining_credit, 'Remaining credit correctly stored' );  | 
               | 
               | 
            
        
          | 215 | 
           | 
          214 | 
           | 
        
        
          | 216 | 
              # re-read debit info  | 
          215 | 
              # re-read debit info  | 
        
        
          | 217 | 
              $debit_1->discard_changes;  | 
          216 | 
              $debit_1->discard_changes;  | 
        
  
    | 
      
            Lines 224-233
          subtest 'apply() tests' => sub {
      
      
        Link Here
      
     | 
  
        
          | 224 | 
              is( $THE_offset->type, 'Manual Credit', 'Passed type stored correctly' );  | 
          223 | 
              is( $THE_offset->type, 'Manual Credit', 'Passed type stored correctly' );  | 
        
        
          | 225 | 
           | 
          224 | 
           | 
        
        
          | 226 | 
              $debits = Koha::Account::Lines->search({ accountlines_id => $debit_2->id }); | 
          225 | 
              $debits = Koha::Account::Lines->search({ accountlines_id => $debit_2->id }); | 
        
          
            
              | 227 | 
                  $remaining_credit = $credit->apply( { debits => [ $debits->as_list ] } ); | 
              226 | 
                  $credit = $credit->apply( { debits => [ $debits->as_list ] } ); | 
            
            
              | 228 | 
                  is( $remaining_credit, 0, 'No remaining credit left' );  | 
              227 | 
                  is( $credit->amountoutstanding * 1, 0, 'No remaining credit' );  | 
            
            
              | 229 | 
                  $credit->discard_changes;  | 
               | 
               | 
            
            
              | 230 | 
                  is( $credit->amountoutstanding * 1, 0, 'No outstanding credit' );  | 
            
        
          | 231 | 
              $debit_2->discard_changes;  | 
          228 | 
              $debit_2->discard_changes;  | 
        
        
          | 232 | 
              is( $debit_2->amountoutstanding * 1, 10, 'Outstanding amount decremented correctly' );  | 
          229 | 
              is( $debit_2->amountoutstanding * 1, 10, 'Outstanding amount decremented correctly' );  | 
        
        
          | 233 | 
           | 
          230 | 
           | 
        
  
    | 
      
            Lines 279-290
          subtest 'apply() tests' => sub {
      
      
        Link Here
      
     | 
  
        
          | 279 | 
              is( $credit_2->discard_changes->amountoutstanding * -1, 20, 'No changes made' );  | 
          276 | 
              is( $credit_2->discard_changes->amountoutstanding * -1, 20, 'No changes made' );  | 
        
        
          | 280 | 
           | 
          277 | 
           | 
        
        
          | 281 | 
              $debits = Koha::Account::Lines->search({ accountlines_id => { -in => [ $debit_1->id, $debit_2->id, $debit_3->id ] } }); | 
          278 | 
              $debits = Koha::Account::Lines->search({ accountlines_id => { -in => [ $debit_1->id, $debit_2->id, $debit_3->id ] } }); | 
        
          
            
              | 282 | 
                  $remaining_credit = $credit_2->apply( { debits => [ $debits->as_list ], offset_type => 'Manual Credit' } ); | 
              279 | 
                  $credit_2 = $credit_2->apply( { debits => [ $debits->as_list ], offset_type => 'Manual Credit' } ); | 
            
        
          | 283 | 
           | 
          280 | 
           | 
        
        
          | 284 | 
              is( $debit_1->discard_changes->amountoutstanding * 1,  0, 'No changes to already cancelled debit' );  | 
          281 | 
              is( $debit_1->discard_changes->amountoutstanding * 1,  0, 'No changes to already cancelled debit' );  | 
        
        
          | 285 | 
              is( $debit_2->discard_changes->amountoutstanding * 1,  0, 'Debit cancelled' );  | 
          282 | 
              is( $debit_2->discard_changes->amountoutstanding * 1,  0, 'Debit cancelled' );  | 
        
        
          | 286 | 
              is( $debit_3->discard_changes->amountoutstanding * 1, 90, 'Outstanding amount correctly calculated' );  | 
          283 | 
              is( $debit_3->discard_changes->amountoutstanding * 1, 90, 'Outstanding amount correctly calculated' );  | 
        
          
            
              | 287 | 
                  is( $credit_2->discard_changes->amountoutstanding * 1, 0, 'No remaining credit' );  | 
              284 | 
                  is( $credit_2->amountoutstanding * 1, 0, 'No remaining credit' );  | 
            
        
          | 288 | 
           | 
          285 | 
           | 
        
        
          | 289 | 
              my $library  = $builder->build_object( { class => 'Koha::Libraries' } ); | 
          286 | 
              my $library  = $builder->build_object( { class => 'Koha::Libraries' } ); | 
        
        
          | 290 | 
              my $biblio = $builder->build_sample_biblio();  | 
          287 | 
              my $biblio = $builder->build_sample_biblio();  | 
        
  
    | 
      
            Lines 336-342
          subtest 'apply() tests' => sub {
      
      
        Link Here
      
     | 
  
        
          | 336 | 
                  }  | 
          333 | 
                  }  | 
        
        
          | 337 | 
              );  | 
          334 | 
              );  | 
        
        
          | 338 | 
              my $debits_renew = Koha::Account::Lines->search({ accountlines_id => $accountline->id })->as_list; | 
          335 | 
              my $debits_renew = Koha::Account::Lines->search({ accountlines_id => $accountline->id })->as_list; | 
        
          
            
              | 339 | 
                  $credit_forgive->apply( { debits => $debits_renew, offset_type => 'Forgiven' } ); | 
              336 | 
                  $credit_forgive = $credit_forgive->apply( { debits => $debits_renew, offset_type => 'Forgiven' } ); | 
            
        
          | 340 | 
              is( $called, 0, 'C4::Circulation::AddRenew NOT called when RenewAccruingItemWhenPaid enabled but credit type is "FORGIVEN"' );  | 
          337 | 
              is( $called, 0, 'C4::Circulation::AddRenew NOT called when RenewAccruingItemWhenPaid enabled but credit type is "FORGIVEN"' );  | 
        
        
          | 341 | 
           | 
          338 | 
           | 
        
        
          | 342 | 
              $accountline = Koha::Account::Line->new(  | 
          339 | 
              $accountline = Koha::Account::Line->new(  | 
        
  
    | 
      
            Lines 355-363
          subtest 'apply() tests' => sub {
      
      
        Link Here
      
     | 
  
        
          | 355 | 
              )->store();  | 
          352 | 
              )->store();  | 
        
        
          | 356 | 
              my $credit_renew = $account->add_credit({ amount => 100, user_id => $patron->id, interface => 'commandline' }); | 
          353 | 
              my $credit_renew = $account->add_credit({ amount => 100, user_id => $patron->id, interface => 'commandline' }); | 
        
        
          | 357 | 
              $debits_renew = Koha::Account::Lines->search({ accountlines_id => $accountline->id })->as_list; | 
          354 | 
              $debits_renew = Koha::Account::Lines->search({ accountlines_id => $accountline->id })->as_list; | 
        
          
            
              | 358 | 
                  $credit_renew->apply( { debits => $debits_renew, offset_type => 'Manual Credit' } ); | 
              355 | 
                  $credit_renew = $credit_renew->apply( { debits => $debits_renew, offset_type => 'Manual Credit' } ); | 
            
        
          | 359 | 
              is( $called, 1, 'RenewAccruingItemWhenPaid causes C4::Circulation::AddRenew to be called when appropriate' );  | 
          356 | 
              is( $called, 1, 'RenewAccruingItemWhenPaid causes C4::Circulation::AddRenew to be called when appropriate' );  | 
        
        
          | 360 | 
           | 
          357 | 
           | 
        
            
               | 
               | 
              358 | 
                  my @messages = @{$credit_renew->messages}; | 
            
            
              | 359 | 
                  is( $messages[0]->type, 'info', 'Info message added for renewal' );  | 
            
            
              | 360 | 
                  is( $messages[0]->message, 'renewal', 'Message is "renewal"' );  | 
            
            
              | 361 | 
                  is( $messages[0]->payload->{itemnumber}, $item->id, 'itemnumber found in payload' ); | 
            
            
              | 362 | 
                  is( $messages[0]->payload->{due_date}, 1, 'due_date key in payload' ); | 
            
            
              | 363 | 
                  is( $messages[0]->payload->{success}, 1, "'success' key in payload" ); | 
            
            
              | 364 | 
               | 
            
        
          | 361 | 
              $schema->storage->txn_rollback;  | 
          365 | 
              $schema->storage->txn_rollback;  | 
        
        
          | 362 | 
          };  | 
          366 | 
          };  | 
        
        
          | 363 | 
           | 
          367 | 
           | 
        
            
              | 364 | 
              -   | 
               | 
               |