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::Branch; # GetBranches
83 my $booksellerid = $input->param('booksellerid');
84 my $title = $input->param('title');
85 my $author = $input->param('author');
86 my $copyright = $input->param('copyright');
87 my @booksellers = GetBookSeller($booksellerid);
88 my $count = scalar @booksellers;
89 my $ordnum = $input->param('ordnum');
90 my $biblionumber = $input->param('biblionumber');
91 my $basketno = $input->param('basketno');
92 my $suggestionid = $input->param('suggestionid');
93 # my $donation = $input->param('donation');
94 my $close = $input->param('close');
97 my $dbh = C4::Context->dbh;
99 if ( $ordnum eq '' ) { # create order
102 # $ordnum=newordernum;
103 if ( $biblionumber && !$suggestionid ) {
104 $data = GetBiblioData($biblionumber);
107 # get suggestion fields if applicable. If it's a subscription renewal, then the biblio already exists
108 # otherwise, retrieve suggestion information.
111 $data = GetBiblioData($biblionumber);
114 $data = GetSuggestion($suggestionid);
119 $data = GetOrder($ordnum);
120 $biblionumber = $data->{'biblionumber'};
121 #get basketno and suppleirno. too!
122 my $data2 = GetBasket( $data->{'basketno'} );
123 $basketno = $data2->{'basketno'};
124 $booksellerid = $data2->{'booksellerid'};
127 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
129 template_name => "acqui/neworderempty.tmpl",
132 authnotrequired => 0,
133 flagsrequired => { acquisition => 1 },
138 # get currencies (for change rates calcs if needed)
139 my @rates = GetCurrencies();
140 $count = scalar @rates;
142 my @loop_currency = ();
143 for ( my $i = 0 ; $i < $count ; $i++ ) {
145 $line{currency} = $rates[$i]->{'currency'};
146 $line{rate} = $rates[$i]->{'rate'};
147 push @loop_currency, \%line;
150 # build itemtype list
151 my $itemtypes = GetItemTypes;
155 foreach my $thisitemtype (sort keys %$itemtypes) {
156 push @itemtypesloop, $itemtypes->{$thisitemtype}->{'itemtype'};
157 $itemtypesloop{$itemtypes->{$thisitemtype}->{'itemtype'}} = $itemtypes->{$thisitemtype}->{'description'};
160 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 $borrower= GetMember($loggedinuser);
189 my ( $flags, $homebranch )= ($borrower->{'flags'},$borrower->{'branchcode'});
194 my %select_bookfunds;
196 @bookfund = GetBookFunds($homebranch);
197 $count2 = scalar @bookfund;
199 for ( my $i = 0 ; $i < $count2 ; $i++ ) {
200 push @select_bookfund, $bookfund[$i]->{'bookfundid'};
201 $select_bookfunds{ $bookfund[$i]->{'bookfundid'} } =
202 $bookfund[$i]->{'bookfundname'};
204 my $CGIbookfund = CGI::scrolling_list(
207 -values => \@select_bookfund,
208 -default => $data->{'bookfundid'},
209 -labels => \%select_bookfunds,
218 $bookfundid = $data->{'bookfundid'};
219 $bookfundname = $select_bookfunds{$bookfundid};
223 my $CGIsort1 = buildCGIsort( "Asort1", "sort1", $data->{'sort1'} );
225 $template->param( CGIsort1 => $CGIsort1 );
228 $template->param( sort1 => $data->{'sort1'} );
231 my $CGIsort2 = buildCGIsort( "Asort2", "sort2", $data->{'sort2'} );
233 $template->param( CGIsort2 => $CGIsort2 );
236 $template->param( sort2 => $data->{'sort2'} );
241 #do a biblioitems lookup on bib
242 my @bibitems = GetBiblioItemByBiblioNumber($biblionumber);
243 my $bibitemscount = scalar @bibitems;
245 if ( $bibitemscount > 0 ) {
246 # warn "NEWBIBLIO: bibitems for $biblio exists\n";
250 for ( my $i = 0 ; $i < $bibitemscount ; $i++ ) {
252 $line{biblioitemnumber} = $bibitems[$i]->{'biblioitemnumber'};
253 $line{isbn} = $bibitems[$i]->{'isbn'};
254 $line{itemtype} = $bibitems[$i]->{'itemtype'};
255 $line{volumeddesc} = $bibitems[$i]->{'volumeddesc'};
256 push( @bibitemloop, \%line );
258 $template->param( bibitemloop => \@bibitemloop );
260 $template->param( bibitemexists => "1" );
266 bookfundid => $bookfundid,
267 bookfundname => $bookfundname
272 existing => $biblionumber,
274 basketno => $basketno,
275 booksellerid => $booksellerid,
276 suggestionid => $suggestionid,
277 biblionumber => $biblionumber,
278 biblioitemnumber => $data->{'biblioitemnumber'},
279 itemtype => $data->{'itemtype'},
280 discount => $booksellers[0]->{'discount'},
281 listincgst => $booksellers[0]->{'listincgst'},
282 listprice => $booksellers[0]->{'listprice'},
283 gstreg => $booksellers[0]->{'gstreg'},
284 invoiceinc => $booksellers[0]->{'invoiceincgst'},
285 invoicedisc => $booksellers[0]->{'invoicedisc'},
286 nocalc => $booksellers[0]->{'nocalc'},
287 name => $booksellers[0]->{'name'},
288 currency => $booksellers[0]->{'listprice'},
289 gstrate => C4::Context->preference("gist"),
290 loop_currencies => \@loop_currency,
291 orderexists => ( $new eq 'yes' ) ? 0 : 1,
292 title => $data->{'title'},
293 author => $data->{'author'},
294 copyrightdate => $data->{'copyrightdate'},
295 CGIitemtype => $CGIitemtype,
296 CGIbookfund => $CGIbookfund,
297 isbn => $data->{'isbn'},
298 seriestitle => $data->{'seriestitle'},
299 quantity => $data->{'quantity'},
300 listprice => $data->{'listprice'},
301 rrp => $data->{'rrp'},
302 total => $data->{ecost}*$data->{quantity},
303 invoice => $data->{'booksellerinvoicenumber'},
304 ecost => $data->{'ecost'},
305 notes => $data->{'notes'},
306 publishercode => $data->{'publishercode'},
307 # donation => $donation
310 output_html_with_http_headers $input, $cookie, $template->output;