Merge remote-tracking branch 'origin/new/bug_8550'
[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 under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
11 # version.
12 #
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License along
18 # with Koha; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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;
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 C4::Dates qw/format_date/;
39
40 my $query = new CGI;
41 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
42     {
43         template_name   => "reports/itemslost.tmpl",
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 $orderbyfilter    = $params->{'orderbyfilter'}   || undef;
57     my $branchfilter     = $params->{'branchfilter'}    || undef;
58     my $barcodefilter    = $params->{'barcodefilter'}   || undef;
59     my $itemtypesfilter  = $params->{'itemtypesfilter'} || undef;
60     my $loststatusfilter = $params->{'loststatusfilter'} || undef;
61
62     my %where;
63     $where{'homebranch'}       = $branchfilter    if defined $branchfilter;
64     $where{'barcode'}          = $barcodefilter   if defined $barcodefilter;
65     $where{'authorised_value'} = $loststatusfilter if defined $loststatusfilter;
66     
67     my $itype = C4::Context->preference('item-level_itypes') ? "itype" : "itemtype";
68     $where{$itype}            = $itemtypesfilter if defined $itemtypesfilter;
69
70     my $items = GetLostItems( \%where, $orderbyfilter ); 
71     foreach my $it (@$items) {
72         $it->{'datelastseen'} = format_date($it->{'datelastseen'});
73     }
74     $template->param(
75                      total       => scalar @$items,
76                      itemsloop   => $items,
77                      get_items   => $get_items,
78                      itype_level => C4::Context->preference('item-level_itypes'),
79                  );
80 }
81
82 # getting all branches.
83 #my $branches = GetBranches;
84 #my $branch   = C4::Context->userenv->{"branchname"};
85
86 # getting all itemtypes
87 my $itemtypes = &GetItemTypes();
88 my @itemtypesloop;
89 foreach my $thisitemtype ( sort {$itemtypes->{$a}->{description} cmp $itemtypes->{$b}->{description}} keys %$itemtypes ) {
90     my %row = (
91         value       => $thisitemtype,
92         description => $itemtypes->{$thisitemtype}->{'description'},
93     );
94     push @itemtypesloop, \%row;
95 }
96
97 # get lost statuses
98 my $lost_status_loop = C4::Koha::GetAuthorisedValues( 'LOST' );
99
100 $template->param( branchloop     => GetBranchesLoop(C4::Context->userenv->{'branch'}),
101                   itemtypeloop   => \@itemtypesloop,
102                   loststatusloop => $lost_status_loop,
103 );
104
105 # writing the template
106 output_html_with_http_headers $query, $cookie, $template->output;