Documents que contenen l’error 3000 (Factura duplicada) 3001 (El registro ya esta dado de alta) 3002 (No existe el registro) al monitor de documents del SII.

Son errors que normalment podem marcar con enviats.

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:%' or LogMessage like '3001:%' or LogMessage like '3000:%')

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=14 and ActStatus<>'O' and (LogMessage like '3002:%' or LogMessage like '3001:%' or LogMessage like '3000:%')

union all

select 
ECM2.AbsEntry,
OPCH.DocDate,OPCH.DocNum,OPCH.CardCode,OPCH.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 OPCH on OPCH.DocEntry=ECM2.SrcObjAbs
join OCRD on OCRD.CardCode=OPCH.CardCode
where ECM2.SrcObjType=18 and ActStatus<>'O' and (LogMessage like '3002:%' or LogMessage like '3001:%' or LogMessage like '3000:%')

union all

select 
ECM2.AbsEntry,
ORPC.DocDate,ORPC.DocNum,ORPC.CardCode,ORPC.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 ORPC on ORPC.DocEntry=ECM2.SrcObjAbs
join OCRD on OCRD.CardCode=ORPC.CardCode
where ECM2.SrcObjType=19 and ActStatus<>'O' and (LogMessage like '3002:%' or LogMessage like '3001:%' or LogMessage like '3000:%')

)
select SrcObjType,DocNum
from DADES 
group by SrcObjType,DocNum

i el procés per marcar-les com enviades manual:

update T0 set T0.ActStatus='O', T0.ActMessage='Manual'
from ECM2 T0
join ECM3 T1 on T1.AbsEntry=T0.AbsEntry and T1.LogType='R'
join OINV T2 on T2.DocEntry=T0.SrcObjAbs
join OCRD T3 on T3.CardCode=T2.CardCode
where T0.SrcObjType=13 and ActStatus<>'O' and (LogMessage like '3000:%' or LogMessage like '3001:%' or LogMessage like '3002:%')

update T0 set T0.ActStatus='O', T0.ActMessage='Manual'
from ECM2 T0
join ECM3 T1 on T1.AbsEntry=T0.AbsEntry and T1.LogType='R'
join ORIN T2 on T2.DocEntry=T0.SrcObjAbs
join OCRD T3 on T3.CardCode=T2.CardCode
where T0.SrcObjType=14 and ActStatus<>'O' and (LogMessage like '3000:%' or LogMessage like '3001:%' or LogMessage like '3002:%')

update T0 set T0.ActStatus='O', T0.ActMessage='Manual'
from ECM2 T0
join ECM3 T1 on T1.AbsEntry=T0.AbsEntry and T1.LogType='R'
join OPCH T2 on T2.DocEntry=T0.SrcObjAbs
join OCRD T3 on T3.CardCode=T2.CardCode
where T0.SrcObjType=18 and ActStatus<>'O' and (LogMessage like '3000:%' or LogMessage like '3001:%' or LogMessage like '3002:%')

update T0 set T0.ActStatus='O', T0.ActMessage='Manual'
from ECM2 T0
join ECM3 T1 on T1.AbsEntry=T0.AbsEntry and T1.LogType='R'
join ORPC T2 on T2.DocEntry=T0.SrcObjAbs
join OCRD T3 on T3.CardCode=T2.CardCode
where T0.SrcObjType=19 and ActStatus<>'O' and (LogMessage like '3000:%' or LogMessage like '3001:%' or LogMessage like '3002:%')