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 $itemtype=$input->param('itemtype');
37 my $datelastseen = $input->param('datelastseen');
38 my $offset = $input->param('offset');
39 my $markseen = $input->param('markseen');
40 $offset=0 unless $offset;
41 my $pagesize = $input->param('pagesize');
42 $pagesize=50 unless $pagesize;
43 my $uploadbarcodes = $input->param('uploadbarcodes');
44 my $branchcode = $input->param('branchcode');
45 my $op = $input->param('op');
46 # warn "uploadbarcodes : ".$uploadbarcodes;
47 # use Data::Dumper; warn Dumper($input);
48 my ($template, $borrowernumber, $cookie)
49 = get_template_and_user
({template_name
=> "tools/inventory.tmpl",
53 flagsrequired
=> {tools
=> 1},
57 my $branches = GetBranches
();
59 push @branch_loop, {value
=> "", branchname
=> "All Locations", };
60 for my $branch_hash (keys %$branches) {
61 push @branch_loop, {value
=> "$branch_hash",
62 branchname
=> $branches->{$branch_hash}->{'branchname'},
63 selected
=> ($branch_hash eq $branchcode?
1:0)};
67 my $itemtypes = GetItemTypes
;
69 foreach my $thisitemtype (sort keys %$itemtypes) {
70 my $selected = 1 if $thisitemtype eq $itemtype;
71 my %row =(value
=> $thisitemtype,
72 selected
=> $selected,
73 description
=> $itemtypes->{$thisitemtype}->{'description'},
75 push @itemtypesloop, \
%row;
77 $template->param(itemtypeloop
=> \
@itemtypesloop);
79 my @authorised_value_list;
80 my $authorisedvalue_categories;
82 my $dbh=C4
::Context
->dbh;
83 my $rqauthcategorie=$dbh->prepare("SELECT authorised_value FROM marc_subfield_structure WHERE frameworkcode=? AND kohafield='items.location'");
84 my $rq=$dbh->prepare("SELECT frameworkcode FROM biblio_framework");
86 while (my ($fwkcode)=$rq->fetchrow){
87 $rqauthcategorie->execute($fwkcode);
88 while (my ($authcat)=$rqauthcategorie->fetchrow){
89 if ($authcat && $authorisedvalue_categories!~/\b$authcat\W/){
90 $authorisedvalue_categories.="$authcat ";
91 my $data=GetAuthorisedValues
($authcat);
92 foreach my $value (@
$data){
93 $value->{selected
}=1 if ($value->{authorised_value
} eq ($location));
95 push @authorised_value_list,@
$data;
102 $template->param(branchloop
=> \
@branch_loop,
103 authorised_values
=>\
@authorised_value_list,
104 DHTMLcalendar_dateformat
=> C4
::Dates
->DHTMLcalendar(),
105 minlocation
=> $minlocation,
106 maxlocation
=> $maxlocation,
108 branchcode
=>$branchcode,
110 pagesize
=> $pagesize,
111 datelastseen
=> $datelastseen,
113 if ($uploadbarcodes && length($uploadbarcodes)>0){
114 my $dbh=C4
::Context
->dbh;
115 my $date = format_date_in_iso
($input->param('setdate')) || C4
::Dates
->today('iso');
117 my $strsth="select * from issues, items where items.itemnumber=issues.itemnumber and items.barcode =? and issues.returndate is null";
118 my $qonloan = $dbh->prepare($strsth);
119 $strsth="select * from items where items.barcode =? and issues.wthdrawn=1";
120 my $qwthdrawn = $dbh->prepare($strsth);
123 while (my $barcode=<$uploadbarcodes>){
126 if ($qwthdrawn->execute($barcode) &&$qwthdrawn->rows){
127 push @errorloop, {'barcode'=>$barcode,'ERR_WTHDRAWN'=>1};
129 my $item = GetItem
('', $barcode);
131 ModItem
({ datelastseen
=> $date }, undef, $item->{'itemnumber'});
133 $qonloan->execute($barcode);
135 my $data = $qonloan->fetchrow_hashref;
136 my ($doreturn, $messages, $iteminformation, $borrower) =AddReturn
($barcode, $data->{homebranch
});
137 if ($doreturn){push @errorloop, {'barcode'=>$barcode,'ERR_ONLOAN_RET'=>1}}
138 else {push @errorloop, {'barcode'=>$barcode,'ERR_ONLOAN_NOT_RET'=>1}}
141 push @errorloop, {'barcode'=>$barcode,'ERR_BARCODE'=>1};
147 $template->param(date
=>format_date
($date),Number
=>$count);
148 # $template->param(errorfile=>$errorfile) if ($errorfile);
149 $template->param(errorloop
=>\
@errorloop) if (@errorloop);
152 foreach ($input->param) {
153 /SEEN-(.+)/ and &ModDateLastSeen
($1);
156 if ($markseen or $op) {
157 my $res = GetItemsForInventory
($minlocation,$maxlocation,$location,$itemtype,$datelastseen,$branchcode,$offset,$pagesize);
158 $template->param(loop =>$res,
159 nextoffset
=> ($offset+$pagesize),
160 prevoffset
=> ($offset?
$offset-$pagesize:0),
164 output_html_with_http_headers
$input, $cookie, $template->output;