added caching of results of GetMarcStructure
[koha.git] / acqui / parcel.pl
blobfb95c55e6432cc4b247bcb291d939faa9019c953
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 @booksellers=GetBookSeller($supplierid);
70 my $count = scalar @booksellers;
72 my $invoice=$input->param('invoice') || '';
73 my $freight=$input->param('freight');
74 my $gst=$input->param('gst');
75 my $datereceived = ($input->param('op') eq 'new') ? C4::Dates->new($input->param('datereceived'))
76 : C4::Dates->new($input->param('datereceived'), 'iso') ;
77 $datereceived = C4::Dates->new() unless $datereceived;
78 my $code=$input->param('code');
80 my ($template, $loggedinuser, $cookie)
81 = get_template_and_user({template_name => "acqui/parcel.tmpl",
82 query => $input,
83 type => "intranet",
84 authnotrequired => 0,
85 flagsrequired => {acquisition => 1},
86 debug => 1,
87 });
88 my $cfstr = "%.2f"; # currency format string -- could get this from currency table.
89 my @parcelitems=GetParcel($supplierid,$invoice,$datereceived->output('iso'));
90 my $countlines = scalar @parcelitems;
91 my $totalprice=0;
92 my $totalfreight=0;
93 my $totalquantity=0;
94 my $total;
95 my $tototal;
96 my $toggle;
97 my @loop_received = ();
98 for (my $i=0;$i<$countlines;$i++){
99 #$total=($parcelitems[$i]->{'unitprice'} + $parcelitems[$i]->{'freight'}) * $parcelitems[$i]->{'quantityreceived'}; #weird, are the freight fees counted by book? (pierre)
100 $total=($parcelitems[$i]->{'unitprice'} ) * $parcelitems[$i]->{'quantityreceived'}; #weird, are the freight fees counted by book? (pierre)
101 $parcelitems[$i]->{'unitprice'}+=0;
102 my %line;
103 if ($toggle==0){
104 $line{color}='#EEEEEE';
105 $toggle=1;
106 } else {
107 $line{color}='white';
108 $toggle=0;
110 %line = %{$parcelitems[$i]};
111 $line{invoice} = $invoice;
112 $line{gst} = $gst;
113 $line{total} = sprintf($cfstr,$total);
114 $line{supplierid} = $supplierid;
115 push @loop_received, \%line;
116 $totalprice+=$parcelitems[$i]->{'unitprice'};
117 $line{unitprice} = sprintf($cfstr,$parcelitems[$i]->{'unitprice'});
118 #double FIXME - totalfreight is redefined later.
120 # 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..
121 if ( $i > 0 && $totalfreight != $parcelitems[$i]->{'freight'}) {
122 warn "FREIGHT CHARGE MISMATCH!!";
124 $totalfreight=$parcelitems[$i]->{'freight'};
125 #$totalfreight+=$parcelitems[$i]->{'freight'};
126 $totalfreight=$parcelitems[$i]->{'freight'};
127 $totalquantity+=$parcelitems[$i]->{'quantityreceived'};
128 $tototal+=$total;
131 my $pendingorders = GetPendingOrders($supplierid);
132 my $countpendings = scalar @$pendingorders;
134 # pending orders totals
135 my ($totalPunitprice,$totalPquantity,$totalPecost, $totalPqtyrcvd);
136 my $ordergrandtotal;
137 my @loop_orders = ();
138 for (my $i=0;$i<$countpendings;$i++){
139 my %line;
140 if ($toggle==0){
141 $line{color}='#EEEEEE';
142 $toggle=1;
143 } else {
144 $line{color}='white';
145 $toggle=0;
147 %line = %{$pendingorders->[$i]};
148 $line{quantity}+=0;
149 $line{quantityreceived}+=0;
150 $line{unitprice}+=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;
159 $line{gst} = $gst;
160 $line{total} = $total;
161 $line{supplierid} = $supplierid;
162 $ordergrandtotal += $line{ecost}*$line{quantity};
163 push @loop_orders, \%line;
165 $freight = $totalfreight unless $freight;
166 $totalfreight=$freight;
167 $tototal=$tototal+$freight;
169 $template->param(invoice => $invoice,
170 datereceived => $datereceived->output('iso'),
171 invoicedatereceived => $datereceived->output('iso'),
172 formatteddatereceived => $datereceived->output(),
173 name => $booksellers[0]->{'name'},
174 supplierid => $supplierid,
175 gst => $gst,
176 freight => $freight,
177 invoice => $invoice,
178 countreceived => $countlines,
179 loop_received => \@loop_received,
180 countpending => $countpendings,
181 loop_orders => \@loop_orders,
182 totalprice => sprintf($cfstr,$totalprice),
183 totalfreight => $totalfreight,
184 totalquantity => $totalquantity,
185 tototal => sprintf($cfstr,$tototal),
186 ordergrandtotal => sprintf($cfstr,$ordergrandtotal),
187 gst => $gst,
188 grandtot => sprintf($cfstr,$tototal+$gst),
189 totalPunitprice => sprintf("%.2f",$totalPunitprice),
190 totalPquantity => $totalPquantity,
191 totalPqtyrcvd => $totalPqtyrcvd,
192 totalPecost => sprintf("%.2f",$totalPecost),
194 output_html_with_http_headers $input, $cookie, $template->output;