﻿

ALTER VIEW [dbo].[View_NewManHours_Plan]
AS
--scs修改于2024.05.24
SELECT  p.ManHoursPlanId, 
p.ResourcePlanId, 
p.EProjectId, 
p.EngineerId, 
p.Account, 
p.DisciplineId,
(CASE WHEN p.Discipline='M00' THEN 'Project Management' ELSE p.Discipline END) AS Discipline, 
(CASE WHEN p.Roles='M00' THEN 'M00_Project Management' 
		     WHEN CHARINDEX('_',p.Roles)=0 THEN p.Roles+'_'+p.Discipline
			 WHEN CHARINDEX('_',p.Roles)>0 THEN LEFT(p.Roles,(CHARINDEX('_',p.Roles)))+p.Discipline + 
			                 SUBSTRING(p.Roles,CHARINDEX('_',p.Roles),LEN(p.Roles)) END) AS Roles,
p.ManHours, 
p.AccountDisabled, 
e.ProjectControl_JobNo,  
e.ProjectControl_JobType,
e.PM_MA_JobReveive,
e.ProjectControl_JobStatus, 
e.ProjectControl_JobTitle, 
e.ProjectControl_BUCode, 
e.ProjectControl_PC_CancelDate,
e.CM_MA_MC, 
e.Job_Hold,
e.PM_MA_ProjectApproval,--final approve
u.UserName AS EngineerName, 
u.DepartId, 
u.DepartName, 
e.ProjectControl_MS_ResourcePlanReceived,
e.ProjectControl_NetworkDate,
u.IsCalculated,
(SELECT ISNULL(SUM(ISNULL(act.Hours,0)),0) FROM dbo.ManHours_Actual act WHERE act.ManHoursPlanId=p.ManHoursPlanId) AS ActHours
FROM dbo.ManHours_Plan AS p 
LEFT JOIN dbo.Editor_EProject AS e ON p.EProjectId = e.EProjectId
LEFT JOIN dbo.View_Sys_Users AS u ON p.EngineerId = u.UserId
WHERE (p.EProjectId IS NOT NULL)



GO


