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