From: Martin Renvoize Date: Sat, 15 Jun 2019 06:17:46 +0000 (+0100) Subject: Bug 22563: (QA follow-up) Catch LOST maninvoice cases X-Git-Tag: v19.11.00~1075 X-Git-Url: http://git.equinoxoli.org/?p=koha.git;a=commitdiff_plain;h=c437f84a65237a1b4eabbb2b5c1b8f661649a1d0 Bug 22563: (QA follow-up) Catch LOST maninvoice cases One could add a manual invoice of type LOST but we would not associate it with an issue_id. This patch tries to catch such cases and extrapolate an issue_id to add to the accountline. Signed-off-by: Martin Renvoize Signed-off-by: Tomas Cohen Arazi Signed-off-by: Martin Renvoize --- diff --git a/C4/Accounts.pm b/C4/Accounts.pm index 5601291..3049116 100644 --- a/C4/Accounts.pm +++ b/C4/Accounts.pm @@ -87,9 +87,7 @@ sub chargelostitem { my $issue_id = $checkout ? $checkout->issue_id : undef; my $account = Koha::Account->new({ patron_id => $borrowernumber }); - # first make sure the borrower hasn't already been charged for this item - # FIXME this should be more exact - # there is no reason a user can't lose an item, find and return it, and lost it again + # first make sure the borrower hasn't already been charged for this item (for this issuance) my $existing_charges = $account->lines->search( { itemnumber => $itemnumber, @@ -156,6 +154,20 @@ sub manualinvoice { my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef; + my $issue_id; + if ( $type eq 'LOST' && $itemnum ) { + my $checkouts = Koha::Checkouts->search( + { itemnumber => $itemnum, borrowernumber => $borrowernumber } ); + my $checkout = + $checkouts->count + ? $checkouts->next + : Koha::Old::Checkouts->search( + { itemnumber => $itemnum, borrowernumber => $borrowernumber }, + { order_by => { 'DESC' => 'returndate' }, rows => 1 } + )->next; + $issue_id = $checkout ? $checkout->issue_id : undef; + } + my $accountline = Koha::Account::Line->new( { borrowernumber => $borrowernumber, @@ -165,6 +177,7 @@ sub manualinvoice { accounttype => $type, amountoutstanding => $amountleft, itemnumber => $itemnum || undef, + issue_id => $issue_id, note => $note, manager_id => $manager_id, interface => C4::Context->interface, diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/maninvoice.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/maninvoice.tt index 7ce2a42..4772da3 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/maninvoice.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/maninvoice.tt @@ -44,7 +44,7 @@