fix for #343
[koha.git] / acqui / basket.pl
1 #!/usr/bin/perl
2
3 # $Id$
4
5 #script to show display basket of 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 C4::Date;
36 use strict;
37
38 my $query =new CGI;
39 my $basket=$query ->param('basket');
40 my ($template, $loggedinuser, $cookie)
41     = get_template_and_user({template_name => "acqui/basket.tmpl",
42                              query => $query,
43                              type => "intranet",
44                              authnotrequired => 0,
45                              flagsrequired => {acquisition => 1},
46                              debug => 1,
47                              });
48
49 my ($count,@results);
50 if ($basket eq ''){
51         $basket=newbasket();
52         $results[0]->{'booksellerid'}=$query->param('id');
53         $results[0]->{'authorisedby'} = $loggedinuser;
54 } else {
55         ($count,@results)=basket($basket);
56 }
57
58 my ($count2,@booksellers)=bookseller($results[0]->{'booksellerid'});
59
60 my $line_total; # total of each line
61 my $sub_total; # total of line totals
62 my $gist;      # GST
63 my $grand_total; # $subttotal + $gist
64 my $toggle=0;
65
66 my @books_loop;
67 for (my $i=0;$i<$count;$i++){
68         my $rrp=$results[$i]->{'listprice'};
69         $rrp=curconvert($results[$i]->{'currency'},$rrp);
70
71         $line_total=$results[$i]->{'quantity'}*$results[$i]->{'ecost'};
72         $sub_total+=$line_total;
73         $gist=sprintf("%.2f",$sub_total*0.125);
74         $grand_total=$sub_total+$gist;
75         my %line;
76         if ($toggle==0){
77                 $line{color}='#ffffcc';
78                 $toggle=1;
79         } else {
80                 $line{color}='white';
81                 $toggle=0;
82         }
83         $line{ordernumber} = $results[$i]->{'ordernumber'};
84         $line{isbn} = $results[$i]->{'isbn'};
85         $line{booksellerid} = $results[$i]->{'booksellerid'};
86         $line{basket}=$basket;
87         $line{title} = $results[$i]->{'title'};
88         $line{author} = $results[$i]->{'author'};
89         $line{i} = $i;
90         $line{rrp} = $results[$i]->{'rrp'};
91         $line{ecost} = $results[$i]->{'ecost'};
92         $line{quantity} = $results[$i]->{'quantity'};
93         $line{line_total} = $line_total;
94         $line{biblionumber} = $results[$i]->{'biblionumber'};
95         push @books_loop, \%line;
96 }
97 $template->param(basket => $basket,
98                                                 authorisedby => $results[0]->{'authorisedby'},
99                                                 entrydate => format_date($results[0]->{'entrydate'}),
100                                                 id=> $results[0]->{'booksellerid'},
101                                                 name => $booksellers[0]->{'name'},
102                                                 books_loop => \@books_loop,
103                                                 count =>$count,
104                                                 sub_total => $sub_total,
105                                                 gist => $gist,
106                                                 grand_total =>$grand_total,
107                                                 );
108 output_html_with_http_headers $query, $cookie, $template->output;