fix bad link.
[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::Database;
66 use HTML::Template;
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('code') || '';
75 my $freight=$input->param('freight');
76 my $gst=$input->param('gst');
77 my $date=$input->param('datereceived');
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
89 my @parcelitems=GetParcel($supplierid,$invoice,$date);
90 my $countlines = scalar @parcelitems;
91
92 my $totalprice=0;
93 my $totalfreight=0;
94 my $totalquantity=0;
95 my $total;
96 my $tototal;
97 my $toggle;
98 my @loop_received = ();
99 for (my $i=0;$i<$countlines;$i++){
100     $total=($parcelitems[$i]->{'unitprice'} + $parcelitems[$i]->{'freight'}) * $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;
109 }
110     $line{basketno} = $parcelitems[$i]->{'basketno'};
111     $line{isbn} = $parcelitems[$i]->{'isbn'};
112     $line{ordernumber} = $parcelitems[$i]->{'ordernumber'};
113     $line{biblionumber} = $parcelitems[$i]->{'biblionumber'};
114     $line{invoice} = $invoice;
115     $line{gst} = $gst;
116     $line{title} = $parcelitems[$i]->{'title'};
117     $line{author} = $parcelitems[$i]->{'author'};
118     $line{unitprice} = $parcelitems[$i]->{'unitprice'};
119     $line{ecost} = $parcelitems[$i]->{'ecost'};
120     $line{quantityrecieved} = $parcelitems[$i]->{'quantityreceived'};
121     $line{quantity} = $parcelitems[$i]->{'quantity'};
122     $line{total} = $total;
123     $line{supplierid} = $supplierid;
124     push @loop_received, \%line;
125     $totalprice+=$parcelitems[$i]->{'unitprice'};
126     $totalfreight+=$parcelitems[$i]->{'freight'};
127     $totalquantity+=$parcelitems[$i]->{'quantityreceived'};
128     $tototal+=$total;
129 }
130 my $pendingorders = GetPendingOrders($supplierid);
131 my $countpendings = scalar @$pendingorders;
132
133 my @loop_orders = ();
134 for (my $i=0;$i<$countpendings;$i++){
135     my %line;
136     if ($toggle==0){
137         $line{color}='#EEEEEE';
138         $toggle=1;
139 } else {
140         $line{color}='white';
141         $toggle=0;
142 }
143     $line{basketno} = $pendingorders->[$i]->{'basketno'};
144     $line{isbn} = $pendingorders->[$i]->{'isbn'};
145     $line{ordernumber} = $pendingorders->[$i]->{'ordernumber'};
146     $line{biblionumber} = $pendingorders->[$i]->{'biblionumber'};
147     $line{invoice} = $invoice;
148     $line{gst} = $gst;
149     $line{title} = $pendingorders->[$i]->{'title'};
150     $line{author} = $pendingorders->[$i]->{'author'};
151     $line{unitprice} = $pendingorders->[$i]->{'unitprice'};
152     $line{ecost} = $pendingorders->[$i]->{'ecost'};
153     $line{quantityrecieved} = $pendingorders->[$i]->{'quantityreceived'};
154     $line{quantity} = $pendingorders->[$i]->{'quantity'};
155     $line{total} = $total;
156     $line{supplierid} = $supplierid;
157     push @loop_orders, \%line;
158 }
159
160 $totalfreight=$freight;
161 $tototal=$tototal+$freight;
162
163 $template->param(invoice => $invoice,
164                         date => $date,
165                         name => $booksellers[0]->{'name'},
166                         supplierid => $supplierid,
167                         gst => $gst,
168                         freight => $freight,
169                         invoice => $invoice,
170                         countreceived => $countlines,
171                         loop_received => \@loop_received,
172                         countpending => $countpendings,
173                         loop_orders => \@loop_orders,
174                         totalprice => $totalprice,
175                         totalfreight => $totalfreight,
176                         totalquantity => $totalquantity,
177                         tototal => $tototal,
178                         gst => $gst,
179                         grandtot => $tototal+$gst,
180                         intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
181         intranetstylesheet => C4::Context->preference("intranetstylesheet"),
182         IntranetNav => C4::Context->preference("IntranetNav"),
183                         );
184 output_html_with_http_headers $input, $cookie, $template->output;