
CREATE TABLE [dbo].[WBS_WorkPackageDetail](
	[WorkPackageDetailId] [nvarchar](50) NOT NULL,
	[WorkPackageId] [nvarchar](50) NULL,
	[Months] [datetime] NULL,
	[PlanNum] [decimal](9, 2) NULL,
	[ThisNum] [decimal](9, 2) NULL,
 CONSTRAINT [PK_WBS_WorkPackageDetail] PRIMARY KEY CLUSTERED 
(
	[WorkPackageDetailId] 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].[WBS_WorkPackageDetail]  WITH CHECK ADD  CONSTRAINT [FK_WBS_WorkPackageDetail_WBS_WorkPackage] FOREIGN KEY([WorkPackageId])
REFERENCES [dbo].[WBS_WorkPackage] ([WorkPackageId])
GO

ALTER TABLE [dbo].[WBS_WorkPackageDetail] CHECK CONSTRAINT [FK_WBS_WorkPackageDetail_WBS_WorkPackage]
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'主键' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_WorkPackageDetail', @level2type=N'COLUMN',@level2name=N'WorkPackageDetailId'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'外键' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_WorkPackageDetail', @level2type=N'COLUMN',@level2name=N'WorkPackageId'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'月份' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_WorkPackageDetail', @level2type=N'COLUMN',@level2name=N'Months'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'概算工程量' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_WorkPackageDetail', @level2type=N'COLUMN',@level2name=N'PlanNum'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'实际工程量' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_WorkPackageDetail', @level2type=N'COLUMN',@level2name=N'ThisNum'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'分部分项明细表' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_WorkPackageDetail'
GO

exec sp_addextendedproperty 'MS_Description', N'��Ŀ����', 'SCHEMA', 'dbo', 'TABLE', 'PHTGL_ContractTrack', 'COLUMN',
     'ProjectName'
go

exec sp_addextendedproperty 'MS_Description', N'��Ŀ��������', 'SCHEMA', 'dbo', 'TABLE', 'PHTGL_ContractTrack',
     'COLUMN', 'ProjectDescription'
go

CREATE VIEW [dbo].[View_WBS_WorkPackageDetail]
AS
/********控制项明细********/
SELECT detail.WorkPackageDetailId, 
detail.WorkPackageId, 
detail.Months, 
c.WorkPackageCode, 
c.PackageContent,
c.ProjectId,
c.Unit,   --单位
c.PlanProjectQuantity,   --概算工作量
c.RealProjectQuantity,   --实际工程量
CONVERT(FLOAT,(select sum(ISNULL(PlanNum,0)) from WBS_WorkPackageDetail where WorkPackageId=detail.WorkPackageId and Months<=detail.Months)) as TotalPlanNum,  --累计计划完成量
CONVERT(FLOAT,(select sum(ISNULL(ThisNum,0)) from WBS_WorkPackageDetail where WorkPackageId=detail.WorkPackageId and Months<=detail.Months)) as TotalThisNum,  --累计完成量
CONVERT(FLOAT,(select sum(ISNULL(d.PlanNum,0)) from WBS_WorkPackageDetail d
 where d.WorkPackageId=detail.WorkPackageId and Months=detail.Months)) as PlanNum,  --本月计划完成量
CONVERT(FLOAT,(select sum(ISNULL(d.ThisNum,0)) from WBS_WorkPackageDetail d
 where d.WorkPackageId=detail.WorkPackageId and Months=detail.Months)) as ThisNum  --本月完成量
FROM dbo.WBS_WorkPackageDetail AS detail
LEFT JOIN WBS_WorkPackage AS c ON c.WorkPackageId=detail.WorkPackageId

exec sp_addextendedproperty 'MS_Description', N'������', 'SCHEMA', 'dbo', 'TABLE', 'PHTGL_ContractTrack', 'COLUMN',
     'Quantity'
go

exec sp_addextendedproperty 'MS_Description', N'ȫ���ù̶��ۺϵ���', 'SCHEMA', 'dbo', 'TABLE', 'PHTGL_ContractTrack',
     'COLUMN', 'TotalCostFixedComprehensiveUnitPrice'
go

exec sp_addextendedproperty 'MS_Description', N'���ķ�', 'SCHEMA', 'dbo', 'TABLE', 'PHTGL_ContractTrack', 'COLUMN',
     'MainMaterialCost'
go

exec sp_addextendedproperty 'MS_Description', N'�ϼ�/Ԫ', 'SCHEMA', 'dbo', 'TABLE', 'PHTGL_ContractTrack', 'COLUMN',
     'TotalPrice'
go

exec sp_addextendedproperty 'MS_Description', N'�������', 'SCHEMA', 'dbo', 'TABLE', 'PHTGL_ContractTrack', 'COLUMN',
     'CalculationRule'
go

exec sp_addextendedproperty 'MS_Description', N'��������', 'SCHEMA', 'dbo', 'TABLE', 'PHTGL_ContractTrack', 'COLUMN',
     'WorkContent'
go

exec sp_addextendedproperty 'MS_Description', N'��ע', 'SCHEMA', 'dbo', 'TABLE', 'PHTGL_ContractTrack', 'COLUMN',
     'Remarks'
go

exec sp_addextendedproperty 'MS_Description', N'ʩ���ְ���', 'SCHEMA', 'dbo', 'TABLE', 'PHTGL_ContractTrack', 'COLUMN',
     'ConstructionSubcontractor'
go



GO



CREATE TABLE [dbo].[WBS_WorkPackageParentDetail](
	[WorkPackageParentDetailId] [nvarchar](50) NOT NULL,
	[ParentId] [nvarchar](50) NULL,
	[ProjectId] [nvarchar](50) NULL,
	[Months] [datetime] NULL,
	[PlanNum] [decimal](9, 2) NULL,
	[ThisNum] [decimal](9, 2) NULL,
 CONSTRAINT [PK_WBS_WorkPackageParentDetail] PRIMARY KEY CLUSTERED 
(
	[WorkPackageParentDetailId] 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

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'主键' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_WorkPackageParentDetail', @level2type=N'COLUMN',@level2name=N'WorkPackageParentDetailId'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'外键' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_WorkPackageParentDetail', @level2type=N'COLUMN',@level2name=N'ParentId'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'项目id' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_WorkPackageParentDetail', @level2type=N'COLUMN',@level2name=N'ProjectId'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'月份' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_WorkPackageParentDetail', @level2type=N'COLUMN',@level2name=N'Months'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'概算工程量' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_WorkPackageParentDetail', @level2type=N'COLUMN',@level2name=N'PlanNum'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'实际工程量' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_WorkPackageParentDetail', @level2type=N'COLUMN',@level2name=N'ThisNum'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'分部分项父级明细表' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_WorkPackageParentDetail'
GO

exec sp_addextendedproperty 'MS_Description', N'��ִͬ�и��ٱ�id', 'SCHEMA', 'dbo', 'TABLE',
     'PHTGL_ContractTrackMatchWBS', 'COLUMN', 'ContractTrackId'
go

exec sp_addextendedproperty 'MS_Description', N'WBS������������Ʊ�id', 'SCHEMA', 'dbo', 'TABLE',
     'PHTGL_ContractTrackMatchWBS', 'COLUMN', 'ControlItemAndCycleId'
go

CREATE VIEW [dbo].[View_WBS_WorkPackageParentDetail]
AS
/********控制项父级明细********/
SELECT detail.WorkPackageParentDetailId, 
detail.ParentId,
detail.ProjectId, 
detail.Months, 
CONVERT(FLOAT,(select sum(ISNULL(PlanNum,0)) from WBS_WorkPackageParentDetail 
where ParentId=detail.ParentId and Months=detail.Months)) as PlanNum,    --本月计划完成预算
CONVERT(FLOAT,(select sum(ISNULL(d.ThisNum,0)) from WBS_WorkPackageParentDetail d
where d.ParentId=detail.ParentId and Months=detail.Months)) as ThisNum,  --本月实际完成预算 
CONVERT(FLOAT,(select sum(ISNULL(PlanNum,0)) from WBS_WorkPackageParentDetail 
where ParentId=detail.ParentId and Months<=detail.Months)) as TotalPlanNum,  --累计计划完成预算
CONVERT(FLOAT,(select sum(ISNULL(ThisNum,0)) from WBS_WorkPackageParentDetail 
where ParentId=detail.ParentId and Months<=detail.Months)) as TotalThisNum  --累计完成预算
FROM dbo.WBS_WorkPackageParentDetail AS detail

-- auto-generated definition
create table dbo.PHTGL_ContractTrackProgress
(
    ContractTrackProgressId varchar(50) not null
        constraint PHTGL_ContractTrackProgress_pk
            primary key,
    ContractTrackId         varchar(50),
    BCWS_Quantity           nvarchar(50),
    BCWS_OutputValue        nvarchar(50),
    BCWS_Percentage         nvarchar(50),
    ACWP_Quantity           nvarchar(50),
    ACWP_OutputValue        nvarchar(50),
    ACWP_Percentage         nvarchar(50)
)
go

exec sp_addextendedproperty 'MS_Description', N'��ִͬ�и��ٽ�չ����ӱ�', 'SCHEMA', 'dbo', 'TABLE',
     'PHTGL_ContractTrackProgress'
go

exec sp_addextendedproperty 'MS_Description', N'��ͬ���ٱ�����', 'SCHEMA', 'dbo', 'TABLE',
     'PHTGL_ContractTrackProgress', 'COLUMN', 'ContractTrackId'
go

exec sp_addextendedproperty 'MS_Description', N'BCWS������', 'SCHEMA', 'dbo', 'TABLE', 'PHTGL_ContractTrackProgress',
     'COLUMN', 'BCWS_Quantity'
go

exec sp_addextendedproperty 'MS_Description', N'BCWS��ֵ', 'SCHEMA', 'dbo', 'TABLE', 'PHTGL_ContractTrackProgress',
     'COLUMN', 'BCWS_OutputValue'
go

exec sp_addextendedproperty 'MS_Description', N'BCWS�ٷֱ�', 'SCHEMA', 'dbo', 'TABLE', 'PHTGL_ContractTrackProgress',
     'COLUMN', 'BCWS_Percentage'
go

GO

exec sp_addextendedproperty 'MS_Description', N'ACWP��ֵ ', 'SCHEMA', 'dbo', 'TABLE', 'PHTGL_ContractTrackProgress',
     'COLUMN', 'ACWP_OutputValue'
go

INSERT INTO dbo.Sys_Menu(MenuId,MenuName,Url,SortIndex,SuperMenu,MenuType,IsOffice,IsEnd,IsUsed)
VALUES('B479EC55-E12A-4F91-AF3F-864DAAA136FB','进度完成情况录入','JDGL/Check/CompleteInput.aspx',20,'0','Menu_JDGL',0,1,1)
GO
INSERT INTO dbo.Sys_ButtonToMenu(ButtonToMenuId,MenuId,ButtonName,SortIndex)
VALUES('22724257-9FC3-4CE2-864C-8740F1F77F99','B479EC55-E12A-4F91-AF3F-864DAAA136FB','保存',4)
GO

INSERT INTO dbo.Sys_Menu(MenuId,MenuName,Url,SortIndex,SuperMenu,MenuType,IsOffice,IsEnd,IsUsed)
VALUES('F0E296C3-6499-43E5-88CD-E00C5180D3BC','Ӯ��ֵ����','JDGL/Check/EarnedValueCurve.aspx',30,'0','Menu_JDGL',0,1,1)
GO