From 9b1e34fb9f86f9c8ae418cb925bf98313d5a8873 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 15 Feb 2024 17:10:00 +0000 Subject: [PATCH] Bug 34478: Move writeoff-individual to paycollect.pl Signed-off-by: Jonathan Druart --- .../prog/en/modules/members/paycollect.tt | 5 +-- members/pay.pl | 35 ---------------- members/paycollect.pl | 41 +++++++++++++++++++ 3 files changed, 43 insertions(+), 38 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tt index 68c331646c..eb5fb97836 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tt @@ -231,12 +231,12 @@ -
+ [% INCLUDE 'csrf-token.inc' %]
Write off an individual charge + - @@ -244,7 +244,6 @@ - diff --git a/members/pay.pl b/members/pay.pl index e9c9378003..af492f22e8 100755 --- a/members/pay.pl +++ b/members/pay.pl @@ -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+)$/) { diff --git a/members/paycollect.pl b/members/paycollect.pl index 03b45af68d..8ddf4a1dfc 100755 --- a/members/paycollect.pl +++ b/members/paycollect.pl @@ -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') ); } -- 2.39.5