Lines 132-138
$schema->storage->txn_rollback;
Link Here
|
132 |
|
132 |
|
133 |
subtest 'UpdateFine tests' => sub { |
133 |
subtest 'UpdateFine tests' => sub { |
134 |
|
134 |
|
135 |
plan tests => 25; |
135 |
plan tests => 53; |
136 |
|
136 |
|
137 |
$schema->storage->txn_begin; |
137 |
$schema->storage->txn_begin; |
138 |
|
138 |
|
Lines 168-175
subtest 'UpdateFine tests' => sub {
Link Here
|
168 |
my $fines = Koha::Account::Lines->search( |
168 |
my $fines = Koha::Account::Lines->search( |
169 |
{ borrowernumber => $patron->borrowernumber } ); |
169 |
{ borrowernumber => $patron->borrowernumber } ); |
170 |
is( $fines->count, 0, "No fine added when amount is 0" ); |
170 |
is( $fines->count, 0, "No fine added when amount is 0" ); |
|
|
171 |
# Total : Outstanding : MaxFine |
172 |
# 0 : 0 : 100 |
171 |
|
173 |
|
172 |
# Add fine 1 |
174 |
# Add fine 1 - First Item Overdue |
173 |
UpdateFine( |
175 |
UpdateFine( |
174 |
{ |
176 |
{ |
175 |
issue_id => $checkout1->issue_id, |
177 |
issue_id => $checkout1->issue_id, |
Lines 185-194
subtest 'UpdateFine tests' => sub {
Link Here
|
185 |
is( $fines->count, 1, "Fine added when amount is greater than 0" ); |
187 |
is( $fines->count, 1, "Fine added when amount is greater than 0" ); |
186 |
my $fine = $fines->next; |
188 |
my $fine = $fines->next; |
187 |
is( $fine->amount, '50.000000', "Fine amount correctly set to 50" ); |
189 |
is( $fine->amount, '50.000000', "Fine amount correctly set to 50" ); |
|
|
190 |
is( $fine->amountoutstanding, '50.000000', "Fine amountoutstanding correctly set to 50" ); |
188 |
is( $fine->issue_id, $checkout1->issue_id, "Fine is associated with the correct issue" ); |
191 |
is( $fine->issue_id, $checkout1->issue_id, "Fine is associated with the correct issue" ); |
189 |
is( $fine->itemnumber, $checkout1->itemnumber, "Fine is associated with the correct item" ); |
192 |
is( $fine->itemnumber, $checkout1->itemnumber, "Fine is associated with the correct item" ); |
|
|
193 |
# Total : Outstanding : MaxFine |
194 |
# 50 : 50 : 100 |
190 |
|
195 |
|
191 |
# Increase fine 1 |
196 |
# Increase fine 1 - First Item Overdue |
192 |
UpdateFine( |
197 |
UpdateFine( |
193 |
{ |
198 |
{ |
194 |
issue_id => $checkout1->issue_id, |
199 |
issue_id => $checkout1->issue_id, |
Lines 204-211
subtest 'UpdateFine tests' => sub {
Link Here
|
204 |
is( $fines->count, 1, "Existing fine updated" ); |
209 |
is( $fines->count, 1, "Existing fine updated" ); |
205 |
$fine = $fines->next; |
210 |
$fine = $fines->next; |
206 |
is( $fine->amount, '80.000000', "Fine amount correctly updated to 80" ); |
211 |
is( $fine->amount, '80.000000', "Fine amount correctly updated to 80" ); |
|
|
212 |
is( $fine->amountoutstanding, '80.000000', "Fine amountoutstanding correctly updated to 80" ); |
213 |
# Total : Outstanding : MaxFine |
214 |
# 80 : 80 : 100 |
207 |
|
215 |
|
208 |
# Add fine 2 |
216 |
# Add fine 2 - Second Item Overdue |
209 |
UpdateFine( |
217 |
UpdateFine( |
210 |
{ |
218 |
{ |
211 |
issue_id => $checkout2->issue_id, |
219 |
issue_id => $checkout2->issue_id, |
Lines 223-235
subtest 'UpdateFine tests' => sub {
Link Here
|
223 |
is( $fines->count, 2, "New fine added for second checkout" ); |
231 |
is( $fines->count, 2, "New fine added for second checkout" ); |
224 |
$fine = $fines->next; |
232 |
$fine = $fines->next; |
225 |
is( $fine->amount, '80.000000', "First fine amount unchanged" ); |
233 |
is( $fine->amount, '80.000000', "First fine amount unchanged" ); |
|
|
234 |
is( $fine->amountoutstanding, '80.000000', "First fine amountoutstanding unchanged" ); |
226 |
my $fine2 = $fines->next; |
235 |
my $fine2 = $fines->next; |
227 |
is( $fine2->amount, '20.000000', "Second fine capped at '20' by MaxFine" ); |
236 |
is( $fine2->amount, '20.000000', "Second fine capped at '20' by MaxFine" ); |
|
|
237 |
is( $fine2->amountoutstanding, '20.000000', "Second fine amountoutstanding capped at '20' by MaxFine" ); |
228 |
is( $fine2->issue_id, $checkout2->issue_id, "Second fine is associated with the correct issue" ); |
238 |
is( $fine2->issue_id, $checkout2->issue_id, "Second fine is associated with the correct issue" ); |
229 |
is( $fine2->itemnumber, $checkout2->itemnumber, "Second fine is associated with the correct item" ); |
239 |
is( $fine2->itemnumber, $checkout2->itemnumber, "Second fine is associated with the correct item" ); |
|
|
240 |
is( $fine->amount + $fine2->amount, '100', "Total fines = 100" ); |
241 |
is( $fine->amountoutstanding + $fine2->amountoutstanding, '100', "Total outstanding = 100" ); |
242 |
# Total : Outstanding : MaxFine |
243 |
# 100 : 100 : 100 |
230 |
|
244 |
|
231 |
# Partial pay fine 1 |
245 |
# Partial pay fine 1 |
232 |
$fine->amountoutstanding('50')->store; |
246 |
$fine->amountoutstanding('50.000000')->store; |
|
|
247 |
# Total : Outstanding : MaxFine |
248 |
# 100 : 50 : 100 |
249 |
|
250 |
# Increase fine 2 - Second item overdue |
233 |
UpdateFine( |
251 |
UpdateFine( |
234 |
{ |
252 |
{ |
235 |
issue_id => $checkout2->issue_id, |
253 |
issue_id => $checkout2->issue_id, |
Lines 247-257
subtest 'UpdateFine tests' => sub {
Link Here
|
247 |
is( $fines->count, 2, "Still two fines after second checkout update" ); |
265 |
is( $fines->count, 2, "Still two fines after second checkout update" ); |
248 |
$fine = $fines->next; |
266 |
$fine = $fines->next; |
249 |
is( $fine->amount, '80.000000', "First fine amount unchanged" ); |
267 |
is( $fine->amount, '80.000000', "First fine amount unchanged" ); |
|
|
268 |
is( $fine->amountoutstanding, '50.000000', "First fine amountoutstanding unchanged" ); |
250 |
$fine2 = $fines->next; |
269 |
$fine2 = $fines->next; |
251 |
is( $fine2->amount, '30.000000', "Second fine increased after partial payment of first" ); |
270 |
is( $fine2->amount, '30.000000', "Second fine increased after partial payment of first" ); |
|
|
271 |
is( $fine2->amountoutstanding, '30.000000', "Second fine amountoutstanding increased after partial payment of first" ); |
272 |
is( $fine->amount + $fine2->amount, '110', "Total fines = 100" ); |
273 |
is( $fine->amountoutstanding + $fine2->amountoutstanding, '80', "Total outstanding = 80" ); |
274 |
# Total : Outstanding : MaxFine |
275 |
# 110 : 80 : 100 |
252 |
|
276 |
|
253 |
# Fix fine 1, create third fine |
277 |
# Fix fine 1 - First item renewed |
254 |
$fine->status('RETURNED')->store; |
278 |
$fine->status('RETURNED')->store; |
|
|
279 |
|
280 |
# Add fine 3 - First item second overdue |
255 |
UpdateFine( |
281 |
UpdateFine( |
256 |
{ |
282 |
{ |
257 |
issue_id => $checkout1->issue_id, |
283 |
issue_id => $checkout1->issue_id, |
Lines 269-281
subtest 'UpdateFine tests' => sub {
Link Here
|
269 |
is( $fines->count, 3, "Third fine added for overdue renewal" ); |
295 |
is( $fines->count, 3, "Third fine added for overdue renewal" ); |
270 |
$fine = $fines->next; |
296 |
$fine = $fines->next; |
271 |
is( $fine->amount, '80.000000', "First fine amount unchanged" ); |
297 |
is( $fine->amount, '80.000000', "First fine amount unchanged" ); |
|
|
298 |
is( $fine->amountoutstanding, '50.000000', "First fine amountoutstanding unchanged" ); |
272 |
$fine2 = $fines->next; |
299 |
$fine2 = $fines->next; |
273 |
is( $fine2->amount, '30.000000', "Second fine amount unchanged" ); |
300 |
is( $fine2->amount, '30.000000', "Second fine amount unchanged" ); |
|
|
301 |
is( $fine2->amountoutstanding, '30.000000', "Second fine amountoutstanding unchanged" ); |
274 |
my $fine3 = $fines->next; |
302 |
my $fine3 = $fines->next; |
275 |
is( $fine3->amount, '20.000000', "Third fine amount capped due to MaxFine" ); |
303 |
is( $fine3->amount, '20.000000', "Third fine amount capped due to MaxFine" ); |
|
|
304 |
is( $fine3->amountoutstanding, '20.000000', "Third fine amountoutstanding capped at '20' by MaxFine" ); |
276 |
is( $fine3->issue_id, $checkout1->issue_id, "Third fine is associated with the correct issue" ); |
305 |
is( $fine3->issue_id, $checkout1->issue_id, "Third fine is associated with the correct issue" ); |
277 |
is( $fine3->itemnumber, $checkout1->itemnumber, "Third fine is associated with the correct item" ); |
306 |
is( $fine3->itemnumber, $checkout1->itemnumber, "Third fine is associated with the correct item" ); |
|
|
307 |
is( $fine->amount + $fine2->amount + $fine3->amount, '130', "Total fines = 130" ); |
308 |
is( $fine->amountoutstanding + $fine2->amountoutstanding + $fine3->amountoutstanding, '100', "Total outstanding = 100" ); |
309 |
# Total : Outstanding : MaxFine |
310 |
# 130 : 100 : 100 |
311 |
|
312 |
# Payoff accruing fine and ensure next increment doesn't create a new one (bug #24146) |
313 |
$fine3->amountoutstanding('0')->store; |
314 |
is( $fine->amount + $fine2->amount + $fine3->amount, '130', "Total fines = 130" ); |
315 |
is( $fine->amountoutstanding + $fine2->amountoutstanding + $fine3->amountoutstanding, '80', "Total outstanding = 80" ); |
316 |
# Total : Outstanding : MaxFine |
317 |
# 130 : 80 : 100 |
318 |
|
319 |
# Increase fine 3 - First item, second overdue increase |
320 |
UpdateFine( |
321 |
{ |
322 |
issue_id => $checkout1->issue_id, |
323 |
itemnumber => $item1->itemnumber, |
324 |
borrowernumber => $patron->borrowernumber, |
325 |
amount => '50', |
326 |
due => $checkout1->date_due |
327 |
} |
328 |
); |
278 |
|
329 |
|
|
|
330 |
$fines = Koha::Account::Lines->search( |
331 |
{ borrowernumber => $patron->borrowernumber }, |
332 |
{ order_by => { '-asc' => 'accountlines_id' } } |
333 |
); |
334 |
is( $fines->count, 3, "Still three fines after third checkout update" ); |
335 |
$fine = $fines->next; |
336 |
is( $fine->amount, '80.000000', "First fine amount unchanged" ); |
337 |
is( $fine->amountoutstanding, '50.000000', "First fine amountoutstanding unchanged" ); |
338 |
$fine2 = $fines->next; |
339 |
is( $fine2->amount, '30.000000', "Second fine amount unchanged" ); |
340 |
is( $fine2->amountoutstanding, '30.000000', "Second fine amountoutstanding unchanged" ); |
341 |
$fine3 = $fines->next; |
342 |
is( $fine3->amount, '40.000000', "Third fine amount capped due to MaxFine" ); |
343 |
is( $fine3->amountoutstanding, '20.000000', "Third fine amountoutstanding increased ..." ); |
344 |
is( $fine3->issue_id, $checkout1->issue_id, "Third fine is associated with the correct issue" ); |
345 |
is( $fine3->itemnumber, $checkout1->itemnumber, "Third fine is associated with the correct item" ); |
346 |
is( $fine->amount + $fine2->amount + $fine3->amount, '150', "Total fines = 150" ); |
347 |
is( $fine->amountoutstanding + $fine2->amountoutstanding + $fine3->amountoutstanding, '100', "Total outstanding = 100" ); |
348 |
# Total : Outstanding : MaxFine |
349 |
# 150 : 100 : 100 |
350 |
|
279 |
# FIXME: Add test to check whether sundry/manual charges are included within MaxFine. |
351 |
# FIXME: Add test to check whether sundry/manual charges are included within MaxFine. |
280 |
# FIXME: Add test to ensure other charges are not included within MaxFine. |
352 |
# FIXME: Add test to ensure other charges are not included within MaxFine. |
281 |
|
353 |
|
282 |
- |
|
|