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