oops, commenting out all those warn!
[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::Interface::CGI::Output;
26 use C4::Circulation::Circ2;
27 use C4::Date;
28 use HTML::Template;
29
30 # Fixed variables
31 my $linecolor1='#ffffcc';
32 my $linecolor2='white';
33 my $backgroundimage="/images/background-mem.gif";
34 my $script_name="/cgi-bin/koha/admin/branches.pl";
35 my $pagepagesize=20;
36
37
38 #######################################################################################
39 # Main loop....
40 my $input = new CGI;
41 my $minlocation=$input->param('minlocation');
42 my $maxlocation=$input->param('maxlocation');
43 $maxlocation=$minlocation.'Z' unless $maxlocation;
44 my $datelastseen = $input->param('datelastseen');
45 my $offset = $input->param('offset');
46 my $markseen = $input->param('markseen');
47 $offset=0 unless $offset;
48 my $pagesize = $input->param('pagesize');
49 $pagesize=20 unless $pagesize;
50 my $uploadbarcodes = $input->param('uploadbarcodes');
51 # warn "uploadbarcodes : ".$uploadbarcodes;
52
53 my ($template, $borrowernumber, $cookie)
54     = get_template_and_user({template_name => "reports/inventory.tmpl",
55                              query => $input,
56                              type => "intranet",
57                              authnotrequired => 0,
58                              flagsrequired => {editcatalogue => 1},
59                              debug => 1,
60                              });
61 $template->param(minlocation => $minlocation,
62                                 maxlocation => $maxlocation,
63                                 offset => $offset,
64                                 pagesize => $pagesize,
65                                 datelastseen => $datelastseen,
66                                 intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
67                 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
68                 IntranetNav => C4::Context->preference("IntranetNav"),
69                                 );
70 if ($uploadbarcodes && length($uploadbarcodes)>0){
71         my $dbh=C4::Context->dbh;
72         my $date=format_date($input->param('setdate'));
73         $date = format_date("today") unless $date;
74 #       warn "$date";
75         my $strsth="update items set (datelastseen = $date) where items.barcode =?";
76         my $qupdate = $dbh->prepare($strsth);
77         my $strsth="select * from issues, items where items.itemnumber=issues.itemnumber and items.barcode =? and issues.returndate is null";
78         my $qonloan = $dbh->prepare($strsth);
79         my $strsth="select * from items where items.barcode =? and issues.wthdrawn=1";
80         my $qwthdrawn = $dbh->prepare($strsth);
81         my @errorloop;
82         my $count=0;
83         while (my $barcode=<$uploadbarcodes>){
84                 chomp $barcode;
85 #               warn "$barcode";
86                 if ($qwthdrawn->execute($barcode) &&$qwthdrawn->rows){
87                         push @errorloop, {'barcode'=>$barcode,'ERR_WTHDRAWN'=>1};
88                 }else{
89                         $qupdate->execute($barcode);
90                         $count += $qupdate->rows;
91 #                       warn "$count";
92                         if ($count){
93                                 $qonloan->execute($barcode);
94                                 if ($qonloan->rows){
95                                         my $data = $qonloan->fetchrow_hashref;
96                                         my ($doreturn, $messages, $iteminformation, $borrower) =returnbook($barcode, $data->{homebranch});
97                                         if ($doreturn){push @errorloop, {'barcode'=>$barcode,'ERR_ONLOAN_RET'=>1}}
98                                         else {push @errorloop, {'barcode'=>$barcode,'ERR_ONLOAN_NOT_RET'=>1}}
99                                 }
100                         } else {
101                                 push @errorloop, {'barcode'=>$barcode,'ERR_BARCODE'=>1};
102                         }
103                 }
104         }
105         $qupdate->finish;
106         $qonloan->finish;
107         $qwthdrawn->finish;
108         $template->param(date=>$date,Number=>$count);
109 #       $template->param(errorfile=>$errorfile) if ($errorfile);
110         $template->param(errorloop=>\@errorloop) if (@errorloop);
111 }else{
112         if ($markseen) {
113                 foreach my $field ($input->param) {
114                         if ($field =~ /SEEN-(.*)/) {
115                                 &itemseen($1);
116                         }
117                 }
118         }
119         if ($minlocation) {
120                 my $res = C4::Circulation::Circ2::listitemsforinventory($minlocation,$maxlocation,$datelastseen,$offset,$pagesize);
121                 $template->param(loop =>$res,
122                                                 nextoffset => ($offset+$pagesize),
123                                                 prevoffset => ($offset?$offset-$pagesize:0),
124                                                 );
125         }
126 }
127 output_html_with_http_headers $input, $cookie, $template->output;
128
129 # Local Variables:
130 # tab-width: 8
131 # End: