﻿if not Exists(SELECT * FROM information_schema.tables where Table_name = 'Sanad')
begin
	create table dbo.Sanad
	(
		ID	int primary key,
		Code int NOT NULL,
		Mat_ID bigint references Matter(ID) NOT NULL,
		FC_ID int references Finance_Cycle(ID) NOT NULL,
		Pro_ID_VahedMali int references OtherProperties(ID) NOT NULL,
		Pro_ID_Subject int references OtherProperties(ID) NOT NULL,
		Tarikh int NOT NULL,
		Saat int NOT NULL,
		Title nvarchar(1000) NULL,
		[Description] nvarchar(1000) NULL,
		Dom_ID_Noe int references domain(ID) NOT NULL,
		Dom_ID_Vaziat int references domain(ID) NOT NULL,
		Dom_ID_Marja int references domain(ID) NOT NULL,
		CodeKarbar int references Karbar(ID) NOT NULL,
		TarikhSabt int not NULL,
		SaatSabt int not NULL
	)
end
;
if not Exists(SELECT * FROM information_schema.tables where Table_name = 'SanadDetail')
begin
	CREATE TABLE dbo.SanadDetail
	(
		ID int IDENTITY(1,1) NOT NULL,
		San_ID int references Sanad(ID) NOT NULL,
		SerialNo int NOT NULL,
		AI_ID_Kol int references AccountItem(ID) not NULL,
		AI_ID_Moin int references AccountItem(ID) not NULL,
		Taf_ID bigint references Tafsili(ID) NULL,
		Taf2_ID bigint references Tafsili(ID) NULL,
		Taf3_ID bigint references Tafsili(ID) NULL,
		Title nvarchar(1000) NULL,
		Debit decimal(19, 4) NOT NULL,
		Credit decimal(19, 4) NOT NULL,
		Refrence_ID bigint NOT NULL,
		Dom_ID_Marja int references Domain(ID) NOT NULL
	)
end
;
if not Exists(SELECT * FROM information_schema.tables where Table_name = 'SanadRefrenceID')
begin
	create table dbo.SanadRefrenceID
	(
		ID	int primary key Identity(1,1),
		San_ID	int references Sanad(ID) not null,
		Bar_ID	int references Bargeh(ID)null,
		DaryaftPardakht_ID	int references DaryaftPardakht(ID) null,
		GardesheChek_ID	int references GardesheChek(ID) null,
		Prod_ID	int references Product(ID) null,
		KalDarAnbar_ID	int references KalaDarAnbar(ID) null,
		Kal_ID	int references Kala(ID) null,
		Taf_ID	bigint references Tafsili(ID) null,
		ProductDetail_ID	int references ProductDetail(ID) null,
		ConvertGood_ID	int references ConvertGood(ID) null,
		StoreDocumentAccount_ID	int references StoreDocument(ID) null,
		CommercialStore_ID	int references CommercialStore(ID) null,
		TafsiliRemind_ID	int references dbo.TafsiliRemind(ID) null
	)
end