5 #script to recieve orders
6 #written by chris@katipo.co.nz 24/2/2000
8 # Copyright 2000-2002 Katipo Communications
10 # This file is part of Koha.
12 # Koha is free software; you can redistribute it and/or modify it under the
13 # terms of the GNU General Public License as published by the Free Software
14 # Foundation; either version 2 of the License, or (at your option) any later
17 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
18 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
19 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License along with
22 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
23 # Suite 330, Boston, MA 02111-1307 USA
32 use C4::Interface::CGI::Output;
40 my $supplierid = $input->param('supplierid');
41 my $dbh = C4::Context->dbh;
43 my $search = $input->param('recieve');
44 my $invoice = $input->param('invoice');
45 my $freight = $input->param('freight');
46 my $biblio = $input->param('biblio');
47 my $biblioitem = $input->param('bibitem'); # added my mason 20060324
48 my $catview = $input->param('catview');
49 my $gst = $input->param('gst');
50 my $noitems = $input->param('items');
51 my $set_barcode = $input->param('set_barcode');
52 my $library_name = C4::Context->preference("LibraryName");
54 my ( $count, @results ) =
55 ordersearch( $search, $supplierid, $biblio, $catview );
57 if ( $library_name eq "Horowhenua Library Trust" && $count > 1 ) {
58 ( $count, @results ) = ordersearch( $search, $biblio, $catview );
62 #warn "COUNT = $count";
63 #warn "C:$count for ordersearch($search,$supplierid,$biblio,$catview);";
65 my ( $count2, @booksellers );
67 ( $count2, @booksellers ) = bookseller( $results[0]->{'booksellerid'} );
70 ( $count2, @booksellers ) = bookseller($supplierid);
73 #warn Dumper @results;
75 my $date = $results[0]->{'entrydate'};
76 my $exchange = getcurrency( $booksellers[0]->{'listprice'} );
78 my $no_multi = $input->param('no_multi');
80 #-------------------------
82 # bugzilla: http://bugzilla.katipo.co.nz/show_bug.cgi?id=3916 , mason.
83 # ok lets do a lookup to see how many orders exist for a bibitem, if there are >1,
84 # then we need to display them to the user so they can choose, because the system cant
85 # work it out, as there are no itemnumbers stored in the aqorders records :(
89 #warn "MASON BIBITEM= $biblioitem";
90 my $query2 = " select * from aqorders where biblioitemnumber =?";
91 my $sth2 = $dbh->prepare($query2);
92 $sth2->execute($biblioitem);
93 while ( my $data2 = $sth2->fetchrow_hashref ) {
97 #warn Dumper "DATA2:", $data2->{'basketno'};
98 my $query3 = " select * from aqbasket where basketno =?";
99 my $sth3 = $dbh->prepare($query3);
100 $sth3->execute( $data2->{'basketno'} );
101 my $data3 = $sth3->fetchrow_hashref;
104 $data2->{'booksellerid'} = $data3->{'booksellerid'};
105 push( @results2, $data2 );
109 #warn Dumper @results2;
112 my $result_count = scalar(@results2);
114 #warn "MULTI REESULT $result_count";
115 #warn "NO_MULTI = $no_multi";
116 my ( $template, $loggedinuser, $cookie );
118 if ( $result_count > 1 && $no_multi != 1 ) {
120 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
122 template_name => "acqui/acquire-multi-order.tmpl",
125 authnotrequired => 0,
126 flagsrequired => { acquisition => 1 },
131 #warn "IN MULTI IF \n";
133 # cool, now lets shove the results into a loop
134 for ( my $i = 0 ; $i < $result_count ; $i++ ) {
137 $line{booksellerid} = $results2[$i]->{'booksellerid'};
138 $line{biblionumber} = $results2[$i]->{'biblionumber'};
139 $line{biblioitemnumber} = $results2[$i]->{'biblioitemnumber'};
140 $line{ordernumber} = $results2[$i]->{'ordernumber'};
141 $line{title} = $results2[$i]->{'title'};
142 $line{booksellerinvoicenumber} =
143 $results[$i]->{'booksellerinvoicenumber'};
144 $line{datereceived} = $results2[$i]->{'datereceived'};
145 $line{entrydate} = $results2[$i]->{'entrydate'};
146 $line{quantity} = $results2[$i]->{'quantity'};
147 $line{listprice} = $results2[$i]->{'listprice'};
148 $line{freight} = $results2[$i]->{'freight'};
149 $line{unitprice} = $results2[$i]->{'unitprice'};
150 $line{quantityreceived} = $results2[$i]->{'quantityreceived'};
151 $line{supplierreference} = $results2[$i]->{'supplierreference'};
152 $line{purchaseordernumber} = $results2[$i]->{'purchaseordernumber'};
153 $line{basketno} = $results2[$i]->{'basketno'};
154 $line{timestamp} = $results2[$i]->{'timestamp'};
155 $line{rrp} = $results2[$i]->{'rrp'};
156 $line{budgetdate} = $results2[$i]->{'budgetdate'};
159 #warn "LOOPING", $results2[$i]->{'ordernumber'};
166 biblioitem => $biblioitem,
170 elsif ( $count == 1 ) {
172 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
175 template_name => "acqui/acquire.tmpl",
178 authnotrequired => 0,
179 flagsrequired => { acquisition => 1 },
186 my $itemtype2 = $results[0]->{'itemtype'};
188 if ( $results[0]->{'freight'} > 0 ) {
189 $freightperitem = $results[0]->{'freight'};
192 if ( $noitems > 0 ) {
193 $freightperitem = $freight / $noitems;
196 $freightperitem = sprintf( "%.2f", $freightperitem );
200 "Select itemtype,description from itemtypes order by description");
205 $itemtypes{''} = "Please choose";
207 while ( my ( $value, $lib ) = $sth->fetchrow_array ) {
208 push @itemtype, $value;
209 $itemtypes{$value} = $lib;
212 my $CGIitemtype = CGI::scrolling_list(
214 -values => \@itemtype,
215 -default => $results[0]->{'itemtype'},
216 -labels => \%itemtypes,
225 my ( $count2, @branches ) = branches();
226 for ( my $i = 0 ; $i < $count2 ; $i++ ) {
227 push @select_branch, $branches[$i]->{'branchcode'}; #
228 $select_branches{ $branches[$i]->{'branchcode'} } =
229 $branches[$i]->{'branchname'};
231 my $CGIbranch = CGI::scrolling_list(
233 -values => \@select_branch,
234 -default => $results[0]->{'branchcode'},
235 -labels => \%select_branches,
240 my $auto_barcode = C4::Context->boolean_preference("autoBarcode") || 0;
241 #warn "ACQIRE AUTO BARCODE = $auto_barcode";
243 # See whether barcodes should be automatically allocated.
244 # Defaults to 0, meaning "no".
246 if ( $auto_barcode eq '1' ) {
247 $sth = $dbh->prepare("Select max(barcode) barcode from items");
250 while ( my $data = $sth->fetchrow_hashref ) {
251 push( @data_results, $data );
253 $barcode = @data_results[0]->{'barcode'} + 1;
254 #warn 'moo', @data_results[0]->{'barcode'};
255 #warn "auto Barcode = $barcode";
257 #$barcode = sprintf( "%.0f", $barcode );
258 #warn "auto Barcode = $barcode";
268 my %select_bookfunds;
269 ( $count2, @bookfund ) = bookfunds();
270 for ( my $i = 0 ; $i < $count2 ; $i++ ) {
271 push @select_bookfund, $bookfund[$i]->{'bookfundid'};
272 $select_bookfunds{ $bookfund[$i]->{'bookfundid'} } =
273 $bookfund[$i]->{'bookfundname'};
275 my $CGIbookfund = CGI::scrolling_list(
277 -values => \@select_bookfund,
278 -default => $results[0]->{'bookfundid'},
279 -labels => \%select_bookfunds,
284 if ( $results[0]->{'quantityreceived'} == 0 ) {
285 $results[0]->{'quantityreceived'} = '';
287 if ( $results[0]->{'unitprice'} == 0 ) {
288 $results[0]->{'unitprice'} = '';
291 #warn Dumper( $results[0] );
294 biblionumber => $results[0]->{'biblionumber'},
295 ordernumber => $results[0]->{'ordernumber'},
296 biblioitemnumber => $results[0]->{'biblioitemnumber'},
297 supplierid => $results[0]->{'booksellerid'},
302 # catview => ($catview ne 'yes'?1:0),
304 name => $booksellers[0]->{'name'},
305 date => format_date($date),
306 title => $results[0]->{'title'},
307 author => $results[0]->{'author'},
308 copyrightdate => $results[0]->{'copyrightdate'},
310 # copyrightdate => format_date($results[0]->{'copyrightdate'}),
311 # itemtype => $results[0]->{'itemtype'},
312 CGIbranch => $CGIbranch,
313 CGIbookfund => $CGIbookfund,
314 CGIitemtype => $CGIitemtype,
315 isbn => $results[0]->{'isbn'},
316 seriestitle => $results[0]->{'seriestitle'},
317 volinf => $results[0]->{'volumeddesc'},
319 set_barcode => $set_barcode,
321 # bookfund => $results[0]->{'bookfundid'},
322 quantity => $results[0]->{'quantity'},
323 quantityreceived => $results[0]->{'quantityreceived'},
324 rrp => $results[0]->{'rrp'},
325 ecost => $results[0]->{'ecost'},
326 unitprice => $results[0]->{'unitprice'},
328 notes => $results[0]->{'notes'},
329 freightperitem => $freightperitem,
330 nocalc => $booksellers[0]->{'nocalc'},
331 invoicedisc => $booksellers[0]->{'invoicedisc'},
332 invoiceinc => $booksellers[0]->{'invoiceincgst'},
333 applygst => $booksellers[0]->{'gstreg'},
334 discount => $booksellers[0]->{'discount'},
336 supplierid => $booksellers[0]->{'id'},
338 currency => $exchange->{'rate'},
339 basketno => $results[0]->{'basketno'},
340 booksellerinvoicenumber => $results[0]->{'booksellerinvoicenumber'},
341 itemtype2 => $itemtype2, #added by mason BGZLA:3823
345 #warn Dumper $booksellers[0];
346 #warn Dumper $results[0];
348 # MASON: this is a little fix, to ensure that the 'create new biblio group' checkbox # ONLY appears in acquire.tmpl for biblioitems that already have 1 OR MORE items
350 my $biblioitemnumber = $results[0]->{'biblioitemnumber'};
351 my $error = &countitems($biblioitemnumber);
353 #warn "MASON: number of items for $biblioitemnumber = $error";
355 $template->param( createbibitem => 'YES' );
359 else { # whats this loop for ??? mason
360 # why this loop when acqui
362 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
365 template_name => "acqui/searchresult.tmpl",
368 authnotrequired => 0,
369 flagsrequired => { acquisition => 1 },
375 for ( my $i = 0 ; $i < $count ; $i++ ) {
377 $line{isbn} = $results[$i]->{'isbn'};
378 $line{basketno} = $results[$i]->{'basketno'};
379 $line{quantity} = $results[$i]->{'quantity'};
380 $line{quantityrecieved} = $results[$i]->{'quantityreceived'};
381 $line{ordernumber} = $results[$i]->{'ordernumber'};
382 $line{biblionumber} = $results[$i]->{'biblionumber'};
383 $line{invoice} = $invoice;
384 $line{freight} = $freight;
386 $line{title} = $results[$i]->{'title'};
387 $line{author} = $results[$i]->{'author'};
388 $line{vol} = $results[$i]->{'volume'};
389 $line{volinf} = $results[$i]->{'volumeddesc'};
390 $line{supplierid} = $supplierid;
391 $line{noitems} = $noitems;
396 date => format_date($date),
397 name => $booksellers[0]->{'name'},
398 supplierid => $supplierid,
402 warn "MASON: search= $search";
406 output_html_with_http_headers $input, $cookie, $template->output;Chris