Lines 238-358
if ( $op eq 'delete_confirm' ) {
Link Here
|
238 |
"loggedinuser: $loggedinuser; creationdate: %s; authorisedby: %s", |
238 |
"loggedinuser: $loggedinuser; creationdate: %s; authorisedby: %s", |
239 |
$basket->{creationdate}, $basket->{authorisedby}; |
239 |
$basket->{creationdate}, $basket->{authorisedby}; |
240 |
|
240 |
|
241 |
#to get active currency |
241 |
#to get active currency |
242 |
my $cur = GetCurrency(); |
242 |
my $cur = GetCurrency(); |
243 |
|
243 |
|
244 |
|
244 |
|
245 |
my @results = GetOrders( $basketno ); |
245 |
my @results = GetOrders( $basketno ); |
246 |
|
|
|
247 |
my $gist = $bookseller->{gstrate} // C4::Context->preference("gist") // 0; |
248 |
$gist = 0 if $gist == 0.0000; |
249 |
my $discount = $bookseller->{'discount'} / 100; |
250 |
my $total_rrp = 0; # RRP Total, its value will be assigned to $total_rrp_gsti or $total_rrp_gste depending of $bookseller->{'listincgst'} |
251 |
my $total_rrp_gsti = 0; # RRP Total, GST included |
252 |
my $total_rrp_gste = 0; # RRP Total, GST excluded |
253 |
my $gist_rrp = 0; |
254 |
my $total_rrp_est = 0; |
255 |
|
256 |
my $qty_total; |
257 |
my @books_loop; |
246 |
my @books_loop; |
258 |
my $suggestion; |
|
|
259 |
|
247 |
|
260 |
for my $order ( @results ) { |
248 |
my @book_foot_loop; |
261 |
my $rrp = $order->{'listprice'} || 0; |
249 |
my %foot; |
262 |
my $qty = $order->{'quantity'} || 0; |
250 |
my $total_quantity = 0; |
263 |
if (!defined $order->{quantityreceived}) { |
251 |
my $total_gste = 0; |
264 |
$order->{quantityreceived} = 0; |
252 |
my $total_gsti = 0; |
265 |
} |
253 |
my $total_gstvalue = 0; |
266 |
for ( qw(rrp ecost quantityreceived)) { |
254 |
for my $order (@results) { |
267 |
if (!defined $order->{$_}) { |
255 |
my $line = get_order_infos( $order, $bookseller); |
268 |
$order->{$_} = 0; |
256 |
if ( $line->{uncertainprice} ) { |
269 |
} |
|
|
270 |
} |
271 |
|
272 |
my $budget = GetBudget( $order->{'budget_id'} ); |
273 |
$rrp = ConvertCurrency( $order->{'currency'}, $rrp ); |
274 |
|
275 |
$total_rrp += $qty * $order->{'rrp'}; |
276 |
my $line_total = $qty * $order->{'ecost'}; |
277 |
$total_rrp_est += $qty * $order->{'ecost'}; |
278 |
# FIXME: what about the "actual cost" field? |
279 |
$qty_total += $qty; |
280 |
my %line = %{ $order }; |
281 |
my $biblionumber = $order->{'biblionumber'}; |
282 |
my $countbiblio = CountBiblioInOrders($biblionumber); |
283 |
my $ordernumber = $order->{'ordernumber'}; |
284 |
my @subscriptions = GetSubscriptionsId ($biblionumber); |
285 |
my $itemcount = GetItemsCount($biblionumber); |
286 |
my $holds = GetHolds ($biblionumber); |
287 |
my @items = GetItemnumbersFromOrder( $ordernumber ); |
288 |
my $itemholds; |
289 |
foreach my $item (@items){ |
290 |
my $nb = GetItemHolds($biblionumber, $item); |
291 |
if ($nb){ |
292 |
$itemholds += $nb; |
293 |
} |
294 |
} |
295 |
# if the biblio is not in other orders and if there is no items elsewhere and no subscriptions and no holds we can then show the link "Delete order and Biblio" see bug 5680 |
296 |
$line{can_del_bib} = 1 if $countbiblio <= 1 && $itemcount == scalar @items && !(@subscriptions) && !($holds); |
297 |
$line{items} = ($itemcount) - (scalar @items); |
298 |
$line{left_item} = 1 if $line{items} >= 1; |
299 |
$line{left_biblio} = 1 if $countbiblio > 1; |
300 |
$line{biblios} = $countbiblio - 1; |
301 |
$line{left_subscription} = 1 if scalar @subscriptions >= 1; |
302 |
$line{subscriptions} = scalar @subscriptions; |
303 |
($holds >= 1) ? $line{left_holds} = 1 : $line{left_holds} = 0; |
304 |
$line{left_holds_on_order} = 1 if $line{left_holds}==1 && ($line{items} == 0 || $itemholds ); |
305 |
$line{holds} = $holds; |
306 |
$line{holds_on_order} = $itemholds?$itemholds:$holds if $line{left_holds_on_order}; |
307 |
$line{order_received} = ( $qty == $order->{'quantityreceived'} ); |
308 |
$line{basketno} = $basketno; |
309 |
$line{budget_name} = $budget->{budget_name}; |
310 |
$line{rrp} = sprintf( "%.2f", $line{'rrp'} ); |
311 |
$line{ecost} = sprintf( "%.2f", $line{'ecost'} ); |
312 |
$line{line_total} = sprintf( "%.2f", $line_total ); |
313 |
if ($line{uncertainprice}) { |
314 |
$template->param( uncertainprices => 1 ); |
257 |
$template->param( uncertainprices => 1 ); |
315 |
$line{rrp} .= ' (Uncertain)'; |
|
|
316 |
} |
258 |
} |
317 |
if ($line{'title'}){ |
259 |
|
318 |
my $volume = $order->{'volume'}; |
260 |
push @books_loop, $line; |
319 |
my $seriestitle = $order->{'seriestitle'}; |
261 |
|
320 |
$line{'title'} .= " / $seriestitle" if $seriestitle; |
262 |
$foot{$$line{gstgsti}}{gstgsti} = $$line{gstgsti}; |
321 |
$line{'title'} .= " / $volume" if $volume; |
263 |
$foot{$$line{gstgsti}}{gstvalue} += $$line{gstvalue}; |
322 |
} else { |
264 |
$total_gstvalue += $$line{gstvalue}; |
323 |
$line{'title'} = "Deleted bibliographic notice, can't find title."; |
265 |
$foot{$$line{gstgsti}}{quantity} += $$line{quantity}; |
324 |
} |
266 |
$total_quantity += $$line{quantity}; |
325 |
|
267 |
$foot{$$line{gstgsti}}{totalgste} += $$line{totalgste}; |
326 |
$suggestion = GetSuggestionInfoFromBiblionumber($line{biblionumber}); |
268 |
$total_gste += $$line{totalgste}; |
327 |
$line{suggestionid} = $suggestion->{suggestionid}; |
269 |
$foot{$$line{gstgsti}}{totalgsti} += $$line{totalgsti}; |
328 |
$line{surnamesuggestedby} = $suggestion->{surnamesuggestedby}; |
270 |
$total_gsti += $$line{totalgsti}; |
329 |
$line{firstnamesuggestedby} = $suggestion->{firstnamesuggestedby}; |
|
|
330 |
|
331 |
push @books_loop, \%line; |
332 |
} |
271 |
} |
333 |
|
272 |
|
334 |
my $total_est_gste; |
273 |
push @book_foot_loop, map {$_} values %foot; |
335 |
my $total_est_gsti; |
274 |
|
336 |
my $gist_est; |
275 |
# Get cancelled orders |
337 |
if ($gist){ # if we have GST |
276 |
@results = GetCancelledOrders($basketno); |
338 |
if ( $bookseller->{'listincgst'} ) { # if prices already includes GST |
277 |
my @cancelledorders_loop; |
339 |
$total_rrp_gsti = $total_rrp; # we know $total_rrp_gsti |
278 |
for my $order (@results) { |
340 |
$total_rrp_gste = $total_rrp_gsti / ( $gist + 1 ); # and can reverse compute other values |
279 |
my $line = get_order_infos( $order, $bookseller); |
341 |
$gist_rrp = $total_rrp_gsti - $total_rrp_gste; # |
280 |
push @cancelledorders_loop, $line; |
342 |
$total_est_gste = $total_rrp_gste - ( $total_rrp_gste * $discount ); |
281 |
} |
343 |
$total_est_gsti = $total_rrp_est; |
|
|
344 |
} else { # if prices does not include GST |
345 |
$total_rrp_gste = $total_rrp; # then we use the common way to compute other values |
346 |
$gist_rrp = $total_rrp_gste * $gist; # |
347 |
$total_rrp_gsti = $total_rrp_gste + $gist_rrp; # |
348 |
$total_est_gste = $total_rrp_est; |
349 |
$total_est_gsti = $total_rrp_gsti - ( $total_rrp_gsti * $discount ); |
350 |
} |
351 |
$gist_est = $gist_rrp - ( $gist_rrp * $discount ); |
352 |
} else { |
353 |
$total_rrp_gsti = $total_rrp; |
354 |
$total_est_gsti = $total_rrp_est; |
355 |
} |
356 |
|
282 |
|
357 |
my $contract = &GetContract($basket->{contractnumber}); |
283 |
my $contract = &GetContract($basket->{contractnumber}); |
358 |
my @orders = GetOrders($basketno); |
284 |
my @orders = GetOrders($basketno); |
Lines 391-408
my $total_est_gste;
Link Here
|
391 |
booksellerid => $bookseller->{'id'}, |
317 |
booksellerid => $bookseller->{'id'}, |
392 |
name => $bookseller->{'name'}, |
318 |
name => $bookseller->{'name'}, |
393 |
books_loop => \@books_loop, |
319 |
books_loop => \@books_loop, |
|
|
320 |
book_foot_loop => \@book_foot_loop, |
394 |
cancelledorders_loop => \@cancelledorders, |
321 |
cancelledorders_loop => \@cancelledorders, |
395 |
gist_rate => sprintf( "%.2f", $gist * 100 ) . '%', |
322 |
total_quantity => $total_quantity, |
396 |
total_rrp_gste => sprintf( "%.2f", $total_rrp_gste ), |
323 |
total_gste => sprintf( "%.2f", $total_gste ), |
397 |
total_est_gste => sprintf( "%.2f", $total_est_gste ), |
324 |
total_gsti => sprintf( "%.2f", $total_gsti ), |
398 |
gist_est => sprintf( "%.2f", $gist_est ), |
325 |
total_gstvalue => sprintf( "%.2f", $total_gstvalue ), |
399 |
gist_rrp => sprintf( "%.2f", $gist_rrp ), |
326 |
currency => $cur->{'currency'}, |
400 |
total_rrp_gsti => sprintf( "%.2f", $total_rrp_gsti ), |
327 |
listincgst => $bookseller->{listincgst}, |
401 |
total_est_gsti => sprintf( "%.2f", $total_est_gsti ), |
|
|
402 |
# currency => $bookseller->{'listprice'}, |
403 |
currency => $cur->{'currency'}, |
404 |
qty_total => $qty_total, |
405 |
GST => $gist, |
406 |
basketgroups => $basketgroups, |
328 |
basketgroups => $basketgroups, |
407 |
grouped => $basket->{basketgroupid}, |
329 |
grouped => $basket->{basketgroupid}, |
408 |
unclosable => @orders ? 0 : 1, |
330 |
unclosable => @orders ? 0 : 1, |
Lines 410-413
my $total_est_gste;
Link Here
|
410 |
); |
332 |
); |
411 |
} |
333 |
} |
412 |
|
334 |
|
|
|
335 |
sub get_order_infos { |
336 |
my $order = shift; |
337 |
my $bookseller = shift; |
338 |
my $qty = $order->{'quantity'} || 0; |
339 |
if ( !defined $order->{quantityreceived} ) { |
340 |
$order->{quantityreceived} = 0; |
341 |
} |
342 |
my $budget = GetBudget( $order->{'budget_id'} ); |
343 |
|
344 |
my %line = %{ $order }; |
345 |
$line{order_received} = ( $qty == $order->{'quantityreceived'} ); |
346 |
$line{basketno} = $basketno; |
347 |
$line{budget_name} = $budget->{budget_name}; |
348 |
$line{rrp} = ConvertCurrency( $order->{'currency'}, $line{rrp} ); # FIXME from comm |
349 |
if ( $bookseller->{'listincgst'} ) { |
350 |
$line{rrpgsti} = sprintf( "%.2f", $line{rrp} ); |
351 |
$line{gstgsti} = sprintf( "%.2f", $line{gstrate} * 100 ); |
352 |
$line{rrpgste} = sprintf( "%.2f", $line{rrp} / ( 1 + ( $line{gstgsti} / 100 ) ) ); |
353 |
$line{gstgste} = sprintf( "%.2f", $line{gstgsti} / ( 1 + ( $line{gstgsti} / 100 ) ) ); |
354 |
$line{ecostgsti} = sprintf( "%.2f", $line{ecost} ); |
355 |
$line{ecostgste} = sprintf( "%.2f", $line{ecost} / ( 1 + ( $line{gstgsti} / 100 ) ) ); |
356 |
$line{gstvalue} = sprintf( "%.2f", ( $line{ecostgsti} - $line{ecostgste} ) * $line{quantity}); |
357 |
$line{totalgste} = sprintf( "%.2f", $order->{quantity} * $line{ecostgste} ); |
358 |
$line{totalgsti} = sprintf( "%.2f", $order->{quantity} * $line{ecostgsti} ); |
359 |
} else { |
360 |
$line{rrpgsti} = sprintf( "%.2f", $line{rrp} * ( 1 + ( $line{gstrate} ) ) ); |
361 |
$line{rrpgste} = sprintf( "%.2f", $line{rrp} ); |
362 |
$line{gstgsti} = sprintf( "%.2f", $line{gstrate} * 100 ); |
363 |
$line{gstgste} = sprintf( "%.2f", $line{gstrate} * 100 ); |
364 |
$line{ecostgsti} = sprintf( "%.2f", $line{ecost} * ( 1 + ( $line{gstrate} ) ) ); |
365 |
$line{ecostgste} = sprintf( "%.2f", $line{ecost} ); |
366 |
$line{gstvalue} = sprintf( "%.2f", ( $line{ecostgsti} - $line{ecostgste} ) * $line{quantity}); |
367 |
$line{totalgste} = sprintf( "%.2f", $order->{quantity} * $line{ecostgste} ); |
368 |
$line{totalgsti} = sprintf( "%.2f", $order->{quantity} * $line{ecostgsti} ); |
369 |
} |
370 |
|
371 |
if ( $line{uncertainprice} ) { |
372 |
$line{rrpgste} .= ' (Uncertain)'; |
373 |
} |
374 |
if ( $line{'title'} ) { |
375 |
my $volume = $order->{'volume'}; |
376 |
my $seriestitle = $order->{'seriestitle'}; |
377 |
$line{'title'} .= " / $seriestitle" if $seriestitle; |
378 |
$line{'title'} .= " / $volume" if $volume; |
379 |
} else { |
380 |
$line{'title'} = "Deleted bibliographic notice, can't find title."; |
381 |
} |
382 |
|
383 |
my $biblionumber = $order->{'biblionumber'}; |
384 |
my $countbiblio = CountBiblioInOrders($biblionumber); |
385 |
my $ordernumber = $order->{'ordernumber'}; |
386 |
my @subscriptions = GetSubscriptionsId ($biblionumber); |
387 |
my $itemcount = GetItemsCount($biblionumber); |
388 |
my $holds = GetHolds ($biblionumber); |
389 |
my @items = GetItemnumbersFromOrder( $ordernumber ); |
390 |
my $itemholds; |
391 |
foreach my $item (@items){ |
392 |
my $nb = GetItemHolds($biblionumber, $item); |
393 |
if ($nb){ |
394 |
$itemholds += $nb; |
395 |
} |
396 |
} |
397 |
# if the biblio is not in other orders and if there is no items elsewhere and no subscriptions and no holds we can then show the link "Delete order and Biblio" see bug 5680 |
398 |
$line{can_del_bib} = 1 if $countbiblio <= 1 && $itemcount == scalar @items && !(@subscriptions) && !($holds); |
399 |
$line{items} = ($itemcount) - (scalar @items); |
400 |
$line{left_item} = 1 if $line{items} >= 1; |
401 |
$line{left_biblio} = 1 if $countbiblio > 1; |
402 |
$line{biblios} = $countbiblio - 1; |
403 |
$line{left_subscription} = 1 if scalar @subscriptions >= 1; |
404 |
$line{subscriptions} = scalar @subscriptions; |
405 |
($holds >= 1) ? $line{left_holds} = 1 : $line{left_holds} = 0; |
406 |
$line{left_holds_on_order} = 1 if $line{left_holds}==1 && ($line{items} == 0 || $itemholds ); |
407 |
$line{holds} = $holds; |
408 |
$line{holds_on_order} = $itemholds?$itemholds:$holds if $line{left_holds_on_order}; |
409 |
|
410 |
|
411 |
my $suggestion = GetSuggestionInfoFromBiblionumber($line{biblionumber}); |
412 |
$line{suggestionid} = $$suggestion{suggestionid}; |
413 |
$line{surnamesuggestedby} = $$suggestion{surnamesuggestedby}; |
414 |
$line{firstnamesuggestedby} = $$suggestion{firstnamesuggestedby}; |
415 |
|
416 |
return \%line; |
417 |
} |
418 |
|
413 |
output_html_with_http_headers $query, $cookie, $template->output; |
419 |
output_html_with_http_headers $query, $cookie, $template->output; |