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
        );
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/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tt (+2 lines)
Lines 90-95 $(document).ready(function() { Link Here
90
          [% CASE 'Pay00' %]Payment, thanks (cash via SIP2)
90
          [% CASE 'Pay00' %]Payment, thanks (cash via SIP2)
91
          [% CASE 'Pay01' %]Payment, thanks (VISA via SIP2)
91
          [% CASE 'Pay01' %]Payment, thanks (VISA via SIP2)
92
          [% CASE 'Pay02' %]Payment, thanks (credit card via SIP2)
92
          [% CASE 'Pay02' %]Payment, thanks (credit card via SIP2)
93
          [% CASE 'VOID' %]Payment, Voided
93
          [% CASE 'N' %]New card
94
          [% CASE 'N' %]New card
94
          [% CASE 'F' %]Fine
95
          [% CASE 'F' %]Fine
95
          [% CASE 'A' %]Account management fee
96
          [% CASE 'A' %]Account management fee
Lines 122-127 $(document).ready(function() { Link Here
122
        [% IF ( reverse_col) %]
123
        [% IF ( reverse_col) %]
123
          [% IF ( account.payment ) %]
124
          [% IF ( account.payment ) %]
124
            <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>
125
            <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>
126
            <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>
125
          [% ELSE %]
127
          [% ELSE %]
126
            &nbsp;
128
            &nbsp;
127
          [% END %]
129
          [% END %]
(-)a/members/boraccount.pl (-1 / +6 lines)
Lines 49-55 my ($template, $loggedinuser, $cookie) = get_template_and_user( Link Here
49
    }
49
    }
50
);
50
);
51
51
52
my $borrowernumber=$input->param('borrowernumber');
52
my $borrowernumber = $input->param('borrowernumber');
53
my $action = $input->param('action') || '';
53
my $action = $input->param('action') || '';
54
54
55
#get patron details
55
#get patron details
Lines 62-67 unless ( $patron ) { Link Here
62
if ( $action eq 'reverse' ) {
62
if ( $action eq 'reverse' ) {
63
  ReversePayment( scalar $input->param('accountlines_id') );
63
  ReversePayment( scalar $input->param('accountlines_id') );
64
}
64
}
65
elsif ( $action eq 'void' ) {
66
    my $payment_id = scalar $input->param('accountlines_id');
67
    my $payment    = Koha::Account::Lines->find( $payment_id );
68
    $payment->void();
69
}
65
70
66
if ( $patron->category->category_type eq 'C') {
71
if ( $patron->category->category_type eq 'C') {
67
    my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
72
    my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
(-)a/t/db_dependent/Accounts.t (-2 / +59 lines)
Lines 18-24 Link Here
18
18
19
use Modern::Perl;
19
use Modern::Perl;
20
20
21
use Test::More tests => 22;
21
use Test::More tests => 23;
22
use Test::MockModule;
22
use Test::MockModule;
23
use Test::Warn;
23
use Test::Warn;
24
24
Lines 490-492 subtest 'balance' => sub { Link Here
490
    $patron->delete;
490
    $patron->delete;
491
};
491
};
492
492
493
- 
493
subtest "Koha::Account::Line::void tests" => sub {
494
495
    plan tests => 12;
496
497
    # Create a borrower
498
    my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
499
    my $branchcode   = $builder->build({ source => 'Branch' })->{ branchcode };
500
501
    my $borrower = Koha::Patron->new( {
502
        cardnumber => 'dariahall',
503
        surname => 'Hall',
504
        firstname => 'Daria',
505
    } );
506
    $borrower->categorycode( $categorycode );
507
    $borrower->branchcode( $branchcode );
508
    $borrower->store;
509
510
    my $account = Koha::Account->new({ patron_id => $borrower->id });
511
512
    my $line1 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amount => 10, amountoutstanding => 10 })->store();
513
    my $line2 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amount => 20, amountoutstanding => 20 })->store();
514
515
    is( $account->balance(), "30.000000", "Account balance is 30" );
516
    is( $line1->amountoutstanding, 10, 'First fee has amount outstanding of 10' );
517
    is( $line2->amountoutstanding, 20, 'Second fee has amount outstanding of 20' );
518
519
    my $id = $account->pay(
520
        {
521
            lines  => [$line1, $line2],
522
            amount => 30,
523
        }
524
    );
525
    my $account_payment = Koha::Account::Lines->find( $id );
526
527
    is( $account->balance(), "0.000000", "Account balance is 0" );
528
529
    $line1->_result->discard_changes();
530
    $line2->_result->discard_changes();
531
    is( $line1->amountoutstanding, '0.000000', 'First fee has amount outstanding of 0' );
532
    is( $line2->amountoutstanding, '0.000000', 'Second fee has amount outstanding of 0' );
533
534
    $account_payment->void();
535
536
    is( $account->balance(), "30.000000", "Account balance is again 30" );
537
538
    $account_payment->_result->discard_changes();
539
    $line1->_result->discard_changes();
540
    $line2->_result->discard_changes();
541
542
    is( $account_payment->accounttype, 'VOID', 'Voided payment accounttype is VOID' );
543
    is( $account_payment->amount, '0.000000', 'Voided payment amount is 0' );
544
    is( $account_payment->amountoutstanding, '0.000000', 'Voided payment amount outstanding is 0' );
545
546
    is( $line1->amountoutstanding, '10.000000', 'First fee again has amount outstanding of 10' );
547
    is( $line2->amountoutstanding, '20.000000', 'Second fee again has amount outstanding of 20' );
548
};
549
550
1;

Return to bug 18790