From 852a7b0235e7626606981acade80b3db8d667568 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 12 Nov 2019 14:47:44 +0100 Subject: [PATCH] Bug 22393: simplify? --- members/maninvoice.pl | 93 +++++++++++++++++++++++++-------------------------- 1 file changed, 45 insertions(+), 48 deletions(-) diff --git a/members/maninvoice.pl b/members/maninvoice.pl index 7299eb8575..01289310c2 100755 --- a/members/maninvoice.pl +++ b/members/maninvoice.pl @@ -97,59 +97,56 @@ if ($add) { my $barcode = $input->param('barcode'); if ($barcode) { my $item = Koha::Items->find( { barcode => $barcode } ); - if ($item) { - $item_id = $item->itemnumber; - } - else { + unless ( $item ) { $template->param( error => 'itemnumber' ); $failed = 1; - } - } - my $issue_id; - if ( $debit_type eq 'LOST' && $item_id ) { - my $checkouts = Koha::Checkouts->search( - { itemnumber => $item_id, borrowernumber => $borrowernumber } ); - my $checkout = - $checkouts->count - ? $checkouts->next - : Koha::Old::Checkouts->search( - { itemnumber => $item_id, borrowernumber => $borrowernumber }, - { order_by => { -desc => 'returndate' }, rows => 1 } - )->next; - $issue_id = $checkout ? $checkout->issue_id : undef; - } + } else { + $item_id = $item->itemnumber; + my $issue_id; + if ( $debit_type eq 'LOST' && $item_id ) { + my $checkouts = Koha::Checkouts->search( + { itemnumber => $item_id, borrowernumber => $borrowernumber } ); + my $checkout = + $checkouts->count + ? $checkouts->next + : Koha::Old::Checkouts->search( + { itemnumber => $item_id, borrowernumber => $borrowernumber }, + { order_by => { -desc => 'returndate' }, rows => 1 } + )->next; + $issue_id = $checkout ? $checkout->issue_id : undef; + } - unless ($failed) { - try { - $patron->account->add_debit( - { - amount => $amount, - description => $desc, - note => $note, - user_id => $logged_in_user->borrowernumber, - interface => 'intranet', - library_id => $library_id, - type => $debit_type, - item_id => $item_id, - issue_id => $issue_id + try { + $patron->account->add_debit( + { + amount => $amount, + description => $desc, + note => $note, + user_id => $logged_in_user->borrowernumber, + interface => 'intranet', + library_id => $library_id, + type => $debit_type, + item_id => $item_id, + issue_id => $issue_id + } + ); + + if ( C4::Context->preference('AccountAutoReconcile') ) { + $patron->account->reconcile_balance; } - ); - - if ( C4::Context->preference('AccountAutoReconcile') ) { - $patron->account->reconcile_balance; + + print $input->redirect( + "/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber" + ); + exit; } - - print $input->redirect( - "/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber" - ); - exit; - } - catch { - my $error = $_; - if ( ref($error) eq 'Koha::Exceptions::Object::FKConstraint' ) { - $template->param( error => $error->broken_fk ); - } else { - $template->param( error => '1' ); + catch { + my $error = $_; + if ( ref($error) eq 'Koha::Exceptions::Object::FKConstraint' ) { + $template->param( error => $error->broken_fk ); + } else { + $template->param( error => '1' ); + } } } } -- 2.11.0