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

(-)a/Koha/Account/Line.pm (+46 lines)
Lines 20-25 use Modern::Perl; Link Here
20
use Carp;
20
use Carp;
21
21
22
use Koha::Database;
22
use Koha::Database;
23
use Koha::Account::Offsets;
23
24
24
use base qw(Koha::Object);
25
use base qw(Koha::Object);
25
26
Lines 33-38 Koha::Account::Lines - Koha accountline Object class Link Here
33
34
34
=cut
35
=cut
35
36
37
=head3 void
38
39
$payment_accountline->void();
40
41
=cut
42
43
sub void {
44
    my ($self) = @_;
45
46
    # Make sure it is a payment we are voiding
47
    return unless $self->accounttype =~ /^Pay/;
48
49
    my @account_offsets =
50
      Koha::Account::Offsets->search( { credit_id => $self->id, type => 'Payment' } );
51
52
    foreach my $account_offset (@account_offsets) {
53
        my $fee_paid = Koha::Account::Lines->find( $account_offset->debit_id );
54
55
        next unless $fee_paid;
56
57
        my $amount_paid = $account_offset->amount * -1; # amount paid is stored as a negative amount
58
        my $new_amount = $fee_paid->amountoutstanding + $amount_paid;
59
        $fee_paid->amountoutstanding($new_amount);
60
        $fee_paid->store();
61
62
        Koha::Account::Offset->new(
63
            {
64
                credit_id => $self->id,
65
                debit_id  => $fee_paid->id,
66
                amount    => $amount_paid,
67
                type      => 'Void Payment',
68
            }
69
        )->store();
70
    }
71
72
    $self->set(
73
        {
74
            accounttype       => 'VOID',
75
            amountoutstanding => 0,
76
            amount            => 0,
77
        }
78
    );
79
    $self->store();
80
}
81
36
=head3 type
82
=head3 type
37
83
38
=cut
84
=cut
(-)a/installer/data/mysql/account_offset_types.sql (-1 / +2 lines)
Lines 9-12 INSERT INTO account_offset_types ( type ) VALUES Link Here
9
('Dropbox'),
9
('Dropbox'),
10
('Rental Fee'),
10
('Rental Fee'),
11
('Fine Update'),
11
('Fine Update'),
12
('Fine');
12
('Fine'),
13
('Void Payment');
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tt (+2 lines)
Lines 60-65 Link Here
60
          [% CASE 'Pay00' %]Payment, thanks (cash via SIP2)
60
          [% CASE 'Pay00' %]Payment, thanks (cash via SIP2)
61
          [% CASE 'Pay01' %]Payment, thanks (VISA via SIP2)
61
          [% CASE 'Pay01' %]Payment, thanks (VISA via SIP2)
62
          [% CASE 'Pay02' %]Payment, thanks (credit card via SIP2)
62
          [% CASE 'Pay02' %]Payment, thanks (credit card via SIP2)
63
          [% CASE 'VOID' %]Payment, Voided
63
          [% CASE 'N' %]New card
64
          [% CASE 'N' %]New card
64
          [% CASE 'F' %]Fine
65
          [% CASE 'F' %]Fine
65
          [% CASE 'A' %]Account management fee
66
          [% CASE 'A' %]Account management fee
Lines 93-98 Link Here
93
        [% IF ( reverse_col) %]
94
        [% IF ( reverse_col) %]
94
          [% IF ( account.payment ) %]
95
          [% IF ( account.payment ) %]
95
            <a href="boraccount.pl?action=reverse&amp;accountlines_id=[% account.accountlines_id %]&amp;borrowernumber=[% account.borrowernumber %]" class="btn btn-default btn-xs"><i class="fa fa-undo"></i> Reverse</a>
96
            <a href="boraccount.pl?action=reverse&amp;accountlines_id=[% account.accountlines_id %]&amp;borrowernumber=[% account.borrowernumber %]" class="btn btn-default btn-xs"><i class="fa fa-undo"></i> Reverse</a>
97
            <a href="boraccount.pl?action=void&amp;accountlines_id=[% account.accountlines_id %]&amp;borrowernumber=[% account.borrowernumber %]" class="btn btn-default btn-xs"><i class="fa fa-ban"></i> Void</a>
96
          [% ELSE %][% SET footerjs = 1 %]
98
          [% ELSE %][% SET footerjs = 1 %]
97
            &nbsp;
99
            &nbsp;
98
          [% END %]
100
          [% END %]
(-)a/members/boraccount.pl (-1 / +6 lines)
Lines 48-54 my ($template, $loggedinuser, $cookie) = get_template_and_user( Link Here
48
    }
48
    }
49
);
49
);
50
50
51
my $borrowernumber=$input->param('borrowernumber');
51
my $borrowernumber = $input->param('borrowernumber');
52
my $action = $input->param('action') || '';
52
my $action = $input->param('action') || '';
53
53
54
my $logged_in_user = Koha::Patrons->find( $loggedinuser ) or die "Not logged in";
54
my $logged_in_user = Koha::Patrons->find( $loggedinuser ) or die "Not logged in";
Lines 63-68 output_and_exit_if_error( $input, $cookie, $template, { module => 'members', log Link Here
63
if ( $action eq 'reverse' ) {
63
if ( $action eq 'reverse' ) {
64
  ReversePayment( scalar $input->param('accountlines_id') );
64
  ReversePayment( scalar $input->param('accountlines_id') );
65
}
65
}
66
elsif ( $action eq 'void' ) {
67
    my $payment_id = scalar $input->param('accountlines_id');
68
    my $payment    = Koha::Account::Lines->find( $payment_id );
69
    $payment->void();
70
}
66
71
67
if ( $patron->is_child ) {
72
if ( $patron->is_child ) {
68
    my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
73
    my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
(-)a/t/db_dependent/Accounts.t (-2 / +58 lines)
Lines 18-24 Link Here
18
18
19
use Modern::Perl;
19
use Modern::Perl;
20
20
21
use Test::More tests => 23;
21
use Test::More tests => 24;
22
use Test::MockModule;
22
use Test::MockModule;
23
use Test::Warn;
23
use Test::Warn;
24
24
Lines 630-633 subtest "Koha::Account::chargelostitem tests" => sub { Link Here
630
    is( $procfee->amount, "2.040000",  "Processing fee if processing fee");
630
    is( $procfee->amount, "2.040000",  "Processing fee if processing fee");
631
};
631
};
632
632
633
subtest "Koha::Account::Line::void tests" => sub {
634
635
    plan tests => 12;
636
637
    # Create a borrower
638
    my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
639
    my $branchcode   = $builder->build({ source => 'Branch' })->{ branchcode };
640
641
    my $borrower = Koha::Patron->new( {
642
        cardnumber => 'dariahall',
643
        surname => 'Hall',
644
        firstname => 'Daria',
645
    } );
646
    $borrower->categorycode( $categorycode );
647
    $borrower->branchcode( $branchcode );
648
    $borrower->store;
649
650
    my $account = Koha::Account->new({ patron_id => $borrower->id });
651
652
    my $line1 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amount => 10, amountoutstanding => 10 })->store();
653
    my $line2 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amount => 20, amountoutstanding => 20 })->store();
654
655
    is( $account->balance(), "30.000000", "Account balance is 30" );
656
    is( $line1->amountoutstanding, 10, 'First fee has amount outstanding of 10' );
657
    is( $line2->amountoutstanding, 20, 'Second fee has amount outstanding of 20' );
658
659
    my $id = $account->pay(
660
        {
661
            lines  => [$line1, $line2],
662
            amount => 30,
663
        }
664
    );
665
    my $account_payment = Koha::Account::Lines->find( $id );
666
667
    is( $account->balance(), "0.000000", "Account balance is 0" );
668
669
    $line1->_result->discard_changes();
670
    $line2->_result->discard_changes();
671
    is( $line1->amountoutstanding, '0.000000', 'First fee has amount outstanding of 0' );
672
    is( $line2->amountoutstanding, '0.000000', 'Second fee has amount outstanding of 0' );
673
674
    $account_payment->void();
675
676
    is( $account->balance(), "30.000000", "Account balance is again 30" );
677
678
    $account_payment->_result->discard_changes();
679
    $line1->_result->discard_changes();
680
    $line2->_result->discard_changes();
681
682
    is( $account_payment->accounttype, 'VOID', 'Voided payment accounttype is VOID' );
683
    is( $account_payment->amount, '0.000000', 'Voided payment amount is 0' );
684
    is( $account_payment->amountoutstanding, '0.000000', 'Voided payment amount outstanding is 0' );
685
686
    is( $line1->amountoutstanding, '10.000000', 'First fee again has amount outstanding of 10' );
687
    is( $line2->amountoutstanding, '20.000000', 'Second fee again has amount outstanding of 20' );
688
};
689
633
1;
690
1;
634
- 

Return to bug 18790