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