Very beginning of late serial consulting in acquisitions
[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 strict;
27 use C4::Auth;
28 use C4::Koha;
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 C4::Acquisition;
36 use C4::Date;
37
38 my $query =new CGI;
39 my $basketno = $query ->param('basket');
40 my $supplierid = $query->param('id');
41 my ($template, $loggedinuser, $cookie)
42     = get_template_and_user({template_name => "acqui/basket.tmpl",
43                              query => $query,
44                              type => "intranet",
45                              authnotrequired => 0,
46                              flagsrequired => {acquisition => 1},
47                              debug => 1,
48                              });
49 my ($count,@results);
50
51 my ($count2,@booksellers)=bookseller($supplierid);
52
53 my $basket = getbasket($basketno);
54 # if new basket, pre-fill infos
55 $basket->{creationdate} = "" unless ($basket->{creationdate});
56 $basket->{authorisedby} = $loggedinuser unless ($basket->{authorisedby});
57 ($count,@results)=getbasketcontent($basketno);
58
59 my $line_total; # total of each line
60 my $sub_total; # total of line totals
61 my $gist;      # GST
62 my $grand_total; # $subttotal + $gist
63 my $toggle=0;
64
65 my @books_loop;
66 for (my $i=0;$i<$count;$i++){
67         my $rrp=$results[$i]->{'listprice'};
68         $rrp=curconvert($results[$i]->{'currency'},$rrp);
69
70         $line_total=$results[$i]->{'quantity'}*$results[$i]->{'ecost'};
71         $sub_total+=$line_total;
72         my %line;
73         if ($toggle==0){
74                 $line{color}='#EEEEEE';
75                 $toggle=1;
76         } else {
77                 $line{color}='white';
78                 $toggle=0;
79         }
80         $line{ordernumber} = $results[$i]->{'ordernumber'};
81         $line{publishercode} = $results[$i]->{'publishercode'};
82         $line{isbn} = $results[$i]->{'isbn'};
83         $line{booksellerid} = $results[$i]->{'booksellerid'};
84         $line{basketno}=$basketno;
85         $line{title} = $results[$i]->{'title'};
86         $line{author} = $results[$i]->{'author'};
87         $line{i} = $i;
88         $line{rrp} = $results[$i]->{'rrp'};
89         $line{ecost} = $results[$i]->{'ecost'};
90         $line{quantity} = $results[$i]->{'quantity'};
91         $line{quantityrecieved} = $results[$i]->{'quantityreceived'};
92         $line{line_total} = $line_total;
93         $line{biblionumber} = $results[$i]->{'biblionumber'};
94         push @books_loop, \%line;
95 }
96 my $prefgist =C4::Context->preference("gist");
97 $gist=sprintf("%.2f",$sub_total*$prefgist);
98 $grand_total=$sub_total+$gist;
99
100 $template->param(basketno => $basketno,
101                                 creationdate => $basket->{creationdate},
102                                 authorisedby => $basket->{authorisedby},
103                                 authorisedbyname => $basket->{authorisedbyname},
104                                 booksellerid=> $booksellers[0]->{'id'},
105                                 name => $booksellers[0]->{'name'},
106                                 entrydate => format_date($results[0]->{'entrydate'}),
107                                 books_loop => \@books_loop,
108                                 count =>$count,
109                                 sub_total => $sub_total,
110                                 gist => $gist,
111                                 grand_total =>$grand_total,
112                                 currency => $booksellers[0]->{'listprice'},
113                                 );
114 output_html_with_http_headers $query, $cookie, $template->output;