Bug 6679: Fixing 26 perlcritic violations in C4/Tags.pm
[koha.git] / acqui / orderreceive.pl
blob1ea0bd1bca3de045ecf5c4a62b5090fed0e83f18
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
21 # with Koha; if not, write to the Free Software Foundation, Inc.,
22 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 =head1 NAME
26 orderreceive.pl
28 =head1 DESCRIPTION
30 This script shows all order already receive and all pendings orders.
31 It permit to write a new order as 'received'.
33 =head1 CGI PARAMETERS
35 =over 4
37 =item booksellerid
39 to know on what supplier this script has to display receive order.
41 =item receive
43 =item invoice
45 the number of this invoice.
47 =item freight
49 =item biblio
51 The biblionumber of this order.
53 =item datereceived
55 =item catview
57 =item gst
59 =back
61 =cut
63 use strict;
64 use warnings;
66 use CGI;
67 use C4::Context;
68 use C4::Koha; # GetKohaAuthorisedValues GetItemTypes
69 use C4::Acquisition;
70 use C4::Auth;
71 use C4::Output;
72 use C4::Dates qw/format_date/;
73 use C4::Bookseller qw/ GetBookSellerFromId /;
74 use C4::Budgets qw/ GetBudget /;
75 use C4::Members;
76 use C4::Branch; # GetBranches
77 use C4::Items;
78 use C4::Biblio;
79 use C4::Suggestions;
82 my $input = new CGI;
84 my $dbh = C4::Context->dbh;
85 my $booksellerid = $input->param('booksellerid');
86 my $ordernumber = $input->param('ordernumber');
87 my $search = $input->param('receive');
88 my $invoice = $input->param('invoice');
89 my $freight = $input->param('freight');
90 my $datereceived = $input->param('datereceived');
93 $datereceived = $datereceived ? C4::Dates->new($datereceived, 'iso') : C4::Dates->new();
95 my $bookseller = GetBookSellerFromId($booksellerid);
96 my $input_gst = ($input->param('gst') eq '' ? undef : $input->param('gst'));
97 my $gst= $input_gst // $bookseller->{gstrate} // C4::Context->preference("gist") // 0;
98 my $results = SearchOrder($ordernumber,$search);
100 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
102 template_name => "acqui/orderreceive.tmpl",
103 query => $input,
104 type => "intranet",
105 authnotrequired => 0,
106 flagsrequired => {acquisition => 'order_receive'},
107 debug => 1,
111 my $count = scalar @$results;
112 # prepare the form for receiving
113 if ( $count == 1 ) {
114 my $order = $results->[0];
116 # Check if ACQ framework exists
117 my $acq_fw = GetMarcStructure(1, 'ACQ');
118 unless($acq_fw) {
119 $template->param('NoACQframework' => 1);
122 my $AcqCreateItem = C4::Context->preference('AcqCreateItem');
123 if ($AcqCreateItem eq 'receiving') {
124 $template->param(
125 AcqCreateItemReceiving => 1,
126 UniqueItemFields => C4::Context->preference('UniqueItemFields'),
128 } elsif ($AcqCreateItem eq 'ordering') {
129 my $fw = ($acq_fw) ? 'ACQ' : '';
130 my @itemnumbers = GetItemnumbersFromOrder($order->{ordernumber});
131 my @items;
132 foreach (@itemnumbers) {
133 my $item = GetItem($_);
134 if($item->{homebranch}) {
135 $item->{homebranchname} = GetBranchName($item->{homebranch});
137 if($item->{holdingbranch}) {
138 $item->{holdingbranchname} = GetBranchName($item->{holdingbranch});
140 if(my $code = GetAuthValCode("items.notforloan", $fw)) {
141 $item->{notforloan} = GetKohaAuthorisedValueLib($code, $item->{notforloan});
143 if(my $code = GetAuthValCode("items.restricted", $fw)) {
144 $item->{restricted} = GetKohaAuthorisedValueLib($code, $item->{restricted});
146 if(my $code = GetAuthValCode("items.location", $fw)) {
147 $item->{location} = GetKohaAuthorisedValueLib($code, $item->{location});
149 if(my $code = GetAuthValCode("items.ccode", $fw)) {
150 $item->{collection} = GetKohaAuthorisedValueLib($code, $item->{ccode});
152 if(my $code = GetAuthValCode("items.materials", $fw)) {
153 $item->{materials} = GetKohaAuthorisedValueLib($code, $item->{materials});
155 my $itemtype = getitemtypeinfo($item->{itype});
156 $item->{itemtype} = $itemtype->{description};
157 push @items, $item;
159 $template->param(items => \@items);
162 if ( $order->{'unitprice'} == 0 ) {
163 $order->{'unitprice'} = '';
166 my $suggestion = GetSuggestionInfoFromBiblionumber($order->{'biblionumber'});
168 my $authorisedby = $order->{'authorisedby'};
169 my $member = GetMember( borrowernumber => $authorisedby );
171 my $budget = GetBudget( $order->{'budget_id'} );
173 $template->param(
174 AcqCreateItem => $AcqCreateItem,
175 count => 1,
176 biblionumber => $order->{'biblionumber'},
177 ordernumber => $order->{'ordernumber'},
178 biblioitemnumber => $order->{'biblioitemnumber'},
179 booksellerid => $order->{'booksellerid'},
180 freight => $freight,
181 gst => $gst,
182 name => $bookseller->{'name'},
183 date => format_date($order->{entrydate}),
184 title => $order->{'title'},
185 author => $order->{'author'},
186 copyrightdate => $order->{'copyrightdate'},
187 isbn => $order->{'isbn'},
188 seriestitle => $order->{'seriestitle'},
189 bookfund => $budget->{budget_name},
190 quantity => $order->{'quantity'},
191 quantityreceivedplus1 => $order->{'quantityreceived'} + 1,
192 quantityreceived => $order->{'quantityreceived'},
193 rrp => $order->{'rrp'},
194 ecost => $order->{'ecost'},
195 unitprice => $order->{'unitprice'},
196 memberfirstname => $member->{firstname} || "",
197 membersurname => $member->{surname} || "",
198 invoice => $invoice,
199 datereceived => $datereceived->output(),
200 datereceived_iso => $datereceived->output('iso'),
201 notes => $order->{notes},
202 suggestionid => $suggestion->{suggestionid},
203 surnamesuggestedby => $suggestion->{surnamesuggestedby},
204 firstnamesuggestedby => $suggestion->{firstnamesuggestedby},
207 else {
208 my @loop;
209 for ( my $i = 0 ; $i < $count ; $i++ ) {
210 my %line = %{ @$results[$i] };
212 $line{invoice} = $invoice;
213 $line{datereceived} = $datereceived->output();
214 $line{freight} = $freight;
215 $line{gst} = $gst;
216 $line{title} = @$results[$i]->{'title'};
217 $line{author} = @$results[$i]->{'author'};
218 $line{booksellerid} = $booksellerid;
219 push @loop, \%line;
222 $template->param(
223 loop => \@loop,
224 booksellerid => $booksellerid,
227 my $op = $input->param('op');
228 if ($op and $op eq 'edit'){
229 $template->param(edit => 1);
231 output_html_with_http_headers $input, $cookie, $template->output;