-- 1.1.4 Power.TechnologicalConnection

-- Расширяем модель данных об осмотре электроустановок и приемке электроучета
alter table InspectionEPU drop column ActDate 
alter table InspectionEPU add ActExecutorID int
alter table InspectionEPU add ActDateStart datetime
alter table InspectionEPU add ActDateFinish datetime
alter table InspectionEPU add IsWitnesIndividual bit
alter table InspectionEPU add WitnesIndividualID int
alter table InspectionEPU add WitnesOther nvarchar(200)
alter table InspectionEPU add IsPowerForTermo bit
alter table InspectionEPU add ForTermoPermitDate datetime
alter table InspectionEPU add ForTermoPermitNumber nvarchar(50)
alter table InspectionEPU add ForTermoPermitPower float
alter table InspectionEPU add IsOwnerLiable bit
alter table InspectionEPU add LiableName nvarchar(100)
alter table InspectionEPU add LiableOrderSource nvarchar(50)
alter table InspectionEPU add LiableOrderDate datetime
alter table InspectionEPU add LiableOrderNumber nvarchar(50)
alter table InspectionEPU add LiableCheckKnowledgeDate datetime
alter table InspectionEPU add LiableSecurityGroup int
alter table InspectionEPU add AdditionalCheckAfterSMR bit
alter table InspectionEPU add InspectionEPUAttachID int
alter table InspectionEPU add Inspection nvarchar(1024)
GO
ALTER TABLE InspectionEPU
	ADD FOREIGN KEY (ActExecutorID) 
		REFERENCES Персонал (Код_работника)
		
ALTER TABLE InspectionEPU
	ADD FOREIGN KEY(WitnesIndividualID) 
		REFERENCES Individuals(IndividualID)
		
ALTER TABLE InspectionEPU
	ADD FOREIGN KEY (InspectionEPUAttachID) 
		REFERENCES StoreDocuments (DocumentID)
		ON DELETE CASCADE
		
-- Расширяем модель данных о приеме электроучета
alter table SealAccounts add ActNumber nvarchar(50)
alter table SealAccounts add ActDate datetime
alter table SealAccounts add ActExecutorID int
alter table SealAccounts add SealAccountReasonID int
alter table SealAccounts add OtherSealPlace nvarchar(300)
alter table SealAccounts add ActNote nvarchar(300)
GO
create table SealAccountReasons
(
	ReasonID	int IDENTITY(1,1),
	Description		nvarchar(100),
	PRIMARY KEY (ReasonID)
)
GO
insert into SealAccountReasons (Description) Values('По заявке')
insert into SealAccountReasons (Description) Values('Вновь')
insert into SealAccountReasons (Description) Values('После снятия пломбы')
GO
ALTER TABLE SealAccounts
	ADD FOREIGN KEY (ActExecutorID) 
		REFERENCES Персонал (Код_работника)
		
ALTER TABLE SealAccounts
	ADD FOREIGN KEY (SealAccountReasonID)
		REFERENCES SealAccountReasons (ReasonID)
