this file replaces recieve.pl
[koha.git] / acqui / receive.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 use C4::Auth;
27 use C4::Acquisition;
28 use C4::Biblio;
29 use C4::Output;
30 use CGI;
31 use C4::Interface::CGI::Output;
32 use C4::Database;
33 use HTML::Template;
34 use strict;
35
36 my $input=new CGI;
37 my $supplierid=$input->param('supplierid');
38 my ($count,@booksellers)=bookseller($supplierid);
39 my $invoice=$input->param('code') || '';
40 my $freight=$input->param('freight');
41 my $gst=$input->param('gst');
42 my $date=$input->param('datereceived');
43 my $code=$input->param('code');
44
45 my ($template, $loggedinuser, $cookie)
46     = get_template_and_user({template_name => "acqui/recieve.tmpl",
47                              query => $input,
48                              type => "intranet",
49                              authnotrequired => 0,
50                              flagsrequired => {acquisition => 1},
51                              debug => 1,
52                              });
53
54 my ($countlines,@parcelitems)=getparcelinformation($supplierid,$invoice,$date);
55 my $totalprice=0;
56 my $totalfreight=0;
57 my $totalquantity=0;
58 my $total;
59 my $tototal;
60 my $toggle;
61 my @loop_received = ();
62 for (my $i=0;$i<$countlines;$i++){
63         $total=($parcelitems[$i]->{'unitprice'} + $parcelitems[$i]->{'freight'}) * $parcelitems[$i]->{'quantityreceived'};   #weird, are the freight fees counted by book? (pierre)
64         $parcelitems[$i]->{'unitprice'}+=0;
65         my %line;
66         if ($toggle==0){
67                 $line{color}='#EEEEEE';
68                 $toggle=1;
69         } else {
70                 $line{color}='white';
71                 $toggle=0;
72         }
73         $line{basketno} = $parcelitems[$i]->{'basketno'};
74         $line{isbn} = $parcelitems[$i]->{'isbn'};
75         $line{ordernumber} = $parcelitems[$i]->{'ordernumber'};
76         $line{biblionumber} = $parcelitems[$i]->{'biblionumber'};
77         $line{invoice} = $invoice;
78         $line{gst} = $gst;
79         $line{title} = $parcelitems[$i]->{'title'};
80         $line{author} = $parcelitems[$i]->{'author'};
81         $line{unitprice} = $parcelitems[$i]->{'unitprice'};
82         $line{ecost} = $parcelitems[$i]->{'ecost'};
83         $line{quantityrecieved} = $parcelitems[$i]->{'quantityreceived'};
84         $line{quantity} = $parcelitems[$i]->{'quantity'};
85         $line{total} = $total;
86         $line{supplierid} = $supplierid;
87         push @loop_received, \%line;
88         $totalprice+=$parcelitems[$i]->{'unitprice'};
89         $totalfreight+=$parcelitems[$i]->{'freight'};
90         $totalquantity+=$parcelitems[$i]->{'quantityreceived'};
91         $tototal+=$total;
92 }
93 my ($countpendings,@pendingorders)=getallorders($supplierid);
94 my @loop_orders = ();
95 for (my $i=0;$i<$countpendings;$i++){
96         my %line;
97         if ($toggle==0){
98                 $line{color}='#EEEEEE';
99                 $toggle=1;
100         } else {
101                 $line{color}='white';
102                 $toggle=0;
103         }
104         $line{basketno} = $pendingorders[$i]->{'basketno'};
105         $line{isbn} = $pendingorders[$i]->{'isbn'};
106         $line{ordernumber} = $pendingorders[$i]->{'ordernumber'};
107         $line{biblionumber} = $pendingorders[$i]->{'biblionumber'};
108         $line{invoice} = $invoice;
109         $line{gst} = $gst;
110         $line{title} = $pendingorders[$i]->{'title'};
111         $line{author} = $pendingorders[$i]->{'author'};
112         $line{unitprice} = $pendingorders[$i]->{'unitprice'};
113         $line{ecost} = $pendingorders[$i]->{'ecost'};
114         $line{quantityrecieved} = $pendingorders[$i]->{'quantityreceived'};
115         $line{quantity} = $pendingorders[$i]->{'quantity'};
116         $line{total} = $total;
117         $line{supplierid} = $supplierid;
118         push @loop_orders, \%line;
119 }
120
121 $totalfreight=$freight;
122 $tototal=$tototal+$freight;
123
124 $template->param(invoice => $invoice,
125                                                 date => $date,
126                                                 name => $booksellers[0]->{'name'},
127                                                 supplierid => $supplierid,
128                                                 gst => $gst,
129                                                 freight => $freight,
130                                                 invoice => $invoice,
131                                                 countreceived => $countlines,
132                                                 loop_received => \@loop_received,
133                                                 countpending => $countpendings,
134                                                 loop_orders => \@loop_orders,
135                                                 totalprice => $totalprice,
136                                                 totalfreight => $totalfreight,
137                                                 totalquantity => $totalquantity,
138                                                 tototal => $tototal,
139                                                 gst => $gst,
140                                                 grandtot => $tototal+$gst,
141                                                 intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
142                 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
143                 IntranetNav => C4::Context->preference("IntranetNav"),
144                                                 );
145 output_html_with_http_headers $input, $cookie, $template->output;