SAP b1 事务通知冻结与具有超额信用的客户的销售订单文件
SAP b1 transaction Nofitication to block sales order documents with customers who has Over Credit
情况:客户有 50K 信用额度和 0 余额。客户订购的金额超过其信用额度(例如 54,000)。因此必须触发交易通知。
问题:获取客户信用额度;获取客户订单余额;
到目前为止我尝试了什么:
IF @object_type='17' AND @transaction_type IN ('A','U')
BEGIN
Declare @CredLimit As nvarchar(250)
SET @CredLimit= (SELECT T0.CreditLine FROM OCRD T0
WHERE T0.CardCode=@list_of_cols_val_tab_del)
IF (
SELECT (T0.DocTotal+T1.Balance) FROM ORDR T0 INNER JOIN OCRD T1 ON T0.CardCode=T1.CardCode
WHERE DocStatus='O' AND T1.DocEntry=@list_of_cols_val_tab_del) > @CredLimit
BEGIN
Set @error = -1
SET @error_message = 'Business Partner is Over Credit Limit! Save this document as DRAFT, thank you'
END
END
SAP b1 有自己的系统定义信用额度通知,但我们不想回答它 "Yes or No",我们只想通知 SO 的编码器销售订单现在正在制作客户在 CL 上,因此将 SO 保存为草稿。
IF @object_type='17' AND @transaction_type IN ('A','U')
BEGIN
Declare @CredLimit As nvarchar(250)
SET @CredLimit= (SELECT T0.CreditLine FROM OCRD T0
WHERE T0.CardCode=(SELECT CardCode FROM ORDR
WHERE DocEntry = @list_of_cols_val_tab_del)
IF (
SELECT (T0.DocTotal+T1.Balance)
FROM ORDR T0
INNER JOIN OCRD T1 ON T0.CardCode=T1.CardCode
WHERE DocStatus='O' AND T1.DocEntry=@list_of_cols_val_tab_del) > @CredLimit
BEGIN
Set @error = -1
SET @error_message = 'Business Partner is Over Credit Limit! Save this document as DRAFT, thank you'
END
END
问题是在 SET @CredLimit
语句中检查 T0.CardCode
是否等于 @list_of_cols_val_tab_del
,这实际上是订单的 DocEntry
。实际上,现在我看了一下,你甚至可以做
IF @object_type='17' AND @transaction_type IN ('A','U')
BEGIN
IF EXISTS (
SELECT T0.DocEntry
FROM ORDR T0
INNER JOIN OCRD T1 ON T0.CardCode=T1.CardCode
WHERE DocStatus='O'
AND T1.DocEntry=@list_of_cols_val_tab_del
AND (T0.DocTotal + T1.Balance) > T1.CreditLine)
BEGIN
Set @error = -1
SET @error_message = 'Business Partner is Over Credit Limit! Save this document as DRAFT, thank you'
END
END
在第二个版本中,您完全忽略了不必要的变量声明步骤。
情况:客户有 50K 信用额度和 0 余额。客户订购的金额超过其信用额度(例如 54,000)。因此必须触发交易通知。 问题:获取客户信用额度;获取客户订单余额;
到目前为止我尝试了什么:
IF @object_type='17' AND @transaction_type IN ('A','U')
BEGIN
Declare @CredLimit As nvarchar(250)
SET @CredLimit= (SELECT T0.CreditLine FROM OCRD T0
WHERE T0.CardCode=@list_of_cols_val_tab_del)
IF (
SELECT (T0.DocTotal+T1.Balance) FROM ORDR T0 INNER JOIN OCRD T1 ON T0.CardCode=T1.CardCode
WHERE DocStatus='O' AND T1.DocEntry=@list_of_cols_val_tab_del) > @CredLimit
BEGIN
Set @error = -1
SET @error_message = 'Business Partner is Over Credit Limit! Save this document as DRAFT, thank you'
END
END
SAP b1 有自己的系统定义信用额度通知,但我们不想回答它 "Yes or No",我们只想通知 SO 的编码器销售订单现在正在制作客户在 CL 上,因此将 SO 保存为草稿。
IF @object_type='17' AND @transaction_type IN ('A','U')
BEGIN
Declare @CredLimit As nvarchar(250)
SET @CredLimit= (SELECT T0.CreditLine FROM OCRD T0
WHERE T0.CardCode=(SELECT CardCode FROM ORDR
WHERE DocEntry = @list_of_cols_val_tab_del)
IF (
SELECT (T0.DocTotal+T1.Balance)
FROM ORDR T0
INNER JOIN OCRD T1 ON T0.CardCode=T1.CardCode
WHERE DocStatus='O' AND T1.DocEntry=@list_of_cols_val_tab_del) > @CredLimit
BEGIN
Set @error = -1
SET @error_message = 'Business Partner is Over Credit Limit! Save this document as DRAFT, thank you'
END
END
问题是在 SET @CredLimit
语句中检查 T0.CardCode
是否等于 @list_of_cols_val_tab_del
,这实际上是订单的 DocEntry
。实际上,现在我看了一下,你甚至可以做
IF @object_type='17' AND @transaction_type IN ('A','U')
BEGIN
IF EXISTS (
SELECT T0.DocEntry
FROM ORDR T0
INNER JOIN OCRD T1 ON T0.CardCode=T1.CardCode
WHERE DocStatus='O'
AND T1.DocEntry=@list_of_cols_val_tab_del
AND (T0.DocTotal + T1.Balance) > T1.CreditLine)
BEGIN
Set @error = -1
SET @error_message = 'Business Partner is Over Credit Limit! Save this document as DRAFT, thank you'
END
END
在第二个版本中,您完全忽略了不必要的变量声明步骤。