Bug 34478: Move writeoff-individual to paycollect.pl

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Martin Renvoize 2024-02-15 17:10:00 +00:00 committed by Jonathan Druart
parent b920d12090
commit 9b1e34fb9f
Signed by: jonathan.druart
GPG key ID: A085E712BEF0E0F0
3 changed files with 43 additions and 38 deletions

View file

@ -231,12 +231,12 @@
<li role="presentation" class="active"><a href="#">Write off</a></li>
</ul>
<form name="woindivfine" id="woindivfine" action="/cgi-bin/koha/members/pay.pl" method="post" >
<form name="woindivfine" id="woindivfine" action="/cgi-bin/koha/members/paycollect.pl" method="post" >
[% INCLUDE 'csrf-token.inc' %]
<fieldset class="rows">
<legend>Write off an individual charge</legend>
<input type="hidden" name="op" value="cud-writeoff-individual" />
<input type="hidden" name="borrowernumber" id="borrowernumber" value="[% patron.borrowernumber | html %]" />
<input type="hidden" name="pay_individual" id="pay_individual" value="[% pay_individual | html %]" />
<input type="hidden" name="itemnumber" id="itemnumber" value="[% itemnumber | html %]" />
<input type="hidden" name="description" id="description" value="[% individual_description | html %]" />
<input type="hidden" name="debit_type_code" id="debit_type_code" value="[% debit_type_code | html %]" />
@ -244,7 +244,6 @@
<input type="hidden" name="accountlines_id" id="accountlines_id" value="[% accountlines_id | html %]" />
<input type="hidden" name="payment_note" id="payment_note" value="[% payment_note | html %]" />
<input type="hidden" name="amountoutstanding" id="amountoutstanding" value="[% amountoutstanding | html %]" />
<input type="hidden" name="confirm_writeoff" id="confirm_writeoff" value="1" />
<input type="hidden" name="change_given" id="change_given" />
<table>
<thead><tr>

View file

@ -94,41 +94,6 @@ elsif ( $op eq 'cud-woall' ) {
elsif ( $op eq 'cud-apply_credits' ) {
apply_credits({ patron => $patron, cgi => $input });
}
elsif ( $input->param('confirm_writeoff') ) {
#FIXME: This block really belongs in paycollect
my $item_id = $input->param('itemnumber');
my $accountlines_id = $input->param('accountlines_id');
my $amount = $input->param('amountwrittenoff');
my $payment_note = $input->param("payment_note");
my $accountline = Koha::Account::Lines->find( $accountlines_id );
$amount = $accountline->amountoutstanding if (abs($amount - $accountline->amountoutstanding) < 0.01) && C4::Context->preference('RoundFinesAtPayment');
if ( $amount > $accountline->amountoutstanding ) {
print $input->redirect( "/cgi-bin/koha/members/paycollect.pl?"
. "borrowernumber=$borrowernumber"
. "&amount=" . $accountline->amount
. "&amountoutstanding=" . $accountline->amountoutstanding
. "&debit_type_code=" . $accountline->debit_type_code
. "&accountlines_id=" . $accountlines_id
. "&change_given=" . $change_given
. "&writeoff_individual=1"
. "&error_over=1" );
} else {
$payment_id = Koha::Account->new( { patron_id => $borrowernumber } )->pay(
{
amount => $amount,
lines => [ Koha::Account::Lines->find($accountlines_id) ],
type => 'WRITEOFF',
note => $payment_note,
interface => C4::Context->interface,
item_id => $item_id,
library_id => $branch,
}
)->{payment_id};
}
}
for (@names) {
if ($op =~ /^cud-pay_indiv_(\d+)$/) {

View file

@ -58,6 +58,9 @@ my $logged_in_user = Koha::Patrons->find( $loggedinuser );
my $patron = Koha::Patrons->find( $borrowernumber );
output_and_exit_if_error( $input, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } );
# get operation
my $op = $input->param('op') // qw{};
my $account = $patron->account;
my $category = $patron->category;
my $user = $input->remote_user;
@ -264,6 +267,44 @@ if ( $total_paid and $total_paid ne '0.00' ) {
$total_paid = '0.00'; #TODO not right with pay_individual
}
if ( $op eq 'cud-writeoff-individual' ) {
my $item_id = $input->param('itemnumber');
my $accountlines_id = $input->param('accountlines_id');
my $amount = $input->param('amountwrittenoff');
my $payment_note = $input->param("payment_note");
my $accountline = Koha::Account::Lines->find( $accountlines_id );
$amount = $accountline->amountoutstanding if (abs($amount - $accountline->amountoutstanding) < 0.01) && C4::Context->preference('RoundFinesAtPayment');
if ( $amount > $accountline->amountoutstanding ) {
print $input->redirect( "/cgi-bin/koha/members/paycollect.pl?"
. "borrowernumber=$borrowernumber"
. "&amount=" . $accountline->amount
. "&amountoutstanding=" . $accountline->amountoutstanding
. "&debit_type_code=" . $accountline->debit_type_code
. "&accountlines_id=" . $accountlines_id
. "&writeoff_individual=1"
. "&error_over=1" );
} else {
$payment_id = Koha::Account->new( { patron_id => $borrowernumber } )->pay(
{
amount => $amount,
lines => [ Koha::Account::Lines->find($accountlines_id) ],
type => 'WRITEOFF',
note => $payment_note,
interface => C4::Context->interface,
item_id => $item_id,
library_id => $library_id,
}
)->{payment_id};
my $url = "/cgi-bin/koha/members/pay.pl";
$url .= "?borrowernumber=$borrowernumber";
print $input->redirect($url);
}
}
if ( $input->param('error_over') ) {
$template->param( error_over => 1, total_due => scalar $input->param('amountoutstanding') );
}