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

(-)a/C4/Circulation.pm (-1 / +1 lines)
Lines 2617-2623 sub _FixOverduesOnReturn { Link Here
2617
                    }
2617
                    }
2618
                );
2618
                );
2619
2619
2620
                $credit->apply({ debits => [ $accountline ], offset_type => 'Forgiven' });
2620
                $credit->apply({ debits => [ $accountline ] });
2621
2621
2622
                if (C4::Context->preference("FinesLog")) {
2622
                if (C4::Context->preference("FinesLog")) {
2623
                    &logaction("FINES", 'MODIFY',$borrowernumber,"Overdue forgiven: item $item");
2623
                    &logaction("FINES", 'MODIFY',$borrowernumber,"Overdue forgiven: item $item");
(-)a/Koha/Account.pm (-13 / +3 lines)
Lines 353-364 sub payin_amount { Link Here
353
353
354
            # Offset debts passed first
354
            # Offset debts passed first
355
            if ( exists( $params->{debits} ) ) {
355
            if ( exists( $params->{debits} ) ) {
356
                $credit = $credit->apply(
356
                $credit = $credit->apply( { debits => $params->{debits} } );
357
                    {
358
                        debits      => $params->{debits},
359
                        offset_type => $params->{type}
360
                    }
361
                );
362
            }
357
            }
363
358
364
            # Offset against remaining balance if AutoReconcile
359
            # Offset against remaining balance if AutoReconcile
Lines 366-376 sub payin_amount { Link Here
366
                && $credit->amountoutstanding != 0 )
361
                && $credit->amountoutstanding != 0 )
367
            {
362
            {
368
                $credit = $credit->apply(
363
                $credit = $credit->apply(
369
                    {
364
                    { debits => [ $self->outstanding_debits->as_list ], } );
370
                        debits      => [ $self->outstanding_debits->as_list ],
371
                        offset_type => $params->{type}
372
                    }
373
                );
374
            }
365
            }
375
        }
366
        }
376
    );
367
    );
Lines 612-619 sub payout_amount { Link Here
612
603
613
            # Offset against credits
604
            # Offset against credits
614
            for my $credit ( @{$outstanding_credits} ) {
605
            for my $credit ( @{$outstanding_credits} ) {
615
                $credit->apply(
606
                $credit->apply( { debits => [$payout] } );
616
                    { debits => [$payout], offset_type => 'PAYOUT' } );
617
                $payout->discard_changes;
607
                $payout->discard_changes;
618
                last if $payout->amountoutstanding == 0;
608
                last if $payout->amountoutstanding == 0;
619
            }
609
            }
(-)a/Koha/Account/Line.pm (-27 / +13 lines)
Lines 289-294 sub void { Link Here
289
                }
289
                }
290
            )->store();
290
            )->store();
291
291
292
            # Link void to payment
293
            $self->set({
294
                amountoutstanding => $self->amount,
295
                status => 'VOID'
296
            })->store();
297
            $self->apply( { debits => [$void] } );
298
292
            # Reverse any applied payments
299
            # Reverse any applied payments
293
            foreach my $account_offset (@account_offsets) {
300
            foreach my $account_offset (@account_offsets) {
294
                my $fee_paid =
301
                my $fee_paid =
Lines 311-323 sub void { Link Here
311
                )->store();
318
                )->store();
312
            }
319
            }
313
320
314
            # Link void to payment
315
            $self->set({
316
                amountoutstanding => $self->amount,
317
                status => 'VOID'
318
            })->store();
319
            $self->apply({ debits => [$void]});
320
321
            if ( C4::Context->preference("FinesLog") ) {
321
            if ( C4::Context->preference("FinesLog") ) {
322
                logaction(
322
                logaction(
323
                    "FINES", 'VOID',
323
                    "FINES", 'VOID',
Lines 422-433 sub cancel { Link Here
422
            )->store();
422
            )->store();
423
423
424
            # Link cancellation to charge
424
            # Link cancellation to charge
425
            $cancellation->apply(
425
            $cancellation->apply( { debits => [$self] } );
426
                {
427
                    debits      => [$self],
428
                    offset_type => 'CANCELLATION'
429
                }
430
            );
431
            $cancellation->status('APPLIED')->store();
426
            $cancellation->status('APPLIED')->store();
432
427
433
            # Update status of original debit
428
            # Update status of original debit
Lines 549-560 sub reduce { Link Here
549
            my $debit_outstanding = $self->amountoutstanding;
544
            my $debit_outstanding = $self->amountoutstanding;
550
            if ( $debit_outstanding >= $params->{amount} ) {
545
            if ( $debit_outstanding >= $params->{amount} ) {
551
546
552
                $reduction->apply(
547
                $reduction->apply( { debits => [$self] } );
553
                    {
554
                        debits      => [$self],
555
                        offset_type => uc( $params->{reduction_type} )
556
                    }
557
                );
558
                $reduction->status('APPLIED')->store();
548
                $reduction->status('APPLIED')->store();
559
            }
549
            }
560
            else {
550
            else {
Lines 565-571 sub reduce { Link Here
565
                    {
555
                    {
566
                        credit_id => $reduction->accountlines_id,
556
                        credit_id => $reduction->accountlines_id,
567
                        debit_id  => $self->accountlines_id,
557
                        debit_id  => $self->accountlines_id,
568
                        type      => uc( $params->{reduction_type} ),
558
                        type      => 'APPLY',
569
                        amount    => 0
559
                        amount    => 0
570
                    }
560
                    }
571
                )->store();
561
                )->store();
Lines 583-589 sub reduce { Link Here
583
=head3 apply
573
=head3 apply
584
574
585
    my $debits = $account->outstanding_debits;
575
    my $debits = $account->outstanding_debits;
586
    my $outstanding_amount = $credit->apply( { debits => $debits, [ offset_type => $offset_type ] } );
576
    my $outstanding_amount = $credit->apply( { debits => $debits } );
587
577
588
Applies the credit to a given debits array reference.
578
Applies the credit to a given debits array reference.
589
579
Lines 593-601 Applies the credit to a given debits array reference. Link Here
593
583
594
=item debits - Koha::Account::Lines object set of debits
584
=item debits - Koha::Account::Lines object set of debits
595
585
596
=item offset_type (optional) - a string indicating the offset type (valid values are those from
597
the 'account_offset_types' table)
598
599
=back
586
=back
600
587
601
=cut
588
=cut
Lines 604-610 sub apply { Link Here
604
    my ( $self, $params ) = @_;
591
    my ( $self, $params ) = @_;
605
592
606
    my $debits      = $params->{debits};
593
    my $debits      = $params->{debits};
607
    my $offset_type = $params->{offset_type} // 'Credit Applied';
608
594
609
    unless ( $self->is_credit ) {
595
    unless ( $self->is_credit ) {
610
        Koha::Exceptions::Account::IsNotCredit->throw(
596
        Koha::Exceptions::Account::IsNotCredit->throw(
Lines 645-651 sub apply { Link Here
645
                {   credit_id => $self->id,
631
                {   credit_id => $self->id,
646
                    debit_id  => $debit->id,
632
                    debit_id  => $debit->id,
647
                    amount    => $amount_to_cancel * -1,
633
                    amount    => $amount_to_cancel * -1,
648
                    type      => $offset_type,
634
                    type      => 'APPLY'
649
                }
635
                }
650
            )->store();
636
            )->store();
651
637
Lines 777-783 sub payout { Link Here
777
                }
763
                }
778
            )->store();
764
            )->store();
779
765
780
            $self->apply( { debits => [$payout], offset_type => 'PAYOUT' } );
766
            $self->apply( { debits => [$payout] } );
781
            $self->status('PAID')->store;
767
            $self->status('PAID')->store;
782
        }
768
        }
783
    );
769
    );
(-)a/Koha/REST/V1/Patrons/Account.pm (-2 / +2 lines)
Lines 134-145 sub add_credit { Link Here
134
134
135
        if ($debits) {
135
        if ($debits) {
136
            # pay them!
136
            # pay them!
137
            $credit = $credit->apply({ debits => [ $debits->as_list ], offset_type => 'payment' });
137
            $credit = $credit->apply({ debits => [ $debits->as_list ] });
138
        }
138
        }
139
139
140
        if ($credit->amountoutstanding != 0) {
140
        if ($credit->amountoutstanding != 0) {
141
            my $outstanding_debits = $account->outstanding_debits;
141
            my $outstanding_debits = $account->outstanding_debits;
142
            $credit->apply({ debits => [ $outstanding_debits->as_list ], offset_type => 'payment' });
142
            $credit->apply({ debits => [ $outstanding_debits->as_list ] });
143
        }
143
        }
144
144
145
        return $c->render( status => 200, openapi => { account_line_id => $credit->id } );
145
        return $c->render( status => 200, openapi => { account_line_id => $credit->id } );
(-)a/t/db_dependent/Circulation.t (-8 / +4 lines)
Lines 2726-2733 subtest 'AddReturn | is_overdue' => sub { Link Here
2726
                interface => 'test',
2726
                interface => 'test',
2727
            }
2727
            }
2728
        );
2728
        );
2729
        $credit->apply(
2729
        $credit->apply( { debits => [$debit] } );
2730
            { debits => [ $debit ], offset_type => 'Payment' } );
2731
2730
2732
        is( int( $patron->account->balance() ),
2731
        is( int( $patron->account->balance() ),
2733
            0, "Overdue fine should be paid off" );
2732
            0, "Overdue fine should be paid off" );
Lines 2853-2859 subtest 'AddReturn | is_overdue' => sub { Link Here
2853
                interface => 'test',
2852
                interface => 'test',
2854
            }
2853
            }
2855
        );
2854
        );
2856
        $credit->apply( { debits => [$debit], offset_type => 'Payment' } );
2855
        $credit->apply( { debits => [$debit] } );
2857
2856
2858
        is( $patron->account->balance(), .05, 'Overdue fine reduced to $0.05' );
2857
        is( $patron->account->balance(), .05, 'Overdue fine reduced to $0.05' );
2859
2858
Lines 3190-3197 subtest 'AddReturn | is_overdue' => sub { Link Here
3190
                    item_id    => $item->itemnumber
3189
                    item_id    => $item->itemnumber
3191
                }
3190
                }
3192
            );
3191
            );
3193
            $overdue_forgive->apply(
3192
            $overdue_forgive->apply( { debits => [$overdue_fee] } );
3194
                { debits => [$overdue_fee], offset_type => 'Forgiven' } );
3195
            $overdue_fee->discard_changes;
3193
            $overdue_fee->discard_changes;
3196
            is($overdue_fee->amountoutstanding + 0, 0, 'Overdue fee forgiven');
3194
            is($overdue_fee->amountoutstanding + 0, 0, 'Overdue fee forgiven');
3197
3195
Lines 3288-3295 subtest 'AddReturn | is_overdue' => sub { Link Here
3288
                    item_id    => $item->itemnumber
3286
                    item_id    => $item->itemnumber
3289
                }
3287
                }
3290
            );
3288
            );
3291
            $overdue_forgive->apply(
3289
            $overdue_forgive->apply( { debits => [$overdue_fee] } );
3292
                { debits => [$overdue_fee], offset_type => 'Forgiven' } );
3293
            $overdue_fee->discard_changes;
3290
            $overdue_fee->discard_changes;
3294
            is($overdue_fee->amountoutstanding + 0, 0, 'Overdue fee forgiven');
3291
            is($overdue_fee->amountoutstanding + 0, 0, 'Overdue fee forgiven');
3295
3292
3296
- 

Return to bug 22435