@@ -, +, @@ on it. It should now be marked as cancelled that it still works --- Koha/Account/Line.pm | 50 +++++++++++++- .../prog/en/includes/accounts.inc | 1 + .../prog/en/modules/members/boraccount.tt | 15 ++++- members/boraccount.pl | 6 ++ members/cancel-charge.pl | 48 ++++++++++++++ t/db_dependent/Koha/Account/Line.t | 66 +++++++++++++++++++ 6 files changed, 183 insertions(+), 3 deletions(-) create mode 100755 members/cancel-charge.pl --- a/Koha/Account/Line.pm +++ a/Koha/Account/Line.pm @@ -285,6 +285,54 @@ sub void { } +=head3 cancel + + $debit_accountline->cancel(); + +Cancel a charge. It will mark the debit as 'cancelled' by updating its +status to 'CANCELLED'. +Charges that have been fully or partially paid cannot be cancelled. + +Return self in case of success, undef otherwise + +=cut + +sub cancel { + my ($self) = @_; + + # Make sure it is a charge we are cancelling + return unless $self->is_debit; + + # Make sure it is not already cancelled + return if $self->status && $self->status eq 'CANCELLED'; + + # Make sure it has not be paid yet + return if $self->amount != $self->amountoutstanding; + + if ( C4::Context->preference("FinesLog") ) { + logaction('FINES', 'CANCEL', $self->borrowernumber, Dumper({ + action => 'cancel_charge', + borrowernumber => $self->borrowernumber, + amount => $self->amount, + amountoutstanding => $self->amountoutstanding, + description => $self->description, + debit_type_code => $self->debit_type_code, + note => $self->note, + itemnumber => $self->itemnumber, + manager_id => $self->manager_id, + })); + } + + $self->set({ + status => 'CANCELLED', + amountoutstanding => 0, + amount => 0, + }); + $self->store(); + + return $self; +} + =head3 reduce $charge_accountline->reduce({ @@ -754,7 +802,7 @@ sub adjust { sub is_credit { my ($self) = @_; - return ( $self->amount < 0 ); + return defined $self->credit_type_code; } =head3 is_debit --- a/koha-tmpl/intranet-tmpl/prog/en/includes/accounts.inc +++ a/koha-tmpl/intranet-tmpl/prog/en/includes/accounts.inc @@ -31,6 +31,7 @@ [%- CASE 'FORGIVEN' -%] (Forgiven) [%- CASE 'VOID' -%] (Voided) [%- CASE 'LOST' -%] (Lost) + [%- CASE 'CANCELLED' -%] (Cancelled) [%- CASE -%] [%- END -%] [%- END -%] --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tt @@ -95,8 +95,19 @@ [% IF account.is_debit && account.amountoutstanding > 0 %] Pay [% END %] - [% IF account.is_credit %] - Void + [% IF account.is_credit && account.status != 'VOID' %] + Void payment + [% END %] + [% IF account.is_debit && account.amount == account.amountoutstanding && account.status != 'CANCELLED' %] +
[% END %] [% IF CAN_user_updatecharges_payout && account.is_credit && ( account.amountoutstanding < 0 ) %] --- a/members/boraccount.pl +++ a/members/boraccount.pl @@ -34,6 +34,7 @@ use Koha::Cash::Registers; use Koha::Patrons; use Koha::Patron::Categories; use Koha::Items; +use Koha::Token; my $input=CGI->new; @@ -202,6 +203,10 @@ foreach my $renew_result(@renew_results) { }; } +my $csrf_token = Koha::Token->new->generate_csrf({ + session_id => scalar $input->cookie('CGISESSID'), +}); + $template->param( patron => $patron, finesview => 1, @@ -211,6 +216,7 @@ $template->param( payment_id => $payment_id, change_given => $change_given, renew_results => $renew_results_display, + csrf_token => $csrf_token, ); output_html_with_http_headers $input, $cookie, $template->output; --- a/members/cancel-charge.pl +++ a/members/cancel-charge.pl @@ -0,0 +1,48 @@ +#!/usr/bin/perl + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see