Commenting out a line that was preventing the script executing
[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::Input;
28 use C4::Database;
29 use C4::Auth;
30 use C4::Acquisition;
31 use C4::Suggestions;
32 use C4::Biblio;
33 use C4::Search;
34 use C4::Output;
35 use C4::Input;
36 use C4::Koha;
37 use C4::Interface::CGI::Output;
38 use HTML::Template;
39
40 my $input=new CGI;
41 my $booksellerid=$input->param('booksellerid');
42 my $title=$input->param('title');
43 my $author=$input->param('author');
44 my $copyright=$input->param('copyright');
45 my ($count,@booksellers)=bookseller($booksellerid);
46 my $ordnum=$input->param('ordnum');
47 my $biblio=$input->param('biblio');
48 my $basketno=$input->param('basketno');
49 my $suggestionid = $input->param('suggestionid');
50 my $close= $input->param('close');
51 my $data;
52 my $new;
53 my $dbh = C4::Context->dbh;
54 if ($ordnum eq ''){ # create order
55         $new='yes';
56 #       $ordnum=newordernum;
57         if ($biblio && !$suggestionid) {
58                         $data=bibdata($biblio);
59         }
60         # get suggestion fields if applicable. If it's a subscription renewal, then the biblio already exists
61         # otherwise, retrieve suggestion information.
62         if ($suggestionid) {
63                 if ($biblio) {
64                         $data=bibdata($biblio);
65                 } else {
66                         $data = getsuggestion($suggestionid);
67                 }
68         }
69         if ($data->{'title'} eq ''){
70                 $data->{'title'}=$title;
71                 $data->{'author'}=$author;
72                 $data->{'copyrightdate'}=$copyright;
73         }
74 }else { #modify order
75         $data=getsingleorder($ordnum);
76         $biblio=$data->{'biblionumber'};
77 }
78 my ($template, $loggedinuser, $cookie)
79     = get_template_and_user({template_name => "acqui/newbiblio.tmpl",
80                              query => $input,
81                              type => "intranet",
82                              authnotrequired => 0,
83                              flagsrequired => {acquisition => 1},
84                              debug => 1,
85                              });
86
87
88 # get currencies (for change rates calcs if needed
89 my ($count,$rates)=getcurrencies();
90 my @loop_currency = ();
91 for (my $i=0;$i<$count;$i++){
92         my %line;
93         $line{currency} = $rates->[$i]->{'currency'};
94         $line{rate} = $rates->[$i]->{'rate'};
95         push @loop_currency, \%line;
96 }
97
98 # build itemtype list
99 my $sth=$dbh->prepare("Select itemtype,description from itemtypes order by description");
100 $sth->execute;
101 my  @itemtype;
102 my %itemtypes;
103 while (my ($value,$lib) = $sth->fetchrow_array) {
104         push @itemtype, $value;
105         $itemtypes{$value}=$lib;
106 }
107 my $CGIitemtype=CGI::scrolling_list( -name     => 'format',
108                         -values   => \@itemtype,
109                         -default  => $data->{'itemtype'},
110                         -labels   => \%itemtypes,
111                         -size     => 1,
112                         -multiple => 0 );
113 $sth->finish;
114
115 # build branches list
116 my $branches = getbranches;
117 my @branchloop;
118 foreach my $thisbranch (sort keys %$branches) {
119         my %row =(value => $thisbranch,
120                                 branchname => $branches->{$thisbranch}->{'branchname'},
121                         );
122         push @branchloop, \%row;
123 }
124 $template->param(branchloop =>\@branchloop);
125
126 # build bookfund list
127 my $sthtemp = $dbh->prepare("Select flags, branchcode from borrowers where borrowernumber = ?");
128 $sthtemp->execute($loggedinuser);
129 my ($flags, $homebranch)=$sthtemp->fetchrow;
130
131 my $count2;
132 my @bookfund;
133 my @select_bookfund;
134 my %select_bookfunds;
135 ($count2,@bookfund)=bookfunds($homebranch);
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 my $bookfundname;
147 my $bookfundid;
148 if ($close){
149         $bookfundid=$data->{'bookfundid'};
150         $bookfundname= $select_bookfunds{$bookfundid};
151 }
152
153 #Build sort lists
154 my $CGIsort1 = buildCGIsort("Asort1","sort1",$data->{'sort1'});
155 if ($CGIsort1) {
156         $template->param(CGIsort1 => $CGIsort1);
157 } else {
158         $template->param( sort1 => $data->{'sort1'});
159 }
160
161 my $CGIsort2 = buildCGIsort("Asort2","sort2",$data->{'sort2'});
162 if ($CGIsort2) {
163         $template->param(CGIsort2 =>$CGIsort2);
164 } else {
165         $template->param( sort2 => $data->{'sort2'});
166 }
167
168 # fill template
169 $template->param( close=> $close, bookfundid=>$bookfundid, bookfundname=>$bookfundname) if ($close);
170
171
172 $template->param( existing => $biblio,
173                                                 title => $title,
174                                                 ordnum => $ordnum,
175                                                 basketno => $basketno,
176                                                 booksellerid => $booksellerid,
177                                                 suggestionid => $suggestionid,
178                                                 biblio => $biblio,
179                                                 biblioitemnumber => $data->{'biblioitemnumber'},
180                                                 itemtype => $data->{'itemtype'},
181                                                 discount => $booksellers[0]->{'discount'},
182                                                 listincgst => $booksellers[0]->{'listincgst'},
183                                                 listprice => $booksellers[0]->{'listprice'},
184                                                 gstreg => $booksellers[0]->{'gstreg'},
185                                                 invoiceinc => $booksellers[0]->{'invoiceincgst'},
186                                                 invoicedisc => $booksellers[0]->{'invoicedisc'},
187                                                 nocalc => $booksellers[0]->{'nocalc'},
188                                                 name => $booksellers[0]->{'name'},
189                                                 currency => $booksellers[0]->{'listprice'},
190                                                 gstrate => C4::Context->preference("gist") ,
191                                                 loop_currencies => \@loop_currency,
192                                                 orderexists => ($new eq 'yes')?0:1,
193                                                 title => $data->{'title'},
194                                                 author => $data->{'author'},
195                                                 copyrightdate => $data->{'copyrightdate'},
196                                                 CGIitemtype => $CGIitemtype,
197                                                 CGIbookfund => $CGIbookfund,
198                                                 isbn => $data->{'isbn'},
199                                                 seriestitle => $data->{'seriestitle'},
200                                                 quantity => $data->{'quantity'},
201                                                 listprice => $data->{'listprice'},
202                                                 rrp => $data->{'rrp'},
203                                                 invoice => $data->{'booksellerinvoicenumber'},
204                                                 ecost => $data->{'ecost'},
205                                                 notes => $data->{'notes'},
206                                                 publishercode => $data->{'publishercode'});
207
208 output_html_with_http_headers $input, $cookie, $template->output;