use Modern::Perl;
-use Test::More tests => 41;
+use Test::More tests => 34;
use Test::MockModule;
use Test::Warn;
can_ok( 'C4::Accounts',
qw(
- getnextacctno
chargelostitem
manualinvoice
purge_zero_balance_fees )
branch => $branchcode,
};
});
+$context->mock( 'interface', sub { return "commandline" } );
my $userenv_branchcode = $branchcode;
-# Test chargelostitem
+# Test manualinvoice
my $itemtype = $builder->build( { source => 'Itemtype' } );
my $item = $builder->build( { source => 'Item', value => { itype => $itemtype->{itemtype} } } );
my $patron = $builder->build( { source => 'Borrower' } );
my $amount = '5.000000';
my $description = "Test fee!";
-chargelostitem( $patron->{borrowernumber}, $item->{itemnumber}, $amount, $description );
-my ($accountline) = Koha::Account::Lines->search(
- {
- borrowernumber => $patron->{borrowernumber}
- }
-);
-is( $accountline->amount, $amount, 'Accountline amount set correctly for chargelostitem' );
-is( $accountline->description, $description, 'Accountline description set correctly for chargelostitem' );
-is( $accountline->branchcode, $branchcode, 'Accountline branchcode set correctly for chargelostitem' );
-$dbh->do(q|DELETE FROM accountlines|);
-
-# Test manualinvoice, reuse some of the vars from testing chargelostitem
my $type = 'L';
my $note = 'Test note!';
-manualinvoice( $patron->{borrowernumber}, $item->{itemnumber}, $description, $type, $amount, $note );
-($accountline) = Koha::Account::Lines->search(
+warning_like {
+ C4::Accounts::manualinvoice( $patron->{borrowernumber},
+ $item->{itemnumber}, $description, $type, $amount, $note )
+}
+qr/C4::Accounts::manualinvoice is deprecated in favor of Koha::Account->add_debit/,
+ "deprecation warning received for manualinvoice";
+my ($accountline) = Koha::Account::Lines->search(
{
borrowernumber => $patron->{borrowernumber}
}
is( $accountline->note, $note, 'Accountline note set correctly for manualinvoice' );
is( $accountline->branchcode, $branchcode, 'Accountline branchcode set correctly for manualinvoice' );
-# Test _FixAccountForLostAndReturned, use the accountline from the manualinvoice to test
-C4::Circulation::_FixAccountForLostAndReturned( $item->{itemnumber} );
-my ( $accountline_fee, $accountline_payment ) = Koha::Account::Lines->search(
- {
- borrowernumber => $patron->{borrowernumber}
- }
-);
-is( $accountline_fee->accounttype, 'LR', 'Lost item fee account type updated to LR' );
-is( $accountline_fee->amountoutstanding, '0.000000', 'Lost item fee amount outstanding updated to 0' );
-is( $accountline_payment->accounttype, 'CR', 'Lost item fee account type is CR' );
-is( $accountline_payment->amount, "-$amount", 'Lost item refund amount is correct' );
-is( $accountline_payment->branchcode, $branchcode, 'Lost item refund branchcode is set correctly' );
$dbh->do(q|DELETE FROM accountlines|);
# Testing purge_zero_balance_fees
borrowernumber,
amountoutstanding,
date,
- description
+ description,
+ interface
)
- VALUES ( ?, ?, (select date_sub(CURRENT_DATE, INTERVAL ? DAY) ), ? )"
+ VALUES ( ?, ?, (select date_sub(CURRENT_DATE, INTERVAL ? DAY) ), ?, ? )"
);
my $days = 5;
my $borrower = Koha::Patron->new( { firstname => 'Test', surname => 'Patron', categorycode => $categorycode, branchcode => $branchcode } )->store();
for my $data ( @test_data ) {
- $sth->execute($borrower->borrowernumber, $data->{amount}, $data->{days_ago}, $data->{description});
+ $sth->execute($borrower->borrowernumber, $data->{amount}, $data->{days_ago}, $data->{description}, 'commandline');
}
purge_zero_balance_fees( $days );
my $account = Koha::Account->new({ patron_id => $borrower->id });
- my $line1 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amountoutstanding => 100 })->store();
- my $line2 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amountoutstanding => 200 })->store();
+ my $line1 = $account->add_debit({ type => 'account', amount => 100, interface => 'commandline' });
+ my $line2 = $account->add_debit({ type => 'account', amount => 200, interface => 'commandline' });
$sth = $dbh->prepare("SELECT count(*) FROM accountlines");
$sth->execute;
$note = $sth->fetchrow_array;
is($note,'$200.00 payment note', '$200.00 payment note is registered');
- my $line3 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amountoutstanding => 42, accounttype => 'TEST' })->store();
+ my $line3 = $account->add_debit({ type => 'account', amount => 42, interface => 'commandline' });
my $payment_id = $account->pay( { lines => [$line3], amount => 42 } );
my $payment = Koha::Account::Lines->find( $payment_id );
is( $payment->amount(), '-42.000000', "Payment paid the specified fine" );
$line3 = Koha::Account::Lines->find( $line3->id );
is( $line3->amountoutstanding, '0.000000', "Specified fine is paid" );
- is( $payment->branchcode, $userenv_branchcode, 'Branchcode set correctly' );
+ is( $payment->branchcode, undef, 'branchcode passed, then undef' );
};
subtest "Koha::Account::pay particular line tests" => sub {
my $account = Koha::Account->new({ patron_id => $borrower->id });
- my $line1 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amountoutstanding => 1 })->store();
- my $line2 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amountoutstanding => 2 })->store();
- my $line3 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amountoutstanding => 3 })->store();
- my $line4 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amountoutstanding => 4 })->store();
+ my $line1 = $account->add_debit({ type => 'account', amount => 1, interface => 'commandline' });
+ my $line2 = $account->add_debit({ type => 'account', amount => 2, interface => 'commandline' });
+ my $line3 = $account->add_debit({ type => 'account', amount => 3, interface => 'commandline' });
+ my $line4 = $account->add_debit({ type => 'account', amount => 4, interface => 'commandline' });
is( $account->balance(), 10, "Account balance is 10" );
my $account = Koha::Account->new({ patron_id => $borrower->id });
- my $line = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amountoutstanding => 42 })->store();
+ my $line = $account->add_debit({ type => 'account', amount => 42, interface => 'commandline' });
is( $account->balance(), 42, "Account balance is 42" );
$patron->delete;
};
-subtest "Koha::Account::chargelostitem tests" => sub {
- plan tests => 40;
+subtest "C4::Accounts::chargelostitem tests" => sub {
+ plan tests => 3;
- my $lostfine;
- my $procfee;
+ my $branch = $builder->build( { source => 'Branch' } );
+ my $branchcode = $branch->{branchcode};
+
+ my $staff = $builder->build( { source => 'Borrower' } );
+ my $staff_id = $staff->{borrowernumber};
+
+ my $module = Test::MockModule->new('C4::Context');
+ $module->mock(
+ 'userenv',
+ sub {
+ return {
+ flags => 1,
+ number => $staff_id,
+ branch => $branchcode,
+ };
+ }
+ );
my $itype_no_replace_no_fee = $builder->build({ source => 'Itemtype', value => {
rentalcharge => 0,
my $cli_issue_id_3 = $builder->build({ source => 'Issue', value => { borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3 } })->{issue_id};
my $cli_issue_id_4 = $builder->build({ source => 'Issue', value => { borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4 } })->{issue_id};
- my $duck = Koha::Items->find({itemnumber=>$cli_itemnumber1});
-
- t::lib::Mocks::mock_preference('item-level_itypes', '1');
- t::lib::Mocks::mock_preference('useDefaultReplacementCost', '0');
-
- C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber1, 0, "Perdedor");
- $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'L' });
- $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'PF' });
- ok( !$lostfine, "No lost fine if no replacementcost or default when pref off");
- ok( !$procfee, "No processing fee if no processing fee");
- C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber1, 6.12, "Perdedor");
- $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'L' });
- $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'PF' });
- ok( $lostfine->amount == 6.12, "Lost fine equals replacementcost when pref off and no default set");
- ok( !$procfee, "No processing fee if no processing fee");
- $lostfine->delete();
-
- C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber2, 0, "Perdedor");
- $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'L' });
- $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'PF' });
- ok( !$lostfine, "No lost fine if no replacementcost but default set when pref off");
- ok( !$procfee, "No processing fee if no processing fee");
- C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber2, 6.12, "Perdedor");
- $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'L' });
- $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'PF' });
- ok( $lostfine->amount == 6.12 , "Lost fine equals replacementcost when pref off and default set");
- ok( !$procfee, "No processing fee if no processing fee");
- $lostfine->delete();
-
- C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber3, 0, "Perdedor");
- $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'L' });
- $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'PF' });
- ok( !$lostfine, "No lost fine if no replacementcost and no default set when pref off");
- ok( $procfee->amount == 8.16, "Processing fee if processing fee");
- is( $procfee->issue_id, $cli_issue_id_3, "Processing fee issue id is correct" );
- $procfee->delete();
- C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber3, 6.12, "Perdedor");
- $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'L' });
- $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'PF' });
- ok( $lostfine->amount == 6.12 , "Lost fine equals replacementcost when pref off and no default set");
- ok( $procfee->amount == 8.16, "Processing fee if processing fee");
- is( $procfee->issue_id, $cli_issue_id_3, "Processing fee issue id is correct" );
- $lostfine->delete();
- $procfee->delete();
-
- C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 0, "Perdedor");
- $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'L' });
- $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'PF' });
- ok( !$lostfine, "No lost fine if no replacementcost but default set when pref off");
- ok( $procfee->amount == 2.04, "Processing fee if processing fee");
- is( $procfee->issue_id, $cli_issue_id_4, "Processing fee issue id is correct" );
- $procfee->delete();
- C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 6.12, "Perdedor");
- $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'L' });
- $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'PF' });
- ok( $lostfine->amount == 6.12 , "Lost fine equals replacementcost when pref off and default set");
- ok( $procfee->amount == 2.04, "Processing fee if processing fee");
- is( $procfee->issue_id, $cli_issue_id_4, "Processing fee issue id is correct" );
- $lostfine->delete();
- $procfee->delete();
-
- t::lib::Mocks::mock_preference('useDefaultReplacementCost', '1');
-
- C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber1, 0, "Perdedor");
- $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'L' });
- $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'PF' });
- ok( !$lostfine, "No lost fine if no replacementcost or default when pref on");
- ok( !$procfee, "No processing fee if no processing fee");
- C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber1, 6.12, "Perdedor");
- $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'L' });
- $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'PF' });
- is( $lostfine->amount, "6.120000", "Lost fine equals replacementcost when pref on and no default set");
- ok( !$procfee, "No processing fee if no processing fee");
-
- C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber2, 0, "Perdedor");
- $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'L' });
- $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'PF' });
- is( $lostfine->amount(), "16.320000", "Lost fine is default if no replacementcost but default set when pref on");
- ok( !$procfee, "No processing fee if no processing fee");
- $lostfine->delete();
- C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber2, 6.12, "Perdedor");
- $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'L' });
- $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'PF' });
- is( $lostfine->amount, "6.120000" , "Lost fine equals replacementcost when pref on and default set");
- ok( !$procfee, "No processing fee if no processing fee");
-
- C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber3, 0, "Perdedor");
- $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'L' });
- $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'PF' });
- ok( !$lostfine, "No lost fine if no replacementcost and default not set when pref on");
- is( $procfee->amount, "8.160000", "Processing fee if processing fee");
- is( $procfee->issue_id, $cli_issue_id_3, "Processing fee issue id is correct" );
- $procfee->delete();
- C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber3, 6.12, "Perdedor");
- $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'L' });
- $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'PF' });
- is( $lostfine->amount, "6.120000", "Lost fine equals replacementcost when pref on and no default set");
- is( $procfee->amount, "8.160000", "Processing fee if processing fee");
- is( $procfee->issue_id, $cli_issue_id_3, "Processing fee issue id is correct" );
-
- C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 0, "Perdedor");
- $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'L' });
- $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'PF' });
- is( $lostfine->amount, "4.080000", "Lost fine is default if no replacementcost but default set when pref on");
- is( $procfee->amount, "2.040000", "Processing fee if processing fee");
- is( $procfee->issue_id, $cli_issue_id_4, "Processing fee issue id is correct" );
- $lostfine->delete();
- $procfee->delete();
- C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 6.12, "Perdedor");
- $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'L' });
- $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'PF' });
- is( $lostfine->amount, "6.120000", "Lost fine equals replacementcost when pref on and default set");
- is( $procfee->amount, "2.040000", "Processing fee if processing fee");
- is( $procfee->issue_id, $cli_issue_id_4, "Processing fee issue id is correct" );
+ my $lostfine;
+ my $procfee;
+
+ subtest "fee application tests" => sub {
+ plan tests => 40;
+
+ t::lib::Mocks::mock_preference('item-level_itypes', '1');
+ t::lib::Mocks::mock_preference('useDefaultReplacementCost', '0');
+
+ C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber1, 0, "Perdedor");
+ $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'L' });
+ $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'PF' });
+ ok( !$lostfine, "No lost fine if no replacementcost or default when pref off");
+ ok( !$procfee, "No processing fee if no processing fee");
+ C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber1, 6.12, "Perdedor");
+ $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'L' });
+ $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'PF' });
+ ok( $lostfine->amount == 6.12, "Lost fine equals replacementcost when pref off and no default set");
+ ok( !$procfee, "No processing fee if no processing fee");
+ $lostfine->delete();
+
+ C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber2, 0, "Perdedor");
+ $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'L' });
+ $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'PF' });
+ ok( !$lostfine, "No lost fine if no replacementcost but default set when pref off");
+ ok( !$procfee, "No processing fee if no processing fee");
+ C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber2, 6.12, "Perdedor");
+ $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'L' });
+ $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'PF' });
+ ok( $lostfine->amount == 6.12 , "Lost fine equals replacementcost when pref off and default set");
+ ok( !$procfee, "No processing fee if no processing fee");
+ $lostfine->delete();
+
+ C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber3, 0, "Perdedor");
+ $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'L' });
+ $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'PF' });
+ ok( !$lostfine, "No lost fine if no replacementcost and no default set when pref off");
+ ok( $procfee->amount == 8.16, "Processing fee if processing fee");
+ is( $procfee->issue_id, $cli_issue_id_3, "Processing fee issue id is correct" );
+ $procfee->delete();
+ C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber3, 6.12, "Perdedor");
+ $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'L' });
+ $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'PF' });
+ ok( $lostfine->amount == 6.12 , "Lost fine equals replacementcost when pref off and no default set");
+ ok( $procfee->amount == 8.16, "Processing fee if processing fee");
+ is( $procfee->issue_id, $cli_issue_id_3, "Processing fee issue id is correct" );
+ $lostfine->delete();
+ $procfee->delete();
+
+ C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 0, "Perdedor");
+ $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'L' });
+ $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'PF' });
+ ok( !$lostfine, "No lost fine if no replacementcost but default set when pref off");
+ ok( $procfee->amount == 2.04, "Processing fee if processing fee");
+ is( $procfee->issue_id, $cli_issue_id_4, "Processing fee issue id is correct" );
+ $procfee->delete();
+ C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 6.12, "Perdedor");
+ $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'L' });
+ $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'PF' });
+ ok( $lostfine->amount == 6.12 , "Lost fine equals replacementcost when pref off and default set");
+ ok( $procfee->amount == 2.04, "Processing fee if processing fee");
+ is( $procfee->issue_id, $cli_issue_id_4, "Processing fee issue id is correct" );
+ $lostfine->delete();
+ $procfee->delete();
+
+ t::lib::Mocks::mock_preference('useDefaultReplacementCost', '1');
+
+ C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber1, 0, "Perdedor");
+ $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'L' });
+ $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'PF' });
+ ok( !$lostfine, "No lost fine if no replacementcost or default when pref on");
+ ok( !$procfee, "No processing fee if no processing fee");
+ C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber1, 6.12, "Perdedor");
+ $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'L' });
+ $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'PF' });
+ is( $lostfine->amount, "6.120000", "Lost fine equals replacementcost when pref on and no default set");
+ ok( !$procfee, "No processing fee if no processing fee");
+
+ C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber2, 0, "Perdedor");
+ $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'L' });
+ $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'PF' });
+ is( $lostfine->amount(), "16.320000", "Lost fine is default if no replacementcost but default set when pref on");
+ ok( !$procfee, "No processing fee if no processing fee");
+ $lostfine->delete();
+ C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber2, 6.12, "Perdedor");
+ $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'L' });
+ $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'PF' });
+ is( $lostfine->amount, "6.120000" , "Lost fine equals replacementcost when pref on and default set");
+ ok( !$procfee, "No processing fee if no processing fee");
+
+ C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber3, 0, "Perdedor");
+ $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'L' });
+ $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'PF' });
+ ok( !$lostfine, "No lost fine if no replacementcost and default not set when pref on");
+ is( $procfee->amount, "8.160000", "Processing fee if processing fee");
+ is( $procfee->issue_id, $cli_issue_id_3, "Processing fee issue id is correct" );
+ $procfee->delete();
+ C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber3, 6.12, "Perdedor");
+ $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'L' });
+ $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'PF' });
+ is( $lostfine->amount, "6.120000", "Lost fine equals replacementcost when pref on and no default set");
+ is( $procfee->amount, "8.160000", "Processing fee if processing fee");
+ is( $procfee->issue_id, $cli_issue_id_3, "Processing fee issue id is correct" );
+
+ C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 0, "Perdedor");
+ $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'L' });
+ $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'PF' });
+ is( $lostfine->amount, "4.080000", "Lost fine is default if no replacementcost but default set when pref on");
+ is( $procfee->amount, "2.040000", "Processing fee if processing fee");
+ is( $procfee->issue_id, $cli_issue_id_4, "Processing fee issue id is correct" );
+ $lostfine->delete();
+ $procfee->delete();
+ C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 6.12, "Perdedor");
+ $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'L' });
+ $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'PF' });
+ is( $lostfine->amount, "6.120000", "Lost fine equals replacementcost when pref on and default set");
+ is( $procfee->amount, "2.040000", "Processing fee if processing fee");
+ is( $procfee->issue_id, $cli_issue_id_4, "Processing fee issue id is correct" );
+ $lostfine->delete();
+ $procfee->delete();
+ };
+
+ subtest "basic fields tests" => sub {
+ plan tests => 12;
+
+ t::lib::Mocks::mock_preference('ProcessingFeeNote', 'Test Note');
+ C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, '1.99', "Perdedor");
+
+ # Lost Item Fee
+ $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'L' });
+ ok($lostfine, "Lost fine created");
+ is($lostfine->manager_id, $staff_id, "Lost fine manager_id set correctly");
+ is($lostfine->issue_id, $cli_issue_id_4, "Lost fine issue_id set correctly");
+ is($lostfine->description, "Perdedor", "Lost fine issue_id set correctly");
+ is($lostfine->note, '', "Lost fine does not contain a note");
+ is($lostfine->branchcode, $branchcode, "Lost fine branchcode set correctly");
+
+ # Processing Fee
+ $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'PF' });
+ ok($procfee, "Processing fee created");
+ is($procfee->manager_id, $staff_id, "Processing fee manager_id set correctly");
+ is($procfee->issue_id, $cli_issue_id_4, "Processing fee issue_id set correctly");
+ is($procfee->description, "Perdedor", "Processing fee issue_id set correctly");
+ is($procfee->note, C4::Context->preference("ProcessingFeeNote"), "Processing fee contains note matching ProcessingFeeNote");
+ is($procfee->branchcode, $branchcode, "Processing fee branchcode set correctly");
+ $lostfine->delete();
+ $procfee->delete();
+ };
+
+ subtest "FinesLog tests" => sub {
+ plan tests => 2;
+
+ my $action_logs = $schema->resultset('ActionLog')->search()->count;
+
+ t::lib::Mocks::mock_preference( 'FinesLog', 0 );
+ C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 0, "Perdedor");
+ $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'L' });
+ $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'PF' });
+ is( $schema->resultset('ActionLog')->count(), $action_logs + 0, 'No logs were added' );
+ $lostfine->delete();
+ $procfee->delete();
+
+ t::lib::Mocks::mock_preference( 'FinesLog', 1 );
+ C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 0, "Perdedor");
+ $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'L' });
+ $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'PF' });
+ is( $schema->resultset('ActionLog')->count(), $action_logs + 2, 'Logs were added' );
+ $lostfine->delete();
+ $procfee->delete();
+ };
# Cleanup - this must be replaced with a transaction per subtest
Koha::Patrons->find($cli_borrowernumber)->checkouts->delete;
plan tests => 21;
my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
+ my $account = $patron->account;
my $today = dt_from_string;
my $res = 3;
my $rent = 5;
my $manual = 7;
- Koha::Account::Line->new(
+ $account->add_debit(
{
- borrowernumber => $patron->borrowernumber,
- accountno => 1,
- date => $today,
- description => 'a Res fee',
- accounttype => 'Res',
- amountoutstanding => $res,
+ description => 'a Res fee',
+ type => 'reserve',
+ amount => $res,
+ interface => 'commandline'
}
- )->store;
- Koha::Account::Line->new(
+ );
+ $account->add_debit(
{
- borrowernumber => $patron->borrowernumber,
- accountno => 2,
- date => $today,
- description => 'a Rental fee',
- accounttype => 'Rent',
- amountoutstanding => $rent,
+ description => 'a Rental fee',
+ type => 'rent',
+ amount => $rent,
+ interface => 'commandline'
}
- )->store;
+ );
Koha::Account::Line->new(
{
borrowernumber => $patron->borrowernumber,
- accountno => 3,
date => $today,
description => 'a Manual invoice fee',
accounttype => 'Copie',
amountoutstanding => $manual,
+ interface => 'commandline'
}
)->store;
Koha::AuthorisedValue->new(
}
)->store;
- my $account = $patron->account;
t::lib::Mocks::mock_preference( 'HoldsInNoissuesCharge', 0 );
t::lib::Mocks::mock_preference( 'RentalsInNoissuesCharge', 0 );
}
);
- my $debit = Koha::Account::Line->new({ borrowernumber => $patron->id, date => '1900-01-01', amountoutstanding => 0 })->store();
- my $credit = Koha::Account::Line->new({ borrowernumber => $patron->id, date => '1900-01-01', amountoutstanding => -5 })->store();
+ my $debit = Koha::Account::Line->new({ borrowernumber => $patron->id, date => '1900-01-01', amountoutstanding => 0, interface => 'commandline' })->store();
+ my $credit = Koha::Account::Line->new({ borrowernumber => $patron->id, date => '1900-01-01', amountoutstanding => -5, interface => 'commandline' })->store();
my $offset = Koha::Account::Offset->new({ credit_id => $credit->id, debit_id => $debit->id, type => 'Payment', amount => 0 })->store();
purge_zero_balance_fees( 1 );
my $debit_2 = Koha::Account::Lines->find( $debit->id );
ok( $credit_2, 'Credit was correctly not deleted when credit has balance' );
is( Koha::Account::Lines->count({ borrowernumber => $patron->id }), 2, "The 2 account lines still exists" );
- $debit = Koha::Account::Line->new({ borrowernumber => $patron->id, date => '1900-01-01', amountoutstanding => 5 })->store();
- $credit = Koha::Account::Line->new({ borrowernumber => $patron->id, date => '1900-01-01', amountoutstanding => 0 })->store();
+ $debit = Koha::Account::Line->new({ borrowernumber => $patron->id, date => '1900-01-01', amountoutstanding => 5, interface => 'commanline' })->store();
+ $credit = Koha::Account::Line->new({ borrowernumber => $patron->id, date => '1900-01-01', amountoutstanding => 0, interface => 'commandline' })->store();
$offset = Koha::Account::Offset->new({ credit_id => $credit->id, debit_id => $debit->id, type => 'Payment', amount => 0 })->store();
purge_zero_balance_fees( 1 );
$debit_2 = $credit_2 = undef;
ok( $credit_2, 'Credit was correctly not deleted when debit has balance' );
is( Koha::Account::Lines->count({ borrowernumber => $patron->id }), 2 + 2, "The 2 + 2 account lines still exists" );
- $debit = Koha::Account::Line->new({ borrowernumber => $patron->id, date => '1900-01-01', amountoutstanding => 0 })->store();
- $credit = Koha::Account::Line->new({ borrowernumber => $patron->id, date => '1900-01-01', amountoutstanding => 0 })->store();
+ $debit = Koha::Account::Line->new({ borrowernumber => $patron->id, date => '1900-01-01', amountoutstanding => 0, interface => 'commandline' })->store();
+ $credit = Koha::Account::Line->new({ borrowernumber => $patron->id, date => '1900-01-01', amountoutstanding => 0, interface => 'commandline' })->store();
$offset = Koha::Account::Offset->new({ credit_id => $credit->id, debit_id => $debit->id, type => 'Payment', amount => 0 })->store();
purge_zero_balance_fees( 1 );
$debit_2 = Koha::Account::Lines->find( $debit->id );
is( Koha::Account::Lines->count({ borrowernumber => $patron->id }), 2 + 2, "The 2 + 2 account lines still exists, the last 2 have been deleted ok" );
};
-subtest "Koha::Account::Line::void tests" => sub {
-
- plan tests => 15;
-
- # Create a borrower
- my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
- my $branchcode = $builder->build({ source => 'Branch' })->{ branchcode };
-
- my $borrower = Koha::Patron->new( {
- cardnumber => 'dariahall',
- surname => 'Hall',
- firstname => 'Daria',
- } );
- $borrower->categorycode( $categorycode );
- $borrower->branchcode( $branchcode );
- $borrower->store;
-
- my $account = Koha::Account->new({ patron_id => $borrower->id });
-
- my $line1 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amount => 10, amountoutstanding => 10 })->store();
- my $line2 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amount => 20, amountoutstanding => 20 })->store();
-
- is( $account->balance(), 30, "Account balance is 30" );
- is( $line1->amountoutstanding, 10, 'First fee has amount outstanding of 10' );
- is( $line2->amountoutstanding, 20, 'Second fee has amount outstanding of 20' );
-
- my $id = $account->pay(
- {
- lines => [$line1, $line2],
- amount => 30,
- }
- );
-
- my $account_payment = Koha::Account::Lines->find( $id );
-
- is( $account->balance(), 0, "Account balance is 0" );
-
- $line1->_result->discard_changes();
- $line2->_result->discard_changes();
- is( $line1->amountoutstanding+0, 0, 'First fee has amount outstanding of 0' );
- is( $line2->amountoutstanding+0, 0, 'Second fee has amount outstanding of 0' );
-
- my $ret = $account_payment->void();
-
- is( ref($ret), 'Koha::Account::Line', 'Void returns the account line' );
- is( $account->balance(), 30, "Account balance is again 30" );
-
- $account_payment->_result->discard_changes();
- $line1->_result->discard_changes();
- $line2->_result->discard_changes();
-
- is( $account_payment->accounttype, 'VOID', 'Voided payment accounttype is VOID' );
- is( $account_payment->amount+0, 0, 'Voided payment amount is 0' );
- is( $account_payment->amountoutstanding+0, 0, 'Voided payment amount outstanding is 0' );
-
- is( $line1->amountoutstanding+0, 10, 'First fee again has amount outstanding of 10' );
- is( $line2->amountoutstanding+0, 20, 'Second fee again has amount outstanding of 20' );
-
- # Accountlines that are not credits should be un-voidable
- my $line1_pre = $line1->unblessed();
- $ret = $line1->void();
- $line1->_result->discard_changes();
- my $line1_post = $line1->unblessed();
- is( $ret, undef, 'Attempted void on non-credit returns undef' );
- is_deeply( $line1_pre, $line1_post, 'Non-credit account line cannot be voided' )
-};
subtest "Koha::Account::Offset credit & debit tests" => sub {
my $account = Koha::Account->new({ patron_id => $borrower->id });
- my $line1 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amount => 10, amountoutstanding => 10 })->store();
- my $line2 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amount => 20, amountoutstanding => 20 })->store();
+ my $line1 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amount => 10, amountoutstanding => 10, interface => 'commandline' })->store();
+ my $line2 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amount => 20, amountoutstanding => 20, interface => 'commandline' })->store();
my $id = $account->pay(
{
}
)->store();
+ my $manager = $builder->build_object({ class => "Koha::Patrons" });
+ my $context = new Test::MockModule('C4::Context');
+ $context->mock( 'userenv', sub {
+ return {
+ number => $manager->borrowernumber,
+ branch => $manager->branchcode,
+ };
+ });
my $account = Koha::Account->new({ patron_id => $borrower->id });
- my $line = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amountoutstanding => 27 })->store();
+ my $line = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amountoutstanding => 27, interface => 'commandline' })->store();
my $letter = Koha::Notice::Templates->find( { code => 'ACCOUNT_PAYMENT' } );
$letter->content('[%- USE Price -%]A payment of [% credit.amount * -1 | $Price %] has been applied to your account.');
$letter->store();
t::lib::Mocks::mock_preference('UseEmailReceipts', '0');
-
my $id = $account->pay( { amount => 1 } );
is( Koha::Notice::Messages->search()->count(), 0, 'Notice for payment not sent if UseEmailReceipts is disabled' );