Merging from Katipo work
[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('invoice');
40 my $freight=$input->param('freight');
41 my $gst=$input->param('gst');
42 my $date=localtime(time);
43
44 my ($template, $loggedinuser, $cookie)
45     = get_template_and_user({template_name => "acqui/recieve.tmpl",
46                              query => $input,
47                              type => "intranet",
48                              authnotrequired => 0,
49                              flagsrequired => {acquisition => 1},
50                              debug => 1,
51                              });
52
53 my @results;
54 ($count,@results)=invoice($invoice);
55 if ($invoice eq ''){
56         ($count,@results)=getallorders($supplierid);
57 }
58 my $totalprice=0;
59 my $totalfreight=0;
60 my $totalquantity=0;
61 my $total;
62 my $tototal;
63 my $toggle;
64 my @loop_orders = ();
65 for (my$i=0;$i<$count;$i++){
66         $total=($results[$i]->{'unitprice'} + $results[$i]->{'freight'}) * $results[$i]->{'quantityreceived'};   #weird, are the freight fees counted by book? (pierre)
67         $results[$i]->{'unitprice'}+=0;
68         my %line;
69         if ($toggle==0){
70                 $line{color}='#EEEEEE';
71                 $toggle=1;
72         } else {
73                 $line{color}='white';
74                 $toggle=0;
75         }
76         $line{basketno} = $results[$i]->{'basketno'};
77         $line{isbn} = $results[$i]->{'isbn'};
78         $line{ordernumber} = $results[$i]->{'ordernumber'};
79         $line{biblionumber} = $results[$i]->{'biblionumber'};
80         $line{invoice} = $invoice;
81         $line{gst} = $gst;
82         $line{title} = ($results[$i]->{'truetitle'}?$results[$i]->{'truetitle'}:$results[$i]->{'suggestedtitle'});
83         $line{author} = $results[$i]->{'author'};
84         $line{unitprice} = $results[$i]->{'unitprice'};
85         $line{quantityrecieved} = $results[$i]->{'quantityreceived'};
86         $line{total} = $total;
87         $line{supplierid} = $supplierid;
88         push @loop_orders, \%line;
89         $totalprice+=$results[$i]->{'unitprice'};
90         $totalfreight+=$results[$i]->{'freight'};
91         $totalquantity+=$results[$i]->{'quantityreceived'};
92         $tototal+=$total;
93 }
94
95 $totalfreight=$freight;
96 $tototal=$tototal+$freight;
97
98 $template->param(invoice => $invoice,
99                                                 date => $date,
100                                                 name => $booksellers[0]->{'name'},
101                                                 supplierid => $supplierid,
102                                                 gst => $gst,
103                                                 freight => $freight,
104                                                 invoice => $invoice,
105                                                 count => $count,
106                                                 loop_orders => \@loop_orders,
107                                                 totalprice => $totalprice,
108                                                 totalfreight => $totalfreight,
109                                                 totalquantity => $totalquantity,
110                                                 tototal => $tototal,
111                                                 gst => $gst,
112                                                 grandtot => $tototal+$gst,
113                                                 );
114 output_html_with_http_headers $input, $cookie, $template->output;