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