﻿ALTER TABLE dbo.FC_SESRelatedData ADD OtherDef NVARCHAR(300) NULL
GO
ALTER TABLE dbo.Base_FileType ADD IsExport BIT NULL
GO
UPDATE dbo.Base_FileType SET IsExport=0
GO

ALTER VIEW [dbo].[View_FC_ContractManagement]
AS
SELECT cm.OccurDate,fc.FO_NO,dis.Discipline AS DisciplineEn,dis.DisciplineCN,con.Contractor AS ContractorEn,con.ContractorCN, 
       (CASE WHEN con.Contractor IS NULL THEN con.ContractorCN WHEN con.ContractorCN IS NULL THEN con.Contractor ELSE con.Contractor+con.ContractorCN END)AS Contractor, 
	   (CASE WHEN dis.Discipline IS NULL THEN dis.DisciplineCN WHEN dis.DisciplineCN IS NULL THEN dis.Discipline ELSE dis.Discipline+dis.DisciplineCN END) AS Discipline,
	   cm.Remark,ftype.FileType,u.UserName AS Contract_Admin, u2.UserName AS Main_Coordinator,mcdep.DepartName AS MCDept,
	   u3.UserName AS User_Representative, bycDep.DepartCode AS BycDept,ftype.IsExport
FROM dbo.FC_ContractManagement cm
LEFT JOIN dbo.FC_SESRelatedData fc ON fc.ID = cm.FC_ID
LEFT JOIN dbo.Base_Discipline AS dis ON dis.DisciplineId = fc.DisciplineId
LEFT JOIN dbo.Base_Contractor AS con ON con.ContractorId = fc.Contractor
LEFT JOIN dbo.Base_FileType ftype ON ftype.FileTypeId = cm.FileTypeId
LEFT JOIN dbo.Sys_User AS u ON u.UserId = fc.Contract_Admin
LEFT JOIN dbo.Sys_User AS u2 ON u2.UserId = fc.Main_Coordinator
LEFT JOIN dbo.Sys_User AS u3 ON u3.UserId=fc.User_Representative
LEFT JOIN dbo.Base_Depart mcdep ON mcdep.DepartId = u2.DepartId
LEFT JOIN dbo.Base_Depart bycDep ON bycDep.DepartId=cm.BycDept


GO

CREATE VIEW [dbo].[View_EMC_Contractor_Qualification]
AS
SELECT cm.FoId,fc.FO_NO,cm.QueName,cm.QueDef,cm.QueType,cm.LimitStartDate,cm.LimitEndDate,cm.Remark,
       (CASE WHEN con.Contractor IS NULL THEN con.ContractorCN WHEN con.ContractorCN IS NULL THEN con.Contractor ELSE con.Contractor+con.ContractorCN END)AS Contractor, 
	   (CASE WHEN dis.Discipline IS NULL THEN dis.DisciplineCN WHEN dis.DisciplineCN IS NULL THEN dis.Discipline ELSE dis.Discipline+dis.DisciplineCN END) AS Discipline,
	   u.UserName AS Contract_Admin, u2.UserName AS Main_Coordinator,fc.Expire_Date,fc.Contractor AS ContractorId ,fc.FC_Status 
FROM dbo.EMC_Contractor_Qualification cm
LEFT JOIN dbo.FC_SESRelatedData fc ON fc.ID = cm.FoId
LEFT JOIN dbo.Base_Discipline AS dis ON dis.DisciplineId = fc.DisciplineId
LEFT JOIN dbo.Base_Contractor AS con ON con.ContractorId = fc.Contractor
LEFT JOIN dbo.Sys_User AS u ON u.UserId = fc.Contract_Admin
LEFT JOIN dbo.Sys_User AS u2 ON u2.UserId = fc.Main_Coordinator

GO


