synch'ing 2.2 and head
[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::Output;
30 use CGI;
31 use C4::Interface::CGI::Output;
32 use C4::Database;
33 use HTML::Template;
34 use C4::Acquisition;
35 use C4::Date;
36
37 my $query =new CGI;
38 my $basketno = $query->param('basket');
39 my $booksellerid = $query->param('supplierid');
40 my $order = $query->param('order');
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
52 my $basket = getbasket($basketno);
53 # FIXME : the query->param('supplierid') below is probably useless. The bookseller is always known from the basket
54 # if no booksellerid in parameter, get it from basket
55 # warn "=>".$basket->{booksellerid};
56 $booksellerid = $basket->{booksellerid} unless $booksellerid;
57 my ($count2,@booksellers)=bookseller($booksellerid);
58
59 # get librarian branch...
60 if (C4::Context->preference("IndependantBranches")) {
61         my $userenv = C4::Context->userenv;
62         unless ($userenv->{flags} == 1){
63                 my $validtest = ($basket->{creationdate} = "") 
64                                         || ($userenv->{branch} eq $basket->{branch})
65                                         || ($userenv->{branch} = '')
66                                         || ($basket->{branch} = '');
67                 unless ($validtest) {
68                         print $query->redirect("../mainpage.pl");
69                         exit 1;
70                 }
71         }
72 }
73
74 # if new basket, pre-fill infos
75 $basket->{creationdate} = "" unless ($basket->{creationdate});
76 $basket->{authorisedby} = $loggedinuser unless ($basket->{authorisedby});
77 ($count,@results)=getbasketcontent($basketno,'',$order);
78
79 my $line_total; # total of each line
80 my $sub_total; # total of line totals
81 my $gist;      # GST
82 my $grand_total; # $subttotal + $gist
83
84 # my $line_total_est; # total of each line
85 my $sub_total_est; # total of line totals
86 my $gist_est;      # GST
87 my $grand_total_est; # $subttotal + $gist
88
89 my $qty_total;
90
91 my @books_loop;
92 for (my $i=0;$i<$count;$i++){
93         my $rrp=$results[$i]->{'listprice'};
94         $rrp=curconvert($results[$i]->{'currency'},$rrp);
95
96         $sub_total_est+=$results[$i]->{'quantity'}*$results[$i]->{'rrp'};
97         $line_total=$results[$i]->{'quantity'}*$results[$i]->{'ecost'};
98         $sub_total+=$line_total;
99         $qty_total += $results[$i]->{'quantity'};
100         my %line;
101         $line{ordernumber} = $results[$i]->{'ordernumber'};
102         $line{publishercode} = $results[$i]->{'publishercode'};
103         $line{isbn} = $results[$i]->{'isbn'};
104         $line{booksellerid} = $results[$i]->{'booksellerid'};
105         $line{basketno}=$basketno;
106         $line{title} = $results[$i]->{'title'};
107         $line{notes} = $results[$i]->{'notes'};
108         $line{author} = $results[$i]->{'author'};
109         $line{i} = $i;
110         $line{rrp} = sprintf("%.2f",$results[$i]->{'rrp'});
111         $line{ecost} = sprintf("%.2f",$results[$i]->{'ecost'});
112         $line{quantity} = $results[$i]->{'quantity'};
113         $line{quantityrecieved} = $results[$i]->{'quantityreceived'};
114         $line{line_total} = sprintf("%.2f",$line_total);
115         $line{biblionumber} = $results[$i]->{'biblionumber'};
116         $line{bookfundid} = $results[$i]->{'bookfundid'};
117         $line{odd} = $i %2;
118         push @books_loop, \%line;
119 }
120 my $prefgist =C4::Context->preference("gist");
121 $gist=sprintf("%.2f",$sub_total*$prefgist);
122 $grand_total=$sub_total+$gist;
123 $grand_total_est = $sub_total_est+sprintf("%.2f",$sub_total_est*$prefgist);
124 $gist_est = sprintf("%.2f",$sub_total_est*$prefgist);
125 $template->param(basketno => $basketno,
126                                 creationdate => format_date($basket->{creationdate}),
127                                 authorisedby => $basket->{authorisedby},
128                                 authorisedbyname => $basket->{authorisedbyname},
129                                 closedate => format_date($basket->{closedate}),
130                                 active => $booksellers[0]->{'active'},
131                                 booksellerid=> $booksellers[0]->{'id'},
132                                 name => $booksellers[0]->{'name'},
133                                 address1 => $booksellers[0]->{'address1'},
134                                 address2 => $booksellers[0]->{'address2'},
135                                 address3 => $booksellers[0]->{'address3'},
136                                 address4 => $booksellers[0]->{'address4'},
137                                 entrydate => format_date($results[0]->{'entrydate'}),
138                                 books_loop => \@books_loop,
139                                 count =>$count,
140                                 sub_total => $sub_total,
141                                 gist => $gist,
142                                 grand_total =>$grand_total,
143                                 sub_total_est => $sub_total_est,
144                                 gist_est => $gist_est,
145                                 grand_total_est =>$grand_total_est,
146                                 currency => $booksellers[0]->{'listprice'},
147                                 qty_total => $qty_total,
148                                 );
149 output_html_with_http_headers $query, $cookie, $template->output;