sub get_Price { my $SupplierID = shift; my $SupplierPID = shift; # tax type 0,1,2 which could be different # depending on the country of the shop my $Tax = shift; # could be e.g. buying price or selling price my $Price_Type = shift; #if the request comes from a basket with amount in basket my $amount = shift || 0; #clientID is the shop/market my $ClientID = $STASH{ClientID}; my $return; my $cond = GX::SQL::Condition->new(); $cond->add("ClientID",'=',$ClientID); my $customer_cond = GX::SQL::Condition->new(); # customerID 10000 is a dummy for public prices $customer_cond->add("CustomerID",'=',10000); # if there are individual prices they are also considered $customer_cond->add("CustomerID",'=',$STASH{account}->{ID}) if $STASH{account}->{ID}; $customer_cond->bool('OR'); $cond->add($customer_cond); $cond->add("SupplierID",'=',$SupplierID); $cond->add("SupplierPID",'=',$SupplierPID); $cond->add("Price_Type",'=',$Price_Type); $cond->bool('AND'); my @prices; my $previous_price; my $udx_prices = $DB->table('UDX_Prices'); $udx_prices->select_options ("ORDER BY Amount ASC, Price ASC"); my $sth = $udx_prices->select([' Price_Type, Amount, Price, Discount, Rebate, Currency, Price_Quantity'], $cond); while (my $_ = $sth->fetchrow_hashref) { #calculate customer discount in percent if available $_->{Price_Discount} = sprintf("%0.2f", ($_->{Price} * ( $STASH{account}->{Discount} ) / 100)); $_->{Price} = sprintf("%0.2f", ($_->{Price} - $_->{Price_Discount} )); my ($new_price,$old_price); $old_price = $_->{Price} * 100 / $_->{Price_Quantity}; $_->{Price} = sprintf("%0.2f", ($_->{Price}) / $_->{Price_Quantity}); $new_price = $_->{Price} * 100; if ($old_price == $new_price) { $_->{Price_Quantity} = 1; } else { $_->{Price} = sprintf("%0.2f", ($old_price / 100)); } # if the previous price is smaller skip the price if ($previous_price->{Price} && $previous_price->{Price} <= $_->{Price}) { next; } # if the amount is the same as before skip the price next if $previous_price->{Amount} == $_->{Amount}; $_->{Tax} = $STASH{shop}->{'Local_Tax' . $Tax}; $_->{Gross_Price} = sprintf("%0.2f", ($_->{Price} * (100 + $STASH{shop}->{'Local_Tax' . $Tax}) / 100)); $_->{Tara} = sprintf("%0.2f", ($_->{Gross_Price} - $_->{Price})); $previous_price = $_; push @prices, $_; } $return->{prices} = \@prices; return $return; }