=cut
-=head2 GetLostItems
-
- $items = GetLostItems( $where );
-
-This function gets a list of lost items.
-
-=over 2
-
-=item input:
-
-C<$where> is a hashref. it containts a field of the items table as key
-and the value to match as value. For example:
-
-{ barcode => 'abc123',
- homebranch => 'CPL', }
-
-=item return:
-
-C<$items> is a reference to an array full of hashrefs with columns
-from the "items" table as keys.
-
-=item usage in the perl script:
-
- my $where = { barcode => '0001548' };
- my $items = GetLostItems( $where );
- $template->param( itemsloop => $items );
-
-=back
-
-=cut
-
-sub GetLostItems {
- # Getting input args.
- my $where = shift;
- my $dbh = C4::Context->dbh;
-
- my $query = "
- SELECT title, author, lib, itemlost, authorised_value, barcode, datelastseen, price, replacementprice, homebranch,
- itype, itemtype, holdingbranch, location, itemnotes, items.biblionumber as biblionumber, itemcallnumber
- FROM items
- LEFT JOIN biblio ON (items.biblionumber = biblio.biblionumber)
- LEFT JOIN biblioitems ON (items.biblionumber = biblioitems.biblionumber)
- LEFT JOIN authorised_values ON (items.itemlost = authorised_values.authorised_value)
- WHERE
- authorised_values.category = 'LOST'
- AND itemlost IS NOT NULL
- AND itemlost <> 0
- ";
- my @query_parameters;
- foreach my $key (keys %$where) {
- $query .= " AND $key LIKE ?";
- push @query_parameters, "%$where->{$key}%";
- }
-
- my $sth = $dbh->prepare($query);
- $sth->execute( @query_parameters );
- my $items = [];
- while ( my $row = $sth->fetchrow_hashref ){
- push @$items, $row;
- }
- return $items;
-}
-
=head2 GetItemsForInventory
($itemlist, $iTotalRecords) = GetItemsForInventory( {
+[% USE AuthorisedValues %]
[% USE Branches %]
[% USE ColumnsSettings %]
+[% USE KohaDates %]
[% INCLUDE 'doc-head-open.inc' %]
<title>Koha › Reports › Lost items</title>
[% INCLUDE 'doc-head-close.inc' %]
[% IF ( get_items ) %]
<div class="results">
- [% IF ( total ) %]
- [% total %] lost items found
+ [% IF items.count%]
+ [% items.count %] lost items found
[% ELSE %]
No lost items found
[% END %]
</div>
- [% IF itemsloop %]
+ [% IF items.count %]
<table id="lostitems-table">
<thead>
<tr>
</tr>
</thead>
<tbody>
- [% FOREACH itemsloo IN itemsloop %]
+ [% FOREACH item IN items %]
<tr>
<td>
- <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% itemsloo.biblionumber %]" title="[% itemsloo.itemnotes %]">[% itemsloo.title |html %]</a>
+ <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% item.biblionumber %]" title="[% item.itemnotes %]">[% item.biblio.title |html %]</a>
</td>
- <td>[% itemsloo.author %]</td>
- <td>[% itemsloo.lib %]</td>
+ <td>[% item.biblio.author %]</td>
+ <td>[% AuthorisedValues.GetByCode( 'LOST', item.itemlost ) %]</td>
<td>
- <a href="/cgi-bin/koha/catalogue/moredetail.pl?biblionumber=[% itemsloo.biblionumber %]" title="[% itemsloo.itemnotes %]">[% itemsloo.barcode %]</a>
+ <a href="/cgi-bin/koha/catalogue/moredetail.pl?biblionumber=[% item.biblionumber %]" title="[% item.itemnotes %]">[% item.barcode %]</a>
</td>
- <td>[% itemsloo.itemcallnumber %]</td>
- <td>[% itemsloo.datelastseen %]</td>
- <td>[% itemsloo.price %]</td>
- <td>[% itemsloo.replacementprice %]</td>
- <td>[% Branches.GetName(itemsloo.homebranch) %]</td>
- <td>[% IF ( itemsloo.itype_level ) %][% itemsloo.itype %][% ELSE %][% itemsloo.itemtype %][% END %]</td>
- <td>[% Branches.GetName(itemsloo.holdingbranch) %]</td>
- <td>[% itemsloo.location %]</td>
- <td>[% itemsloo.itemnotes %]</td>
+ <td>[% item.itemcallnumber %]</td>
+ <td>[% item.datelastseen | $KohaDates %]</td>
+ <td>[% item.price %]</td>
+ <td>[% item.replacementprice %]</td>
+ <td>[% Branches.GetName(item.homebranch) %]</td>
+ <td>[% item.effective_itemtype %]</td>
+ <td>[% Branches.GetName(item.holdingbranch) %]</td>
+ <td>[% item.location %]</td>
+ <td>[% item.itemnotes %]</td>
</tr>
[% END %]
</tbody>
my $params = $query->Vars;
my $get_items = $params->{'get_items'};
-if ( $get_items ) {
- my $branchfilter = $params->{'branchfilter'} || undef;
- my $barcodefilter = $params->{'barcodefilter'} || undef;
- my $itemtypesfilter = $params->{'itemtypesfilter'} || undef;
+if ($get_items) {
+ my $branchfilter = $params->{'branchfilter'} || undef;
+ my $barcodefilter = $params->{'barcodefilter'} || undef;
+ my $itemtypesfilter = $params->{'itemtypesfilter'} || undef;
my $loststatusfilter = $params->{'loststatusfilter'} || undef;
- my %where;
- $where{'homebranch'} = $branchfilter if defined $branchfilter;
- $where{'barcode'} = $barcodefilter if defined $barcodefilter;
- $where{'authorised_value'} = $loststatusfilter if defined $loststatusfilter;
-
- my $itype = C4::Context->preference('item-level_itypes') ? "itype" : "itemtype";
- $where{$itype} = $itemtypesfilter if defined $itemtypesfilter;
-
- my $items = GetLostItems( \%where );
- foreach my $it (@$items) {
- $it->{'datelastseen'} = eval { output_pref( { dt => dt_from_string( $it->{'datelastseen'} ), dateonly => 1 }); }
- if ( $it->{'datelastseen'} );
+ my $params = {
+ ( $branchfilter ? ( homebranch => $branchfilter ) : () ),
+ (
+ $loststatusfilter
+ ? ( itemlost => $loststatusfilter )
+ : ( itemlost => { '!=' => 0 } )
+ ),
+ ( $barcodefilter ? ( barcode => { like => "%$barcodefilter%" } ) : () ),
+ };
+
+ my $attributes;
+ if ($itemtypesfilter) {
+ if ( C4::Context->preference('item-level_itypes') ) {
+ $params->{itype} = $itemtypesfilter;
+ }
+ else {
+ # We want a join on biblioitems
+ $attributes = { join => 'biblioitem' };
+ $params->{'biblioitem.itemtype'} = $itemtypesfilter;
+ }
}
+ my $items = Koha::Items->search( $params, $attributes );
+
$template->param(
- total => scalar @$items,
- itemsloop => $items,
- get_items => $get_items,
- itype_level => C4::Context->preference('item-level_itypes'),
- );
+ items => $items,
+ get_items => $get_items,
+ );
}
# getting all itemtypes