Bug 4141 Reconcile 3.0.x and HEAD database updates for 3.2.0
[koha.git] / acqui / orderreceive.pl
bloba1e6fce4b99ffcb540441401901f87f32b3cc0b4
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
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 warnings; FIXME - Bug 2505
61 use CGI;
62 use C4::Context;
63 use C4::Koha; # GetKohaAuthorisedValues GetItemTypes
64 use C4::Acquisition;
65 use C4::Auth;
66 use C4::Output;
67 use C4::Dates qw/format_date/;
68 use C4::Bookseller;
69 use C4::Members;
70 use C4::Branch; # GetBranches
71 use C4::Items;
72 use C4::Biblio;
75 my $input = new CGI;
77 my $dbh = C4::Context->dbh;
78 my $supplierid = $input->param('supplierid');
79 my $ordernumber = $input->param('ordernumber');
80 my $search = $input->param('receive');
81 my $invoice = $input->param('invoice');
82 my $freight = $input->param('freight');
83 my $datereceived = $input->param('datereceived');
86 $datereceived = $datereceived ? C4::Dates->new($datereceived, 'iso') : C4::Dates->new();
88 my $bookseller = GetBookSellerFromId($supplierid);
89 my $gst= $input->param('gst') || $bookseller->{gstrate} || C4::Context->preference("gist") || 0;
90 my $results = SearchOrder($ordernumber,$search);
93 my $count = scalar @$results;
94 my $order = GetOrder($ordernumber);
97 my $date = @$results[0]->{'entrydate'};
99 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
101 template_name => "acqui/orderreceive.tmpl",
102 query => $input,
103 type => "intranet",
104 authnotrequired => 0,
105 flagsrequired => {acquisition => 'order_receive'},
106 debug => 1,
110 # prepare the form for receiving
111 if ( $count == 1 ) {
112 if (C4::Context->preference('AcqCreateItem') eq 'receiving') {
113 # prepare empty item form
114 my $cell = PrepareItemrecordDisplay('','','','ACQ');
115 unless ($cell) {
116 $cell = PrepareItemrecordDisplay('','','','');
117 $template->param('NoACQframework' => 1);
119 my @itemloop;
120 push @itemloop,$cell;
122 $template->param(items => \@itemloop);
125 if ( @$results[0]->{'quantityreceived'} == 0 ) {
126 @$results[0]->{'quantityreceived'} = '';
128 if ( @$results[0]->{'unitprice'} == 0 ) {
129 @$results[0]->{'unitprice'} = '';
131 $template->param(
132 count => 1,
133 biblionumber => @$results[0]->{'biblionumber'},
134 ordernumber => @$results[0]->{'ordernumber'},
135 biblioitemnumber => @$results[0]->{'biblioitemnumber'},
136 supplierid => @$results[0]->{'booksellerid'},
137 freight => $freight,
138 gst => $gst,
139 name => $bookseller->{'name'},
140 date => format_date($date),
141 title => @$results[0]->{'title'},
142 author => @$results[0]->{'author'},
143 copyrightdate => @$results[0]->{'copyrightdate'},
144 isbn => @$results[0]->{'isbn'},
145 seriestitle => @$results[0]->{'seriestitle'},
146 bookfund => @$results[0]->{'bookfundid'},
147 quantity => @$results[0]->{'quantity'},
148 quantityreceivedplus1 => @$results[0]->{'quantityreceived'} + 1,
149 quantityreceived => @$results[0]->{'quantityreceived'},
150 rrp => @$results[0]->{'rrp'},
151 ecost => @$results[0]->{'ecost'},
152 unitprice => @$results[0]->{'unitprice'},
153 invoice => $invoice,
154 datereceived => $datereceived->output(),
155 datereceived_iso => $datereceived->output('iso'),
156 notes => $order->{notes}
159 else {
160 my @loop;
161 for ( my $i = 0 ; $i < $count ; $i++ ) {
162 my %line = %{ @$results[$i] };
164 $line{invoice} = $invoice;
165 $line{datereceived} = $datereceived->output();
166 $line{freight} = $freight;
167 $line{gst} = $gst;
168 $line{title} = @$results[$i]->{'title'};
169 $line{author} = @$results[$i]->{'author'};
170 $line{supplierid} = $supplierid;
171 push @loop, \%line;
174 $template->param(
175 loop => \@loop,
176 supplierid => $supplierid,
179 my $op = $input->param('op');
180 if ($op eq 'edit'){
181 $template->param(edit => 1);
183 output_html_with_http_headers $input, $cookie, $template->output;