unimarc bugfix : the encoding is in field 100 in UNIMARC. when TransformHTMLtoXML...
[koha.git] / tools / 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 use C4::Koha;
28 use C4::Branch; # GetBranches
29
30 my $input = new CGI;
31 my $minlocation=$input->param('minlocation') || 'A';
32 my $maxlocation=$input->param('maxlocation');
33 $maxlocation=$minlocation.'Z' unless $maxlocation;
34 my $datelastseen = $input->param('datelastseen');
35 $datelastseen = format_date_in_iso($datelastseen);
36 my $offset = $input->param('offset');
37 my $markseen = $input->param('markseen');
38 $offset=0 unless $offset;
39 my $pagesize = $input->param('pagesize');
40 $pagesize=50 unless $pagesize;
41 my $uploadbarcodes = $input->param('uploadbarcodes');
42 my $branchcode = $input->param('branchcode');
43 my $op = $input->param('op');
44 # warn "uploadbarcodes : ".$uploadbarcodes;
45
46 my ($template, $borrowernumber, $cookie)
47     = get_template_and_user({template_name => "tools/inventory.tmpl",
48                 query => $input,
49                 type => "intranet",
50                 authnotrequired => 0,
51                 flagsrequired => {tools => 1},
52                 debug => 1,
53                 });
54
55 my $branches = GetBranches();
56 my @branch_loop;
57 push @branch_loop, {value => "", branchname => "All Branches", };
58 for my $branch_hash (keys %$branches) {
59         push @branch_loop, {value => "$branch_hash",
60                            branchname => $branches->{$branch_hash}->{'branchname'}, 
61                            selected => ($branch_hash eq $branchcode?1:0)};      
62 }
63 $template->param(branchloop => \@branch_loop,
64                 DHTMLcalendar_dateformat => get_date_format_string_for_DHTMLcalendar(),
65                 minlocation => $minlocation,
66                 maxlocation => $maxlocation,
67                 offset => $offset,
68                 pagesize => $pagesize,
69                 datelastseen => $datelastseen,
70                 intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
71                 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
72                 IntranetNav => C4::Context->preference("IntranetNav"),
73                 );
74 if ($uploadbarcodes && length($uploadbarcodes)>0){
75     my $dbh=C4::Context->dbh;
76     my $date=format_date($input->param('setdate'));
77     $date = format_date("today") unless $date;
78 #       warn "$date";
79     my $strsth="update items set (datelastseen = $date) where items.barcode =?";
80     my $qupdate = $dbh->prepare($strsth);
81     my $strsth="select * from issues, items where items.itemnumber=issues.itemnumber and items.barcode =? and issues.returndate is null";
82     my $qonloan = $dbh->prepare($strsth);
83     my $strsth="select * from items where items.barcode =? and issues.wthdrawn=1";
84     my $qwthdrawn = $dbh->prepare($strsth);
85     my @errorloop;
86     my $count=0;
87     while (my $barcode=<$uploadbarcodes>){
88         chomp $barcode;
89 #               warn "$barcode";
90         if ($qwthdrawn->execute($barcode) &&$qwthdrawn->rows){
91             push @errorloop, {'barcode'=>$barcode,'ERR_WTHDRAWN'=>1};
92         }else{
93             $qupdate->execute($barcode);
94             $count += $qupdate->rows;
95 #                       warn "$count";
96             if ($count){
97                 $qonloan->execute($barcode);
98                 if ($qonloan->rows){
99                     my $data = $qonloan->fetchrow_hashref;
100                     my ($doreturn, $messages, $iteminformation, $borrower) =AddReturn($barcode, $data->{homebranch});
101                     if ($doreturn){push @errorloop, {'barcode'=>$barcode,'ERR_ONLOAN_RET'=>1}}
102                     else {push @errorloop, {'barcode'=>$barcode,'ERR_ONLOAN_NOT_RET'=>1}}
103                 }
104             } else {
105                 push @errorloop, {'barcode'=>$barcode,'ERR_BARCODE'=>1};
106             }
107         }
108     }
109     $qupdate->finish;
110     $qonloan->finish;
111     $qwthdrawn->finish;
112     $template->param(date=>$date,Number=>$count);
113 #       $template->param(errorfile=>$errorfile) if ($errorfile);
114     $template->param(errorloop=>\@errorloop) if (@errorloop);
115 }else{
116     if ($markseen) {
117         foreach my $field ($input->param) {
118             if ($field =~ /SEEN-(.*)/) {
119                 &ModDateLastSeen($1);
120             }
121         }
122     }
123     if ($op) {
124         my $res = GetItemsForInventory($minlocation,$maxlocation,$datelastseen,$branchcode,$offset,$pagesize);
125         $template->param(loop =>$res,
126                         nextoffset => ($offset+$pagesize),
127                         prevoffset => ($offset?$offset-$pagesize:0),
128                         );
129     }
130 }
131 output_html_with_http_headers $input, $cookie, $template->output;
132
133 # Local Variables:
134 # tab-width: 8
135 # End: