- $price = $num->unformat_number($price);
- }
- if ($price){
- $orderinfo{'listprice'} = $price;
- eval {
- require C4::Acquisition;
- import C4::Acquisition qw/GetBasket/;
- };
- if ($@){
- croak $@;
- }
- eval {
- require C4::Bookseller;
- import C4::Bookseller qw/GetBookSellerFromId/;
- };
- if ($@){
- croak $@;
- }
- my $basket = GetBasket( $orderinfo{basketno} );
- my $bookseller = GetBookSellerFromId( $basket->{booksellerid} );
- my $gst = $bookseller->{gstrate} || C4::Context->preference("gist") || 0;
- $orderinfo{'unitprice'} = $orderinfo{listprice} - ( $orderinfo{listprice} * ( $bookseller->{discount} / 100 ) );
- $orderinfo{'ecost'} = $orderinfo{unitprice};
+ # in France, the cents separator is the , but sometimes, ppl use a .
+ # in this case, the price will be x100 when unformatted ! Replace the . by a , to get a proper price calculation
+ $price =~ s/\./,/ if C4::Context->preference("CurrencyFormat") eq "FR";
+ $price = Koha::Number::Price->new($price)->unformat;
+ $orderinfo{gstrate} = $bookseller->{gstrate};
+ my $c = $c_discount ? $c_discount : $bookseller->{discount} / 100;
+ if ( $bookseller->{listincgst} ) {
+ if ( $c_discount ) {
+ $orderinfo{ecost} = $price;
+ $orderinfo{rrp} = $orderinfo{ecost} / ( 1 - $c );
+ } else {
+ $orderinfo{ecost} = $price * ( 1 - $c );
+ $orderinfo{rrp} = $price;
+ }
+ } else {
+ if ( $c_discount ) {
+ $orderinfo{ecost} = $price / ( 1 + $orderinfo{gstrate} );
+ $orderinfo{rrp} = $orderinfo{ecost} / ( 1 - $c );
+ } else {
+ $orderinfo{rrp} = $price / ( 1 + $orderinfo{gstrate} );
+ $orderinfo{ecost} = $orderinfo{rrp} * ( 1 - $c );
+ }
+ }
+ $orderinfo{listprice} = $orderinfo{rrp} / $cur->{rate};
+ $orderinfo{unitprice} = $orderinfo{ecost};
+ $orderinfo{total} = $orderinfo{ecost} * $c_quantity;