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