fixing bug #526 : gst rate is now calculated through systempref gist entry.
[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::Catalogue;
28 use C4::Biblio;
29 use C4::Output;
30 use C4::Search;
31 use C4::Auth;
32 use C4::Output;
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 $title=$input->param('title');
40 my $author=$input->param('author');
41 my $copyright=$input->param('copyright');
42 my ($count,@booksellers)=bookseller($id);
43 my $ordnum=$input->param('ordnum');
44 my $biblio=$input->param('biblio');
45 my $basket=$input->param('basket');
46 my $data;
47 my $new;
48 my $dbh = C4::Context->dbh;
49 if ($ordnum eq ''){
50         $new='yes';
51         $ordnum=newordernum;
52         if ($biblio) {
53                         $data=bibdata($biblio);
54         }
55         if ($data->{'title'} eq ''){
56                 $data->{'title'}=$title;
57                 $data->{'author'}=$author;
58                 $data->{'copyrightdate'}=$copyright;
59         }
60 }else {
61         $data=getsingleorder($ordnum);
62         $biblio=$data->{'biblionumber'};
63 }
64 my ($template, $loggedinuser, $cookie)
65     = get_template_and_user({template_name => "acqui/newbiblio.tmpl",
66                              query => $input,
67                              type => "intranet",
68                              authnotrequired => 0,
69                              flagsrequired => {acquisition => 1},
70                              debug => 1,
71                              });
72
73 #my ($count2,$currencies)=getcurrencies;
74 my ($count,$rates)=getcurrencies();
75 my @loop_currency = ();
76 for (my $i=0;$i<$count;$i++){
77         my %line;
78         $line{currency} = $rates->[$i]->{'currency'};
79         $line{rate} = $rates->[$i]->{'rate'};
80         push @loop_currency, \%line;
81 }
82
83 my $query="Select itemtype,description from itemtypes order by description";
84 my $sth=$dbh->prepare($query);
85 $sth->execute;
86 my  @itemtype;
87 my %itemtypes;
88 push @itemtype, "";
89 $itemtypes{''} = "Please choose";
90 while (my ($value,$lib) = $sth->fetchrow_array) {
91         push @itemtype, $value;
92         $itemtypes{$value}=$lib;
93 }
94
95 my $CGIitemtype=CGI::scrolling_list( -name     => 'format',
96                         -values   => \@itemtype,
97                         -default  => $data->{'itemtype'},
98                         -labels   => \%itemtypes,
99                         -size     => 1,
100                         -multiple => 0 );
101 $sth->finish;
102
103 my @branches;
104 my @select_branch;
105 my %select_branches;
106 my ($count2,@branches)=branches();
107 for (my $i=0;$i<$count2;$i++){
108         push @select_branch, $branches[$i]->{'branchcode'};#
109         $select_branches{$branches[$i]->{'branchcode'}} = $branches[$i]->{'branchname'};
110 }
111 my $CGIbranch=CGI::scrolling_list( -name     => 'branch',
112                         -values   => \@select_branch,
113                         -default  => $data->{'branchcode'},
114                         -labels   => \%select_branches,
115                         -size     => 1,
116                         -multiple => 0 );
117
118 my $auto_barcode = C4::Context->boolean_preference("autoBarcode") || 0;
119         # See whether barcodes should be automatically allocated.
120         # Defaults to 0, meaning "no".
121 my $barcode;
122 if ($auto_barcode eq '1') {
123         $sth=$dbh->prepare("Select max(barcode) from items");
124         $sth->execute;
125         my $data=$sth->fetchrow_hashref;
126         $barcode = $data->{'barcode'}+1;
127         $sth->finish;
128 }
129
130 my @bookfund;
131 my @select_bookfund;
132 my %select_bookfunds;
133 ($count2,@bookfund)=bookfunds();
134 for (my $i=0;$i<$count2;$i++){
135         push @select_bookfund, $bookfund[$i]->{'bookfundid'};
136         $select_bookfunds{$bookfund[$i]->{'bookfundid'}} = $bookfund[$i]->{'bookfundname'}
137 }
138 my $CGIbookfund=CGI::scrolling_list( -name     => 'bookfund',
139                         -values   => \@select_bookfund,
140                         -default  => $data->{'bookfundid'},
141                         -labels   => \%select_bookfunds,
142                         -size     => 1,
143                         -multiple => 0 );
144
145 $template->param( existing => $biblio,
146                                                 title => $title,
147                                                 ordnum => $ordnum,
148                                                 basket => $basket,
149                                                 id => $id,
150                                                 biblio => $biblio,
151                                                 biblioitemnumber => $data->{'biblioitemnumber'},
152                                                 itemtype => $data->{'itemtype'},
153                                                 discount => $booksellers[0]->{'discount'},
154                                         listincgst => $booksellers[0]->{'listincgst'},
155                                                 listprice => $booksellers[0]->{'listprice'},
156                                                 gstreg => $booksellers[0]->{'gstreg'},
157                                                 name => $booksellers[0]->{'name'},
158                                                 currency => $booksellers[0]->{'listprice'},
159                                                 gstrate => C4::Context->preference("gist") ,
160                                                 loop_currencies => \@loop_currency,
161                                                 orderexists => ($new eq 'yes')?0:1,
162                                                 title => $data->{'title'},
163                                                 author => $data->{'author'},
164                                                 copyrightdate => $data->{'copyrightdate'},
165                                                 CGIitemtype => $CGIitemtype,
166                                                 CGIbranch => $CGIbranch,
167                                                 CGIbookfund => $CGIbookfund,
168                                                 isbn => $data->{'isbn'},
169                                                 seriestitle => $data->{'seriestitle'},
170                                                 quantity => $data->{'quantity'},
171                                                 listprice => $data->{'listprice'},
172                                                 rrp => $data->{'rrp'},
173                                                 ecost => $data->{'ecost'},
174                                                 notes => $data->{'notes'},
175                                                 barcode => $data->{'barcode'},);
176
177 output_html_with_http_headers $input, $cookie, $template->output;
178