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.
69 my $basketno = $query->param('basketno');
70 my $booksellerid = $query->param('supplierid');
71 my $order = $query->param('order');
72 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
74 template_name => "acqui/basket.tmpl",
78 flagsrequired => { acquisition => 1 },
83 my $basket = GetBasket($basketno);
85 # FIXME : the query->param('supplierid') below is probably useless. The bookseller is always known from the basket
86 # if no booksellerid in parameter, get it from basket
87 # warn "=>".$basket->{booksellerid};
88 $booksellerid = $basket->{booksellerid} unless $booksellerid;
89 my @booksellers = GetBookSeller($booksellerid);
90 my $count2 = scalar @booksellers;
91 # FIXME: do something with count2?
92 # FIXME: how do you know the first BookSeller in the array is the one you want?
93 # FIXME: GetBookSeller should be changing to reliably return 1 record based on ID,
94 # but we still should give some kind of Error back to the user if it fails.
96 # get librarian branch...
97 if ( C4::Context->preference("IndependantBranches") ) {
98 my $userenv = C4::Context->userenv;
99 unless ( $userenv->{flags} == 1 ) {
100 my $validtest = ( $basket->{creationdate} eq '' )
101 || ( $userenv->{branch} eq $basket->{branch} )
102 || ( $userenv->{branch} eq '' )
103 || ( $basket->{branch} eq '' );
104 unless ($validtest) {
105 print $query->redirect("../mainpage.pl");
111 # if new basket, pre-fill infos
112 $basket->{creationdate} = "" unless ( $basket->{creationdate} );
113 $basket->{authorisedby} = $loggedinuser unless ( $basket->{authorisedby} );
115 sprintf "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
128 # my $line_total_est; # total of each line
129 my $sub_total_est; # total of line totals
130 my $sub_total_rrp; # total of line totals
132 my $grand_total_est; # $subttotal + $gist
136 for ( my $i = 0 ; $i < $count ; $i++ ) {
137 my $rrp = $results[$i]->{'listprice'};
138 $rrp = ConvertCurrency( $results[$i]->{'currency'}, $rrp );
139 $sub_total_rrp += $results[$i]->{'quantity'} * $results[$i]->{'rrp'};
140 $line_total = $results[$i]->{'quantity'} * $results[$i]->{'ecost'};
141 $sub_total += $line_total;
142 $qty_total += $results[$i]->{'quantity'};
144 %line=%{$results[$i]};
145 if ( $toggle == 0 ) {
146 $line{color} = '#EEEEEE';
150 $line{color} = 'white';
153 $line{order_received} = ($results[$i]->{'quantity'} eq $results[$i]->{'quantityreceived'});
154 $line{publishercode} = $results[$i]->{'publishercode'};
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;
166 $grand_total_est = $sub_total_est;
167 unless ($booksellers[0]->{'listincgst'}) {
168 $grand_total += $gist;
169 $grand_total_est += sprintf( "%.2f", $sub_total_est * $prefgist );
171 my $grand_total_rrp = sprintf( "%.2f", $sub_total_rrp );
172 $gist_est = sprintf( "%.2f", $sub_total_est * $prefgist );
174 basketno => $basketno,
175 creationdate => format_date( $basket->{creationdate} ),
176 authorisedby => $basket->{authorisedby},
177 authorisedbyname => $basket->{authorisedbyname},
178 closedate => format_date( $basket->{closedate} ),
179 active => $booksellers[0]->{'active'},
180 booksellerid => $booksellers[0]->{'id'},
181 name => $booksellers[0]->{'name'},
182 address1 => $booksellers[0]->{'address1'},
183 address2 => $booksellers[0]->{'address2'},
184 address3 => $booksellers[0]->{'address3'},
185 address4 => $booksellers[0]->{'address4'},
186 entrydate => format_date( $results[0]->{'entrydate'} ),
187 books_loop => \@books_loop,
189 sub_total => sprintf( "%.2f", $sub_total),
191 grand_total => sprintf( "%.2f", $grand_total),
192 sub_total_est => $sub_total_est,
193 gist_est => $gist_est,
194 grand_total_est => $grand_total_est,
195 grand_total_rrp => $grand_total_rrp,
196 currency => $booksellers[0]->{'listprice'},
197 qty_total => $qty_total,
200 output_html_with_http_headers $query, $cookie, $template->output;