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/;
40 This script display all informations about basket for the supplier given
41 on input arg. Moreover, it allows us to add a new order for this supplier from
42 an existing record, a suggestion or a new record.
54 the supplier this script have to display the basket.
63 my $basketno = $query->param('basketno');
64 my $booksellerid = $query->param('supplierid');
65 my $sort = $query->param('order');
69 foreach (split /\,/, $sort) {
73 # other possibly valid tables for later: aqbookfund biblio biblioitems
75 (/^\s*(aqorderbreakdown)\.(\w+)\s*$/ and $2 eq 'bookfundid' ) or
76 (/^\s*(biblioitems)\.(\w+)\s*$/ and $2 eq 'publishercode')
78 $sorthash{table
} = $1;
79 $sorthash{field
} = $2;
83 push @sort_loop, \
%sorthash;
87 my ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
89 template_name
=> "acqui/basket.tmpl",
93 flagsrequired
=> { acquisition
=> 1 },
98 my $basket = GetBasket
($basketno);
100 # FIXME : what about the "discount" percentage?
101 # FIXME : the query->param('supplierid') below is probably useless. The bookseller is always known from the basket
102 # if no booksellerid in parameter, get it from basket
103 # warn "=>".$basket->{booksellerid};
104 $booksellerid = $basket->{booksellerid
} unless $booksellerid;
105 my ($bookseller) = GetBookSellerFromId
($booksellerid);
107 if ( !$bookseller ) {
108 $template->param( NO_BOOKSELLER
=> 1 );
112 # get librarian branch...
113 if ( C4
::Context
->preference("IndependantBranches") ) {
114 my $userenv = C4
::Context
->userenv;
115 unless ( $userenv->{flags
} == 1 ) {
116 my $validtest = ( $basket->{creationdate
} eq '' )
117 || ( $userenv->{branch
} eq $basket->{branch
} )
118 || ( $userenv->{branch
} eq '' )
119 || ( $basket->{branch
} eq '' );
120 unless ($validtest) {
121 print $query->redirect("../mainpage.pl");
127 # if new basket, pre-fill infos
128 $basket->{creationdate
} = "" unless ( $basket->{creationdate
} );
129 $basket->{authorisedby
} = $loggedinuser unless ( $basket->{authorisedby
} );
132 "loggedinuser: $loggedinuser; creationdate: %s; authorisedby: %s",
133 $basket->{creationdate
}, $basket->{authorisedby
};
135 my @results = GetOrders
( $basketno, $sort );
136 my $count = scalar @results;
138 my $sub_total; # total of line totals
139 my $grand_total; # $subttotal + $gist
141 # my $line_total_est; # total of each line
142 my $sub_total_est; # total of line totals
143 my $sub_total_rrp; # total of line totals
144 my $grand_total_est; # $subttotal + $gist
148 for ( my $i = 0 ; $i < $count ; $i++ ) {
149 my $rrp = $results[$i]->{'listprice'};
150 my $qty = $results[$i]->{'quantity'};
151 $rrp = ConvertCurrency
( $results[$i]->{'currency'}, $rrp );
152 $sub_total_rrp += $qty * $results[$i]->{'rrp'};
153 my $line_total = $qty * $results[$i]->{'ecost'};
154 # FIXME: what about the "actual cost" field?
155 $sub_total += $line_total;
157 my %line = %{ $results[$i] };
158 ($i%2) and $line{toggle
} = 1;
159 $line{order_received
}= ( $qty eq $results[$i]->{'quantityreceived'} );
160 $line{basketno
} = $basketno;
162 $line{rrp
} = sprintf( "%.2f", $line{'rrp'} );
163 $line{ecost
} = sprintf( "%.2f", $line{'ecost'} );
164 $line{line_total
} = sprintf( "%.2f", $line_total );
166 push @books_loop, \
%line;
168 my $prefgist = C4
::Context
->preference("gist") || 0;
169 my $gist = $sub_total * $prefgist;
170 my $gist_rrp = $sub_total_rrp * $prefgist;
171 $grand_total = $sub_total_est = $sub_total;
172 $grand_total_est = $sub_total_est; # FIXME: Too many things that are ALL the SAME
174 if ($temp = $bookseller->{'listincgst'}) {
175 $template->param(listincgst
=> $temp);
178 $grand_total += $gist;
179 $grand_total_est += $sub_total_est * $prefgist; # same thing as += gist
181 if ($temp = $bookseller->{'discount'}) {
182 $template->param(discount
=> sprintf( "%.2f", $temp ));
185 basketno
=> $basketno,
186 creationdate
=> format_date
( $basket->{creationdate
} ),
187 authorisedby
=> $basket->{authorisedby
},
188 authorisedbyname
=> $basket->{authorisedbyname
},
189 closedate
=> format_date
( $basket->{closedate
} ),
190 active
=> $bookseller->{'active'},
191 booksellerid
=> $bookseller->{'id'},
192 name
=> $bookseller->{'name'},
193 address1
=> $bookseller->{'address1'},
194 address2
=> $bookseller->{'address2'},
195 address3
=> $bookseller->{'address3'},
196 address4
=> $bookseller->{'address4'},
197 entrydate
=> format_date
( $results[0]->{'entrydate'} ),
198 books_loop
=> \
@books_loop,
199 sort_loop
=> \
@sort_loop,
201 gist
=> $gist ?
sprintf( "%.2f", $gist ) : 0,
202 gist_rate
=> sprintf( "%.2f", $prefgist * 100) . '%',
203 gist_est
=> sprintf( "%.2f", $sub_total_est * $prefgist ),
204 gist_rrp
=> sprintf( "%.2f", $gist_rrp),
205 sub_total
=> sprintf( "%.2f", $sub_total ),
206 grand_total
=> sprintf( "%.2f", $grand_total ),
207 sub_total_est
=> sprintf( "%.2f", $sub_total_est),
208 grand_total_est
=> sprintf( "%.2f", $grand_total_est),
209 sub_total_rrp
=> sprintf( "%.2f", $sub_total_rrp),
210 grand_total_rrp
=> sprintf( "%.2f", $sub_total_rrp + $gist_rrp),
211 currency
=> $bookseller->{'listprice'},
212 qty_total
=> $qty_total,
216 output_html_with_http_headers
$query, $cookie, $template->output;