catalogue.pm deals only with acquisitions.
[koha.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::Acquisition;
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 $sth=$dbh->prepare("Select itemtype,description from itemtypes order by description");
82 $sth->execute;
83 my  @itemtype;
84 my %itemtypes;
85 push @itemtype, "";
86 $itemtypes{''} = "Please choose";
87 while (my ($value,$lib) = $sth->fetchrow_array) {
88         push @itemtype, $value;
89         $itemtypes{$value}=$lib;
90 }
91
92 my $CGIitemtype=CGI::scrolling_list( -name     => 'format',
93                         -values   => \@itemtype,
94                         -default  => $data->{'itemtype'},
95                         -labels   => \%itemtypes,
96                         -size     => 1,
97                         -multiple => 0 );
98 $sth->finish;
99
100 my @branches;
101 my @select_branch;
102 my %select_branches;
103 my ($count2,@branches)=branches();
104 for (my $i=0;$i<$count2;$i++){
105         push @select_branch, $branches[$i]->{'branchcode'};#
106         $select_branches{$branches[$i]->{'branchcode'}} = $branches[$i]->{'branchname'};
107 }
108 my $CGIbranch=CGI::scrolling_list( -name     => 'branch',
109                         -values   => \@select_branch,
110                         -default  => $data->{'branchcode'},
111                         -labels   => \%select_branches,
112                         -size     => 1,
113                         -multiple => 0 );
114
115 my $auto_barcode = C4::Context->boolean_preference("autoBarcode") || 0;
116         # See whether barcodes should be automatically allocated.
117         # Defaults to 0, meaning "no".
118 my $barcode;
119 if ($auto_barcode eq '1') {
120         $sth=$dbh->prepare("Select max(barcode) from items");
121         $sth->execute;
122         my $data=$sth->fetchrow_hashref;
123         $barcode = $data->{'barcode'}+1;
124         $sth->finish;
125 }
126
127 my @bookfund;
128 my @select_bookfund;
129 my %select_bookfunds;
130 ($count2,@bookfund)=bookfunds();
131 for (my $i=0;$i<$count2;$i++){
132         push @select_bookfund, $bookfund[$i]->{'bookfundid'};
133         $select_bookfunds{$bookfund[$i]->{'bookfundid'}} = $bookfund[$i]->{'bookfundname'}
134 }
135 my $CGIbookfund=CGI::scrolling_list( -name     => 'bookfund',
136                         -values   => \@select_bookfund,
137                         -default  => $data->{'bookfundid'},
138                         -labels   => \%select_bookfunds,
139                         -size     => 1,
140                         -multiple => 0 );
141
142 $template->param( existing => $biblio,
143                                                 title => $title,
144                                                 ordnum => $ordnum,
145                                                 basket => $basket,
146                                                 id => $id,
147                                                 biblio => $biblio,
148                                                 biblioitemnumber => $data->{'biblioitemnumber'},
149                                                 itemtype => $data->{'itemtype'},
150                                                 discount => $booksellers[0]->{'discount'},
151                                                 listincgst => $booksellers[0]->{'listincgst'},
152                                                 listprice => $booksellers[0]->{'listprice'},
153                                                 gstreg => $booksellers[0]->{'gstreg'},
154                                                 name => $booksellers[0]->{'name'},
155                                                 currency => $booksellers[0]->{'listprice'},
156                                                 gstrate => C4::Context->preference("gist") ,
157                                                 loop_currencies => \@loop_currency,
158                                                 orderexists => ($new eq 'yes')?0:1,
159                                                 title => $data->{'title'},
160                                                 author => $data->{'author'},
161                                                 copyrightdate => $data->{'copyrightdate'},
162                                                 CGIitemtype => $CGIitemtype,
163                                                 CGIbranch => $CGIbranch,
164                                                 CGIbookfund => $CGIbookfund,
165                                                 isbn => $data->{'isbn'},
166                                                 seriestitle => $data->{'seriestitle'},
167                                                 quantity => $data->{'quantity'},
168                                                 listprice => $data->{'listprice'},
169                                                 rrp => $data->{'rrp'},
170                                                 ecost => $data->{'ecost'},
171                                                 notes => $data->{'notes'},
172                                                 sort1 => $data->{'sort1'},
173                                                 sort2 => $data->{'sort2'},
174                                                 barcode => $data->{'barcode'},
175                                                 publishercode => $data->{'publishercode'});
176
177 output_html_with_http_headers $input, $cookie, $template->output;