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
31 use C4::Dates qw/format_date/;
36 $debug = $ENV{DEBUG} || 1;
45 This script display all informations about basket for the supplier given
46 on input arg. Moreover, it allow to add a new order for this supplier from
47 an existing record, a suggestion or from a new record.
55 this parameter seems to be unused.
59 the supplier this script have to display the basket.
68 my $basketno = $query->param('basketno');
69 my $booksellerid = $query->param('supplierid');
70 my $order = $query->param('order');
71 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
73 template_name => "acqui/basket.tmpl",
77 flagsrequired => { acquisition => 1 },
82 my $basket = GetBasket($basketno);
84 # FIXME : the query->param('supplierid') below is probably useless. The bookseller is always known from the basket
85 # if no booksellerid in parameter, get it from basket
86 # warn "=>".$basket->{booksellerid};
87 $booksellerid = $basket->{booksellerid} unless $booksellerid;
88 my ($bookseller) = GetBookSellerFromId($booksellerid);
91 $template->param( NO_BOOKSELLER => 1 );
95 # get librarian branch...
96 if ( C4::Context->preference("IndependantBranches") ) {
97 my $userenv = C4::Context->userenv;
98 unless ( $userenv->{flags} == 1 ) {
99 my $validtest = ( $basket->{creationdate} 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} );
115 "loggedinuser: $loggedinuser; creationdate: %s; authorisedby: %s",
116 $basket->{creationdate}, $basket->{authorisedby};
118 my @results = GetOrders( $basketno, $order );
119 my $count = scalar @results;
121 my $line_total; # total of each line
122 my $sub_total; # total of line totals
124 my $grand_total; # $subttotal + $gist
127 # my $line_total_est; # total of each line
128 my $sub_total_est; # total of line totals
129 my $sub_total_rrp; # total of line totals
131 my $grand_total_est; # $subttotal + $gist
135 for ( my $i = 0 ; $i < $count ; $i++ ) {
136 my $rrp = $results[$i]->{'listprice'};
137 $rrp = ConvertCurrency( $results[$i]->{'currency'}, $rrp );
138 $sub_total_rrp += $results[$i]->{'quantity'} * $results[$i]->{'rrp'};
139 $line_total = $results[$i]->{'quantity'} * $results[$i]->{'ecost'};
140 $sub_total += $line_total;
141 $qty_total += $results[$i]->{'quantity'};
143 %line = %{ $results[$i] };
145 if ( $toggle == 0 ) {
146 $line{color} = '#EEEEEE';
150 $line{color} = 'white';
153 $line{order_received} =
154 ( $results[$i]->{'quantity'} eq $results[$i]->{'quantityreceived'} );
155 $line{publishercode} = $results[$i]->{'publishercode'};
156 $line{basketno} = $basketno;
158 $line{rrp} = sprintf( "%.2f", $line{'rrp'} );
159 $line{ecost} = sprintf( "%.2f", $line{'ecost'} );
160 $line{line_total} = sprintf( "%.2f", $line_total );
162 push @books_loop, \%line;
164 my $prefgist = C4::Context->preference("gist");
165 $gist = sprintf( "%.2f", $sub_total * $prefgist );
166 $grand_total = $sub_total;
167 $grand_total_est = $sub_total_est;
168 unless ( $bookseller->{'listincgst'} ) {
169 $grand_total += $gist;
170 $grand_total_est += sprintf( "%.2f", $sub_total_est * $prefgist );
172 my $grand_total_rrp = sprintf( "%.2f", $sub_total_rrp );
173 $gist_est = sprintf( "%.2f", $sub_total_est * $prefgist );
175 basketno => $basketno,
176 creationdate => format_date( $basket->{creationdate} ),
177 authorisedby => $basket->{authorisedby},
178 authorisedbyname => $basket->{authorisedbyname},
179 closedate => format_date( $basket->{closedate} ),
180 active => $bookseller->{'active'},
181 booksellerid => $bookseller->{'id'},
182 name => $bookseller->{'name'},
183 address1 => $bookseller->{'address1'},
184 address2 => $bookseller->{'address2'},
185 address3 => $bookseller->{'address3'},
186 address4 => $bookseller->{'address4'},
187 entrydate => format_date( $results[0]->{'entrydate'} ),
188 books_loop => \@books_loop,
190 sub_total => sprintf( "%.2f", $sub_total ),
192 grand_total => sprintf( "%.2f", $grand_total ),
193 sub_total_est => $sub_total_est,
194 gist_est => $gist_est,
195 grand_total_est => $grand_total_est,
196 grand_total_rrp => $grand_total_rrp,
197 currency => $bookseller->{'listprice'},
198 qty_total => $qty_total,
202 output_html_with_http_headers $query, $cookie, $template->output;