Bug 9002 - Remove Problematic Logic from Patron Messaging Preferences Form
[koha.git] / acqui / orderreceive.pl
blobfc79ccbba473342d79089fcb0451ab61e03b0936
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 invoiceid
43 the id of this invoice.
45 =item freight
47 =item biblio
49 The biblionumber of this order.
51 =item datereceived
53 =item catview
55 =item gst
57 =back
59 =cut
61 use strict;
62 use warnings;
64 use CGI;
65 use C4::Context;
66 use C4::Koha; # GetKohaAuthorisedValues GetItemTypes
67 use C4::Acquisition;
68 use C4::Auth;
69 use C4::Output;
70 use C4::Dates qw/format_date/;
71 use C4::Bookseller qw/ GetBookSellerFromId /;
72 use C4::Budgets qw/ GetBudget /;
73 use C4::Members;
74 use C4::Branch; # GetBranches
75 use C4::Items;
76 use C4::Biblio;
77 use C4::Suggestions;
80 my $input = new CGI;
82 my $dbh = C4::Context->dbh;
83 my $invoiceid = $input->param('invoiceid');
84 my $invoice = GetInvoice($invoiceid);
85 my $booksellerid = $invoice->{booksellerid};
86 my $freight = $invoice->{shipmentcost};
87 my $datereceived = $invoice->{shipmentdate};
88 my $ordernumber = $input->param('ordernumber');
90 $datereceived = $datereceived ? C4::Dates->new($datereceived, 'iso') : C4::Dates->new();
92 my $bookseller = GetBookSellerFromId($booksellerid);
93 my $results;
94 $results = SearchOrder($ordernumber) if $ordernumber;
96 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
98 template_name => "acqui/orderreceive.tmpl",
99 query => $input,
100 type => "intranet",
101 authnotrequired => 0,
102 flagsrequired => {acquisition => 'order_receive'},
103 debug => 1,
107 unless ( $results and @$results) {
108 output_html_with_http_headers $input, $cookie, $template->output;
109 exit;
112 # prepare the form for receiving
113 my $order = $results->[0];
115 # Check if ACQ framework exists
116 my $acq_fw = GetMarcStructure(1, 'ACQ');
117 unless($acq_fw) {
118 $template->param('NoACQframework' => 1);
121 my $AcqCreateItem = C4::Context->preference('AcqCreateItem');
122 if ($AcqCreateItem eq 'receiving') {
123 $template->param(
124 AcqCreateItemReceiving => 1,
125 UniqueItemFields => C4::Context->preference('UniqueItemFields'),
127 } elsif ($AcqCreateItem eq 'ordering') {
128 my $fw = ($acq_fw) ? 'ACQ' : '';
129 my @itemnumbers = GetItemnumbersFromOrder($order->{ordernumber});
130 my @items;
131 foreach (@itemnumbers) {
132 my $item = GetItem($_);
133 if($item->{homebranch}) {
134 $item->{homebranchname} = GetBranchName($item->{homebranch});
136 if($item->{holdingbranch}) {
137 $item->{holdingbranchname} = GetBranchName($item->{holdingbranch});
139 if(my $code = GetAuthValCode("items.notforloan", $fw)) {
140 $item->{notforloan} = GetKohaAuthorisedValueLib($code, $item->{notforloan});
142 if(my $code = GetAuthValCode("items.restricted", $fw)) {
143 $item->{restricted} = GetKohaAuthorisedValueLib($code, $item->{restricted});
145 if(my $code = GetAuthValCode("items.location", $fw)) {
146 $item->{location} = GetKohaAuthorisedValueLib($code, $item->{location});
148 if(my $code = GetAuthValCode("items.ccode", $fw)) {
149 $item->{collection} = GetKohaAuthorisedValueLib($code, $item->{ccode});
151 if(my $code = GetAuthValCode("items.materials", $fw)) {
152 $item->{materials} = GetKohaAuthorisedValueLib($code, $item->{materials});
154 my $itemtype = getitemtypeinfo($item->{itype});
155 $item->{itemtype} = $itemtype->{description};
156 push @items, $item;
158 $template->param(items => \@items);
161 $order->{quantityreceived} = '' if $order->{quantityreceived} == 0;
162 $order->{unitprice} = '' if $order->{unitprice} == 0;
164 my $rrp;
165 my $ecost;
166 my $unitprice;
167 if ( $bookseller->{listincgst} ) {
168 if ( $bookseller->{invoiceincgst} ) {
169 $rrp = $order->{rrp};
170 $ecost = $order->{ecost};
171 $unitprice = $order->{unitprice};
172 } else {
173 $rrp = $order->{rrp} / ( 1 + $order->{gstrate} );
174 $ecost = $order->{ecost} / ( 1 + $order->{gstrate} );
175 $unitprice = $order->{unitprice} / ( 1 + $order->{gstrate} );
177 } else {
178 if ( $bookseller->{invoiceincgst} ) {
179 $rrp = $order->{rrp} * ( 1 + $order->{gstrate} );
180 $ecost = $order->{ecost} * ( 1 + $order->{gstrate} );
181 $unitprice = $order->{unitprice} * ( 1 + $order->{gstrate} );
182 } else {
183 $rrp = $order->{rrp};
184 $ecost = $order->{ecost};
185 $unitprice = $order->{unitprice};
189 my $suggestion = GetSuggestionInfoFromBiblionumber($order->{biblionumber});
191 my $authorisedby = $order->{authorisedby};
192 my $member = GetMember( borrowernumber => $authorisedby );
194 my $budget = GetBudget( $order->{budget_id} );
196 $template->param(
197 AcqCreateItem => $AcqCreateItem,
198 count => 1,
199 biblionumber => $order->{'biblionumber'},
200 ordernumber => $order->{'ordernumber'},
201 biblioitemnumber => $order->{'biblioitemnumber'},
202 subscriptionid => $order->{subscriptionid},
203 booksellerid => $order->{'booksellerid'},
204 freight => $freight,
205 name => $bookseller->{'name'},
206 date => format_date($order->{entrydate}),
207 title => $order->{'title'},
208 author => $order->{'author'},
209 copyrightdate => $order->{'copyrightdate'},
210 isbn => $order->{'isbn'},
211 seriestitle => $order->{'seriestitle'},
212 bookfund => $budget->{budget_name},
213 quantity => $order->{'quantity'},
214 quantityreceivedplus1 => $order->{'quantityreceived'} + 1,
215 quantityreceived => $order->{'quantityreceived'},
216 rrp => sprintf( "%.2f", $rrp ),
217 ecost => sprintf( "%.2f", $ecost ),
218 memberfirstname => $member->{firstname} || "",
219 membersurname => $member->{surname} || "",
220 invoiceid => $invoice->{invoiceid},
221 invoice => $invoice->{invoicenumber},
222 datereceived => $datereceived->output(),
223 datereceived_iso => $datereceived->output('iso'),
224 notes => $order->{notes},
225 suggestionid => $suggestion->{suggestionid},
226 surnamesuggestedby => $suggestion->{surnamesuggestedby},
227 firstnamesuggestedby => $suggestion->{firstnamesuggestedby},
230 # regardless of the content of $unitprice e.g 0 or '' or any string will return in these cases 0.00
231 # and the 'IF' in the .tt will show 0.00 and not 'ecost' (see BZ 7129)
232 # So if $unitprice == 0 we don't create unitprice
233 if ( $unitprice != 0) {
234 $template->param(
235 unitprice => sprintf( "%.2f", $unitprice),
239 my $op = $input->param('op');
240 if ($op and $op eq 'edit'){
241 $template->param(edit => 1);
243 output_html_with_http_headers $input, $cookie, $template->output;