All open sales orders without a Credit Card record

Previous  Next |  Direct link to this topic

The SQL below will show all open orders without any Credit Card connected where either the customer or the document is marked as "Use Credit Card".

SELECT

T0.DocEntry 'Document entry',

T0.DocNum AS 'Document number',

T1.CardCode AS 'Customer code',

T1.CardName AS 'Customer name',

CASE WHEN T0.DocTotalFC <> 0 THEN T0.DocTotalFC ELSE T0.DocTotal END AS 'Open Doc. Total',

T0.DocCur AS 'Currency'

FROM ORDR T0

LEFT JOIN OCRD T1 ON T1.CardCode = CASE WHEN (ISNULL(T0.FatherCard, '') <> '' AND T0.FatherType = 'P') THEN T0.FatherCard ELSE T0.CardCode END

LEFT JOIN [@BOY_E0_BPEXT] T3 ON T3.U_CardCode = CASE WHEN (ISNULL(T0.FatherCard, '') <> '' AND T0.FatherType = 'P') THEN T0.FatherCard ELSE T0.CardCode END

LEFT JOIN [@BOY_E0_OTCC] T4 ON T4.U_DOCENTRY = T0.DocEntry AND T4.U_OBJECTTYPE = 17

WHERE

(

           T0.U_BOY_E0_CCPAYEX = 'Y'

          OR

          ISNULL(T1.U_BOY_E0_OTCC, 'N') = 'Y'

          OR

          (T0.U_BOY_E0_CCPAYEX = 'B' AND T1.U_BOY_E0_CCPAY = 'Y')

)

AND ISNULL(T4.U_TRANSREF, ISNULL(T3.U_DefaultCard, '')) = ''

AND T0.DocStatus = 'O'