Cust Conta NCR Report
Cust Conta NCR Report
[USP_CRM_CustomerContact_Report]
--Declare
@BranchID int,
@CompanyID int,
@YearId int,
@FromDate datetime,
@ToDate datetime
As
--set @BranchID = 4
--set @FromDate = '01-Jan-2024'
--set @ToDate = getdate()
BEGIN
with vView as (
--- Lead ----
SELECT distinct row_number() over (Order by d.dtDocDate) as
RowNumber,d.lId,d.sDocNo as [Lead No],d.dtDocDate,a1.sName as [Customer Name],
emp.sRemarks as [Sales Person],
dt.sName as [Transaction Type],d.sDocNo as [Transaction No]
,ST.sName AS [Transaction Status]
,cl.sName as [Contact Person],cl.sMobile as [Contact No.],
case when cl.cFlag='N' then 'Note' else isnull(ct.sName,'') end as Activity,
case when em.lId>0 then 'Email' end As Email,case when cl.cFlag='N' then cl.sNarr
else cl.sSubject end as Subject,cl.lStatusHdr,
convert(varchar,convert(date,convert(varchar(20),cl.dtFromDate)),103)as [Schedule
Date],
case when cl.cFlag='N' then '' else cl.sNarr end as Remarks,
case when (cl.lStatus != 40 and cl.lStatus != 50 and cl.dtFromDate <
DateAdd(Minute,330,GETUTCDATE()) and cl.cFlag in ('C')) then 'Overdue'
when cl.lStatus=10 then 'Done' when cl.lStatus=20 then 'Process' when cl.lStatus=30
then 'Hold' when cl.lStatus=30 then 'Done' when cl.lStatus=50 then 'Closed' else ''
end as [Status of Activity],
Convert(decimal(18,2),isnull(cf.cfValue1,0)) as Amount,cnt.sEmailId as [Email
ID],cm.sName as Currency
ENd