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

(-)a/C4/Circulation.pm (-1 / +1 lines)
Lines 2616-2622 sub _FixOverduesOnReturn { Link Here
2616
                    }
2616
                    }
2617
                );
2617
                );
2618
2618
2619
                $credit->apply({ debits => [ $accountline ], offset_type => 'Forgiven' });
2619
                $credit->apply({ debits => [ $accountline ] });
2620
2620
2621
                if (C4::Context->preference("FinesLog")) {
2621
                if (C4::Context->preference("FinesLog")) {
2622
                    &logaction("FINES", 'MODIFY',$borrowernumber,"Overdue forgiven: item $item");
2622
                    &logaction("FINES", 'MODIFY',$borrowernumber,"Overdue forgiven: item $item");
(-)a/Koha/Account.pm (-13 / +3 lines)
Lines 354-365 sub payin_amount { Link Here
354
354
355
            # Offset debts passed first
355
            # Offset debts passed first
356
            if ( exists( $params->{debits} ) ) {
356
            if ( exists( $params->{debits} ) ) {
357
                $credit = $credit->apply(
357
                $credit = $credit->apply( { debits => $params->{debits} } );
358
                    {
359
                        debits      => $params->{debits},
360
                        offset_type => $params->{type}
361
                    }
362
                );
363
            }
358
            }
364
359
365
            # Offset against remaining balance if AutoReconcile
360
            # Offset against remaining balance if AutoReconcile
Lines 367-377 sub payin_amount { Link Here
367
                && $credit->amountoutstanding != 0 )
362
                && $credit->amountoutstanding != 0 )
368
            {
363
            {
369
                $credit = $credit->apply(
364
                $credit = $credit->apply(
370
                    {
365
                    { debits => [ $self->outstanding_debits->as_list ], } );
371
                        debits      => [ $self->outstanding_debits->as_list ],
372
                        offset_type => $params->{type}
373
                    }
374
                );
375
            }
366
            }
376
        }
367
        }
377
    );
368
    );
Lines 613-620 sub payout_amount { Link Here
613
604
614
            # Offset against credits
605
            # Offset against credits
615
            for my $credit ( @{$outstanding_credits} ) {
606
            for my $credit ( @{$outstanding_credits} ) {
616
                $credit->apply(
607
                $credit->apply( { debits => [$payout] } );
617
                    { debits => [$payout], offset_type => 'PAYOUT' } );
618
                $payout->discard_changes;
608
                $payout->discard_changes;
619
                last if $payout->amountoutstanding == 0;
609
                last if $payout->amountoutstanding == 0;
620
            }
610
            }
(-)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 2640-2647 subtest 'AddReturn | is_overdue' => sub { Link Here
2640
                interface => 'test',
2640
                interface => 'test',
2641
            }
2641
            }
2642
        );
2642
        );
2643
        $credit->apply(
2643
        $credit->apply( { debits => [$debit] } );
2644
            { debits => [ $debit ], offset_type => 'Payment' } );
2645
2644
2646
        is( int( $patron->account->balance() ),
2645
        is( int( $patron->account->balance() ),
2647
            0, "Overdue fine should be paid off" );
2646
            0, "Overdue fine should be paid off" );
Lines 2767-2773 subtest 'AddReturn | is_overdue' => sub { Link Here
2767
                interface => 'test',
2766
                interface => 'test',
2768
            }
2767
            }
2769
        );
2768
        );
2770
        $credit->apply( { debits => [$debit], offset_type => 'Payment' } );
2769
        $credit->apply( { debits => [$debit] } );
2771
2770
2772
        is( $patron->account->balance(), .05, 'Overdue fine reduced to $0.05' );
2771
        is( $patron->account->balance(), .05, 'Overdue fine reduced to $0.05' );
2773
2772
Lines 3104-3111 subtest 'AddReturn | is_overdue' => sub { Link Here
3104
                    item_id    => $item->itemnumber
3103
                    item_id    => $item->itemnumber
3105
                }
3104
                }
3106
            );
3105
            );
3107
            $overdue_forgive->apply(
3106
            $overdue_forgive->apply( { debits => [$overdue_fee] } );
3108
                { debits => [$overdue_fee], offset_type => 'Forgiven' } );
3109
            $overdue_fee->discard_changes;
3107
            $overdue_fee->discard_changes;
3110
            is($overdue_fee->amountoutstanding + 0, 0, 'Overdue fee forgiven');
3108
            is($overdue_fee->amountoutstanding + 0, 0, 'Overdue fee forgiven');
3111
3109
Lines 3202-3209 subtest 'AddReturn | is_overdue' => sub { Link Here
3202
                    item_id    => $item->itemnumber
3200
                    item_id    => $item->itemnumber
3203
                }
3201
                }
3204
            );
3202
            );
3205
            $overdue_forgive->apply(
3203
            $overdue_forgive->apply( { debits => [$overdue_fee] } );
3206
                { debits => [$overdue_fee], offset_type => 'Forgiven' } );
3207
            $overdue_fee->discard_changes;
3204
            $overdue_fee->discard_changes;
3208
            is($overdue_fee->amountoutstanding + 0, 0, 'Overdue fee forgiven');
3205
            is($overdue_fee->amountoutstanding + 0, 0, 'Overdue fee forgiven');
3209
3206
3210
- 

Return to bug 22435