cleanup parcel.pl and tmpl
[koha_gimpoz] / acqui / parcel.pl
1 #!/usr/bin/perl
2
3
4 #script to recieve orders
5 #written by chris@katipo.co.nz 24/2/2000
6
7
8 # Copyright 2000-2002 Katipo Communications
9 #
10 # This file is part of Koha.
11 #
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.
16 #
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.
20 #
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
24
25
26 =head1 NAME
27
28 parcel.pl
29
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.
33
34 =head1 CGI PARAMETERS
35
36 =over 4
37
38 =item supplierid
39 To know the supplier this script has to show orders.
40
41 =item code
42 is the bookseller invoice number.
43
44 =item freight
45
46
47 =item gst
48
49
50 =item datereceived
51 To filter the results list on this given date.
52
53 =back
54
55 =cut
56
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/;
64
65 use strict;
66
67 my $input=new CGI;
68 my $supplierid=$input->param('supplierid');
69 my @booksellers=GetBookSeller($supplierid);
70 my $count = scalar @booksellers;
71
72 my $invoice=$input->param('invoice') || '';
73 my $freight=$input->param('freight');
74 my $gst=$input->param('gst');
75 my $datereceived=C4::Dates->new($input->param('datereceived'),'iso') || C4::Dates->new();
76 my $code=$input->param('code');
77
78 my ($template, $loggedinuser, $cookie)
79     = get_template_and_user({template_name => "acqui/parcel.tmpl",
80                  query => $input,
81                                  type => "intranet",
82                  authnotrequired => 0,
83                  flagsrequired => {acquisition => 1},
84                  debug => 1,
85 });
86 my $cfstr = "%.2f";  # currency format string -- could get this from currency table.
87 my @parcelitems=GetParcel($supplierid,$invoice,$datereceived->output('iso'));
88 my $countlines = scalar @parcelitems;
89 my $totalprice=0;
90 my $totalfreight=0;
91 my $totalquantity=0;
92 my $total;
93 my $tototal;
94 my $toggle;
95 my @loop_received = ();
96 for (my $i=0;$i<$countlines;$i++){
97     #$total=($parcelitems[$i]->{'unitprice'} + $parcelitems[$i]->{'freight'}) * $parcelitems[$i]->{'quantityreceived'};   #weird, are the freight fees counted by book? (pierre)
98     $total=($parcelitems[$i]->{'unitprice'}  ) * $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} = sprintf($cfstr,$total);
112     $line{supplierid} = $supplierid;
113     push @loop_received, \%line;
114     $totalprice+=$parcelitems[$i]->{'unitprice'};
115         $line{unitprice} = sprintf($cfstr,$parcelitems[$i]->{'unitprice'});
116 #double FIXME - totalfreight is redefined later.
117
118  # 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..
119      if ( $i > 0 && $totalfreight != $parcelitems[$i]->{'freight'}) {
120                warn "FREIGHT CHARGE MISMATCH!!";
121        }
122        $totalfreight=$parcelitems[$i]->{'freight'};
123     #$totalfreight+=$parcelitems[$i]->{'freight'};
124     $totalfreight=$parcelitems[$i]->{'freight'};
125     $totalquantity+=$parcelitems[$i]->{'quantityreceived'};
126     $tototal+=$total;
127 }
128
129 my $pendingorders = GetPendingOrders($supplierid);
130 my $countpendings = scalar @$pendingorders;
131
132 # pending orders totals
133 my ($totalPunitprice,$totalPquantity,$totalPecost, $totalPqtyrcvd);
134
135 my @loop_orders = ();
136 for (my $i=0;$i<$countpendings;$i++){
137     my %line;
138     if ($toggle==0){
139         $line{color}='#EEEEEE';
140         $toggle=1;
141     } else {
142             $line{color}='white';
143             $toggle=0;
144     }
145     %line = %{$pendingorders->[$i]};
146         $line{quantity}+=0;
147         $line{quantityreceived}+=0;
148         $line{unitprice}+=0;
149     $totalPunitprice += $line{unitprice};
150     $totalPquantity +=$line{quantity};
151     $totalPqtyrcvd +=$line{quantityreceived};
152     $totalPecost += $line{ecost};
153     $line{ecost} = sprintf("%.2f",$line{ecost});
154     $line{unitprice} = sprintf("%.2f",$line{unitprice});
155     $line{invoice} = $invoice;
156     $line{gst} = $gst;
157     $line{total} = $total;
158     $line{supplierid} = $supplierid;
159     push @loop_orders, \%line;
160 }
161 $freight = $totalfreight unless $freight;
162 $totalfreight=$freight;
163 $tototal=$tototal+$freight;
164
165 $template->param(invoice => $invoice,
166                 datereceived => $datereceived->output('iso'),
167                 formatteddatereceived => $datereceived->output(),
168                 name => $booksellers[0]->{'name'},
169                 supplierid => $supplierid,
170                 gst => $gst,
171                 freight => $freight,
172                 invoice => $invoice,
173                 countreceived => $countlines,
174                 loop_received => \@loop_received,
175                 countpending => $countpendings,
176                 loop_orders => \@loop_orders,
177                 totalprice => sprintf($cfstr,$totalprice),
178                 totalfreight => $totalfreight,
179                 totalquantity => $totalquantity,
180                 tototal => sprintf($cfstr,$tototal),
181                 gst => $gst,
182                 grandtot => sprintf($cfstr,$tototal+$gst),
183                 totalPunitprice => sprintf("%.2f",$totalPunitprice),
184                 totalPquantity => $totalPquantity,
185                 totalPqtyrcvd => $totalPqtyrcvd,
186                 totalPecost => sprintf("%.2f",$totalPecost),
187                 );
188 output_html_with_http_headers $input, $cookie, $template->output;