Merge remote-tracking branch 'origin/new/bug_5347'
[koha.git] / reports / itemslost.pl
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
8 # version.
9 #
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License along with
15 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
16 # Suite 330, Boston, MA  02111-1307 USA
17
18
19 =head1 itemslost
20
21 This script displays lost items.
22
23 =cut
24
25 use strict;
26 use warnings;
27
28 use CGI;
29 use C4::Auth;
30 use C4::Output;
31 use C4::Biblio;
32 use C4::Items;
33 use C4::Koha;                  # GetItemTypes
34 use C4::Branch; # GetBranches
35 use C4::Dates qw/format_date/;
36
37 my $query = new CGI;
38 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
39     {
40         template_name   => "reports/itemslost.tmpl",
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 $orderbyfilter    = $params->{'orderbyfilter'}   || undef;
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 %where;
60     $where{'homebranch'}       = $branchfilter    if defined $branchfilter;
61     $where{'barcode'}          = $barcodefilter   if defined $barcodefilter;
62     $where{'authorised_value'} = $loststatusfilter if defined $loststatusfilter;
63     
64     my $itype = C4::Context->preference('item-level_itypes') ? "itype" : "itemtype";
65     $where{$itype}            = $itemtypesfilter if defined $itemtypesfilter;
66
67     my $items = GetLostItems( \%where, $orderbyfilter ); 
68     foreach my $it (@$items) {
69         $it->{'datelastseen'} = format_date($it->{'datelastseen'});
70     }
71     $template->param(
72                      total       => scalar @$items,
73                      itemsloop   => $items,
74                      get_items   => $get_items,
75                      itype_level => C4::Context->preference('item-level_itypes'),
76                  );
77 }
78
79 # getting all branches.
80 #my $branches = GetBranches;
81 #my $branch   = C4::Context->userenv->{"branchname"};
82
83 # getting all itemtypes
84 my $itemtypes = &GetItemTypes();
85 my @itemtypesloop;
86 foreach my $thisitemtype ( sort {$itemtypes->{$a}->{description} cmp $itemtypes->{$b}->{description}} keys %$itemtypes ) {
87     my %row = (
88         value       => $thisitemtype,
89         description => $itemtypes->{$thisitemtype}->{'description'},
90     );
91     push @itemtypesloop, \%row;
92 }
93
94 # get lost statuses
95 my $lost_status_loop = C4::Koha::GetAuthorisedValues( 'LOST' );
96
97 $template->param( branchloop     => GetBranchesLoop(C4::Context->userenv->{'branch'}),
98                   itemtypeloop   => \@itemtypesloop,
99                   loststatusloop => $lost_status_loop,
100 );
101
102 # writing the template
103 output_html_with_http_headers $query, $cookie, $template->output;