From 5cfe4c4fe858a1f6c48d76300f967aacca4eb94a Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Mon, 10 Feb 2020 15:11:54 +0000 Subject: [PATCH] Bug 22393: (follow-up) Handle deleted items This patch adds fallback handling to looking items in the old items table if they're not found in the items table. --- members/maninvoice.pl | 57 ++++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 22 deletions(-) diff --git a/members/maninvoice.pl b/members/maninvoice.pl index 665bcbbf73..8e03b36214 100755 --- a/members/maninvoice.pl +++ b/members/maninvoice.pl @@ -84,16 +84,17 @@ if ($add) { } ); - # Note: If the logged in user is not allowed to see this patron an invoice can be forced - # Here we are trusting librarians not to hack the system +# Note: If the logged in user is not allowed to see this patron an invoice can be forced +# Here we are trusting librarians not to hack the system my $desc = $input->param('desc'); my $amount = $input->param('amount'); my $note = $input->param('note'); my $debit_type = $input->param('type'); - # If LOST try to match barcode to Item and then try to match Item + Borrower to an Issue. + # If barcode is passed, attempt to find the associated item my $failed; my $item_id; + my $issue_id; my $barcode = $input->param('barcode'); if ($barcode) { my $item = Koha::Items->find( { barcode => $barcode } ); @@ -101,22 +102,35 @@ if ($add) { $item_id = $item->itemnumber; } else { - $template->param( error => 'itemnumber' ); - $failed = 1; + $item = Koha::Old::Items->find( { barcode => $barcode } ); + if ($item) { + $item_id = $item->itemnumber; + } + else { + $template->param( error => 'itemnumber' ); + $failed = 1; + } + } + + 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; } - } - 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) { @@ -139,16 +153,15 @@ if ($add) { $patron->account->reconcile_balance; } - print $input->redirect( - "/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber" - ); + 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 { + } + else { $template->param( error => '1' ); } } -- 2.20.1