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

(-)a/C4/Circulation.pm (-1 / +1 lines)
Lines 2608-2614 sub _FixOverduesOnReturn { Link Here
2608
                    }
2608
                    }
2609
                );
2609
                );
2610
2610
2611
                $credit->apply({ debits => [ $accountline ], offset_type => 'Forgiven' });
2611
                $credit->apply({ debits => [ $accountline ] });
2612
2612
2613
                if (C4::Context->preference("FinesLog")) {
2613
                if (C4::Context->preference("FinesLog")) {
2614
                    &logaction("FINES", 'MODIFY',$borrowernumber,"Overdue forgiven: item $item");
2614
                    &logaction("FINES", 'MODIFY',$borrowernumber,"Overdue forgiven: item $item");
(-)a/Koha/Account.pm (-6 / +3 lines)
Lines 360-367 sub payin_amount { Link Here
360
            if ( exists( $params->{debits} ) ) {
360
            if ( exists( $params->{debits} ) ) {
361
                $credit = $credit->apply(
361
                $credit = $credit->apply(
362
                    {
362
                    {
363
                        debits      => $params->{debits},
363
                        debits => $params->{debits}
364
                        offset_type => $Koha::Account::offset_type->{$params->{type}}
365
                    }
364
                    }
366
                );
365
                );
367
            }
366
            }
Lines 372-379 sub payin_amount { Link Here
372
            {
371
            {
373
                $credit = $credit->apply(
372
                $credit = $credit->apply(
374
                    {
373
                    {
375
                        debits      => [ $self->outstanding_debits->as_list ],
374
                        debits => [ $self->outstanding_debits->as_list ]
376
                        offset_type => $Koha::Account::offset_type->{$params->{type}}
377
                    }
375
                    }
378
                );
376
                );
379
            }
377
            }
Lines 617-624 sub payout_amount { Link Here
617
615
618
            # Offset against credits
616
            # Offset against credits
619
            for my $credit ( @{$outstanding_credits} ) {
617
            for my $credit ( @{$outstanding_credits} ) {
620
                $credit->apply(
618
                $credit->apply( { debits => [$payout] } );
621
                    { debits => [$payout], offset_type => 'PAYOUT' } );
622
                $payout->discard_changes;
619
                $payout->discard_changes;
623
                last if $payout->amountoutstanding == 0;
620
                last if $payout->amountoutstanding == 0;
624
            }
621
            }
(-)a/Koha/Account/Line.pm (-27 / +13 lines)
Lines 288-293 sub void { Link Here
288
                }
288
                }
289
            )->store();
289
            )->store();
290
290
291
            # Link void to payment
292
            $self->set({
293
                amountoutstanding => $self->amount,
294
                status => 'VOID'
295
            })->store();
296
            $self->apply( { debits => [$void] } );
297
291
            # Reverse any applied payments
298
            # Reverse any applied payments
292
            foreach my $account_offset (@account_offsets) {
299
            foreach my $account_offset (@account_offsets) {
293
                my $fee_paid =
300
                my $fee_paid =
Lines 310-322 sub void { Link Here
310
                )->store();
317
                )->store();
311
            }
318
            }
312
319
313
            # Link void to payment
314
            $self->set({
315
                amountoutstanding => $self->amount,
316
                status => 'VOID'
317
            })->store();
318
            $self->apply({ debits => [$void]});
319
320
            if ( C4::Context->preference("FinesLog") ) {
320
            if ( C4::Context->preference("FinesLog") ) {
321
                logaction(
321
                logaction(
322
                    "FINES", 'VOID',
322
                    "FINES", 'VOID',
Lines 421-432 sub cancel { Link Here
421
            )->store();
421
            )->store();
422
422
423
            # Link cancellation to charge
423
            # Link cancellation to charge
424
            $cancellation->apply(
424
            $cancellation->apply( { debits => [$self] } );
425
                {
426
                    debits      => [$self],
427
                    offset_type => 'CANCELLATION'
428
                }
429
            );
430
            $cancellation->status('APPLIED')->store();
425
            $cancellation->status('APPLIED')->store();
431
426
432
            # Update status of original debit
427
            # Update status of original debit
Lines 548-559 sub reduce { Link Here
548
            my $debit_outstanding = $self->amountoutstanding;
543
            my $debit_outstanding = $self->amountoutstanding;
549
            if ( $debit_outstanding >= $params->{amount} ) {
544
            if ( $debit_outstanding >= $params->{amount} ) {
550
545
551
                $reduction->apply(
546
                $reduction->apply( { debits => [$self] } );
552
                    {
553
                        debits      => [$self],
554
                        offset_type => uc( $params->{reduction_type} )
555
                    }
556
                );
557
                $reduction->status('APPLIED')->store();
547
                $reduction->status('APPLIED')->store();
558
            }
548
            }
559
            else {
549
            else {
Lines 564-570 sub reduce { Link Here
564
                    {
554
                    {
565
                        credit_id => $reduction->accountlines_id,
555
                        credit_id => $reduction->accountlines_id,
566
                        debit_id  => $self->accountlines_id,
556
                        debit_id  => $self->accountlines_id,
567
                        type      => uc( $params->{reduction_type} ),
557
                        type      => 'APPLY',
568
                        amount    => 0
558
                        amount    => 0
569
                    }
559
                    }
570
                )->store();
560
                )->store();
Lines 582-588 sub reduce { Link Here
582
=head3 apply
572
=head3 apply
583
573
584
    my $debits = $account->outstanding_debits;
574
    my $debits = $account->outstanding_debits;
585
    my $credit = $credit->apply( { debits => $debits, [ offset_type => $offset_type ] } );
575
    my $credit = $credit->apply( { debits => $debits } );
586
576
587
Applies the credit to a given debits array reference.
577
Applies the credit to a given debits array reference.
588
578
Lines 592-600 Applies the credit to a given debits array reference. Link Here
592
582
593
=item debits - Koha::Account::Lines object set of debits
583
=item debits - Koha::Account::Lines object set of debits
594
584
595
=item offset_type (optional) - a string indicating the offset type (valid values are those from
596
the 'account_offset_types' table)
597
598
=back
585
=back
599
586
600
=cut
587
=cut
Lines 603-609 sub apply { Link Here
603
    my ( $self, $params ) = @_;
590
    my ( $self, $params ) = @_;
604
591
605
    my $debits      = $params->{debits};
592
    my $debits      = $params->{debits};
606
    my $offset_type = $params->{offset_type} // 'Credit Applied';
607
593
608
    unless ( $self->is_credit ) {
594
    unless ( $self->is_credit ) {
609
        Koha::Exceptions::Account::IsNotCredit->throw(
595
        Koha::Exceptions::Account::IsNotCredit->throw(
Lines 644-650 sub apply { Link Here
644
                {   credit_id => $self->id,
630
                {   credit_id => $self->id,
645
                    debit_id  => $debit->id,
631
                    debit_id  => $debit->id,
646
                    amount    => $amount_to_cancel * -1,
632
                    amount    => $amount_to_cancel * -1,
647
                    type      => $offset_type,
633
                    type      => 'APPLY'
648
                }
634
                }
649
            )->store();
635
            )->store();
650
636
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 133-144 sub add_credit { Link Here
133
133
134
        if ($debits) {
134
        if ($debits) {
135
            # pay them!
135
            # pay them!
136
            $credit = $credit->apply({ debits => [ $debits->as_list ], offset_type => 'payment' });
136
            $credit = $credit->apply({ debits => [ $debits->as_list ] });
137
        }
137
        }
138
138
139
        if ($credit->amountoutstanding != 0) {
139
        if ($credit->amountoutstanding != 0) {
140
            my $outstanding_debits = $account->outstanding_debits;
140
            my $outstanding_debits = $account->outstanding_debits;
141
            $credit->apply({ debits => [ $outstanding_debits->as_list ], offset_type => 'payment' });
141
            $credit->apply({ debits => [ $outstanding_debits->as_list ] });
142
        }
142
        }
143
143
144
        $credit->discard_changes;
144
        $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