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 $gst = $bookseller->{gstrate} // C4::Context->preference("gist") // 0;
97 my $results = SearchOrder($ordernumber,$search);
99 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
101 template_name => "acqui/orderreceive.tmpl",
104 authnotrequired => 0,
105 flagsrequired => {acquisition => 'order_receive'},
110 my $count = scalar @$results;
111 # prepare the form for receiving
113 my $order = $results->[0];
115 # Check if ACQ framework exists
116 my $acq_fw = GetMarcStructure(1, 'ACQ');
118 $template->param('NoACQframework' => 1);
121 my $AcqCreateItem = C4::Context->preference('AcqCreateItem');
122 if ($AcqCreateItem eq 'receiving') {
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});
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};
158 $template->param(items => \@items);
161 if ( $order->{'unitprice'} == 0 ) {
162 $order->{'unitprice'} = '';
165 my $suggestion = GetSuggestionInfoFromBiblionumber($order->{'biblionumber'});
167 my $authorisedby = $order->{'authorisedby'};
168 my $member = GetMember( borrowernumber => $authorisedby );
170 my $budget = GetBudget( $order->{'budget_id'} );
173 AcqCreateItem => $AcqCreateItem,
175 biblionumber => $order->{'biblionumber'},
176 ordernumber => $order->{'ordernumber'},
177 biblioitemnumber => $order->{'biblioitemnumber'},
178 booksellerid => $order->{'booksellerid'},
181 name => $bookseller->{'name'},
182 date => format_date($order->{entrydate}),
183 title => $order->{'title'},
184 author => $order->{'author'},
185 copyrightdate => $order->{'copyrightdate'},
186 isbn => $order->{'isbn'},
187 seriestitle => $order->{'seriestitle'},
188 bookfund => $budget->{budget_name},
189 quantity => $order->{'quantity'},
190 quantityreceivedplus1 => $order->{'quantityreceived'} + 1,
191 quantityreceived => $order->{'quantityreceived'},
192 rrp => $order->{'rrp'},
193 ecost => sprintf( "%.2f",$order->{'ecost'}),
194 unitprice => sprintf( "%.2f",$order->{'unitprice'}),
195 memberfirstname => $member->{firstname} || "",
196 membersurname => $member->{surname} || "",
197 invoiceid => $invoice->{invoiceid},
198 invoice => $invoice->{invoicenumber},
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},
209 for ( my $i = 0 ; $i < $count ; $i++ ) {
210 my %line = %{ @$results[$i] };
212 $line{invoice} = $invoice->{invoicenumber};
213 $line{datereceived} = $datereceived->output();
214 $line{freight} = $freight;
216 $line{title} = @$results[$i]->{'title'};
217 $line{author} = @$results[$i]->{'author'};
218 $line{booksellerid} = $booksellerid;
224 booksellerid => $booksellerid,
225 invoiceid => $invoice->{invoiceid},
228 my $op = $input->param('op');
229 if ($op and $op eq 'edit'){
230 $template->param(edit => 1);
232 output_html_with_http_headers $input, $cookie, $template->output;