sub chargelostitem {
my $dbh = C4::Context->dbh();
my ($borrowernumber, $itemnumber, $amount, $description) = @_;
- my $itype = Koha::ItemTypes->find({ itemtype => Koha::Items->find($itemnumber)->effective_itemtype() });
+ my $item = Koha::Items->find($itemnumber);
+ my $itype = Koha::ItemTypes->find({ itemtype => $item->effective_itemtype() });
my $replacementprice = $amount;
my $defaultreplacecost = $itype->defaultreplacecost;
my $processfee = $itype->processfee;
$replacementprice = $defaultreplacecost;
}
my $checkout = Koha::Checkouts->find({ itemnumber => $itemnumber });
+ if ( !$checkout && $item->in_bundle ) {
+ my $host = $item->bundle_host;
+ $checkout = $host->checkout;
+ }
my $issue_id = $checkout ? $checkout->issue_id : undef;
my $account = Koha::Account->new({ patron_id => $borrowernumber });
}
}
- # Mark missing bundle items as lost and report unexpected items
- if ( $item->is_bundle ) {
- my $BundleLostValue = C4::Context->preference('BundleLostValue');
- my $barcodes = $query->param('verify-items-bundle-contents-barcodes');
- my @barcodes = map { s/^\s+|\s+$//gr } ( split /\n/, $barcodes );
- my $expected_items = { map { $_->barcode => $_ } $item->bundle_items->as_list };
- my $verify_items = Koha::Items->search( { barcode => { 'in' => \@barcodes } } );
- my @unexpected_items;
- my @missing_items;
- my @bundle_items;
- while ( my $verify_item = $verify_items->next ) {
- # Fix and lost statuses
- $verify_item->itemlost(0);
-
- # Expected item, remove from lookup table
- if ( delete $expected_items->{$verify_item->barcode} ) {
- push @bundle_items, $verify_item;
- }
- # Unexpected item, warn and remove from bundle
- else {
- $verify_item->remove_from_bundle;
- push @unexpected_items, $verify_item;
- }
- # Store results
- $verify_item->store();
- }
- for my $missing_item ( keys %{$expected_items} ) {
- my $bundle_item = $expected_items->{$missing_item};
- $bundle_item->itemlost($BundleLostValue)->store();
- push @missing_items, $bundle_item;
- }
- $template->param(
- unexpected_items => \@unexpected_items,
- missing_items => \@missing_items,
- bundle_items => \@bundle_items
- );
- }
} elsif ( C4::Context->preference('ShowAllCheckins') and !$messages->{'BadBarcode'} and !$needs_confirm and !$bundle_confirm ) {
$input{duedate} = 0;
$returneditems{0} = $barcode;
items_bundle_return_confirmation => 1,
);
}
+
+ # Mark missing bundle items as lost and report unexpected items
+ if ( $item->is_bundle && $query->param('confirm_items_bundle_return') ) {
+ my $BundleLostValue = C4::Context->preference('BundleLostValue');
+ my $barcodes = $query->param('verify-items-bundle-contents-barcodes');
+ my @barcodes = map { s/^\s+|\s+$//gr } ( split /\n/, $barcodes );
+ my $expected_items = { map { $_->barcode => $_ } $item->bundle_items->as_list };
+ my $verify_items = Koha::Items->search( { barcode => { 'in' => \@barcodes } } );
+ my @unexpected_items;
+ my @missing_items;
+ my @bundle_items;
+ while ( my $verify_item = $verify_items->next ) {
+ # Fix and lost statuses
+ $verify_item->itemlost(0);
+
+ # Update last_seen
+ $verify_item->datelastseen( dt_from_string()->ymd() );
+
+ # Update last_borrowed if actual checkin
+ $verify_item->datelastborrowed( dt_from_string()->ymd() ) if $issue;
+
+ # Expected item, remove from lookup table
+ if ( delete $expected_items->{$verify_item->barcode} ) {
+ push @bundle_items, $verify_item;
+ }
+ # Unexpected item, warn and remove from bundle
+ else {
+ $verify_item->remove_from_bundle;
+ push @unexpected_items, $verify_item;
+ }
+
+ # Store results
+ $verify_item->store();
+ }
+ for my $missing_item ( keys %{$expected_items} ) {
+ my $bundle_item = $expected_items->{$missing_item};
+ $bundle_item->itemlost($BundleLostValue)->store();
+ # Add return_claim record if this is an actual checkin
+ if ($issue) {
+ $bundle_item->_result->create_related(
+ 'return_claims',
+ {
+ issue_id => $issue->issue_id,
+ itemnumber => $bundle_item->itemnumber,
+ borrowernumber => $issue->borrowernumber,
+ created_by => C4::Context->userenv()->{number},
+ created_on => dt_from_string
+ }
+ );
+ }
+ push @missing_items, $bundle_item;
+ # NOTE: We cannot use C4::LostItem here because the item itself doesn't have a checkout
+ # and thus would not get charged.. it's checked out as part of the bundle.
+ if ( C4::Context->preference('WhenLostChargeReplacementFee') && $issue ) {
+ C4::Accounts::chargelostitem(
+ $issue->borrowernumber,
+ $bundle_item->itemnumber,
+ $bundle_item->replacementprice,
+ sprintf( "%s %s %s",
+ $bundle_item->biblio->title || q{},
+ $bundle_item->barcode || q{},
+ $bundle_item->itemcallnumber || q{},
+ ),
+ );
+ }
+ }
+ $template->param(
+ unexpected_items => \@unexpected_items,
+ missing_items => \@missing_items,
+ bundle_items => \@bundle_items
+ );
+ }
}
$template->param( inputloop => \@inputloop );
<th>[% t('Author') | html %]</th>
<th>[% t('Item type') | html %]</th>
<th>[% t('Barcode') | html %]</th>
+ [% IF !item.onloan %]
<th>[% t('Status') | html %]</th>
+ [% END %]
</tr>
</thead>
<tbody>
[% FOREACH bundle_item IN item.bundle_items %]
+ [% IF !item.onloan %]
<tr data-barcode="[% bundle_item.barcode | html %]">
<td>[% INCLUDE 'biblio-title.inc' biblio=bundle_item.biblio link = 1 %]</td>
<td>[% bundle_item.biblio.author | html %]</td>
<td>[% bundle_item.barcode | html %]</td>
<td>[% INCLUDE 'item-status.inc' item=bundle_item %]</td>
</tr>
+ [% ELSIF !bundle_item.itemlost %]
+ <tr data-barcode="[% bundle_item.barcode | html %]">
+ <td>[% INCLUDE 'biblio-title.inc' biblio=bundle_item.biblio link = 1 %]</td>
+ <td>[% bundle_item.biblio.author | html %]</td>
+ <td>[% ItemTypes.GetDescription(bundle_item.itype) | html %]</td>
+ <td>[% bundle_item.barcode | html %]</td>
+ </tr>
+ [% END %]
[% END %]
</tbody>
</table>
<div class="form-group">
<label for="verify-items-bundle-contents-barcodes">Barcodes</label>
<textarea autocomplete="off" id="verify-items-bundle-contents-barcodes" name="verify-items-bundle-contents-barcodes" class="form-control"></textarea>
+ [% IF item.onloan %]
<div class="help-block">[% t('Scan all barcodes of items found in the items bundle. If any items are missing, they will be marked as lost') | html %]</div>
+ [% ELSE %]
+ <div class="help-block">[% t('Optionally scan all barcodes of items found in the items bundle to perform an inventory check. If any items are missing, they will be marked as lost') | html %]</div>
+ [% END %]
</div>
</div>
<input type="hidden" name="dd-[% inputloo.counter | html %]" value="[% inputloo.duedate | html %]" />
<input type="hidden" name="bn-[% inputloo.counter | html %]" value="[% inputloo.borrowernumber | html %]" />
[% END %]
+ [% IF item.onloan %]
<button type="submit" class="btn btn-default"><i class="fa fa-check"></i> [% t('Confirm checkin and mark missing items as lost') | html %]</button>
+ [% ELSE %]
+ <button type="submit" class="btn btn-default"><i class="fa fa-check"></i> [% t('Confirm inventory check and mark items as lost') | html %]</button>
+ [% END %]
<button type="button" data-dismiss="modal" class="btn btn-default"><i class="fa fa-close"></i> [% t('Cancel') | html %]</button>
</div>
</form>