Hi ,
Iam using this SP to set approval limit for a particular item group .Currently it will block invoicing if the credit days is 10 (OINV.DocTotal-OINV.PaidToDate>0 and DATEDIFF(Day,OINV.DocDate,GETDATE())>10 ).I need to create an exception in this SP to 60 days only for the customers whose county is "TEST" &"TEST2" .
USE [NABIL_DB]
GO
/****** Object: StoredProcedure [dbo].[SP_Oil_CreditDays_10] Script Date: 11/08/2014 14:58:15 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[SP_Oil_CreditDays_10]
@list_of_cols_val_tab_del NVARCHAR(255), @error_message NVARCHAR(255) OUTPUT
AS
BEGIN
declare @RowCount int
select
@RowCount=COUNT(RDR1.ItemCode)
from ORDR
inner join RDR1 on ORDR.DocEntry=RDR1.DocEntry
inner join OITM on RDR1.ItemCode=OITM.ItemCode and OITM.U_SeriesGrp='O' and isnull(ORDR.U_Approved,'N')='N'
where
ORDR.DocEntry=@list_of_cols_val_tab_del
if @RowCount>0
begin
select @RowCount=0
select
@RowCount=COUNT(OINV.DocEntry)
from
OINV
inner join INV1 on OINV.DocEntry=INV1.DocEntry
inner join OITM on INV1.ItemCode=OITM.ItemCode and OITM.U_SeriesGrp='O'
where
OINV.DocTotal-OINV.PaidToDate>0 and DATEDIFF(Day,OINV.DocDate,GETDATE())>10
and OINV.CardCode=(select ORDR.CardCode from ORDR where ORDR.DocEntry=@list_of_cols_val_tab_del)
if @RowCount>0
begin
select @error_message= 'This doccument required approval. Please select Approval to "Yes" to continue'
return -1
end
else
begin
return 0
end
end
return 0
End