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

(-)a/Koha/Account/Line.pm (-1 / +7 lines)
Lines 304-309 sub reduce { Link Here
304
        Koha::Exceptions::Account::IsNotDebit->throw(
304
        Koha::Exceptions::Account::IsNotDebit->throw(
305
            error => 'Account line ' . $self->id . 'is not a debit' );
305
            error => 'Account line ' . $self->id . 'is not a debit' );
306
    }
306
    }
307
    if ( $self->debit_type_code eq 'PAYOUT' ) {
308
        Koha::Exceptions::Account::IsNotDebit->throw(
309
            error => 'Account line ' . $self->id . 'is a payout' );
310
    }
307
311
308
    # Check for mandatory parameters
312
    # Check for mandatory parameters
309
    my @mandatory = ( 'interface', 'reduction_type', 'amount' );
313
    my @mandatory = ( 'interface', 'reduction_type', 'amount' );
Lines 401-407 sub reduce { Link Here
401
        }
405
        }
402
    );
406
    );
403
407
404
    return $reduction->discard_changes;
408
    $reduction->discard_changes;
409
    return $reduction;
405
}
410
}
406
411
407
=head3 apply
412
=head3 apply
Lines 583-588 sub payout { Link Here
583
        }
588
        }
584
    );
589
    );
585
590
591
    $payout->discard_changes;
586
    return $payout;
592
    return $payout;
587
}
593
}
588
594
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tt (-1 / +1 lines)
Lines 87-93 Link Here
87
        [% IF CAN_user_updatecharges_payout && account.is_credit && ( account.amountoutstanding < 0 ) %]
87
        [% IF CAN_user_updatecharges_payout && account.is_credit && ( account.amountoutstanding < 0 ) %]
88
          <button type="button" data-toggle="modal" data-target="#issuePayoutModal" data-account="[%- PROCESS account_type_description account=account -%]" data-accountline="[% account.accountlines_id | html %]" data-amount="[% account.amountoutstanding | $Price %]" class="btn btn-default btn-xs"><i class="fa fa-money"></i> Issue payout</button>
88
          <button type="button" data-toggle="modal" data-target="#issuePayoutModal" data-account="[%- PROCESS account_type_description account=account -%]" data-accountline="[% account.accountlines_id | html %]" data-amount="[% account.amountoutstanding | $Price %]" class="btn btn-default btn-xs"><i class="fa fa-money"></i> Issue payout</button>
89
        [% END %]
89
        [% END %]
90
        [% IF CAN_user_updatecharges_refund && account.is_debit && ( account.amountoutstanding != account.amount ) && !(account.status == 'REFUNDED' ) %]
90
        [% IF CAN_user_updatecharges_refund && account.is_debit && ( account.amountoutstanding != account.amount ) && !(account.status == 'REFUNDED') && !(account.debit_type_code == 'PAYOUT') %]
91
          <button type="button" data-toggle="modal" data-target="#issueRefundModal" data-item="[%- PROCESS account_type_description account=account -%]" data-accountline="[% account.accountlines_id | html %]" data-amount="[% account.amount | $Price %]" data-amountoutstanding="[% account.amountoutstanding | $Price %]" class="btn btn-default btn-xs"><i class="fa fa-money"></i> Issue refund</button>
91
          <button type="button" data-toggle="modal" data-target="#issueRefundModal" data-item="[%- PROCESS account_type_description account=account -%]" data-accountline="[% account.accountlines_id | html %]" data-amount="[% account.amount | $Price %]" data-amountoutstanding="[% account.amountoutstanding | $Price %]" class="btn btn-default btn-xs"><i class="fa fa-money"></i> Issue refund</button>
92
        [% END %]
92
        [% END %]
93
      </td>
93
      </td>
(-)a/t/db_dependent/Koha/Account/Lines.t (-14 / +34 lines)
Lines 895-901 subtest "void() tests" => sub { Link Here
895
895
896
subtest "payout() tests" => sub {
896
subtest "payout() tests" => sub {
897
897
898
    plan tests => 17;
898
    plan tests => 18;
899
899
900
    $schema->storage->txn_begin;
900
    $schema->storage->txn_begin;
901
901
Lines 948-956 subtest "payout() tests" => sub { Link Here
948
    )->store();
948
    )->store();
949
949
950
    is( $account->balance(), -10, "Account balance is -10" );
950
    is( $account->balance(), -10, "Account balance is -10" );
951
    is( $debit1->amountoutstanding,
951
    is( $debit1->amountoutstanding + 0,
952
        10, 'Overdue fee has an amount outstanding of 10' );
952
        10, 'Overdue fee has an amount outstanding of 10' );
953
    is( $credit1->amountoutstanding,
953
    is( $credit1->amountoutstanding + 0,
954
        -20, 'Credit has an amount outstanding of -20' );
954
        -20, 'Credit has an amount outstanding of -20' );
955
955
956
    my $pay_params = {
956
    my $pay_params = {
Lines 1017-1028 subtest "payout() tests" => sub { Link Here
1017
        }
1017
        }
1018
    );
1018
    );
1019
1019
1020
    is( $payout->amount(),            10, "Payout amount is 10" );
1020
    is( ref($payout), 'Koha::Account::Line',
1021
    is( $payout->amountoutstanding(), 0,  "Payout amountoutstanding is 0" );
1021
        '->payout() returns a Koha::Account::Line' );
1022
    is( $account->balance(),          0,  "Account balance is 0" );
1022
    is( $payout->amount() + 0,            10, "Payout amount is 10" );
1023
    is( $debit1->amountoutstanding,
1023
    is( $payout->amountoutstanding() + 0, 0,  "Payout amountoutstanding is 0" );
1024
    is( $account->balance() + 0,          0,  "Account balance is 0" );
1025
    is( $debit1->amountoutstanding + 0,
1024
        10, 'Overdue fee still has an amount outstanding of 10' );
1026
        10, 'Overdue fee still has an amount outstanding of 10' );
1025
    is( $credit1->amountoutstanding,
1027
    is( $credit1->amountoutstanding + 0,
1026
        -10, 'Credit has an new amount outstanding of -10' );
1028
        -10, 'Credit has an new amount outstanding of -10' );
1027
    is( $credit1->status(), 'PAID', "Credit has a new status of PAID" );
1029
    is( $credit1->status(), 'PAID', "Credit has a new status of PAID" );
1028
1030
Lines 1031-1037 subtest "payout() tests" => sub { Link Here
1031
1033
1032
subtest "reduce() tests" => sub {
1034
subtest "reduce() tests" => sub {
1033
1035
1034
    plan tests => 25;
1036
    plan tests => 27;
1035
1037
1036
    $schema->storage->txn_begin;
1038
    $schema->storage->txn_begin;
1037
1039
Lines 1142-1153 subtest "reduce() tests" => sub { Link Here
1142
    # (Refund 5 on debt of 20)
1144
    # (Refund 5 on debt of 20)
1143
    my $reduction = $debit1->reduce($reduce_params);
1145
    my $reduction = $debit1->reduce($reduce_params);
1144
1146
1147
    is( ref($reduction), 'Koha::Account::Line',
1148
        '->reduce() returns a Koha::Account::Line' );
1145
    is( $reduction->amount() * 1, -5, "Reduce amount is -5" );
1149
    is( $reduction->amount() * 1, -5, "Reduce amount is -5" );
1146
    is( $reduction->amountoutstanding() * 1,
1150
    is( $reduction->amountoutstanding() * 1,
1147
        0, "Reduce amountoutstanding is 0" );
1151
        0, "Reduce amountoutstanding is 0" );
1148
    is( $debit1->amountoutstanding() * 1,
1152
    is( $debit1->amountoutstanding() * 1,
1149
        15, "Debit amountoutstanding reduced by 5 to 15" );
1153
        15, "Debit amountoutstanding reduced by 5 to 15" );
1150
    is( $account->balance() * 1, -5,       "Account balance is -5" );
1154
    is( $account->balance() * 1, -5,        "Account balance is -5" );
1151
    is( $reduction->status(),    'APPLIED', "Reduction status is 'APPLIED'" );
1155
    is( $reduction->status(),    'APPLIED', "Reduction status is 'APPLIED'" );
1152
1156
1153
    my $offsets = Koha::Account::Offsets->search(
1157
    my $offsets = Koha::Account::Offsets->search(
Lines 1160-1167 subtest "reduce() tests" => sub { Link Here
1160
1164
1161
    # Zero offset created when zero outstanding
1165
    # Zero offset created when zero outstanding
1162
    # (Refund another 5 on paid debt of 20)
1166
    # (Refund another 5 on paid debt of 20)
1163
    $credit1->apply( { debits => [ $debit1 ] } );
1167
    $credit1->apply( { debits => [$debit1] } );
1164
    is($debit1->amountoutstanding + 0, 0, 'Debit1 amountoutstanding reduced to 0');
1168
    is( $debit1->amountoutstanding + 0,
1169
        0, 'Debit1 amountoutstanding reduced to 0' );
1165
    $reduction = $debit1->reduce($reduce_params);
1170
    $reduction = $debit1->reduce($reduce_params);
1166
    is( $reduction->amount() * 1, -5, "Reduce amount is -5" );
1171
    is( $reduction->amount() * 1, -5, "Reduce amount is -5" );
1167
    is( $reduction->amountoutstanding() * 1,
1172
    is( $reduction->amountoutstanding() * 1,
Lines 1182-1188 subtest "reduce() tests" => sub { Link Here
1182
        $debit1->reduce($reduce_params);
1187
        $debit1->reduce($reduce_params);
1183
    }
1188
    }
1184
    'Koha::Exceptions::ParameterTooHigh',
1189
    'Koha::Exceptions::ParameterTooHigh',
1185
'->reduce cannot reduce mor than the original amount (combined reductions test)';
1190
'->reduce cannot reduce more than the original amount (combined reductions test)';
1191
1192
    # Throw exception if attempting to reduce a payout
1193
    my $payout = $reduction->payout(
1194
        {
1195
            interface   => 'intranet',
1196
            staff_id    => $staff->borrowernumber,
1197
            branch      => $branchcode,
1198
            payout_type => 'CASH',
1199
            amount      => 5
1200
        }
1201
    );
1202
    throws_ok {
1203
        $payout->reduce($reduce_params);
1204
    }
1205
    'Koha::Exceptions::Account::IsNotDebit',
1206
      '->reduce() cannot be used on a payout debit';
1186
1207
1187
    $schema->storage->txn_rollback;
1208
    $schema->storage->txn_rollback;
1188
};
1209
};
1189
- 

Return to bug 23442