Llista els documents amb error al monitor de documents segons el codi d’error tornat per hisenda:

with DADES as 
(
select 
ECM2.AbsEntry,
OINV.DocDate,OINV.DocNum,OINV.CardCode,OINV.CardName,OCRD.LicTradNum,
ECM2.ActStatus,ECM2.ActMessage,ECM2.ObjectID,ECM2.SrcObjType,ECM2.SrcObjAbs,
ECM3.LogType,ECM3.LogMessage 
from ECM2 
join ECM3 on ECM3.AbsEntry=ECM2.AbsEntry and ECM3.LogType='R'
join OINV on OINV.DocEntry=ECM2.SrcObjAbs
join OCRD on OCRD.CardCode=OINV.CardCode
where ECM2.SrcObjType=13 and ActStatus<>'O' and LogMessage like '3002:%'

union all

select 
ECM2.AbsEntry,
ORIN.DocDate,ORIN.DocNum,ORIN.CardCode,ORIN.CardName,OCRD.LicTradNum,
ECM2.ActStatus,ECM2.ActMessage,ECM2.ObjectID,ECM2.SrcObjType,ECM2.SrcObjAbs,
ECM3.LogType,ECM3.LogMessage 
from ECM2 
join ECM3 on ECM3.AbsEntry=ECM2.AbsEntry and ECM3.LogType='R'
join ORIN on ORIN.DocEntry=ECM2.SrcObjAbs
join OCRD on OCRD.CardCode=ORIN.CardCode
where ECM2.SrcObjType=18 and ActStatus<>'O' and LogMessage like '3002:%'
)
select SrcObjType,DocNum
from DADES 
group by SrcObjType,DocNum

 

image_pdf