4 #script to recieve orders
5 #written by chris@katipo.co.nz 24/2/2000
7 # Copyright 2000-2002 Katipo Communications
9 # This file is part of Koha.
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
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.
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
29 This script shows all order already receive and all pendings orders.
30 It permit to write a new order as 'received'.
37 to know on what supplier this script has to display receive order.
42 the number of this invoice.
47 The biblionumber of this order.
60 # use warnings; # FIXME
63 use C4::Koha; # GetKohaAuthorisedValues GetItemTypes
67 use C4::Dates qw/format_date/;
70 use C4::Branch; # GetBranches
73 my $supplierid = $input->param('supplierid');
74 my $dbh = C4::Context->dbh;
76 my $search = $input->param('receive');
77 my $invoice = $input->param('invoice');
78 my $freight = $input->param('freight');
79 my $biblionumber = $input->param('biblionumber');
80 my $datereceived = C4::Dates->new($input->param('datereceived'),'iso') || C4::Dates->new();
81 my $catview = $input->param('catview');
82 my $gst = $input->param('gst');
84 my @results = SearchOrder( $search, $supplierid, $biblionumber, $catview );
85 my $count = scalar @results;
86 my $order = GetOrder($search);
88 my $bookseller = GetBookSellerFromId( $results[0]->{'booksellerid'} );
90 my $date = $results[0]->{'entrydate'};
92 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
94 template_name => "acqui/orderreceive.tmpl",
98 flagsrequired => { acquisition => 1 },
105 my (@itemtypesloop,@locationloop,@ccodeloop);
106 my $itemtypes = GetItemTypes;
107 foreach my $thisitemtype (sort {$itemtypes->{$a}->{'description'} cmp $itemtypes->{$b}->{'description'}} keys %$itemtypes) {
108 push @itemtypesloop, {
109 value => $thisitemtype,
110 description => $itemtypes->{$thisitemtype}->{'description'},
111 selected => ($thisitemtype eq $results[0]->{itemtype}), # ifdef itemtype @ bibliolevel, use it as default for item level.
114 my $locs = GetKohaAuthorisedValues( 'items.location' );
115 foreach my $thisloc (sort {$locs->{$a} cmp $locs->{$b}} keys %$locs) {
116 push @locationloop, {
118 description => $locs->{$thisloc},
121 my $ccodes = GetKohaAuthorisedValues( 'items.ccode' );
122 foreach my $thisccode (sort {$ccodes->{$a} cmp $ccodes->{$b}} keys %$ccodes) {
125 description => $ccodes->{$thisccode},
129 itemtypeloop => \@itemtypesloop,
130 locationloop => \@locationloop,
131 ccodeloop => \@ccodeloop,
132 branchloop => GetBranchesLoop($order->{branchcode}),
133 itype => C4::Context->preference('item-level_itypes'),
137 # See whether barcodes should be automatically allocated.
138 # FIXME : only incremental is implemented here, and it creates a race condition.
139 # FIXME : Same problems as other autoBarcode: breaks if any unexpected data is encountered (like alphanumerical barcode)
140 # FIXME : Fails when >1 items are added (via js).
141 if ( C4::Context->preference('autoBarcode') eq 'incremental' ) {
142 my $sth = $dbh->prepare("Select max(barcode) from items");
144 my $data = $sth->fetchrow_hashref;
145 $barcode = $results[0]->{'barcode'} + 1;
148 if ( $results[0]->{'quantityreceived'} == 0 ) {
149 $results[0]->{'quantityreceived'} = '';
151 if ( $results[0]->{'unitprice'} == 0 ) {
152 $results[0]->{'unitprice'} = '';
154 # $results[0]->{'copyrightdate'} = format_date( $results[0]->{'copyrightdate'} ); # this usu fails.
157 biblionumber => $results[0]->{'biblionumber'},
158 ordernumber => $results[0]->{'ordernumber'},
159 biblioitemnumber => $results[0]->{'biblioitemnumber'},
160 supplierid => $results[0]->{'booksellerid'},
161 catview => ( $catview ne 'yes' ? 1 : 0 ),
162 title => $results[0]->{'title'},
163 author => $results[0]->{'author'},
164 copyrightdate => $results[0]->{'copyrightdate'},
165 itemtype => $results[0]->{'itemtype'},
166 isbn => $results[0]->{'isbn'},
167 seriestitle => $results[0]->{'seriestitle'},
169 bookfund => $results[0]->{'bookfundid'},
170 quantity => $results[0]->{'quantity'},
171 quantityreceivedplus1 => $results[0]->{'quantityreceived'} + 1,
172 quantityreceived => $results[0]->{'quantityreceived'},
173 rrp => $results[0]->{'rrp'},
174 ecost => $results[0]->{'ecost'},
175 unitprice => $results[0]->{'unitprice'},
180 for ( my $i = 0 ; $i < $count ; $i++ ) {
181 my %line = %{ $results[$i] };
182 $line{title} = $results[$i]->{'title'};
183 $line{author} = $results[$i]->{'author'};
188 supplierid => $supplierid,
193 date => format_date($date),
194 datereceived => $datereceived->output(),
195 datereceived_iso => $datereceived->output('iso'),
197 name => $bookseller->{'name'},
202 output_html_with_http_headers $input, $cookie, $template->output;