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
21 # with Koha; if not, write to the Free Software Foundation, Inc.,
22 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
30 This script shows all order already receive and all pendings orders.
31 It permit to write a new order as 'received'.
39 to know on what supplier this script has to display receive order.
45 the id of this invoice.
51 The biblionumber of this order.
68 use C4::Koha; # GetKohaAuthorisedValues GetItemTypes
72 use C4::Dates qw/format_date/;
73 use C4::Bookseller qw/ GetBookSellerFromId /;
74 use C4::Budgets qw/ GetBudget /;
76 use C4::Branch; # GetBranches
84 my $dbh = C4::Context->dbh;
85 my $invoiceid = $input->param('invoiceid');
86 my $invoice = GetInvoice($invoiceid);
87 my $booksellerid = $invoice->{booksellerid};
88 my $freight = $invoice->{shipmentcost};
89 my $datereceived = $invoice->{shipmentdate};
90 my $ordernumber = $input->param('ordernumber');
91 my $search = $input->param('receive');
93 $datereceived = $datereceived ? C4::Dates->new($datereceived, 'iso') : C4::Dates->new();
95 my $bookseller = GetBookSellerFromId($booksellerid);
96 my $results = SearchOrder($ordernumber,$search);
98 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
100 template_name => "acqui/orderreceive.tmpl",
103 authnotrequired => 0,
104 flagsrequired => {acquisition => 'order_receive'},
109 my $count = scalar @$results;
110 # prepare the form for receiving
112 my $order = $results->[0];
114 # Check if ACQ framework exists
115 my $acq_fw = GetMarcStructure(1, 'ACQ');
117 $template->param('NoACQframework' => 1);
120 my $AcqCreateItem = C4::Context->preference('AcqCreateItem');
121 if ($AcqCreateItem eq 'receiving') {
123 AcqCreateItemReceiving => 1,
124 UniqueItemFields => C4::Context->preference('UniqueItemFields'),
126 } elsif ($AcqCreateItem eq 'ordering') {
127 my $fw = ($acq_fw) ? 'ACQ' : '';
128 my @itemnumbers = GetItemnumbersFromOrder($order->{ordernumber});
130 foreach (@itemnumbers) {
131 my $item = GetItem($_);
132 if($item->{homebranch}) {
133 $item->{homebranchname} = GetBranchName($item->{homebranch});
135 if($item->{holdingbranch}) {
136 $item->{holdingbranchname} = GetBranchName($item->{holdingbranch});
138 if(my $code = GetAuthValCode("items.notforloan", $fw)) {
139 $item->{notforloan} = GetKohaAuthorisedValueLib($code, $item->{notforloan});
141 if(my $code = GetAuthValCode("items.restricted", $fw)) {
142 $item->{restricted} = GetKohaAuthorisedValueLib($code, $item->{restricted});
144 if(my $code = GetAuthValCode("items.location", $fw)) {
145 $item->{location} = GetKohaAuthorisedValueLib($code, $item->{location});
147 if(my $code = GetAuthValCode("items.ccode", $fw)) {
148 $item->{collection} = GetKohaAuthorisedValueLib($code, $item->{ccode});
150 if(my $code = GetAuthValCode("items.materials", $fw)) {
151 $item->{materials} = GetKohaAuthorisedValueLib($code, $item->{materials});
153 my $itemtype = getitemtypeinfo($item->{itype});
154 $item->{itemtype} = $itemtype->{description};
157 $template->param(items => \@items);
160 $order->{quantityreceived} = '' if $order->{quantityreceived} == 0;
161 $order->{unitprice} = '' if $order->{unitprice} == 0;
166 if ( $bookseller->{listincgst} ) {
167 if ( $bookseller->{invoiceincgst} ) {
168 $rrp = $order->{rrp};
169 $ecost = $order->{ecost};
170 $unitprice = $order->{unitprice};
172 $rrp = $order->{rrp} / ( 1 + $order->{gstrate} );
173 $ecost = $order->{ecost} / ( 1 + $order->{gstrate} );
174 $unitprice = $order->{unitprice} / ( 1 + $order->{gstrate} );
177 if ( $bookseller->{invoiceincgst} ) {
178 $rrp = $order->{rrp} * ( 1 + $order->{gstrate} );
179 $ecost = $order->{ecost} * ( 1 + $order->{gstrate} );
180 $unitprice = $order->{unitprice} * ( 1 + $order->{gstrate} );
182 $rrp = $order->{rrp};
183 $ecost = $order->{ecost};
184 $unitprice = $order->{unitprice};
188 my $suggestion = GetSuggestionInfoFromBiblionumber($order->{biblionumber});
190 my $authorisedby = $order->{authorisedby};
191 my $member = GetMember( borrowernumber => $authorisedby );
193 my $budget = GetBudget( $order->{budget_id} );
196 AcqCreateItem => $AcqCreateItem,
198 biblionumber => $order->{'biblionumber'},
199 ordernumber => $order->{'ordernumber'},
200 biblioitemnumber => $order->{'biblioitemnumber'},
201 booksellerid => $order->{'booksellerid'},
203 gstrate => $order->{gstrate} || $bookseller->{gstrate} || C4::Context->preference("gist") || 0,
204 name => $bookseller->{'name'},
205 date => format_date($order->{entrydate}),
206 title => $order->{'title'},
207 author => $order->{'author'},
208 copyrightdate => $order->{'copyrightdate'},
209 isbn => $order->{'isbn'},
210 seriestitle => $order->{'seriestitle'},
211 bookfund => $budget->{budget_name},
212 quantity => $order->{'quantity'},
213 quantityreceivedplus1 => $order->{'quantityreceived'} + 1,
214 quantityreceived => $order->{'quantityreceived'},
215 rrp => sprintf( "%.2f", $rrp ),
216 ecost => sprintf( "%.2f", $ecost ),
217 memberfirstname => $member->{firstname} || "",
218 membersurname => $member->{surname} || "",
219 invoiceid => $invoice->{invoiceid},
220 invoice => $invoice->{invoicenumber},
221 datereceived => $datereceived->output(),
222 datereceived_iso => $datereceived->output('iso'),
223 notes => $order->{notes},
224 suggestionid => $suggestion->{suggestionid},
225 surnamesuggestedby => $suggestion->{surnamesuggestedby},
226 firstnamesuggestedby => $suggestion->{firstnamesuggestedby},
229 # regardless of the content of $unitprice e.g 0 or '' or any string will return in these cases 0.00
230 # and the 'IF' in the .tt will show 0.00 and not 'ecost' (see BZ 7129)
231 # So if $unitprice == 0 we don't create unitprice
232 if ( $unitprice != 0) {
234 unitprice => sprintf( "%.2f", $unitprice),
240 for ( my $i = 0 ; $i < $count ; $i++ ) {
241 my %line = %{ @$results[$i] };
243 $line{invoice} = $invoice->{invoicenumber};
244 $line{datereceived} = $datereceived->output();
245 $line{freight} = $freight;
246 $line{gstrate} = @$results[$i]->{'gstrate'} || $bookseller->{gstrate} || C4::Context->preference("gist") || 0;
247 $line{title} = @$results[$i]->{'title'};
248 $line{author} = @$results[$i]->{'author'};
249 $line{booksellerid} = $booksellerid;
255 booksellerid => $booksellerid,
256 invoiceid => $invoice->{invoiceid},
259 my $op = $input->param('op');
260 if ($op and $op eq 'edit'){
261 $template->param(edit => 1);
263 output_html_with_http_headers $input, $cookie, $template->output;