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
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
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.
36 To know the supplier this script has to show orders.
39 is the bookseller invoice number.
48 To filter the results list on this given date.
60 use C4::Dates qw/format_date format_date_in_iso/;
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');
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",
85 flagsrequired => { acquisition => 1 },
90 # If receiving error, report the error (coming from finishreceive.pl).
91 if (scalar(@rcv_err)) {
94 for my $err (@rcv_err) {
95 push @$error_loop, { "error_$err" => 1, barcode => $rcv_err_barcode[$cnt] };
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;
108 my $totalfreight = 0;
109 my $totalquantity = 0;
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;
120 %line = %{ $parcelitems[$i] };
121 $line{invoice} = $invoice;
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'};
140 my $pendingorders = GetPendingOrders($supplierid);
141 my $countpendings = scalar @$pendingorders;
143 # pending orders totals
144 my ($totalPunitprice, $totalPquantity, $totalPecost, $totalPqtyrcvd);
146 my @loop_orders = ();
147 for (my $i = 0 ; $i < $countpendings ; $i++) {
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;
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;
174 datereceived => $datereceived->output('iso'),
175 invoicedatereceived => $datereceived->output('iso'),
176 formatteddatereceived => $datereceived->output(),
177 name => $bookseller->{'name'},
178 supplierid => $supplierid,
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),
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;