use C4::Output;
use C4::Biblio;
use C4::Items;
-use C4::Koha; # GetItemTypes
-use C4::Branch; # GetBranches
-use C4::Dates qw/format_date/;
+use Koha::DateUtils;
my $query = new CGI;
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
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 $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 $itype = C4::Context->preference('item-level_itypes') ? "itype" : "itemtype";
- $where{$itype} = $itemtypesfilter if defined $itemtypesfilter;
+ my $items = Koha::Items->search( $params, $attributes );
- my $items = GetLostItems( \%where );
- foreach my $it (@$items) {
- $it->{'datelastseen'} = format_date($it->{'datelastseen'});
- }
$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 branches.
-#my $branches = GetBranches;
-#my $branch = C4::Context->userenv->{"branchname"};
-
# getting all itemtypes
-my $itemtypes = &GetItemTypes();
-my @itemtypesloop;
-foreach my $thisitemtype ( sort {$itemtypes->{$a}->{translated_description} cmp $itemtypes->{$b}->{translated_description}} keys %$itemtypes ) {
- my %row = (
- value => $thisitemtype,
- description => $itemtypes->{$thisitemtype}->{'translated_description'},
- );
- push @itemtypesloop, \%row;
-}
+my $itemtypes = Koha::ItemTypes->search_with_localization;
# get lost statuses
my $lost_status_loop = C4::Koha::GetAuthorisedValues( 'LOST' );
-$template->param( branchloop => GetBranchesLoop(C4::Context->userenv->{'branch'}),
- itemtypeloop => \@itemtypesloop,
+$template->param(
+ itemtypes => $itemtypes,
loststatusloop => $lost_status_loop,
);