Road to 1.9.1
[wip/koha-chris_n.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::Catalogue;
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 C4::Catalogue;
35 use strict;
36
37 my $input=new CGI;
38 my $id=$input->param('id');
39 my ($count,@booksellers)=bookseller($id);
40 my $invoice=$input->param('invoice');
41 my $freight=$input->param('freight');
42 my $gst=$input->param('gst');
43 my $user=$input->remote_user;
44 my $date=localtime(time);
45
46 my ($template, $loggedinuser, $cookie)
47     = get_template_and_user({template_name => "acqui/recieve.tmpl",
48                              query => $input,
49                              type => "intranet",
50                              authnotrequired => 0,
51                              flagsrequired => {acquisition => 1},
52                              debug => 1,
53                              });
54
55 my @results;
56 ($count,@results)=invoice($invoice);
57 if ($invoice eq ''){
58         ($count,@results)=getallorders($id);
59 }
60 my $totalprice=0;
61 my $totalfreight=0;
62 my $totalquantity=0;
63 my $total;
64 my $tototal;
65 my $toggle;
66 my @loop_orders = ();
67 for (my$i=0;$i<$count;$i++){
68         warn "nb : ".$results[$i]->{'ordernumber'};
69         $total=($results[$i]->{'unitprice'} + $results[$i]->{'freight'}) * $results[$i]->{'quantityreceived'};
70         $results[$i]->{'unitprice'}+=0;
71         my %line;
72         if ($toggle==0){
73                 $line{color}='#ffffcc';
74                 $toggle=1;
75         } else {
76                 $line{color}='white';
77                 $toggle=0;
78         }
79         $line{basketno} = $results[$i]->{'basketno'};
80         $line{isbn} = $results[$i]->{'isbn'};
81         $line{ordernumber} = $results[$i]->{'ordernumber'};
82         $line{biblionumber} = $results[$i]->{'biblionumber'};
83         $line{invoice} = $invoice;
84         $line{gst} = $gst;
85         $line{title} = $results[$i]->{'title'};
86         $line{author} = $results[$i]->{'author'};
87         $line{unitprice} = $results[$i]->{'unitprice'};
88         $line{quantityrecieved} = $results[$i]->{'quantityreceived'};
89         $line{total} = $total;
90         push @loop_orders, \%line;
91         $totalprice+=$results[$i]->{'unitprice'};
92         $totalfreight+=$results[$i]->{'freight'};
93         $totalquantity+=$results[$i]->{'quantityreceived'};
94         $tototal+=$total;
95 }
96
97 $totalfreight=$freight;
98 $tototal=$tototal+$freight;
99
100 $template->param(invoice => $invoice,
101                                                 user => $user,
102                                                 date => $date,
103                                                 name => $booksellers[0]->{'name'},
104                                                 gst => $gst,
105                                                 freight => $freight,
106                                                 invoice => $invoice,
107                                                 count => $count,
108                                                 loop_orders => \@loop_orders,
109                                                 totalprice => $totalprice,
110                                                 totalfreight => $totalfreight,
111                                                 totalquantity => $totalquantity,
112                                                 tototal => $tototal,
113                                                 gst => $gst,
114                                                 grandtot => $tototal+$gst,
115                                                 );
116 output_html_with_http_headers $input, $cookie, $template->output;