Bug Fixing : userid was blanked out in partial edit.
[koha.git] / acqui / parcel.pl
1 #!/usr/bin/perl
2
3 # $Id$
4
5 #script to recieve orders
6 #written by chris@katipo.co.nz 24/2/2000
7
8
9 # Copyright 2000-2002 Katipo Communications
10 #
11 # This file is part of Koha.
12 #
13 # Koha is free software; you can redistribute it and/or modify it under the
14 # terms of the GNU General Public License as published by the Free Software
15 # Foundation; either version 2 of the License, or (at your option) any later
16 # version.
17 #
18 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
19 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
20 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License along with
23 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
24 # Suite 330, Boston, MA  02111-1307 USA
25
26
27 =head1 NAME
28
29 parcel.pl
30
31 =head1 DESCRIPTION
32 This script shows all orders receipt or pending for a given supplier.
33 It allows to write an order as 'received' when he arrives.
34
35 =head1 CGI PARAMETERS
36
37 =over 4
38
39 =item supplierid
40 To know the supplier this script has to show orders.
41
42 =item code
43 is the bookseller invoice number.
44
45 =item freight
46
47
48 =item gst
49
50
51 =item datereceived
52 To filter the results list on this given date.
53
54 =back
55
56 =cut
57
58 use C4::Auth;
59 use C4::Acquisition;
60 use C4::Bookseller;
61 use C4::Biblio;
62 use CGI;
63 use C4::Output;
64 use C4::Date;
65
66 use strict;
67
68 my $input=new CGI;
69 my $supplierid=$input->param('supplierid');
70 my @booksellers=GetBookSeller($supplierid);
71 my $count = scalar @booksellers;
72
73 my $invoice=$input->param('invoice') || '';
74 my $freight=$input->param('freight');
75 my $gst=$input->param('gst');
76 my $datereceived=format_date_in_iso($input->param('datereceived')) || format_date(join "-",Date::Calc::Today());
77 my $code=$input->param('code');
78
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 @parcelitems=GetParcel($supplierid,$invoice,$datereceived);
88 my $countlines = scalar @parcelitems;
89
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     $parcelitems[$i]->{'unitprice'}+=0;
100     my %line;
101     if ($toggle==0){
102         $line{color}='#EEEEEE';
103         $toggle=1;
104     } else {
105             $line{color}='white';
106             $toggle=0;
107     }
108     %line = %{$parcelitems[$i]};
109     $line{invoice} = $invoice;
110     $line{gst} = $gst;
111     $line{total} = $total;
112     $line{supplierid} = $supplierid;
113     push @loop_received, \%line;
114     $totalprice+=$parcelitems[$i]->{'unitprice'};
115     $totalfreight+=$parcelitems[$i]->{'freight'};
116     $totalquantity+=$parcelitems[$i]->{'quantityreceived'};
117     $tototal+=$total;
118 }
119 my $pendingorders = GetPendingOrders($supplierid);
120 my $countpendings = scalar @$pendingorders;
121
122 # pending orders totals
123 my ($totalPunitprice,$totalPquantity,$totalPecost);
124
125 my @loop_orders = ();
126 for (my $i=0;$i<$countpendings;$i++){
127     my %line;
128     if ($toggle==0){
129         $line{color}='#EEEEEE';
130         $toggle=1;
131     } else {
132             $line{color}='white';
133             $toggle=0;
134     }
135     %line = %{$pendingorders->[$i]};
136     $totalPunitprice += $line{unitprice};
137     $totalPquantity +=$line{quantity};
138     $totalPecost += $line{ecost};
139     $line{ecost} = sprintf("%.2f",$line{ecost});
140     $line{unitprice} = sprintf("%.2f",$line{unitprice});
141     $line{invoice} = $invoice;
142     $line{gst} = $gst;
143     $line{total} = $total;
144     $line{supplierid} = $supplierid;
145     push @loop_orders, \%line;
146 }
147
148 $totalfreight=$freight;
149 $tototal=$tototal+$freight;
150
151 $template->param(invoice => $invoice,
152                 datereceived => $datereceived,
153                 formatteddatereceived => format_date($datereceived),
154                 name => $booksellers[0]->{'name'},
155                 supplierid => $supplierid,
156                 gst => $gst,
157                 freight => $freight,
158                 invoice => $invoice,
159                 countreceived => $countlines,
160                 loop_received => \@loop_received,
161                 countpending => $countpendings,
162                 loop_orders => \@loop_orders,
163                 totalprice => $totalprice,
164                 totalfreight => $totalfreight,
165                 totalquantity => $totalquantity,
166                 tototal => $tototal,
167                 gst => $gst,
168                 grandtot => $tototal+$gst,
169                 totalPunitprice => sprintf("%.2f",$totalPunitprice),
170                 totalPquantity => $totalPquantity,
171                 totalPecost => sprintf("%.2f",$totalPecost),
172                 );
173 output_html_with_http_headers $input, $cookie, $template->output;