-my ($count2,@booksellers)=bookseller($booksellerid);
-
-# if new basket, pre-fill infos
-$basket->{creationdate} = "" unless ($basket->{creationdate});
-$basket->{authorisedby} = $loggedinuser unless ($basket->{authorisedby});
-($count,@results)=getbasketcontent($basketno,'',$order);
-
-my $line_total; # total of each line
-my $sub_total; # total of line totals
-my $gist; # GST
-my $grand_total; # $subttotal + $gist
-my $toggle=0;
-
-my @books_loop;
-for (my $i=0;$i<$count;$i++){
- my $rrp=$results[$i]->{'listprice'};
- $rrp=curconvert($results[$i]->{'currency'},$rrp);
-
- $line_total=$results[$i]->{'quantity'}*$results[$i]->{'ecost'};
- $sub_total+=$line_total;
- my %line;
- if ($toggle==0){
- $line{color}='#EEEEEE';
- $toggle=1;
+my ($bookseller) = GetBookSellerFromId($booksellerid);
+
+if ( !$bookseller ) {
+ $template->param( NO_BOOKSELLER => 1 );
+}
+else {
+
+ # get librarian branch...
+ if ( C4::Context->preference("IndependantBranches") ) {
+ my $userenv = C4::Context->userenv;
+ unless ( $userenv->{flags} == 1 ) {
+ my $validtest = ( $basket->{creationdate} eq '' )
+ || ( $userenv->{branch} eq $basket->{branch} )
+ || ( $userenv->{branch} eq '' )
+ || ( $basket->{branch} eq '' );
+ unless ($validtest) {
+ print $query->redirect("../mainpage.pl");
+ exit 1;
+ }
+ }
+ }
+
+ # if new basket, pre-fill infos
+ $basket->{creationdate} = "" unless ( $basket->{creationdate} );
+ $basket->{authorisedby} = $loggedinuser unless ( $basket->{authorisedby} );
+ $debug
+ and warn sprintf
+ "loggedinuser: $loggedinuser; creationdate: %s; authorisedby: %s",
+ $basket->{creationdate}, $basket->{authorisedby};
+
+ my @results = GetOrders( $basketno, $sort );
+ my $count = scalar @results;
+
+ my $sub_total; # total of line totals
+ my $grand_total; # $subttotal + $gist
+
+ # my $line_total_est; # total of each line
+ my $sub_total_est; # total of line totals
+ my $sub_total_rrp; # total of line totals
+ my $grand_total_est; # $subttotal + $gist
+
+ my $qty_total;
+ my @books_loop;
+ for ( my $i = 0 ; $i < $count ; $i++ ) {
+ my $rrp = $results[$i]->{'listprice'};
+ my $qty = $results[$i]->{'quantity'};
+ $rrp = ConvertCurrency( $results[$i]->{'currency'}, $rrp );
+ $sub_total_rrp += $qty * $results[$i]->{'rrp'};
+ my $line_total = $qty * $results[$i]->{'ecost'};
+ # FIXME: what about the "actual cost" field?
+ $sub_total += $line_total;
+ $qty_total += $qty;
+ my %line = %{ $results[$i] };
+ ($i%2) and $line{toggle} = 1;
+ $line{order_received}= ( $qty eq $results[$i]->{'quantityreceived'} );
+ $line{basketno} = $basketno;
+ $line{i} = $i;
+ $line{rrp} = sprintf( "%.2f", $line{'rrp'} );
+ $line{ecost} = sprintf( "%.2f", $line{'ecost'} );
+ $line{line_total} = sprintf( "%.2f", $line_total );
+ $line{odd} = $i % 2;
+ push @books_loop, \%line;
+ }
+ my $prefgist = C4::Context->preference("gist") || 0;
+ my $gist = $sub_total * $prefgist;
+ my $gist_rrp = $sub_total_rrp * $prefgist;
+ $grand_total = $sub_total_est = $sub_total;
+ $grand_total_est = $sub_total_est; # FIXME: Too many things that are ALL the SAME
+ my $temp;
+ if ($temp = $bookseller->{'listincgst'}) {
+ $template->param(listincgst => $temp);
+ $gist = 0;