Removing duplicate email form field. Fixes Bug 3010.
[koha.git] / acqui / parcel.pl
blob62c77e4ed7d6f880c1e221ef448c121bfad0c53a
1 #!/usr/bin/perl
3 #script to receive orders
4 #written by chris@katipo.co.nz 24/2/2000
6 # Copyright 2000-2002 Katipo Communications
8 # This file is part of Koha.
10 # Koha is free software; you can redistribute it and/or modify it under the
11 # terms of the GNU General Public License as published by the Free Software
12 # Foundation; either version 2 of the License, or (at your option) any later
13 # version.
15 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
16 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
17 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License along with
20 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
21 # Suite 330, Boston, MA 02111-1307 USA
23 =head1 NAME
25 parcel.pl
27 =head1 DESCRIPTION
28 This script shows all orders receipt or pending for a given supplier.
29 It allows to write an order as 'received' when he arrives.
31 =head1 CGI PARAMETERS
33 =over 4
35 =item supplierid
36 To know the supplier this script has to show orders.
38 =item code
39 is the bookseller invoice number.
41 =item freight
44 =item gst
47 =item datereceived
48 To filter the results list on this given date.
50 =back
52 =cut
54 use C4::Auth;
55 use C4::Acquisition;
56 use C4::Bookseller;
57 use C4::Biblio;
58 use CGI;
59 use C4::Output;
60 use C4::Dates qw/format_date format_date_in_iso/;
62 use strict;
64 my $input = new CGI;
65 my $supplierid = $input->param('supplierid');
66 my $bookseller = GetBookSellerFromId($supplierid);
68 my $invoice = $input->param('invoice') || '';
69 my $freight = $input->param('freight');
70 my $gst = $input->param('gst');
71 my $datereceived =
72 ($input->param('op') eq 'new')
73 ? C4::Dates->new($input->param('datereceived'))
74 : C4::Dates->new($input->param('datereceived'), 'iso');
75 $datereceived = C4::Dates->new() unless $datereceived;
76 my $code = $input->param('code');
77 my @rcv_err = $input->param('error');
78 my @rcv_err_barcode = $input->param('error_bc');
80 my ($template, $loggedinuser, $cookie) = get_template_and_user(
81 { template_name => "acqui/parcel.tmpl",
82 query => $input,
83 type => "intranet",
84 authnotrequired => 0,
85 flagsrequired => { acquisition => 1 },
86 debug => 1,
90 # If receiving error, report the error (coming from finishreceive.pl).
91 if (scalar(@rcv_err)) {
92 my $cnt = 0;
93 my $error_loop;
94 for my $err (@rcv_err) {
95 push @$error_loop, { "error_$err" => 1, barcode => $rcv_err_barcode[$cnt] };
96 $cnt++;
98 $template->param(
99 receive_error => 1,
100 error_loop => $error_loop,
104 my $cfstr = "%.2f"; # currency format string -- could get this from currency table.
105 my @parcelitems = GetParcel($supplierid, $invoice, $datereceived->output('iso'));
106 my $countlines = scalar @parcelitems;
107 my $totalprice = 0;
108 my $totalfreight = 0;
109 my $totalquantity = 0;
110 my $total;
111 my $tototal;
112 my @loop_received = ();
114 for (my $i = 0 ; $i < $countlines ; $i++) {
116 #$total=($parcelitems[$i]->{'unitprice'} + $parcelitems[$i]->{'freight'}) * $parcelitems[$i]->{'quantityreceived'}; #weird, are the freight fees counted by book? (pierre)
117 $total = ($parcelitems[$i]->{'unitprice'}) * $parcelitems[$i]->{'quantityreceived'}; #weird, are the freight fees counted by book? (pierre)
118 $parcelitems[$i]->{'unitprice'} += 0;
119 my %line;
120 %line = %{ $parcelitems[$i] };
121 $line{invoice} = $invoice;
122 $line{gst} = $gst;
123 $line{total} = sprintf($cfstr, $total);
124 $line{supplierid} = $supplierid;
125 push @loop_received, \%line;
126 $totalprice += $parcelitems[$i]->{'unitprice'};
127 $line{unitprice} = sprintf($cfstr, $parcelitems[$i]->{'unitprice'});
129 #double FIXME - totalfreight is redefined later.
131 # FIXME - each order in a parcel holds the freight for the whole parcel. This means if you receive a parcel with items from multiple budgets, you'll see the freight charge in each budget..
132 if ($i > 0 && $totalfreight != $parcelitems[$i]->{'freight'}) {
133 warn "FREIGHT CHARGE MISMATCH!!";
135 $totalfreight = $parcelitems[$i]->{'freight'};
136 $totalquantity += $parcelitems[$i]->{'quantityreceived'};
137 $tototal += $total;
140 my $pendingorders = GetPendingOrders($supplierid);
141 my $countpendings = scalar @$pendingorders;
143 # pending orders totals
144 my ($totalPunitprice, $totalPquantity, $totalPecost, $totalPqtyrcvd);
145 my $ordergrandtotal;
146 my @loop_orders = ();
147 for (my $i = 0 ; $i < $countpendings ; $i++) {
148 my %line;
149 %line = %{ $pendingorders->[$i] };
150 $line{quantity} += 0;
151 $line{quantityreceived} += 0;
152 $line{unitprice} += 0;
153 $totalPunitprice += $line{unitprice};
154 $totalPquantity += $line{quantity};
155 $totalPqtyrcvd += $line{quantityreceived};
156 $totalPecost += $line{ecost};
157 $line{ecost} = sprintf("%.2f", $line{ecost});
158 $line{ordertotal} = sprintf("%.2f", $line{ecost} * $line{quantity});
159 $line{unitprice} = sprintf("%.2f", $line{unitprice});
160 $line{invoice} = $invoice;
161 $line{gst} = $gst;
162 $line{total} = $total;
163 $line{supplierid} = $supplierid;
164 $ordergrandtotal += $line{ecost} * $line{quantity};
165 push @loop_orders, \%line;
167 $freight = $totalfreight unless $freight;
169 #$totalfreight=$freight;
170 $tototal = $tototal + $freight;
172 $template->param(
173 invoice => $invoice,
174 datereceived => $datereceived->output('iso'),
175 invoicedatereceived => $datereceived->output('iso'),
176 formatteddatereceived => $datereceived->output(),
177 name => $bookseller->{'name'},
178 supplierid => $supplierid,
179 gst => $gst,
180 freight => $freight,
181 invoice => $invoice,
182 countreceived => $countlines,
183 loop_received => \@loop_received,
184 countpending => $countpendings,
185 loop_orders => \@loop_orders,
186 totalprice => sprintf($cfstr, $totalprice),
187 totalfreight => $totalfreight,
188 totalquantity => $totalquantity,
189 tototal => sprintf($cfstr, $tototal),
190 ordergrandtotal => sprintf($cfstr, $ordergrandtotal),
191 gst => $gst,
192 grandtot => sprintf($cfstr, $tototal + $gst),
193 totalPunitprice => sprintf("%.2f", $totalPunitprice),
194 totalPquantity => $totalPquantity,
195 totalPqtyrcvd => $totalPqtyrcvd,
196 totalPecost => sprintf("%.2f", $totalPecost),
198 output_html_with_http_headers $input, $cookie, $template->output;