Bug 7772 - reports/bor_issues_top.pl: we need to exit(0) for plack
[koha.git] / acqui / orderreceive.pl
blob2b59698a71c5f11b9fbfca75beb436f449afbc75
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 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::Budgets qw/ GetBudget /;
74 use C4::Members;
75 use C4::Branch; # GetBranches
76 use C4::Items;
77 use C4::Biblio;
78 use C4::Suggestions;
81 my $input = new CGI;
83 my $dbh = C4::Context->dbh;
84 my $booksellerid = $input->param('booksellerid');
85 my $ordernumber = $input->param('ordernumber');
86 my $search = $input->param('receive');
87 my $invoice = $input->param('invoice');
88 my $freight = $input->param('freight');
89 my $datereceived = $input->param('datereceived');
92 $datereceived = $datereceived ? C4::Dates->new($datereceived, 'iso') : C4::Dates->new();
94 my $bookseller = GetBookSellerFromId($booksellerid);
95 my $input_gst = ($input->param('gst') eq '' ? undef : $input->param('gst'));
96 my $gst= $input_gst // $bookseller->{gstrate} // C4::Context->preference("gist") // 0;
97 my $results = SearchOrder($ordernumber,$search);
100 my $count = scalar @$results;
101 my $order = GetOrder($ordernumber);
104 my $date = @$results[0]->{'entrydate'};
106 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
108 template_name => "acqui/orderreceive.tmpl",
109 query => $input,
110 type => "intranet",
111 authnotrequired => 0,
112 flagsrequired => {acquisition => 'order_receive'},
113 debug => 1,
117 # prepare the form for receiving
118 if ( $count == 1 ) {
119 if (C4::Context->preference('AcqCreateItem') eq 'receiving') {
120 # Check if ACQ framework exists
121 my $marc = GetMarcStructure(1, 'ACQ');
122 unless($marc) {
123 $template->param('NoACQframework' => 1);
125 $template->param(
126 AcqCreateItemReceiving => 1,
127 UniqueItemFields => C4::Context->preference('UniqueItemFields'),
131 if ( @$results[0]->{'quantityreceived'} == 0 ) {
132 @$results[0]->{'quantityreceived'} = '';
134 if ( @$results[0]->{'unitprice'} == 0 ) {
135 @$results[0]->{'unitprice'} = '';
138 my $suggestion = GetSuggestionInfoFromBiblionumber(@$results[0]->{'biblionumber'});
140 my $authorisedby = @$results[0]->{'authorisedby'};
141 my $member = GetMember( borrowernumber => $authorisedby );
143 my $budget = GetBudget( @$results[0]->{'budget_id'} );
145 $template->param(
146 count => 1,
147 biblionumber => @$results[0]->{'biblionumber'},
148 ordernumber => @$results[0]->{'ordernumber'},
149 biblioitemnumber => @$results[0]->{'biblioitemnumber'},
150 booksellerid => @$results[0]->{'booksellerid'},
151 freight => $freight,
152 gst => $gst,
153 name => $bookseller->{'name'},
154 date => format_date($date),
155 title => @$results[0]->{'title'},
156 author => @$results[0]->{'author'},
157 copyrightdate => @$results[0]->{'copyrightdate'},
158 isbn => @$results[0]->{'isbn'},
159 seriestitle => @$results[0]->{'seriestitle'},
160 bookfund => $budget->{budget_name},
161 quantity => @$results[0]->{'quantity'},
162 quantityreceivedplus1 => @$results[0]->{'quantityreceived'} + 1,
163 quantityreceived => @$results[0]->{'quantityreceived'},
164 rrp => @$results[0]->{'rrp'},
165 ecost => @$results[0]->{'ecost'},
166 unitprice => @$results[0]->{'unitprice'},
167 memberfirstname => $member->{firstname} || "",
168 membersurname => $member->{surname} || "",
169 invoice => $invoice,
170 datereceived => $datereceived->output(),
171 datereceived_iso => $datereceived->output('iso'),
172 notes => $order->{notes},
173 suggestionid => $suggestion->{suggestionid},
174 surnamesuggestedby => $suggestion->{surnamesuggestedby},
175 firstnamesuggestedby => $suggestion->{firstnamesuggestedby},
178 else {
179 my @loop;
180 for ( my $i = 0 ; $i < $count ; $i++ ) {
181 my %line = %{ @$results[$i] };
183 $line{invoice} = $invoice;
184 $line{datereceived} = $datereceived->output();
185 $line{freight} = $freight;
186 $line{gst} = $gst;
187 $line{title} = @$results[$i]->{'title'};
188 $line{author} = @$results[$i]->{'author'};
189 $line{booksellerid} = $booksellerid;
190 push @loop, \%line;
193 $template->param(
194 loop => \@loop,
195 booksellerid => $booksellerid,
198 my $op = $input->param('op');
199 if ($op eq 'edit'){
200 $template->param(edit => 1);
202 output_html_with_http_headers $input, $cookie, $template->output;