3 #script to show display basket of orders
4 #written by chris@katipo.co.nz 24/2/2000
6 # Copyright 2000-2002 Katipo Communications
8 # This file is part of Koha.
10 # Koha is free software; you can redistribute it and/or modify it under the
11 # terms of the GNU General Public License as published by the Free Software
12 # Foundation; either version 2 of the License, or (at your option) any later
15 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
16 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
17 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License along with
20 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
21 # Suite 330, Boston, MA 02111-1307 USA
29 this script allows to create a new record to order it. This record shouldn't exist
37 the bookseller the librarian has to buy a new book.
40 the title of this new record.
43 the author of this new record.
46 the copyright of this new record.
49 the number of this order.
54 the basket number for this new order.
57 if this order comes from a suggestion.
79 use C4::Interface::CGI::Output;
80 use C4::Branch; # GetBranches
84 my $booksellerid = $input->param('booksellerid');
85 my $title = $input->param('title');
86 my $author = $input->param('author');
87 my $copyright = $input->param('copyright');
88 my @booksellers = GetBookSeller($booksellerid);
89 my $count = scalar @booksellers;
90 my $ordnum = $input->param('ordnum');
91 my $biblionumber = $input->param('biblionumber');
92 my $basketno = $input->param('basketno');
93 my $suggestionid = $input->param('suggestionid');
94 # my $donation = $input->param('donation');
95 my $close = $input->param('close');
98 my $dbh = C4::Context->dbh;
100 if ( $ordnum eq '' ) { # create order
103 # $ordnum=newordernum;
104 if ( $biblionumber && !$suggestionid ) {
105 $data = GetBiblioData($biblionumber);
108 # get suggestion fields if applicable. If it's a subscription renewal, then the biblio already exists
109 # otherwise, retrieve suggestion information.
112 $data = GetBiblioData($biblionumber);
115 $data = GetSuggestion($suggestionid);
120 $data = GetOrder($ordnum);
121 $biblionumber = $data->{'biblionumber'};
122 #get basketno and suppleirno. too!
123 my $data2 = GetBasket( $data->{'basketno'} );
124 $basketno = $data2->{'basketno'};
125 $booksellerid = $data2->{'booksellerid'};
128 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
130 template_name => "acqui/neworderempty.tmpl",
133 authnotrequired => 0,
134 flagsrequired => { acquisition => 1 },
139 # get currencies (for change rates calcs if needed)
140 my @rates = GetCurrencies();
141 $count = scalar @rates;
143 my @loop_currency = ();
144 for ( my $i = 0 ; $i < $count ; $i++ ) {
146 $line{currency} = $rates[$i]->{'currency'};
147 $line{rate} = $rates[$i]->{'rate'};
148 push @loop_currency, \%line;
151 # build itemtype list
152 my $itemtypes = GetItemTypes;
156 foreach my $thisitemtype (sort keys %$itemtypes) {
157 push @itemtypesloop, $itemtypes->{$thisitemtype}->{'itemtype'};
158 $itemtypesloop{$itemtypes->{$thisitemtype}->{'itemtype'}} = $itemtypes->{$thisitemtype}->{'description'};
161 my $CGIitemtype = CGI::scrolling_list(
163 -values => \@itemtypesloop,
164 -default => $data->{'itemtype'},
165 -labels => \%itemtypesloop,
171 # build branches list
172 my $onlymine=C4::Context->preference('IndependantBranches') &&
173 C4::Context->userenv &&
174 C4::Context->userenv->{flags}!=1 &&
175 C4::Context->userenv->{branch};
176 my $branches = GetBranches($onlymine);
178 foreach my $thisbranch ( sort keys %$branches ) {
180 value => $thisbranch,
181 branchname => $branches->{$thisbranch}->{'branchname'},
183 push @branchloop, \%row;
185 $template->param( branchloop => \@branchloop );
187 # build bookfund list
188 my ($flags, $homebranch) = GetFlagsAndBranchFromBorrower($loggedinuser);
193 my %select_bookfunds;
195 @bookfund = GetBookFunds($homebranch);
196 $count2 = scalar @bookfund;
198 for ( my $i = 0 ; $i < $count2 ; $i++ ) {
199 push @select_bookfund, $bookfund[$i]->{'bookfundid'};
200 $select_bookfunds{ $bookfund[$i]->{'bookfundid'} } =
201 $bookfund[$i]->{'bookfundname'};
203 my $CGIbookfund = CGI::scrolling_list(
205 -values => \@select_bookfund,
206 -default => $data->{'bookfundid'},
207 -labels => \%select_bookfunds,
216 $bookfundid = $data->{'bookfundid'};
217 $bookfundname = $select_bookfunds{$bookfundid};
221 my $CGIsort1 = buildCGIsort( "Asort1", "sort1", $data->{'sort1'} );
223 $template->param( CGIsort1 => $CGIsort1 );
226 $template->param( sort1 => $data->{'sort1'} );
229 my $CGIsort2 = buildCGIsort( "Asort2", "sort2", $data->{'sort2'} );
231 $template->param( CGIsort2 => $CGIsort2 );
234 $template->param( sort2 => $data->{'sort2'} );
239 #do a biblioitems lookup on bib
240 my @bibitems = GetBiblioItemByBiblioNumber($biblionumber);
241 my $bibitemscount = scalar @bibitems;
243 if ( $bibitemscount > 0 ) {
244 # warn "NEWBIBLIO: bibitems for $biblio exists\n";
248 for ( my $i = 0 ; $i < $bibitemscount ; $i++ ) {
250 $line{biblioitemnumber} = $bibitems[$i]->{'biblioitemnumber'};
251 $line{isbn} = $bibitems[$i]->{'isbn'};
252 $line{itemtype} = $bibitems[$i]->{'itemtype'};
253 $line{volumeddesc} = $bibitems[$i]->{'volumeddesc'};
254 push( @bibitemloop, \%line );
256 $template->param( bibitemloop => \@bibitemloop );
258 $template->param( bibitemexists => "1" );
264 bookfundid => $bookfundid,
265 bookfundname => $bookfundname
270 existing => $biblionumber,
272 basketno => $basketno,
273 booksellerid => $booksellerid,
274 suggestionid => $suggestionid,
275 biblionumber => $biblionumber,
276 biblioitemnumber => $data->{'biblioitemnumber'},
277 itemtype => $data->{'itemtype'},
278 discount => $booksellers[0]->{'discount'},
279 listincgst => $booksellers[0]->{'listincgst'},
280 listprice => $booksellers[0]->{'listprice'},
281 gstreg => $booksellers[0]->{'gstreg'},
282 invoiceinc => $booksellers[0]->{'invoiceincgst'},
283 invoicedisc => $booksellers[0]->{'invoicedisc'},
284 nocalc => $booksellers[0]->{'nocalc'},
285 name => $booksellers[0]->{'name'},
286 currency => $booksellers[0]->{'listprice'},
287 gstrate => C4::Context->preference("gist"),
288 loop_currencies => \@loop_currency,
289 orderexists => ( $new eq 'yes' ) ? 0 : 1,
290 title => $data->{'title'},
291 author => $data->{'author'},
292 copyrightdate => $data->{'copyrightdate'},
293 CGIitemtype => $CGIitemtype,
294 CGIbookfund => $CGIbookfund,
295 isbn => $data->{'isbn'},
296 seriestitle => $data->{'seriestitle'},
297 quantity => $data->{'quantity'},
298 listprice => $data->{'listprice'},
299 rrp => $data->{'rrp'},
300 total => $data->{ecost}*$data->{quantity},
301 invoice => $data->{'booksellerinvoicenumber'},
302 ecost => $data->{'ecost'},
303 notes => $data->{'notes'},
304 publishercode => $data->{'publishercode'},
305 # donation => $donation
308 output_html_with_http_headers $input, $cookie, $template->output;