0% found this document useful (0 votes)
22 views1 page

Sales Salon Obat Per Perawatan

This SQL query summarizes sales data from a transaction table including date, store, product, sales quantity, sales amount, cost of goods sold, and other attributes. It groups the data by date, store, product, and product description.

Uploaded by

ridwan maulana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views1 page

Sales Salon Obat Per Perawatan

This SQL query summarizes sales data from a transaction table including date, store, product, sales quantity, sales amount, cost of goods sold, and other attributes. It groups the data by date, store, product, and product description.

Uploaded by

ridwan maulana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

SELECT TDate,StoreCode, StoreName, ProductCode, ReffCode,

ProductDesc,BrandCode,BrandDesc,`TypeCode`,`TypeDesc`,
ObatID, ObatDesc, ObatTypeCode, ObatTypeDesc,
SalesPrice, SUM(SalesQty) AS TSalesQty, (SUM(SalesQty)*ObatQty) AS TObatQty,
ROUND(SUM(HppObat),0) AS TObatCOGS,
SUM(SalesTotal) AS TSales, ROUND(SUM(SalesCOGS),0) AS TCOGS, SUM(SalesDisc)
AS SalesDisc
FROM
(
SELECT DATE_FORMAT(trxh.TransDate,'%d-%m-%Y') AS TDate,
trxh.StoreCode,str.StoreName ,trxd.ProductCode, prd.reffCode, prd.ProductDesc,
prd.`BrandCode`,pd.`BrandDesc`,IFNULL(trxd.`SalesDisc`,0) AS
SalesDisc, trxd.`SalesPrice`,
IFNULL(vObat.ItemID, '') AS ObatID, IFNULL(vObat.ProductDesc,'')
AS ObatDesc, IFNULL(vObat.Qty,0) AS ObatQty,
vObat.HppObat AS HppObat,
IFNULL(vObat.SizeCode,'') AS ObatSC, IFNULL(vObat.TypeCode,'') AS
ObatTypeCode, IFNULL(vObat.TypeDesc, '') AS ObatTypeDesc
,(CASE WHEN trxd.SalesType IN ('S') THEN trxd.SalesQty
WHEN trxd.SalesType IN ('R') THEN trxd.SalesQty * -1
END ) AS SalesQty ,
(CASE WHEN trxd.SalesType IN ('S') THEN trxd.SalesTotal
WHEN trxd.SalesType IN ('R') THEN trxd.SalesTotal * -
1 END ) AS SalesTotal ,
(CASE WHEN trxd.SalesType IN ('S') THEN (trxd.SalesCOGS *
trxd.SalesQty)
WHEN trxd.SalesType IN ('R') THEN (trxd.SalesCOGS *
trxd.SalesQty) * -1 END ) AS SalesCOGS ,ms.`TypeCode` ,ms.`TypeDesc`
FROM trx_sales_product trxd
LEFT JOIN trx_sales trxh ON trxh.TransNo = trxd.TransNo
LEFT JOIN (
SELECT a.`StoreCode` , a.`StoreName`
FROM mst_store a
UNION ALL
SELECT b.`WhseCode` AS StoreCode, b.`WhseName` AS StoreName
FROM `mst_warehouse` b
) str ON str.StoreCode = trxh.StoreCode
LEFT JOIN mst_product prd ON prd.ProductID = trxd.ProductCode
LEFT JOIN `mst_productbrand` pd ON pd.BrandCode = prd.BrandCode
LEFT JOIN `mst_producttype` ms ON ms.typecode = prd.typecode
LEFT JOIN
(
SELECT ch.ProductID, ch.ItemID, de.ProductDesc, ch.Qty,
ch.SizeCode, de.TypeCode, ty.TypeDesc, ch.`COGS` AS HppObat
FROM mst_product_child ch
LEFT JOIN mst_product de ON ch.ItemID = de.ProductID
LEFT JOIN mst_producttype ty ON de.TypeCode = ty.TypeCode
-- left join `mst_priceproduct` price on
ch.`ItemID`=price.`ProductID`
) vObat ON vObat.ProductId = trxd.ProductCode
WHERE DATE(trxh.TransDate) BETWEEN STR_TO_DATE('19-06-2023','%d-%m-%Y')
AND STR_TO_DATE('19-07-2023','%d-%m-%Y')
) vTrx
GROUP BY TDate, StoreCOde, ProductCode, ReffCode, ProductDesc , ObatID,
ObatDesc
ORDER BY TDate,StoreCOde,ProductCode, ReffCode, ProductDesc ASC ;

SET sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy