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