From a95b754da235ffab20a6fee18daf1b8dd818cb46 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Mon, 17 Dec 2018 07:25:25 +0000 Subject: [PATCH] Bug 21747: Update members/manivoice to use add_debit https://bugs.koha-community.org/show_bug.cgi?id=21756 --- members/maninvoice.pl | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/members/maninvoice.pl b/members/maninvoice.pl index db7a447ffa..459a0866ff 100755 --- a/members/maninvoice.pl +++ b/members/maninvoice.pl @@ -38,6 +38,8 @@ use Koha::Patrons; use Koha::Patron::Categories; +use Try::Tiny; + my $input=new CGI; my $flagsrequired = { borrowers => 'edit_borrowers' }; @@ -69,8 +71,19 @@ if ($add){ my $amount=$input->param('amount'); my $type=$input->param('type'); my $note = $input->param('note'); - my $error = manualinvoice( $borrowernumber, $itemnum, $desc, $type, $amount, $note ); - if ($error) { + try { + my $account = $patron->account; + my $invoice = $account->add_debit( + { + amount => $amount, + item_id => $itemnum, + description => $desc, + type => $type, + note => $note + } + ); + } + catch { my ( $template, $loggedinuser, $cookie ) = get_template_and_user( { template_name => "members/maninvoice.tt", query => $input, @@ -80,16 +93,17 @@ if ($add){ debug => 1, } ); - if ( $error =~ /FOREIGN KEY/ && $error =~ /itemnumber/ ) { - $template->param( 'ITEMNUMBER' => 1 ); + if ( $_->isa('Koha::Exceptions::Object::FKConstraint') $error =~ /FOREIGN KEY/ && $error =~ /itemnumber/ ) { + $template->param( 'ITEMNUMBER' => 1 ) if ($_->broken_fk eq 'itemnumber'); + $template->param( 'ERROR' => $_->message ); } $template->param( csrf_token => Koha::Token->new->generate_csrf({ session_id => scalar $input->cookie('CGISESSID') }) ); - $template->param( 'ERROR' => $error ); output_html_with_http_headers $input, $cookie, $template->output; - } else { - print $input->redirect("/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber"); exit; - } + }; + + print $input->redirect("/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber"); + exit; } } else { -- 2.19.2