removed duplicate call to C4::Context->marcfromkohafield
[koha.git] / acqui / orderreceive.pl
blob5e86eb53d0367da7b020a138b4b77147eaf4c675
1 #!/usr/bin/perl
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
14 # version.
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
24 =head1 NAME
26 orderreceive.pl
28 =head1 DESCRIPTION
29 This script shows all order already receive and all pendings orders.
30 It permit to write a new order as 'received'.
32 =head1 CGI PARAMETERS
34 =over 4
36 =item supplierid
37 to know on what supplier this script has to display receive order.
39 =item receive
41 =item invoice
42 the number of this invoice.
44 =item freight
46 =item biblio
47 The biblionumber of this order.
49 =item datereceived
51 =item catview
53 =item gst
55 =back
57 =cut
59 use strict;
60 use CGI;
61 use C4::Context;
62 use C4::Koha; # GetKohaAuthorisedValues GetItemTypes
63 use C4::Acquisition;
64 use C4::Auth;
65 use C4::Output;
66 use C4::Dates qw/format_date/;
67 use C4::Bookseller;
68 use C4::Members;
69 use C4::Branch; # GetBranches
71 my $input = new CGI;
72 my $supplierid = $input->param('supplierid');
73 my $dbh = C4::Context->dbh;
75 my $search = $input->param('receive');
76 my $invoice = $input->param('invoice');
77 my $freight = $input->param('freight');
78 my $biblionumber = $input->param('biblionumber');
79 my $datereceived = C4::Dates->new($input->param('datereceived'),'iso') || C4::Dates->new();
80 my $catview = $input->param('catview');
81 my $gst = $input->param('gst');
83 my @results = SearchOrder( $search, $supplierid, $biblionumber, $catview );
84 my $count = scalar @results;
86 my @booksellers = GetBookSeller( $results[0]->{'booksellerid'} );
88 my $date = $results[0]->{'entrydate'};
90 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
92 template_name => "acqui/orderreceive.tmpl",
93 query => $input,
94 type => "intranet",
95 authnotrequired => 0,
96 flagsrequired => { acquisition => 1 },
97 debug => 1,
100 $template->param($count);
102 if ( $count == 1 ) {
104 my (@itemtypesloop,@locationloop,@ccodeloop);
105 my $itemtypes = GetItemTypes;
106 foreach my $thisitemtype (sort keys %$itemtypes) {
107 my %row = (
108 value => $thisitemtype,
109 description => $itemtypes->{$thisitemtype}->{'description'},
110 selected => ($thisitemtype eq $results[0]->{itemtype}), # ifdef itemtype @ bibliolevel, use it as default for item level.
112 push @itemtypesloop, \%row;
115 my $locs = GetKohaAuthorisedValues( 'items.location' );
116 foreach my $thisloc (sort keys %$locs) {
117 my $row = {
118 value => $thisloc,
119 description => $locs->{$thisloc},
121 push @locationloop, $row;
123 my $ccodes= GetKohaAuthorisedValues( 'items.ccode' );
124 foreach my $thisccode (sort keys %$ccodes) {
125 push @ccodeloop, {
126 value => $thisccode,
127 description => $ccodes->{$thisccode},
130 $template->param(itemtypeloop => \@itemtypesloop ,
131 locationloop => \@locationloop,
132 ccodeloop => \@ccodeloop,
133 itype => C4::Context->preference('item-level_itypes'),
136 my $onlymine=C4::Context->preference('IndependantBranches') &&
137 C4::Context->userenv &&
138 C4::Context->userenv->{flags} !=1 &&
139 C4::Context->userenv->{branch};
140 my $branches = GetBranches($onlymine);
141 my @branchloop;
142 foreach my $thisbranch ( sort keys %$branches ) {
143 my %row = (
144 value => $thisbranch,
145 description => $branches->{$thisbranch}->{'branchname'},
147 push @branchloop, \%row;
150 my $auto_barcode = C4::Context->boolean_preference("autoBarcode") || 0;
152 # See whether barcodes should be automatically allocated.
153 # Defaults to 0, meaning "no".
154 my $barcode;
155 if ( $auto_barcode ) {
156 my $sth = $dbh->prepare("Select max(barcode) from items");
157 $sth->execute;
158 my $data = $sth->fetchrow_hashref;
159 $barcode = $results[0]->{'barcode'} + 1;
160 $sth->finish;
163 if ( $results[0]->{'quantityreceived'} == 0 ) {
164 $results[0]->{'quantityreceived'} = '';
166 if ( $results[0]->{'unitprice'} == 0 ) {
167 $results[0]->{'unitprice'} = '';
169 # $results[0]->{'copyrightdate'} = format_date( $results[0]->{'copyrightdate'} ); # this usu fails.
170 $template->param(
171 branchloop => \@branchloop,
172 count => 1,
173 biblionumber => $results[0]->{'biblionumber'},
174 ordernumber => $results[0]->{'ordernumber'},
175 biblioitemnumber => $results[0]->{'biblioitemnumber'},
176 supplierid => $results[0]->{'booksellerid'},
177 freight => $freight,
178 gst => $gst,
179 catview => ( $catview ne 'yes' ? 1 : 0 ),
180 name => $booksellers[0]->{'name'},
181 date => format_date($date),
182 title => $results[0]->{'title'},
183 author => $results[0]->{'author'},
184 copyrightdate => $results[0]->{'copyrightdate'},
185 itemtype => $results[0]->{'itemtype'},
186 isbn => $results[0]->{'isbn'},
187 seriestitle => $results[0]->{'seriestitle'},
188 barcode => $barcode,
189 bookfund => $results[0]->{'bookfundid'},
190 quantity => $results[0]->{'quantity'},
191 quantityreceivedplus1 => $results[0]->{'quantityreceived'} + 1,
192 quantityreceived => $results[0]->{'quantityreceived'},
193 rrp => $results[0]->{'rrp'},
194 ecost => $results[0]->{'ecost'},
195 unitprice => $results[0]->{'unitprice'},
196 invoice => $invoice,
197 datereceived => $datereceived->output(),
198 datereceived_iso => $datereceived->output('iso'),
201 else {
202 my @loop;
203 for ( my $i = 0 ; $i < $count ; $i++ ) {
204 my %line = %{ $results[$i] };
206 $line{invoice} = $invoice;
207 $line{datereceived} = $datereceived->output();
208 $line{freight} = $freight;
209 $line{gst} = $gst;
210 $line{title} = $results[$i]->{'title'};
211 $line{author} = $results[$i]->{'author'};
212 $line{supplierid} = $supplierid;
213 push @loop, \%line;
215 $template->param(
216 loop => \@loop,
217 date => format_date($date),
218 datereceived => $datereceived->output(),
219 name => $booksellers[0]->{'name'},
220 supplierid => $supplierid,
221 invoice => $invoice,
225 output_html_with_http_headers $input, $cookie, $template->output;