bugfixes. seems to work better.
[koha.git] / acqui / acquire.pl
1 #!/usr/bin/perl
2
3 # $Id$
4
5 #script to recieve orders
6 #written by chris@katipo.co.nz 24/2/2000
7
8
9 # Copyright 2000-2002 Katipo Communications
10 #
11 # This file is part of Koha.
12 #
13 # Koha is free software; you can redistribute it and/or modify it under the
14 # terms of the GNU General Public License as published by the Free Software
15 # Foundation; either version 2 of the License, or (at your option) any later
16 # version.
17 #
18 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
19 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
20 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License along with
23 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
24 # Suite 330, Boston, MA  02111-1307 USA
25 use strict;
26 use CGI;
27 use C4::Context;
28 use C4::Catalogue;
29 use C4::Biblio;
30 use C4::Output;
31 use C4::Search;
32 use C4::Auth;
33 use C4::Biblio;
34 use C4::Output;
35 use C4::Interface::CGI::Output;
36 use C4::Database;
37 use HTML::Template;
38
39 my $input=new CGI;
40 my $id=$input->param('id');
41 my $dbh = C4::Context->dbh;
42
43 my $search=$input->param('recieve');
44 my $invoice=$input->param('invoice');
45 my $freight=$input->param('freight');
46 my $biblio=$input->param('biblio');
47 my $catview=$input->param('catview');
48 my $gst=$input->param('gst');
49 my ($count,@results)=ordersearch($search,$id,$biblio,$catview);
50 my ($count2,@booksellers)=bookseller($results[0]->{'booksellerid'});
51 my @date=split('-',$results[0]->{'entrydate'});
52 my $date="$date[2]/$date[1]/$date[0]";
53
54 my ($template, $loggedinuser, $cookie)
55     = get_template_and_user({template_name => "acqui/acquire.tmpl",
56                              query => $input,
57                              type => "intranet",
58                              authnotrequired => 0,
59                              flagsrequired => {acquisition => 1},
60                              debug => 1,
61                              });
62
63 $template->param($count);
64 if ($count == 1){
65         my $query="Select itemtype,description from itemtypes order by description";
66         my $sth=$dbh->prepare($query);
67         $sth->execute;
68         my  @itemtype;
69         my %itemtypes;
70         push @itemtype, "";
71         $itemtypes{''} = "Please choose";
72         while (my ($value,$lib) = $sth->fetchrow_array) {
73                 push @itemtype, $value;
74                 $itemtypes{$value}=$lib;
75         }
76
77         my $CGIitemtype=CGI::scrolling_list( -name     => 'format',
78                                 -values   => \@itemtype,
79                                 -default  => $results[0]->{'itemtype'},
80                                 -labels   => \%itemtypes,
81                                 -size     => 1,
82                                 -multiple => 0 );
83         $sth->finish;
84
85         my @branches;
86         my @select_branch;
87         my %select_branches;
88         my ($count2,@branches)=branches();
89         for (my $i=0;$i<$count2;$i++){
90                 push @select_branch, $branches[$i]->{'branchcode'};#
91                 $select_branches{$branches[$i]->{'branchcode'}} = $branches[$i]->{'branchname'};
92         }
93         my $CGIbranch=CGI::scrolling_list( -name     => 'branch',
94                                 -values   => \@select_branch,
95                                 -default  => $results[0]->{'branchcode'},
96                                 -labels   => \%select_branches,
97                                 -size     => 1,
98                                 -multiple => 0 );
99         $sth->finish;
100
101         my $auto_barcode = C4::Context->boolean_preference("autoBarcode") || 0;
102                 # See whether barcodes should be automatically allocated.
103                 # Defaults to 0, meaning "no".
104         my $barcode;
105         if ($auto_barcode eq '1') {
106                 $sth=$dbh->prepare("Select max(barcode) from items");
107                 $sth->execute;
108                 my $data=$sth->fetchrow_hashref;
109                 $barcode = $results[0]->{'barcode'}+1;
110                 $sth->finish;
111         }
112
113         my @bookfund;
114         my @select_bookfund;
115         my %select_bookfunds;
116         ($count2,@bookfund)=bookfunds();
117         for (my $i=0;$i<$count2;$i++){
118                 push @select_bookfund, $bookfund[$i]->{'bookfundid'};
119                 $select_bookfunds{$bookfund[$i]->{'bookfundid'}} = $bookfund[$i]->{'bookfundname'}
120         }
121         my $CGIbookfund=CGI::scrolling_list( -name     => 'bookfund',
122                                 -values   => \@select_bookfund,
123                                 -default  => $results[0]->{'bookfundid'},
124                                 -labels   => \%select_bookfunds,
125                                 -size     => 1,
126                                 -multiple => 0 );
127
128         my $rrp=$results[0]->{'rrp'};
129         if ($results[0]->{'quantityreceived'} == 0){
130         $results[0]->{'quantityreceived'}='';
131         }
132         if ($results[0]->{'unitprice'} == 0){
133         $results[0]->{'unitprice'}='';
134         }
135         $template->param(
136                 count => 1,
137                 biblionumber => $results[0]->{'biblionumber'},
138                 ordernumber => $results[0]->{'ordernumber'},
139                 biblioitemnumber => $results[0]->{'biblioitemnumber'},
140                 booksellerid => $results[0]->{'booksellerid'},
141                 freight => $freight,
142                 gst => $gst,
143                 catview => ($catview ne 'yes'?1:0),
144                 name => $booksellers[0]->{'name'},
145                 date => $date,
146                 title => $results[0]->{'title'},
147                 author => $results[0]->{'author'},
148                 copyrightdate => $results[0]->{'copyrightdate'},
149                 CGIitemtype => $CGIitemtype,
150                 CGIbranch => $CGIbranch,
151                 isbn => $results[0]->{'isbn'},
152                 seriestitle => $results[0]->{'seriestitle'},
153                 barcode => $barcode,
154                 CGIbookfund => $CGIbookfund,
155                 quantity => $results[0]->{'quantity'},
156                 quantityreceived => $results[0]->{'quantityreceived'},
157                 rrp => $rrp,
158                 ecost => $results[0]->{'ecost'},
159                 unitprice => $results[0]->{'unitprice'},
160                 invoice => $invoice,
161                 notes => $results[0]->{'notes'},
162         );
163 } else {
164         my @loop;
165         for (my $i=0;$i<$count;$i++){
166                 my %line;
167                 $line{isbn} = $results[$i]->{'isbn'};
168                 $line{basketno} = $results[$i]->{'basketno'};
169                 $line{quantity} = $results[$i]->{'quantity'};
170                 $line{quantityrecieved} = $results[$i]->{'quantityreceived'};
171                 $line{ordernumber} = $results[$i]->{'ordernumber'};
172                 $line{biblionumber} = $results[$i]->{'biblionumber'};
173                 $line{invoice} = $invoice;
174                 $line{freight} = $freight;
175                 $line{gst} = $gst;
176                 $line{title} = $results[$i]->{'title'};
177                 $line{author} = $results[$i]->{'author'};
178                 $line{id} = $id;
179                 push @loop,\%line;
180         }
181         $template->param( loop => \@loop,
182                                                 user => $loggedinuser,
183                                                 date => $date,
184                                                 name => $booksellers[0]->{'name'},
185                                                 id => $id,
186                                                 invoice => $invoice,
187 );
188
189 }
190 output_html_with_http_headers $input, $cookie, $template->output;