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

(-)a/Koha/Account/Line.pm (+46 lines)
Lines 21-26 use Carp; Link Here
21
21
22
use Koha::Database;
22
use Koha::Database;
23
use Koha::Items;
23
use Koha::Items;
24
use Koha::Account::Offsets;
24
25
25
use base qw(Koha::Object);
26
use base qw(Koha::Object);
26
27
Lines 46-51 sub item { Link Here
46
    return Koha::Item->_new_from_dbic( $rs );
47
    return Koha::Item->_new_from_dbic( $rs );
47
}
48
}
48
49
50
=head3 void
51
52
$payment_accountline->void();
53
54
=cut
55
56
sub void {
57
    my ($self) = @_;
58
59
    # Make sure it is a payment we are voiding
60
    return unless $self->accounttype =~ /^Pay/;
61
62
    my @account_offsets =
63
      Koha::Account::Offsets->search( { credit_id => $self->id, type => 'Payment' } );
64
65
    foreach my $account_offset (@account_offsets) {
66
        my $fee_paid = Koha::Account::Lines->find( $account_offset->debit_id );
67
68
        next unless $fee_paid;
69
70
        my $amount_paid = $account_offset->amount * -1; # amount paid is stored as a negative amount
71
        my $new_amount = $fee_paid->amountoutstanding + $amount_paid;
72
        $fee_paid->amountoutstanding($new_amount);
73
        $fee_paid->store();
74
75
        Koha::Account::Offset->new(
76
            {
77
                credit_id => $self->id,
78
                debit_id  => $fee_paid->id,
79
                amount    => $amount_paid,
80
                type      => 'Void Payment',
81
            }
82
        )->store();
83
    }
84
85
    $self->set(
86
        {
87
            accounttype       => 'VOID',
88
            amountoutstanding => 0,
89
            amount            => 0,
90
        }
91
    );
92
    $self->store();
93
}
94
49
=head3 _type
95
=head3 _type
50
96
51
=cut
97
=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 => 25;
21
use Test::More tests => 26;
22
use Test::MockModule;
22
use Test::MockModule;
23
use Test::Warn;
23
use Test::Warn;
24
24
Lines 847-850 subtest "Koha::Account::non_issues_charges tests" => sub { Link Here
847
    is( Koha::Account::Lines->count({ borrowernumber => $patron->id }), 2 + 2, "The 2 + 2 account lines still exists, the last 2 have been deleted ok" );
847
    is( Koha::Account::Lines->count({ borrowernumber => $patron->id }), 2 + 2, "The 2 + 2 account lines still exists, the last 2 have been deleted ok" );
848
};
848
};
849
849
850
subtest "Koha::Account::Line::void tests" => sub {
851
852
    plan tests => 12;
853
854
    # Create a borrower
855
    my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
856
    my $branchcode   = $builder->build({ source => 'Branch' })->{ branchcode };
857
858
    my $borrower = Koha::Patron->new( {
859
        cardnumber => 'dariahall',
860
        surname => 'Hall',
861
        firstname => 'Daria',
862
    } );
863
    $borrower->categorycode( $categorycode );
864
    $borrower->branchcode( $branchcode );
865
    $borrower->store;
866
867
    my $account = Koha::Account->new({ patron_id => $borrower->id });
868
869
    my $line1 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amount => 10, amountoutstanding => 10 })->store();
870
    my $line2 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amount => 20, amountoutstanding => 20 })->store();
871
872
    is( $account->balance(), 30, "Account balance is 30" );
873
    is( $line1->amountoutstanding, 10, 'First fee has amount outstanding of 10' );
874
    is( $line2->amountoutstanding, 20, 'Second fee has amount outstanding of 20' );
875
876
    my $id = $account->pay(
877
        {
878
            lines  => [$line1, $line2],
879
            amount => 30,
880
        }
881
    );
882
    my $account_payment = Koha::Account::Lines->find( $id );
883
884
    is( $account->balance(), 0, "Account balance is 0" );
885
886
    $line1->_result->discard_changes();
887
    $line2->_result->discard_changes();
888
    is( $line1->amountoutstanding, '0.000000', 'First fee has amount outstanding of 0' );
889
    is( $line2->amountoutstanding, '0.000000', 'Second fee has amount outstanding of 0' );
890
891
    $account_payment->void();
892
893
    is( $account->balance(), 30, "Account balance is again 30" );
894
895
    $account_payment->_result->discard_changes();
896
    $line1->_result->discard_changes();
897
    $line2->_result->discard_changes();
898
899
    is( $account_payment->accounttype, 'VOID', 'Voided payment accounttype is VOID' );
900
    is( $account_payment->amount, '0.000000', 'Voided payment amount is 0' );
901
    is( $account_payment->amountoutstanding, '0.000000', 'Voided payment amount outstanding is 0' );
902
903
    is( $line1->amountoutstanding, '10.000000', 'First fee again has amount outstanding of 10' );
904
    is( $line2->amountoutstanding, '20.000000', 'Second fee again has amount outstanding of 20' );
905
};
906
850
1;
907
1;
851
- 

Return to bug 18790