fix for bug 2371: Change fine block message behavior...
[koha.git] / acqui / parcel.pl
blob58235548577c97160aecc514d89aa7d8d9923521
1 #!/usr/bin/perl
4 #script to recieve orders
5 #written by chris@katipo.co.nz 24/2/2000
8 # Copyright 2000-2002 Katipo Communications
10 # This file is part of Koha.
12 # Koha is free software; you can redistribute it and/or modify it under the
13 # terms of the GNU General Public License as published by the Free Software
14 # Foundation; either version 2 of the License, or (at your option) any later
15 # version.
17 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
18 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
19 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License along with
22 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
23 # Suite 330, Boston, MA 02111-1307 USA
26 =head1 NAME
28 parcel.pl
30 =head1 DESCRIPTION
31 This script shows all orders receipt or pending for a given supplier.
32 It allows to write an order as 'received' when he arrives.
34 =head1 CGI PARAMETERS
36 =over 4
38 =item supplierid
39 To know the supplier this script has to show orders.
41 =item code
42 is the bookseller invoice number.
44 =item freight
47 =item gst
50 =item datereceived
51 To filter the results list on this given date.
53 =back
55 =cut
57 use C4::Auth;
58 use C4::Acquisition;
59 use C4::Bookseller;
60 use C4::Biblio;
61 use CGI;
62 use C4::Output;
63 use C4::Dates qw/format_date format_date_in_iso/;
65 use strict;
67 my $input=new CGI;
68 my $supplierid=$input->param('supplierid');
69 my $bookseller=GetBookSellerFromId($supplierid);
71 my $invoice=$input->param('invoice') || '';
72 my $freight=$input->param('freight');
73 my $gst=$input->param('gst');
74 my $datereceived = ($input->param('op') eq 'new') ? C4::Dates->new($input->param('datereceived'))
75 : C4::Dates->new($input->param('datereceived'), 'iso') ;
76 $datereceived = C4::Dates->new() unless $datereceived;
77 my $code=$input->param('code');
79 my ($template, $loggedinuser, $cookie)
80 = get_template_and_user({template_name => "acqui/parcel.tmpl",
81 query => $input,
82 type => "intranet",
83 authnotrequired => 0,
84 flagsrequired => {acquisition => 1},
85 debug => 1,
86 });
87 my $cfstr = "%.2f"; # currency format string -- could get this from currency table.
88 my @parcelitems=GetParcel($supplierid,$invoice,$datereceived->output('iso'));
89 my $countlines = scalar @parcelitems;
90 my $totalprice=0;
91 my $totalfreight=0;
92 my $totalquantity=0;
93 my $total;
94 my $tototal;
95 my $toggle;
96 my @loop_received = ();
97 for (my $i=0;$i<$countlines;$i++){
98 #$total=($parcelitems[$i]->{'unitprice'} + $parcelitems[$i]->{'freight'}) * $parcelitems[$i]->{'quantityreceived'}; #weird, are the freight fees counted by book? (pierre)
99 $total=($parcelitems[$i]->{'unitprice'} ) * $parcelitems[$i]->{'quantityreceived'}; #weird, are the freight fees counted by book? (pierre)
100 $parcelitems[$i]->{'unitprice'}+=0;
101 my %line;
102 if ($toggle==0){
103 $line{color}='#EEEEEE';
104 $toggle=1;
105 } else {
106 $line{color}='white';
107 $toggle=0;
109 %line = %{$parcelitems[$i]};
110 $line{invoice} = $invoice;
111 $line{gst} = $gst;
112 $line{total} = sprintf($cfstr,$total);
113 $line{supplierid} = $supplierid;
114 push @loop_received, \%line;
115 $totalprice+=$parcelitems[$i]->{'unitprice'};
116 $line{unitprice} = sprintf($cfstr,$parcelitems[$i]->{'unitprice'});
117 #double FIXME - totalfreight is redefined later.
119 # 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..
120 if ( $i > 0 && $totalfreight != $parcelitems[$i]->{'freight'}) {
121 warn "FREIGHT CHARGE MISMATCH!!";
123 $totalfreight=$parcelitems[$i]->{'freight'};
124 $totalquantity+=$parcelitems[$i]->{'quantityreceived'};
125 $tototal+=$total;
128 my $pendingorders = GetPendingOrders($supplierid);
129 my $countpendings = scalar @$pendingorders;
131 # pending orders totals
132 my ($totalPunitprice,$totalPquantity,$totalPecost, $totalPqtyrcvd);
133 my $ordergrandtotal;
134 my @loop_orders = ();
135 for (my $i=0;$i<$countpendings;$i++){
136 my %line;
137 if ($toggle==0){
138 $line{color}='#EEEEEE';
139 $toggle=1;
140 } else {
141 $line{color}='white';
142 $toggle=0;
144 %line = %{$pendingorders->[$i]};
145 $line{quantity}+=0;
146 $line{quantityreceived}+=0;
147 $line{unitprice}+=0;
148 $totalPunitprice += $line{unitprice};
149 $totalPquantity +=$line{quantity};
150 $totalPqtyrcvd +=$line{quantityreceived};
151 $totalPecost += $line{ecost};
152 $line{ecost} = sprintf("%.2f",$line{ecost});
153 $line{ordertotal} = sprintf("%.2f",$line{ecost}*$line{quantity});
154 $line{unitprice} = sprintf("%.2f",$line{unitprice});
155 $line{invoice} = $invoice;
156 $line{gst} = $gst;
157 $line{total} = $total;
158 $line{supplierid} = $supplierid;
159 $ordergrandtotal += $line{ecost}*$line{quantity};
160 push @loop_orders, \%line;
162 $freight = $totalfreight unless $freight;
163 #$totalfreight=$freight;
164 $tototal=$tototal+$freight;
166 $template->param(invoice => $invoice,
167 datereceived => $datereceived->output('iso'),
168 invoicedatereceived => $datereceived->output('iso'),
169 formatteddatereceived => $datereceived->output(),
170 name => $bookseller->{'name'},
171 supplierid => $supplierid,
172 gst => $gst,
173 freight => $freight,
174 invoice => $invoice,
175 countreceived => $countlines,
176 loop_received => \@loop_received,
177 countpending => $countpendings,
178 loop_orders => \@loop_orders,
179 totalprice => sprintf($cfstr,$totalprice),
180 totalfreight => $totalfreight,
181 totalquantity => $totalquantity,
182 tototal => sprintf($cfstr,$tototal),
183 ordergrandtotal => sprintf($cfstr,$ordergrandtotal),
184 gst => $gst,
185 grandtot => sprintf($cfstr,$tototal+$gst),
186 totalPunitprice => sprintf("%.2f",$totalPunitprice),
187 totalPquantity => $totalPquantity,
188 totalPqtyrcvd => $totalPqtyrcvd,
189 totalPecost => sprintf("%.2f",$totalPecost),
191 output_html_with_http_headers $input, $cookie, $template->output;