|
Lines 1-16
Link Here
|
| 1 |
#!/usr/bin/perl |
1 |
#!/usr/bin/perl |
| 2 |
# |
2 |
# |
| 3 |
# This Koha test module is a stub! |
3 |
# This Koha test module is a stub! |
| 4 |
# Add more tests here!!! |
4 |
# Add more tests here!!! |
| 5 |
|
5 |
|
| 6 |
use strict; |
6 |
use strict; |
| 7 |
use warnings; |
7 |
use warnings; |
| 8 |
|
8 |
|
| 9 |
use Test::More tests => 1; |
9 |
use Test::More tests => 19; |
|
|
10 |
|
| 11 |
use C4::Context; |
| 10 |
|
12 |
|
| 11 |
BEGIN { |
13 |
BEGIN { |
| 12 |
use_ok('C4::Accounts'); |
14 |
use_ok('Koha::Database'); |
|
|
15 |
use_ok('Koha::Accounts'); |
| 16 |
use_ok('Koha::Accounts::DebitTypes'); |
| 17 |
use_ok('Koha::Accounts::CreditTypes'); |
| 13 |
} |
18 |
} |
| 14 |
|
19 |
|
|
|
20 |
## Intial Setup ## |
| 21 |
my $borrower = Koha::Database->new()->schema->resultset('Borrower')->create( |
| 22 |
{ |
| 23 |
surname => 'Test', |
| 24 |
categorycode => 'S', |
| 25 |
branchcode => 'MPL', |
| 26 |
account_balance => 0, |
| 27 |
} |
| 28 |
); |
| 29 |
|
| 30 |
my $biblio = |
| 31 |
Koha::Database->new()->schema->resultset('Biblio') |
| 32 |
->create( { title => "Test Record" } ); |
| 33 |
my $biblioitem = |
| 34 |
Koha::Database->new()->schema->resultset('Biblioitem') |
| 35 |
->create( { biblionumber => $biblio->biblionumber() } ); |
| 36 |
my $item = Koha::Database->new()->schema->resultset('Item')->create( |
| 37 |
{ |
| 38 |
biblionumber => $biblio->biblionumber(), |
| 39 |
biblioitemnumber => $biblioitem->biblioitemnumber(), |
| 40 |
replacementprice => 25.00, |
| 41 |
barcode => q{TEST_ITEM_BARCODE} |
| 42 |
} |
| 43 |
); |
| 44 |
|
| 45 |
my $issue = Koha::Database->new()->schema->resultset('Issue')->create( |
| 46 |
{ |
| 47 |
borrowernumber => $borrower->borrowernumber(), |
| 48 |
itemnumber => $item->itemnumber(), |
| 49 |
} |
| 50 |
); |
| 51 |
## END initial setup |
| 52 |
|
| 53 |
ok( Koha::Accounts::DebitTypes::Fine eq 'FINE', 'Test DebitTypes::Fine' ); |
| 54 |
ok( Koha::Accounts::DebitTypes::Lost eq 'LOST', 'Test DebitTypes::Lost' ); |
| 55 |
ok( |
| 56 |
Koha::Accounts::DebitTypes::IsValid('FINE'), |
| 57 |
'Test DebitTypes::IsValid with valid debit type' |
| 58 |
); |
| 59 |
ok( |
| 60 |
!Koha::Accounts::DebitTypes::IsValid('Not A Valid Fee Type'), |
| 61 |
'Test DebitTypes::IsValid with an invalid debit type' |
| 62 |
); |
| 63 |
my $authorised_value = |
| 64 |
Koha::Database->new()->schema->resultset('AuthorisedValue')->create( |
| 65 |
{ |
| 66 |
category => 'MANUAL_INV', |
| 67 |
authorised_value => 'TEST', |
| 68 |
lib => 'Test', |
| 69 |
} |
| 70 |
); |
| 71 |
ok( Koha::Accounts::DebitTypes::IsValid('TEST'), |
| 72 |
'Test DebitTypes::IsValid with valid authorised value debit type' ); |
| 73 |
$authorised_value->delete(); |
| 74 |
|
| 75 |
my $debit = AddDebit( |
| 76 |
{ |
| 77 |
borrower => $borrower, |
| 78 |
amount => 5.00, |
| 79 |
type => Koha::Accounts::DebitTypes::Fine, |
| 80 |
branchcode => 'MPL', |
| 81 |
} |
| 82 |
); |
| 83 |
ok( $debit, "AddDebit returned a valid debit id " . $debit->id() ); |
| 84 |
|
| 85 |
ok( |
| 86 |
$borrower->account_balance() == 5.00, |
| 87 |
"Borrower's account balance updated correctly" |
| 88 |
); |
| 89 |
|
| 90 |
my $debit2 = AddDebit( |
| 91 |
{ |
| 92 |
borrower => $borrower, |
| 93 |
amount => 7.00, |
| 94 |
type => Koha::Accounts::DebitTypes::Fine, |
| 95 |
branchcode => 'MPL', |
| 96 |
} |
| 97 |
); |
| 98 |
|
| 99 |
my $credit = AddCredit( |
| 100 |
{ |
| 101 |
borrower => $borrower, |
| 102 |
type => Koha::Accounts::CreditTypes::Payment, |
| 103 |
amount => 9.00, |
| 104 |
branchcode => 'MPL', |
| 105 |
} |
| 106 |
); |
| 107 |
|
| 108 |
RecalculateAccountBalance( { borrower => $borrower } ); |
| 109 |
ok( |
| 110 |
sprintf( "%.2f", $borrower->account_balance() ) eq "3.00", |
| 111 |
"RecalculateAccountBalance updated balance correctly." |
| 112 |
); |
| 113 |
|
| 114 |
Koha::Database->new()->schema->resultset('AccountCredit')->create( |
| 115 |
{ |
| 116 |
borrowernumber => $borrower->borrowernumber(), |
| 117 |
type => Koha::Accounts::CreditTypes::Payment, |
| 118 |
amount_paid => 3.00, |
| 119 |
amount_remaining => 3.00, |
| 120 |
} |
| 121 |
); |
| 122 |
NormalizeBalances( { borrower => $borrower } ); |
| 123 |
ok( |
| 124 |
$borrower->account_balance() == 0.00, |
| 125 |
"NormalizeBalances updated balance correctly." |
| 126 |
); |
| 127 |
|
| 128 |
# Adding advance credit with no balance due |
| 129 |
$credit = AddCredit( |
| 130 |
{ |
| 131 |
borrower => $borrower, |
| 132 |
type => Koha::Accounts::CreditTypes::Payment, |
| 133 |
amount => 9.00, |
| 134 |
branchcode => 'MPL', |
| 135 |
} |
| 136 |
); |
| 137 |
ok( |
| 138 |
$borrower->account_balance() == -9, |
| 139 |
'Adding a $9 credit for borrower with 0 balance results in a -9 dollar account balance' |
| 140 |
); |
| 141 |
|
| 142 |
my $debit3 = AddDebit( |
| 143 |
{ |
| 144 |
borrower => $borrower, |
| 145 |
amount => 5.00, |
| 146 |
type => Koha::Accounts::DebitTypes::Fine, |
| 147 |
branchcode => 'MPL', |
| 148 |
} |
| 149 |
); |
| 150 |
ok( |
| 151 |
$borrower->account_balance() == -4, |
| 152 |
'Adding a $5 debit when the balance is negative results in the debit being automatically paid, resulting in a balance of -4' |
| 153 |
); |
| 154 |
|
| 155 |
my $debit4 = AddDebit( |
| 156 |
{ |
| 157 |
borrower => $borrower, |
| 158 |
amount => 6.00, |
| 159 |
type => Koha::Accounts::DebitTypes::Fine, |
| 160 |
branchcode => 'MPL', |
| 161 |
} |
| 162 |
); |
| 163 |
ok( |
| 164 |
$borrower->account_balance() == 2, |
| 165 |
'Adding another debit ( 6.00 ) more than the negative account balance results in a partial credit and a balance due of 2.00' |
| 166 |
); |
| 167 |
$credit = AddCredit( |
| 168 |
{ |
| 169 |
borrower => $borrower, |
| 170 |
type => Koha::Accounts::CreditTypes::WriteOff, |
| 171 |
amount => 2.00, |
| 172 |
branchcode => 'MPL', |
| 173 |
debit_id => $debit4->debit_id(), |
| 174 |
} |
| 175 |
); |
| 176 |
ok( $borrower->account_balance() == 0, |
| 177 |
'WriteOff of remaining 2.00 balance succeeds' ); |
| 178 |
|
| 179 |
my $debit5 = DebitLostItem( |
| 180 |
{ |
| 181 |
borrower => $borrower, |
| 182 |
issue => $issue, |
| 183 |
} |
| 184 |
); |
| 185 |
ok( $borrower->account_balance() == 25, |
| 186 |
'DebitLostItem adds debit for replacement price of item' ); |
| 15 |
|
187 |
|
|
|
188 |
my $lost_credit = |
| 189 |
CreditLostItem( { borrower => $borrower, debit => $debit5 } ); |
| 190 |
ok( |
| 191 |
$borrower->account_balance() == 0, |
| 192 |
'CreditLostItem adds credit for same about as the debit for the lost tiem' |
| 193 |
); |
| 16 |
|
194 |
|
|
|
195 |
## Post test cleanup ## |
| 196 |
$issue->delete(); |
| 197 |
$item->delete(); |
| 198 |
$biblio->delete(); |
| 199 |
$borrower->delete(); |