+subtest "Koha::Account::non_issues_charges tests" => sub {
+ plan tests => 21;
+
+ my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
+
+ my $today = dt_from_string;
+ my $res = 3;
+ my $rent = 5;
+ my $manual = 7;
+ Koha::Account::Line->new(
+ {
+ borrowernumber => $patron->borrowernumber,
+ accountno => 1,
+ date => $today,
+ description => 'a Res fee',
+ accounttype => 'Res',
+ amountoutstanding => $res,
+ }
+ )->store;
+ Koha::Account::Line->new(
+ {
+ borrowernumber => $patron->borrowernumber,
+ accountno => 2,
+ date => $today,
+ description => 'a Rental fee',
+ accounttype => 'Rent',
+ amountoutstanding => $rent,
+ }
+ )->store;
+ Koha::Account::Line->new(
+ {
+ borrowernumber => $patron->borrowernumber,
+ accountno => 3,
+ date => $today,
+ description => 'a Manual invoice fee',
+ accounttype => 'Copie',
+ amountoutstanding => $manual,
+ }
+ )->store;
+ Koha::AuthorisedValue->new(
+ {
+ category => 'MANUAL_INV',
+ authorised_value => 'Copie',
+ lib => 'Fee for copie',
+ }
+ )->store;
+
+ t::lib::Mocks::mock_preference( 'HoldsInNoissuesCharge', 0 );
+ t::lib::Mocks::mock_preference( 'RentalsInNoissuesCharge', 0 );
+ t::lib::Mocks::mock_preference( 'ManInvInNoissuesCharge', 0 );
+ my ( $total, $non_issues_charges, $other_charges ) =
+ C4::Members::GetMemberAccountBalance( $patron->borrowernumber );
+ is(
+ $total,
+ $res + $rent + $manual,
+ 'Total charges should be Res + Rent + Manual'
+ );
+ is( $non_issues_charges, 0,
+ 'If 0|0|0 there should not have non issues charges' );
+ is( $other_charges, 15, 'If 0|0|0 there should only have other charges' );
+
+ t::lib::Mocks::mock_preference( 'HoldsInNoissuesCharge', 0 );
+ t::lib::Mocks::mock_preference( 'RentalsInNoissuesCharge', 0 );
+ t::lib::Mocks::mock_preference( 'ManInvInNoissuesCharge', 1 );
+ ( $total, $non_issues_charges, $other_charges ) =
+ C4::Members::GetMemberAccountBalance( $patron->borrowernumber );
+ is(
+ $total,
+ $res + $rent + $manual,
+ 'Total charges should be Res + Rent + Manual'
+ );
+ is( $non_issues_charges, $manual,
+ 'If 0|0|1 Only Manual should be a non issue charge' );
+ is(
+ $other_charges,
+ $res + $rent,
+ 'If 0|0|1 Res + Rent should be other charges'
+ );
+
+ t::lib::Mocks::mock_preference( 'HoldsInNoissuesCharge', 0 );
+ t::lib::Mocks::mock_preference( 'RentalsInNoissuesCharge', 1 );
+ t::lib::Mocks::mock_preference( 'ManInvInNoissuesCharge', 0 );
+ ( $total, $non_issues_charges, $other_charges ) =
+ C4::Members::GetMemberAccountBalance( $patron->borrowernumber );
+ is(
+ $total,
+ $res + $rent + $manual,
+ 'Total charges should be Res + Rent + Manual'
+ );
+ is( $non_issues_charges, $rent,
+ 'If 0|1|0 Only Rental should be a non issue charge' );
+ is(
+ $other_charges,
+ $res + $manual,
+ 'If 0|1|0 Rent + Manual should be other charges'
+ );
+
+ t::lib::Mocks::mock_preference( 'HoldsInNoissuesCharge', 0 );
+ t::lib::Mocks::mock_preference( 'RentalsInNoissuesCharge', 1 );
+ t::lib::Mocks::mock_preference( 'ManInvInNoissuesCharge', 1 );
+ ( $total, $non_issues_charges, $other_charges ) =
+ C4::Members::GetMemberAccountBalance( $patron->borrowernumber );
+ is(
+ $total,
+ $res + $rent + $manual,
+ 'Total charges should be Res + Rent + Manual'
+ );
+ is(
+ $non_issues_charges,
+ $rent + $manual,
+ 'If 0|1|1 Rent + Manual should be non issues charges'
+ );
+ is( $other_charges, $res, 'If 0|1|1 there should only have other charges' );
+
+ t::lib::Mocks::mock_preference( 'HoldsInNoissuesCharge', 1 );
+ t::lib::Mocks::mock_preference( 'RentalsInNoissuesCharge', 0 );
+ t::lib::Mocks::mock_preference( 'ManInvInNoissuesCharge', 0 );
+ ( $total, $non_issues_charges, $other_charges ) =
+ C4::Members::GetMemberAccountBalance( $patron->borrowernumber );
+ is(
+ $total,
+ $res + $rent + $manual,
+ 'Total charges should be Res + Rent + Manual'
+ );
+ is( $non_issues_charges, $res,
+ 'If 1|0|0 Only Res should be non issues charges' );
+ is(
+ $other_charges,
+ $rent + $manual,
+ 'If 1|0|0 Rent + Manual should be other charges'
+ );
+
+ t::lib::Mocks::mock_preference( 'HoldsInNoissuesCharge', 1 );
+ t::lib::Mocks::mock_preference( 'RentalsInNoissuesCharge', 1 );
+ t::lib::Mocks::mock_preference( 'ManInvInNoissuesCharge', 0 );
+ ( $total, $non_issues_charges, $other_charges ) =
+ C4::Members::GetMemberAccountBalance( $patron->borrowernumber );
+ is(
+ $total,
+ $res + $rent + $manual,
+ 'Total charges should be Res + Rent + Manual'
+ );
+ is(
+ $non_issues_charges,
+ $res + $rent,
+ 'If 1|1|0 Res + Rent should be non issues charges'
+ );
+ is( $other_charges, $manual,
+ 'If 1|1|0 Only Manual should be other charges' );
+
+ t::lib::Mocks::mock_preference( 'HoldsInNoissuesCharge', 1 );
+ t::lib::Mocks::mock_preference( 'RentalsInNoissuesCharge', 1 );
+ t::lib::Mocks::mock_preference( 'ManInvInNoissuesCharge', 1 );
+ ( $total, $non_issues_charges, $other_charges ) =
+ C4::Members::GetMemberAccountBalance( $patron->borrowernumber );
+ is(
+ $total,
+ $res + $rent + $manual,
+ 'Total charges should be Res + Rent + Manual'
+ );
+ is(
+ $non_issues_charges,
+ $res + $rent + $manual,
+ 'If 1|1|1 Res + Rent + Manual should be non issues charges'
+ );
+ is( $other_charges, 0, 'If 1|1|1 there should not have any other charges' );
+};
+