Bug 20012: use Modern::Perl in Reports perl scripts
[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 Modern::Perl;
29
30 use CGI qw ( -utf8 );
31 use C4::Auth;
32 use C4::Output;
33 use C4::Biblio;
34 use C4::Items;
35 use Koha::DateUtils;
36
37 my $query = new CGI;
38 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
39     {
40         template_name   => "reports/itemslost.tt",
41         query           => $query,
42         type            => "intranet",
43         authnotrequired => 0,
44         flagsrequired   => { reports => '*' },
45         debug           => 1,
46     }
47 );
48
49 my $params = $query->Vars;
50 my $get_items = $params->{'get_items'};
51
52 if ($get_items) {
53     my $branchfilter     = $params->{'branchfilter'}     || undef;
54     my $barcodefilter    = $params->{'barcodefilter'}    || undef;
55     my $itemtypesfilter  = $params->{'itemtypesfilter'}  || undef;
56     my $loststatusfilter = $params->{'loststatusfilter'} || undef;
57
58     my $params = {
59         ( $branchfilter ? ( homebranch => $branchfilter ) : () ),
60         (
61             $loststatusfilter
62             ? ( itemlost => $loststatusfilter )
63             : ( itemlost => { '!=' => 0 } )
64         ),
65         ( $barcodefilter ? ( barcode => { like => "%$barcodefilter%" } ) : () ),
66     };
67
68     my $attributes;
69     if ($itemtypesfilter) {
70         if ( C4::Context->preference('item-level_itypes') ) {
71             $params->{itype} = $itemtypesfilter;
72         }
73         else {
74             # We want a join on biblioitems
75             $attributes = { join => 'biblioitem' };
76             $params->{'biblioitem.itemtype'} = $itemtypesfilter;
77         }
78     }
79
80     my $items = Koha::Items->search( $params, $attributes );
81
82     $template->param(
83         items     => $items,
84         get_items => $get_items,
85     );
86 }
87
88 # getting all itemtypes
89 my $itemtypes = Koha::ItemTypes->search_with_localization;
90
91 # get lost statuses
92 my $lost_status_loop = C4::Koha::GetAuthorisedValues( 'LOST' );
93
94 $template->param(
95                   itemtypes => $itemtypes,
96                   loststatusloop => $lost_status_loop,
97 );
98
99 # writing the template
100 output_html_with_http_headers $query, $cookie, $template->output;