Вы находитесь на странице: 1из 60

USE [ATPL]

GO
/****** Object: StoredProcedure [dbo].[SBO_SP_TransactionNotification] Script Date:
9/3/2018 6:23:40 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER proc [dbo].[SBO_SP_TransactionNotification]

@object_type nvarchar(20), -- SBO Object Type


@transaction_type nchar(1), -- [A]dd, [U]pdate, [D]elete, [C]ancel, C[L]ose
@num_of_cols_in_key int,
@list_of_key_cols_tab_del nvarchar(255),
@list_of_cols_val_tab_del nvarchar(255)

AS

begin

-- Return values
declare @error int -- Result (0 for no error)
declare @error_message nvarchar (200) -- Error string to be displayed
select @error = 0
select @error_message = N'Ok'
Declare @Result AS INT
Declare @code AS nvarchar(20)

Declare @BaseType as nvarchar(20)


Declare @BaseNUm as nvarchar(20)
Declare @BaseEntry as nvarchar(20)
Declare @ItemCode as nvarchar(20)
-----------------------------------------------------------------------------------------
---------------------------------------

-- ADD YOUR CODE HERE

-----------------------------------------------------------------------------------------
---------------------------------------
-----Query Manager Remove Message--------
IF @object_type='160' and @transaction_type=N'D'
Begin

if exists(SELECT T1.CatName,T0.QName FROM [dbo].[OUQR] T0 WITH(READPAST)


INNER JOIN [dbo].[OQCN] T1 WITH(READPAST) ON T0.Qcategory=T1.categoryId
WHERE cast(T0.IntrnalKey as nvarchar)+' '+cast(T0.Qcategory as
nvarchar)=@list_of_cols_val_tab_del )
BEGIN

SELECT @Error=1601, @error_message = 'You Are Not Allowed to Delete Query...Please


Contact Admin.'

END
end

---------------Form Setting BP Master Account Balance Control-----


--IF @object_type='218' and @transaction_type=N'U'
--Begin
--IF EXISTS(select * from [dbo].[CHFL] where ObjName=@list_of_cols_val_tab_del AND
FldNum=14 and Objname='OCRD')
--SELECT @Error=1601, @error_message = 'You Are Not Allowed to Add BPBalance...Please
Contact Admin.'
--end
----------By jaheer On 29.Jul.18--------------

---------------------------------------Warehouse Details----------
IF @object_type='64' and @transaction_type IN (N'U')
Begin

if exists(SELECT A.WHSCODE,A.Excisable,B.Excisable FROM [dbo].[OWHS] A


INNER JOIN (SELECT WHSCODE,MAX(logInstanc)+1 MAXLOG FROM [dbo].[AWHS] GROUP BY WHSCODE) C
ON A.WHSCODE=C.WhsCode
INNER JOIN [dbo].[AWHS] B ON A.WHSCODE=B.WhsCode AND (C.MAXLOG-1)=B.logInstanc
WHERE A.WHSCODE=@list_of_cols_val_tab_del AND A.Excisable<>B.Excisable AND A.userSign2
NOT IN (1))
BEGIN
SELECT @Error=6401, @error_message = 'You Are Not Allowed to Change Excisable
Details...Please Contact Admin.'
end

END
------------------------------- Production Order Validation----------------------
IF @object_type='202' and @transaction_type IN (N'A',N'U')
Begin

-- Item Validation
--select @Error=2021, @error_message = 'Item Not Exits in BOM...'+ ItemCode from WOR1
--where ItemCode not in (select Code from ITT1 a,OWOR b where a.Father=b.ItemCode
--and b.DocEntry=@list_of_cols_val_tab_del
--union all
--select U_itemid from [@FAST_PROD_BOM_D0] a,OWOR b where a.U_masterid=b.ItemCode
--and b.DocEntry=@list_of_cols_val_tab_del )
--and DocEntry=@list_of_cols_val_tab_del

--Item Count Validation


if exists(select a.DocNum from OWOR a left outer join
(select father,count(*) BOMCnt from itt1 group by father) b on a.ItemCode=b.Father
left outer join
(select a.ItemCode, COUNT(*) WORCnt from OWOR a,WOR1 b where a.DocEntry=b.DocEntry
and a.DocEntry=@list_of_cols_val_tab_del group by a.ItemCode ) c on a.ItemCode=c.ItemCode
where isnull(b.BOMCnt,0)<>isnull(c.WORCnt,0) and a.DocEntry=@list_of_cols_val_tab_del)
select @Error=2021, @error_message = 'BOM Item is Missing...'

if exists(select b.ItemCode,COUNT(*) cnt from owor a,wor1 b where a.docentry=b.docentry


and a.docentry=@list_of_cols_val_tab_del
group by b.ItemCode having COUNT(*)>1)
select @Error=2021, @error_message = 'Item Should Not get Duplicate...'

if exists(select convert(nvarchar,GETDATE(),8) where convert(nvarchar,GETDATE(),8)


between '09:00:00' and '18:00:00')
Begin
if exists(select a.ItemCode,a.ItemName,b.DocNum from OITM a,OWOR b
where a.ItemCode like '%1000' and a.ManSerNum='N' and a.ItemCode=b.ItemCode
and b.docentry=@list_of_cols_val_tab_del and a.ItemCode not in ('06 R 0016601000'))
select @Error=2022, @error_message = 'SAP Serial No Tracking Not Enabled...'
End

--if exists(select a.DocEntry from OWOR a,[@INM_OSNT] b


-- where a.ItemCode=b.U_ItemCode and a.DocEntry=b.U_WOEntry and b.U_Status in ('P') and
a.Status='L'
--and a.docentry=@list_of_cols_val_tab_del)
--select @Error=2021, @error_message = 'Work Order Having Pending Serial No'

if exists(select a.DocEntry from OWOR a,[@INM_OSNT] b


where a.ItemCode=b.U_ItemCode and a.DocEntry=b.U_WOEntry and b.U_Status in ('RJ') and
a.Status='L'
and ISNULL(b.U_RSE,'N')='N' and a.docentry=@list_of_cols_val_tab_del)
select @Error=2021, @error_message = 'Work Order Having Pending Rejection Serial No for
Rejection/Salvage Entry'

if exists(select a.PlannedQty,B.PlannedQty,a.docentry from OWOR a inner join AWOR b on


a.docentry=b.DocEntry
where (a.PlannedQty<>b.plannedqty or a.Warehouse<>b.Warehouse)
and a.docentry=@list_of_cols_val_tab_del)
select @Error=2022, @error_message = 'Work Order Qty or Header warhouse should not be
modified'

if exists(select a.wareHouse,B.wareHouse,a.docentry,b.LogInstanc from WOR1 a inner join


AWO1 b on a.docentry=b.DocEntry and a.LineNum=b.LineNum
where (a.Warehouse<>b.Warehouse)
and a.docentry=@list_of_cols_val_tab_del)
select @Error=2023, @error_message = 'Detail level warehouse should not be modified'

--if exists(select a.DocEntry from [dbo].[OWOR] a,[dbo].[@INM_WIP1] b,[dbo].[@INM_OWIP] c


-- where a.ItemCode=c.U_ItemCode and b.DocEntry=c.DocEntry and a.DocEntry=c.U_WOEntry AND
A.DOCNUM=C.U_WONO and b.U_Status not in ('P','C','','') and a.Status='L'
-- and ISNULL(b.U_PTS,'N')='N' AND ISNULL(B.U_SerialNo,'')!='' and
a.docentry=@list_of_cols_val_tab_del)
--select @Error=2000, @error_message = 'Work Order Having Pending Serial No for
Production Transfer Entry'

------Control Enabled by Mr.Sivakaman 06/01/2018 ------------(MRP-Production Order


Closing Purpose)------------

--if exists(select aa.u_itemcode,aa.u_serialno,bb.U_PTS from (select


b.u_serialno,c.u_itemcode,c.u_type,b.u_status,b.u_pts from [dbo].[OWOR]
a,[dbo].[@INM_WIP1] b,[dbo].[@INM_OWIP] c
-- where a.ItemCode=c.U_ItemCode and b.DocEntry=c.DocEntry and a.DocEntry=c.U_WOEntry AND
A.DOCNUM=C.U_WONO and b.U_Status not in ('P','C','')
-- and a.Status='L'
-- and ISNULL(b.U_PTS,'N')='N' AND ISNULL(B.U_SerialNo,'')!='' and
a.docentry=@list_of_cols_val_tab_del
-- ) aa left join

-- (select a.u_serialno,a.u_itemcode,b.u_pts from (select


b.u_serialno,c.u_itemcode,max(c.docentry) docentry from [dbo].[OWOR] a,[dbo].[@INM_WIP1]
b,[dbo].[@INM_OWIP] c
-- where a.ItemCode=c.U_ItemCode and b.DocEntry=c.DocEntry and a.DocEntry=c.U_WOEntry AND
A.DOCNUM=C.U_WONO and b.U_Status not in ('P','C','')
-- and a.Status='L'
-- AND ISNULL(B.U_SerialNo,'')!='' and a.docentry=@list_of_cols_val_tab_del
-- group by b.u_serialno,c.u_itemcode,b.U_SerialNo
--) a inner join

-- (select b.u_serialno,c.u_itemcode,b.u_pts,max(c.docentry) docentry from [dbo].[OWOR]


a,[dbo].[@INM_WIP1] b,[dbo].[@INM_OWIP] c
-- where a.ItemCode=c.U_ItemCode and b.DocEntry=c.DocEntry and a.DocEntry=c.U_WOEntry AND
A.DOCNUM=C.U_WONO and b.U_Status not in ('P','C','')
-- and a.Status='L'
-- AND ISNULL(B.U_SerialNo,'')!='' and a.docentry=@list_of_cols_val_tab_del
-- group by b.u_serialno,c.u_itemcode,b.U_SerialNo,b.u_pts
-- ) b on a.docentry=b.docentry and a.u_itemcode=b.u_itemcode and
a.u_serialno=b.u_serialno ) bb on aa.u_itemcode=bb.u_itemcode and
aa.u_serialno=bb.u_serialno

-- left join (SELECT a.U_WOEntry,a.U_ItemCode,a.U_ItemName,c.U_SerialNo FROM [@INM_OPTS]


a
--inner join [@INM_PTS2] c on a.docentry=c.DocEntry
--where isnull(c.u_selected,'')='Y' and a.U_WOEntry=@list_of_cols_val_tab_del) cc on
aa.U_ItemCode=cc.U_ItemCode and aa.u_serialno=cc.u_serialno
-- where isnull(CC.U_SerialNo,'')='')
--select @Error=2030, @error_message = 'Work Order Having Pending Serial No for
Production Transfer Entry'

-----------------------------------------------------------------------------

--if exists(SELECT * FROM OWOR A


--INNER JOIN [@INM_WOR2] B ON A.DOCENTRY=B.U_WOEntry
--WHERE ISNULL(B.U_PTS,'')='' and a.docentry=@list_of_cols_val_tab_del)
--select @Error=2021, @error_message = 'PTS to be marked for atleast one operation'

End

-----CRM Machine Linked and Qty Per Hr Entered.----Jaheer 31.10.16------


--IF @object_type='202' and @transaction_type IN (N'A')
--Begin

--if exists(SELECT
T0.DOCENTRY,T0.DOCNUM,T0.ITEMCODE,T1.U_NEWSEQ,T1.U_OPERID,T2.U_MNO,ISNULL(T2.OutQtyRT,0.0
00000) OutQtyRT FROM [dbo].[OWOR] T0
--INNER JOIN [@INM_WOR2] T1 ON T0.DOCENTRY=T1.CODE
--LEFT OUTER JOIN (SELECT T0.DOCNUM,T0.U_DocDate,T0.U_ItemCode,T0.U_Active,T1.Lineid
OperLine,T1.U_OperID,T1.U_Operaton,T1.U_PTS
--,T2.U_mno, ISNULL(T2.OutQtyRT,0.000000) OutQtyRT FROM [dbo].[@INM_OCRM] T0
--INNER JOIN [dbo].[@INM_CRM1] T1 ON T0.DocEntry=T1.DocEntry
--LEFT OUTER JOIN
--(SELECT DOCENTRY,U_UNIQID,U_MNO,ISNULL(U_OutQtyRT,0.000000) OutQtyRT FROM
[dbo].[@INM_CRM2] WHERE ISNULL(U_MNO,'')!=''
--AND U_SELECTED='Y' AND U_Usage='R' AND ISNULL(U_OutQtyRT,0.000000)=0.000000
--) T2 ON T1.DocEntry=T2.DocEntry AND T1.LineId=T2.U_UniqID
--WHERE T1.U_OperID NOT IN ('PACKING') AND T1.U_OperID IS NOT NULL AND T1.U_PTS='Y'
-- AND ISNULL(T2.OutQtyRT,0.000000)=0.000000 AND T0.U_ACTIVE='Y') T2 ON
T0.ITEMCODE=T2.U_ITEMCODE AND T1.U_OPERID=T2.U_OPERID
--WHERE T1.U_PTS='Y' and T1.U_OperID NOT IN ('PACKING') AND T1.U_OperID IS NOT NULL and
T0.docentry=@list_of_cols_val_tab_del)

--BEGIN
--DECLARE @OPER NVARCHAR(150),@MAC NVARCHAR(250)
--SELECT @OPER=T1.U_OPERID,@MAC=CASE WHEN ISNULL(T2.U_MNO,'')='' THEN 'Kindly Link
Machine Details On CRM' ELSE
--'For Machine No:'+T2.U_MNO+' Enter Qty.Per.Hr Details On CRM Master' end FROM
[dbo].[OWOR] T0
--INNER JOIN [@INM_WOR2] T1 ON T0.DOCENTRY=T1.CODE
--LEFT OUTER JOIN (SELECT T0.DOCNUM,T0.U_DocDate,T0.U_ItemCode,T0.U_Active,T1.Lineid
OperLine,T1.U_OperID,T1.U_Operaton,T1.U_PTS
--,T2.U_mno, ISNULL(T2.OutQtyRT,0.000000) OutQtyRT FROM [dbo].[@INM_OCRM] T0
--INNER JOIN [dbo].[@INM_CRM1] T1 ON T0.DocEntry=T1.DocEntry
--LEFT OUTER JOIN
--(SELECT DOCENTRY,U_UNIQID,U_MNO,ISNULL(U_OutQtyRT,0.000000) OutQtyRT FROM
[dbo].[@INM_CRM2] WHERE ISNULL(U_MNO,'')!=''
--AND U_SELECTED='Y' AND U_Usage='R' AND ISNULL(U_OutQtyRT,0.000000)=0.000000
--) T2 ON T1.DocEntry=T2.DocEntry AND T1.LineId=T2.U_UniqID
--WHERE T1.U_OperID NOT IN ('PACKING') AND T1.U_OperID IS NOT NULL AND T1.U_PTS='Y'
-- AND ISNULL(T2.OutQtyRT,0.000000)=0.000000 AND T0.U_ACTIVE='Y') T2 ON
T0.ITEMCODE=T2.U_ITEMCODE AND T1.U_OPERID=T2.U_OPERID
--WHERE T1.U_PTS='Y' and T1.U_OperID NOT IN ('PACKING') AND T1.U_OperID IS NOT NULL and
T0.docentry=@list_of_cols_val_tab_del

--select @Error=2023, @error_message = 'Operation Code:'+@OPER+' '+@MAC


--end
--END
-------------

IF @object_type = 'CRM' and @transaction_type IN (N'A',N'U')

BEGIN

EXEC @Result = [dbo].[@INSPL_Production_TN_CRM] @list_of_cols_val_tab_del

IF @Result <> 0

SELECT @error = U_ErrorCode , @error_message = U_ErrorName FROM OADM

END

---------------------------------- Machine/Instrument Master-------------------------

IF @object_type = 'MAC' and @transaction_type IN (N'A',N'U')

BEGIN

EXEC @Result = [dbo].[@INSPL_Production_TN_MachineInstrument]


@list_of_cols_val_tab_del

IF @Result <> 0

SELECT @error = U_ErrorCode , @error_message = U_ErrorName FROM OADM

END

---------------------------------- General Indent-------------------------


IF @object_type = 'GIN' and @transaction_type IN (N'A',N'U')

BEGIN

EXEC @Result = [dbo].[@INSPL_Production_TN_GeneralIndent]


@list_of_cols_val_tab_del

IF @Result <> 0

SELECT @error = U_ErrorCode , @error_message = U_ErrorName FROM OADM

END

---------------------------------- Material Issue-------------------------

IF @object_type = 'MIS' and @transaction_type IN (N'A',N'U')

BEGIN

EXEC @Result = [dbo].[@INSPL_Production_TN_MaterialIssue]


@list_of_cols_val_tab_del

IF @Result <> 0

SELECT @error = U_ErrorCode , @error_message = U_ErrorName FROM OADM

END

---------------------------------- Security Inward-------------------------

IF @object_type = 'SECGI' and @transaction_type IN (N'A',N'U')

BEGIN

EXEC @Result = [dbo].[@INSPL_Security_TN_GateInward] @list_of_cols_val_tab_del

IF @Result <> 0

SELECT @error = U_ErrorCode , @error_message = U_ErrorName FROM OADM


END

---------------------------------- Security Outward-------------------------

IF @object_type = 'SECGO' and @transaction_type IN (N'A',N'U')

BEGIN

EXEC @Result = [dbo].[@INSPL_Security_TN_GateOutward] @list_of_cols_val_tab_del

IF @Result <> 0

SELECT @error = U_ErrorCode , @error_message = U_ErrorName FROM OADM


END

---------------------------------- Security LREntry-------------------------


IF @object_type = 'SECLRE' and @transaction_type IN (N'A',N'U')

BEGIN

EXEC @Result = [dbo].[@INSPL_Security_TN_LREntry] @list_of_cols_val_tab_del

IF @Result <> 0

SELECT @error = U_ErrorCode , @error_message = U_ErrorName FROM OADM


END

---------------------------------- RDC-------------------------

IF @object_type = 'RDC' and @transaction_type IN (N'A',N'U')

BEGIN

EXEC @Result = [dbo].[@INSPL_Subcontract_RDCNRDC_TN_RDC]


@list_of_cols_val_tab_del

IF @Result <> 0

SELECT @error = U_ErrorCode , @error_message = U_ErrorName FROM OADM


END

IF @object_type = 'NDC' and @transaction_type IN (N'A',N'U')

BEGIN

EXEC @Result = [dbo].[@INSPL_Subcontract_RDCNRDC_TN_NRDC]


@list_of_cols_val_tab_del

IF @Result <> 0

SELECT @error = U_ErrorCode , @error_message = U_ErrorName FROM OADM


END

--------------------------------- RDC RECEIPT-------------------------

IF @object_type = 'RDR' and @transaction_type IN (N'A',N'U')

BEGIN

EXEC @Result = [dbo].[@INSPL_Subcontract_RDCNRDC_TN_RDCReceipt]


@list_of_cols_val_tab_del

IF @Result <> 0

SELECT @error = U_ErrorCode , @error_message = U_ErrorName FROM OADM


END

--------------------------------- Subcontracting BOM-------------------------

IF @object_type = 'SBM' and @transaction_type IN (N'A',N'U')

BEGIN
EXEC @Result = [dbo].[@INSPL_Subcontract_TN_SubcontractingBOM]
@list_of_cols_val_tab_del

IF @Result <> 0

SELECT @error = U_ErrorCode , @error_message = U_ErrorName FROM OADM


END

--------------------------------- JOB Order-------------------------

IF @object_type = 'JOR' and @transaction_type IN (N'A',N'U')

BEGIN

EXEC @Result = [dbo].[@INSPL_Subcontract_TN_JobOrder] @list_of_cols_val_tab_del

IF @Result <> 0

SELECT @error = U_ErrorCode , @error_message = U_ErrorName FROM OADM


END

--------------------------------- jOB oRDER DELIVERY SCHEDULE-------------------------

IF @object_type = 'JDS' and @transaction_type IN (N'A',N'U')

BEGIN

EXEC @Result = [dbo].[@INSPL_Subcontract_TN_DeliverySchedule]


@list_of_cols_val_tab_del

IF @Result <> 0

SELECT @error = U_ErrorCode , @error_message = U_ErrorName FROM OADM


END

--------------------------------- DC Advise-------------------------

IF @object_type = 'JDC' and @transaction_type IN (N'A',N'U')

BEGIN

EXEC @Result = [dbo].[@INSPL_Subcontract_TN_OutwardDc] @list_of_cols_val_tab_del

IF @Result <> 0

SELECT @error = U_ErrorCode , @error_message = U_ErrorName FROM OADM


END

------------------------------- Rework DC-------------------------

IF @object_type = 'JREWDC' and @transaction_type IN (N'A',N'U')

BEGIN

EXEC @Result = [dbo].[@INSPL_Subcontract_TN_ReworkDc] @list_of_cols_val_tab_del


IF @Result <> 0

SELECT @error = U_ErrorCode , @error_message = U_ErrorName FROM OADM


END

------------------------------- Rejection DC-------------------------

IF @object_type = 'JREJDC' and @transaction_type IN (N'A',N'U')

BEGIN

EXEC @Result = [dbo].[@INSPL_Subcontract_TN_RejectionDc]


@list_of_cols_val_tab_del

IF @Result <> 0

SELECT @error = U_ErrorCode , @error_message = U_ErrorName FROM OADM


END

--------------------------------- JO Amendment------------------------

IF @object_type = 'JOA' and @transaction_type IN (N'A',N'U')

BEGIN

EXEC @Result = [dbo].[@INSPL_Subcontract_TN_JobOrderAmendment]


@list_of_cols_val_tab_del

IF @Result <> 0

SELECT @error = U_ErrorCode , @error_message = U_ErrorName FROM OADM


END

------------------------------------ Sub Contracting GRN-------------------------


IF @object_type = 'GRN' and @transaction_type IN (N'A',N'U')
BEGIN
EXEC @Result = [dbo].[@INSPL_Subcontract_TN_GRN] @list_of_cols_val_tab_del
IF @Result <> 0
SELECT @error = U_ErrorCode , @error_message = U_ErrorName FROM OADM
END

-------------------------------- Without Process Material Receipt -----------------------


--
IF @object_type = 'WPM' and @transaction_type IN (N'A',N'U')
BEGIN
EXEC @Result = [dbo].[@INSPL_Subcontract_TN_WithoutProcessReceipt]
@list_of_cols_val_tab_del
IF @Result <> 0
SELECT @error = U_ErrorCode , @error_message = U_ErrorName FROM OADM
END

-------------------------------- Scrap Receipt -------------------------


IF @object_type = 'SCR' and @transaction_type IN (N'A',N'U')
BEGIN
EXEC @Result = [dbo].[@INSPL_Subcontract_TN_ScrapReceipt]
@list_of_cols_val_tab_del
IF @Result <> 0
SELECT @error = U_ErrorCode , @error_message = U_ErrorName FROM OADM
END

---------------------------------- Inter Unit Issue -------------------------


IF @object_type = 'IUI' and @transaction_type IN (N'A',N'U')
BEGIN
EXEC @Result = [dbo].[@INSPL_Subcontract_TN_InterUnitIssue]
@list_of_cols_val_tab_del
IF @Result <> 0
SELECT @error = U_ErrorCode , @error_message = U_ErrorName FROM OADM
END

---------------------------------- Inter Unit Receipt -------------------------


IF @object_type = 'IUR' and @transaction_type IN (N'A',N'U')
BEGIN
EXEC @Result = [dbo].[@INSPL_Subcontract_TN_InterUnitReceipt]
@list_of_cols_val_tab_del
IF @Result <> 0
SELECT @error = U_ErrorCode , @error_message = U_ErrorName FROM OADM
END

---------------------------------- Inward Inspection -------------------------


IF @object_type = 'INW' and @transaction_type IN (N'A',N'U')
BEGIN
EXEC @Result = [dbo].[@INSPL_Quality_TN_InwardInspection]
@list_of_cols_val_tab_del

IF @Result <> 0
SELECT @error = U_ErrorCode , @error_message = U_ErrorName FROM OADM

Update [@inq_inw1] set U_ST='O' where isnull(U_STEntry,'')='' and


U_InvntItem='Y' and Docentry=@list_of_cols_val_tab_del
END

IF @object_type = 'INW' and @transaction_type IN (N'A')


BEGIN

if exists (select docentry from [@INQ_OINW] where


(isnull(convert(date,u_docdate),'')<>convert(date,getdate()) or
isnull(convert(date,U_InspDate),'')<>convert(date,getdate()))
and docentry=@list_of_cols_val_tab_del)
SELECT @Error=110,@error_message = 'Document / Inspection Date should be equal to curent
date'
END

---------------------------------- Inprocess Inspection -------------------------


IF @object_type = 'IPI' and @transaction_type IN (N'A',N'U')
BEGIN
EXEC @Result = [dbo].[@INSPL_Quality_TN_InwardInspection]
@list_of_cols_val_tab_del
IF @Result <> 0
SELECT @error = U_ErrorCode , @error_message = U_ErrorName FROM OADM
END

--------------------Purchase Addon Validation---------------


------------------------------------ Purchase Indent-------------------------(ERRROR
Truncated)
IF @object_type = 'IND' and @transaction_type IN (N'A',N'U')
BEGIN
EXEC @Result = [dbo].[@INSPL_Purchase_TN_PurchaseIndent]
@list_of_cols_val_tab_del
IF @Result <> 0
SELECT @error = U_ErrorCode , @error_message = U_ErrorName FROM OADM
END

---------------------------------Purchase Enquiry -------------------------


IF @object_type = 'RFQ' and @transaction_type IN (N'A',N'U')
BEGIN
EXEC @Result = [dbo].[@INSPL_Purchase_TN_PurchaseEnquiry]
@list_of_cols_val_tab_del
IF @Result <> 0
SELECT @error = U_ErrorCode , @error_message = U_ErrorName FROM OADM
END

---------------------------------Purchase Quotation -------------------------


IF @object_type = '540000006' and @transaction_type IN (N'A',N'U')
BEGIN
EXEC @Result = [dbo].[@INSPL_Purchase_TN_PurchaseQuotation]
@list_of_cols_val_tab_del
IF @Result <> 0
SELECT @error = U_ErrorCode , @error_message = U_ErrorName FROM OADM
END

------------------------------ Purchase Order-------------------------


IF @object_type = '22' and @transaction_type IN (N'A',N'U')
BEGIN
EXEC @Result = [dbo].[@INSPL_Purchase_TN_PurchaseOrder]
@list_of_cols_val_tab_del
IF @Result <> 0
SELECT @error = U_ErrorCode , @error_message = U_ErrorName FROM OADM
END

-------------------------------- Purchase Order-------------------------


IF @object_type = '112' and @transaction_type IN (N'A',N'U')
BEGIN
EXEC @Result = [dbo].[@INSPL_Purchase_TN_PurchaseOrderDraft]
@list_of_cols_val_tab_del
IF @Result <> 0
SELECT @error = U_ErrorCode , @error_message = U_ErrorName FROM OADM
END

-------------------------------- A/P Invoice-------------------------


IF @object_type = '18' and @transaction_type IN (N'A',N'U')
BEGIN
EXEC @Result = [dbo].[@INSPL_Purchase_TN_APInvoice] @list_of_cols_val_tab_del
IF @Result <> 0
SELECT @error = U_ErrorCode , @error_message = U_ErrorName FROM OADM
END

-------------------------------------- Purchase Order Amendment -------------------------


IF @object_type = 'POA' and @transaction_type IN (N'A',N'U')
BEGIN
EXEC @Result = [dbo].[@INSPL_Purchase_TN_PurchaseOrderAmendment]
@list_of_cols_val_tab_del
IF @Result <> 0
SELECT @error = U_ErrorCode , @error_message = U_ErrorName FROM OADM
END

------------------------------------ Purchase Delivery Schedule -------------------------


IF @object_type = 'PDS' and @transaction_type IN (N'A',N'U')
BEGIN
EXEC @Result = [dbo].[@INSPL_Purchase_TN_PurchaseSchedule]
@list_of_cols_val_tab_del
IF @Result <> 0
SELECT @error = U_ErrorCode , @error_message = U_ErrorName FROM OADM
END

---------------------------------Import Purchase Order Confirmation --------------------


-----
IF @object_type = 'IPC' and @transaction_type IN (N'A',N'U')
BEGIN
EXEC @Result = [dbo].[@INSPL_Purchase_TN_ImportPOConfirmation]
@list_of_cols_val_tab_del
IF @Result <> 0
SELECT @error = U_ErrorCode , @error_message = U_ErrorName FROM OADM
END

---------------------------------Import Material Dispatch Details ----------------------


---
IF @object_type = 'IMD' and @transaction_type IN (N'A',N'U')
BEGIN
EXEC @Result = [dbo].[@INSPL_Purchase_TN_ImportMaterialDispatch]
@list_of_cols_val_tab_del
IF @Result <> 0
SELECT @error = U_ErrorCode , @error_message = U_ErrorName FROM OADM
END

-------------------------------Rate Master -------------------------


IF @object_type = 'RAT' and @transaction_type IN (N'A',N'U')
BEGIN
EXEC @Result = DBO.[@INSPL_Purchase_TN_RateMaster] @list_of_cols_val_tab_del
IF @Result <> 0
SELECT @error = U_ErrorCode , @error_message = U_ErrorName FROM OADM
END

-------------------------------Supplier Registration -------------------------


IF @object_type = 'SRF' and @transaction_type IN (N'A',N'U')
BEGIN
EXEC @Result = DBO.[@INSPL_Purchase_TN_SupplierRegistration]
@list_of_cols_val_tab_del
IF @Result <> 0
SELECT @error = U_ErrorCode , @error_message = U_ErrorName FROM OADM
END

-------------------------------Supplier Evaluation -------------------------


IF @object_type = 'SEN' and @transaction_type IN (N'A',N'U')
BEGIN
EXEC @Result = DBO.[@INSPL_Purchase_TN_SupplierEvaluation]
@list_of_cols_val_tab_del
IF @Result <> 0
SELECT @error = U_ErrorCode , @error_message = U_ErrorName FROM OADM
END

---------------------------------General Indent -------------------------


IF @object_type = 'GIN' and @transaction_type IN (N'A',N'U')
BEGIN
EXEC @Result = DBO.[@INSPL_Production_TN_GeneralIndent]
@list_of_cols_val_tab_del
IF @Result <> 0
SELECT @error = U_ErrorCode , @error_message = U_ErrorName FROM OADM
END

IF @object_type = 'WIP' and @transaction_type IN (N'A',N'U')


BEGIN
EXEC @Result = [dbo].[@INSPL_Production_TN_WorkInProgress]
@list_of_cols_val_tab_del,@transaction_type
IF @Result <> 0
SELECT @error = U_ErrorCode , @error_message = U_ErrorName FROM OADM

if exists(select DocEntry from [@inm_wip2] where isnull(docentry,0)=0)


BEGIN

SELECT @Error=1601, @error_message = 'DocEntry Should Not Be Empty'

END

END

---------------------------------- Work Order Completion -------------------------

IF @object_type = 'PTS' and @transaction_type IN (N'A',N'U')

BEGIN

if exists(select * from [@inm_opts] where isnull(U_towhs,'')='' and


docentry=@list_of_cols_val_tab_del)
select @Error=2021, @error_message = 'To warehouse cannot be left empty'

EXEC @Result = [dbo].[_IND_sp_TN_PROD_ProductionTransfer]


@list_of_cols_val_tab_del

IF @Result <> 0

SELECT @error = U_ErrorCode , @error_message = U_ErrorName FROM OADM

END

---------------------------------- Rejection Salvage -------------------------


IF @object_type = 'RSE' and @transaction_type IN (N'A',N'U')

BEGIN

EXEC @Result = [dbo].[@INSPL_Production_TN_RejectionSalvage]


@list_of_cols_val_tab_del

IF @Result <> 0

SELECT @error = U_ErrorCode , @error_message = U_ErrorName FROM OADM

END

IF @object_type = 'RSE' and @transaction_type IN (N'A')

BEGIN

if exists( select a.docentry from [@INM_ORSE] a inner join [@INM_RSE1] b on


a.docentry=b.docentry
left join OUSR c on a.UserSign=c.USERID
where a.u_type<>'DA'
and (a.series<>3714)
and c.USERID not in ('1','9','12')
and isnull(a.U_StrApp,'')='Yes'
and a.DocEntry=@list_of_cols_val_tab_del)

SELECT @Error=1000,@error_message = 'You have not permission to make Stores Approval'

end

IF @object_type = 'RSE' and @transaction_type IN (N'A')

BEGIN
if exists( select a.docentry from [@INM_ORSE] a inner join [@INM_RSE1] b on
a.docentry=b.docentry
left join OUSR c on a.UserSign=c.USERID
where a.u_type='SR'
and (a.series=3711)
and a.U_FromWhs in ('RY-CUST')
and c.USERID not in ('33','39','1','102')
and a.DocEntry=@list_of_cols_val_tab_del)
SELECT @Error=100,@error_message = 'You have not permission to make Sales Return Entry'

if exists( select a.docentry from [@INM_ORSE] a inner join [@INM_RSE1] b on


a.docentry=b.docentry
left join OUSR c on a.UserSign=c.USERID
where a.u_type='SR'
and (a.series=3711)
and a.U_FromWhs in ('RY-CUST')
and c.USERID in ('33','39','1','102')
and isnull(a.U_StrApp,'')='Yes'
and a.DocEntry=@list_of_cols_val_tab_del)

SELECT @Error=1000,@error_message = 'You have not permission to make Stores Approval'

if exists( select a.docentry from [@INM_ORSE] a inner join [@INM_RSE1] b on


a.docentry=b.docentry
left join OUSR c on a.UserSign=c.USERID
where a.u_type='SR'
and (a.series=3711)
and a.U_FromWhs in ('RY-CUST')
and c.USERID in ('33','39','1','102')
and (ISNULL(a.U_ProdApp,'')='No' or ISNULL(a.U_QCApp,'')='No')
and a.DocEntry=@list_of_cols_val_tab_del)

SELECT @Error=1000,@error_message = 'Please do Production and Quality Approval'


END

--IF @object_type = 'RSE' and @transaction_type IN (N'A',N'U')

--BEGIN
--Set @Basetype=(Select U_Type From [@inm_orse] Where DocEntry=@list_of_cols_val_tab_del)
--Set @code=(
--select top 1 aa.cardcode from (select a.cardcode,A.DocEntry,c.U_SREntry,c.U_ItemCode
from ordn a inner join rdn1 b on a.docentry=b.docentry
--LEFT JOIN [@INM_ORSE] C ON A.DOCENTRY=C.U_SREntry and b.itemcode=c.U_ItemCode
--and c.docentry<>@list_of_cols_val_tab_del
--where B.whscode in ('J-RWS-C','RY-CUST')
--and a.docdate>='01-DEC-17'
--and datediff(dd,a.DocDate,getdate())>2) aa
--where (isnull(aa.u_srentry,0)=0 or isnull(aa.u_itemcode,'')=''))

--if exists (select A.DocEntry from [@INM_ORSE] a where a.u_itemcode is not null
--and isnull(a.U_RejQty,0)>0
-- and @Basetype<>'SR'
-- and isnull(@code,'')<>''
-- and a.DocEntry=@list_of_cols_val_tab_del)
-- SELECT @Error=10,@error_message = 'Sales Return are pending for Rejectio Salvage '

--END

IF @object_type = 'RSE' and @transaction_type IN (N'U')

BEGIN
if exists(SELECT
A.DOCNUM,A.U_DocDt,A.U_Type,A.U_ItemCode,A.U_RejQty,A.U_ActWgt,SUM(B.U_ScrQty) U_ScrQty
,SUM(B.U_Weight) U_Weight,SUM(B.U_TotalWgt) U_TotalWgt,A.U_ProdApp,A.U_QCApp,A.U_StrApp
FROM [dbo].[@INM_ORSE] A
INNER JOIN [dbo].[@INM_RSE1] B ON A.DOCENTRY=B.DocEntry
WHERE B.U_ScrQty<>0 AND isnull(A.U_ActWgt,0.000000)=0 and
a.DocEntry=@list_of_cols_val_tab_del
GROUP BY
A.DOCNUM,A.U_DocDt,A.U_Type,A.U_ItemCode,A.U_RejQty,A.U_ActWgt,A.U_ProdApp,A.U_QCApp,A.U_
StrApp)
SELECT @Error=20 , @error_message = 'Kindly Enter Physical Weight....'

--if exists (select A.DocEntry from [@INM_ORSE] a where a.U_DocDt>='20171101'


--and a.u_itemcode is not null
--and (isnull(a.U_StrApp,'')='No' or ISNULL(a.U_ProdApp,'')='No' or
ISNULL(a.U_QCApp,'')='No' )
-- and datediff(dd,getdate(),a.U_docdt)>6
-- and a.DocEntry<>@list_of_cols_val_tab_del)
--SELECT @Error=10,@error_message = 'Rej. Documents are pending for Approval for last 6
days. Pls Chk QM-Pending Transaction --Pending Stock Posting - Rejection/Salvage ver2.0'

end

IF @object_type = 'RSE' and @transaction_type IN (N'A')

BEGIN
Set @Basetype=(Select U_Type From [@inm_orse] Where DocEntry=@list_of_cols_val_tab_del)
if exists (select A.DocEntry from [@INM_ORSE] a where a.U_DocDt>='20171101'
and a.u_itemcode is not null
and isnull(a.U_RejQty,0)>0
and (isnull(a.U_StrApp,'')='No' or ISNULL(a.U_ProdApp,'')='No' or
ISNULL(a.U_QCApp,'')='No' )
and datediff(dd,a.U_docdt,getdate())>2
and @Basetype<>'DA'
and a.DocEntry<>@list_of_cols_val_tab_del
)
SELECT @Error=10,@error_message = 'Rej. Documents are pending for Approval for last 2
days. Pls Chk QM-Pending Transaction --Pending Stock Posting - Rejection/Salvage ver2.0'
END

IF @object_type = 'RSE' and @transaction_type IN (N'A')


BEGIN
Set @Basetype=(Select U_Type From [@inm_orse] Where DocEntry=@list_of_cols_val_tab_del)
if exists (select A.DocEntry from [@INM_ORSE] a where a.U_DocDt>='20171101'
and a.u_itemcode is not null
and isnull(a.U_RejQty,0)>0
and (isnull(a.U_StrApp,'')='No' or ISNULL(a.U_ProdApp,'')='No' or
ISNULL(a.U_QCApp,'')='No' )
and datediff(dd,a.U_docdt,getdate())>5
and @Basetype='DA'
and a.DocEntry<>@list_of_cols_val_tab_del)
SELECT @Error=11,@error_message = 'Rej. Documents(Disassembly Type) are pending for
Approval for last 5 days. Pls Chk QM-Pending Transaction --Pending Stock Posting -
Rejection/Salvage ver2.0'

END

IF @object_type = 'RSE' and @transaction_type IN (N'A')


BEGIN
if exists (select aa.U_SerialNo, aa.cnt from (select b.U_SerialNo,COUNT(*) cnt from
[@INM_ORSE] a,[@INM_RSE2] b where a.DocEntry =b.DocEntry
and b.U_SerialNo in (select U_SerialNo from [@INM_RSE2] where
DocEntry=@list_of_cols_val_tab_del and
U_Selected='Y' and ISNULL(U_SerialNo,'')<>'')
and ISNULL(b.U_SerialNo,'')<>'' and isnull(b.U_Selected,'N')='Y' group by b.U_SerialNo
having COUNT(*)>1)aa
)
Begin
Declare
@Serialno1 NVARCHAR (60)
select @Serialno1=aa.U_SerialNo from (select b.U_SerialNo,COUNT(*) cnt from [@INM_ORSE]
a,[@INM_RSE2] b where a.DocEntry =b.DocEntry
and b.U_SerialNo in (select U_SerialNo from [@INM_RSE2] where
DocEntry=@list_of_cols_val_tab_del and
U_Selected='Y' and ISNULL(U_SerialNo,'')<>'')
and ISNULL(b.U_SerialNo,'')<>'' and isnull(b.U_Selected,'N')='Y' group by b.U_SerialNo
having COUNT(*)>1)aa
begin
SELECT @Error=2021, @error_message = 'Serial No.: '+@Serialno1+' is Duplicated'
end
end

END

---------------------------------- Good Issue -------------------------

IF @object_type = '60' and @transaction_type IN (N'A',N'U')

BEGIN

Set @BaseType=(Select Top 1 U_BaseType From IGE1 Where


DocEntry=@list_of_cols_val_tab_del)
Set @BaseEntry=(Select Top 1 U_BaseEntry From IGE1 Where
DocEntry=@list_of_cols_val_tab_del)

if exists(Select a.U_BaseType ,a.U_BaseEntry,a.u_baseline,count(*) cnt from


(select distinct U_basetype,U_baseentry,U_BaseLine,docentry from ige1
where isnull(U_Basetype,'')<>'' and U_BaseEntry=@BaseEntry and U_BaseType=@BaseType) a
group by a.U_BaseType,a.U_BaseEntry,a.u_baseline having count(*)>1)
SELECT @Error=2025, @error_message = 'Goods Issue Posting cant be duplicated'

IF @object_type = '60' and @transaction_type IN (N'A',N'U')

BEGIN
IF EXISTS (select a.DocEntry from oige a inner join ige1 b on a.docentry=b.docentry
where isnull(b.u_baseentry,'')<>''
and isnull(b.u_basetype,'')=''

AND a.DocEntry = @list_of_cols_val_tab_del )


SELECT @Error=2026, @error_message = 'Goods Issue Posting cant be duplicated'

IF EXISTS (select a.DocEntry from oige a inner join ige1 b on a.docentry=b.docentry


where isnull(b.u_baseentry,'')=''
and isnull(b.u_basetype,'')<>''

AND a.DocEntry = @list_of_cols_val_tab_del )


SELECT @Error=2027, @error_message = 'Goods Issue Posting cant be duplicated'

IF EXISTS (select a.DocEntry from oige a inner join ige1 b on a.docentry=b.docentry


where isnull(b.u_baseentry,'')<>''
and isnull(b.u_baseline,'')=''
AND a.DocEntry = @list_of_cols_val_tab_del )
SELECT @Error=2028, @error_message = 'Goods Issue Posting cant be duplicated'

end

--if exists(SELECT M.DOCENTRY FROM

--(select a.docentry dentry,b.docentry,b.u_basetype,b.u_baseentry from OIGE a inner join


-- (select distinct docentry,u_basetype,u_baseentry from IGE1 where
isnull(u_basetype,'')<>'' and isnull(u_baseentry,'')<>'' ) b
-- on a.docentry=b.docentry where a.docentry=@list_of_cols_val_tab_del) M INNER JOIN

-- (select a.docentry dentry,b.docentry,b.u_basetype,b.u_baseentry from OIGE a inner join


-- (select distinct docentry,u_basetype,u_baseentry
-- from IGE1 where isnull(u_basetype,'')<>'' and isnull(u_baseentry,'')<>'' ) b
-- on a.docentry=b.docentry where a.docentry<>@list_of_cols_val_tab_del) n
-- ON M.U_BaseType=ISNULL(N.U_BaseType,'') AND M.U_BaseEntry=ISNULL(N.U_BaseEntry,''))
--SELECT @Error=2025, @error_message = 'Goods Issue Posting cant be duplicated'

EXEC @Result = [dbo].[@INSPL_Inventory_TN_GoodsIssue] @list_of_cols_val_tab_del

IF @Result <> 0

SELECT @error = U_ErrorCode , @error_message = U_ErrorName FROM OADM

END

---------------------------------- Good Receipt -------------------------

IF @object_type = '59' and @transaction_type IN (N'A',N'U')

BEGIN

Set @BaseType=(Select Top 1 U_BaseType From IGN1 Where


DocEntry=@list_of_cols_val_tab_del)
Set @BaseEntry=(Select Top 1 U_BaseEntry From IGN1 Where
DocEntry=@list_of_cols_val_tab_del)
Set @BaseNum=(Select Top 1 U_BaseNum From IGN1 Where DocEntry=@list_of_cols_val_tab_del)

if exists(Select a.U_BaseType ,a.U_BaseEntry,a.itemcode,count(*) cnt from


(select distinct U_basetype,U_baseentry,itemcode,docentry from ign1 where
isnull(U_Basetype,'')<>''
and U_BaseEntry=@BaseEntry and U_BaseType=@BaseType) a
group by a.U_BaseType,a.U_BaseEntry,a.itemcode having count(*)>1)
SELECT @Error=2025, @error_message = 'Goods Receipt Posting cant be duplicated'

if exists(Select a.U_BaseType ,a.U_BaseNum,a.itemcode,count(*) cnt from


(select distinct U_basetype,U_basenum,itemcode,docentry from ign1 where
isnull(U_Basetype,'')='SCR'
and U_BaseNum=@BaseNum and U_BaseType=@BaseType ) a
group by a.U_BaseType,a.U_BaseNum,a.itemcode having count(*)>1)
SELECT @Error=2035, @error_message = 'Goods Receipt Posting cant be duplicated'
IF @object_type = '59' and @transaction_type IN (N'A',N'U')

BEGIN
IF EXISTS (select a.DocEntry from oign a inner join ign1 b on a.docentry=b.docentry
where isnull(b.u_baseentry,'')<>''
and isnull(b.u_basetype,'')=''

AND a.DocEntry = @list_of_cols_val_tab_del )


SELECT @Error=2036, @error_message = 'Goods Receipt Posting cant be duplicated'

IF EXISTS (select a.DocEntry from oign a inner join ign1 b on a.docentry=b.docentry


where isnull(b.u_baseentry,'')=''
and isnull(b.u_basetype,'')<>''

AND a.DocEntry = @list_of_cols_val_tab_del )


SELECT @Error=2037, @error_message = 'Goods Receipt Posting cant be duplicated'

IF EXISTS (select a.DocEntry from oign a inner join ign1 b on a.docentry=b.docentry


where isnull(b.u_baseentry,'')<>''
and isnull(b.u_baseline,'')=''
AND a.DocEntry = @list_of_cols_val_tab_del )
SELECT @Error=2038, @error_message = 'Goods Receipt Posting cant be duplicated'

end

--IF EXISTS (select * from OIGN A INNER JOIN IGN1 B ON A.DOCENTRY=B.DocEntry


--WHERE B.ItemCode NOT IN (select A.U_ITEMCODE from [@INM_OPTS] A
--INNER JOIN IGN1 B ON A.Object=B.U_BaseType AND A.DOCNUM=B.U_BaseNum AND
A.DOCENTRY=B.U_BaseEntry
--AND B.DOCENTRY=@list_of_cols_val_tab_del)
--AND A.DOCENTRY=@list_of_cols_val_tab_del)
--SELECT @Error=2026, @error_message = 'Wrong Goods Receipt Posting cant....Please
Contact Administrator..'

--if exists(SELECT M.DOCENTRY FROM


--(select a.docentry dentry,b.docentry,b.u_basetype,b.u_baseentry from OIGN a inner join
-- (select distinct docentry,u_basetype,u_baseentry,ItemCode from IGN1 where
isnull(u_basetype,'')<>'' and isnull(u_baseentry,'')<>'' ) b
-- on a.docentry=b.docentry where a.docentry=@list_of_cols_val_tab_del) M INNER JOIN

-- (select a.docentry dentry,b.docentry,b.u_basetype,b.u_baseentry from OIGN a inner join


(select distinct docentry,u_basetype,u_baseentry
-- from IGN1 where isnull(u_basetype,'')<>'' and isnull(u_baseentry,'')<>'' ) b
-- on a.docentry=b.docentry where a.docentry<>@list_of_cols_val_tab_del) n
-- ON M.U_BaseType=ISNULL(N.U_BaseType,'') AND M.U_BaseEntry=ISNULL(N.U_BaseEntry,''))
--SELECT @Error=2025, @error_message = 'Goods Receipt Posting cant be duplicated'

EXEC @Result = [dbo].[@INSPL_Inventory_TN_GoodsReceipt]


@list_of_cols_val_tab_del

IF @Result <> 0

SELECT @error = U_ErrorCode , @error_message = U_ErrorName FROM OADM


END

---------------------------------- Inventory Transfer -------------------------

IF @object_type = '67' and @transaction_type IN (N'A',N'U')

BEGIN

Set @BaseType=(Select Top 1 U_BaseType From WTR1 Where


DocEntry=@list_of_cols_val_tab_del)
Set @BaseEntry=(Select Top 1 U_BaseEntry From WTR1 Where
DocEntry=@list_of_cols_val_tab_del)

if exists(Select a.U_BaseType ,a.U_BaseEntry,a.itemcode,a.WhsCode,count(*) cnt from


(select distinct U_basetype,U_baseentry,itemcode,docentry,WhsCode from WTR1 where
isnull(U_Basetype,'')<>'' and U_BaseEntry=@BaseEntry and U_BaseType=@BaseType) a
group by a.U_BaseType,a.U_BaseEntry,a.itemcode,a.WhsCode having count(*)>1)
SELECT @Error=2025, @error_message = 'Inventory Transfer Posting cant be duplicated'

IF @object_type = '67' and @transaction_type IN (N'A',N'U')

BEGIN
IF EXISTS (select a.DocEntry from OWTR a inner join WTR1 b on a.docentry=b.docentry
where isnull(b.u_baseentry,'')<>''
and isnull(b.u_basetype,'')=''

AND a.DocEntry = @list_of_cols_val_tab_del )


SELECT @Error=2036, @error_message = 'Inventory Transfer Posting cant be duplicated'

IF EXISTS (select a.DocEntry from OWTR a inner join WTR1 b on a.docentry=b.docentry


where isnull(b.u_baseentry,'')=''
and isnull(b.u_basetype,'')<>''

AND a.DocEntry = @list_of_cols_val_tab_del )


SELECT @Error=2037, @error_message = 'Inventory Transfer Posting cant be duplicated'

IF EXISTS (select a.DocEntry from OWTR a inner join WTR1 b on a.docentry=b.docentry


where isnull(b.u_baseentry,'')<>''
and isnull(b.u_baseline,'')=''
AND a.DocEntry = @list_of_cols_val_tab_del )
SELECT @Error=2038, @error_message = 'Inventory Transfer Posting cant be duplicated'

end

--if exists(SELECT M.DOCENTRY FROM

--(select a.docentry dentry,b.docentry,b.u_basetype,b.u_baseentry from owtr a inner join


-- (select distinct docentry,u_basetype,u_baseentry from wtr1 where
isnull(u_basetype,'')<>'' and isnull(u_baseentry,'')<>'' ) b
-- on a.docentry=b.docentry where a.docentry=@list_of_cols_val_tab_del) M INNER JOIN

-- (select a.docentry dentry,b.docentry,b.u_basetype,b.u_baseentry from owtr a inner join


(select distinct docentry,u_basetype,u_baseentry
-- from wtr1 where isnull(u_basetype,'')<>'' and isnull(u_baseentry,'')<>'' ) b
-- on a.docentry=b.docentry where a.docentry<>@list_of_cols_val_tab_del) n
-- ON M.U_BaseType=ISNULL(N.U_BaseType,'') AND M.U_BaseEntry=ISNULL(N.U_BaseEntry,''))
--SELECT @Error=2025, @error_message = 'Inventory Transfer Posting cant be duplicated'

EXEC @Result = [dbo].[@INSPL_Inventory_TN_InventoryTransfer]


@list_of_cols_val_tab_del

IF @Result <> 0

SELECT @error = U_ErrorCode , @error_message = U_ErrorName FROM OADM

END

IF @object_type = '67' and @transaction_type IN (N'A',N'U')

BEGIN
if exists(SELECT a.DocEntry FROM OWTR A INNER JOIN WTR1 B ON A.DOCENTRY=B.DOCENTRY
INNER JOIN
(select a.DocEntry,a.itemcode,b.SysNumber,c.DistNumber from oitl a inner join itl1 b on
a.LogEntry=b.logentry
inner join osrn c on a.itemcode=c.itemcode and b.SysNumber=c.SysNumber
where a.itemcode=b.ItemCode
and a.doctype='67') C ON a.docentry=c.DocEntry and b.itemcode=c.ItemCode

inner join (SELECT A.U_ItemCode,C.U_SerialNo FROM [@INM_ORSE] A


INNER join [@INM_RSE2] C ON A.DOCENTRY=C.DocEntry
WHERE (ISNULL(A.U_ProdApp,'')<>'Yes' or ISNULL(A.U_QCApp,'')<>'Yes' or
ISNULL(A.U_StrApp,'')<>'Yes')
and isnull(c.u_selected,'')='Y') d on b.ItemCode=d.U_ItemCode and
c.DistNumber=d.U_SerialNo
where A.DocEntry=@list_of_cols_val_tab_del )

begin
declare @SERIALNO NVARCHAR (30),@ITEMCOD2 NVARCHAR (100)

SELECT @itemcod2=b.itemcode,@serialno=c.distnumber FROM OWTR A INNER JOIN WTR1 B ON


A.DOCENTRY=B.DOCENTRY
INNER JOIN
(select a.DocEntry,a.itemcode,b.SysNumber,c.DistNumber from oitl a inner join itl1 b on
a.LogEntry=b.logentry
inner join osrn c on a.itemcode=c.itemcode and b.SysNumber=c.SysNumber
where a.itemcode=b.ItemCode
and a.doctype='67') C ON a.docentry=c.DocEntry and b.itemcode=c.ItemCode

inner join (SELECT A.U_ItemCode,C.U_SerialNo FROM [@INM_ORSE] A


INNER join [@INM_RSE2] C ON A.DOCENTRY=C.DocEntry
WHERE (ISNULL(A.U_ProdApp,'')<>'Yes' or ISNULL(A.U_QCApp,'')<>'Yes' or
ISNULL(A.U_StrApp,'')<>'Yes')
and isnull(c.u_selected,'')='Y') d on b.ItemCode=d.U_ItemCode and
c.DistNumber=d.U_SerialNo
where A.DocEntry=@list_of_cols_val_tab_del

begin

SELECT @Error=15, @error_message = 'Itemcode:'+@ITEMCOD2+', '+'Serial No:'+@serialno+'


is waiting for approval in Rejection and Salvage.Please reselect'
end
end
end

-------------------------------- GRPO-------------------------
IF @object_type = '20' and @transaction_type IN (N'A',N'U')
BEGIN
EXEC @Result = [dbo].[@INSPL_Purchase_TN_GoodsReceiptPO]
@list_of_cols_val_tab_del
IF @Result <> 0
SELECT @error = U_ErrorCode , @error_message = U_ErrorName FROM OADM
END

IF @object_type='12' and @transaction_type IN (N'A',N'U')


Begin

if exists(select a.userid from ousr a where isnull(a.u_location,'')='' and


a.userid=@list_of_cols_val_tab_del)
select @Error=2021, @error_message = 'Location cannot be left empty'

end

IF @object_type='12' and @transaction_type IN (N'A',N'U')


Begin

if exists(select a.userid from ousr a where isnull(a.u_location,'') not in(select code


from olct)
and a.userid=@list_of_cols_val_tab_del)
select @Error=2021, @error_message = 'Enter correct location code'

end

IF @object_type='12' and @transaction_type IN (N'A',N'U')


Begin

if exists(select a.userid from ousr a where isnull(a.branch,'')=''


and a.userid=@list_of_cols_val_tab_del)
select @Error=2021, @error_message = 'Branch cannot be left empty'

end

IF @object_type='12' and @transaction_type IN (N'A',N'U')


Begin

if exists(select a.userid from ousr a inner join


(select code,
case
when name='BOND' then 2 when name='Chennai'
then 3 when name='Jamshedpur'
then 4 when name='Utharanchal'
then 5
when name='Hosur' then 7
when name='Alwar' then 9
when name='Pune' then 8
else 0
end u_location from oubr) b
on a.branch=b.Code
where a.U_Location<>b.u_location
and a.userid=@list_of_cols_val_tab_del)
select @Error=2021, @error_message = 'Select branch and location correcly'

end

IF @object_type='4' and @transaction_type IN (N'A',N'U')


Begin

if exists(select ItemCode from oitm where GLMethod='C' AND INVNTITEM='Y'


and itemcode=@list_of_cols_val_tab_del)
select @Error=2021, @error_message = 'Select GL Account By Warehouse'

end

IF @object_type='4' and @transaction_type IN (N'A',N'U')


Begin

if exists(select a.ItemCode from [OITM] a where ISNULL(a.invntryuom,'')=''


and a.ItemCode=@list_of_cols_val_tab_del)
select @Error=2024, @error_message = 'Kindly Enter Inventory UOM!!!!'

end

IF @object_type='4' and @transaction_type IN (N'U')


Begin

if exists(select a.docentry from OITM a inner join AITM b on a.ITEMCODE=b.ITEMCODE


where (isnull(a.U_AppInDt,'')<>isnull(b.U_AppInDt,'') OR
isnull(a.U_AppInTime,'')<>isnull(b.U_AppInTime,''))
and a.itemcode=@list_of_cols_val_tab_del )
SELECT @Error=2021, @error_message = 'Approved Initial date/Time Cant Change'

if exists(select a.docentry from OITM a inner join AITM b on a.ITEMCODE=b.ITEMCODE


where (isnull(a.U_APPCOMDT,'')<>isnull(b.U_APPCOMDT,'') OR
isnull(a.U_AppComTime,'')<>isnull(b.U_AppComTime,''))
and isnull(b.U_APPCOMDT,'')<>''
and a.itemcode=@list_of_cols_val_tab_del )

SELECT @Error=2021, @error_message = 'Approved Complete date/Time Cant Change'

end

IF @object_type='4' and @transaction_type IN (N'A')


Begin

if exists(select ItemCode from oitm a inner join oitb b on a.itmsgrpcod=b.itmsgrpcod


where isnull(b.u_type,'')='B'
and a.usersign not in (35,36,169,102,188) AND A.QRYGROUP22='Y'
and itemcode=@list_of_cols_val_tab_del)
select @Error=2022, @error_message = 'Yo are not allowed to add BOM Item '
END

IF @object_type='4' and @transaction_type IN (N'A','U')


Begin

if exists(select a.ItemCode from [OITM] a left outer join [OITW] b on


a.ItemCode=b.ItemCode
left join OITB c on a.ItmsGrpCod=c.ItmsGrpCod
where isnull(b.WhsCode,'')='' and isnull(c.u_type,'')='B'
and a.usersign in (35,36,169,1,102,1,188)
and a.itemcode=@list_of_cols_val_tab_del)
select @Error=2021, @error_message = 'Warehouse should not left empty'

if exists(select ItemCode from oitm a inner join oitb b on a.itmsgrpcod=b.itmsgrpcod


where isnull(b.u_type,'')<>'B'
and a.usersign in (35,36,169,188) AND A.QRYGROUP22='N'
and itemcode=@list_of_cols_val_tab_del)
select @Error=2022, @error_message = 'You are not allowed to add Other than BOM Item '

if exists(select a.ItemCode from oitm a inner join OITW b on a.ItemCode=b.ItemCode inner


join OWHS c on b.WhsCode=c.WhsCode where isnull(c.u_type,'')<>'B'
and a.usersign in (35,36,169,188) AND A.QRYGROUP22='N'
and a.ItemCode=@list_of_cols_val_tab_del)
select @Error=2021, @error_message = 'You are not allowed to add Other than BOM Warehouse
'

if exists(select A.ItemCode from oitm a where a.usersign in (35,36,169,188)


AND (isnull(QryGroup21,'')<>'N' OR isnull(QryGroup22,'')<>'Y')
and a.ItemCode=@list_of_cols_val_tab_del)
select @Error=2021, @error_message = 'Select BOM/Non BOM Item property correctly '

end

IF @object_type='4' and @transaction_type IN (N'A')


Begin

if exists(select A.ItemCode from oitm a where (isnull(U_AppComDt,'')<>'' or


isnull(U_AppComTime,'')<>'')
and a.ItemCode=@list_of_cols_val_tab_del)
select @Error=2021, @error_message = 'Approval Completed Date/Time should be null '

end

IF @object_type='4' and @transaction_type IN (N'U')


Begin

if exists(select * from OITM A WHERE A.QRYGROUP21='Y'


AND A.ITEMCODE IN (SELECT DISTINCT CODE FROM OITT UNION ALL SELECT DISTINCT CODE FROM
ITT1) AND a.itemcode=@list_of_cols_val_tab_del)
SELECT @Error=2021, @error_message = 'BOM Item Must Be Linked With Item Property
BOM....'

If Exists (Select a.ItemCode from [OITM] A inner join aitm b on a.itemcode=b.ItemCode


wHERE a.ItemCode =@list_of_cols_val_tab_del and a.UserSign2 not in('1','102','59','58')
and isnull(a.U_AppStage,'')<>isnull(b.u_appstage,'')
and b.LogInstanc>=0)
SELECT @error=1050, @error_message = 'Please contact manager. You dont have permission
Modify the Item Approval Stage'

If Exists (Select a.ItemCode from OITM A inner join aitm b on a.itemcode=b.ItemCode


inner join (select itemcode,max(loginstanc) Loginstanc from oitm group by itemcode) c on
b.itemcode=c.itemcode and b.LogInstanc=c.Loginstanc
wHERE a.ItemCode =@list_of_cols_val_tab_del and a.UserSign2 not in('1','102','58','59')
and isnull(a.U_AppStage,'')<>isnull(b.u_appstage,''))

SELECT @error=1050, @error_message = 'Please contact manager. You dont have permission
Modify the Item Approval Stage'

If Exists (Select a.ItemCode from OITM A inner join aitm b on a.itemcode=b.ItemCode


wHERE a.ItemCode =@list_of_cols_val_tab_del and a.UserSign2 not in('1','102','58','59')
and isnull(a.frozenFor,'')<>isnull(b.frozenFor,'')
and b.LogInstanc=1)

SELECT @error=1050, @error_message = 'Please contact manager. You dont have permission
Modify the Active/Inactive'

If Exists (Select a.ItemCode from OITM A inner join aitm b on a.itemcode=b.ItemCode


inner join (select itemcode,max(loginstanc) Loginstanc from oitm group by itemcode) c on
b.itemcode=c.itemcode and b.LogInstanc=c.Loginstanc
wHERE A.ItemCode =@list_of_cols_val_tab_del and A.UserSign2 not in('1','59','58')
and isnull(a.frozenFor,'')<>isnull(b.frozenFor,'')
)

SELECT @error=1052, @error_message = 'Please contact manager. You dont have permission
Modify the Active/Inactive'

If Exists (Select a.ItemCode from OITM A inner join aitm b on a.itemcode=b.ItemCode


wHERE a.ItemCode =@list_of_cols_val_tab_del and a.UserSign2 not in('1','59','58')
and (isnull(a.GSTRelevnt,'')<>isnull(b.GSTRelevnt,'') OR
isnull(a.ChapterID,'')<>isnull(b.ChapterID,''))
and b.LogInstanc=1)

SELECT @error=1050, @error_message = 'Please contact manager. You dont have permission
Modify the GST/HSN'

If Exists (Select a.ItemCode from OITM A inner join aitm b on a.itemcode=b.ItemCode


inner join (select itemcode,max(loginstanc) Loginstanc from oitm group by itemcode) c on
b.itemcode=c.itemcode and b.LogInstanc=c.Loginstanc
wHERE A.ItemCode =@list_of_cols_val_tab_del and A.UserSign2 not in('1','59','58')
and (isnull(a.GSTRelevnt,'')<>isnull(b.GSTRelevnt,'') OR
isnull(a.ChapterID,'')<>isnull(b.ChapterID,'')))

SELECT @error=1050, @error_message = 'Please contact manager. You dont have permission
Modify the GST/HSN'

end

IF @object_type='4' and @transaction_type IN (N'A',N'U')


Begin
if exists(select a.itemCode from [OITM] a where a.ItmsGrpCod in
('138','278','180','154','137','160')
AND ((isnull(a.U_ProdOrd,'')='') or (isnull(a.U_ProdOrd,'')='N' ) )
and a.ItemCode=@list_of_cols_val_tab_del)
select @Error=2025, @error_message = 'Kindly Select Production Order Yes!!!!'

end

IF @object_type='4' and @transaction_type IN (N'A',N'U')


Begin

if exists(select a.ItemCode from [OITM] a where a.ItmsGrpCod in


('138','278','154','137','160')
AND ((isnull(a.U_serialno,'')='') or (isnull(a.U_serialno,'')='N'))
and a.ItemCode=@list_of_cols_val_tab_del)
select @Error=2024, @error_message = 'Kindly Select Serial Number Tracking Yes!!!!'

end

IF @object_type='4' and @transaction_type IN (N'A',N'U')


Begin

if exists(select a.ItemCode from [OITM] a where a.ItmsGrpCod in ('138','278')


AND ((isnull(a.U_PrntStage,'')='') or (isnull(a.U_PrntStage,'')='A' ) )
and a.ItemCode=@list_of_cols_val_tab_del)
select @Error=2024, @error_message = 'Kindly Select Print Stage as Before Status!!!!'

end

IF @object_type='4' and @transaction_type IN (N'A',N'U')


Begin

if exists(select a.ItemCode from [OITM] a where a.ItmsGrpCod in ('137','154','160')


AND ( (isnull(a.U_PrntStage,'')='') or (isnull(a.U_PrntStage,'')='B') )
and a.ItemCode=@list_of_cols_val_tab_del)
select @Error=2024, @error_message = 'Kindly Select Print Stage as After Stage Print!!!!'

end

IF @object_type='21' and @transaction_type IN (N'A',N'U')


Begin

if exists(select a.docentry from ORPD a


inner join rpd1 b on a.docentry=b.docentry
inner join ousr c on a.UserSign=c.userid
inner join owhs d on b.WhsCode=d.WhsCode
where c.u_location<>d.location
and a.DocType='I' and a.DocEntry=@list_of_cols_val_tab_del)
select @Error=2021, @error_message = 'user location and warhouse location mismatching'

end
IF @object_type='30' and @transaction_type IN (N'A',N'U')
Begin

Set @BaseType=(Select Top 1 U_BaseType From JDT1 Where TransId=@list_of_cols_val_tab_del


and isnull(u_basetype,'')='WIP')
Set @BaseEntry=(Select Top 1 U_BaseEntry From JDT1 Where
TransId=@list_of_cols_val_tab_del and isnull(u_basetype,'')='WIP')

if exists(select a.u_basetype,a.u_baseentry,count(*) cnt from (select distinct


U_basetype,U_baseentry,transid from JDT1 where isnull(U_Basetype,'')<>''
and U_BaseEntry=@BaseEntry and U_BaseType=@BaseType) a
group by a.u_basetype,a.u_baseentry
having count(*)>1
)
select @Error=2021, @error_message = 'MOH/SOH Posting Should not be duplicated'

if exists(select a.transid,count(distinct c.Segment_1) from ojdt a inner join jdt1 b on


a.transid=b.transid
inner join oact c on b.Account=c.acctcode
where
a.TransType not in (67,24,46,30)
and
a.transid=@list_of_cols_val_tab_del and a.usersign not
in('29','30','59','67','68','58','17','18','126','128','1','168')
group by a.transid
having count(distinct Segment_1)>1
)
select @Error=2021, @error_message = 'Segment Mismatching'

if exists(select * from ojdt a inner join ajdt b on a.transid=b.transid


where (isnull(a.duedate,'')<>b.DueDate or isnull(a.memo,'')<>b.memo or
isnull(a.ref1,'')<>b.Ref1 or
isnull(a.ref2,'')<>b.ref2 or isnull(a.Ref3,'')<>b.Ref3)
and a.transid=@list_of_cols_val_tab_del and a.usersign2<>58
and a.usersign2<>1 and a.usersign2<>126 and a.usersign2<>128 and a.usersign2<>140)
select @Error=2021, @error_message = 'Do not modify the data'

if exists(select * from jdt1 a inner join ajd1 b on a.transid=b.transid and


a.line_id=b.line_id
inner join ojdt c on a.transid=c.transid
where (isnull(a.LineMemo,'')<>b.LineMemo or isnull(a.ref1,'')<>b.ref1 or
isnull(a.ref2,'')<>b.ref2 or isnull(a.Ref3Line,'')<>b.Ref3Line)
and a.transid=@list_of_cols_val_tab_del and c.usersign2<>58
and C.usersign2<>1 and c.usersign2<>126 and c.usersign2<>128 and c.usersign2<>140)
select @Error=2021, @error_message = 'Do not modify the data'

end

--IF @object_type='30' and @transaction_type IN (N'A',N'U')


--Begin

--if exists(select a.transid from ojdt a inner join jdt1 b on a.transid=b.transid


--inner join oact c on b.Account=c.AcctCode
--where c.FatherNum in (12270100,12250100,12230100,12220100,12210100)
--and c.AcctCode in(select BalInvntAc from owhs)
--and a.TransId=@list_of_cols_val_tab_del AND A.TransType=30)
--select @Error=2021, @error_message = 'Inventory Account Should not be allowed in
Journal Entry'
--end

--IF @object_type='30' and @transaction_type IN (N'A',N'U')


--Begin

--if exists(select a.transid from ojdt a inner join jdt1 b on a.transid=b.transid


--inner join oact c on b.Account=c.AcctCode
--where c.acctcode in (select IncreasAc from OWHS union select DecreasAc from OWHS)
--and a.TransId=@list_of_cols_val_tab_del AND A.TransType=30
-------By: Jaheer On 4/6/2016-------Should Not asllow Manual JE ---and a.usersign not
in('58')
--)
--select @Error=2021, @error_message = 'inventory Offset decrease/increase Account Should
not be allowed in Journal Entry'

--end

IF @object_type='30' and @transaction_type IN (N'A',N'U')


Begin

if exists(select * from ojdt a inner join (select b.TransId,c.Segment_1,case when


c.Segment_1=21
then 3 when c.Segment_1=22 then 4 when
c.Segment_1=23 then 5 else 3 end location from
jdt1 b inner join
oact c on b.account=c.AcctCode) d on a.transid=d.transid
inner join ousr e on a.UserSign=e.USERID
where d.Location<>e.U_Location and a.UserSign2 not in
('1','29','30','59','67','68','58','57','17','18','126','128','102','130','137','140')
and a.TransId=@list_of_cols_val_tab_del)
select @Error=2021, @error_message = 'Segment wrongly selected'
end
-----------------------------------------------------------------------------------------
----------
IF @object_type = '15' and @transaction_type IN (N'A',N'U')

BEGIN

EXEC @Result = [dbo].[@INSPl_Sales_TN_DeliveryNote] @list_of_cols_val_tab_del

IF @Result <> 0

SELECT @error = U_ErrorCode , @error_message = U_ErrorName FROM OADM

END

IF @object_type='15' and @transaction_type IN (N'A',N'U')


Begin

if exists(select * from odln a


inner join dln1 b on a.docentry=b.docentry
inner join ousr c on a.UserSign=c.userid
inner join owhs d on b.WhsCode=d.WhsCode
where c.u_location<>d.location
and a.DocType='I' and a.DocEntry=@list_of_cols_val_tab_del )
SELECT @Error=2021, @error_message = 'You are not allowed for this type of transaction
or Warehouse wrongly selected'
end

IF @object_type='15' and @transaction_type IN (N'A',N'U')


Begin

if exists(SELECT A.DocEntry FROM ODLN A INNER JOIN DLN1 B ON A.DOCENTRY=B.DOCENTRY


WHERE ISNULL(A.CARDCODE,'')<>isnull(B.OcrCode,'')
AND a.DocEntry=@list_of_cols_val_tab_del )
SELECT @Error=2021, @error_message = 'Customer Code and Cost Center Customer code
should not be change'

if exists(SELECT A.DocEntry FROM ODLN A INNER JOIN DLN1 B ON A.DOCENTRY=B.DocEntry


INNER JOIN OITM C ON B.ITEMCODE=C.ItemCode
INNER JOIN OITB D ON C.ItmsGrpCod=D.ItmsGrpCod
WHERE isnull(D.u_ccenter,'')<>isnull(b.ocrcode2,'')
and b.itemcode <>'PCO'
and a.DocEntry=@list_of_cols_val_tab_del )
SELECT @Error=1704, @error_message = 'Product Cost Center Mismatching'

if exists(SELECT A.DocEntry FROM ODLN A INNER JOIN DLN1 B ON A.DOCENTRY=B.DocEntry


WHERE isnull(b.ocrcode2,'')=''
and a.DocEntry=@list_of_cols_val_tab_del
and b.itemcode <>'PCO' )
SELECT @Error=1704, @error_message = 'Product Cost Center Cant be left empty'

End

IF @object_type='14' and @transaction_type IN (N'A',N'U')


Begin

if exists(select * from orin a


inner join rin1 b on a.docentry=b.docentry
inner join ousr c on a.UserSign=c.userid
inner join owhs d on b.WhsCode=d.WhsCode
where c.u_location<>d.location
and a.DocType='I'
and a.DocEntry=@list_of_cols_val_tab_del )
SELECT @Error=2202, @error_message = 'You are not allowed for this type of transaction
or Warehouse wrongly selected'
end

IF @object_type='14' and @transaction_type IN (N'A',N'U')


Begin

if exists(select a.DocEntry from [ORIN] a where a.GSTTranTyp='--' and a.DocType='S'


and isnull(a.Indicator,'')='' and a.DocEntry=@list_of_cols_val_tab_del)
SELECT @Error=2202, @error_message = 'Service based bill of supply invoices indicator
should not be left empty'

if exists(SELECT A.DocEntry FROM ORIN A INNER JOIN RIN1 B ON A.DOCENTRY=B.DocEntry


INNER JOIN OITM C ON B.ITEMCODE=C.ItemCode
INNER JOIN OITB D ON C.ItmsGrpCod=D.ItmsGrpCod
WHERE isnull(D.u_ccenter,'')<>isnull(b.ocrcode2,'')
and b.itemcode <>'PCO'
and a.DocEntry=@list_of_cols_val_tab_del )
SELECT @Error=1704, @error_message = 'Product Cost Center Mismatching'

if exists(SELECT A.DocEntry FROM ORIN A INNER JOIN RIN1 B ON A.DOCENTRY=B.DocEntry


WHERE isnull(b.ocrcode2,'')=''
and a.DocEntry=@list_of_cols_val_tab_del
and b.itemcode <>'PCO' )
SELECT @Error=1704, @error_message = 'Product Cost Center Cant be left empty'

end

IF @object_type='22' and @transaction_type IN (N'A',N'U')


Begin

if exists(select * from opor a inner join (select docentry,case when


left(b.taxcode,1)='C' then 3 when left(b.taxcode,1)='J'
then 4 when left(b.taxcode,1)='U' then 5
when left(b.taxcode,1)='H' then 7
when left(b.taxcode,1)='P' then 8
when left(b.taxcode,1)='A' then 9
else 0 end
u_location from por1 b WHERE DocEntry=@list_of_cols_val_tab_del) d on
a.docentry=d.docentry
inner join ousr c on a.usersign=c.userid
where d.u_location<>c.u_location
and a.DocEntry=@list_of_cols_val_tab_del )
SELECT @Error=2201, @error_message = 'tax code wrongly selected'
end

IF @object_type='20' and @transaction_type IN (N'A',N'U')


Begin

Set @BaseType=(Select Top 1 U_GRNType From OPDN Where DocEntry=@list_of_cols_val_tab_del)


Set @BaseEntry=(Select Top 1 U_GPEntry From PDN1 Where
DocEntry=@list_of_cols_val_tab_del)

if exists(Select a.U_GPEntry,count(*) cnt from


(select distinct A.DocEntry,A.U_GPEntry from PDN1 A INNER JOIN OPDN B ON
A.DOCENTRY=B.DocEntry where isnull(B.U_GRNType,'')<>''
and A.U_GPEntry=@BaseEntry and B.U_GRNType='BO') a
group by a.U_GPEntry having count(*)>1)
SELECT @Error=2025, @error_message = 'Gate Pass No. should not be duplicated'

if exists(select * from opDN a inner join (select docentry,case when


left(b.taxcode,1)='C' then 3 when left(b.taxcode,1)='J' then 4 when
left(b.taxcode,1)='U' then 5
when left(b.taxcode,1)='H' then 7
when left(b.taxcode,1)='P' then 8
when left(b.taxcode,1)='A' then 9
else 0 end
u_location
from pDN1 b) d on a.docentry=d.docentry
inner join ousr c on a.usersign=c.userid
where d.u_location<>c.u_location
and a.DocEntry=@list_of_cols_val_tab_del )
SELECT @Error=2001, @error_message = 'tax code wrongly selected'
end

IF @object_type='20' and @transaction_type IN (N'A')


Begin
if exists (select * from [OPDN] a,[PDN1] b
where a.DocEntry=b.DocEntry and a.docdate<>CAST(CONVERT(NVARCHAR(8),GETDATE(),112) AS
DATETIME) and a.usersign not in ('1','139','68','67') and
a.DocEntry=@list_of_cols_val_tab_del )
SELECT @Error=2002 , @error_message = 'Posting Date Should be Current System Date'
end

IF @object_type='20' and @transaction_type IN (N'A')


Begin
if exists (select A.DOCNUM,A.DocDate,B.U_BaseType,B.U_BaseNum,C.DocDate FROM [dbo].[OPDN]
A INNER JOIN [dbo].[PDN1] B
ON A.DOCENTRY=B.DOCENTRY INNER JOIN [dbo].[OPOR] C ON B.U_BASENUM=C.DOCNUM AND
B.U_BASETYPE=C.OBJTYPE
AND B.U_BaseEntry=C.DocEntry
WHERE A.U_GRNType='BO' AND A.DocDate<C.DocDate and A.DocENTRY=@list_of_cols_val_tab_del)
begin
declare @pono nvarchar(15),@podate nvarchar(15)
select @pono=B.U_BaseNum,@podate=convert(nvarchar(12),C.DocDate,106) FROM [dbo].[OPDN] A
INNER JOIN [dbo].[PDN1] B
ON A.DOCENTRY=B.DOCENTRY INNER JOIN [dbo].[OPOR] C ON B.U_BASENUM=C.DOCNUM AND
B.U_BASETYPE=C.OBJTYPE
AND B.U_BaseEntry=C.DocEntry
WHERE A.U_GRNType='BO' AND A.DocDate<C.DocDate and A.DocENTRY=@list_of_cols_val_tab_del

SELECT @Error = 2003 , @error_message ='PO Date For the PO No:'+@pono+' is '+@podate+'
you cant add GRPO Today'
end
end

IF @object_type='18' and @transaction_type IN (N'A',N'U')


Begin

if exists(select * from opch a inner join (select docentry,case when


left(b.taxcode,1)='C' then 3 when left(b.taxcode,1)='J' then 4 when
left(b.taxcode,1)='U' then 5
when left(b.taxcode,1)='H' then 7
when left(b.taxcode,1)='P' then 8
when left(b.taxcode,1)='A' then 9
else 0 end
u_location
from pch1 b) d on a.docentry=d.docentry
inner join ousr c on a.usersign=c.userid
where d.u_location<>c.u_location and a.usersign <> ('185')
and a.DocEntry=@list_of_cols_val_tab_del )
SELECT @Error=2021, @error_message = 'tax code wrongly selected'
if exists(select a.docentry,b.price,c.price from opch a inner join pch1 b on
a.docentry=b.docentry
inner join pdn1 c on b.baseentry=c.docentry and b.baseline=c.linenum and b.basetype=20
where
isnull(b.price,0)<>isnull(c.price,0)
and a.DocEntry=@list_of_cols_val_tab_del )
SELECT @Error=2021, @error_message = 'GRPO Price and AP Invoice Price Mismatching'

end

IF @object_type='19' and @transaction_type IN (N'A',N'U')


Begin

if exists(select * from orpc a inner join (select docentry,case when


left(b.taxcode,1)='C' then 3 when left(b.taxcode,1)='J' then 4 when
left(b.taxcode,1)='U' then 5
when left(b.taxcode,1)='H' then 7
when left(b.taxcode,1)='P' then 8
when left(b.taxcode,1)='A' then 9
else 0 end
u_location
from rpc1 b) d on a.docentry=d.docentry
inner join ousr c on a.usersign=c.userid
where d.u_location<>c.u_location
and a.DocEntry=@list_of_cols_val_tab_del )
SELECT @Error=2021, @error_message = 'tax code wrongly selected'
end

--if @object_type='19' and @transaction_type IN (N'A',N'U')


--begin

--declare @baseentry1 as nchar(20)


--set @baseentry1=(
--select distinct c.DocEntry from orpc a inner join rpc1 b on a.docentry=b.docentry
--inner join pch1 c on b.baseentry=c.docentry
--where a.docentry=@list_of_cols_val_tab_del and a.doctype='I')

--if exists(select c.DocEntry,c.itemcode,c.LineNum,d.U_RejQty,sum(b.quantity) qty from


orpc a inner join rpc1 b
-- on a.docentry=b.docentry
--inner join pch1 c on b.baseentry=c.docentry
--inner join pdn1 d on c.BaseEntry=d.docentry and c.BaseLine=d.LineNum
--where c.docentry=@BaseEntry1
--and a.doctype='I'
--group by c.DocEntry,c.itemcode,d.U_RejQty,c.LineNum
--having sum(b.quantity)>d.U_RejQty)

--begin
--Select @error = -121, @error_message = 'Credit memo qty shouldnt be greater than
rejection qty'
--end
--end

/******Commented On 3-Aug-2016 Service Rejection Amount Based On Service Contract*******/


--if @object_type='19' and @transaction_type IN (N'A',N'U')
--begin
--declare @baseentry2 as nchar(20)
--set @baseentry2=''
--set @baseentry2=(
--select distinct c.DocEntry from orpc a inner join rpc1 b on a.docentry=b.docentry
--inner join pch1 c on b.baseentry=c.docentry AND B.BASETYPE=C.OBJTYPE
--where a.docentry=@list_of_cols_val_tab_del
--and a.doctype='S'
--)
--if exists(select
c.DocEntry,c.LineNum,d.U_RejQty,d.U_InspQty,c.LineTotal,round(c.LineTotal/isnull(b.U_Quan
tity,0),0) price,
--isnull(d.U_RejQty,0)*round(c.LineTotal/isnull(b.U_Quantity,0),0) rej_Amt,
--sum(b.linetotal) credit_AMt from orpc a inner join rpc1 b
-- on a.docentry=b.docentry
--inner join pch1 c on b.baseentry=c.docentry and b.BaseLine=c.linenum
--inner join pdn1 d on c.baseentry=d.docentry and c.BaseLine=d.LineNum
--where c.docentry=@BaseEntry2
--and
--a.doctype='S'
--and b.U_BaseType='GRN'
--group by c.DocEntry,c.LineNum,d.U_RejQty,d.U_InspQty,
--
c.LineTotal,round(c.LineTotal/isnull(b.U_Quantity,0),0),isnull(d.U_RejQty,0)*round(c.Line
Total/isnull(b.U_Quantity,0),0)
--having
sum(b.linetotal)>(isnull(d.U_RejQty,0)*round(c.LineTotal/isnull(b.U_Quantity,0),0))+(isnu
ll(d.U_RejQty,0)*round(c.LineTotal/isnull(b.U_Quantity,0),0))*5/100)

--begin
--Select @error = -121, @error_message = 'Credit memo amount should not be greater than
rejection amt'
--end
--END

IF @object_type='21' and @transaction_type IN (N'A',N'U')


Begin

if exists(select * from orpd a inner join (select docentry,case when


left(b.taxcode,1)='C' then 3 when left(b.taxcode,1)='J' then 4 when
left(b.taxcode,1)='U' then 5
when left(b.taxcode,1)='H' then 7
when left(b.taxcode,1)='P' then 8
when left(b.taxcode,1)='A' then 9
else 0 end
u_location
from rpd1 b) d on a.docentry=d.docentry
inner join ousr c on a.usersign=c.userid
where d.u_location<>c.u_location
and a.DocEntry=@list_of_cols_val_tab_del )
SELECT @Error=2021, @error_message = 'tax code wrongly selected'
end

IF @object_type='140000009' and @transaction_type IN (N'A',N'U')


Begin

if exists(select * from ooei a inner join (select docentry,case when


left(b.taxcode,1)='C' then 3 when left(b.taxcode,1)='J' then 4 when
left(b.taxcode,1)='U' then 5
when left(b.taxcode,1)='H' then 7
when left(b.taxcode,1)='P' then 8
when left(b.taxcode,1)='A' then 9
else 0 end
u_location
from oei1 b ) d on a.docentry=d.docentry
inner join ousr c on a.usersign=c.userid
where d.u_location<>c.u_location
and a.DocEntry=@list_of_cols_val_tab_del )
SELECT @Error=2021, @error_message = 'tax code wrongly selected'

if exists(select a.DocDate,b.* from ooei a inner join oei1 b on a.docentry=b.docentry


inner join nnm1 c on a.series=c.series
where b.basetype=15
and c.SeriesName like '%ST%'
and a.DocEntry=@list_of_cols_val_tab_del )
SELECT @Error=2021, @error_message = 'For Delivery based Transaction, do not select ST
series '

if exists(select a.DocDate,b.* from ooei a inner join oei1 b on a.docentry=b.docentry


inner join nnm1 c on a.series=c.series
where b.basetype=67
and c.SeriesName not like '%ST%'
and a.DocEntry=@list_of_cols_val_tab_del )
SELECT @Error=2021, @error_message = 'For Inventory transfer based Transaction, please
select ST series '

end

IF @object_type='140000010' and @transaction_type IN (N'A',N'U')


Begin

if exists(select * from oiei a inner join (select docentry,case when


left(b.taxcode,1)='C' then 3 when left(b.taxcode,1)='J' then 4 when
left(b.taxcode,1)='U' then 5
when left(b.taxcode,1)='H' then 7
when left(b.taxcode,1)='P' then 8
when left(b.taxcode,1)='A' then 9
else 0 end
u_location
from iei1 b ) d on a.docentry=d.docentry
inner join ousr c on a.usersign=c.userid
where d.u_location<>c.u_location
and a.DocEntry=@list_of_cols_val_tab_del )
SELECT @Error=2021, @error_message = 'tax code wrongly selected'
end

IF @object_type='17' and @transaction_type IN (N'A',N'U')


Begin

if exists(select * from ordr a inner join (select docentry,case when


left(b.taxcode,1)='C' then 3 when left(b.taxcode,1)='J'
then 4 when left(b.taxcode,1)='U' then 5
when left(b.taxcode,1)='H' then 7
when left(b.taxcode,1)='P' then 8
when left(b.taxcode,1)='A' then 9
else 0 end
u_location
from rdr1 b) d on a.docentry=d.docentry
inner join ousr c on a.usersign=c.userid
where d.u_location<>c.u_location
and a.DocEntry=@list_of_cols_val_tab_del )
SELECT @Error=1701, @error_message = 'tax code wrongly selected'

if exists(SELECT T0.DocNum,T0.U_SalesType FROM [dbo].[ORDR] T0


INNER JOIN [dbo].[NNM1] T1 ON T0.ObjType=T1.ObjectCode AND T0.Series=T1.Series
WHERE T1.Remark like '%%FREE SAMPLE%%' AND ISNULL(T0.U_SalesType,'')='' and
T0.DocEntry=@list_of_cols_val_tab_del )
SELECT @Error=1703, @error_message = 'Please Select Sales Type...'

-------After Eway Bill All Locations Considered Delivery Type as Direct So Disable this
Below Control----------

--if exists(SELECT T0.DocEntry,T0.DOCNUM,T0.CardCode,T0.CardName,T0.U_DELTYPE FROM


[dbo].[ORDR] T0
--WHERE T0.CardCode not in (select DISTINCT U_CARDCODE from [dbo].[@INS_OODE] WHERE
ISNULL(U_CARDCODE,'')!='' AND U_TYPE!='CI')
--AND ISNULL(T0.U_DELTYPE,'')!='DI'
--and T0.DocEntry=@list_of_cols_val_tab_del )
--SELECT @Error=1702, @error_message = 'Please Select Delivery Type as Direct...'

--if exists(SELECT T0.DocEntry,T0.DOCNUM,T0.CardCode,T0.CardName,T0.U_DELTYPE FROM


[dbo].[ORDR] T0
--WHERE T0.CardCode in (select DISTINCT U_CARDCODE from [dbo].[@INS_OODE] WHERE
ISNULL(U_CARDCODE,'')!='' AND U_TYPE!='CI')
--AND ISNULL(T0.U_DELTYPE,'')!='DE' and T0.cardcode not in ('CC1023','CC1019','CC1202')
--and T0.DocEntry=@list_of_cols_val_tab_del )
--SELECT @Error=1704, @error_message = 'Please Select Delivery Type as Depot...'

if exists (select a.docentry from [ordr] a inner join [rdr1] b on a.docentry=b.docentry


where a.doctype='I' and a.U_DELTYPE<>'DI' and a.docentry=@list_of_cols_val_tab_del)
select @error=1702, @error_message='Please Select Delivery Type as Direct'

--if exists(SELECT a.docentry FROM ORDR A INNER JOIN RDR1 B ON A.DOCENTRY=B.DOCENTRY


INNER JOIN ADOC C ON A.DOCENTRY=B.DOCENTRY
--INNER JOIN ADO1 D ON A.DOCENTRY=D.DOCENTRY AND B.LineNum=D.LineNum
--WHERE B.Quantity<>D.QUANTITY
--and a.DocEntry=@list_of_cols_val_tab_del
--)
--SELECT @Error=1704, @error_message = 'Sales Order Qty should not be changed'

----------------------------------------------------------------------------------------

if exists(select a.CardCode,a.DocEntry,a.DocDate,b.TaxCode from ordr a inner join rdr1 b


on a.docentry=b.DocEntry INNER JOIN
(select a.KeyFld_1_V,b.TaxCode,b.EfctFrom,case when isnull(b.EfctTo,'')='' then GETDATE()
else isnull(b.EfctTo,'') end Effto
from TCD2 a inner join TCD3 b on a.absid=b.Tcd2Id
--where KeyFld_1_V='CC1147'
) M ON a.cardcode=m.KeyFld_1_V
where a.docdate between m.EfctFrom and m.Effto
and b.taxcode<>m.TaxCode
and a.DocEntry=@list_of_cols_val_tab_del )
SELECT @Error=1705, @error_message = 'Please Dont change the tax code'
if exists(select a.CardCode,a.DocEntry,a.DocDate,b.TaxCode,b.ItemCode from ordr a inner
join rdr1 b on a.docentry=b.DocEntry INNER JOIN
(select a.KeyFld_1_V,KeyFld_2_V,b.TaxCode,b.EfctFrom,case when isnull(b.EfctTo,'')=''
then GETDATE() else isnull(b.EfctTo,'') end Effto
from TCD2 a inner join TCD3 b on a.absid=b.Tcd2Id
where a.tcd1id=2
--where KeyFld_1_V='CC1147'
) M ON a.cardcode=m.KeyFld_1_V and b.ItemCode=m.KeyFld_2_V
where a.docdate between m.EfctFrom and m.Effto
and b.taxcode<>m.TaxCode
and a.DocEntry=@list_of_cols_val_tab_del )
SELECT @Error=1705, @error_message = 'Please Dont change the tax code'

if exists(SELECT A.DocEntry FROM ORDR A INNER JOIN RDR1 B ON A.DOCENTRY=B.DOCENTRY


WHERE ISNULL(A.CARDCODE,'')<>isnull(B.OcrCode,'')
and a.DocEntry=@list_of_cols_val_tab_del )
SELECT @Error=1704, @error_message = 'Customer Code and Cost Center Customer code
should not be change'

if exists(SELECT A.DocEntry FROM ORDR A INNER JOIN RDR1 B ON A.DOCENTRY=B.DocEntry


INNER JOIN OITM C ON B.ITEMCODE=C.ItemCode
INNER JOIN OITB D ON C.ItmsGrpCod=D.ItmsGrpCod
WHERE isnull(D.u_ccenter,'')<>isnull(b.ocrcode2,'')
and b.itemcode <>'PCO'
and a.DocEntry=@list_of_cols_val_tab_del )

SELECT @Error=1704, @error_message = 'Product Cost Center Mismatching'

if exists(SELECT A.DocEntry FROM ORDR A INNER JOIN RDR1 B ON A.DOCENTRY=B.DocEntry


WHERE isnull(b.ocrcode2,'')=''
and a.DocEntry=@list_of_cols_val_tab_del
and b.itemcode <>'PCO' )
SELECT @Error=1704, @error_message = 'Product Cost Center Cant be left empty'

end

IF @object_type='16' and @transaction_type IN (N'A',N'U')


Begin

if exists(SELECT A.DocEntry FROM ORDN A INNER JOIN RDN1 B ON A.DOCENTRY=B.DOCENTRY


WHERE ISNULL(A.CARDCODE,'')<>isnull(B.OcrCode,'')
and a.DocEntry=@list_of_cols_val_tab_del )
SELECT @Error=1704, @error_message = 'Customer Code and Cost Center Customer code
should not be change'

if exists(SELECT A.DocEntry FROM ORDN A INNER JOIN RDN1 B ON A.DOCENTRY=B.DocEntry


INNER JOIN OITM C ON B.ITEMCODE=C.ItemCode
INNER JOIN OITB D ON C.ItmsGrpCod=D.ItmsGrpCod
WHERE isnull(D.u_ccenter,'')<>isnull(b.ocrcode2,'')
and b.itemcode <>'PCO'
and a.DocEntry=@list_of_cols_val_tab_del )

SELECT @Error=1704, @error_message = 'Product Cost Center Mismatching'

if exists(SELECT A.DocEntry FROM ORDN A INNER JOIN RDN1 B ON A.DOCENTRY=B.DocEntry


WHERE isnull(b.ocrcode2,'')=''
and a.DocEntry=@list_of_cols_val_tab_del
and b.itemcode <>'PCO' )
SELECT @Error=1704, @error_message = 'Product Cost Center Cant be left empty'

--if exists(select a.DocEntry from [ordn] a inner join [rdn1] b on a.docentry=b.docentry


--inner join oitm c on b.itemcode=c.itemcode
--and isnull(c.PrchseItem,'')='N'
-- and a.docentry=@list_of_cols_val_tab_del)
--select @Error=1705, @error_message = 'Please Make Purchase Tick for the Selected Item'
---Not Needed.06.Aug.18

end

IF @object_type='15' and @transaction_type IN (N'A',N'U')


Begin

if exists(select * from [dbo].[ODLN] a inner join (select docentry,case when


left(b.taxcode,1)='C' then 3 when left(b.taxcode,1)='J' then 4 when
left(b.taxcode,1)='U' then 5
when left(b.taxcode,1)='H' then 7
when left(b.taxcode,1)='P' then 8
when left(b.taxcode,1)='A' then 9 else 0 end
u_location
from [dbo].[DLN1] b) d on a.docentry=d.docentry
inner join ousr c on a.usersign=c.userid
where d.u_location<>c.u_location
and a.DocEntry=@list_of_cols_val_tab_del )
SELECT @Error=2021, @error_message = 'tax code wrongly selected'

-------After Eway Bill All Locations Considered Delivery Type as Direct So Disable this
Below Control----------

--if exists(SELECT T0.DocEntry,T0.DOCNUM,T0.CardCode,T0.CardName,T0.U_DELTYPE FROM


[dbo].[ODLN] T0
--WHERE T0.CardCode not in (select DISTINCT U_CARDCODE from [dbo].[@INS_OODE] WHERE
ISNULL(U_CARDCODE,'')!='' AND U_TYPE!='CI')
--AND ISNULL(T0.U_DELTYPE,'')!='DI'
--and T0.DocEntry=@list_of_cols_val_tab_del )
--SELECT @Error=1503, @error_message = 'Please Select Delivery Type as Direct...'

--if exists(SELECT T0.DocEntry,T0.DOCNUM,T0.CardCode,T0.CardName,T0.U_DELTYPE FROM


[dbo].[ODLN] T0
--WHERE T0.CardCode in (select DISTINCT U_CARDCODE from [dbo].[@INS_OODE] WHERE
ISNULL(U_CARDCODE,'')!='' AND U_TYPE!='CI')
--AND ISNULL(T0.U_DELTYPE,'')!='DE' AND T0.cardcode not in ('CC1023','CC1019','CC1202')
--and T0.DocEntry=@list_of_cols_val_tab_del )
--SELECT @Error=1504, @error_message = 'Please Select Delivery Type as Depot...'

if exists (select a.docentry from [ODLN] a inner join [DLN1] b on a.docentry=b.docentry


where a.doctype='I' and a.U_DELTYPE<>'DI' and a.docentry=@list_of_cols_val_tab_del)
select @error=1503, @error_message='Please Select Delivery Type as Direct'

-----------------------------------------------------------------------------------------
----
if exists(select a.docentry,b.price,c.price from odln a inner join dln1 b on
a.docentry=b.docentry
inner join rdr1 c on b.baseentry=c.docentry and b.baseline=c.linenum and b.basetype=17
where a.doctype='I'
and isnull(b.price,0)<>isnull(c.price,0)
and a.DocEntry=@list_of_cols_val_tab_del )
SELECT @Error=1505, @error_message = 'Delivery and Sales Order Price Mismatching'

if exists(select a.CardCode,a.DocEntry,a.DocDate,b.TaxCode from [dbo].[ODLN] a inner join


[dbo].[DLN1] b on a.docentry=b.DocEntry INNER JOIN
(select a.KeyFld_1_V,b.TaxCode,b.EfctFrom,case when isnull(b.EfctTo,'')='' then GETDATE()
else isnull(b.EfctTo,'') end Effto
from [dbo].[TCD2] a inner join [dbo].[TCD3] b on a.absid=b.Tcd2Id
) M ON a.cardcode=m.KeyFld_1_V
where a.docdate between m.EfctFrom and m.Effto
and b.taxcode<>m.TaxCode
and a.DocEntry=@list_of_cols_val_tab_del )
SELECT @Error=1506, @error_message = 'Please Dont change the tax code'

if exists(select a.CardCode,a.DocEntry,a.DocDate,b.TaxCode,b.ItemCode from [dbo].[ODLN] a


inner join [dbo].[DLN1] b on a.docentry=b.DocEntry INNER JOIN
(select a.KeyFld_1_V,a.KeyFld_2_V,b.TaxCode,b.EfctFrom,case when isnull(b.EfctTo,'')=''
then GETDATE() else isnull(b.EfctTo,'') end Effto
from [dbo].[TCD2] a inner join [dbo].[TCD3] b on a.absid=b.Tcd2Id
where a.tcd1id=2
) M ON a.cardcode=m.KeyFld_1_V and b.ItemCode=m.KeyFld_2_V
where a.docdate between m.EfctFrom and m.Effto
and b.taxcode<>m.TaxCode
and a.DocEntry=@list_of_cols_val_tab_del )
SELECT @Error=1507, @error_message = 'Please Dont change the tax code'

end

IF @object_type='13' and @transaction_type IN (N'A',N'U')


Begin

Set @BaseEntry=(Select baseentry From oinv Where DocEntry=@list_of_cols_val_tab_del and


basetype='67')

if exists(select A.DocEntry from oinv a inner join (select docentry,case when


left(b.taxcode,1)='C' then 3 when left(b.taxcode,1)='J' then 4 when
left(b.taxcode,1)='U' then 5
when left(b.taxcode,1)='H' then 7
when left(b.taxcode,1)='P' then 8
when left(b.taxcode,1)='A' then 9
else 0 end
u_location
from inv1 b) d on a.docentry=d.docentry
inner join ousr c on a.usersign=c.userid
where d.u_location<>c.u_location
and a.DocEntry=@list_of_cols_val_tab_del )
SELECT @Error=1305, @error_message = 'tax code wrongly selected'

if exists(SELECT A.DocEntry,B.SeriesName,B.GroupCode,D.Grp FROM OINV A INNER JOIN NNM1 B


ON A.OBJTYPE=B.OBJECTCODE AND A.Series=B.Series
AND A.ObjType=B.ObjectCode
INNER JOIN INV1 C ON A.DOCENTRY=C.DocEntry
INNER JOIN (SELECT CODE,LOCATION,CASE CODE WHEN 3 THEN 1 WHEN 4 THEN 2 WHEN 5 THEN 3
WHEN 9 THEN 4 WHEN 7 THEN 5 WHEN 8 THEN 6 END Grp FROM OLCT WHERE CODE NOT IN (1,2,6)) D
ON C.LocCode=D.Code
WHERE A.BaseType='67' AND B.GroupCode<>D.Grp
and a.DocEntry=@list_of_cols_val_tab_del )
SELECT @Error=1305, @error_message = 'Choose Correct /ST/ Series'

if exists(SELECT a.DocEntry FROM OINV A


inner join NNM1 C ON A.OBJTYPE=C.OBJECTCODE AND A.SERIES=C.Series WHERE
isnull(a.basetype,'')<>'67'
and C.SeriesName LIKE '%%/ST'
and a.DocEntry=@list_of_cols_val_tab_del )
SELECT @Error=1305, @error_message = 'Inventory Transfer /ST/ Series not allowed'

if exists (select a.DocEntry from oinv a inner join inv1 b on a.docentry=b.DocEntry


inner join dln1 c on C.DocEntry =B .BaseEntry and C.LineNum =B.BaseLine
where isnull(b.quantity,0)<>isnull(c.quantity,0) and
a.DocEntry=@list_of_cols_val_tab_del)
select @error=1306, @error_message =' Qty Should not be changeable'

if exists(SELECT A.DocEntry FROM [dbo].[OINV] A INNER JOIN [dbo].[INV1] B ON


A.DOCENTRY=B.DOCENTRY
WHERE ISNULL(A.CARDCODE,'')<>isnull(B.OcrCode,'') AND A.BaseType!='67'
AND a.DocEntry=@list_of_cols_val_tab_del )
SELECT @Error=1307, @error_message = 'Customer Code and Cost Center Customer code
should not be change'

if exists(select A.DOCNUM,a.DocEntry,c.ItemCode from OINV a inner join INV1 b on


a.docentry=b.DocEntry
left join DLN1 c on b.baseentry=c.DocEntry and b.BaseLine=c.LineNum and b.basetype=15
where isnull(c.ItemCode,'')='' and a.basetype<>'67' AND A.GSTTrantyp NOT IN ('GD')
and a.doctype='I' and a.DocEntry=@list_of_cols_val_tab_del )
SELECT @Error=1308, @error_message = 'Selected Item not available in Delivery'

if exists (select * from oinv a inner join inv1 b on a.docentry=b.DocEntry


inner join [dln1] c on C.DocEntry =B .BaseEntry and C.LineNum =B.BaseLine
where isnull(b.Price,0)<>isnull(c.Price,0) and a.DocEntry=@list_of_cols_val_tab_del)
select @error=1309, @error_message = 'Price Should not be changeable.... Please Check
Price List'

-------After Eway Bill All Locations Considered Delivery Type as Direct So Disable this
Below Control----------

--if exists(SELECT T0.DocEntry,T0.DOCNUM,T0.CardCode,T0.CardName,T0.U_DELTYPE FROM


[dbo].[OINV] T0
--WHERE T0.CardCode not in (select DISTINCT U_CARDCODE from [dbo].[@INS_OODE] WHERE
ISNULL(U_CARDCODE,'')!='' AND U_TYPE!='CI')
--AND ISNULL(T0.U_DELTYPE,'')!='DI'
--and T0.DocEntry=@list_of_cols_val_tab_del )
--SELECT @Error=1303, @error_message = 'Please Select Delivery Type as Direct...'

--if exists(SELECT T0.DocEntry,T0.DOCNUM,T0.CardCode,T0.CardName,T0.U_DELTYPE FROM


[dbo].[OINV] T0
--WHERE T0.CardCode in (select DISTINCT U_CARDCODE from [dbo].[@INS_OODE] WHERE
ISNULL(U_CARDCODE,'')!='' AND U_TYPE!='CI')
--AND ISNULL(T0.U_DELTYPE,'')='DE' AND T0.cardcode not in ('CC1023','CC1019','CC1202')
--and T0.DocEntry=@list_of_cols_val_tab_del )
--SELECT @Error=1304, @error_message = 'Please Select Delivery Type as Direct...'

if exists (select a.docentry from [OINV] a inner join [INV1] b on a.docentry=b.docentry


where a.doctype='I' and a.U_DELTYPE<>'DI' and a.docentry=@list_of_cols_val_tab_del)
select @error=1303, @error_message='Please Select Delivery Type as Direct'
-----------------------------------------------------------------------------------------
--
if exists(select a.docentry,b.price,c.price from oinv a inner join inv1 b on
a.docentry=b.docentry
inner join dln1 c on b.baseentry=c.docentry and b.baseline=c.linenum and b.basetype=15
where a.doctype='I'
and isnull(b.price,0)<>isnull(c.price,0)
and a.DocEntry=@list_of_cols_val_tab_del )
SELECT @Error=1310, @error_message = 'Delivery and Invoice Price Mismatching'

if exists(select a.CardCode,a.DocEntry,a.DocDate,b.TaxCode from OINV a inner join INV1 b


on a.docentry=b.DocEntry INNER JOIN
(select a.KeyFld_1_V,b.TaxCode,b.EfctFrom,a.KeyFld_2_V,case when isnull(b.EfctTo,'')=''
then GETDATE() else isnull(b.EfctTo,'') end Effto
from TCD2 a inner join TCD3 b on a.absid=b.Tcd2Id
)M ON a.cardcode=m.KeyFld_1_V
where a.docdate between m.EfctFrom and m.Effto
and b.taxcode<>m.TaxCode
and isnull(m.KeyFld_2_V,'')=''
and a.DocEntry=@list_of_cols_val_tab_del )
SELECT @Error=1706, @error_message = 'Please Dont change the tax code'

if exists(select a.CardCode,a.DocEntry,a.DocDate,b.TaxCode,b.ItemCode from OINV a inner


join INV1 b on a.docentry=b.DocEntry INNER JOIN
(select a.KeyFld_1_V,a.KeyFld_2_V,b.TaxCode,b.EfctFrom,case when isnull(b.EfctTo,'')=''
then GETDATE() else isnull(b.EfctTo,'') end Effto
from TCD2 a inner join TCD3 b on a.absid=b.Tcd2Id
where a.tcd1id=2
)M ON a.cardcode=m.KeyFld_1_V and b.ItemCode=m.KeyFld_2_V
where a.docdate between m.EfctFrom and m.Effto
and b.taxcode<>m.TaxCode
and a.DocEntry=@list_of_cols_val_tab_del )
SELECT @Error=1707, @error_message = 'Please Dont change the tax code'

if exists(SELECT A.DocEntry FROM OINV A INNER JOIN INV1 B ON A.DOCENTRY=B.DocEntry


INNER JOIN OITM C ON B.ITEMCODE=C.ItemCode
INNER JOIN OITB D ON C.ItmsGrpCod=D.ItmsGrpCod
WHERE isnull(D.u_ccenter,'')<>isnull(b.ocrcode2,'')
and b.itemcode <>'PCO'
and a.DocEntry=@list_of_cols_val_tab_del )
SELECT @Error=1704, @error_message = 'Product Cost Center Mismatching'

if exists(SELECT A.DocEntry FROM OINV A INNER JOIN INV1 B ON A.DOCENTRY=B.DocEntry


WHERE isnull(b.ocrcode2,'')=''
and a.DocEntry=@list_of_cols_val_tab_del
and b.itemcode <>'PCO' )
SELECT @Error=1704, @error_message = 'Product Cost Center Cant be left empty'

if exists(SELECT BaseEntry,count(*) cnt FROM OINV A


where a.baseentry=@BaseEntry
group by BaseEntry
having count(*)>1
)
SELECT @Error=1305, @error_message = 'Inventory Transfer Cant be duplicated'

end

IF @object_type='14' and @transaction_type IN (N'A',N'U')


Begin

if exists(select * from orin a inner join (select docentry,case when


left(b.taxcode,1)='C' then 3 when left(b.taxcode,1)='J' then 4 when
left(b.taxcode,1)='U' then 5
when left(b.taxcode,1)='H' then 7
when left(b.taxcode,1)='P' then 8
when left(b.taxcode,1)='A' then 9
else 0 end
u_location
from rin1 b) d on a.docentry=d.docentry
inner join ousr c on a.usersign=c.userid
where d.u_location<>c.u_location
and a.DocEntry=@list_of_cols_val_tab_del )
SELECT @Error=2021, @error_message = 'tax code wrongly selected'

if exists(SELECT A.DocEntry FROM ORIN A INNER JOIN RIN1 B ON A.DOCENTRY=B.DOCENTRY


WHERE ISNULL(A.CARDCODE,'')<>isnull(B.OcrCode,'')
AND a.DocEntry=@list_of_cols_val_tab_del )
SELECT @Error=2021, @error_message = 'Customer Code and Cost Center Customer code
should not be change'

end

IF @object_type='2' and @transaction_type IN (N'A',N'U')


Begin

if exists(select a.cardcode from [OCRD] a where a.cardtype='C' and


isnull(a.IndustryC,'')='' and
a.cardcode=@list_of_cols_val_tab_del)
select @Error=1251, @error_message = 'Kindly Link Industry Field BP Master Data'

end

IF @object_type='4' and @transaction_type IN (N'A',N'U')


Begin

if exists(select b.itemcode,b.whscode,b.onhand from oitm a inner join oitw b on


a.itemcode=b.itemcode
where b.whscode like '%IYR%'
and (isnull(a.u_qccheck,'N')='N' or isnull(a.u_qcinsp,'N')='N')
and b.onhand>0 and a.itemcode=@list_of_cols_val_tab_del )

SELECT @Error=2021, @error_message = 'Dont change QC field values'


end

IF @object_type='4' and @transaction_type IN (N'A',N'U')


Begin
if exists(select * from OITM A WHERE A.QRYGROUP21=A.QRYGROUP22 AND
a.itemcode=@list_of_cols_val_tab_del and A.itemtype<>'F' )
SELECT @Error=2021, @error_message = 'Item Property Must Be Either Bom or Non Bom'
end

IF @object_type='4' and @transaction_type IN (N'A')


Begin

if exists(select A.ITEMCODE,ISNULL(BWeight1,0.000000) Weight1


from OITM A WHERE (A.QRYGROUP21='Y' OR A.QRYGROUP22='Y') AND ISNULL(BWeight1,0.000000)=0
AND a.itemcode=@list_of_cols_val_tab_del )
SELECT @Error=0401, @error_message = 'Please Enter Weight on Purchasing Data Tab...'
end

IF @object_type='4' and @transaction_type IN (N'U')


Begin

if exists(select * from OITM A WHERE A.QRYGROUP21='Y'


AND A.ITEMCODE IN (SELECT DISTINCT CODE FROM OITT UNION ALL SELECT DISTINCT CODE FROM
ITT1) AND a.itemcode=@list_of_cols_val_tab_del)
SELECT @Error=2021, @error_message = 'BOM Item Must Be Linked With Item Property
BOM....'
end

IF @object_type='4' and @transaction_type IN (N'A',N'U')


Begin

if exists(select * from [oitm] a where a.ItmsGrpCod in ('154','137') AND


ISNULL(a.U_PLCShortId,'')=''
and a.itemcode=@list_of_cols_val_tab_del)
select @Error=2024, @error_message = 'Kindly Enter PLC short ID!!!!'

end

--IF @object_type='4' and @transaction_type IN (N'U')


--Begin

--if exists(select * from OITM A WHERE A.QRYGROUP22='Y'


--AND A.ITEMCODE NOT IN (SELECT DISTINCT CODE FROM OITT UNION ALL SELECT DISTINCT CODE
FROM ITT1) AND a.itemcode=@list_of_cols_val_tab_del)
--SELECT @Error=2021, @error_message = 'NonBOM Item Must Be Linked With Item Property
Non BOM....'
-- end

--IF @object_type='SNL' and @transaction_type IN (N'A',N'U')


--Begin

----if exists(Select U_prefix,count(*) cnt from [@inm_snl2] where isnull(U_Prefix,'')<>''


----group by U_prefix having count(*)>1)
----SELECT @Error=2021, @error_message = 'Prefix Already Exists'

--if exists(Select U_ItemCode,count(*) cnt from [@inm_snl1] where


isnull(U_ItemCode,'')<>''
--group by U_ItemCode having count(*)>1)
--SELECT @Error=2021, @error_message = 'ItemCode Already Exists'
--end

-------------serial no logic ---------------------------------------

IF @object_type = 'SNL' and @transaction_type IN (N'A',N'U')

BEGIN

EXEC @Result =[dbo].[@INSPL_Production_TN_SerialNumberLogic]


@list_of_cols_val_tab_del

IF @Result <> 0

SELECT @error = U_ErrorCode , @error_message = U_ErrorName FROM OADM

END

-------------------------------------------Depot/Customer Inward Entry-------------------


---

IF @object_type = 'ODE' and @transaction_type IN (N'A',N'U')

BEGIN

EXEC @Result =[dbo].[@INSPl_Sales_TN_Depot/Customer_InwardEntry]


@list_of_cols_val_tab_del

IF @Result <> 0

SELECT @error = U_ErrorCode , @error_message = U_ErrorName FROM OADM

END

IF @object_type='15' and @transaction_type IN (N'A',N'U')


Begin

if exists(select U_DelType,docentry from odln


where isnull(u_deltype,'')='' and docentry=@list_of_cols_val_tab_del )

SELECT @Error=2021, @error_message = 'Delivery Type Cant be left empty'


end

IF @object_type='13' and @transaction_type IN (N'A',N'U')


Begin

if exists(select a.docentry from oinv a inner join inv1 b on a.docentry=b.docentry inner


join odln c on b.baseentry=c.docentry
where isnull(a.u_deltype,'')<>isnull(c.u_deltype,'') and
a.docentry=@list_of_cols_val_tab_del )

SELECT @Error=2021, @error_message = 'Invoice Delivery Type should match with DI


delivery type'
end
IF @object_type='13' and @transaction_type IN (N'A',N'U')
Begin

if exists(select U_DelType,docentry from [dbo].[oinv]


where isnull(u_deltype,'')='' and docentry=@list_of_cols_val_tab_del )

SELECT @Error=2021, @error_message = 'Delivery Type Cant be left empty'


end
----------------Meharaj--------------------------
IF @object_type='17' and @transaction_type IN (N'A',N'U')
Begin

if exists(select a.cardcode,c.CardCode,b.itemcode,c.ItemCode from ordr a inner join


rdr1 b on a.docentry=b.docentry left join ospp c
on a.cardcode=c.cardcode and b.itemcode=c.itemcode
where b.itemcode!='PCO' and isnull(c.itemcode,'')='' and
a.docentry=@list_of_cols_val_tab_del )

SELECT @Error=1721, @error_message = 'Please add the item into Price List'
end

-----------------------------Meharaj----------------------
IF @object_type='15' and @transaction_type IN (N'A',N'U')
Begin

if exists(select a.docentry from odln a inner join dln1 b on a.docentry=b.docentry inner


join oinv c on b.TrgetEntry=c.docentry
where isnull(a.u_deltype,'')<>isnull(c.u_deltype,'') and
a.docentry=@list_of_cols_val_tab_del )

SELECT @Error=2021, @error_message = 'Delivery Type cant be change'


end
-----------------Delivery SHould be Made on Same Month of Sales order 22/04/2017 As per
Requirement----------------
IF @object_type='15' and @transaction_type IN (N'A')
Begin

if exists(SELECT T0.DOCNUM,T0.DocDate,T3.DocDate,T4.SeriesName FROM [dbo].[ODLN] T0


INNER JOIN [dbo].[DLN1] T1 ON T0.DocEntry=T1.DocEntry
INNER JOIN [dbo].[RDR1] T2 ON T1.BaseType=T2.ObjType AND T1.BaseEntry=T2.DocEntry and
T1.BaseLine=T2.LineNum
INNER JOIN [dbo].[ORDR] T3 ON T2.DocEntry=T3.DocEntry AND T1.BaseDocNum=T3.DocNum
INNER JOIN [dbo].[NNM1] T4 ON T0.ObjType=T4.ObjectCode AND T0.Series=T4.Series
WHERE CONVERT(NVARCHAR(6),T0.DocDate,112)<>CONVERT(NVARCHAR(6),T3.DocDate,112) and
T0.docentry=@list_of_cols_val_tab_del )

SELECT @Error=1501, @error_message = 'Delivery Should be Made On the Same Month of


Sales order Created..'
end

-------------------------------------------BOM Update MODE RESTRICTION-------------------


----------------
-- dixit / mohamed yucub / sthiya/
IF @transaction_type IN (N'U') AND (@Object_type = N'66')
BEGIN
If Exists (Select * from [OITT] A inner join [ITT1] B on A.Code =B.Father
wHERE a.Code =@list_of_cols_val_tab_del and a.UserSign2 in('35','36','169','188'))
begin
SET @error=1050
SET @error_message = 'Please contact manager... You dont have permission update the
BOM'
End
End

-------------------------------------------BOM ADD MODE RESTRICTION----------------------


-------------
-- abdul/ thanigai
IF @transaction_type IN (N'A') AND (@Object_type = N'66')
BEGIN
If Exists (Select * from [OITT] A inner join [ITT1] B on A.Code =B.Father
wHERE a.Code =@list_of_cols_val_tab_del and a.UserSign in('32'))
begin
SET @error=1050
SET @error_message = 'Please contact manager... You dont have permission Create the
BOM'
End
End

-- Item Master Weight


IF @transaction_type IN (N'A') AND (@Object_type = N'66')
BEGIN
If Exists (SELECT T0.ItemCode,ISNULL(T0.BWeight1,0.000000) Weight FROM [dbo].[OITM] T0
INNER JOIN [dbo].[ITT1] T1 ON T0.ItemCode=T1.Code INNER JOIN [dbo].[OITT] T2 ON
T1.Father=T2.Code
WHERE (T0.QryGroup21='Y' OR T0.QryGroup22='Y') AND ISNULL(T0.BWeight1,0.000000)=0 AND
T1.Code=@list_of_cols_val_tab_del)
begin
DECLARE @ITEM NVARCHAR(150)

SELECT @ITEM=T0.ItemCode FROM [dbo].[OITM] T0


INNER JOIN [dbo].[ITT1] T1 ON T0.ItemCode=T1.Code INNER JOIN [dbo].[OITT] T2 ON
T1.Father=T2.Code
WHERE (T0.QryGroup21='Y' OR T0.QryGroup22='Y') AND ISNULL(T0.BWeight1,0.000000)=0 AND
T2.Code=@list_of_cols_val_tab_del

SET @error=6601
SET @error_message = 'Please Enter Weight for '+@ITEM+' in Item Master first...'
End
End

IF @transaction_type IN (N'A') AND (@Object_type = N'66')


BEGIN
If Exists (SELECT T0.ItemCode,ISNULL(T0.BWeight1,0.000000) Weight FROM [dbo].[OITM] T0
INNER JOIN [dbo].[OITT] T1 ON T0.ItemCode=T1.Code
WHERE (T0.QryGroup21='Y' OR T0.QryGroup22='Y') AND ISNULL(T0.BWeight1,0.000000)=0 AND
T1.Code=@list_of_cols_val_tab_del)
BEGIN
SET @error=6602
SET @error_message = 'Please Enter Weight for '+@list_of_cols_val_tab_del+' in Item
Master first...'
End
End
------------------Warehouse Mismatch Add Mode------------------------
IF @transaction_type IN (N'A') AND (@Object_type = N'66')
BEGIN
If Exists (select a.Code,e.Location,f.Location from [OITT] a inner join [ITT1] b on
a.Code=b.Father
left join [OWHS] c on a.ToWH=c.WhsCode
left join [OWHS] d on b.Warehouse=d.WhsCode
left join [OLCT] e on c.Location=e.Code
left join [OLCT] f on d.Location=f.Code
where c.Location<>d.Location and a.Code=@list_of_cols_val_tab_del)
BEGIN
SET @error=6603
SET @error_message = 'Location Mismatch please choose correct Location Warehouse!!!!!!!'
End
End

-------- Warehouse Mismacth Update Mode------------

IF @transaction_type IN (N'U') AND (@Object_type = N'66')


BEGIN
If Exists (select a.Code,e.Location,f.Location from [OITT] a inner join [ITT1] b on
a.Code=b.Father
left join [OWHS] c on a.ToWH=c.WhsCode
left join [OWHS] d on b.Warehouse=d.WhsCode
left join [OLCT] e on c.Location=e.Code
left join [OLCT] f on d.Location=f.Code
where c.Location<>d.Location and a.Code=@list_of_cols_val_tab_del)
begin
SET @error=6604
SET @error_message = 'Location Mismatch please choose correct Location Warehouse!!!!!!!'
End
End
-----------------

--IF @transaction_type IN (N'A',N'U') AND (@Object_type = N'66')


--BEGIN
--If Exists (select a.Code from oitt a inner join itt1 b on a.code=b.father
--inner join oitm c on a.code=c.ItemCode
--inner join oitm d on b.code=d.ItemCode
--where (isnull(c.BWeight1,0)=0 or isnull(d.BWeight1,0)=0) and
a.Code=@list_of_cols_val_tab_del)
--begin
--SET @error=6600
--SET @error_message = 'Without weight in Item Master BOM Cant add/update'
--End
--End

-- Item Master Scrap Item


IF @transaction_type IN (N'A') AND (@Object_type = N'66')
BEGIN
If Exists (select A.ScrapItem,B.Code from
(SELECT DISTINCT U_ScrapItem ScrapItem FROM [dbo].[OITM] B WHERE
ISNULL(B.U_ScrapItem,'')!='') A
INNER JOIN [dbo].[ITT1] B ON A.ScrapItem=B.Code INNER JOIN [dbo].[OITT] C ON
B.Father=C.code
WHERE C.Code=@list_of_cols_val_tab_del)
begin
DECLARE @SCRITEM NVARCHAR(150)
SELECT @SCRITEM=A.ScrapItem from
(SELECT DISTINCT U_ScrapItem ScrapItem FROM [dbo].[OITM] B WHERE
ISNULL(B.U_ScrapItem,'')!='') A
INNER JOIN [dbo].[ITT1] B ON A.ScrapItem=B.Code INNER JOIN [dbo].[OITT] C ON
B.Father=C.code
WHERE C.Code=@list_of_cols_val_tab_del

SET @error=6603
SET @error_message = @SCRITEM+' is a ScrapItem You cant add as a BOM Child...'
End
End
-- Item Master Scrap Item OITT
IF @transaction_type IN (N'A') AND (@Object_type = N'66')
BEGIN
If Exists (select A.ScrapItem,B.Code from
(SELECT DISTINCT U_ScrapItem ScrapItem FROM [dbo].[OITM] B WHERE
ISNULL(B.U_ScrapItem,'')!='') A
INNER JOIN [dbo].[OITT] B ON A.ScrapItem=B.Code
WHERE B.Code=@list_of_cols_val_tab_del)
begin
SET @error=6604
SET @error_message = @list_of_cols_val_tab_del+' is a ScrapItem You cant add as a BOM
Father...'
End
End
--------Approval template------
IF @transaction_type IN (N'A','U') AND (@Object_type = N'ATP')
BEGIN
IF EXISTS (SELECT A.CODE,a.Object,A.U_Name,b.U_OrgName,C.firstName,C.lastName FROM
[dbo].[@INIA_OATP] A
INNER JOIN [dbo].[@INIA_ATP1] b on a.code=b.Code
LEFT OUTER JOIN [dbo].[OHEM] C ON B.U_UserId=C.userId
WHERE A.U_Active='Y' AND C.empID IS NULL AND a.Code =@list_of_cols_val_tab_del)
BEGIN
DECLARE @USR NVARCHAR(250)
SET @USR=(SELECT TOP 1 b.U_OrgName FROM [dbo].[@INIA_OATP] A
INNER JOIN [dbo].[@INIA_ATP1] b on a.code=b.Code
LEFT OUTER JOIN [dbo].[OHEM] C ON B.U_UserId=C.userId
WHERE A.U_Active='Y' AND C.empID IS NULL AND a.DocEntry =@list_of_cols_val_tab_del)
SET @error=1050
SET @error_message = @USR+' User Not Linked With Employee Master...'
End
End

-------------------------------- Inventory Revaluation-------------------------


IF @object_type = '162' and @transaction_type IN (N'A',N'U')
BEGIN

if exists(SELECT A.docentry FROM OMRV a INNER JOIN MRV1 B ON A.DOCENTRY=B.DOCENTRY


INNER JOIN OITW C ON B.ITEMCODE=C.ITEMCODE
WHERE B.WHSCODE=C.WHSCODE
AND C.OnHand=0
and a.docentry=@list_of_cols_val_tab_del )

SET @error=1050
SET @error_message = 'Inventory revaluation cant be done when stock is zero'
END

-----------------------------------------------Outgoing payment validation---------------


----------
IF @object_type='46' and @transaction_type IN (N'A',N'U')
Begin
if exists(select a.docnum from ovpm a inner join vpm2 b on a.docentry=b.docnum
inner join ocrd oc on a.CardCode=oc.CardCode
inner join opch c on b.docentry=c.docentry
inner join pch1 d on c.docentry=d.docentry
inner join pdn1 e on d.baseentry=e.docentry and d.baseline=e.LineNum and
d.basetype=e.objtype
where b.invtype=18
and oc.groupcode<>121
and ((d.Quantity-d.OpenCreQty)<e.U_RejQty)
and c.DocType='I' and a.DocEntry=@list_of_cols_val_tab_del )
begin
DECLARE
@ITEMCOD NVARCHAR (100),@docnum NVARCHAR(20)
select @docnum=c.docnum,@ITEMCOD=d.ItemCode from ovpm a inner join vpm2 b on
a.docentry=b.docnum
inner join ocrd oc on a.CardCode=oc.CardCode
inner join opch c on b.docentry=c.docentry
inner join pch1 d on c.docentry=d.docentry
inner join pdn1 e on d.baseentry=e.docentry and d.baseline=e.LineNum and
d.basetype=e.objtype
where b.invtype=18
and oc.groupcode<>121
and ((d.Quantity-d.OpenCreQty)<e.U_RejQty)
and c.DocType='I' and a.DocEntry=@list_of_cols_val_tab_del ORDER BY D.LineNum DESC
begin
SELECT @Error=2021, @error_message = 'Itemcode:'+@ITEMCOD+', '+'Invoice
No:'+@docnum+'--Credit memo not raised.Please raise'
end
END
end

--IF @object_type = '46' and @transaction_type IN (N'A',N'U')


--BEGIN

--if exists(select a.docentry,a.tobe_paid,a.tpay+isnull(b.tpay,0) from (select


c.DocEntry,c.docnum,c.DocTotal-isnull(g.DocTotal,0) tobe_paid,sum(isnull(b.SumApplied,0))
tpay from ovpm a inner join vpm2 b on a.docnum=b.docnum
--inner join opch c on b.docentry=c.docentry
--inner join pch1 d on c.docentry=d.docentry
--inner join pdn1 e on d.baseentry=e.docentry and d.baseline=e.LineNum
--inner join RPC1 f on d.docentry=f.BaseEntry and d.LineNum=f.BaseLine
--inner join ORPC g on f.docentry=g.DocEntry
--where b.invtype=18
--and e.docentry in(select docentry from pdn1 where isnull(U_REJQTY,0)>0)
--and c.DocType='I'
--and a.DocEntry=@list_of_cols_val_tab_del
--group by c.DocEntry,c.docnum,c.DocTotal-isnull(g.DocTotal,0)
-- ) a
-- left join
-- (select c.DocEntry,c.docnum,c.DocTotal-isnull(g.DocTotal,0)
tobe_paid,sum(isnull(b.SumApplied,0)) tpay from ovpm a inner join vpm2 b on
a.docnum=b.docnum
--inner join opch c on b.docentry=c.docentry
--inner join pch1 d on c.docentry=d.docentry
--inner join pdn1 e on d.baseentry=e.docentry and d.baseline=e.LineNum
--inner join RPC1 f on d.docentry=f.BaseEntry and d.LineNum=f.BaseLine
--inner join ORPC g on f.docentry=g.DocEntry
--where b.invtype=18
--and e.docentry in(select docentry from pdn1 where isnull(U_REJQTY,0)>0)
--and c.DocType='I'
--and a.DocEntry<>@list_of_cols_val_tab_del
--group by c.DocEntry,c.docnum,c.DocTotal-isnull(g.DocTotal,0)
-- ) b on a.docentry=b.DocEntry
-- where a.tpay+isnull(b.tpay,0)>a.tobe_paid)

--SET @error=1050
--SET @error_message = 'Payment shold be deducted for Rejection Qty '

--END

------IF @object_type='46' and @transaction_type IN (N'A',N'U')


------Begin
------if exists(select a.docnum,c.DocNum
inv_no,c.DocDate,e.DocEntry,e.U_ItemCode,e.U_RejQty
------,f.docentry
------,c.doctype,b.InvType,h.DocNum from ovpm a inner join vpm2 b on a.DocEntry=b.docnum
------inner join opch c on b.docentry=c.docentry
------inner join pch1 d on c.docentry=d.docentry
------inner join pdn1 e on d.baseentry=e.docentry and d.baseline=e.LineNum
------inner join opdn h on e.docentry=h.docentry
------left join (select b.baseentry,b.baseline,b.docentry from orpc a inner join rpc1 b
on a.docentry=b.docentry
------where doctype='S') f
------on d.docentry=f.baseentry and d.linenum=f.BaseLine
------where b.invtype=18
------and isnull(e.u_rejqty,0)>0
------and c.DocType='S'
------and isnull(f.DocEntry,0)=0
------and d.u_basetype='GRN')
------begin
------SELECT @Error=2021, @error_message = 'Credit memo is not raised one of the
invoces'
------end
------end

--IF @object_type='13' and @transaction_type IN (N'A',N'U')


--Begin

--if exists(select a.docentry from oinv a inner join adoc b on a.docentry=b.docentry


--where isnull(a.u_deltype,'')<>isnull(b.u_deltype,'')
--and b.loginstanc<>1 and a.docentry=@list_of_cols_val_tab_del )

--SELECT @Error=2021, @error_message = 'Delivery type cant be change'


--end
--------------- meharaj comment the control 26-10-2016 19:00---------
IF @object_type='17' and @transaction_type IN (N'A',N'U')
Begin

if exists(select a.cardcode,c.CardCode,b.itemcode,c.ItemCode from ordr a inner join rdr1


b on a.docentry=b.docentry left join ospp c
on a.cardcode=c.cardcode and b.itemcode=c.itemcode
where b.itemcode!='PCO' and B.PRICE<>ISNULL(C.PRICE,0) AND
a.docentry=@list_of_cols_val_tab_del )

SELECT @Error=1721, @error_message = 'Price is not matching with price list price'
end
--------------- meharaj comment the control 26-10-2016 19:00---------
-------------------------------- Draft Validation-------------------------
--IF @object_type = '112' and @transaction_type IN (N'A',N'U')
--BEGIN

--if exists(select a.DocEntry from odrf a inner join drf1 b on a.docentry=b.docentry


--where a.objtype=22
--and a.series in (2588,2594,2598)
--and a.doctype<>'S'
--and a.docentry=@list_of_cols_val_tab_del )

--SET @error=1050
--SET @error_message = 'Please select Document type as service or select correct series'

--END

IF @object_type='1250000001' and @transaction_type IN (N'A',N'U')


Begin

if exists(SELECT b.SeriesName,A.DocNum,D.ItemCode,D.QRYGROUP44,A.ObjType FROM


[dbo].[OWTQ] A
INNER JOIN [dbo].[NNM1] B ON A.ObjType=B.ObjectCode AND A.Series=B.Series
INNER JOIN [dbo].[WTQ1] C ON A.DOCENTRY=C.DOCENTRY
INNER JOIN [dbo].[OITM] D ON C.ItemCode=D.ItemCode
WHERE B.SeriesName='1617C_ST' AND D.QRYGROUP44!='Y' AND
a.DocEntry=@list_of_cols_val_tab_del)
select @Error=1251, @error_message = 'Item property - Inter Unit Transfer Items Must Be
Tick'

end

---------Sales order Draft-------------------------------------------------------------


IF @object_type='112' and @transaction_type IN (N'A',N'U')
Begin

if exists(select * from [dbo].[ODRF] a inner join (select docentry,case when


left(b.taxcode,1)='C' then 3 when left(b.taxcode,1)='J'
then 4 when left(b.taxcode,1)='U' then 5
when left(b.taxcode,1)='H' then 7
when left(b.taxcode,1)='P' then 8
when left(b.taxcode,1)='A' then 9
else 0 end
u_location
from [dbo].[DRF1] b) d on a.docentry=d.docentry
inner join ousr c on a.usersign=c.userid
where A.OBJTYPE='17' AND d.u_location<>c.u_location
and a.DocEntry=@list_of_cols_val_tab_del )
SELECT @Error=1701, @error_message = 'tax code wrongly selected'
----------------Meharaj--------------------------

if exists(select a.cardcode,c.CardCode,b.itemcode,c.ItemCode from [dbo].[ODRF] a inner


join
[dbo].[DRF1] b on a.docentry=b.docentry left join ospp c
on a.cardcode=c.cardcode and b.itemcode=c.itemcode
where A.OBJTYPE='17' AND b.itemcode!='PCO' and isnull(c.itemcode,'')='' and
a.docentry=@list_of_cols_val_tab_del )

SELECT @Error=1721, @error_message = 'Please add the item into Price List'

--------------- meharaj comment the control 26-10-2016 19:00---------

if exists(select a.cardcode,c.CardCode,b.itemcode,c.ItemCode from [dbo].[ODRF] a inner


join [dbo].[DRF1] b on a.docentry=b.docentry left join ospp c
on a.cardcode=c.cardcode and b.itemcode=c.itemcode
where A.OBJTYPE='17' AND b.itemcode!='PCO' and B.PRICE<>ISNULL(C.PRICE,0) AND
a.docentry=@list_of_cols_val_tab_del )

SELECT @Error=1721, @error_message = 'Price is not matching with price list price'

if exists (select a.docentry from [dbo].[ODRF] a inner join [dbo].[DRF1] b on


a.docentry=b.docentry
where A.OBJTYPE='17' AND a.U_DELTYPE<>'DI' and a.docentry=@list_of_cols_val_tab_del)
select @error=17000, @error_message='Please Select Delivery Type as Direct'

if exists(SELECT T0.DocNum,T0.U_SalesType FROM [dbo].[ODRF] T0


INNER JOIN [dbo].[NNM1] T1 ON T0.ObjType=T1.ObjectCode AND T0.Series=T1.Series
WHERE T0.OBJTYPE='17' AND T1.Remark like '%%FREE SAMPLE%%' AND
ISNULL(T0.U_SalesType,'')='' and T0.DocEntry=@list_of_cols_val_tab_del )
SELECT @Error=1703, @error_message = 'Please Select Sales Type...'

if exists(select a.CardCode,a.DocEntry,a.DocDate,b.TaxCode from [dbo].[ODRF] a inner join


[dbo].[DRF1] b on a.docentry=b.DocEntry INNER JOIN
(select a.KeyFld_1_V,b.TaxCode,b.EfctFrom,case when isnull(b.EfctTo,'')='' then GETDATE()
else isnull(b.EfctTo,'') end Effto
from TCD2 a inner join TCD3 b on a.absid=b.Tcd2Id
--where KeyFld_1_V='CC1147'
) M ON a.cardcode=m.KeyFld_1_V
where A.OBJTYPE='17' AND a.docdate between m.EfctFrom and m.Effto
and b.taxcode<>m.TaxCode
and a.DocEntry=@list_of_cols_val_tab_del )
SELECT @Error=1705, @error_message = 'Please Dont change the tax code'

if exists(select a.CardCode,a.DocEntry,a.DocDate,b.TaxCode,b.ItemCode from [dbo].[ODRF] a


inner join [dbo].[DRF1] b on a.docentry=b.DocEntry INNER JOIN
(select a.KeyFld_1_V,KeyFld_2_V,b.TaxCode,b.EfctFrom,case when isnull(b.EfctTo,'')=''
then GETDATE() else isnull(b.EfctTo,'') end Effto
from TCD2 a inner join TCD3 b on a.absid=b.Tcd2Id
where a.tcd1id=2
--where KeyFld_1_V='CC1147'
) M ON a.cardcode=m.KeyFld_1_V and b.ItemCode=m.KeyFld_2_V
where A.OBJTYPE='17' AND a.docdate between m.EfctFrom and m.Effto
and b.taxcode<>m.TaxCode
and a.DocEntry=@list_of_cols_val_tab_del )
SELECT @Error=1705, @error_message = 'Please Dont change the tax code'

if exists(SELECT A.DocEntry FROM [dbo].[ODRF] A INNER JOIN [dbo].[DRF1] B ON


A.DOCENTRY=B.DOCENTRY
WHERE A.OBJTYPE='17' AND ISNULL(A.CARDCODE,'')<>isnull(B.OcrCode,'')
and a.DocEntry=@list_of_cols_val_tab_del )
SELECT @Error=1704, @error_message = 'Customer Code and Cost Center Customer code
should not be change'

if exists(SELECT A.DocEntry FROM [dbo].[ODRF] A INNER JOIN [dbo].[DRF1] B ON


A.DOCENTRY=B.DocEntry
INNER JOIN OITM C ON B.ITEMCODE=C.ItemCode
INNER JOIN OITB D ON C.ItmsGrpCod=D.ItmsGrpCod
WHERE A.OBJTYPE='17' AND isnull(D.u_ccenter,'')<>isnull(b.ocrcode2,'')
and b.itemcode <>'PCO'
and a.DocEntry=@list_of_cols_val_tab_del )

SELECT @Error=1704, @error_message = 'Product Cost Center Mismatching'

if exists(SELECT A.DocEntry FROM [dbo].[ODRF] A INNER JOIN [dbo].[DRF1] B ON


A.DOCENTRY=B.DocEntry
WHERE A.OBJTYPE='17' AND isnull(b.ocrcode2,'')=''
and a.DocEntry=@list_of_cols_val_tab_del
and b.itemcode <>'PCO' )
SELECT @Error=1704, @error_message = 'Product Cost Center Cant be left empty'
END

-----------------------------------------------------------------------------------------
---------

if @object_type='103' and @transaction_type IN (N'A',N'U')


begin
If Exists (select code from oclt
where usersign not in (1) and code=@list_of_cols_val_tab_del)
begin
Select @error = 100, @error_message = 'You are not allowed to add/modify activity type'
end
end

if @object_type='84' and @transaction_type IN (N'A',N'U')


begin
If Exists (select code from OCLS
where usersign not in (1) and code=@list_of_cols_val_tab_del)
begin
Select @error = 100, @error_message = 'You are not allowed to add/modify activity
Subject'
end
end
IF @object_type='140' and @transaction_type IN (N'A',N'U')
Begin
if exists(select a.docnum from opdf a inner join pdf2 b on a.docentry=b.docnum
inner join ocrd oc on a.CardCode=oc.CardCode
inner join opch c on b.docentry=c.docentry
inner join pch1 d on c.docentry=d.docentry
inner join pdn1 e on d.baseentry=e.docentry and d.baseline=e.LineNum
where b.invtype=18
and oc.groupcode<>121
and (d.Quantity-d.OpenCreQty<e.U_RejQty)
and c.DocType='I' and a.DocEntry=@list_of_cols_val_tab_del )
begin
DECLARE
@ITEMCOD1 NVARCHAR (100),@docnum1 NVARCHAR(20)
select @docnum1=c.docnum,@ITEMCOD1=d.ItemCode from opdf a inner join pdf2 b on
a.docentry=b.docnum
inner join ocrd oc on a.CardCode=oc.CardCode
inner join opch c on b.docentry=c.docentry
inner join pch1 d on c.docentry=d.docentry
inner join pdn1 e on d.baseentry=e.docentry and d.baseline=e.LineNum
where b.invtype=18
and oc.groupcode<>121
and (d.Quantity-d.OpenCreQty<e.U_RejQty)
and c.DocType='I' and a.DocEntry=@list_of_cols_val_tab_del ORDER BY D.LineNum DESC
begin
SELECT @Error=2021, @error_message = 'Itemcode:'+@ITEMCOD1+', '+'Invoice
No:'+@docnum1+'--Credit memo not raised.Please raise'
end
END
end

--IF @object_type = '140' and @transaction_type IN (N'A',N'U')


--BEGIN

--if exists(SELECT b.DocEntry,B.SumApplied FROM OPDF A INNER JOIN PDF2 B ON


A.DOCENTRY=B.DocNum
--INNER JOIN (select b.DocEntry,B.SumApplied from OPDF a inner join PDF2 b on
A.DOCENTRY=B.DocNum
--INNER JOIN OWDD C ON A.DOCENTRY=C.DocEntry
--left join OPCH d on a.docentry=d.draftKey
--where C.STATUS <>'N'
--and isnull(d.draftkey,'')=''
----and a.doctype='I'
--and A.ObjType='46'
--and a.docentry<>@list_of_cols_val_tab_del) C ON B.DocEntry=C.DocEntry
--AND B.SumApplied=C.SumApplied
--WHERE A.ObjType='46'
--and a.docentry=@list_of_cols_val_tab_del )

--SET @error=1050
--SET @error_message = 'Already Draftis raised for this Invoice'

--if exists(select a.docnum from opdf a inner join pdf2 b on a.docentry=b.docnum

--inner join (select a.docnum SGRN_NO,a.u_docdate SGRN_Date,a.u_cardcode Vendor_Code,


--a.U_CardName Vendor_Name,b.U_ItemCode,b.U_ItemName,b.U_Quantity Rece_Qty,
--b.U_TotalKg,b.U_InspQty,b.U_AccpQty
----,e.Amt_Paid
--,c.linetotal/b.U_Quantity price,m.accqty*(c.linetotal/b.U_Quantity)
Accp_Value,m.rejqty*(c.linetotal/b.U_Quantity) Rej_Value,f.docnum INv_No,f.docentry
Inv_docentry,f.ObjType
--from [dbo].[@INSC_OPDN]
--a inner join [dbo].[@INSC_PDN1] b on a.docentry=b.docentry
--inner join [dbo].[pdn1] c on b.docentry=c.U_BaseEntry and b.LineId=c.U_BaseLine and
a.Object=c.U_BaseType
--inner join [dbo].[pch1] d on c.docentry=d.baseentry and c.LineNum=d.BaseLine
--inner join [dbo].[opch] f on d.docentry=f.docentry
--left join (select a.U_GRNEntry ,b.U_ItemCode,b.U_BaseLine,sum(isnull(b.u_inspqty,0))
inspqty,sum(isnull(b.U_RejQty,0)) rejqty,
--sum(isnull(b.u_accpqty,0)) accqty from
--[dbo].[@INQ_OINW] a inner join [dbo].[@INQ_INW1] b on a.DocEntry=b.docentry

--where a.u_type='S'
----AND a.U_GRNNo=1002946
--group by a.U_GRNEntry ,b.U_ItemCode,B.U_BaseLine) m on b.DocEntry=m.U_GRNEntry and
b.LineId=m.U_BaseLine
--left join RPC1 R ON d.docentry=r.baseentry and d.LineNum=r.BaseLine
--where isnull(b.U_InspQty,0)>0
--and f.DocType='S'
--and (isnull((m.rejqty*(c.linetotal/b.U_Quantity)),0)-isnull(r.linetotal,0))>0) c on
b.DocEntry=c.inv_docentry and b.InvType=c.objtype
-- where a.DocEntry=@list_of_cols_val_tab_del )

--SET @error=1000
--SET @error_message = 'Please raise credit memo for the Invoice'
--end

--IF @object_type = '112' and @transaction_type IN (N'A',N'U')


--BEGIN

--if exists(select a.DocEntry from odrf a inner join drf1 b on a.docentry=b.docentry


--where a.objtype=22
--and a.series in
--(296,299,302)
--and a.doctype<>'S'
--and a.docentry=@list_of_cols_val_tab_del )

--SET @error=1050
--SET @error_message = 'Please select Document type as service or select correct series'

--if exists(SELECT A.DOCENTRY FROM ODRF A INNER JOIN DRF1 B ON A.DOCENTRY=B.DOCENTRY


--INNER JOIN (select A.CARDCODE,B.ItemCode from opor a inner join por1 b on
a.docentry=b.docentry
--where b.LineStatus<>'C'
--AND A.DocStatus<>'C'
--AND A.DocType='I') C ON A.CARDCODE=C.CARDCODE
--AND B.ITEMCODE=C.ITEMCODE
--WHERE A.ObjType='22'
--and a.docentry=@list_of_cols_val_tab_del )

--SET @error=1050
--SET @error_message = 'Already item is available in OPen PO for the vendor'

--if exists(SELECT A.DOCENTRY FROM ODRF A INNER JOIN DRF1 B ON A.DOCENTRY=B.DOCENTRY


--INNER JOIN (select A.CARDCODE,B.ItemCode from ODRF a inner join DRF1 b on
a.docentry=b.docentry
--INNER JOIN OWDD C ON A.DOCENTRY=C.DocEntry
--left join opor d on a.docentry=d.draftKey
--where C.STATUS <>'N'
--and isnull(d.draftkey,'')=''
--and a.doctype='I'
--and A.ObjType='22'
--and a.docentry<>@list_of_cols_val_tab_del) C ON A.CARDCODE=C.CARDCODE
--AND B.ITEMCODE=C.ITEMCODE
--WHERE A.ObjType='22'
--and a.docentry=@list_of_cols_val_tab_del )

--SET @error=1050
--SET @error_message = 'Already item is available in draft PO for the vendor'

--end

-- Select the return values

------------------transaction updation controls------------------


--IF @object_type='67' and @transaction_type IN (N'U')
--Begin

--if exists(select a.docentry from [OWTR] a where


-- a.DocEntry=@list_of_cols_val_tab_del)
--select @Error=1251, @error_message = 'Update is not alowed'

--end

IF @object_type='59' and @transaction_type IN (N'U')


Begin

if exists(select a.docentry from [OIGN] a where


a.DocEntry=@list_of_cols_val_tab_del)
select @Error=1251, @error_message = 'Update is not alowed'

end

IF @object_type='60' and @transaction_type IN (N'U')


Begin

if exists(select a.docentry from [OIGE] a where


a.DocEntry=@list_of_cols_val_tab_del)
select @Error=1251, @error_message = 'Update is not alowed'

end

-------------------Sales Screens-----------------------
--IF @object_type='17' and @transaction_type IN (N'U')
--Begin

--if exists(select a.docentry from ordr a where


-- a.DocEntry=@list_of_cols_val_tab_del)
--select @Error=98765, @error_message = 'Update is not alowed'

--end

IF @object_type='15' and @transaction_type IN (N'U')


Begin

if exists(select a.docentry from [ODLN] a where


a.DocEntry=@list_of_cols_val_tab_del)
select @Error=9876, @error_message = 'Update is not alowed'

end
IF @object_type='16' and @transaction_type IN (N'U')
Begin

if exists(select a.docentry from [ORDN] a where


a.DocEntry=@list_of_cols_val_tab_del)
select @Error=9876, @error_message = 'Update is not alowed'

end

IF @object_type='16' and @transaction_type IN (N'A')


Begin

if exists(select a.docentry from [ORDN] a INNER JOIN RDN1 B ON A.DOCENTRY=B.DOCENTRY


where B.STOCKPRICE=0 AND
a.DocEntry=@list_of_cols_val_tab_del )
select @Error=1601, @error_message = 'Item Cost is Zero You cant Add..Kindly Contact
Admin'

end

IF @object_type = '16' and @transaction_type IN (N'A',N'U')

BEGIN
if exists(SELECT a.DocEntry FROM ORDN A INNER JOIN RDN1 B ON A.DOCENTRY=B.DOCENTRY
INNER JOIN
(select a.DocEntry,a.itemcode,b.SysNumber,c.DistNumber from oitl a inner join itl1 b on
a.LogEntry=b.logentry
inner join osrn c on a.itemcode=c.itemcode and b.SysNumber=c.SysNumber
where a.itemcode=b.ItemCode
and a.doctype='16') C ON a.docentry=c.DocEntry and b.itemcode=c.ItemCode

inner join (SELECT A.U_ItemCode,C.U_SerialNo FROM [@INM_ORSE] A


INNER join [@INM_RSE2] C ON A.DOCENTRY=C.DocEntry
WHERE isnull(c.u_selected,'')='Y') d on b.ItemCode=d.U_ItemCode and
c.DistNumber=d.U_SerialNo
where A.DocEntry=@list_of_cols_val_tab_del )

begin
declare @SERIALNO2 NVARCHAR (30),@ITEMCOD3 NVARCHAR (100)

SELECT @ITEMCOD3=b.itemcode,@SERIALNO2=c.distnumber FROM ORDN A INNER JOIN RDN1 B ON


A.DOCENTRY=B.DOCENTRY
INNER JOIN
(select a.DocEntry,a.itemcode,b.SysNumber,c.DistNumber from oitl a inner join itl1 b on
a.LogEntry=b.logentry
inner join osrn c on a.itemcode=c.itemcode and b.SysNumber=c.SysNumber
where a.itemcode=b.ItemCode
and a.doctype='16') C ON a.docentry=c.DocEntry and b.itemcode=c.ItemCode

inner join (SELECT A.U_ItemCode,C.U_SerialNo FROM [@INM_ORSE] A


INNER join [@INM_RSE2] C ON A.DOCENTRY=C.DocEntry
WHERE isnull(c.u_selected,'')='Y') d on b.ItemCode=d.U_ItemCode and
c.DistNumber=d.U_SerialNo
where A.DocEntry=@list_of_cols_val_tab_del

begin
SELECT @Error=16, @error_message = 'Itemcode:'+@ITEMCOD3+', '+'Serial No:'+@serialno2+'
is already available in Rejection and Salvage.Please reselect'
end
end
end

--IF @object_type='13' and @transaction_type IN (N'U')


--Begin

--if exists(select a.docentry from [OINV] A WHERE


-- a.DocEntry=@list_of_cols_val_tab_del)
--select @Error=98765, @error_message = 'Update is not allowed'

--end

--IF @object_type='14' and @transaction_type IN (N'U')


--Begin

--if exists(select a.docentry from [ORIN] a where


-- a.DocEntry=@list_of_cols_val_tab_del)
--select @Error=98765, @error_message = 'Update is not alowed'

--end

-------------- END Sales Screens--------------------------


---------------- Purchase Screens------------------------
------ Amendment Not Working so Disable this control by Pradeep ( Mr.Meharaj Sir
Confirmation ) ----------
--IF @object_type='22' and @transaction_type IN (N'U')
--Begin

--if exists(select a.docentry from opor a where


-- a.DocEntry=@list_of_cols_val_tab_del)
--select @Error=87654, @error_message = 'Update is not alowed'

--end

IF @object_type='20' and @transaction_type IN (N'U')


Begin

if exists(select a.docentry from [OPDN] a where


a.DocEntry=@list_of_cols_val_tab_del)
select @Error=87654, @error_message = 'Update is not alowed'

end

IF @object_type='21' and @transaction_type IN (N'U')


Begin

if exists(select a.docentry from [ORPD] a where


a.DocEntry=@list_of_cols_val_tab_del)
select @Error=87654, @error_message = 'Update is not alowed'

end

--IF @object_type='18' and @transaction_type IN (N'U')


--Begin

--if exists(select a.docentry from opch a where


-- a.DocEntry=@list_of_cols_val_tab_del)
--select @Error=1251, @error_message = 'Update is not alowed'

--end

IF @object_type='19' and @transaction_type IN (N'U')


Begin

if exists(select a.docentry from [ORPC] a where


a.DocEntry=@list_of_cols_val_tab_del)
select @Error=1251, @error_message = 'Update is not alowed'

end

--IF @object_type='2' and @transaction_type IN (N'U')


--Begin

--if exists(select a.cardcode from [OCRD] a where


-- a.cardcode=@list_of_cols_val_tab_del)
--select @Error=1251, @error_message = 'Update is not alowed'

--end

--IF @object_type='4' and @transaction_type IN (N'U')


--Begin

--if exists(select a.itemcode from [OITM] a where


-- a.itemcode=@list_of_cols_val_tab_del)
--select @Error=1251, @error_message = 'Update is not alowed'

--end

IF @object_type='1' and @transaction_type IN (N'U')


Begin

if exists(select a.AcctCode from [OACT] a where


a.AcctCode=@list_of_cols_val_tab_del)
select @Error=1251, @error_message = 'Update is not alowed'

end

--IF @object_type='CRM' and @transaction_type IN (N'U')


--Begin

--if exists(select a.DocEntry from [@INM_OCRM] a where


-- a.DocEntry=@list_of_cols_val_tab_del)
--select @Error=1251, @error_message = 'Update is not alowed'

--end

--IF @object_type='MIS' and @transaction_type IN (N'U')


--Begin

--if exists(select a.DocEntry from [@INM_OMIS] a where


-- a.DocEntry=@list_of_cols_val_tab_del)
--select @Error=1251, @error_message = 'Update is not alowed'

--end

IF @object_type='SDS' and @transaction_type IN (N'A',N'U')


Begin

if exists(SELECT A.U_CardCode,A.U_BaseEntry FROM


(SELECT A.U_CardCode,A.U_BaseEntry,A.U_SONO,B.U_SOLineID,B.U_ItemCode FROM [@INS_OSDS] A
INNER JOIN [@INS_SDS1] B ON A.DOCENTRY=B.DOCENTRY
where B.U_ItemCode!='PCO' AND a.DocEntry=@list_of_cols_val_tab_del ) A
INNER JOIN
(SELECT A.U_CardCode,A.U_BaseEntry,A.U_SONO,B.U_SOLineID,B.U_ItemCode FROM [@INS_OSDS] A
INNER JOIN [@INS_SDS1] B ON A.DOCENTRY=B.DOCENTRY
where B.U_ItemCode!='PCO' AND a.DocEntry!=@list_of_cols_val_tab_del AND
CONVERT(VARCHAR(6),A.U_EffectOn,112)=CONVERT(VARCHAR(6),A.U_SODt,112)) B
ON A.U_CardCode=b.U_CardCode AND A.U_BaseEntry=B.U_BaseEntry AND
A.U_SONO=B.U_SONO AND A.U_SOLineID=B.U_SOLineID AND A.U_ItemCode=B.U_ItemCode )
select @Error=13101, @error_message = 'This Sales order PartNo Already Created..'

end

-----------------------------Alert user Locked ----------------------


IF @object_type='12' and @transaction_type IN (N'U')
Begin

if exists(select a.User_Code from [dbo].[OUSR] a where A.USERID=149 AND A.Locked='Y' AND


a.Userid=@list_of_cols_val_tab_del)
select @Error=1201, @error_message = 'AlertSvc User Should Not Locked'

end

-----------------------------Inventory Transfer Request Control ----------------------


IF @object_type='1250000001' and @transaction_type IN (N'A',N'U')
Begin

if exists(select a.DocEntry from owtq a inner join wtq1 b on a.docentry=b.docentry


inner join oitm c on b.itemcode=c.itemcode
and isnull(c.sellitem,'')='N'
and a.docentry=@list_of_cols_val_tab_del)
select @Error=1201, @error_message = 'Kindly select only Sale Item'

if exists(select a.DocEntry from owtq a inner join wtq1 b on a.docentry=b.docentry


inner join oitm c on b.itemcode=c.itemcode
and isnull(c.PrchseItem,'')='N'
and a.docentry=@list_of_cols_val_tab_del)
select @Error=1201, @error_message = 'Please Make Purchase Tick for the Selected Item'

if exists(select a.DocEntry from owtq a inner join wtq1 b on a.docentry=b.docentry


inner join oitm c on b.itemcode=c.itemcode
and isnull(c.GSTRelevnt,'')='N'
and a.docentry=@list_of_cols_val_tab_del)
select @Error=1201, @error_message = 'Please Make GST Tick for the Selected Item'

if exists (select a.DocEntry from [owtq] a inner join [wtq1] b on a.docentry=b.docentry


where ISNULL(B.U_BASETYPE,'')='' and a.towhscode='J-ST' and a.cardcode not in ('CJ2009')
and a.DocEntry=@list_of_cols_val_tab_del)
select @Error=1201, @Error_message ='Please Choose Correct BP Code'

if exists (select a.DocEntry from [owtq] a inner join [wtq1] b on a.docentry=b.docentry


where ISNULL(B.U_BASETYPE,'')='' and a.towhscode='U-ST' and a.cardcode not in ('CU3005')
and a.DocEntry=@list_of_cols_val_tab_del)
select @Error=1201, @Error_message ='Please Choose Correct BP Code'

if exists (select a.DocEntry from [owtq] a inner join [wtq1] b on a.docentry=b.docentry


where ISNULL(B.U_BASETYPE,'')='' and a.towhscode='A-ST' and a.cardcode not in ('CC1347')
and a.DocEntry=@list_of_cols_val_tab_del)
select @Error=1201, @Error_message ='Please Choose Correct BP Code'

if exists (select a.DocEntry from [owtq] a inner join [wtq1] b on a.docentry=b.docentry


where ISNULL(B.U_BASETYPE,'')='' and a.towhscode='P-ST' and a.cardcode not in ('CC1348')
and a.DocEntry=@list_of_cols_val_tab_del)
select @Error=1201, @Error_message ='Please Choose Correct BP Code'

if exists (select a.DocEntry from [owtq] a inner join [wtq1] b on a.docentry=b.docentry


where ISNULL(B.U_BASETYPE,'')='' and a.towhscode='H-ST' and a.cardcode not in ('CC1346')
and a.DocEntry=@list_of_cols_val_tab_del)
select @Error=1201, @Error_message ='Please Choose Correct BP Code'

end

IF @object_type='46' and @transaction_type IN (N'A',N'U')


Begin
if exists (select a.docentry from OVPM C INNER JOIN vpm2 a ON C.DOCENTRY=A.DOCNUM inner
join (select A.DocEntry from [OPCH] a inner join [PCH1] b on a.DocEntry=b.DocEntry
INNER JOIN OWHS OW ON B.WHSCODE=OW.WHSCODE INNER JOIN OLCT L ON OW.Location=L.CODE
INNER JOIN OCRD OC ON A.CARDCODE=OC.CARDCODE
left join [OITM] c on c.ItemCode=b.ItemCode
left join [PDN1] d on d.DocEntry=b.BaseEntry and d.ItemCode=b.ItemCode and
d.LineNum=b.BaseLine
left join [@INQ_OINW] e on e.U_GRNEntry=d.DocEntry
left join [@INQ_INW1] f on d.ItemCode=f.U_ItemCode and d.LineNum=f.U_BaseLine
INNER JOIN OWHS O ON B.WHSCODE=O.WhsCode
where a.DocType='I' and isnull(c.U_QCCheck,'')='Y' and isnull(E.docentry,'')=''
and a.cardcode not in ('SC1849','SC1870','SC1845','SC1471','SC1040')
and oc.groupcode<>121
AND ISNULL(O.DropShip,'')<>'Y'
AND ISNULL(B.TAXONLY,'')<>'Y'
and L.CODE=3)b on a.DocEntry=b.DocEntry
where C.DocEntry=@list_of_cols_val_tab_del
)
select @error=202222 , @error_message= 'Kindly Make Inward Inspection After Create
Payment'
end

-----------------closed------------------------------------------

select @error, @error_message

end

Вам также может понравиться