# If barcode is passed, attempt to find the associated item
my $failed;
my $item_id;
+ my $olditem; # FIXME: When items and deleted_items are merged, we can remove this
my $issue_id;
if ($barcode) {
my $item = Koha::Items->find( { barcode => $barcode } );
$item_id = $item->itemnumber;
}
else {
- $item = Koha::Old::Items->find( { barcode => $barcode } );
- if ($item) {
- $item_id = $item->itemnumber;
+ $item = Koha::Old::Items->search( { barcode => $barcode },
+ { order_by => { -desc => 'timestamp' }, rows => 1 } );
+ if ($item->count) {
+ $item_id = $item->next->itemnumber;
+ $olditem = 1;
}
else {
$template->param( error => 'itemnumber' );
interface => 'intranet',
library_id => $library_id,
type => $debit_type,
- item_id => $item_id,
+ ( $olditem ? () : ( item_id => $item_id ) ),
issue_id => $issue_id
}
);