3 #script to recieve orders
6 # Copyright 2000-2002 Katipo Communications
7 # Copyright 2008-2009 BibLibre SARL
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
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 with
21 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
22 # Suite 330, Boston, MA 02111-1307 USA
29 This script shows all orders receipt or pending for a given supplier.
30 It allows to write an order as 'received' when he arrives.
37 To know the supplier this script has to show orders.
40 is the bookseller invoice number.
49 To filter the results list on this given date.
61 use C4::Dates qw/format_date format_date_in_iso/;
66 my $supplierid=$input->param('supplierid');
67 my $bookseller=GetBookSellerFromId($supplierid);
69 my $invoice=$input->param('invoice') || '';
70 my $freight=$input->param('freight');
71 my $gst= $input->param('gst') || $bookseller->{gstrate} || C4::Context->preference("gist") || 0;
72 my $datereceived = ($input->param('op') eq 'new') ? C4::Dates->new($input->param('datereceived'))
73 : C4::Dates->new($input->param('datereceived'), 'iso') ;
74 $datereceived = C4::Dates->new() unless $datereceived;
75 my $code = $input->param('code');
76 my @rcv_err = $input->param('error');
77 my @rcv_err_barcode = $input->param('error_bc');
79 my ($template, $loggedinuser, $cookie)
80 = get_template_and_user({template_name => "acqui/parcel.tmpl",
84 flagsrequired => {acquisition => 'order_receive'},
88 # If receiving error, report the error (coming from finishrecieve.pl(sic)).
89 if( scalar(@rcv_err) ) {
92 for my $err (@rcv_err) {
93 push @$error_loop, { "error_$err" => 1 , barcode => $rcv_err_barcode[$cnt] };
96 $template->param( receive_error => 1 ,
97 error_loop => $error_loop,
101 my $cfstr = "%.2f"; # currency format string -- could get this from currency table.
102 my @parcelitems = GetParcel($supplierid, $invoice, $datereceived->output('iso'));
103 my $countlines = scalar @parcelitems;
105 my $totalfreight = 0;
106 my $totalquantity = 0;
109 my @loop_received = ();
111 for (my $i = 0 ; $i < $countlines ; $i++) {
113 #$total=($parcelitems[$i]->{'unitprice'} + $parcelitems[$i]->{'freight'}) * $parcelitems[$i]->{'quantityreceived'}; #weird, are the freight fees counted by book? (pierre)
114 $total = ($parcelitems[$i]->{'unitprice'}) * $parcelitems[$i]->{'quantityreceived'}; #weird, are the freight fees counted by book? (pierre)
115 $parcelitems[$i]->{'unitprice'} += 0;
117 %line = %{ $parcelitems[$i] };
118 $line{invoice} = $invoice;
120 $line{total} = sprintf($cfstr, $total);
121 $line{supplierid} = $supplierid;
122 push @loop_received, \%line;
123 $totalprice += $parcelitems[$i]->{'unitprice'};
124 $line{unitprice} = sprintf($cfstr, $parcelitems[$i]->{'unitprice'});
126 #double FIXME - totalfreight is redefined later.
128 # 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..
129 if ($i > 0 && $totalfreight != $parcelitems[$i]->{'freight'}) {
130 warn "FREIGHT CHARGE MISMATCH!!";
132 $totalfreight = $parcelitems[$i]->{'freight'};
133 $totalquantity += $parcelitems[$i]->{'quantityreceived'};
137 my $pendingorders = GetPendingOrders($supplierid);
138 my $countpendings = scalar @$pendingorders;
140 # pending orders totals
141 my ($totalPunitprice, $totalPquantity, $totalPecost, $totalPqtyrcvd);
143 my @loop_orders = ();
144 for (my $i = 0 ; $i < $countpendings ; $i++) {
146 %line = %{$pendingorders->[$i]};
148 $line{quantrem} = $line{quantity} - $line{quantityreceived};
149 $line{quantityreceived}+=0;
151 $totalPunitprice += $line{unitprice};
152 $totalPquantity +=$line{quantity};
153 $totalPqtyrcvd +=$line{quantityreceived};
154 $totalPecost += $line{ecost};
155 $line{ecost} = sprintf("%.2f",$line{ecost});
156 $line{ordertotal} = sprintf("%.2f",$line{ecost}*$line{quantity});
157 $line{unitprice} = sprintf("%.2f",$line{unitprice});
158 $line{invoice} = $invoice;
160 $line{total} = $total;
161 $line{supplierid} = $supplierid;
162 $ordergrandtotal += $line{ecost} * $line{quantity};
163 push @loop_orders, \%line;
165 $freight = $totalfreight unless $freight;
167 #$totalfreight=$freight;
168 $tototal = $tototal + $freight;
172 datereceived => $datereceived->output('iso'),
173 invoicedatereceived => $datereceived->output('iso'),
174 formatteddatereceived => $datereceived->output(),
175 name => $bookseller->{'name'},
176 supplierid => $supplierid,
180 countreceived => $countlines,
181 loop_received => \@loop_received,
182 countpending => $countpendings,
183 loop_orders => \@loop_orders,
184 totalprice => sprintf($cfstr, $totalprice),
185 totalfreight => $totalfreight,
186 totalquantity => $totalquantity,
187 tototal => sprintf($cfstr, $tototal),
188 ordergrandtotal => sprintf($cfstr, $ordergrandtotal),
190 grandtot => sprintf($cfstr, $tototal + $gst),
191 totalPunitprice => sprintf("%.2f", $totalPunitprice),
192 totalPquantity => $totalPquantity,
193 totalPqtyrcvd => $totalPqtyrcvd,
194 totalPecost => sprintf("%.2f", $totalPecost),
196 output_html_with_http_headers $input, $cookie, $template->output;