Lines 142-150
for my $data (@test_data) {
Link Here
|
142 |
|
142 |
|
143 |
$dbh->do(q|DELETE FROM accountlines|); |
143 |
$dbh->do(q|DELETE FROM accountlines|); |
144 |
|
144 |
|
145 |
subtest "Koha::Account::pay tests" => sub { |
145 |
subtest "Koha::Account::pay - always AutoReconcile + notes tests" => sub { |
146 |
|
146 |
|
147 |
plan tests => 13; |
147 |
plan tests => 17; |
148 |
|
148 |
|
149 |
# Create a borrower |
149 |
# Create a borrower |
150 |
my $categorycode = $builder->build({ source => 'Category' })->{ categorycode }; |
150 |
my $categorycode = $builder->build({ source => 'Category' })->{ categorycode }; |
Lines 171-182
subtest "Koha::Account::pay tests" => sub {
Link Here
|
171 |
|
171 |
|
172 |
# There is $100 in the account |
172 |
# There is $100 in the account |
173 |
$sth = $dbh->prepare("SELECT amountoutstanding FROM accountlines WHERE borrowernumber=?"); |
173 |
$sth = $dbh->prepare("SELECT amountoutstanding FROM accountlines WHERE borrowernumber=?"); |
174 |
my $amountoutstanding = $dbh->selectcol_arrayref($sth, {}, $borrower->borrowernumber); |
174 |
my $outstanding_debt = $account->outstanding_debits->total_outstanding; |
175 |
my $amountleft = 0; |
175 |
is($outstanding_debt, 300, 'The account has $300 outstanding debt as expected' ); |
176 |
for my $line ( @$amountoutstanding ) { |
176 |
my $outstanding_credit = $account->outstanding_credits->total_outstanding; |
177 |
$amountleft += $line; |
177 |
is($outstanding_credit, 0, 'The account has $0 outstanding credit as expected' ); |
178 |
} |
|
|
179 |
is($amountleft, 300, 'The account has 300$ as expected' ); |
180 |
|
178 |
|
181 |
# We make a $20 payment |
179 |
# We make a $20 payment |
182 |
my $borrowernumber = $borrower->borrowernumber; |
180 |
my $borrowernumber = $borrower->borrowernumber; |
Lines 188-259
subtest "Koha::Account::pay tests" => sub {
Link Here
|
188 |
is( $accountline->payment_type, "TEST_TYPE", "Payment type passed into pay is set in account line correctly" ); |
186 |
is( $accountline->payment_type, "TEST_TYPE", "Payment type passed into pay is set in account line correctly" ); |
189 |
|
187 |
|
190 |
# There is now $280 in the account |
188 |
# There is now $280 in the account |
191 |
$sth = $dbh->prepare("SELECT amountoutstanding FROM accountlines WHERE borrowernumber=?"); |
189 |
$outstanding_debt = $account->outstanding_debits->total_outstanding; |
192 |
$amountoutstanding = $dbh->selectcol_arrayref($sth, {}, $borrower->borrowernumber); |
190 |
is($outstanding_debt, 280, 'The account has $280 outstanding debt as expected' ); |
193 |
$amountleft = 0; |
191 |
$outstanding_credit = $account->outstanding_credits->total_outstanding; |
194 |
for my $line ( @$amountoutstanding ) { |
192 |
is($outstanding_credit, 0, 'The account has $0 outstanding credit as expected' ); |
195 |
$amountleft += $line; |
|
|
196 |
} |
197 |
is($amountleft, 280, 'The account has $280 as expected' ); |
198 |
|
193 |
|
199 |
# Is the payment note well registered |
194 |
# Is the payment note well registered |
200 |
$sth = $dbh->prepare("SELECT note FROM accountlines WHERE borrowernumber=? ORDER BY accountlines_id DESC LIMIT 1"); |
195 |
is($accountline->note,'$20.00 payment note', '$20.00 payment note is registered'); |
201 |
$sth->execute($borrower->borrowernumber); |
|
|
202 |
my $note = $sth->fetchrow_array; |
203 |
is($note,'$20.00 payment note', '$20.00 payment note is registered'); |
204 |
|
196 |
|
205 |
# We attempt to make a -$30 payment (a NEGATIVE payment) |
197 |
# We attempt to make a -$30 payment (a NEGATIVE payment) |
206 |
$data = '-30.00'; |
198 |
$data = '-30.00'; |
207 |
$payment_note = '-$30.00 payment note'; |
199 |
$payment_note = '-$30.00 payment note'; |
208 |
throws_ok { $account->pay( { amount => $data, note => $payment_note } ) } 'Koha::Exceptions::Account::AmountNotPositive', 'Croaked on call to pay with negative amount'; |
200 |
throws_ok { $account->pay( { amount => $data, note => $payment_note } ) } |
|
|
201 |
'Koha::Exceptions::Account::AmountNotPositive', |
202 |
'Croaked on call to pay with negative amount'; |
209 |
|
203 |
|
210 |
#We make a $150 payment ( > 1stLine ) |
204 |
#We make a $150 payment ( > 1stLine ) |
211 |
$data = '150.00'; |
205 |
$data = '150.00'; |
212 |
$payment_note = '$150.00 payment note'; |
206 |
$payment_note = '$150.00 payment note'; |
213 |
$account->pay( { amount => $data, note => $payment_note } ); |
207 |
$id = $account->pay( { amount => $data, note => $payment_note } )->{payment_id}; |
214 |
|
208 |
|
215 |
# There is now $130 in the account |
209 |
# There is now $130 in the account |
216 |
$sth = $dbh->prepare("SELECT amountoutstanding FROM accountlines WHERE borrowernumber=?"); |
210 |
$outstanding_debt = $account->outstanding_debits->total_outstanding; |
217 |
$amountoutstanding = $dbh->selectcol_arrayref($sth, {}, $borrower->borrowernumber); |
211 |
is($outstanding_debt, 130, 'The account has $130 outstanding debt as expected' ); |
218 |
$amountleft = 0; |
212 |
$outstanding_credit = $account->outstanding_credits->total_outstanding; |
219 |
for my $line ( @$amountoutstanding ) { |
213 |
is($outstanding_credit, 0, 'The account has $0 outstanding credit as expected' ); |
220 |
$amountleft += $line; |
|
|
221 |
} |
222 |
is($amountleft, 130, 'The account has $130 as expected' ); |
223 |
|
214 |
|
224 |
# Is the payment note well registered |
215 |
# Is the payment note well registered |
225 |
$sth = $dbh->prepare("SELECT note FROM accountlines WHERE borrowernumber=? ORDER BY accountlines_id DESC LIMIT 1"); |
216 |
$accountline = Koha::Account::Lines->find( $id ); |
226 |
$sth->execute($borrower->borrowernumber); |
217 |
is($accountline->note,'$150.00 payment note', '$150.00 payment note is registered'); |
227 |
$note = $sth->fetchrow_array; |
|
|
228 |
is($note,'$150.00 payment note', '$150.00 payment note is registered'); |
229 |
|
218 |
|
230 |
#We make a $200 payment ( > amountleft ) |
219 |
#We make a $200 payment ( > amountleft ) |
231 |
$data = '200.00'; |
220 |
$data = '200.00'; |
232 |
$payment_note = '$200.00 payment note'; |
221 |
$payment_note = '$200.00 payment note'; |
233 |
$account->pay( { amount => $data, note => $payment_note } ); |
222 |
$id = $account->pay( { amount => $data, note => $payment_note } )->{payment_id}; |
234 |
|
223 |
|
235 |
# There is now -$70 in the account |
224 |
# There is now -$70 in the account |
236 |
$sth = $dbh->prepare("SELECT amountoutstanding FROM accountlines WHERE borrowernumber=?"); |
225 |
$outstanding_debt = $account->outstanding_debits->total_outstanding; |
237 |
$amountoutstanding = $dbh->selectcol_arrayref($sth, {}, $borrower->borrowernumber); |
226 |
is($outstanding_debt, 0, 'The account has $0 outstanding debt as expected' ); |
238 |
$amountleft = 0; |
227 |
$outstanding_credit = $account->outstanding_credits->total_outstanding; |
239 |
for my $line ( @$amountoutstanding ) { |
228 |
is($outstanding_credit, -70, 'The account has -$70 outstanding credit as expected' ); |
240 |
$amountleft += $line; |
|
|
241 |
} |
242 |
is($amountleft, -70, 'The account has -$70 as expected, (credit situation)' ); |
243 |
|
229 |
|
244 |
# Is the payment note well registered |
230 |
# Is the payment note well registered |
245 |
$sth = $dbh->prepare("SELECT note FROM accountlines WHERE borrowernumber=? ORDER BY accountlines_id DESC LIMIT 1"); |
231 |
$accountline = Koha::Account::Lines->find( $id ); |
246 |
$sth->execute($borrower->borrowernumber); |
232 |
is($accountline->note,'$200.00 payment note', '$200.00 payment note is registered'); |
247 |
$note = $sth->fetchrow_array; |
|
|
248 |
is($note,'$200.00 payment note', '$200.00 payment note is registered'); |
249 |
|
233 |
|
250 |
my $line3 = $account->add_debit({ type => 'ACCOUNT', amount => 42, interface => 'commandline' }); |
234 |
my $line3 = $account->add_debit({ type => 'ACCOUNT', amount => 42, interface => 'commandline' }); |
251 |
my $payment_id = $account->pay( { lines => [$line3], amount => 42 } )->{payment_id}; |
235 |
$id = $account->pay( { lines => [$line3], amount => 42 } )->{payment_id}; |
252 |
my $payment = Koha::Account::Lines->find( $payment_id ); |
236 |
$accountline = Koha::Account::Lines->find( $id ); |
253 |
is( $payment->amount()+0, -42, "Payment paid the specified fine" ); |
237 |
is( $accountline->amount()+0, -42, "Payment paid the specified fine" ); |
254 |
$line3 = Koha::Account::Lines->find( $line3->id ); |
238 |
$line3 = Koha::Account::Lines->find( $line3->id ); |
255 |
is( $line3->amountoutstanding+0, 0, "Specified fine is paid" ); |
239 |
is( $line3->amountoutstanding+0, 0, "Specified fine is paid" ); |
256 |
is( $payment->branchcode, undef, 'branchcode passed, then undef' ); |
240 |
is( $accountline->branchcode, undef, 'branchcode passed, then undef' ); |
257 |
}; |
241 |
}; |
258 |
|
242 |
|
259 |
subtest "Koha::Account::pay particular line tests" => sub { |
243 |
subtest "Koha::Account::pay particular line tests" => sub { |
260 |
- |
|
|