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