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
33 my $minlocation=$input->param('minlocation') || '';
34 my $maxlocation=$input->param('maxlocation');
35 $maxlocation=$minlocation.'Z' unless ( $maxlocation || ! $minlocation );
36 my $location=$input->param('location');
37 my $itemtype=$input->param('itemtype');
38 my $ignoreissued=$input->param('ignoreissued');
39 my $datelastseen = $input->param('datelastseen');
40 my $offset = $input->param('offset');
41 my $markseen = $input->param('markseen');
42 $offset=0 unless $offset;
43 my $pagesize = $input->param('pagesize');
44 $pagesize=50 unless $pagesize;
45 my $uploadbarcodes = $input->param('uploadbarcodes');
46 my $branchcode = $input->param('branchcode');
47 my $op = $input->param('op');
48 # warn "uploadbarcodes : ".$uploadbarcodes;
49 # use Data::Dumper; warn Dumper($input);
50 my ($template, $borrowernumber, $cookie)
51 = get_template_and_user({template_name => "tools/inventory.tmpl",
55 flagsrequired => {tools => 'inventory'},
59 my $branches = GetBranches();
61 push @branch_loop, {value => "", branchname => "All Locations", };
62 for my $branch_hash (keys %$branches) {
63 push @branch_loop, {value => "$branch_hash",
64 branchname => $branches->{$branch_hash}->{'branchname'},
65 selected => ($branch_hash eq $branchcode?1:0)};
69 my $itemtypes = GetItemTypes;
71 foreach my $thisitemtype (sort keys %$itemtypes) {
72 my $selected = 1 if $thisitemtype eq $itemtype;
73 my %row =(value => $thisitemtype,
74 selected => $selected,
75 description => $itemtypes->{$thisitemtype}->{'description'},
77 push @itemtypesloop, \%row;
79 $template->param(itemtypeloop => \@itemtypesloop);
81 my @authorised_value_list;
82 my $authorisedvalue_categories;
84 my $dbh=C4::Context->dbh;
85 my $rqauthcategorie=$dbh->prepare("SELECT authorised_value FROM marc_subfield_structure WHERE frameworkcode=? AND kohafield='items.location'");
86 my $rq=$dbh->prepare("SELECT frameworkcode FROM biblio_framework");
88 while (my ($fwkcode)=$rq->fetchrow){
89 $rqauthcategorie->execute($fwkcode);
90 while (my ($authcat)=$rqauthcategorie->fetchrow){
91 if ($authcat && $authorisedvalue_categories!~/\b$authcat\W/){
92 $authorisedvalue_categories.="$authcat ";
93 my $data=GetAuthorisedValues($authcat);
94 foreach my $value (@$data){
95 $value->{selected}=1 if ($value->{authorised_value} eq ($location));
97 push @authorised_value_list,@$data;
104 $template->param(branchloop => \@branch_loop,
105 authorised_values=>\@authorised_value_list,
106 DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
107 minlocation => $minlocation,
108 maxlocation => $maxlocation,
110 ignoreissued=>$ignoreissued,
111 branchcode=>$branchcode,
113 pagesize => $pagesize,
114 datelastseen => $datelastseen,
116 if ($uploadbarcodes && length($uploadbarcodes)>0){
117 my $dbh=C4::Context->dbh;
118 my $date = format_date_in_iso($input->param('setdate')) || C4::Dates->today('iso');
120 my $strsth="select * from issues, items where items.itemnumber=issues.itemnumber and items.barcode =?";
121 my $qonloan = $dbh->prepare($strsth);
122 $strsth="select * from items where items.barcode =? and items.wthdrawn = 1";
123 my $qwthdrawn = $dbh->prepare($strsth);
126 while (my $barcode=<$uploadbarcodes>){
127 $barcode =~ s/\r?\n$//;
128 if ($qwthdrawn->execute($barcode) &&$qwthdrawn->rows){
129 push @errorloop, {'barcode'=>$barcode,'ERR_WTHDRAWN'=>1};
131 my $item = GetItem('', $barcode);
132 if (defined $item && $item->{'itemnumber'}){
133 ModItem({ datelastseen => $date }, undef, $item->{'itemnumber'});
135 $qonloan->execute($barcode);
137 my $data = $qonloan->fetchrow_hashref;
138 my ($doreturn, $messages, $iteminformation, $borrower) =AddReturn($barcode, $data->{homebranch});
139 if ($doreturn){push @errorloop, {'barcode'=>$barcode,'ERR_ONLOAN_RET'=>1}}
140 else {push @errorloop, {'barcode'=>$barcode,'ERR_ONLOAN_NOT_RET'=>1}}
143 push @errorloop, {'barcode'=>$barcode,'ERR_BARCODE'=>1};
149 $template->param(date=>format_date($date),Number=>$count);
150 # $template->param(errorfile=>$errorfile) if ($errorfile);
151 $template->param(errorloop=>\@errorloop) if (@errorloop);
154 foreach ($input->param) {
155 /SEEN-(.+)/ and &ModDateLastSeen($1);
158 if ($markseen or $op) {
159 my $res = GetItemsForInventory($minlocation,$maxlocation,$location,$itemtype,$ignoreissued,$datelastseen,$branchcode,$offset,$pagesize);
160 $template->param(loop =>$res,
161 nextoffset => ($offset+$pagesize),
162 prevoffset => ($offset?$offset-$pagesize:0),
166 output_html_with_http_headers $input, $cookie, $template->output;