From adbe4f0d9053deeb87e7643bd68538b315bfec2d Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 16 Feb 2024 09:32:57 +0000 Subject: [PATCH] Bug 34478: Add op to pay_individual I also move the writeoff handling out of it's own block in into the rest of the x_individual handling. Signed-off-by: Jonathan Druart --- .../prog/en/modules/members/paycollect.tt | 10 +-- members/paycollect.pl | 70 +++++++------------ 2 files changed, 32 insertions(+), 48 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 eb5fb97836..b04eab2647 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tt @@ -137,8 +137,9 @@
[% INCLUDE 'csrf-token.inc' %] + + - @@ -235,7 +236,8 @@ [% INCLUDE 'csrf-token.inc' %]
Write off an individual charge - + + @@ -264,9 +266,9 @@
  1. - + - +
diff --git a/members/paycollect.pl b/members/paycollect.pl index 8ddf4a1dfc..fee692356e 100755 --- a/members/paycollect.pl +++ b/members/paycollect.pl @@ -43,6 +43,9 @@ my $writeoff_individual = $input->param('writeoff_individual'); my $change_given = $input->param('change_given'); my $type = scalar $input->param('type') || 'PAYMENT'; +# get operation +my $op = $input->param('op') // qw{}; + my $updatecharges_permissions = ($writeoff_individual || $type eq 'WRITEOFF') ? 'writeoff' : 'remaining_permissions'; my ( $template, $loggedinuser, $cookie ) = get_template_and_user( { template_name => 'members/paycollect.tt', @@ -58,9 +61,6 @@ 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; @@ -138,14 +138,15 @@ if ( $selected_accts ) { $total_due = $sum->_resultset->first->get_column('total_amountoutstanding'); } -if ( $total_paid and $total_paid ne '0.00' ) { +if ( $total_paid and $total_paid ne '0.00' && ( $op eq 'cud-writeoff_individual' || $op eq 'cud-pay_individual' ) ) { + $accountlines_id = $input->param('accountlines_id'); $total_paid = $total_due if (abs($total_paid - $total_due) < 0.01) && C4::Context->preference('RoundFinesAtPayment'); if ( $total_paid < 0 or $total_paid > $total_due ) { $template->param( error_over => 1, total_due => $total_due ); - } elsif ( $total_collected < $total_paid && !( $writeoff_individual || $type eq 'WRITEOFF' ) ) { + } elsif ( $total_collected < $total_paid && !( $op eq 'cud-writeoff_individual' || $type eq 'WRITEOFF' ) ) { $template->param( error_under => 1, total_paid => $total_paid @@ -153,10 +154,11 @@ if ( $total_paid and $total_paid ne '0.00' ) { } else { my $url; my $pay_result; - if ($pay_individual) { + if ($op eq 'cud-pay_individual') { my $line = Koha::Account::Lines->find($accountlines_id); $pay_result = $account->pay( { + type => $type, lines => [$line], amount => $total_paid, library_id => $library_id, @@ -184,6 +186,24 @@ if ( $total_paid and $total_paid ne '0.00' ) { $payment->set_additional_fields(\@additional_fields); } + $url = "/cgi-bin/koha/members/pay.pl"; + } elsif ($op eq 'cud-writeoff_individual') { + my $item_id = $input->param('itemnumber'); + my $payment_note = $input->param("payment_note"); + + my $accountline = Koha::Account::Lines->find( $accountlines_id ); + $pay_result = $account->pay( + { + type => 'WRITEOFF', + amount => $total_paid, + lines => [ $accountline ], + note => $payment_note, + interface => C4::Context->interface, + item_id => $item_id, + library_id => $library_id, + } + ); + $payment_id = $pay_result->{payment_id}; $url = "/cgi-bin/koha/members/pay.pl"; } else { @@ -267,44 +287,6 @@ 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