query receitas updated
unknown
plain_text
a year ago
2.3 kB
6
Indexable
$this->db->query("
SELECT (
COALESCE(SUM(tbl_sales_product.subtotal), 0)
+ COALESCE(SUM(tbl_repair_product.subtotal), 0)
- COALESCE(SUM(tbl_returns_product.subtotal), 0)
) - (
COALESCE(SUM(
CASE
WHEN tbl_sales_product.total_tax_val = 0 THEN 0
WHEN tbl_sales_product.second_hand = 1 THEN
(tbl_sales_product.subtotal - tbl_sales_product.cost_price)
- ((tbl_sales_product.subtotal - tbl_sales_product.cost_price) / 1.23)
ELSE
tbl_sales_product.subtotal - (tbl_sales_product.subtotal / 1.23)
END
), 0)
+ COALESCE(SUM(
CASE
WHEN tbl_repair_product.total_tax_val = 0 THEN 0
WHEN tbl_repair_product.second_hand = 1 THEN
(tbl_repair_product.subtotal - tbl_repair_product.cost_price)
- ((tbl_repair_product.subtotal - tbl_repair_product.cost_price) / 1.23)
ELSE
tbl_repair_product.subtotal - (tbl_repair_product.subtotal / 1.23)
END
), 0)
- COALESCE(SUM(
CASE
WHEN tbl_returns_product.total_tax_val = 0 THEN 0
WHEN tbl_returns_product.second_hand = 1 THEN
(tbl_returns_product.subtotal - tbl_returns_product.cost_price)
- ((tbl_returns_product.subtotal - tbl_returns_product.cost_price) / 1.23)
ELSE
tbl_returns_product.subtotal - (tbl_returns_product.subtotal / 1.23)
END
), 0)
) AS final_total
FROM isellpt_isystem_new.tbl_sales_product AS tbl_sales_product
LEFT JOIN isellpt_isystem_new.tbl_sales AS tbl_sales ON tbl_sales_product.sales_id = tbl_sales.id AND tbl_sales.status NOT LIKE '%delete%'
LEFT JOIN isellpt_isystem_new.tbl_repair_product AS tbl_repair_product ON tbl_repair_product.is_deleted = 0
LEFT JOIN isellpt_isystem_new.tbl_returns_product AS tbl_returns_product ON tbl_returns_product.return_id = tbl_sales.return_id
LEFT JOIN isellpt_isystem_new.tbl_returns AS tbl_returns ON tbl_returns_product.return_id = tbl_returns.id AND tbl_returns.status NOT LIKE '%delete%'
")->row();
Editor is loading...
Leave a Comment