Cardcode exists is Sales Order but still it is allowing to add A/R Invoice
IF @transaction_type IN ('A','U') AND @object_type = '13'
FROM OINV T0
INNER JOIN OCRD T1 ON T0.CardCode = T1.CardCode
INNER JOIN INV1 T2 ON T0.DocEntry = T2.DocEntry
and not exists
(SELECT T.DocEntry FROM RDR1 T WHERE T.BaseCard=T1.CardCode))
SELECT @error = 1, @error_message = 'A/R Invoice without Copy From Delivery not Permitted !'
What i require is if user is making A/R invoice directly of a Business Partner and that Business Partner has transaction in Sales Order , then user should not be able to make A/R Invoice. In the above S.P it is allowing.