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