3 # Copyright 2000-2002 Katipo Communications
5 # This file is part of Koha.
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
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.
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
27 use C4::Dates qw/format_date format_date_in_iso/;
29 use C4::Branch; # GetBranches
32 my $minlocation=$input->param('minlocation') || 'A';
33 my $maxlocation=$input->param('maxlocation');
34 $maxlocation=$minlocation.'Z' unless $maxlocation;
35 my $location=$input->param('location');
36 my $datelastseen = $input->param('datelastseen');
37 my $offset = $input->param('offset');
38 my $markseen = $input->param('markseen');
39 $offset=0 unless $offset;
40 my $pagesize = $input->param('pagesize');
41 $pagesize=50 unless $pagesize;
42 my $uploadbarcodes = $input->param('uploadbarcodes');
43 my $branchcode = $input->param('branchcode');
44 my $op = $input->param('op');
45 # warn "uploadbarcodes : ".$uploadbarcodes;
46 # use Data::Dumper; warn Dumper($input);
47 my ($template, $borrowernumber, $cookie)
48 = get_template_and_user({template_name => "tools/inventory.tmpl",
52 flagsrequired => {tools => 1},
56 my $branches = GetBranches();
58 push @branch_loop, {value => "", branchname => "All Locations", };
59 for my $branch_hash (keys %$branches) {
60 push @branch_loop, {value => "$branch_hash",
61 branchname => $branches->{$branch_hash}->{'branchname'},
62 selected => ($branch_hash eq $branchcode?1:0)};
65 my @authorised_value_list;
66 my $authorisedvalue_categories;
68 my $dbh=C4::Context->dbh;
69 my $rqauthcategorie=$dbh->prepare("select authorised_value from marc_subfield_structure where frameworkcode=? and kohafield='items.location'");
70 my $rq=$dbh->prepare("select frameworkcode from biblio_framework");
72 while (my ($fwkcode)=$rq->fetchrow){
73 $rqauthcategorie->execute($fwkcode);
74 while (my ($authcat)=$rqauthcategorie->fetchrow){
75 if ($authcat && $authorisedvalue_categories!~/\b$authcat\W/){
76 $authorisedvalue_categories.="$authcat ";
77 my $data=GetAuthorisedValues($authcat);
78 foreach my $value (@$data){
79 $value->{selected}=1 if ($value->{authorised_value} eq ($location));
81 push @authorised_value_list,@$data;
88 $template->param(branchloop => \@branch_loop,
89 authorised_values=>\@authorised_value_list,
90 DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
91 minlocation => $minlocation,
92 maxlocation => $maxlocation,
94 branchcode=>$branchcode,
96 pagesize => $pagesize,
97 datelastseen => $datelastseen,
99 if ($uploadbarcodes && length($uploadbarcodes)>0){
100 my $dbh=C4::Context->dbh;
101 my $date = format_date_in_iso($input->param('setdate')) || C4::Dates->today('iso');
103 my $strsth="select * from issues, items where items.itemnumber=issues.itemnumber and items.barcode =? and issues.returndate is null";
104 my $qonloan = $dbh->prepare($strsth);
105 $strsth="select * from items where items.barcode =? and issues.wthdrawn=1";
106 my $qwthdrawn = $dbh->prepare($strsth);
109 while (my $barcode=<$uploadbarcodes>){
112 if ($qwthdrawn->execute($barcode) &&$qwthdrawn->rows){
113 push @errorloop, {'barcode'=>$barcode,'ERR_WTHDRAWN'=>1};
115 my $item = GetItem('', $barcode);
117 ModItem({ datelastseen => $date }, undef, $item->{'itemnumber'});
119 $qonloan->execute($barcode);
121 my $data = $qonloan->fetchrow_hashref;
122 my ($doreturn, $messages, $iteminformation, $borrower) =AddReturn($barcode, $data->{homebranch});
123 if ($doreturn){push @errorloop, {'barcode'=>$barcode,'ERR_ONLOAN_RET'=>1}}
124 else {push @errorloop, {'barcode'=>$barcode,'ERR_ONLOAN_NOT_RET'=>1}}
127 push @errorloop, {'barcode'=>$barcode,'ERR_BARCODE'=>1};
133 $template->param(date=>format_date($date),Number=>$count);
134 # $template->param(errorfile=>$errorfile) if ($errorfile);
135 $template->param(errorloop=>\@errorloop) if (@errorloop);
138 foreach ($input->param) {
139 /SEEN-(.+)/ and &ModDateLastSeen($1);
142 if ($markseen or $op) {
143 my $res = GetItemsForInventory($minlocation,$maxlocation,$location,$datelastseen,$branchcode,$offset,$pagesize);
144 $template->param(loop =>$res,
145 nextoffset => ($offset+$pagesize),
146 prevoffset => ($offset?$offset-$pagesize:0),
150 output_html_with_http_headers $input, $cookie, $template->output;