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.
76 use C4::Interface::CGI::Output;
82 my $booksellerid = $input->param('booksellerid');
83 my $title = $input->param('title');
84 my $author = $input->param('author');
85 my $copyright = $input->param('copyright');
86 my @booksellers = GetBookSeller($booksellerid);
87 my $count = scalar @booksellers;
88 my $ordnum = $input->param('ordnum');
89 my $biblionumber = $input->param('biblionumber');
90 my $basketno = $input->param('basketno');
91 my $suggestionid = $input->param('suggestionid');
92 my $close = $input->param('close');
96 my $dbh = C4::Context->dbh;
98 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
100 template_name => "acqui/neworderempty.tmpl",
103 authnotrequired => 0,
104 flagsrequired => { acquisition => 1 },
108 my $me= C4::Context->userenv;
109 my $homebranch=$me->{'branch'} ;
112 my $discount= $booksellers[0]->{'discount'};
113 my $gstrate=C4::Context->preference('gist')*100;
114 if ( $ordnum eq '' ) { # create order
116 if ( $biblionumber ) {
117 my $record=XMLgetbibliohash($dbh,$biblionumber);
118 ###Error checking if a non existent biblionumber given manually
120 print $input->redirect("/cgi-bin/koha/acqui/basket.pl?supplierid=$booksellerid");
122 $data = XMLmarc2koha_onerecord($dbh,$record,"biblios");
123 }elsif($suggestionid){
124 $data = GetSuggestion($suggestionid);
126 if ( $data->{'title'} eq '' ) {
127 $data->{'title'} = $title;
128 $data->{'author'} = $author;
129 $data->{'copyrightdate'} = $copyright;
133 my $basket = GetBasket( $basketno);
134 my @orders=GetOrders($basketno);
137 purchaseordernumber => $orders[0]->{purchaseordernumber}, );
140 creationdate => format_date( $basket->{creationdate} ),
141 authorisedbyname => $basket->{authorisedbyname},);
143 my @datetoday = localtime();
144 my $date = (1900+$datetoday[5])."-".($datetoday[4]+1)."-". $datetoday[3];
146 creationdate => format_date($date),
147 authorisedbyname => $loggedinuser,);
149 }else { #modify order
150 $data = GetSingleOrder($ordnum);
151 $biblionumber = $data->{'biblionumber'};
152 #get basketno and suppleirno. too!
153 my $data2 = GetBasket( $data->{'basketno'} );
154 $basketno = $data->{'basketno'};
155 $booksellerid = $data2->{'booksellerid'};
156 $discount=$data->{'discount'};
157 $gstrate=$data->{'gst'} ;
158 $bookfundid =$data->{'bookfundid'};
159 my $aqbookfund=GetBookFund($data->{'bookfundid'});
160 $branch=$aqbookfund->{branchcode};
162 purchaseordernumber => $data->{purchaseordernumber},
163 creationdate => format_date( $data2->{creationdate} ),
164 authorisedbyname => $data2->{authorisedbyname},);
170 # get currencies (for exchange rates calcs if needed)
171 my @rates = GetCurrencies();
172 my $count = scalar @rates;
174 my @loop_currency = ();
175 for ( my $i = 0 ; $i < $count ; $i++ ) {
177 $line{currency} = $rates[$i]->{'currency'};
178 $line{rate} = $rates[$i]->{'rate'};
179 push @loop_currency, \%line;
186 # build branches list
187 my $branches = GetBranches;
189 foreach my $thisbranch ( sort keys %$branches ) {
190 my $selected=1 if $thisbranch eq $branch;
192 value => $thisbranch,
193 branchname => $branches->{$thisbranch}->{'branchname'},
194 selected=>$selected ,
196 push @branchloop, \%row;
198 $template->param( branchloop => \@branchloop );
200 # build bookfund list
205 my %select_bookfunds;
207 @bookfund = GetBookFunds($homebranch);
208 $count2 = scalar @bookfund;
210 for ( my $i = 0 ; $i < $count2 ; $i++ ) {
211 push @select_bookfund, $bookfund[$i]->{'bookfundid'};
212 $select_bookfunds{ $bookfund[$i]->{'bookfundid'} } =
213 $bookfund[$i]->{'bookfundname'};
214 if ($bookfund[$i]->{'bookfundid'} eq $bookfundid){
218 my $CGIbookfund = CGI::scrolling_list(
219 -name => 'bookfundid',
220 -values => \@select_bookfund,
221 -default => $data->{'bookfundid'},
222 -labels => \%select_bookfunds,
224 -selected =>$selbookfund,
231 $bookfundid = $data->{'bookfundid'};
232 $bookfundname = $select_bookfunds{$bookfundid};
236 my $CGIsort1 = buildCGIsort( "Asort1", "sort1", $data->{'sort1'} );
238 $template->param( CGIsort1 => $CGIsort1 );
241 $template->param( sort1 => $data->{'sort1'} );
244 my $CGIsort2 = buildCGIsort( "Asort2", "sort2", $data->{'sort2'} );
246 $template->param( CGIsort2 => $CGIsort2 );
249 $template->param( sort2 => $data->{'sort2'} );
256 $template->param( bibitemexists => "1" ) if $biblionumber;
259 $line{isbn} = $data->{'isbn'};
260 $line{itemtype} = $data->{'itemtype'};
261 $line{volumeddesc} = $data->{'volumeddesc'};
262 push( @bibitemloop, \%line );
264 $template->param( bibitemloop => \@bibitemloop );
271 bookfundid => $bookfundid,
272 bookfundname => $bookfundname
277 existing => $biblionumber,
279 basketno => $basketno,
280 booksellerid => $booksellerid,
281 suggestionid => $suggestionid,
282 biblionumber => $biblionumber,
283 itemtype => $data->{'itemtype'},
284 discount => $discount,
285 listincgst => $booksellers[0]->{'listincgst'},
286 listprice => $booksellers[0]->{'listprice'},
287 gstreg => $booksellers[0]->{'gstreg'},
288 invoiceinc => $booksellers[0]->{'invoiceincgst'},
289 invoicedisc => $booksellers[0]->{'invoicedisc'},
290 nocalc => $booksellers[0]->{'nocalc'},
291 name => $booksellers[0]->{'name'},
292 currency => $booksellers[0]->{'listprice'},
294 loop_currencies => \@loop_currency,
295 orderexists => ( $new eq 'yes' ) ? 0 : 1,
296 title => $data->{'title'},
297 author => $data->{'author'},
298 copyrightdate => $data->{'copyrightdate'},
299 CGIbookfund => $CGIbookfund,
300 isbn => $data->{'isbn'},
301 seriestitle => $data->{'seriestitle'},
302 quantity => $data->{'quantity'},
303 listprice => $data->{'listprice'},
304 rrp => $data->{'rrp'},
305 invoice => $data->{'booksellerinvoicenumber'},
306 ecost => $data->{'ecost'},
307 total =>$data->{'unitprice'}* $data->{'quantity'},
308 unitprice => $data->{'unitprice'},
309 gst => $data->{'ecost'}*$gstrate/100,
310 notes => $data->{'notes'},
311 publishercode => $data->{'publishercode'},
312 # donation => $donation
315 output_html_with_http_headers $input, $cookie, $template->output;