Fix for Bug 6408 - column alignment off on the patron categories admin
[koha.git] / acqui / orderreceive.pl
blob98ba544246117386b3a0383cd4154fcc6eb24704
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 supplierid
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; FIXME - Bug 2505
65 use CGI;
66 use C4::Context;
67 use C4::Koha; # GetKohaAuthorisedValues GetItemTypes
68 use C4::Acquisition;
69 use C4::Auth;
70 use C4::Output;
71 use C4::Dates qw/format_date/;
72 use C4::Bookseller qw/ GetBookSellerFromId /;
73 use C4::Members;
74 use C4::Branch; # GetBranches
75 use C4::Items;
76 use C4::Biblio;
79 my $input = new CGI;
81 my $dbh = C4::Context->dbh;
82 my $supplierid = $input->param('supplierid');
83 my $ordernumber = $input->param('ordernumber');
84 my $search = $input->param('receive');
85 my $invoice = $input->param('invoice');
86 my $freight = $input->param('freight');
87 my $datereceived = $input->param('datereceived');
90 $datereceived = $datereceived ? C4::Dates->new($datereceived, 'iso') : C4::Dates->new();
92 my $bookseller = GetBookSellerFromId($supplierid);
93 my $input_gst = ($input->param('gst') eq '' ? undef : $input->param('gst'));
94 my $gst= $input_gst // $bookseller->{gstrate} // C4::Context->preference("gist") // 0;
95 my $results = SearchOrder($ordernumber,$search);
98 my $count = scalar @$results;
99 my $order = GetOrder($ordernumber);
102 my $date = @$results[0]->{'entrydate'};
104 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
106 template_name => "acqui/orderreceive.tmpl",
107 query => $input,
108 type => "intranet",
109 authnotrequired => 0,
110 flagsrequired => {acquisition => 'order_receive'},
111 debug => 1,
115 # prepare the form for receiving
116 if ( $count == 1 ) {
117 if (C4::Context->preference('AcqCreateItem') eq 'receiving') {
118 # prepare empty item form
119 my $cell = PrepareItemrecordDisplay('','','','ACQ');
120 unless ($cell) {
121 $cell = PrepareItemrecordDisplay('','','','');
122 $template->param('NoACQframework' => 1);
124 my @itemloop;
125 push @itemloop,$cell;
127 $template->param(items => \@itemloop);
130 if ( @$results[0]->{'quantityreceived'} == 0 ) {
131 @$results[0]->{'quantityreceived'} = '';
133 if ( @$results[0]->{'unitprice'} == 0 ) {
134 @$results[0]->{'unitprice'} = '';
136 $template->param(
137 count => 1,
138 biblionumber => @$results[0]->{'biblionumber'},
139 ordernumber => @$results[0]->{'ordernumber'},
140 biblioitemnumber => @$results[0]->{'biblioitemnumber'},
141 supplierid => @$results[0]->{'booksellerid'},
142 freight => $freight,
143 gst => $gst,
144 name => $bookseller->{'name'},
145 date => format_date($date),
146 title => @$results[0]->{'title'},
147 author => @$results[0]->{'author'},
148 copyrightdate => @$results[0]->{'copyrightdate'},
149 isbn => @$results[0]->{'isbn'},
150 seriestitle => @$results[0]->{'seriestitle'},
151 bookfund => @$results[0]->{'bookfundid'},
152 quantity => @$results[0]->{'quantity'},
153 quantityreceivedplus1 => @$results[0]->{'quantityreceived'} + 1,
154 quantityreceived => @$results[0]->{'quantityreceived'},
155 rrp => @$results[0]->{'rrp'},
156 ecost => @$results[0]->{'ecost'},
157 unitprice => @$results[0]->{'unitprice'},
158 invoice => $invoice,
159 datereceived => $datereceived->output(),
160 datereceived_iso => $datereceived->output('iso'),
161 notes => $order->{notes}
164 else {
165 my @loop;
166 for ( my $i = 0 ; $i < $count ; $i++ ) {
167 my %line = %{ @$results[$i] };
169 $line{invoice} = $invoice;
170 $line{datereceived} = $datereceived->output();
171 $line{freight} = $freight;
172 $line{gst} = $gst;
173 $line{title} = @$results[$i]->{'title'};
174 $line{author} = @$results[$i]->{'author'};
175 $line{supplierid} = $supplierid;
176 push @loop, \%line;
179 $template->param(
180 loop => \@loop,
181 supplierid => $supplierid,
184 my $op = $input->param('op');
185 if ($op eq 'edit'){
186 $template->param(edit => 1);
188 output_html_with_http_headers $input, $cookie, $template->output;