| 
      
            Lines 18-24
          
      
      
        Link Here
      
     | 
  
        
          | 18 | 
          use Modern::Perl;  | 
          18 | 
          use Modern::Perl;  | 
        
        
          | 19 | 
          use utf8;  | 
          19 | 
          use utf8;  | 
        
        
          | 20 | 
           | 
          20 | 
           | 
        
          
            
              | 21 | 
              use Test::More tests => 70;  | 
              21 | 
              use Test::More tests => 73;  | 
            
        
          | 22 | 
          use Test::Exception;  | 
          22 | 
          use Test::Exception;  | 
        
        
          | 23 | 
          use Test::MockModule;  | 
          23 | 
          use Test::MockModule;  | 
        
        
          | 24 | 
          use Test::Deep qw( cmp_deeply );  | 
          24 | 
          use Test::Deep qw( cmp_deeply );  | 
        
  
    | 
      
            Lines 5487-5492
          subtest 'Do not return on renewal (LOST charge)' => sub {
      
      
        Link Here
      
     | 
  
        
          | 5487 | 
              );  | 
          5487 | 
              );  | 
        
        
          | 5488 | 
          };  | 
          5488 | 
          };  | 
        
        
          | 5489 | 
           | 
          5489 | 
           | 
        
            
               | 
               | 
              5490 | 
              subtest 'Lost status does not change when preferences are set to 0' => sub { | 
            
            
              | 5491 | 
                  plan tests => 2;  | 
            
            
              | 5492 | 
               | 
            
            
              | 5493 | 
                  my $library = $builder->build_object( { class => "Koha::Libraries" } ); | 
            
            
              | 5494 | 
                  my $manager = $builder->build_object( { class => "Koha::Patrons" } ); | 
            
            
              | 5495 | 
                  t::lib::Mocks::mock_userenv( { patron => $manager, branchcode => $manager->branchcode } ); | 
            
            
              | 5496 | 
               | 
            
            
              | 5497 | 
                  my $biblio = $builder->build_sample_biblio;  | 
            
            
              | 5498 | 
                  my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); | 
            
            
              | 5499 | 
               | 
            
            
              | 5500 | 
                  my $item = $builder->build_sample_item(  | 
            
            
              | 5501 | 
                      { | 
            
            
              | 5502 | 
                          biblionumber     => $biblio->biblionumber,  | 
            
            
              | 5503 | 
                          library          => $library->branchcode,  | 
            
            
              | 5504 | 
                          replacementprice => 99,  | 
            
            
              | 5505 | 
                          itype            => $itemtype,  | 
            
            
              | 5506 | 
                          itemlost         => 1,  | 
            
            
              | 5507 | 
                      }  | 
            
            
              | 5508 | 
                  );  | 
            
            
              | 5509 | 
               | 
            
            
              | 5510 | 
                  my $debitCharge = Koha::Account::Line->new(  | 
            
            
              | 5511 | 
                      { | 
            
            
              | 5512 | 
                          borrowernumber    => $patron->borrowernumber,  | 
            
            
              | 5513 | 
                          debit_type_code   => 'LOST',  | 
            
            
              | 5514 | 
                          status            => undef,  | 
            
            
              | 5515 | 
                          itemnumber        => $item->itemnumber,  | 
            
            
              | 5516 | 
                          amount            => 12,  | 
            
            
              | 5517 | 
                          amountoutstanding => 12,  | 
            
            
              | 5518 | 
                          interface         => 'something',  | 
            
            
              | 5519 | 
                      }  | 
            
            
              | 5520 | 
                  )->store();  | 
            
            
              | 5521 | 
               | 
            
            
              | 5522 | 
                  # Test for UpdateItemLostStatusWhenPaid  | 
            
            
              | 5523 | 
                  t::lib::Mocks::mock_preference( 'UpdateItemLostStatusWhenPaid', 0 );  | 
            
            
              | 5524 | 
               | 
            
            
              | 5525 | 
                  my $paymentLine = Koha::Account::Line->new(  | 
            
            
              | 5526 | 
                      { | 
            
            
              | 5527 | 
                          borrowernumber    => $patron->borrowernumber,  | 
            
            
              | 5528 | 
                          credit_type_code  => 'CREDIT',  | 
            
            
              | 5529 | 
                          status            => undef,  | 
            
            
              | 5530 | 
                          itemnumber        => $item->itemnumber,  | 
            
            
              | 5531 | 
                          amountoutstanding => 0 - 12,  | 
            
            
              | 5532 | 
                          amount            => 0 - 12,  | 
            
            
              | 5533 | 
                          interface         => 'something',  | 
            
            
              | 5534 | 
                      }  | 
            
            
              | 5535 | 
                  )->store();  | 
            
            
              | 5536 | 
               | 
            
            
              | 5537 | 
                  my $offset = Koha::Account::Offset->new(  | 
            
            
              | 5538 | 
                      { | 
            
            
              | 5539 | 
                          credit_id => $paymentLine->id,  | 
            
            
              | 5540 | 
                          debit_id  => $debitCharge->id,  | 
            
            
              | 5541 | 
                          type      => 'APPLY',  | 
            
            
              | 5542 | 
                          amount    => 0  | 
            
            
              | 5543 | 
                      }  | 
            
            
              | 5544 | 
                  )->store();  | 
            
            
              | 5545 | 
               | 
            
            
              | 5546 | 
                  $paymentLine->apply( { debits => [$debitCharge] } ); | 
            
            
              | 5547 | 
               | 
            
            
              | 5548 | 
                  is(  | 
            
            
              | 5549 | 
                      Koha::Items->find( $item->itemnumber )->itemlost, 1,  | 
            
            
              | 5550 | 
                      "Payment should not change itemlost status when UpdateItemLostStatusWhenPaid is 0"  | 
            
            
              | 5551 | 
                  );  | 
            
            
              | 5552 | 
               | 
            
            
              | 5553 | 
                  # Test for UpdateItemLostStatusWhenWriteOff  | 
            
            
              | 5554 | 
                  t::lib::Mocks::mock_preference( 'UpdateItemLostStatusWhenWriteOff', 0 );  | 
            
            
              | 5555 | 
               | 
            
            
              | 5556 | 
                  my $writeOffLine = Koha::Account::Line->new(  | 
            
            
              | 5557 | 
                      { | 
            
            
              | 5558 | 
                          borrowernumber    => $patron->borrowernumber,  | 
            
            
              | 5559 | 
                          credit_type_code  => 'WRITEOFF',  | 
            
            
              | 5560 | 
                          status            => undef,  | 
            
            
              | 5561 | 
                          itemnumber        => $item->itemnumber,  | 
            
            
              | 5562 | 
                          amountoutstanding => 0 - 12,  | 
            
            
              | 5563 | 
                          amount            => 0 - 12,  | 
            
            
              | 5564 | 
                          interface         => 'something',  | 
            
            
              | 5565 | 
                      }  | 
            
            
              | 5566 | 
                  )->store();  | 
            
            
              | 5567 | 
               | 
            
            
              | 5568 | 
                  $offset = Koha::Account::Offset->new(  | 
            
            
              | 5569 | 
                      { | 
            
            
              | 5570 | 
                          credit_id => $writeOffLine->id,  | 
            
            
              | 5571 | 
                          debit_id  => $debitCharge->id,  | 
            
            
              | 5572 | 
                          type      => 'APPLY',  | 
            
            
              | 5573 | 
                          amount    => 0  | 
            
            
              | 5574 | 
                      }  | 
            
            
              | 5575 | 
                  )->store();  | 
            
            
              | 5576 | 
               | 
            
            
              | 5577 | 
                  $writeOffLine->apply( { debits => [$debitCharge] } ); | 
            
            
              | 5578 | 
               | 
            
            
              | 5579 | 
                  is(  | 
            
            
              | 5580 | 
                      Koha::Items->find( $item->itemnumber )->itemlost, 1,  | 
            
            
              | 5581 | 
                      "Write-off should not change itemlost status when UpdateItemLostStatusWhenWriteOff is 0"  | 
            
            
              | 5582 | 
                  );  | 
            
            
              | 5583 | 
              };  | 
            
            
              | 5584 | 
               | 
            
            
              | 5585 | 
              # Test for UpdateItemLostStatusWhenPaid  | 
            
            
              | 5586 | 
              subtest 'Update lost item to authorized value on payment of balance' => sub { | 
            
            
              | 5587 | 
                  plan tests => 5;  | 
            
            
              | 5588 | 
               | 
            
            
              | 5589 | 
                  my $library = $builder->build_object( { class => "Koha::Libraries" } ); | 
            
            
              | 5590 | 
                  my $manager = $builder->build_object( { class => "Koha::Patrons" } ); | 
            
            
              | 5591 | 
                  t::lib::Mocks::mock_userenv( { patron => $manager, branchcode => $manager->branchcode } ); | 
            
            
              | 5592 | 
               | 
            
            
              | 5593 | 
                  my $biblio = $builder->build_sample_biblio;  | 
            
            
              | 5594 | 
                  my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); | 
            
            
              | 5595 | 
               | 
            
            
              | 5596 | 
                  for my $status ( 2 .. 6 ) { | 
            
            
              | 5597 | 
                      t::lib::Mocks::mock_preference( 'UpdateItemLostStatusWhenPaid', $status );  | 
            
            
              | 5598 | 
               | 
            
            
              | 5599 | 
                      my $item = $builder->build_sample_item(  | 
            
            
              | 5600 | 
                          { | 
            
            
              | 5601 | 
                              biblionumber     => $biblio->biblionumber,  | 
            
            
              | 5602 | 
                              library          => $library->branchcode,  | 
            
            
              | 5603 | 
                              replacementprice => 99,  | 
            
            
              | 5604 | 
                              itype            => $itemtype,  | 
            
            
              | 5605 | 
                              itemlost         => 1,  | 
            
            
              | 5606 | 
                          }  | 
            
            
              | 5607 | 
                      );  | 
            
            
              | 5608 | 
               | 
            
            
              | 5609 | 
                      my $debitCharge = Koha::Account::Line->new(  | 
            
            
              | 5610 | 
                          { | 
            
            
              | 5611 | 
                              borrowernumber    => $patron->borrowernumber,  | 
            
            
              | 5612 | 
                              debit_type_code   => 'LOST',  | 
            
            
              | 5613 | 
                              status            => undef,  | 
            
            
              | 5614 | 
                              itemnumber        => $item->itemnumber,  | 
            
            
              | 5615 | 
                              amount            => 12,  | 
            
            
              | 5616 | 
                              amountoutstanding => 12,  | 
            
            
              | 5617 | 
                              interface         => 'something',  | 
            
            
              | 5618 | 
                          }  | 
            
            
              | 5619 | 
                      )->store();  | 
            
            
              | 5620 | 
               | 
            
            
              | 5621 | 
                      my $paymentLine = Koha::Account::Line->new(  | 
            
            
              | 5622 | 
                          { | 
            
            
              | 5623 | 
                              borrowernumber    => $patron->borrowernumber,  | 
            
            
              | 5624 | 
                              credit_type_code  => 'CREDIT',  | 
            
            
              | 5625 | 
                              status            => undef,  | 
            
            
              | 5626 | 
                              itemnumber        => $item->itemnumber,  | 
            
            
              | 5627 | 
                              amountoutstanding => 0 - 12,  | 
            
            
              | 5628 | 
                              amount            => 0 - 12,  | 
            
            
              | 5629 | 
                              interface         => 'something',  | 
            
            
              | 5630 | 
                          }  | 
            
            
              | 5631 | 
                      )->store();  | 
            
            
              | 5632 | 
               | 
            
            
              | 5633 | 
                      my $offset = Koha::Account::Offset->new(  | 
            
            
              | 5634 | 
                          { | 
            
            
              | 5635 | 
                              credit_id => $paymentLine->id,  | 
            
            
              | 5636 | 
                              debit_id  => $debitCharge->id,  | 
            
            
              | 5637 | 
                              type      => 'APPLY',  | 
            
            
              | 5638 | 
                              amount    => 0  | 
            
            
              | 5639 | 
                          }  | 
            
            
              | 5640 | 
                      )->store();  | 
            
            
              | 5641 | 
               | 
            
            
              | 5642 | 
                      $paymentLine->apply( { debits => [$debitCharge] } ); | 
            
            
              | 5643 | 
               | 
            
            
              | 5644 | 
                      is(  | 
            
            
              | 5645 | 
                          Koha::Items->find( $item->itemnumber )->itemlost, $status,  | 
            
            
              | 5646 | 
                          "Payment should set itemlost to status $status"  | 
            
            
              | 5647 | 
                      );  | 
            
            
              | 5648 | 
                  }  | 
            
            
              | 5649 | 
              };  | 
            
            
              | 5650 | 
               | 
            
            
              | 5651 | 
              # Test for UpdateItemLostStatusWhenWriteOff  | 
            
            
              | 5652 | 
              subtest 'Update lost item to authorized value on write-off of balance' => sub { | 
            
            
              | 5653 | 
                  plan tests => 5;  | 
            
            
              | 5654 | 
               | 
            
            
              | 5655 | 
                  my $library = $builder->build_object( { class => "Koha::Libraries" } ); | 
            
            
              | 5656 | 
                  my $manager = $builder->build_object( { class => "Koha::Patrons" } ); | 
            
            
              | 5657 | 
                  t::lib::Mocks::mock_userenv( { patron => $manager, branchcode => $manager->branchcode } ); | 
            
            
              | 5658 | 
               | 
            
            
              | 5659 | 
                  my $biblio = $builder->build_sample_biblio;  | 
            
            
              | 5660 | 
                  my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); | 
            
            
              | 5661 | 
               | 
            
            
              | 5662 | 
                  for my $status ( 2 .. 6 ) { | 
            
            
              | 5663 | 
                      t::lib::Mocks::mock_preference( 'UpdateItemLostStatusWhenWriteOff', $status );  | 
            
            
              | 5664 | 
               | 
            
            
              | 5665 | 
                      my $item = $builder->build_sample_item(  | 
            
            
              | 5666 | 
                          { | 
            
            
              | 5667 | 
                              biblionumber     => $biblio->biblionumber,  | 
            
            
              | 5668 | 
                              library          => $library->branchcode,  | 
            
            
              | 5669 | 
                              replacementprice => 99,  | 
            
            
              | 5670 | 
                              itype            => $itemtype,  | 
            
            
              | 5671 | 
                              itemlost         => 1,  | 
            
            
              | 5672 | 
                          }  | 
            
            
              | 5673 | 
                      );  | 
            
            
              | 5674 | 
               | 
            
            
              | 5675 | 
                      my $debitCharge = Koha::Account::Line->new(  | 
            
            
              | 5676 | 
                          { | 
            
            
              | 5677 | 
                              borrowernumber    => $patron->borrowernumber,  | 
            
            
              | 5678 | 
                              debit_type_code   => 'LOST',  | 
            
            
              | 5679 | 
                              status            => undef,  | 
            
            
              | 5680 | 
                              itemnumber        => $item->itemnumber,  | 
            
            
              | 5681 | 
                              amount            => 12,  | 
            
            
              | 5682 | 
                              amountoutstanding => 12,  | 
            
            
              | 5683 | 
                              interface         => 'something',  | 
            
            
              | 5684 | 
                          }  | 
            
            
              | 5685 | 
                      )->store();  | 
            
            
              | 5686 | 
               | 
            
            
              | 5687 | 
                      my $writeOffLine = Koha::Account::Line->new(  | 
            
            
              | 5688 | 
                          { | 
            
            
              | 5689 | 
                              borrowernumber    => $patron->borrowernumber,  | 
            
            
              | 5690 | 
                              credit_type_code  => 'WRITEOFF',  | 
            
            
              | 5691 | 
                              status            => undef,  | 
            
            
              | 5692 | 
                              itemnumber        => $item->itemnumber,  | 
            
            
              | 5693 | 
                              amountoutstanding => 0 - 12,  | 
            
            
              | 5694 | 
                              amount            => 0 - 12,  | 
            
            
              | 5695 | 
                              interface         => 'something',  | 
            
            
              | 5696 | 
                          }  | 
            
            
              | 5697 | 
                      )->store();  | 
            
            
              | 5698 | 
               | 
            
            
              | 5699 | 
                      my $offset = Koha::Account::Offset->new(  | 
            
            
              | 5700 | 
                          { | 
            
            
              | 5701 | 
                              credit_id => $writeOffLine->id,  | 
            
            
              | 5702 | 
                              debit_id  => $debitCharge->id,  | 
            
            
              | 5703 | 
                              type      => 'APPLY',  | 
            
            
              | 5704 | 
                              amount    => 0  | 
            
            
              | 5705 | 
                          }  | 
            
            
              | 5706 | 
                      )->store();  | 
            
            
              | 5707 | 
               | 
            
            
              | 5708 | 
                      $writeOffLine->apply( { debits => [$debitCharge] } ); | 
            
            
              | 5709 | 
               | 
            
            
              | 5710 | 
                      is(  | 
            
            
              | 5711 | 
                          Koha::Items->find( $item->itemnumber )->itemlost, $status,  | 
            
            
              | 5712 | 
                          "Write-off should set itemlost to status $status"  | 
            
            
              | 5713 | 
                      );  | 
            
            
              | 5714 | 
                  }  | 
            
            
              | 5715 | 
              };  | 
            
            
              | 5716 | 
               | 
            
        
          | 5490 | 
          subtest 'Filling a hold should cancel existing transfer' => sub { | 
          5717 | 
          subtest 'Filling a hold should cancel existing transfer' => sub { | 
        
        
          | 5491 | 
              plan tests => 4;  | 
          5718 | 
              plan tests => 4;  | 
        
        
          | 5492 | 
           | 
          5719 | 
           | 
        
            
              | 5493 | 
              -   | 
               | 
               |