fix indentation.
[koha.git] / reports / inventory.pl
1 #!/usr/bin/perl
2
3 # Copyright 2000-2002 Katipo Communications
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA  02111-1307 USA
19
20 use strict;
21 use CGI;
22 use C4::Auth;
23 use C4::Context;
24 use C4::Output;
25 use C4::Biblio;
26 use C4::Date;
27
28
29 # Fixed variables
30 my $linecolor1='#ffffcc';
31 my $linecolor2='white';
32 my $backgroundimage="/images/background-mem.gif";
33 my $script_name="/cgi-bin/koha/admin/branches.pl";
34 my $pagepagesize=20;
35
36
37 #######################################################################################
38 # Main loop....
39 my $input = new CGI;
40 my $minlocation=$input->param('minlocation');
41 my $maxlocation=$input->param('maxlocation');
42 $maxlocation=$minlocation.'Z' unless $maxlocation;
43 my $datelastseen = $input->param('datelastseen');
44 my $offset = $input->param('offset');
45 my $markseen = $input->param('markseen');
46 $offset=0 unless $offset;
47 my $pagesize = $input->param('pagesize');
48 $pagesize=20 unless $pagesize;
49 my $uploadbarcodes = $input->param('uploadbarcodes');
50 # warn "uploadbarcodes : ".$uploadbarcodes;
51
52 my ($template, $borrowernumber, $cookie)
53     = get_template_and_user({template_name => "reports/inventory.tmpl",
54                              query => $input,
55                              type => "intranet",
56                              authnotrequired => 0,
57                              flagsrequired => {reports => 1},
58                              debug => 1,
59                              });
60 $template->param(minlocation => $minlocation,
61                                 maxlocation => $maxlocation,
62                                 offset => $offset,
63                                 pagesize => $pagesize,
64                                 datelastseen => $datelastseen,
65                                 intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
66                 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
67                 IntranetNav => C4::Context->preference("IntranetNav"),
68                                 );
69 if ($uploadbarcodes && length($uploadbarcodes)>0){
70         my $dbh=C4::Context->dbh;
71         my $date=format_date($input->param('setdate'));
72         $date = format_date("today") unless $date;
73 #       warn "$date";
74         my $strsth="update items set (datelastseen = $date) where items.barcode =?";
75         my $qupdate = $dbh->prepare($strsth);
76         my $strsth="select * from issues, items where items.itemnumber=issues.itemnumber and items.barcode =? and issues.returndate is null";
77         my $qonloan = $dbh->prepare($strsth);
78         my $strsth="select * from items where items.barcode =? and issues.wthdrawn=1";
79         my $qwthdrawn = $dbh->prepare($strsth);
80         my @errorloop;
81         my $count=0;
82         while (my $barcode=<$uploadbarcodes>){
83                 chomp $barcode;
84 #               warn "$barcode";
85                 if ($qwthdrawn->execute($barcode) &&$qwthdrawn->rows){
86                         push @errorloop, {'barcode'=>$barcode,'ERR_WTHDRAWN'=>1};
87                 }else{
88                         $qupdate->execute($barcode);
89                         $count += $qupdate->rows;
90 #                       warn "$count";
91                         if ($count){
92                                 $qonloan->execute($barcode);
93                                 if ($qonloan->rows){
94                                         my $data = $qonloan->fetchrow_hashref;
95                                         my ($doreturn, $messages, $iteminformation, $borrower) =AddReturn($barcode, $data->{homebranch});
96                                         if ($doreturn){push @errorloop, {'barcode'=>$barcode,'ERR_ONLOAN_RET'=>1}}
97                                         else {push @errorloop, {'barcode'=>$barcode,'ERR_ONLOAN_NOT_RET'=>1}}
98                                 }
99                         } else {
100                                 push @errorloop, {'barcode'=>$barcode,'ERR_BARCODE'=>1};
101                         }
102                 }
103         }
104         $qupdate->finish;
105         $qonloan->finish;
106         $qwthdrawn->finish;
107         $template->param(date=>$date,Number=>$count);
108 #       $template->param(errorfile=>$errorfile) if ($errorfile);
109         $template->param(errorloop=>\@errorloop) if (@errorloop);
110 }else{
111         if ($markseen) {
112                 foreach my $field ($input->param) {
113                         if ($field =~ /SEEN-(.*)/) {
114                                 &ModDateLastSeen($1);
115                         }
116                 }
117         }
118         if ($minlocation) {
119                 my $res = C4::Circulation::Circ2::listitemsforinventory($minlocation,$maxlocation,$datelastseen,$offset,$pagesize);
120                 $template->param(loop =>$res,
121                                                 nextoffset => ($offset+$pagesize),
122                                                 prevoffset => ($offset?$offset-$pagesize:0),
123                                                 );
124         }
125 }
126 output_html_with_http_headers $input, $cookie, $template->output;
127
128 # Local Variables:
129 # tab-width: 8
130 # End: