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 (-6 / +3 lines)
Lines 362-369 sub payin_amount { Link Here
362
            if ( exists( $params->{debits} ) ) {
362
            if ( exists( $params->{debits} ) ) {
363
                $credit = $credit->apply(
363
                $credit = $credit->apply(
364
                    {
364
                    {
365
                        debits      => $params->{debits},
365
                        debits => $params->{debits}
366
                        offset_type => $Koha::Account::offset_type->{$params->{type}}
367
                    }
366
                    }
368
                );
367
                );
369
            }
368
            }
Lines 374-381 sub payin_amount { Link Here
374
            {
373
            {
375
                $credit = $credit->apply(
374
                $credit = $credit->apply(
376
                    {
375
                    {
377
                        debits      => [ $self->outstanding_debits->as_list ],
376
                        debits => [ $self->outstanding_debits->as_list ]
378
                        offset_type => $Koha::Account::offset_type->{$params->{type}}
379
                    }
377
                    }
380
                );
378
                );
381
            }
379
            }
Lines 619-626 sub payout_amount { Link Here
619
617
620
            # Offset against credits
618
            # Offset against credits
621
            for my $credit ( @{$outstanding_credits} ) {
619
            for my $credit ( @{$outstanding_credits} ) {
622
                $credit->apply(
620
                $credit->apply( { debits => [$payout] } );
623
                    { debits => [$payout], offset_type => 'PAYOUT' } );
624
                $payout->discard_changes;
621
                $payout->discard_changes;
625
                last if $payout->amountoutstanding == 0;
622
                last if $payout->amountoutstanding == 0;
626
            }
623
            }
(-)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 $credit = $credit->apply( { debits => $debits, [ offset_type => $offset_type ] } );
576
    my $credit = $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 778-784 sub payout { Link Here
778
                }
764
                }
779
            )->store();
765
            )->store();
780
766
781
            $self->apply( { debits => [$payout], offset_type => 'PAYOUT' } );
767
            $self->apply( { debits => [$payout] } );
782
            $self->status('PAID')->store;
768
            $self->status('PAID')->store;
783
        }
769
        }
784
    );
770
    );
(-)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
        $credit->discard_changes;
145
        $credit->discard_changes;
(-)a/t/db_dependent/Circulation.t (-8 / +4 lines)
Lines 2729-2736 subtest 'AddReturn | is_overdue' => sub { Link Here
2729
                interface => 'test',
2729
                interface => 'test',
2730
            }
2730
            }
2731
        );
2731
        );
2732
        $credit->apply(
2732
        $credit->apply( { debits => [$debit] } );
2733
            { debits => [ $debit ], offset_type => 'Payment' } );
2734
2733
2735
        is( int( $patron->account->balance() ),
2734
        is( int( $patron->account->balance() ),
2736
            0, "Overdue fine should be paid off" );
2735
            0, "Overdue fine should be paid off" );
Lines 2856-2862 subtest 'AddReturn | is_overdue' => sub { Link Here
2856
                interface => 'test',
2855
                interface => 'test',
2857
            }
2856
            }
2858
        );
2857
        );
2859
        $credit->apply( { debits => [$debit], offset_type => 'Payment' } );
2858
        $credit->apply( { debits => [$debit] } );
2860
2859
2861
        is( $patron->account->balance(), .05, 'Overdue fine reduced to $0.05' );
2860
        is( $patron->account->balance(), .05, 'Overdue fine reduced to $0.05' );
2862
2861
Lines 3193-3200 subtest 'AddReturn | is_overdue' => sub { Link Here
3193
                    item_id    => $item->itemnumber
3192
                    item_id    => $item->itemnumber
3194
                }
3193
                }
3195
            );
3194
            );
3196
            $overdue_forgive->apply(
3195
            $overdue_forgive->apply( { debits => [$overdue_fee] } );
3197
                { debits => [$overdue_fee], offset_type => 'Forgiven' } );
3198
            $overdue_fee->discard_changes;
3196
            $overdue_fee->discard_changes;
3199
            is($overdue_fee->amountoutstanding + 0, 0, 'Overdue fee forgiven');
3197
            is($overdue_fee->amountoutstanding + 0, 0, 'Overdue fee forgiven');
3200
3198
Lines 3291-3298 subtest 'AddReturn | is_overdue' => sub { Link Here
3291
                    item_id    => $item->itemnumber
3289
                    item_id    => $item->itemnumber
3292
                }
3290
                }
3293
            );
3291
            );
3294
            $overdue_forgive->apply(
3292
            $overdue_forgive->apply( { debits => [$overdue_fee] } );
3295
                { debits => [$overdue_fee], offset_type => 'Forgiven' } );
3296
            $overdue_fee->discard_changes;
3293
            $overdue_fee->discard_changes;
3297
            is($overdue_fee->amountoutstanding + 0, 0, 'Overdue fee forgiven');
3294
            is($overdue_fee->amountoutstanding + 0, 0, 'Overdue fee forgiven');
3298
3295
3299
- 

Return to bug 22435