3 #script to show display basket of orders
4 #written by chris@katipo.co.nz 24/2/2000
6 # Copyright 2000-2002 Katipo Communications
8 # This file is part of Koha.
10 # Koha is free software; you can redistribute it and/or modify it under the
11 # terms of the GNU General Public License as published by the Free Software
12 # Foundation; either version 2 of the License, or (at your option) any later
15 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
16 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
17 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License along with
20 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
21 # Suite 330, Boston, MA 02111-1307 USA
32 use C4::Dates qw/format_date/;
37 $debug = $ENV{DEBUG} || 1;
46 This script display all informations about basket for the supplier given
47 on input arg. Moreover, it allow to add a new order for this supplier from
48 an existing record, a suggestion or from a new record.
56 this parameter seems to be unused.
60 the supplier this script have to display the basket.
71 my $basketno = $query->param('basketno');
72 my $booksellerid = $query->param('supplierid');
73 my $order = $query->param('order');
74 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
76 template_name => "acqui/basket.tmpl",
80 flagsrequired => { acquisition => 1 },
85 my $basket = GetBasket($basketno);
87 # FIXME : the query->param('supplierid') below is probably useless. The bookseller is always known from the basket
88 # if no booksellerid in parameter, get it from basket
89 # warn "=>".$basket->{booksellerid};
90 $booksellerid = $basket->{booksellerid} unless $booksellerid;
91 my @booksellers = GetBookSeller($booksellerid);
92 my $count2 = scalar @booksellers;
94 # get librarian branch...
95 if ( C4::Context->preference("IndependantBranches") ) {
96 my $userenv = C4::Context->userenv;
97 unless ( $userenv->{flags} == 1 ) {
98 my $validtest = ( $basket->{creationdate} eq '' )
99 || ( $basket->{branch} eq '' )
100 || ( $userenv->{branch} eq $basket->{branch} )
101 || ( $userenv->{branch} eq '' )
102 || ( $basket->{branch} eq '' );
103 unless ($validtest) {
104 print $query->redirect("../mainpage.pl");
110 # if new basket, pre-fill infos
111 $basket->{creationdate} = "" unless ( $basket->{creationdate} );
112 $basket->{authorisedby} = $loggedinuser unless ( $basket->{authorisedby} );
114 sprintf "loggedinuser: $loggedinuser; creationdate: %s; authorisedby: %s",
115 $basket->{creationdate}, $basket->{authorisedby} ;
118 my ( $count, @results );
119 @results = GetOrders( $basketno, $order );
120 $count = scalar @results;
122 my $line_total; # total of each line
123 my $sub_total; # total of line totals
125 my $grand_total; # $subttotal + $gist
129 # my $line_total_est; # total of each line
130 my $sub_total_est; # total of line totals
132 my $grand_total_est; # $subttotal + $gist
137 for ( my $i = 0 ; $i < $count ; $i++ ) {
138 my $rrp = $results[$i]->{'listprice'};
139 $rrp = ConvertCurrency( $results[$i]->{'currency'}, $rrp );
141 $sub_total_est += $results[$i]->{'quantity'} * $results[$i]->{'rrp'};
142 $line_total = $results[$i]->{'quantity'} * $results[$i]->{'ecost'};
143 $sub_total += $line_total;
144 $qty_total += $results[$i]->{'quantity'};
146 %line=%{$results[$i]};
147 if ( $toggle == 0 ) {
148 $line{color} = '#EEEEEE';
152 $line{color} = 'white';
155 $line{basketno} = $basketno;
157 $line{rrp} = sprintf( "%.2f", $line{'rrp'} );
158 $line{ecost} = sprintf( "%.2f", $line{'ecost'} );
159 $line{line_total} = sprintf( "%.2f", $line_total );
161 push @books_loop, \%line;
163 my $prefgist = C4::Context->preference("gist");
164 $gist = sprintf( "%.2f", $sub_total * $prefgist );
165 $grand_total = $sub_total + $gist;
167 $sub_total_est + sprintf( "%.2f", $sub_total_est * $prefgist );
168 $gist_est = sprintf( "%.2f", $sub_total_est * $prefgist );
170 basketno => $basketno,
171 creationdate => format_date( $basket->{creationdate} ),
172 authorisedby => $basket->{authorisedby},
173 authorisedbyname => $basket->{authorisedbyname},
174 closedate => format_date( $basket->{closedate} ),
175 active => $booksellers[0]->{'active'},
176 booksellerid => $booksellers[0]->{'id'},
177 name => $booksellers[0]->{'name'},
178 address1 => $booksellers[0]->{'address1'},
179 address2 => $booksellers[0]->{'address2'},
180 address3 => $booksellers[0]->{'address3'},
181 address4 => $booksellers[0]->{'address4'},
182 entrydate => format_date( $results[0]->{'entrydate'} ),
183 books_loop => \@books_loop,
185 sub_total => $sub_total,
187 grand_total => $grand_total,
188 sub_total_est => $sub_total_est,
189 gist_est => $gist_est,
190 grand_total_est => $grand_total_est,
191 currency => $booksellers[0]->{'listprice'},
192 qty_total => $qty_total,
193 GST => C4::Context->preference("gist"),
195 output_html_with_http_headers $query, $cookie, $template->output;