View | Details | Raw Unified | Return to bug 24146
Collapse All | Expand All

(-)a/t/db_dependent/Overdues.t (-7 / +68 lines)
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 => 43;
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
    # Total : Outstanding : MaxFine
241
    #  100  :     100     :   100
230
242
231
    # Partial pay fine 1
243
    # Partial pay fine 1
232
    $fine->amountoutstanding('50')->store;
244
    $fine->amountoutstanding('50.000000')->store;
245
    # Total : Outstanding : MaxFine
246
    #  100  :     50      :   100
247
248
    # Increase fine 2 - Second item overdue
233
    UpdateFine(
249
    UpdateFine(
234
        {
250
        {
235
            issue_id       => $checkout2->issue_id,
251
            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" );
263
    is( $fines->count,        2,    "Still two fines after second checkout update" );
248
    $fine = $fines->next;
264
    $fine = $fines->next;
249
    is( $fine->amount, '80.000000', "First fine amount unchanged" );
265
    is( $fine->amount, '80.000000', "First fine amount unchanged" );
266
    is( $fine->amountoutstanding, '50.000000', "First fine amountoutstanding unchanged" );
250
    $fine2 = $fines->next;
267
    $fine2 = $fines->next;
251
    is( $fine2->amount, '30.000000', "Second fine increased after partial payment of first" );
268
    is( $fine2->amount, '30.000000', "Second fine increased after partial payment of first" );
269
    is( $fine2->amountoutstanding, '30.000000', "Second fine amountoutstanding increased after partial payment of first" );
270
    # Total : Outstanding : MaxFine
271
    #  110  :     80      :   100
252
272
253
    # Fix fine 1, create third fine
273
    # Fix fine 1 - First item renewed
254
    $fine->status('RETURNED')->store;
274
    $fine->status('RETURNED')->store;
275
276
    # Add fine 3 - First item second overdue
255
    UpdateFine(
277
    UpdateFine(
256
        {
278
        {
257
            issue_id       => $checkout1->issue_id,
279
            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" );
291
    is( $fines->count,        3,    "Third fine added for overdue renewal" );
270
    $fine = $fines->next;
292
    $fine = $fines->next;
271
    is( $fine->amount, '80.000000', "First fine amount unchanged" );
293
    is( $fine->amount, '80.000000', "First fine amount unchanged" );
294
    is( $fine->amountoutstanding, '50.000000', "First fine amountoutstanding unchanged" );
272
    $fine2 = $fines->next;
295
    $fine2 = $fines->next;
273
    is( $fine2->amount, '30.000000', "Second fine amount unchanged" );
296
    is( $fine2->amount, '30.000000', "Second fine amount unchanged" );
297
    is( $fine2->amountoutstanding, '30.000000', "Second fine amountoutstanding unchanged" );
274
    my $fine3 = $fines->next;
298
    my $fine3 = $fines->next;
275
    is( $fine3->amount, '20.000000', "Third fine amount capped due to MaxFine" );
299
    is( $fine3->amount, '20.000000', "Third fine amount capped due to MaxFine" );
300
    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" );
301
    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" );
302
    is( $fine3->itemnumber, $checkout1->itemnumber, "Third fine is associated with the correct item" );
303
    # Total : Outstanding : MaxFine
304
    #  130  :     100     :   100
305
306
    # Payoff accruing fine and ensure next increment doesn't create a new one (bug #24146)
307
    $fine3->amountoutstanding('0')->store;
308
    # Total : Outstanding : MaxFine
309
    #  130  :      80     :   100
310
311
    # Increase fine 3 - First item, second overdue increase
312
    UpdateFine(
313
        {
314
            issue_id       => $checkout1->issue_id,
315
            itemnumber     => $item1->itemnumber,
316
            borrowernumber => $patron->borrowernumber,
317
            amount         => '50',
318
            due            => $checkout1->date_due
319
        }
320
    );
278
321
322
    $fines = Koha::Account::Lines->search(
323
        { borrowernumber => $patron->borrowernumber },
324
        { order_by       => { '-asc' => 'accountlines_id' } }
325
    );
326
    is( $fines->count,        3,    "Still three fines after third checkout update" );
327
    $fine = $fines->next;
328
    is( $fine->amount, '80.000000', "First fine amount unchanged" );
329
    is( $fine->amountoutstanding, '50.000000', "First fine amountoutstanding unchanged" );
330
    $fine2 = $fines->next;
331
    is( $fine2->amount, '30.000000', "Second fine amount unchanged" );
332
    is( $fine2->amountoutstanding, '30.000000', "Second fine amountoutstanding unchanged" );
333
    $fine3 = $fines->next;
334
    is( $fine3->amount, '50.000000', "Third fine amount capped due to MaxFine" );
335
    is( $fine3->amountoutstanding, '20.000000', "Third fine amountoutstanding increased ..." );
336
    is( $fine3->issue_id, $checkout1->issue_id, "Third fine is associated with the correct issue" );
337
    is( $fine3->itemnumber, $checkout1->itemnumber, "Third fine is associated with the correct item" );
338
    # Total : Outstanding : MaxFine
339
    #  160  :      100     :   100
340
    
279
    # FIXME: Add test to check whether sundry/manual charges are included within MaxFine.
341
    # 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.
342
    # FIXME: Add test to ensure other charges are not included within MaxFine.
281
343
282
- 

Return to bug 24146