Saturday, 4 June 2016

Stored Procedure - Owner Name Mandatory for All Purchase & Sales Documents


-----------------------------------SQ-OWner Name Mandatory--------------------------------------------------
If @object_type = '23' and @transaction_type in ( 'A','U')



BEGIN
If exists (Select P.DocEntry, P.DocCur From OQUT P INNER JOIN QUT1 Q on P.DocEntry = Q.DocEntry

Where Q.DocEntry=@list_of_cols_val_tab_del

and isnull(P.OwnerCode ,'') = '' )

Select @error = 2300001-01,

@error_message = 'Please Set Owner Name for SQ'



end
-------------------------------------SO-OWner Name Mandatory---------------------------------------------------
If @object_type = '17' and @transaction_type in ( 'A','U')



BEGIN
If exists (Select P.DocEntry, P.DocCur From ORDR P INNER JOIN RDR1 Q on P.DocEntry = Q.DocEntry

Where Q.DocEntry=@list_of_cols_val_tab_del

and isnull(P.OwnerCode ,'') = '' )

Select @error = 1700001-01,

@error_message = 'Please Set Owner Name for SO'



end
----------------------------------------------------------------------------------------------------

-------------------------------------Delivery - Owner Name Mandatory---------------------------------------------------------------------
If @object_type = '15' and @transaction_type in ( 'A','U')



BEGIN
If exists (Select P.DocEntry, P.DocCur From ODLN P INNER JOIN DLN1 Q on P.DocEntry = Q.DocEntry

Where Q.DocEntry=@list_of_cols_val_tab_del

and isnull(P.OwnerCode ,'') = '' )

Select @error = 151-01,

@error_message = 'Please Set Owner Name for Delivery'



end
-------------------------------------Return - Owner Name Mandatory----------------------------------------------------------------------
If @object_type = '16' and @transaction_type in ( 'A','U')



BEGIN
If exists (Select P.DocEntry, P.DocCur From ORDN P INNER JOIN RDN1 Q on P.DocEntry = Q.DocEntry

Where Q.DocEntry=@list_of_cols_val_tab_del

and isnull(P.OwnerCode ,'') = '' )

Select @error = 161-01,

@error_message ='Please Set Owner Name for Return'



end
-------------------------------------A/R Invoice - Owner Name Mandatory-----------------------------------------------------------------
If @object_type = '13' and @transaction_type in ( 'A','U')



BEGIN
If exists (Select P.DocEntry, P.DocCur From OINV P INNER JOIN INV1 Q on P.DocEntry = Q.DocEntry

Where Q.DocEntry=@list_of_cols_val_tab_del

and isnull(P.OwnerCode ,'') = '' )

Select @error = 131-01,

@error_message ='Please Set Owner Name for A/R Invoice'



end
-------------------------------------A/R Cr.memo - Owner Name Mandatory----------------------------------------------------------------
If @object_type = '14' and @transaction_type in ( 'A','U')



BEGIN
If exists (Select P.DocEntry, P.DocCur From ORIN P INNER JOIN RIN1 Q on P.DocEntry = Q.DocEntry

Where Q.DocEntry=@list_of_cols_val_tab_del

and isnull(P.OwnerCode ,'') = '' )

Select @error = 141-01,

@error_message ='Please Set Owner Name for A/R Cr.memo'



end
-------------------------------------PO - Owner Name Mandatory-------------------------------------------------------------------------------
If @object_type = '22' and @transaction_type in ( 'A','U')



BEGIN
If exists (Select P.DocEntry, P.DocCur From OPOR P INNER JOIN POR1 Q on P.DocEntry = Q.DocEntry

Where Q.DocEntry=@list_of_cols_val_tab_del

and isnull(P.OwnerCode ,'') = '' )

Select @error = 221-01,

@error_message ='Please Set Owner Name for PO'



end
-------------------------------------GRPO - Owner Name Mandatory-----------------------------------------------------------------------
If @object_type = '20' and @transaction_type in ( 'A','U')



BEGIN
If exists (Select P.DocEntry, P.DocCur From OPDN P INNER JOIN PDN1 Q on P.DocEntry = Q.DocEntry

Where Q.DocEntry=@list_of_cols_val_tab_del

and isnull(P.OwnerCode ,'') = '' )

Select @error = 201-01,

@error_message ='Please Set Owner Name for GRPO'



end
-------------------------------------Goods Return - Owner Name Mandatory----------------------------------------------------------------
If @object_type = '21' and @transaction_type in ( 'A','U')



BEGIN
If exists (Select P.DocEntry, P.DocCur From ORPD P INNER JOIN RPD1 Q on P.DocEntry = Q.DocEntry

Where Q.DocEntry=@list_of_cols_val_tab_del

and isnull(P.OwnerCode ,'') = '' )

Select @error = 211,

@error_message ='Please Set Owner Name for Goods Return'



end


-------------------------------------AP Invoice - Owner Name Mandatory--------------------------------------------------------------------
If @object_type = '18' and @transaction_type in ( 'A','U')



BEGIN
If exists (Select P.DocEntry, P.DocCur From OPCH P INNER JOIN PCH1 Q on P.DocEntry = Q.DocEntry

Where Q.DocEntry=@list_of_cols_val_tab_del

and isnull(P.OwnerCode ,'') = '' )

Select @error = 181-01,

@error_message ='Please Set Owner Name for AP Invoice'



end
-------------------------------------AP Cr.memo - Owner Name Mandatory--------------------------------------------------------------------
If @object_type = '19' and @transaction_type in ( 'A','U')



BEGIN
If exists (Select P.DocEntry, P.DocCur From ORPC P INNER JOIN RPC1 Q on P.DocEntry = Q.DocEntry

Where Q.DocEntry=@list_of_cols_val_tab_del

and isnull(P.OwnerCode ,'') = '' )

Select @error = 191-01,

@error_message ='Please Set Owner Name for AP Cr.memo'



end
--------------------------------------------------------------------------------------------------------------------------------------------

Friday, 20 May 2016

Inventory Report Combining of Two Databases

(SELECT  T0.Itemcode ,
CASE When T0.ItemCode like 'DBA%' then 'Database_A' End 'Database',
T1.FrgnName as 'Part No', T1.ItemName, T2.ItmsGrpNam, T0.WhsCode, T0.ONHAND as 'Total Qty',  T0.ONHAND*T0.AVGPRICE as 'StockValue',
CASE WHEN Datediff(day, T1.LASTPURDAT,GETDATE()) >= 30 THEN T0.ONHAND END '>30 Days(Qty)',
CASE WHEN Datediff(day, T1.LASTPURDAT,GETDATE()) >= 30THEN T0.ONHAND*T0.AVGPRICE END '>30 Days(Value)',
CASE WHEN Datediff(day, T1.LASTPURDAT,GETDATE()) >= 60 THEN T0.ONHAND END '>60 Days(Qty)',
CASE WHEN Datediff(day, T1.LASTPURDAT,GETDATE()) >= 60THEN T0.ONHAND*T0.AVGPRICE END '>60 Days(Value)',
CASE WHEN Datediff(day, T1.LASTPURDAT,GETDATE()) >= 90 THEN T0.ONHAND END '>90 Days(Qty)',
CASE WHEN Datediff(day, T1.LASTPURDAT,GETDATE()) >= 90THEN T0.ONHAND*T0.AVGPRICE END '>90 Days(Value)',
CASE WHEN Datediff(day, T1.LASTPURDAT,GETDATE()) >= 180 THEN T0.ONHAND END '>180 Days(Qty)',
CASE WHEN Datediff(day, T1.LASTPURDAT,GETDATE()) >= 180 THEN T0.ONHAND*T0.AVGPRICE END '>180 Days(Value)'
FROM 
[DATABASE_A].[dbo].[OITW] as T0 INNER JOIN [DATABASE_A].[dbo].[OITM] as T1 ON T0.ITEMCODE = T1.ITEMCODE
INNER JOIN [DATABASE_A].[dbo].[OITB] as T2 ON T1.ITMSGRPCOD=T2.ITMSGRPCOD left join
[DATABASE_A].[dbo].[IBT1] as t3 on t3.itemcode = t0.itemcode and t3.whscode = t0.whscode
WHERE
T0.ONHAND>0  and (T0.WhsCode like 'BLR%') and T2.ItmsGrpNam in ('Toner' , 'Cartridge')


Union All


SELECT T0.Itemcode,CASE When T0.ItemCode like 'DBB%' then 'Database_B' End 'Database',
 T1.FrgnName as 'Part No', T1.ItemName, T2.ItmsGrpNam, T0.WhsCode, T0.ONHAND as 'Total Qty',  T0.ONHAND*T0.AVGPRICE as 'StockValue',
CASE WHEN Datediff(day, T1.LASTPURDAT,GETDATE()) >= 30 THEN T0.ONHAND END '>30 Days(Qty)',
CASE WHEN Datediff(day, T1.LASTPURDAT,GETDATE()) >= 30THEN T0.ONHAND*T0.AVGPRICE END '>30 Days(Value)',
CASE WHEN Datediff(day, T1.LASTPURDAT,GETDATE()) >= 60 THEN T0.ONHAND END '>60 Days(Qty)',
CASE WHEN Datediff(day, T1.LASTPURDAT,GETDATE()) >= 60THEN T0.ONHAND*T0.AVGPRICE END '>60 Days(Value)',
CASE WHEN Datediff(day, T1.LASTPURDAT,GETDATE()) >= 90 THEN T0.ONHAND END '>90 Days(Qty)',
CASE WHEN Datediff(day, T1.LASTPURDAT,GETDATE()) >= 90THEN T0.ONHAND*T0.AVGPRICE END '>90 Days(Value)',
CASE WHEN Datediff(day, T1.LASTPURDAT,GETDATE()) >= 180 THEN T0.ONHAND END '>180 Days(Qty)',
CASE WHEN Datediff(day, T1.LASTPURDAT,GETDATE()) >= 180 THEN T0.ONHAND*T0.AVGPRICE END '>180 Days(Value)'
FROM 
[DATABASE_B].[dbo].[OITW] as T0 INNER JOIN [DATABASE_B].[dbo].[OITM] as T1 ON T0.ITEMCODE = T1.ITEMCODE
INNER JOIN [DATABASE_B].[dbo].[OITB] as T2 ON T1.ITMSGRPCOD=T2.ITMSGRPCOD left join
[DATABASE_B].[dbo].[IBT1] as t3 on t3.itemcode = t0.itemcode and t3.whscode = t0.whscode
WHERE
T0.ONHAND>0 and (T0.WhsCode like 'BLR%') and T2.ItmsGrpNam in ('Toner' , 'Cartridge'))
Order By
T1.FrgnName

Wednesday, 2 March 2016

PAN No Mandatory in AR Invoice

  If @object_type = '13' and @transaction_type in ( 'A','U')

BEGINIf exists (Select P.DocEntry From INV12 P INNER JOIN OINV R on P.DocEntry =R.DocEntry

inner join INV1 Q on P.DocEntry = Q.DocEntry

Where P.DocEntry=@list_of_cols_val_tab_del

and isnull(P.Taxid0,'') = '' and R.DocTotal >= '200000'

and Q.LineStatus = 'O'

)

Select @error = 1310001,

@error_message = 'AR Invoice Doctotal Greater than 2 Lakhs. Please set PAN No. for Customer.'

end