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($input->param('op') eq "delete" ){
91 if($input->param('biblionumber') and $input->param('ordernumber')){
92 DelOrder($input->param('biblionumber'), $input->param('ordernumber'));
93 print $input->redirect("/cgi-bin/koha/acqui/parcel.pl?supplierid=$supplierid&datereceived=" . $datereceived->output('iso'));
99 # If receiving error, report the error (coming from finishreceive.pl).
100 if (scalar(@rcv_err)) {
103 for my $err (@rcv_err) {
104 push @$error_loop, { "error_$err" => 1, barcode => $rcv_err_barcode[$cnt] };
109 error_loop => $error_loop,
113 my $cfstr = "%.2f"; # currency format string -- could get this from currency table.
114 my @parcelitems = GetParcel($supplierid, $invoice, $datereceived->output('iso'));
115 my $countlines = scalar @parcelitems;
117 my $totalfreight = 0;
118 my $totalquantity = 0;
121 my @loop_received = ();
123 for (my $i = 0 ; $i < $countlines ; $i++) {
125 #$total=($parcelitems[$i]->{'unitprice'} + $parcelitems[$i]->{'freight'}) * $parcelitems[$i]->{'quantityreceived'}; #weird, are the freight fees counted by book? (pierre)
126 $total = ($parcelitems[$i]->{'unitprice'}) * $parcelitems[$i]->{'quantityreceived'}; #weird, are the freight fees counted by book? (pierre)
127 $parcelitems[$i]->{'unitprice'} += 0;
129 %line = %{ $parcelitems[$i] };
130 $line{invoice} = $invoice;
132 $line{total} = sprintf($cfstr, $total);
133 $line{supplierid} = $supplierid;
134 push @loop_received, \%line;
135 $totalprice += $parcelitems[$i]->{'unitprice'};
136 $line{unitprice} = sprintf($cfstr, $parcelitems[$i]->{'unitprice'});
138 #double FIXME - totalfreight is redefined later.
140 # 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..
141 if ($i > 0 && $totalfreight != $parcelitems[$i]->{'freight'}) {
142 warn "FREIGHT CHARGE MISMATCH!!";
144 $totalfreight = $parcelitems[$i]->{'freight'};
145 $totalquantity += $parcelitems[$i]->{'quantityreceived'};
149 my $pendingorders = GetPendingOrders($supplierid, "", 1);
150 my $countpendings = scalar @$pendingorders;
152 # pending orders totals
153 my ($totalPunitprice, $totalPquantity, $totalPecost, $totalPqtyrcvd);
155 my @loop_orders = ();
156 for (my $i = 0 ; $i < $countpendings ; $i++) {
158 %line = %{ $pendingorders->[$i] };
159 $line{quantity} += 0;
160 $line{quantityreceived} += 0;
161 $line{unitprice} += 0;
162 $totalPunitprice += $line{unitprice};
163 $totalPquantity += $line{quantity};
164 $totalPqtyrcvd += $line{quantityreceived};
165 $totalPecost += $line{ecost};
166 $line{ecost} = sprintf("%.2f", $line{ecost});
167 $line{ordertotal} = sprintf("%.2f", $line{ecost} * $line{quantity});
168 $line{unitprice} = sprintf("%.2f", $line{unitprice});
169 $line{invoice} = $invoice;
171 $line{total} = $total;
172 $line{supplierid} = $supplierid;
173 $ordergrandtotal += $line{ecost} * $line{quantity};
174 push @loop_orders, \%line;
176 $freight = $totalfreight unless $freight;
178 #$totalfreight=$freight;
179 $tototal = $tototal + $freight;
183 datereceived => $datereceived->output('iso'),
184 invoicedatereceived => $datereceived->output('iso'),
185 formatteddatereceived => $datereceived->output(),
186 name => $bookseller->{'name'},
187 supplierid => $supplierid,
191 countreceived => $countlines,
192 loop_received => \@loop_received,
193 countpending => $countpendings,
194 loop_orders => \@loop_orders,
195 totalprice => sprintf($cfstr, $totalprice),
196 totalfreight => $totalfreight,
197 totalquantity => $totalquantity,
198 tototal => sprintf($cfstr, $tototal),
199 ordergrandtotal => sprintf($cfstr, $ordergrandtotal),
201 grandtot => sprintf($cfstr, $tototal + $gst),
202 totalPunitprice => sprintf("%.2f", $totalPunitprice),
203 totalPquantity => $totalPquantity,
204 totalPqtyrcvd => $totalPqtyrcvd,
205 totalPecost => sprintf("%.2f", $totalPecost),
207 output_html_with_http_headers $input, $cookie, $template->output;