I have following table "Cart" & contains the following columns in mysql:
CartID, ProductID, ProductPrice, ProductTax (%), ProductQty
ProductTax is in Percentage but value stored as number/int.
How do i calculate total tax of all products in the cart.
So each product must use its own "ProductTax" Rate ie. in %tage .
(1) example contain 1 product in cart.
ProductPrice: 200 & ProductTax 18%. & ProductQTY:1
So "totaltax" here is: 36.
(2) example contains 2 products in cart
1- ProductPrice: 300 & ProductTax 18% & ProductQTY: 2
2- ProductPrice: 400 & ProductTax 20% & ProductQTY: 1
So for above example "totaltax" is : 108+80= 188
To calculate total tax of all products in the cart:
SELECT SUM((ProductPrice * ProductQty)* ProductTax/100) AS value_sum
FROM Cart
This solves it! – Webgen 10 secs ago edit
Related
I have below variable
quantity ($qty)
purchase price ($pp)
sale price ($sp)
commission 12% ($comm)
suggested sale price
the commission is calculated on the sale price for example if the sale price increase commission will increase too.
I want to calculate the Suggested sale price on a 10% profit ratio ($pr)
here is my code
$comm=12; //(commission 12%)
$pr=10; //(10% profit)
$percent = ((float)$sp/100)*(float)$comm;
$fees=round($percent,2);
$total=((float)$pp*(float)$qty)+(float)$fees;
$profit = ((float)$total/100)*(float)$pr;
$suggested = round(((float)$profit)+((float)$total),2);
I am calling this ajax function on button click, this will give few times different values on button click.
I think this is because when the sale price increase commission also increased based on that sale price.
there is no error in code only issue is it did't calculate correct value of sale price on first call, it need 2 or 3 calls to get correct value. how can I get correct value in first call.
First, a disclaimer: I’m a programmer, not an accountant.
So, thinking out loud for a few moments:
Define Terms
cogs: cost of goods sold (item cost)
sp: sales price
comm: commission
profit: profit
Formulas
profit = sales price - cogs - comm
profit = sales price * profitPercentage
comm = sales price * commPercentage
Substitute
sales price * profitPercentage = sales price - cogs - comm
For sake of example, let’s assume profit is 10% and commission is 15%
sales price * .10 = sales price - cogs - comm
we can then substitute commission
sales price * .10 = sales price - cogs - (sales price * .15)
Simplify
.1(sales price) = sales price - cogs - .15(sales price)
cogs = sales price - .1(sales price) - .15(sales price)
cogs = (1 - .1 - .15)(sales price)
cogs = (.75)(sales price)
sales price = cogs/.75
Test
cogs: $10
price: $13.33
comm: $2.00
profit: $1.33
Code
function calculateSalesPrice(float $cogs, float $commPercent, float $profitPercent) : float
{
$divisor = (1 - $commPercent - $profitPercent);
if($divisor <= 0) {
throw new Exception('Commission and Profit exceed 100%');
}
return round(($cogs/$divisor),2);
}
With this formula, both profit and commission use the sales price as their basis.
We know that magento2 has multiple prices type , for example special price, tier prices, group prices , if one prodcut has multiple price , the magento2 will show the minimum price .
Scenario 1:
Regular Price = 250
Special Price = 200
Group Price (NOT LOGGED) = 180
*** Result in product page: 180
Scenario 2:
Regular Price = 250
Special Price = 120
Group Price (NOT LOGGED) = 180
*** Result in product page: 120
So my question is how to ignore the minimum price , i want to set the group price highest priority , like below sample , i want to show price is 180
Regular Price = 250
Special Price = 120
Group Price (NOT LOGGED) = 180
i have been trying now 2 days and doing research about this but i din't find any solution for this
so i have 3 tables what i want is that if a product is having only single price then show that single price if the product is having multiple prices then show the min price and max price of that product.
so in product id number 2 is having 3 prices.
so if the product is having single price then each product will have their price
if product has multiple prices then display min price $ 19.00 __ $ 26.00 max price.
so how can i do this?? how can i display it on the page???
product (id, price)
1 1
2 2
3 3
product_has_price (product_id, price_id)
1 1
2 2
2 3
3 4
2 5
price (id, price)
1 14.00
2 19.00
3 24.00
4 35.00
5 26.00
thanks if anybody helps
select p.id
, case
when min(i.price) <> max(i.price) then
concat('$ ', min(i.price), '__ $ ', max(i.price))
else concat('$ ', min(i.price))
end as PriceDescription
from product p
join product_has_price php
on p.id = php.product_id
join price i
on i.id = php.price_id
group by
p.id
I have two columns in my database table products.
price discountpercent
100 10
200 70
My Query
SELECT * FROM products order by ?
How can i order by discounted price ?
Use:
ORDER BY price * (100 - discountpercent) / 100
Demo here
My Product table looks like
ID Type Product Code Product Name Price
1 all customers 56620000 Product A 219.68 €
2 all customers 56621000 Product B 4,351.91 €
3 all customers 56622000 Product C 110.98 €
4 155000 56622000 Product C 100.00 €
5 all customers 56626000 Product D 2,410.38 €
6 all customers 56772000 Product E 100.00 €
7 160000 56772000 Product E 90.00 €
If you notice row 3,4 and 6,7 has same product code but with different type and price. That means a product can have a price for all customer as well as for few specific customers. If a customer with customer id 155000 performs a search with product code 56622000, that customer will get price 100.00 € (see row number 4) not 110.98 € (see row number 3). But if that same customer performs a search with product code 56772000, he/she will get price 100.00 €(see row number 6) not 90.00 €(see row number 7). Because there is no specific price for that user for product code 56772000.
My Query: How to execute this operation using PHP and MySql from a single table.?
SELECT *
FROM product
WHERE ProductCode = 'x' AND
Type IN ('y', 'All Customers')
ORDER BY FIELD(Type, 'y', 'All Customers')
LIMIT 1
SQLFiddle Demo
Replace x and y with your desired value shown in the demo.
SELECT *
FROM Products
WHERE ProductCode = 'product_id' AND Type IN ('customer_id', 'All Customers')
ORDER BY Type
LIMIT 1
SELECT * FROM
(SELECT * FROM product
WHERE `Type` = '155000' and ProductCode = '56622000'
LIMIT 1
UNION
SELECT * FROM product
WHERE `Type` = 'all customers' and ProductCode = '56622000'
LIMIT 1) a
LIMIT 1;
SQL FIDDLE DEMO
Thanks for #491243 for the fiddle code.