These should be all tables/views/functions involved in the stored procedure:
CREATE TABLE [dbo].[ActivityType](
[activityTypeId] [int] IDENTITY(1,1) NOT NULL,
[name] [nvarchar](200) NULL,
[code] [tinyint] NULL,
[CTY_ISO] [char](2) NULL,
[isActive] [bit] NULL,
[createdOn] [datetime] NULL,
[createdBy] [int] NULL,
[modifiedOn] [datetime] NULL,
[modifiedBy] [int] NULL,
CONSTRAINT [PK_ActivityType] PRIMARY KEY CLUSTERED
(
[activityTypeId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[ActivityType] ADD CONSTRAINT [DF_ActivityType_isActive] DEFAULT ((1)) FOR [isActive]
GO
CREATE TABLE [dbo].[ActivityDetails](
[activityDetailsId] [int] IDENTITY(1,1) NOT NULL,
[activityId] [int] NOT NULL,
[activityDate] [datetime] NULL,
[location] [varchar](200) NULL,
[title] [varchar](200) NULL,
[activityNeedId] [int] NULL,
[trimmRefNumber] [varchar](50) NULL,
[description] [varchar](1000) NULL,
[contractStartDate] [datetime] NULL,
[contractEndDate] [datetime] NULL,
[channelEventTypeId] [int] NULL,
[posTypeId] [int] NULL,
[mediaType] [varchar](10) NULL,
[startDate] [datetime] NULL,
[endDate] [datetime] NULL,
[mediaTypeId] [int] NULL,
[regionalExpenseCost] [float] NULL,
[agencyName] [varchar](200) NULL,
[isBillsSubmitted] [bit] NULL,
[isActivityCompleted] [bit] NULL,
[activityCompletionDate] [datetime] NULL,
[isAllBillsReceived] [bit] NULL,
[isActivityClosed] [bit] NULL,
[IsCSRDigital] [bit] NULL,
[createOn] [datetime] NULL,
[createdBy] [int] NULL,
[modifiedOn] [datetime] NULL,
[modifiedBy] [int] NULL,
[otherParticipant] [int] NULL,
[reportFilename] [varchar](200) NULL,
[activityFeedback] [varchar](500) NULL,
[activityFollowupPlan] [varchar](500) NULL,
[activityComments] [nvarchar](1000) NULL,
[OtherAttendees] [int] NULL,
[aliastitle] [varchar](200) NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[ActivityDetails] WITH CHECK ADD CONSTRAINT [FK_ActivityDetails_Activity] FOREIGN KEY([activityId])
REFERENCES [dbo].[Activity] ([activityId])
GO
ALTER TABLE [dbo].[ActivityDetails] CHECK CONSTRAINT [FK_ActivityDetails_Activity]
GO
CREATE TABLE [dbo].[FeeGrid](
[feeGridId] [int] IDENTITY(1,1) NOT NULL,
[CTY_ISO] [char](2) NULL,
[CUR_ISO] [char](3) NULL,
[rate] [float] NULL,
[createdOn] [datetime] NULL,
[createdBy] [int] NULL,
[modifiedOn] [datetime] NULL,
[modifiedBy] [int] NULL,
[Start_Date] [datetime] NULL,
[Expiry_Date] [datetime] NULL,
[IsActive] [bit] NULL,
PRIMARY KEY CLUSTERED
(
[feeGridId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[TimeCompensationMatrix](
[compensationId] [int] IDENTITY(1,1) NOT NULL,
[feeGridId] [int] NULL,
[compensationCode] [varchar](20) NULL,
[fromRange] [float] NULL,
[toRange] [float] NULL,
[sessionRate] [float] NULL,
[createdOn] [datetime] NULL,
[createdBy] [int] NULL,
[modifiedOn] [datetime] NULL,
[modifiedBy] [int] NULL,
PRIMARY KEY CLUSTERED
(
[compensationId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[TimeCompensationMatrix] WITH CHECK ADD CONSTRAINT [FK_TimeCompensationMatrix_FeeGrid] FOREIGN KEY([feeGridId])
REFERENCES [dbo].[FeeGrid] ([feeGridId])
GO
ALTER TABLE [dbo].[TimeCompensationMatrix] CHECK CONSTRAINT [FK_TimeCompensationMatrix_FeeGrid]
GO
CREATE TABLE [dbo].[ActivityContracts](
[activityContractId] [int] IDENTITY(1,1) NOT NULL,
[contractTypeId] [int] NULL,
[activityId] [int] NULL,
[actvityInviteeId] [int] NULL,
[inviteeId] [int] NULL,
[doctorAddress] [varchar](200) NULL,
[lectureSubject] [varchar](150) NULL,
[entityAddress] [varchar](500) NULL,
[targetAudience] [varchar](200) NULL,
[seniorDirector] [varchar](125) NULL,
[buId] [int] NULL,
[panNumber] [varchar](125) NULL,
[advisoryBoardName] [varchar](150) NULL,
[startDate] [datetime] NULL,
[endDate] [datetime] NULL,
[numberofMeeting] [int] NULL,
[costPerMeeting] [float] NULL,
[drugName] [varchar](150) NULL,
[advisoryBoardTopic] [varchar](125) NULL,
[theraputicArea] [varchar](125) NULL,
[specialityArea] [varchar](125) NULL,
[travelPreparationTime] [varchar](250) NULL,
[location] [varchar](150) NULL,
[honorariumJustification] [varchar](150) NULL,
[legalDirector] [varchar](125) NULL,
[rbmUserId] [varchar](100) NULL,
[topicDiseaseArea] [varchar](125) NULL,
[dateOfContract] [datetime] NULL,
[diseaseTherapyName] [varchar](125) NULL,
[doctorsRegistrationNumber] [nvarchar](100) NULL,
[statusId] [int] NULL,
[contractDocument] [varchar](150) NULL,
[createdBy] [int] NULL,
[createdOn] [datetime] NULL,
[modifiedBy] [int] NULL,
[modifiedOn] [datetime] NULL,
[expertName] [nvarchar](150) NULL,
[programName] [nvarchar](150) NULL,
[meetingTopic] [nvarchar](200) NULL,
[programDate] [datetime] NULL,
[taggedContractId] [int] NULL,
[closureDocumentFileName] [varchar](150) NULL,
[periodOfActivity] [int] NULL,
[descriptionOfSupport] [varchar](200) NULL,
[objectivesOfEvent] [varchar](100) NULL,
[isBankTransfer] [bit] NULL,
[accountNumber] [bigint] NULL,
[bankName] [varchar](50) NULL,
[paymentPeriod] [int] NULL,
[codesOfPractice] [varchar](200) NULL,
[isMaterialbenefitRequired] [bit] NULL,
[IsSanofiLogo] [bit] NULL,
[logoDetails] [varchar](200) NULL,
[permittedPurpose] [varchar](200) NULL,
[NameOfCities] [nvarchar](250) NULL,
[ContractServiceFileName] [varchar](250) NULL,
[EngagementName] [varchar](300) NULL,
[EngagementType] [varchar](300) NULL,
[DescriptionofService] [varchar](300) NULL,
[Deliverables] [varchar](300) NULL,
[ContactPersonOfSanofi] [varchar](300) NULL,
[ContactPersonEmailAddress] [varchar](300) NULL,
CONSTRAINT [PK__Activity__06BF5B1A65C116E7] PRIMARY KEY CLUSTERED
(
[activityContractId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[ActivityContracts] WITH CHECK ADD CONSTRAINT [FK_ActivityContracts_Activity] FOREIGN KEY([activityId])
REFERENCES [dbo].[Activity] ([activityId])
GO
ALTER TABLE [dbo].[ActivityContracts] CHECK CONSTRAINT [FK_ActivityContracts_Activity]
GO
CREATE TABLE [dbo].[ActivityInvitee](
[actvityInviteeId] [int] IDENTITY(1,1) NOT NULL,
[activityId] [int] NOT NULL,
[inviteeId] [int] NOT NULL,
[hcpRoleId] [int] NULL,
[IsHonorarium] [bit] NOT NULL,
[travelHours] [float] NULL,
[prepareHours] [float] NULL,
[isFeePaid] [bit] NULL,
[facilitationCharge] [float] NULL,
[fee] [float] NULL,
[isLogisticsRequired] [bit] NULL,
[VND_ID] [int] NULL,
[comments] [varchar](250) NULL,
[timeSpent] [float] NULL,
[logisticRequest] [int] NULL,
[createdOn] [datetime] NULL,
[createdBy] [int] NULL,
[modifiedOn] [datetime] NULL,
[modifiedBy] [int] NULL,
[invFirstName] [varchar](200) NULL,
[invLastName] [varchar](200) NULL,
[ExpertLevelId] [int] NULL,
[IsInvAttended] [bit] NULL,
[MedicalApproverDate] [datetime] NULL,
PRIMARY KEY CLUSTERED
(
[actvityInviteeId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[ActivityInvitee] WITH CHECK ADD CONSTRAINT [FK_ActivityInvitee_Activity] FOREIGN KEY([activityId])
REFERENCES [dbo].[Activity] ([activityId])
GO
ALTER TABLE [dbo].[ActivityInvitee] CHECK CONSTRAINT [FK_ActivityInvitee_Activity]
GO
CREATE TABLE [dbo].[Invitee](
[inviteeId] [int] IDENTITY(1,1) NOT NULL,
[inviteeTypeId] [int] NULL,
[refId] [nvarchar](50) NULL,
[firstname] [nvarchar](255) NULL,
[lastname] [nvarchar](255) NULL,
[speciality] [nvarchar](255) NULL,
[address1] [varchar](250) NULL,
[address2] [varchar](250) NULL,
[address3] [varchar](250) NULL,
[state] [varchar](255) NULL,
[city] [varchar](255) NULL,
[pincode] [varchar](255) NULL,
[uniqueCode] [varchar](255) NULL,
[medicalRegCode] [varchar](255) NULL,
[panNumber] [varchar](255) NULL,
[isKOL] [bit] NULL,
[VND_CODE] [nvarchar](255) NULL,
[vatRegNo] [varchar](255) NULL,
[tantinNo] [varchar](255) NULL,
[status] [varchar](255) NULL,
[CTY_ISO] [varchar](255) NULL,
[expertLevelId] [int] NULL,
[createdOn] [datetime] NULL,
[modifiedOn] [datetime] NULL,
[isPresentInMDM] [bit] NULL,
[IsHospitalDr] [bit] NULL,
[AlternateSpecialty] [nvarchar](255) NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[HonorariumAlert](
[Id] [int] IDENTITY(1,1) NOT NULL,
[ExpertLevelCode] [varchar](5) NOT NULL,
[MaxHonorariumAmount] [int] NOT NULL,
[EmailAlert1] [int] NOT NULL,
[EmailAlert2] [int] NOT NULL,
[EmailAlert3] [int] NOT NULL,
[createdOn] [datetime] NOT NULL,
[createdBy] [varchar](50) NULL,
[Year] [int] NOT NULL,
CONSTRAINT [HonorariumAlert_pk] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[HonorariumAlert] ADD DEFAULT (getdate()) FOR [createdOn]
GO
CREATE TABLE [dbo].[ExpertLevel](
[expertLevelId] [int] IDENTITY(1,1) NOT NULL,
[expertLevel] [varchar](50) NOT NULL,
[expertLevelCode] [tinyint] NOT NULL,
[LevelAcronym] [varchar](4) NULL,
CONSTRAINT [PK_ExpertLevel] PRIMARY KEY CLUSTERED
(
[expertLevelId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATE VIEW [dbo].[V_VENDOR_MASTER]
AS
SELECT VND_ID, CTY_ISO, VND_REGNO, VND_CODE, VND_NAME, VND_BANKID, VND_BANKNAME, VND_BANKAC, VND_BANKBR, VND_CTRLKEY, VND_BANKACCHOLDER,
VND_EMPNO, VND_ADDRESS, VND_SOCIALREGNO, VND_CTRLKEY AS 'VND_BANKACCTYPE', VND_ACCGRP, VND_STATUS, VND_CDATE, VND_MDATE,
WH_TAXCODE, PREV_ACCOUNT_NO, ETY_CODE, RECONCILIATION_ACCOUNT
FROM DB_ACCESS.dbo.vendor_master AS vendor_master_1 WITH (NOLOCK)
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties =
Begin PaneConfigurations =
Begin PaneConfiguration = 0
NumPanes = 4
Configuration = "(H (1[40] 4[20] 2[20] 3) )"
End
Begin PaneConfiguration = 1
NumPanes = 3
Configuration = "(H (1 [50] 4 [25] 3))"
End
Begin PaneConfiguration = 2
NumPanes = 3
Configuration = "(H (1 [50] 2 [25] 3))"
End
Begin PaneConfiguration = 3
NumPanes = 3
Configuration = "(H (4 [30] 2 [40] 3))"
End
Begin PaneConfiguration = 4
NumPanes = 2
Configuration = "(H (1 [56] 3))"
End
Begin PaneConfiguration = 5
NumPanes = 2
Configuration = "(H (2 [66] 3))"
End
Begin PaneConfiguration = 6
NumPanes = 2
Configuration = "(H (4 [50] 3))"
End
Begin PaneConfiguration = 7
NumPanes = 1
Configuration = "(V (3))"
End
Begin PaneConfiguration = 8
NumPanes = 3
Configuration = "(H (1[56] 4[18] 2) )"
End
Begin PaneConfiguration = 9
NumPanes = 2
Configuration = "(H (1 [75] 4))"
End
Begin PaneConfiguration = 10
NumPanes = 2
Configuration = "(H (1[66] 2) )"
End
Begin PaneConfiguration = 11
NumPanes = 2
Configuration = "(H (4 [60] 2))"
End
Begin PaneConfiguration = 12
NumPanes = 1
Configuration = "(H (1) )"
End
Begin PaneConfiguration = 13
NumPanes = 1
Configuration = "(V (4))"
End
Begin PaneConfiguration = 14
NumPanes = 1
Configuration = "(V (2))"
End
ActivePaneConfig = 0
End
Begin DiagramPane =
Begin Origin =
Top = 0
Left = 0
End
Begin Tables =
Begin Table = "vendor_master_1"
Begin Extent =
Top = 6
Left = 38
Bottom = 269
Right = 225
End
DisplayFlags = 280
TopColumn = 5
End
End
End
Begin SQLPane =
End
Begin DataPane =
Begin ParameterDefaults = ""
End
Begin ColumnWidths = 24
Width = 284
Width = 1500
Width = 1500
Width = 1500
Width = 1500
Width = 1500
Width = 1500
Width = 1500
Width = 1500
Width = 1500
Width = 1500
Width = 2340
Width = 1500
Width = 1500
Width = 1500
Width = 2280
Width = 1500
Width = 1500
Width = 1500
Width = 1500
Width = 1500
Width = 1500
Width = 1500
Width = 1500
End
End
Begin CriteriaPane =
Begin ColumnWidths = 11
Column = 1440
Alias = 900
Table = 1170
Output = 720
Append = 1400
NewValue = 1170
SortType = 1350
SortOrder = 1410
GroupBy = 1350
Filter = 1350
Or = 1350
Or = 1350
Or = 1350
End
End
End
' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'V_VENDOR_MASTER'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=1 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'V_VENDOR_MASTER'
GO
CREATE TABLE [dbo].[ContractType](
[contractTypeId] [int] IDENTITY(1,1) NOT NULL,
[CTY_ISO] [char](2) NULL,
[name] [varchar](150) NULL,
[Code] [tinyint] NULL,
[isActive] [bit] NULL,
CONSTRAINT [PK__Contract__DFEA4C2C3A6CA48E] PRIMARY KEY CLUSTERED
(
[contractTypeId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[ContractGrid](
[contractGridId] [int] IDENTITY(1,1) NOT NULL,
[activityTypeId] [int] NULL,
[hcpRoleId] [int] NULL,
[inviteeTypeId] [int] NULL,
[honorarium] [bit] NULL,
[consultantContract] [bit] NULL,
[hcpRequest] [smallint] NULL,
[contractTypeId] [int] NULL,
[amountPayable] [bit] NULL,
[CTY_ISO] [char](2) NULL,
[feeGrid] [bit] NULL,
CONSTRAINT [PK_ContractGrid] PRIMARY KEY CLUSTERED
(
[contractGridId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[BusinessUnit](
[buId] [int] NOT NULL,
[name] [varchar](200) NULL,
[TrimmEntityId] [int] NULL,
[CTY_ISO] [char](2) NULL,
[createdOn] [datetime] NULL,
[createdBy] [int] NULL,
[modifiedOn] [datetime] NULL,
[modifiedBy] [int] NULL,
[isActive] [bit] NULL,
[accronym] [varchar](10) NULL,
CONSTRAINT [PK_BusinessUnit] PRIMARY KEY CLUSTERED
(
[buId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATE VIEW [dbo].[V_USERS]
AS
SELECT USER_ID, CTY_ISO, CUR_ISO, NTDOMAIN, NTLOGIN, ETY_ID, DEPARTMENT_ID, TITLE_ID, LASTNAME, FIRSTNAME, LASTNAME_LOCAL, FIRSTNAME_LOCAL, EMAIL,
JOBFUNCTION_ID, MANAGER_USER_ID, COSTCENTER, COSTCENTER_DESC, COSTCENTER_DESC_LOCAL, VND_EMPNO, HR_EMPLOYEE_NUMBER,
WORK_LOCATION_ID, POSITION_ID, EMPLOYEEGROUP_ID, LANG_CODE, SAPNTLOGIN, SIGNATURE_PATH, EPR_THRESHOLD, ISACTIVE, CREATED_ON,
CREATED_BY, UPDATED_ON, UPDATED_BY, APPROVER_LEVEL_ID, BUSINESS_UNIT_ID
FROM DB_ACCESS.dbo.USERS AS USERS_1
GO
CREATE TABLE [dbo].[ActivityBilling](
[activityBillingId] [int] IDENTITY(1,1) NOT NULL,
[activityId] [int] NOT NULL,
[VND_ID] [int] NULL,
[vendorName] [varchar](500) NULL,
[isNewVendor] [bit] NULL,
[activityInviteeId] [int] NULL,
[activityServiceId] [int] NULL,
[Comments] [varchar](500) NULL,
[billRefNo] [varchar](50) NULL,
[billdate] [datetime] NULL,
[amount] [float] NULL,
[billStatusCode] [int] NULL,
[createOn] [datetime] NULL,
[createdBy] [int] NULL,
[modifiedOn] [datetime] NULL,
[modifiedBy] [int] NULL,
[RejectionComments] [nvarchar](1000) NULL,
PRIMARY KEY CLUSTERED
(
[activityBillingId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[ActivityBilling] WITH CHECK ADD CONSTRAINT [FK_ActivityBilling_Activity] FOREIGN KEY([activityId])
REFERENCES [dbo].[Activity] ([activityId])
GO
ALTER TABLE [dbo].[ActivityBilling] CHECK CONSTRAINT [FK_ActivityBilling_Activity]
GO
USE [TRIMM_PRD_STG]
GO
create FUNCTION [dbo].[udf_GetChildActivityContractStatus]
(
@ActivityContractId int
)
RETURNS NVARCHAR(100)
AS
BEGIN
DECLARE @CanAmend bit=1
declare @Count int
select @Count=Count(1) from Activity a
join ActivityContracts ac on a.ActivityId=ac.ActivityId
join Status s on a.statusId=s.statusId
where ac.taggedContractId=@ActivityContractId and (s.code=202 or s.code=205)
if(@Count >0)
begin
set @CanAmend=0
end
RETURN @CanAmend
END
GO
create FUNCTION [dbo].[udf_GetInviteesConsultantContractStatus] --30
(
@InviteeId int
)
RETURNS BIT
AS
BEGIN
DECLARE @IsContractExist BIT = 0
DECLARE @Count INT
SELECT @Count = count('X') from ActivityContracts ac
JOIN ContractType c ON ac.contractTypeId = c.contractTypeId
JOIN [Status] cSt ON cSt.statusId = ac.[statusId]
where inviteeId= @InviteeId and (c.Code = 205 or c.Code= 208) and cst.code = 403 AND cSt.statusIdentifier = 3
IF(@Count >0)
BEGIN
SET @IsContractExist=1
END
RETURN @IsContractExist
END
GO