Bug 14362: PEGI15 Circulation/AgeRestrictionMarkers test fails
[koha.git] / reports / itemslost.pl
1 #!/usr/bin/perl
2
3 # Copyright Liblime 2007
4 # Copyright Biblibre 2009
5 #
6 # This file is part of Koha.
7 #
8 # Koha is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20
21
22 =head1 itemslost
23
24 This script displays lost items.
25
26 =cut
27
28 use strict;
29 use warnings;
30
31 use CGI qw ( -utf8 );
32 use C4::Auth;
33 use C4::Output;
34 use C4::Biblio;
35 use C4::Items;
36 use C4::Koha;                  # GetItemTypes
37 use C4::Branch; # GetBranches
38 use Koha::DateUtils;
39
40 my $query = new CGI;
41 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
42     {
43         template_name   => "reports/itemslost.tt",
44         query           => $query,
45         type            => "intranet",
46         authnotrequired => 0,
47         flagsrequired   => { reports => '*' },
48         debug           => 1,
49     }
50 );
51
52 my $params = $query->Vars;
53 my $get_items = $params->{'get_items'};
54
55 if ( $get_items ) {
56     my $branchfilter     = $params->{'branchfilter'}    || undef;
57     my $barcodefilter    = $params->{'barcodefilter'}   || undef;
58     my $itemtypesfilter  = $params->{'itemtypesfilter'} || undef;
59     my $loststatusfilter = $params->{'loststatusfilter'} || undef;
60
61     my %where;
62     $where{'homebranch'}       = $branchfilter    if defined $branchfilter;
63     $where{'barcode'}          = $barcodefilter   if defined $barcodefilter;
64     $where{'authorised_value'} = $loststatusfilter if defined $loststatusfilter;
65
66     my $itype = C4::Context->preference('item-level_itypes') ? "itype" : "itemtype";
67     $where{$itype}            = $itemtypesfilter if defined $itemtypesfilter;
68
69     my $items = GetLostItems( \%where );
70     foreach my $it (@$items) {
71         $it->{'datelastseen'} = eval { output_pref( { dt => dt_from_string( $it->{'datelastseen'} ), dateonly => 1 }); }
72                    if ( $it->{'datelastseen'} );
73     }
74
75     $template->param(
76                      total       => scalar @$items,
77                      itemsloop   => $items,
78                      get_items   => $get_items,
79                      itype_level => C4::Context->preference('item-level_itypes'),
80                  );
81 }
82
83 # getting all branches.
84 #my $branches = GetBranches;
85 #my $branch   = C4::Context->userenv->{"branchname"};
86
87 # getting all itemtypes
88 my $itemtypes = &GetItemTypes();
89 my @itemtypesloop;
90 foreach my $thisitemtype ( sort {$itemtypes->{$a}->{translated_description} cmp $itemtypes->{$b}->{translated_description}} keys %$itemtypes ) {
91     my %row = (
92         value       => $thisitemtype,
93         description => $itemtypes->{$thisitemtype}->{'translated_description'},
94     );
95     push @itemtypesloop, \%row;
96 }
97
98 # get lost statuses
99 my $lost_status_loop = C4::Koha::GetAuthorisedValues( 'LOST' );
100
101 $template->param( branchloop     => GetBranchesLoop(C4::Context->userenv->{'branch'}),
102                   itemtypeloop   => \@itemtypesloop,
103                   loststatusloop => $lost_status_loop,
104 );
105
106 # writing the template
107 output_html_with_http_headers $query, $cookie, $template->output;