this file replaces recieve.pl
[koha.git] / acqui / parcel.pl
1  
2 #!/usr/bin/perl
3
4 # $Id$
5
6 #script to recieve orders
7 #written by chris@katipo.co.nz 24/2/2000
8
9
10 # Copyright 2000-2002 Katipo Communications
11 #
12 # This file is part of Koha.
13 #
14 # Koha is free software; you can redistribute it and/or modify it under the
15 # terms of the GNU General Public License as published by the Free Software
16 # Foundation; either version 2 of the License, or (at your option) any later
17 # version.
18 #
19 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
20 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
21 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
22 #
23 # You should have received a copy of the GNU General Public License along with
24 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
25 # Suite 330, Boston, MA  02111-1307 USA
26
27 use C4::Auth;
28 use C4::Acquisition;
29 use C4::Biblio;
30 use C4::Output;
31 use CGI;
32 use C4::Interface::CGI::Output;
33 use C4::Database;
34 use HTML::Template;
35 use strict;
36
37 my $input=new CGI;
38 my $supplierid=$input->param('supplierid');
39 my ($count,@booksellers)=bookseller($supplierid);
40 my $invoice=$input->param('code') || '';
41 my $freight=$input->param('freight');
42 my $gst=$input->param('gst');
43 my $date=$input->param('datereceived');
44 my $code=$input->param('code');
45
46 my ($template, $loggedinuser, $cookie)
47     = get_template_and_user({template_name => "acqui/parcel.tmpl",
48                  query => $input,
49                  type => "intranet",
50                  authnotrequired => 0,
51                  flagsrequired => {acquisition => 1},
52                  debug => 1,
53 });
54
55 my ($countlines,@parcelitems)=getparcelinformation($supplierid,$invoice,$date);
56 my $totalprice=0;
57 my $totalfreight=0;
58 my $totalquantity=0;
59 my $total;
60 my $tototal;
61 my $toggle;
62 my @loop_received = ();
63 for (my $i=0;$i<$countlines;$i++){
64     $total=($parcelitems[$i]->{'unitprice'} + $parcelitems[$i]->{'freight'}) * $parcelitems[$i]->{'quantityreceived'};   #weird, are the freight fees counted by book? (pierre)
65     $parcelitems[$i]->{'unitprice'}+=0;
66     my %line;
67     if ($toggle==0){
68         $line{color}='#EEEEEE';
69         $toggle=1;
70 } else {
71         $line{color}='white';
72         $toggle=0;
73 }
74     $line{basketno} = $parcelitems[$i]->{'basketno'};
75     $line{isbn} = $parcelitems[$i]->{'isbn'};
76     $line{ordernumber} = $parcelitems[$i]->{'ordernumber'};
77     $line{biblionumber} = $parcelitems[$i]->{'biblionumber'};
78     $line{invoice} = $invoice;
79     $line{gst} = $gst;
80     $line{title} = $parcelitems[$i]->{'title'};
81     $line{author} = $parcelitems[$i]->{'author'};
82     $line{unitprice} = $parcelitems[$i]->{'unitprice'};
83     $line{ecost} = $parcelitems[$i]->{'ecost'};
84     $line{quantityrecieved} = $parcelitems[$i]->{'quantityreceived'};
85     $line{quantity} = $parcelitems[$i]->{'quantity'};
86     $line{total} = $total;
87     $line{supplierid} = $supplierid;
88     push @loop_received, \%line;
89     $totalprice+=$parcelitems[$i]->{'unitprice'};
90     $totalfreight+=$parcelitems[$i]->{'freight'};
91     $totalquantity+=$parcelitems[$i]->{'quantityreceived'};
92     $tototal+=$total;
93 }
94 my ($countpendings,@pendingorders)=getallorders($supplierid);
95 my @loop_orders = ();
96 for (my $i=0;$i<$countpendings;$i++){
97     my %line;
98     if ($toggle==0){
99         $line{color}='#EEEEEE';
100         $toggle=1;
101 } else {
102         $line{color}='white';
103         $toggle=0;
104 }
105     $line{basketno} = $pendingorders[$i]->{'basketno'};
106     $line{isbn} = $pendingorders[$i]->{'isbn'};
107     $line{ordernumber} = $pendingorders[$i]->{'ordernumber'};
108     $line{biblionumber} = $pendingorders[$i]->{'biblionumber'};
109     $line{invoice} = $invoice;
110     $line{gst} = $gst;
111     $line{title} = $pendingorders[$i]->{'title'};
112     $line{author} = $pendingorders[$i]->{'author'};
113     $line{unitprice} = $pendingorders[$i]->{'unitprice'};
114     $line{ecost} = $pendingorders[$i]->{'ecost'};
115     $line{quantityrecieved} = $pendingorders[$i]->{'quantityreceived'};
116     $line{quantity} = $pendingorders[$i]->{'quantity'};
117     $line{total} = $total;
118     $line{supplierid} = $supplierid;
119     push @loop_orders, \%line;
120 }
121
122 $totalfreight=$freight;
123 $tototal=$tototal+$freight;
124
125 $template->param(invoice => $invoice,
126                         date => $date,
127                         name => $booksellers[0]->{'name'},
128                         supplierid => $supplierid,
129                         gst => $gst,
130                         freight => $freight,
131                         invoice => $invoice,
132                         countreceived => $countlines,
133                         loop_received => \@loop_received,
134                         countpending => $countpendings,
135                         loop_orders => \@loop_orders,
136                         totalprice => $totalprice,
137                         totalfreight => $totalfreight,
138                         totalquantity => $totalquantity,
139                         tototal => $tototal,
140                         gst => $gst,
141                         grandtot => $tototal+$gst,
142                         intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
143         intranetstylesheet => C4::Context->preference("intranetstylesheet"),
144         IntranetNav => C4::Context->preference("IntranetNav"),
145                         );
146 output_html_with_http_headers $input, $cookie, $template->output;