Cizz22 3 months ago
parent 7a9d5aacab
commit fd97475ca5

@ -155,7 +155,7 @@ ORDER BY avg_cost DESC;
async def get_oh_cost_summary(collector_db: CollectorDbSession, last_oh_date:datetime, upcoming_oh_date:datetime): async def get_oh_cost_summary(collector_db: CollectorDbSession, last_oh_date:datetime, upcoming_oh_date:datetime):
query = text(""" query = text("""
part_costs AS ( WITH part_costs AS (
SELECT SELECT
wm.wonum, wm.wonum,
SUM(wm.itemqty * COALESCE(wm.inv_avgcost, po.unit_cost, 0)) AS parts_total_cost SUM(wm.itemqty * COALESCE(wm.inv_avgcost, po.unit_cost, 0)) AS parts_total_cost
@ -172,31 +172,25 @@ async def get_oh_cost_summary(collector_db: CollectorDbSession, last_oh_date:dat
SELECT SELECT
w.wonum, w.wonum,
w.asset_location, w.asset_location,
(COALESCE(pc.parts_total_cost, 0)) AS total_wo_cost -- Use mat_cost_max if parts_total_cost = 0
CASE
WHEN COALESCE(pc.parts_total_cost, 0) = 0 THEN COALESCE(w.mat_cost_max , 0)
ELSE COALESCE(pc.parts_total_cost, 0)
END AS total_wo_cost
FROM wo_staging_maximo_2 w FROM wo_staging_maximo_2 w
LEFT JOIN part_costs pc LEFT JOIN part_costs pc
ON w.wonum = pc.wonum ON w.wonum = pc.wonum
WHERE WHERE
w.worktype = 'OH' w.worktype = 'OH'
AND w.asset_system IN (
'HPB', 'AH', 'APC', 'SCR', 'CL', 'DM', 'CRH', 'ASH', 'BAD', 'DS', 'WTP',
'MT', 'SUP', 'DCS', 'FF', 'EG', 'AI', 'SPS', 'EVM', 'SCW', 'KLH', 'CH',
'TUR', 'LOT', 'HRH', 'ESP', 'CAE', 'GMC', 'BFT', 'LSH', 'CHB', 'BSS',
'LOS', 'LPB', 'SAC', 'CP', 'EHS', 'RO', 'GG', 'MS', 'CW', 'SO', 'ATT',
'AFG', 'EHB', 'RP', 'FO', 'PC', 'APE', 'AF', 'DMW', 'BRS', 'GEN', 'ABS',
'CHA', 'TR', 'H2', 'BDW', 'LOM', 'ACR', 'AL', 'FW', 'COND', 'CCCW', 'IA',
'GSS', 'BOL', 'SSB', 'CO', 'OA', 'CTH-UPD', 'AS', 'DP'
)
AND w.reportdate IS NOT NULL AND w.reportdate IS NOT NULL
AND w.actstart IS NOT NULL AND w.actstart IS NOT NULL
AND w.actfinish IS NOT NULL AND w.actfinish IS NOT NULL
AND w.asset_unit IN ('3', '00') AND w.asset_unit IN ('3', '00')
AND w.reportdate >= '2019-01-01'
AND w.wonum NOT LIKE 'T%' AND w.wonum NOT LIKE 'T%'
) )
SELECT SELECT
asset_location, asset_location,
AVG(total_wo_cost) as avg_cost AVG(total_wo_cost) AS avg_cost
FROM wo_costs FROM wo_costs
GROUP BY asset_location GROUP BY asset_location
ORDER BY COUNT(wonum) DESC; ORDER BY COUNT(wonum) DESC;

Loading…
Cancel
Save