select wsid, pdid, basedjo, busid, bname, scid, sname from
(
select ws.id as wsid, JO.id as pdid, 1 as basedjo, JO.BUSORDER_ID as busid, BO.NAME AS BNAME, JON.STORECARD_ID as scid, SC.NAME AS SNAME
from PLMWorkScheduleItems ws
INNER JOIN PLMJobOrdersRoutines JOR ON (JOR.id = ws.JORoutine_id)
INNER JOIN PLMJOOutputItems JOO ON (JOR.parent_id = JOO.ID)
INNER JOIN PLMJONodes JON ON (JOO.owner_id = JON.ID)
INNER JOIN PLMJobOrders JO ON (JON.parent_id = JO.ID)
INNER JOIN PLMJOSetParsQueues JOQ ON (JO.docqueue_id = JOQ.docqueue_id)
INNER JOIN PLMWorkPlaces WP ON (ws.Workplace_id = WP.ID)
LEFT JOIN BUSORDERS BO ON (JO.BUSORDER_ID = BO.ID)
INNER JOIN STORECARDS SC ON (JON.STORECARD_ID = SC.ID)
where (ws.status = 2)
and (not exists(select id from PLMWorkScheduleItemFixes where Parent_ID = ws.ID)
or ((select min(BeginTime) from PLMWorkScheduleItemFixes where Parent_ID = ws.ID) < :CalcDate))
and (ws.PlannedQuantity > (SELECT COALESCE(sum(Quantity),0) from PLMOperationWSIs WHERE WorkScheduleItem_id = ws.ID))
and WP.CRPPlan > 0
and JOR.Planned = 'A'
and JOQ.InPlan = 'A'
and JOR.TAC+JOR.TBC > 0
) A
order by basedjo, pdid, wsid
Generated by ABRA Software a.s. 27.10.2021 16:34:49