Bug 20120: Prevent writeoffs of more than the amount owed for a fee

In short, it is possible to 'over-writeoff' a fee such that the value of the fee is now a credit.

Test Plan:
1) Attempt to writeoff a single fee, set the amount input to more than
   the amount of the fee.
2) Note the writeoff makes the fee go negative.
3) Apply this patch
4) Attempt to repeat step 1, you should be unable to write-off an
   amount more than the amount outstanding for the fee!

Signed-off-by: George Williams <george@nekls.org>

Signed-off-by: George Williams <george@nekls.org>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
This commit is contained in:
Kyle M Hall 2018-03-09 09:20:40 -05:00 committed by Nick Clemens
parent f8ea20344b
commit 515cab0c46
3 changed files with 54 additions and 13 deletions

View File

@ -2,6 +2,7 @@
[% USE Koha %]
[% USE Branches %]
[% USE AuthorisedValues %]
[% USE Price %]
[% SET footerjs = 1 %]
[% INCLUDE 'doc-head-open.inc' %]
<title>Koha &rsaquo; Patrons &rsaquo; Collect fine payment for [% patron.firstname %] [% patron.surname %]</title>
@ -119,6 +120,8 @@
<input type="hidden" name="accountlines_id" id="accountlines_id" value="[% accountlines_id %]" />
<input type="hidden" name="title" id="title" value="[% title %]" />
<input type="hidden" name="payment_note" id="payment_note" value="[% payment_note %]" />
<input type="hidden" name="amountoutstanding" id="amountoutstanding" value="[% amountoutstanding %]" />
<input type="hidden" name="confirm_writeoff" id="confirm_writeoff" value="1" />
<table>
<thead><tr>
<th>Description</th>
@ -139,12 +142,14 @@
<li>
<label for="paid">Writeoff amount: </label>
<!-- default to writing off all -->
<input name="amountwrittenoff" id="amountwrittenoff" value="[% amountoutstanding %]" />
<input name="amountwrittenoff" id="amountwrittenoff" value="[% amountoutstanding | $Price %]" />
</li>
</ol>
</fieldset>
<div class="action"><input type="submit" name="confirm_writeoff" id="confirm_writeoff" value="Write off this charge" />
<a class="cancel" href="/cgi-bin/koha/members/pay.pl?borrowernumber=[% patron.borrowernumber %]">Cancel</a></div>
<div class="action">
<input type="submit" value="Write off this charge" />
<a class="cancel" href="/cgi-bin/koha/members/pay.pl?borrowernumber=[% patron.borrowernumber %]">Cancel</a>
</div>
</form>
[% ELSE %]
@ -201,12 +206,30 @@
[% Asset.js("js/members-menu.js") %]
<script type= "text/javascript">
$(document).ready(function() {
$('#payindivfine, #woindivfine, #payfine').preventDoubleFormSubmit();
$('#payindivfine, #payfine').preventDoubleFormSubmit();
$("#paid").on("change",function(){
moneyFormat( this );
});
});
prevent_default = 1;
$('#woindivfine').on('submit', function(e){
if ( prevent_default ) {
e.preventDefault();
let amount_outstanding = parseFloat( $('#amountoutstanding').attr('value') );
let amount_writeoff = parseFloat( $('#amountwrittenoff').attr('value') );
if ( amount_writeoff > amount_outstanding ) {
alert(_("You are attemping to writeoff more than the value of the fee."));
$('#woindivfine').beenSubmitted = false;
} else {
prevent_default = 0;
$('#woindivfine').preventDoubleFormSubmit();
$('#woindivfine').submit();
}
}
});
function moneyFormat(textObj) {
var newValue = textObj.value;
var decAmount = "";

View File

@ -93,15 +93,29 @@ if ($writeoff_all) {
my $amount = $input->param('amountwrittenoff');
my $payment_note = $input->param("payment_note");
Koha::Account->new( { patron_id => $borrowernumber } )->pay(
{
amount => $amount,
lines => [ scalar Koha::Account::Lines->find($accountlines_id) ],
type => 'writeoff',
note => $payment_note,
library_id => $branch,
}
);
my $accountline = Koha::Account::Lines->find( $accountlines_id );
if ( $amount > $accountline->amountoutstanding ) {
print $input->redirect( "/cgi-bin/koha/members/paycollect.pl?"
. "borrowernumber=$borrowernumber"
. "&amount=$amount"
. "&amountoutstanding=" . $accountline->amountoutstanding
. "&accounttype=" . $accountline->accounttype
. "&accountlines_id=" . $accountlines_id
. "&writeoff_individual=1"
. "&error_over=1" );
} else {
Koha::Account->new( { patron_id => $borrowernumber } )->pay(
{
amount => $amount,
lines => [ scalar Koha::Account::Lines->find($accountlines_id) ],
type => 'writeoff',
note => $payment_note,
library_id => $branch,
}
);
}
}
for (@names) {

View File

@ -182,6 +182,10 @@ borrower_add_additional_fields($borrower, $template);
$template->param(%$borrower);
if ( $input->param('error_over') ) {
$template->param( error_over => 1, total_due => $input->param('amountoutstanding') );
}
$template->param(
borrowernumber => $borrowernumber, # some templates require global
patron => $patron,