*** empty log message ***
[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::Interface::CGI::Output;
34 use C4::Database;
35 use HTML::Template;
36
37 my $input=new CGI;
38 my $id=$input->param('id');
39 my $dbh = C4::Context->dbh;
40
41 my $search=$input->param('recieve');
42 my $invoice=$input->param('invoice');
43 my $freight=$input->param('freight');
44 my $biblio=$input->param('biblio');
45 my $catview=$input->param('catview');
46 my $gst=$input->param('gst');
47 my ($count,@results)=ordersearch($search,$id,$biblio,$catview);
48 my ($count2,@booksellers)=bookseller($results[0]->{'booksellerid'});
49 my @date=split('-',$results[0]->{'entrydate'});
50 my $date="$date[2]/$date[1]/$date[0]";
51
52 my ($template, $loggedinuser, $cookie)
53     = get_template_and_user({template_name => "acqui/acquire.tmpl",
54                              query => $input,
55                              type => "intranet",
56                              authnotrequired => 0,
57                              flagsrequired => {acquisition => 1},
58                              debug => 1,
59                              });
60
61 $template->param($count);
62 if ($count == 1){
63         my $query="Select itemtype,description from itemtypes order by description";
64         my $sth=$dbh->prepare($query);
65         $sth->execute;
66         my  @itemtype;
67         my %itemtypes;
68         push @itemtype, "";
69         $itemtypes{''} = "Please choose";
70         while (my ($value,$lib) = $sth->fetchrow_array) {
71                 push @itemtype, $value;
72                 $itemtypes{$value}=$lib;
73         }
74
75         my $CGIitemtype=CGI::scrolling_list( -name     => 'format',
76                                 -values   => \@itemtype,
77                                 -default  => $results[0]->{'itemtype'},
78                                 -labels   => \%itemtypes,
79                                 -size     => 1,
80                                 -multiple => 0 );
81         $sth->finish;
82
83         my @branches;
84         my @select_branch;
85         my %select_branches;
86         my ($count2,@branches)=branches();
87         for (my $i=0;$i<$count2;$i++){
88                 push @select_branch, $branches[$i]->{'branchcode'};#
89                 $select_branches{$branches[$i]->{'branchcode'}} = $branches[$i]->{'branchname'};
90         }
91         my $CGIbranch=CGI::scrolling_list( -name     => 'branch',
92                                 -values   => \@select_branch,
93                                 -default  => $results[0]->{'branchcode'},
94                                 -labels   => \%select_branches,
95                                 -size     => 1,
96                                 -multiple => 0 );
97         $sth->finish;
98
99         my $auto_barcode = C4::Context->boolean_preference("autoBarcode") || 0;
100                 # See whether barcodes should be automatically allocated.
101                 # Defaults to 0, meaning "no".
102         my $barcode;
103         if ($auto_barcode eq '1') {
104                 $sth=$dbh->prepare("Select max(barcode) from items");
105                 $sth->execute;
106                 my $data=$sth->fetchrow_hashref;
107                 $barcode = $results[0]->{'barcode'}+1;
108                 $sth->finish;
109         }
110
111         my @bookfund;
112         my @select_bookfund;
113         my %select_bookfunds;
114         ($count2,@bookfund)=bookfunds();
115         for (my $i=0;$i<$count2;$i++){
116                 push @select_bookfund, $bookfund[$i]->{'bookfundid'};
117                 $select_bookfunds{$bookfund[$i]->{'bookfundid'}} = $bookfund[$i]->{'bookfundname'}
118         }
119         my $CGIbookfund=CGI::scrolling_list( -name     => 'bookfund',
120                                 -values   => \@select_bookfund,
121                                 -default  => $results[0]->{'bookfundid'},
122                                 -labels   => \%select_bookfunds,
123                                 -size     => 1,
124                                 -multiple => 0 );
125
126         my $rrp=$results[0]->{'rrp'};
127         if ($results[0]->{'quantityreceived'} == 0){
128         $results[0]->{'quantityreceived'}='';
129         }
130         if ($results[0]->{'unitprice'} == 0){
131         $results[0]->{'unitprice'}='';
132         }
133         $template->param(
134                 count => 1,
135                 biblionumber => $results[0]->{'biblionumber'},
136                 ordernumber => $results[0]->{'ordernumber'},
137                 biblioitemnumber => $results[0]->{'biblioitemnumber'},
138                 booksellerid => $results[0]->{'booksellerid'},
139                 freight => $freight,
140                 gst => $gst,
141                 catview => ($catview ne 'yes'?1:0),
142                 name => $booksellers[0]->{'name'},
143                 date => $date,
144                 title => $results[0]->{'title'},
145                 author => $results[0]->{'author'},
146                 copyrightdate => $results[0]->{'copyrightdate'},
147                 CGIitemtype => $CGIitemtype,
148                 CGIbranch => $CGIbranch,
149                 isbn => $results[0]->{'isbn'},
150                 seriestitle => $results[0]->{'seriestitle'},
151                 barcode => $barcode,
152                 CGIbookfund => $CGIbookfund,
153                 quantity => $results[0]->{'quantity'},
154                 quantityreceived => $results[0]->{'quantityreceived'},
155                 rrp => $rrp,
156                 ecost => $results[0]->{'ecost'},
157                 unitprice => $results[0]->{'unitprice'},
158                 invoice => $invoice,
159                 notes => $results[0]->{'notes'},
160         );
161 } else {
162         my @loop;
163         for (my $i=0;$i<$count;$i++){
164                 my %line;
165                 $line{isbn} = $results[$i]->{'isbn'};
166                 $line{basketno} = $results[$i]->{'basketno'};
167                 $line{quantity} = $results[$i]->{'quantity'};
168                 $line{quantityrecieved} = $results[$i]->{'quantityreceived'};
169                 $line{ordernumber} = $results[$i]->{'ordernumber'};
170                 $line{biblionumber} = $results[$i]->{'biblionumber'};
171                 $line{invoice} = $invoice;
172                 $line{freight} = $freight;
173                 $line{gst} = $gst;
174                 $line{title} = $results[$i]->{'title'};
175                 $line{author} = $results[$i]->{'author'};
176                 $line{id} = $id;
177                 push @loop,\%line;
178         }
179         $template->param( loop => \@loop,
180                                                 date => $date,
181                                                 name => $booksellers[0]->{'name'},
182                                                 id => $id,
183                                                 invoice => $invoice,
184 );
185
186 }
187 output_html_with_http_headers $input, $cookie, $template->output;