rel_3_0 moved to HEAD
[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 C4::Output;
63 use CGI;
64 use C4::Interface::CGI::Output;
65 use C4::Date;
66
67 use strict;
68
69 my $input=new CGI;
70 my $supplierid=$input->param('supplierid');
71 my @booksellers=GetBookSeller($supplierid);
72 my $count = scalar @booksellers;
73
74 my $invoice=$input->param('invoice') || '';
75 my $freight=$input->param('freight');
76 my $gst=$input->param('gst');
77 my $datereceived=$input->param('datereceived') || format_date(join "-",Date::Calc::Today());
78 my $code=$input->param('code');
79
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 @parcelitems=GetParcel($supplierid,$invoice,$datereceived);
89 my $countlines = scalar @parcelitems;
90
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     $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;
108     }
109     %line = %{$parcelitems[$i]};
110     $line{invoice} = $invoice;
111     $line{gst} = $gst;
112     $line{total} = $total;
113     $line{supplierid} = $supplierid;
114     push @loop_received, \%line;
115     $totalprice+=$parcelitems[$i]->{'unitprice'};
116     $totalfreight+=$parcelitems[$i]->{'freight'};
117     $totalquantity+=$parcelitems[$i]->{'quantityreceived'};
118     $tototal+=$total;
119 }
120 my $pendingorders = GetPendingOrders($supplierid);
121 my $countpendings = scalar @$pendingorders;
122
123 my @loop_orders = ();
124 for (my $i=0;$i<$countpendings;$i++){
125     my %line;
126     if ($toggle==0){
127         $line{color}='#EEEEEE';
128         $toggle=1;
129     } else {
130             $line{color}='white';
131             $toggle=0;
132     }
133     %line = %{$pendingorders->[$i]};
134     $line{ecost} = sprintf("%.2f",$line{ecost});
135     $line{unitprice} = sprintf("%.2f",$line{unitprice});
136     $line{invoice} = $invoice;
137     $line{gst} = $gst;
138     $line{total} = $total;
139     $line{supplierid} = $supplierid;
140     push @loop_orders, \%line;
141 }
142
143 $totalfreight=$freight;
144 $tototal=$tototal+$freight;
145
146 $template->param(invoice => $invoice,
147                                                 datereceived => $datereceived,
148                                                 formatteddatereceived => format_date($datereceived),
149                         name => $booksellers[0]->{'name'},
150                         supplierid => $supplierid,
151                         gst => $gst,
152                         freight => $freight,
153                         invoice => $invoice,
154                         countreceived => $countlines,
155                         loop_received => \@loop_received,
156                         countpending => $countpendings,
157                         loop_orders => \@loop_orders,
158                         totalprice => $totalprice,
159                         totalfreight => $totalfreight,
160                         totalquantity => $totalquantity,
161                         tototal => $tototal,
162                         gst => $gst,
163                         grandtot => $tototal+$gst,
164                         intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
165         intranetstylesheet => C4::Context->preference("intranetstylesheet"),
166         IntranetNav => C4::Context->preference("IntranetNav"),
167                         );
168 output_html_with_http_headers $input, $cookie, $template->output;