1. not keep the budget plan history, only keep the current budget plan data and all status will be set "DRAFT" and have to start a new lifecycle in new process control;
2. resource assigned to project before will transform into first his department effortestimation of the project
3. open point: current budget plan ,what is the definition
3
4
5
6
7
8
9
10
ALTER TABLE dbo.BUDGET ADD IS_IN_PROCESS bit NULL, BUDGET_PLAN_STATUS nvarchar(50) NULL ALTER TABLE dbo.BUDGET ADD CONSTRAINT DF_BUDGET_IS_IN_PROCESS DEFAULT 1 FOR IS_IN_PROCESS ALTER TABLE dbo.MEMBERRESOURCE ADD [STARTDATE] [datetime] NULL UPDATE MEMBERRESOURCE SET STARTDATE='2009-9-27' ALTER TABLE MEMBERRESOURCE ALTER COLUMN STARTDATE DATETIME NOT NULL ALTER TABLE MEMBERRESOURCE ALTER COLUMN CLOSEDATE DATETIME NOT NULL if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[RESOURCE_ASSIGN]') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table [dbo].[RESOURCE_ASSIGN] GO CREATE TABLE [dbo].[RESOURCE_ASSIGN] ( [RESOURCE_ASSIGN_ID] [bigint] IDENTITY (1, 1) NOT NULL , [FK_MEMBERRESOURCE_ID] [bigint] NULL , [FK_EFFORT_ESTIMATION_ID] [bigint] NULL , [MANMONTH_10] [real] NULL , [MANMONTH_11] [real] NULL , [MANMONTH_12] [real] NULL , [MANMONTH_01] [real] NULL , [MANMONTH_02] [real] NULL , [MANMONTH_03] [real] NULL , [MANMONTH_04] [real] NULL , [MANMONTH_05] [real] NULL , [MANMONTH_06] [real] NULL , [MANMONTH_07] [real] NULL , [MANMONTH_08] [real] NULL , [MANMONTH_09] [real] NULL ) ON [PRIMARY] GO declare @projectidmax int,@curprojectid int; select @projectidmax=max(fk_project_id) from budget; set @curprojectid=1; while @curprojectid<=@projectidmax begin declare @budgetidmax int; select @budgetidmax=max(budget_id) from budget where fk_project_id=@curprojectid; update budget set IS_IN_PROCESS=1 where ((fk_project_id=@curprojectid) and (budget_id=@budgetidmax)); update budget set IS_IN_PROCESS=0 where ((fk_project_id=@curprojectid) and (budget_id<@budgetidmax)); insert into RESOURCE_ASSIGN( MANMONTH_10, MANMONTH_11, MANMONTH_12, MANMONTH_01, MANMONTH_02, MANMONTH_03, MANMONTH_04, MANMONTH_05, MANMONTH_06, MANMONTH_07, MANMONTH_08, MANMONTH_09,FK_MEMBERRESOURCE_ID, FK_EFFORT_ESTIMATION_ID ) SELECT RESOURCEASSIGNMENT.MANMONTH_10, RESOURCEASSIGNMENT.MANMONTH_11, RESOURCEASSIGNMENT.MANMONTH_12, RESOURCEASSIGNMENT.MANMONTH_01, RESOURCEASSIGNMENT.MANMONTH_02, RESOURCEASSIGNMENT.MANMONTH_03, RESOURCEASSIGNMENT.MANMONTH_04, RESOURCEASSIGNMENT.MANMONTH_05, RESOURCEASSIGNMENT.MANMONTH_06, RESOURCEASSIGNMENT.MANMONTH_07, RESOURCEASSIGNMENT.MANMONTH_08, RESOURCEASSIGNMENT.MANMONTH_09, RESOURCEASSIGNMENT.FK_MEMBERRESOURCE_ID, ( SELECT TOP 1 EFFORT_ESTIMATION_ID FROM dbo.EFFORT_ESTIMATION WHERE (EFFORT_ESTIMATION.FK_FISCALYEAR_ID=RESOURCEASSIGNMENT.FK_FISCALYEAR_ID AND FK_BUDGET_ID IN (SELECT TOP 1 BUDGET_ID FROM dbo.BUDGET WHERE (FK_PROJECT_ID = @curprojectid) AND (IS_IN_PROCESS = 1) AND (FK_DIVISION_ID = (SELECT TOP 1 FK_DIVISION_ID FROM TEAM WHERE TEAM_ID=(SELECT TOP 1 FK_TEAM_ID FROM MEMBERRESOURCE WHERE MEMBERRESOURCE.MEMBERRESOURCE_ID=RESOURCEASSIGNMENT.FK_MEMBERRESOURCE_ID))))) ) FROM RESOURCEASSIGNMENT Where fk_project_id=@curprojectid; set @curprojectid=@curprojectid+1; end INSERT INTO WORKPACKAGE (NAME) VALUES ('ACTUALDATA'); UPDATE EFFORT_ESTIMATION SET IS_ACTUAL=0,FK_WORKPACKAGE_ID=27,INITIAL_TOTAL_MANMONTH=MONTH_10+MONTH_11+MONTH_12+MONTH_1+MONTH_2+MONTH_3+MONTH_4+MONTH_5+MONTH_6+MONTH_7+MONTH_8+MONTH_9 WHERE IS_ACTUAL=1; ALTER TABLE dbo.EFFORT_ESTIMATION ADD IS_ALIGNED bit NULL; ALTER TABLE dbo.EFFORT_ESTIMATION ADD CONSTRAINT DF_EFFORT_ESTIMATION_IS_ALIGNED DEFAULT 0 FOR IS_ALIGNED ; UPDATE EFFORT_ESTIMATION SET IS_ALIGNED = 0; There are two alternatives : [update BUDGET SET BUDGET_PLAN_STATUS='DRAFT'; ] [update BUDGET SET BUDGET_PLAN_STATUS=case when STATUS='FROZEN' and IS_IN_PROCESS='0' then 'APPROVED' ELSE 'DRAFT' END ;] UPDATE EXPENSE_ESTIMATION SET IS_ACTUAL = 0, INIT_TOTAL_COST = MONTH_10 + MONTH_11 + MONTH_12 + MONTH_1 + MONTH_2 + MONTH_3 + MONTH_4 + MONTH_5 + MONTH_6 + MONTH_7 + MONTH_8 + MONTH_9 WHERE (IS_ACTUAL = 1); ??????? have to perfect
Added on April 1st,2011 noon
UPDATE EFFORT_ESTIMATION SET IS_ALIGNED = 1 WHERE (EFFORT_ESTIMATION_ID IN (
SELECT EFFORT_ESTIMATION_ID FROM EFFORT_ESTIMATION INNER JOIN BUDGET ON EFFORT_ESTIMATION.FK_BUDGET_ID = BUDGET.BUDGET_ID
WHERE (BUDGET.BUDGET_PLAN_STATUS = 'APPROVED') AND
(BUDGET.IS_IN_PROCESS = 0)));
DELETE FROM RESOURCE_ASSIGN WHERE (FK_EFFORT_ESTIMATION_ID IS NULL);
update Effort_estimation set is_aligned='1' where EFFORT_ESTIMATION_ID in
(
select EFFORT_ESTIMATION_ID from
(
SELECT SUM(RESOURCE_ASSIGN.MANMONTH_01) AS SUM_MANMONTH1,
SUM(RESOURCE_ASSIGN.MANMONTH_02) AS SUM_MANMONTH2,
SUM(RESOURCE_ASSIGN.MANMONTH_03) AS SUM_MANMONTH3,
SUM(RESOURCE_ASSIGN.MANMONTH_04) AS SUM_MANMONTH4,
SUM(RESOURCE_ASSIGN.MANMONTH_05) AS SUM_MANMONTH5,
SUM(RESOURCE_ASSIGN.MANMONTH_06) AS SUM_MANMONTH6,
SUM(RESOURCE_ASSIGN.MANMONTH_07) AS SUM_MANMONTH7,
SUM(RESOURCE_ASSIGN.MANMONTH_08) AS SUM_MANMONTH8,
SUM(RESOURCE_ASSIGN.MANMONTH_09) AS SUM_MANMONTH9,
SUM(RESOURCE_ASSIGN.MANMONTH_10) AS SUM_MANMONTH10,
SUM(RESOURCE_ASSIGN.MANMONTH_11) AS SUM_MANMONTH11,
SUM(RESOURCE_ASSIGN.MANMONTH_12) AS SUM_MANMONTH12,
EFFORT_ESTIMATION.EFFORT_ESTIMATION_ID,
EFFORT_ESTIMATION.MONTH_1,
EFFORT_ESTIMATION.MONTH_2,
EFFORT_ESTIMATION.MONTH_3,
EFFORT_ESTIMATION.MONTH_4,
EFFORT_ESTIMATION.MONTH_5,
EFFORT_ESTIMATION.MONTH_6,
EFFORT_ESTIMATION.MONTH_7,
EFFORT_ESTIMATION.MONTH_8,
EFFORT_ESTIMATION.MONTH_9,
EFFORT_ESTIMATION.MONTH_10,
EFFORT_ESTIMATION.MONTH_11,
EFFORT_ESTIMATION.MONTH_12
FROM RESOURCE_ASSIGN INNER JOIN
EFFORT_ESTIMATION ON
RESOURCE_ASSIGN.FK_EFFORT_ESTIMATION_ID = EFFORT_ESTIMATION.EFFORT_ESTIMATION_ID
INNER JOIN
BUDGET ON EFFORT_ESTIMATION.FK_BUDGET_ID = BUDGET.BUDGET_ID
WHERE (BUDGET.IS_IN_PROCESS = 1)
GROUP BY EFFORT_ESTIMATION.EFFORT_ESTIMATION_ID,
EFFORT_ESTIMATION.MONTH_1,
EFFORT_ESTIMATION.MONTH_2,
EFFORT_ESTIMATION.MONTH_3,
EFFORT_ESTIMATION.MONTH_4,
EFFORT_ESTIMATION.MONTH_5,
EFFORT_ESTIMATION.MONTH_6,
EFFORT_ESTIMATION.MONTH_7,
EFFORT_ESTIMATION.MONTH_8,
EFFORT_ESTIMATION.MONTH_9,
EFFORT_ESTIMATION.MONTH_10,
EFFORT_ESTIMATION.MONTH_11,
EFFORT_ESTIMATION.MONTH_12
)AAAAA where (SUM_MANMONTH1 = MONTH_1 and SUM_MANMONTH2 = MONTH_2 and SUM_MANMONTH3 = MONTH_3 and SUM_MANMONTH4 = MONTH_4 and SUM_MANMONTH5 = MONTH_5 and SUM_MANMONTH6 = MONTH_6 and SUM_MANMONTH7 = MONTH_7 and SUM_MANMONTH8 = MONTH_8 and SUM_MANMONTH9 = MONTH_9 and SUM_MANMONTH10 = MONTH_10 and SUM_MANMONTH11 = MONTH_11 and SUM_MANMONTH12 = MONTH_12)
)
ALTER TABLE dbo.BUDGET ADD IS_IN_PROCESS bit NULL, BUDGET_PLAN_STATUS nvarchar(50) NULL ALTER TABLE dbo.BUDGET ADD CONSTRAINT DF_BUDGET_IS_IN_PROCESS DEFAULT 1 FOR IS_IN_PROCESS ALTER TABLE dbo.MEMBERRESOURCE ADD [STARTDATE] [datetime] NULL UPDATE MEMBERRESOURCE SET STARTDATE='2009-9-27' ALTER TABLE MEMBERRESOURCE ALTER COLUMN STARTDATE DATETIME NOT NULL ALTER TABLE MEMBERRESOURCE ALTER COLUMN CLOSEDATE DATETIME NOT NULL if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[RESOURCE_ASSIGN]') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table [dbo].[RESOURCE_ASSIGN] GO CREATE TABLE [dbo].[RESOURCE_ASSIGN] ( [RESOURCE_ASSIGN_ID] [bigint] IDENTITY (1, 1) NOT NULL , [FK_MEMBERRESOURCE_ID] [bigint] NULL , [FK_EFFORT_ESTIMATION_ID] [bigint] NULL , [MANMONTH_10] [real] NULL , [MANMONTH_11] [real] NULL , [MANMONTH_12] [real] NULL , [MANMONTH_01] [real] NULL , [MANMONTH_02] [real] NULL , [MANMONTH_03] [real] NULL , [MANMONTH_04] [real] NULL , [MANMONTH_05] [real] NULL , [MANMONTH_06] [real] NULL , [MANMONTH_07] [real] NULL , [MANMONTH_08] [real] NULL , [MANMONTH_09] [real] NULL ) ON [PRIMARY] GO declare @projectidmax int,@curprojectid int; select @projectidmax=max(fk_project_id) from budget; set @curprojectid=1; while @curprojectid<=@projectidmax begin declare @budgetidmax int; select @budgetidmax=max(budget_id) from budget where fk_project_id=@curprojectid; update budget set IS_IN_PROCESS=1 where ((fk_project_id=@curprojectid) and (budget_id=@budgetidmax)); update budget set IS_IN_PROCESS=0 where ((fk_project_id=@curprojectid) and (budget_id<@budgetidmax)); insert into RESOURCE_ASSIGN( MANMONTH_10, MANMONTH_11, MANMONTH_12, MANMONTH_01, MANMONTH_02, MANMONTH_03, MANMONTH_04, MANMONTH_05, MANMONTH_06, MANMONTH_07, MANMONTH_08, MANMONTH_09,FK_MEMBERRESOURCE_ID, FK_EFFORT_ESTIMATION_ID ) SELECT RESOURCEASSIGNMENT.MANMONTH_10, RESOURCEASSIGNMENT.MANMONTH_11, RESOURCEASSIGNMENT.MANMONTH_12, RESOURCEASSIGNMENT.MANMONTH_01, RESOURCEASSIGNMENT.MANMONTH_02, RESOURCEASSIGNMENT.MANMONTH_03, RESOURCEASSIGNMENT.MANMONTH_04, RESOURCEASSIGNMENT.MANMONTH_05, RESOURCEASSIGNMENT.MANMONTH_06, RESOURCEASSIGNMENT.MANMONTH_07, RESOURCEASSIGNMENT.MANMONTH_08, RESOURCEASSIGNMENT.MANMONTH_09, RESOURCEASSIGNMENT.FK_MEMBERRESOURCE_ID, ( SELECT TOP 1 EFFORT_ESTIMATION_ID FROM dbo.EFFORT_ESTIMATION WHERE (EFFORT_ESTIMATION.FK_FISCALYEAR_ID=RESOURCEASSIGNMENT.FK_FISCALYEAR_ID AND FK_BUDGET_ID IN (SELECT TOP 1 BUDGET_ID FROM dbo.BUDGET WHERE (FK_PROJECT_ID = @curprojectid) AND (IS_IN_PROCESS = 1) AND (FK_DIVISION_ID = (SELECT TOP 1 FK_DIVISION_ID FROM TEAM WHERE TEAM_ID=(SELECT TOP 1 FK_TEAM_ID FROM MEMBERRESOURCE WHERE MEMBERRESOURCE.MEMBERRESOURCE_ID=RESOURCEASSIGNMENT.FK_MEMBERRESOURCE_ID))))) ) FROM RESOURCEASSIGNMENT Where fk_project_id=@curprojectid; set @curprojectid=@curprojectid+1; end INSERT INTO WORKPACKAGE (NAME) VALUES ('ACTUALDATA'); UPDATE EFFORT_ESTIMATION SET IS_ACTUAL=0,FK_WORKPACKAGE_ID=27,INITIAL_TOTAL_MANMONTH=MONTH_10+MONTH_11+MONTH_12+MONTH_1+MONTH_2+MONTH_3+MONTH_4+MONTH_5+MONTH_6+MONTH_7+MONTH_8+MONTH_9 WHERE IS_ACTUAL=1; ALTER TABLE dbo.EFFORT_ESTIMATION ADD IS_ALIGNED bit NULL; ALTER TABLE dbo.EFFORT_ESTIMATION ADD CONSTRAINT DF_EFFORT_ESTIMATION_IS_ALIGNED DEFAULT 0 FOR IS_ALIGNED ; UPDATE EFFORT_ESTIMATION SET IS_ALIGNED = 0; update BUDGET SET BUDGET_PLAN_STATUS='DRAFT';