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