select wsid, pdid, basedjo, busid, bname, scid, sname, reqid 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, Req.ID AS reqid --bratri fixovanych DUKu VP
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 PLMProduceRequests Req ON (Req.JobOrder_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 in (0,1) and not exists(select id from PLMWorkScheduleItemFixes where Parent_ID = ws.ID))
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
and JO.id not In
( select iJO.id
from PLMWorkScheduleItems iws
INNER JOIN PLMJobOrdersRoutines iJOR ON (iJOR.id = iws.JORoutine_id)
INNER JOIN PLMJOOutputItems iJOO ON (iJOR.parent_id = iJOO.ID)
INNER JOIN PLMJONodes iJON ON (iJOO.owner_id = iJON.ID)
INNER JOIN PLMJobOrders iJO ON (iJON.parent_id = iJO.ID)
INNER JOIN PLMJOSetParsQueues iJOQ ON (iJO.docqueue_id = iJOQ.docqueue_id)
INNER JOIN PLMWorkPlaces iWP ON (iws.Workplace_id = iWP.ID)
where ((iws.status in (0,1) and exists(select id from PLMWorkScheduleItemFixes where Parent_ID = iws.ID)) or (iws.status = 2))
and (iws.PlannedQuantity > (SELECT COALESCE(sum(Quantity),0) from PLMOperationWSIs WHERE WorkScheduleItem_id = iws.ID))
and iWP.CRPPlan > 0
and iJOR.Planned = 'A'
and iJOQ.InPlan = 'A'
and iJOR.TAC+iJOR.TBC > 0
)
) A
order by basedjo, pdid, wsid
Generated by ABRA Software a.s. 27.10.2021 16:34:49