Rateio por mão de obra direta
Banco de dados SQL SERVER©:
Select T0.DocEntry,T0.DocNum,T0.Type,T0.ItemCode,T0.Status,T0.Warehouse
from OWOR T0
where isnull(T0.U_LG_Cancel,'N') = 'N'
--ops com movimento no mÍs
and exists ( select 'A' from OINM T3
where T3.AppObjAbs = T0.Docentry
and T3.ApplObj = '202'
and T3.DocDate between '20170701' and '20170731')
--ops sem apontamento no periodo
and not exists ( select 'A' from LG_ApontamentoProdVW T4 join OWOR T5 on T4.DocEntryOP
= T5.DocEntry and isnull(T5.U_LG_Cancel,'N') = 'N'
where T4.Period = 91
and T4.DocEntryOP = T0.DocEntry and T4.TipoDoc = 'OP' having SUM(T4.QtdHoras) > 0 )
Banco de dados HANA STUDIO©:
Select T0."DocEntry",T0."DocNum",T0."Type",T0."ItemCode",T0."Status",T0."Warehouse"
from OWOR T0
where IFNULL(T0."U_LG_Cancel",'N') = 'N'
--ops com movimento no mÍs
and exists ( select 'A' from OINM T3
where T3."AppObjAbs" = T0."DocEntry"
and T3."ApplObj" = '202'
and T3."DocDate" between '20170701' and '20170731')
--ops sem apontamento no periodo
and not exists ( select 'A' from LG_ApontamentoProdVW T4 join OWOR T5 on
T4."DocEntryOP"
= T5."DocEntry" and IFNULL(T5."U_LG_Cancel",'N') = 'N'
where T4."Period" = 91
and T4."DocEntryOP" = T0."DocEntry"
and T4."TipoDoc" = 'OP' having SUM(T4."QtdHoras") > 0 )
⚠️ Atenção: Em ambos os casos, antes de executar a consulta, deve substituir as datas pelas datas iniciais e finais do período que está validando e, no campo Period, deve indicar o campo AbsEntry, da tabela OFPR, de acordo com o período contábil que está sendo analisado.