Use ATNDBTest
Go
--
--
--
--
--
--
--
-- حـذف همه جداول احتمالی قبلی
If Exists (Select * From INFORMATION_SCHEMA.TABLES where TABLE_TYPE = 'BASE TABLE' And TABLE_SCHEMA = 'AST' And TABLE_NAME = 'SystemAccCodeDefaultPerAssetGroup') Drop Table AST.SystemAccCodeDefaultPerAssetGroup
If Exists (Select * From INFORMATION_SCHEMA.TABLES where TABLE_TYPE = 'BASE TABLE' And TABLE_SCHEMA = 'AST' And TABLE_NAME = 'AssetDocAccCode') Drop Table AST.AssetDocAccCode
If Exists (Select * From INFORMATION_SCHEMA.TABLES where TABLE_TYPE = 'BASE TABLE' And TABLE_SCHEMA = 'AST' And TABLE_NAME = 'AssetDocDetail') Drop Table AST.AssetDocDetail
If Exists (Select * From INFORMATION_SCHEMA.TABLES where TABLE_TYPE = 'BASE TABLE' And TABLE_SCHEMA = 'AST' And TABLE_NAME = 'Asset') Drop Table AST.Asset
If Exists (Select * From INFORMATION_SCHEMA.TABLES where TABLE_TYPE = 'BASE TABLE' And TABLE_SCHEMA = 'AST' And TABLE_NAME = 'AssetDocHeader') Drop Table AST.AssetDocHeader
If Exists (Select * From INFORMATION_SCHEMA.TABLES where TABLE_TYPE = 'BASE TABLE' And TABLE_SCHEMA = 'AST' And TABLE_NAME = 'AssetDocKind') Drop Table AST.AssetDocKind
If Exists (Select * From INFORMATION_SCHEMA.TABLES where TABLE_TYPE = 'BASE TABLE' And TABLE_SCHEMA = 'AST' And TABLE_NAME = 'AssetType') Drop Table AST.AssetType
If Exists (Select * From INFORMATION_SCHEMA.TABLES where TABLE_TYPE = 'BASE TABLE' And TABLE_SCHEMA = 'AST' And TABLE_NAME = 'AssetGroup') Drop Table AST.AssetGroup
If Exists (Select * From INFORMATION_SCHEMA.TABLES where TABLE_TYPE = 'BASE TABLE' And TABLE_SCHEMA = 'AST' And TABLE_NAME = 'Collectors') Drop Table AST.Collectors
Go
--
--
--
--
--
--
--
-- شمای دارایی ثابت
If Not Exists(SELECT * FROM sys.schemas Where Name = 'AST') Exec('Create Schema AST')
Go
--
--
--
--
--
--
--
-- ایجاد مجدد همه جداول جدید
Create Table AST.Collectors(
	Serial Bigint Identity(1,1) Not Null,
	Code Int Null,
	FADescription Varchar(50) Null,
	ENDescription Varchar(50) Null,
	Comment Varchar(300) Null,
	RecorderRef Int Null,
	RecordDate char(10) Null,
	EditorRef Int Null,
	EditDate char(10) Null,
	OfficeDetailRef Int Null,
	Tag Varchar(50) Null)
Go
Alter Table AST.Collectors Add Constraint PK_AST_Collectors Primary Key Clustered (Serial)
Go

Create Table AST.AssetGroup(
	Serial Int Identity(1,1) Not Null,
	Code Int Null,
	FADescription Varchar(50) Null,
	ENDescription Varchar(50) Null,
	Comment Varchar(300) Null,
	RecorderRef Int Null,
	RecordDate char(10) Null,
	EditorRef Int Null,
	EditDate char(10) Null,
	OfficeDetailRef Int Null,
	Tag Varchar(50) Null)
Go
Alter Table AST.AssetGroup Add Constraint PK_AST_AssetGroup Primary Key Clustered (Serial)
Go

Create Table AST.AssetType(
	Serial Int Identity(1,1) Not Null,
	AssetGroupRef Int Not Null,
	Code Int Null,
	FADescription Varchar(50) Null,
	ENDescription Varchar(50) Null,
	Comment Varchar(300) Null,
	RecorderRef Int Null,
	RecordDate char(10) Null,
	EditorRef Int Null,
	EditDate char(10) Null,
	OfficeDetailRef Int Null,
	Tag Varchar(50) Null)
Go
Alter Table AST.AssetType Add Constraint PK_AST_AssetType Primary Key Clustered (Serial)
Go
Alter Table AST.AssetType Add Constraint FK_AST_AssetType_AssetGroupRef Foreign Key(AssetGroupRef) References AST.AssetGroup (Serial)
Go
Create Nonclustered Index IDX_AST_AssetType_AssetGroupRef ON AST.AssetType(AssetGroupRef ASC)
Go

Create Table AST.AssetDocKind(
	Serial Int Not Null, ------------
	FA_Description Varchar(50) Null, 
	EN_Description Varchar(50) Null, 
	Stream char(1) Null, ------------
	Priority smallint Null) ---------
Go
Alter Table AST.AssetDocKind Add Constraint PK_AST_AssetDocKind Primary Key Clustered (Serial)
Go

Create Table AST.AssetDocHeader(
	Serial Bigint Identity(1,1) Not Null, ---------
	Code Bigint Null, -----------------------------
	AssetDocKindRef int Not Null, -----------------
	AccDocumentHeaderRef Bigint Null, -------------
	FreeData Varchar(Max) Null, -------------------
	FreeData2 Varchar(Max) Null, ------------------
	FreeData3 Varchar(Max) Null, ------------------
	EffectiveDate char(10) Null, ------------------
	Vat Money Null, -------------------------------
	TotalAmount Money Null, -----------------------
	TotalAmount2 Money Null, ----------------------
	ForeignCurrencyFactor float Null, -------------
	ForeignCurrencySymbolRef Smallint Null, -------
	RecorderRef Int Null, -------------------------
	RecordDate char(10) Null, ---------------------
	EditorRef Int Null, ---------------------------
	EditDate char(10) Null, -----------------------
	VerifierRef Int Null, -------------------------
	VerificationDate char(10) Null, ---------------
	Comment Varchar(300) Null, --------------------
	OfficeDetailRef Int Null,
	OfficePeriodRef Int Null,
	RowVersion DateTime,
	Tag Varchar(50) Null)
Go
Alter Table AST.AssetDocHeader Add Constraint PK_AST_AssetDocHeader Primary Key Clustered (Serial)
Go
Alter Table AST.AssetDocHeader Add Constraint FK_AST_AssetDocHeader_AssetDocKindRef Foreign Key(AssetDocKindRef) References AST.AssetDocKind (Serial)
Alter Table AST.AssetDocHeader Add Constraint FK_AST_AssetDocHeader_AccDocumentHeaderRef Foreign Key(AccDocumentHeaderRef) References dbo.AccDocumentHeader (Serial)
Alter Table AST.AssetDocHeader Add Constraint FK_AST_AssetDocHeader_RecorderRef Foreign Key(RecorderRef) References dbo.Users (Serial)
Alter Table AST.AssetDocHeader Add Constraint FK_AST_AssetDocHeader_EditorRef Foreign Key(EditorRef) References dbo.Users (Serial)
Alter Table AST.AssetDocHeader Add Constraint FK_AST_AssetDocHeader_VerifierRef Foreign Key(VerifierRef) References dbo.Users (Serial)
Alter Table AST.AssetDocHeader Add Constraint FK_AST_AssetDocHeader_OfficeDetailRef Foreign Key(OfficeDetailRef) References dbo.OfficeDetail (Serial)
Alter Table AST.AssetDocHeader Add Constraint FK_AST_AssetDocHeader_OfficePeriodRef Foreign Key(OfficePeriodRef) References dbo.OfficePeriod (Serial)
Alter Table AST.AssetDocHeader Add Constraint FK_AST_AssetDocHeader_ForeignCurrencySymbolRef Foreign Key(ForeignCurrencySymbolRef) References dbo.ForeignCurrencySymbol (Serial)
Go
Create Nonclustered Index IDX_AST_AssetDocHeader_AssetDocKindRef On AST.AssetDocHeader(AssetDocKindRef Asc)
Create Nonclustered Index IDX_AST_AssetDocHeader_AccDocumentHeaderRef On AST.AssetDocHeader(AccDocumentHeaderRef Asc)
Create Nonclustered Index IDX_AST_AssetDocHeader_RecorderRef On AST.AssetDocHeader(RecorderRef Asc)
Create Nonclustered Index IDX_AST_AssetDocHeader_EditorRef On AST.AssetDocHeader(EditorRef Asc)
Create Nonclustered Index IDX_AST_AssetDocHeader_VerifierRef On AST.AssetDocHeader(VerifierRef Asc)
Create Nonclustered Index IDX_AST_AssetDocHeader_OfficeDetailRef On AST.AssetDocHeader(OfficeDetailRef Asc)
Create Nonclustered Index IDX_AST_AssetDocHeader_OfficePeriodRef On AST.AssetDocHeader(OfficePeriodRef Asc)
Create Nonclustered Index IDX_AST_AssetDocHeader_ForeignCurrencySymbolRef ON AST.AssetDocHeader(ForeignCurrencySymbolRef ASC)
Go

Create Table AST.Asset(
	Serial Bigint Identity(1,1) Not Null, --------
	AssetTypeRef Int Not Null, -------------------
	Code Varchar(25) Null, -----------------------
	FADescription Varchar(50) Null, --------------
	ENDescription Varchar(50) Null, --------------
	OEM Varchar(25) Null, ------------------------
	UnitRef Bigint Null, -------------------------
	AssetComment Varchar(300) Null, --------------

	LatestAssetPlate Varchar(Max) Null, ----------
	LatestLocationRef Bigint Null, ---------------
	LatestCollectorRef Bigint Null, --------------
	LatestEmployeeRef Bigint Null, ---------------
	LatestCostCenterRef Bigint Null, -------------

	OperationDate Char(10) Null, -----------------
	OperationAssetDocRef Bigint Null, ------------
	DepreciationType Smallint Null, --------------
	DepreciationValue Decimal(6,4) Null, ---------
	Active bit Null, -----------------------------
	InactiveRate Decimal(6,4) Null, --------------
	BuyUnitPrice Money Null, ---------------------
	AccumulatedDepreciation Money Null, ----------
	BookValue Money Null, ------------------------
	ResidualValue Money Null, --------------------

	Barcode Nvarchar(200) Null, ------------------
	BarcodeImg Varbinary(MAX) Null, --------------
	AssetImg Varbinary(MAX) Null, ----------------

	RecorderRef Int Null,	----------------------
	RecordDate Char(10) Null, --------------------
	EditorRef Int Null, --------------------------
	EditDate Char(10) Null, ----------------------

	OfficeDetailRef Int Null,
	Tag Varchar(50) Null)
Go
Alter Table AST.Asset Add Constraint PK_AST_Asset Primary Key Clustered (Serial)
Go
Alter Table AST.Asset Add Constraint FK_AST_Asset_AssetTypeRef Foreign Key(AssetTypeRef) References AST.AssetType (Serial)
Alter Table AST.Asset Add Constraint FK_AST_Asset_UnitRef Foreign Key(UnitRef) References dbo.Units (Serial)
Alter Table AST.Asset Add Constraint FK_AST_Asset_RecorderRef Foreign Key(RecorderRef) References dbo.Users (Serial)
Alter Table AST.Asset Add Constraint FK_AST_Asset_EditorRef Foreign Key(EditorRef) References dbo.Users (Serial)
Alter Table AST.Asset Add Constraint FK_AST_Asset_OfficeDetailRef Foreign Key(OfficeDetailRef) References dbo.OfficeDetail (Serial)
Alter Table AST.Asset Add Constraint FK_AST_Asset_OperationAssetDocRef Foreign Key(OperationAssetDocRef) References AST.AssetDocHeader (Serial)
Alter Table AST.Asset Add Constraint FK_AST_Asset_LatestLocationRef Foreign Key(LatestLocationRef) References PAY.JobLocation (Serial)
Alter Table AST.Asset Add Constraint FK_AST_Asset_LatestCostCenterRef Foreign Key(LatestCostCenterRef) References dbo.CostCenter (Serial)
Alter Table AST.Asset Add Constraint FK_AST_Asset_LatestCollectorRef Foreign Key(LatestCollectorRef) References AST.Collectors (Serial)
Alter Table AST.Asset Add Constraint FK_AST_Asset_LatestEmployeeRef Foreign Key(LatestEmployeeRef) References PAY.Employee (Serial)
Go 
Create Nonclustered Index IDX_AST_Asset_AssetTypeRef On AST.Asset(AssetTypeRef Asc)
Create Nonclustered Index IDX_AST_Asset_UnitRef On AST.Asset(UnitRef Asc)
Create Nonclustered Index IDX_AST_Asset_RecorderRef On AST.Asset(RecorderRef Asc)
Create Nonclustered Index IDX_AST_Asset_EditorRef On AST.Asset(EditorRef Asc)
Create Nonclustered Index IDX_AST_Asset_OfficeDetailRef On AST.Asset(OfficeDetailRef Asc)
Go

Create Table AST.AssetDocDetail(
	Serial Bigint Identity(1,1) Not Null, 
	AssetDocHeaderRef Bigint Not Null, ---
	AssetRef Bigint Not Null, ------------
	Amount Money Null, -------------------
	Amount2 Money Null, ------------------
	Amount3 Money Null, ------------------
	--Amount4 Money Null, ----------------
	String1 Varchar(Max) Null, -----------
	String2 Varchar(Max) Null, -----------
	String3 Varchar(Max) Null, -----------
	Tag Varchar(50) Null)
Go
Alter Table AST.AssetDocDetail Add Constraint PK_AST_AssetDocDetail Primary Key Clustered (Serial)
Go
Alter Table AST.AssetDocDetail Add Constraint FK_AST_AssetDocDetail_AssetDocHeaderRef Foreign Key(AssetDocHeaderRef) References AST.AssetDocHeader (Serial)
Alter Table AST.AssetDocDetail Add Constraint FK_AST_AssetDocDetail_AssetRef Foreign Key(AssetRef) References AST.Asset (Serial)
Go
Create Nonclustered Index IDX_AST_AssetDocDetail_AssetDocHeaderRef On AST.AssetDocDetail(AssetDocHeaderRef Asc)
Create Nonclustered Index IDX_AST_AssetDocDetail_AssetRef On AST.AssetDocDetail(AssetRef Asc)
Go

Create Table AST.AssetDocAccCode(
	Serial Bigint Identity(1,1) Not Null, ----------- 
	AssetDocHeaderRef Bigint Not Null,
	AssetDocDetailRef Bigint Null,
	SystemAccCodeDefaultBaseRef Int Not Null,
	DebitAccAdjutantL1CodeBookRef Bigint Null, -----
	DebitAccEntityL1CodeBookRef Bigint Null, -------
	DebitAccEntityL2CodeBookRef Bigint Null, -------
	DebitAccSecondEntityCodeBookRef Bigint Null, ---
	DebitAccThirdEntityCodeBookRef Bigint Null,	----
	CreditAccAdjutantL1CodeBookRef Bigint Null,	----
	CreditAccEntityL1CodeBookRef Bigint Null, ------
	CreditAccEntityL2CodeBookRef Bigint Null, ------
	CreditAccSecondEntityCodeBookRef Bigint Null, --
	CreditAccThirdEntityCodeBookRef Bigint Null) ---
Go
Alter Table AST.AssetDocAccCode Add Constraint PK_AST_AssetDocAccCode Primary Key Clustered (Serial)
Go
Alter Table AST.AssetDocAccCode Add Constraint FK_AST_AssetDocAccCode_DebitAccAdjutantL1CodeBookRef Foreign Key(DebitAccAdjutantL1CodeBookRef) References dbo.AccAdjutantL1CodeBook (Serial)
Alter Table AST.AssetDocAccCode Add Constraint FK_AST_AssetDocAccCode_DebitAccEntityL1CodeBookRef Foreign Key(DebitAccEntityL1CodeBookRef) References dbo.AccEntityL1CodeBook (Serial)
Alter Table AST.AssetDocAccCode Add Constraint FK_AST_AssetDocAccCode_DebitAccEntityL2CodeBookRef Foreign Key(DebitAccEntityL2CodeBookRef) References dbo.AccEntityL2CodeBook (Serial)
Alter Table AST.AssetDocAccCode Add Constraint FK_AST_AssetDocAccCode_DebitAccSecondEntityCodeBookRef Foreign Key(DebitAccSecondEntityCodeBookRef) References dbo.AccSecondEntityCodeBook (Serial)
Alter Table AST.AssetDocAccCode Add Constraint FK_AST_AssetDocAccCode_DebitAccThirdEntityCodeBookRef Foreign Key(DebitAccThirdEntityCodeBookRef) References dbo.AccThirdEntityCodeBook (Serial)
Alter Table AST.AssetDocAccCode Add Constraint FK_AST_AssetDocAccCode_CreditAccAdjutantL1CodeBookRef Foreign Key(CreditAccAdjutantL1CodeBookRef) References dbo.AccAdjutantL1CodeBook (Serial)
Alter Table AST.AssetDocAccCode Add Constraint FK_AST_AssetDocAccCode_CreditAccEntityL1CodeBookRef Foreign Key(CreditAccEntityL1CodeBookRef) References dbo.AccEntityL1CodeBook (Serial)
Alter Table AST.AssetDocAccCode Add Constraint FK_AST_AssetDocAccCode_CreditAccEntityL2CodeBookRef Foreign Key(CreditAccEntityL2CodeBookRef) References dbo.AccEntityL2CodeBook (Serial)
Alter Table AST.AssetDocAccCode Add Constraint FK_AST_AssetDocAccCode_CreditAccSecondEntityCodeBookRef Foreign Key(CreditAccSecondEntityCodeBookRef) References dbo.AccSecondEntityCodeBook (Serial)
Alter Table AST.AssetDocAccCode Add Constraint FK_AST_AssetDocAccCode_CreditAccThirdEntityCodeBookRef Foreign Key(CreditAccThirdEntityCodeBookRef) References dbo.AccThirdEntityCodeBook (Serial)
Alter Table AST.AssetDocAccCode Add Constraint FK_AST_AssetDocAccCode_AssetDocHeaderRef Foreign Key(AssetDocHeaderRef) References AST.AssetDocHeader (Serial)
Alter Table AST.AssetDocAccCode Add Constraint FK_AST_AssetDocAccCode_AssetDocDetailRef Foreign Key(AssetDocDetailRef) References AST.AssetDocDetail (Serial)
Alter Table AST.AssetDocAccCode Add Constraint FK_AST_AssetDocAccCode_SystemAccCodeDefaultBase Foreign Key(SystemAccCodeDefaultBaseRef) References dbo.SystemAccCodeDefaultBase (Serial)
Go
Create Nonclustered Index IDX_AST_AssetDocAccCode_DebitAccAdjutantL1CodeBookRef On AST.AssetDocAccCode(DebitAccAdjutantL1CodeBookRef Asc)
Create Nonclustered Index IDX_AST_AssetDocAccCode_DebitAccEntityL1CodeBookRef On AST.AssetDocAccCode(DebitAccEntityL1CodeBookRef Asc)
Create Nonclustered Index IDX_AST_AssetDocAccCode_DebitAccEntityL2CodeBookRef On AST.AssetDocAccCode(DebitAccEntityL2CodeBookRef Asc)
Create Nonclustered Index IDX_AST_AssetDocAccCode_DebitAccSecondEntityCodeBookRef On AST.AssetDocAccCode(DebitAccSecondEntityCodeBookRef Asc)
Create Nonclustered Index IDX_AST_AssetDocAccCode_DebitAccThirdEntityCodeBookRef On AST.AssetDocAccCode(DebitAccThirdEntityCodeBookRef Asc)
Create Nonclustered Index IDX_AST_AssetDocAccCode_CreditAccAdjutantL1CodeBookRef On AST.AssetDocAccCode(CreditAccAdjutantL1CodeBookRef Asc)
Create Nonclustered Index IDX_AST_AssetDocAccCode_CreditAccEntityL1CodeBookRef On AST.AssetDocAccCode(CreditAccEntityL1CodeBookRef Asc)
Create Nonclustered Index IDX_AST_AssetDocAccCode_CreditAccEntityL2CodeBookRef On AST.AssetDocAccCode(CreditAccEntityL2CodeBookRef Asc)
Create Nonclustered Index IDX_AST_AssetDocAccCode_CreditAccSecondEntityCodeBookRef On AST.AssetDocAccCode(CreditAccSecondEntityCodeBookRef Asc)
Create Nonclustered Index IDX_AST_AssetDocAccCode_CreditAccThirdEntityCodeBookRef On AST.AssetDocAccCode(CreditAccThirdEntityCodeBookRef Asc)
Create Nonclustered Index IDX_AST_AssetDocAccCode_AssetDocHeaderRef_AssetDocDetailRef On AST.AssetDocAccCode(AssetDocHeaderRef, AssetDocDetailRef, SystemAccCodeDefaultBaseRef Asc)
Go

Create Table AST.SystemAccCodeDefaultPerAssetGroup(
	Serial Bigint Identity(1,1) Not Null, ----------- 
	AssetGroupRef Int Not Null,
	SystemAccCodeDefaultBaseRef Int Not Null,
	DebitAccAdjutantL1CodeBookRef Bigint Null, -----
	DebitAccEntityL1CodeBookRef Bigint Null, -------
	DebitAccEntityL2CodeBookRef Bigint Null, -------
	DebitAccSecondEntityCodeBookRef Bigint Null, ---
	DebitAccThirdEntityCodeBookRef Bigint Null,	----
	CreditAccAdjutantL1CodeBookRef Bigint Null,	----
	CreditAccEntityL1CodeBookRef Bigint Null, ------
	CreditAccEntityL2CodeBookRef Bigint Null, ------
	CreditAccSecondEntityCodeBookRef Bigint Null, --
	CreditAccThirdEntityCodeBookRef Bigint Null) ---
GO
Alter Table AST.SystemAccCodeDefaultPerAssetGroup Add Constraint PK_AST_SystemAccCodeDefaultPerAssetGroup Primary Key Clustered (Serial)
Alter Table AST.SystemAccCodeDefaultPerAssetGroup Add Constraint FK_AST_SystemAccCodeDefaultPerAssetGroup_AssetGroup Foreign Key(AssetGroupRef) References AST.AssetGroup (Serial)
Alter Table AST.SystemAccCodeDefaultPerAssetGroup Add Constraint FK_AST_SystemAccCodeDefaultPerAssetGroup_SystemAccCodeDefaultBase Foreign Key(SystemAccCodeDefaultBaseRef) References dbo.SystemAccCodeDefaultBase (Serial)
GO
Alter Table AST.SystemAccCodeDefaultPerAssetGroup Add Constraint FK_AST_SystemAccCodeDefaultPerAssetGroup_DebitAccAdjutantL1CodeBookRef Foreign Key(DebitAccAdjutantL1CodeBookRef) References dbo.AccAdjutantL1CodeBook (Serial)
Alter Table AST.SystemAccCodeDefaultPerAssetGroup Add Constraint FK_AST_SystemAccCodeDefaultPerAssetGroup_DebitAccEntityL1CodeBookRef Foreign Key(DebitAccEntityL1CodeBookRef) References dbo.AccEntityL1CodeBook (Serial)
Alter Table AST.SystemAccCodeDefaultPerAssetGroup Add Constraint FK_AST_SystemAccCodeDefaultPerAssetGroup_DebitAccEntityL2CodeBookRef Foreign Key(DebitAccEntityL2CodeBookRef) References dbo.AccEntityL2CodeBook (Serial)
Alter Table AST.SystemAccCodeDefaultPerAssetGroup Add Constraint FK_AST_SystemAccCodeDefaultPerAssetGroup_DebitAccSecondEntityCodeBookRef Foreign Key(DebitAccSecondEntityCodeBookRef) References dbo.AccSecondEntityCodeBook (Serial)
Alter Table AST.SystemAccCodeDefaultPerAssetGroup Add Constraint FK_AST_SystemAccCodeDefaultPerAssetGroup_DebitAccThirdEntityCodeBookRef Foreign Key(DebitAccThirdEntityCodeBookRef) References dbo.AccThirdEntityCodeBook (Serial)
Alter Table AST.SystemAccCodeDefaultPerAssetGroup Add Constraint FK_AST_SystemAccCodeDefaultPerAssetGroup_CreditAccAdjutantL1CodeBookRef Foreign Key(CreditAccAdjutantL1CodeBookRef) References dbo.AccAdjutantL1CodeBook (Serial)
Alter Table AST.SystemAccCodeDefaultPerAssetGroup Add Constraint FK_AST_SystemAccCodeDefaultPerAssetGroup_CreditAccEntityL1CodeBookRef Foreign Key(CreditAccEntityL1CodeBookRef) References dbo.AccEntityL1CodeBook (Serial)
Alter Table AST.SystemAccCodeDefaultPerAssetGroup Add Constraint FK_AST_SystemAccCodeDefaultPerAssetGroup_CreditAccEntityL2CodeBookRef Foreign Key(CreditAccEntityL2CodeBookRef) References dbo.AccEntityL2CodeBook (Serial)
Alter Table AST.SystemAccCodeDefaultPerAssetGroup Add Constraint FK_AST_SystemAccCodeDefaultPerAssetGroup_CreditAccSecondEntityCodeBookRef Foreign Key(CreditAccSecondEntityCodeBookRef) References dbo.AccSecondEntityCodeBook (Serial)
Alter Table AST.SystemAccCodeDefaultPerAssetGroup Add Constraint FK_AST_SystemAccCodeDefaultPerAssetGroup_CreditAccThirdEntityCodeBookRef Foreign Key(CreditAccThirdEntityCodeBookRef) References dbo.AccThirdEntityCodeBook (Serial)
Go
Create Nonclustered Index IDX_AST_SystemAccCodeDefaultPerAssetGroup_DebitAccAdjutantL1CodeBookRef On AST.SystemAccCodeDefaultPerAssetGroup(DebitAccAdjutantL1CodeBookRef Asc)
Create Nonclustered Index IDX_AST_SystemAccCodeDefaultPerAssetGroup_DebitAccEntityL1CodeBookRef On AST.SystemAccCodeDefaultPerAssetGroup(DebitAccEntityL1CodeBookRef Asc)
Create Nonclustered Index IDX_AST_SystemAccCodeDefaultPerAssetGroup_DebitAccEntityL2CodeBookRef On AST.SystemAccCodeDefaultPerAssetGroup(DebitAccEntityL2CodeBookRef Asc)
Create Nonclustered Index IDX_AST_SystemAccCodeDefaultPerAssetGroup_DebitAccSecondEntityCodeBookRef On AST.SystemAccCodeDefaultPerAssetGroup(DebitAccSecondEntityCodeBookRef Asc)
Create Nonclustered Index IDX_AST_SystemAccCodeDefaultPerAssetGroup_DebitAccThirdEntityCodeBookRef On AST.SystemAccCodeDefaultPerAssetGroup(DebitAccThirdEntityCodeBookRef Asc)
Create Nonclustered Index IDX_AST_SystemAccCodeDefaultPerAssetGroup_CreditAccAdjutantL1CodeBookRef On AST.SystemAccCodeDefaultPerAssetGroup(CreditAccAdjutantL1CodeBookRef Asc)
Create Nonclustered Index IDX_AST_SystemAccCodeDefaultPerAssetGroup_CreditAccEntityL1CodeBookRef On AST.SystemAccCodeDefaultPerAssetGroup(CreditAccEntityL1CodeBookRef Asc)
Create Nonclustered Index IDX_AST_SystemAccCodeDefaultPerAssetGroup_CreditAccEntityL2CodeBookRef On AST.SystemAccCodeDefaultPerAssetGroup(CreditAccEntityL2CodeBookRef Asc)
Create Nonclustered Index IDX_AST_SystemAccCodeDefaultPerAssetGroup_CreditAccSecondEntityCodeBookRef On AST.SystemAccCodeDefaultPerAssetGroup(CreditAccSecondEntityCodeBookRef Asc)
Create Nonclustered Index IDX_AST_SystemAccCodeDefaultPerAssetGroup_CreditAccThirdEntityCodeBookRef On AST.SystemAccCodeDefaultPerAssetGroup(CreditAccThirdEntityCodeBookRef Asc)
Create Nonclustered Index IDX_AST_SystemAccCodeDefaultPerAssetGroup_AssetGroupRef_SystemAccCodeDefaultBaseRef On AST.SystemAccCodeDefaultPerAssetGroup(AssetGroupRef, SystemAccCodeDefaultBaseRef Asc)
Go
--
--
--
--
--
--
--
-- ایجاد داده در جداول پایه دارایی ثابت
INSERT [AST].[AssetDocKind] ([Serial], [FA_Description], [EN_Description], [Stream], [Priority]) VALUES (310, N'خرید اموال',     N'Assets purchase', N'+', 10)
INSERT [AST].[AssetDocKind] ([Serial], [FA_Description], [EN_Description], [Stream], [Priority]) VALUES (315, N'استقرار اموال',  N'Assets Establish', N'+', 10)
INSERT [AST].[AssetDocKind] ([Serial], [FA_Description], [EN_Description], [Stream], [Priority]) VALUES (320, N'تحویل و انتقال', N'Carry over Asset', N'-', 20) 
INSERT [AST].[AssetDocKind] ([Serial], [FA_Description], [EN_Description], [Stream], [Priority]) VALUES (330, N'تجدید ارزیابی',  N'Assets revaluation', N'+', 30)
INSERT [AST].[AssetDocKind] ([Serial], [FA_Description], [EN_Description], [Stream], [Priority]) VALUES (340, N'بیمه دارایی ها', N'Assets insurance', N'+', 40)
INSERT [AST].[AssetDocKind] ([Serial], [FA_Description], [EN_Description], [Stream], [Priority]) VALUES (350, N'تعمییرات اساسی', N'Major overhaul', N'+', 50)
INSERT [AST].[AssetDocKind] ([Serial], [FA_Description], [EN_Description], [Stream], [Priority]) VALUES (360, N'محاسبه استهلاک',  N'Calculate depreciation', N'-', 60)
INSERT [AST].[AssetDocKind] ([Serial], [FA_Description], [EN_Description], [Stream], [Priority]) VALUES (370, N'اسقاط دارایی',   N'Residual', N'-', 70)
INSERT [AST].[AssetDocKind] ([Serial], [FA_Description], [EN_Description], [Stream], [Priority]) VALUES (380, N'خروج اموال',     N'Output', N'-', 80)
--
--
--
--
--
--
--
-- 
If Exists(Select * From sys.objects Where name = 'New_Code') Drop Function dbo.New_Code
Go
Create Function dbo.New_Code(@Table_Name Varchar(50),@Kind Varchar(50),	@OfficeDetailRef Int, @OfficePeriodRef	Int)
Returns Bigint
With Encryption
As  
Begin 
	Declare @Code	Bigint

	If @Table_Name = 'Storages'
		Select @Code = (Select Max(Code) From storages Where OfficeDetailRef = @OfficeDetailRef)
	Else If @Table_Name = 'Groups'	
		Select @Code = (Select Max(Code) From groups Where OfficeDetailRef = @OfficeDetailRef)
	Else If @Table_Name = 'Units'
		Select @Code = (Select Max(Code) From units Where OfficeDetailRef = @OfficeDetailRef)
	Else If @Table_Name = 'Warehouse'
		Select @Code = (Select Max(Code) From WarehoUse Where OfficeDetailRef = @OfficeDetailRef)
	Else If @Table_Name = 'UnitWeight'
		Select @Code = (Select Max(Code) From UnitWeight  Where OfficeDetailRef = @OfficeDetailRef)
	Else If @Table_Name = 'Part' 
		Select @Code = (Select Max(Cast(Code As Bigint)) From part Where OfficeDetailRef = @OfficeDetailRef)
	Else If @Table_Name = 'GetterOrPayerFactor'
		Select @Code = (Select Max(Code) From GetterOrPayerFactor  Where KindRef = Cast(@Kind As Smallint) And OfficeDetailRef = @OfficeDetailRef)
	Else If @Table_Name = 'Broker'
		Select @Code = (Select Max(Code) From Broker  Where BrokerKindRef = Cast(@Kind As Smallint) And OfficeDetailRef = @OfficeDetailRef)
	Else If @Table_Name = 'FactorHeader'
		Select @Code = (Select Max(Code) From FactorHeader  Where FactorKindRef = @Kind And OfficeDetailRef = @OfficeDetailRef And OfficePeriodRef = @OfficePeriodRef)
	Else If @Table_Name = 'WarehouseVerification'
		Select @Code = (Select Max(WarehouseVerificationCode) From FactorHeader  Where FactorKindRef in (Select Serial From FactorKind Where Stream = @Kind) And OfficeDetailRef = @OfficeDetailRef And OfficePeriodRef = @OfficePeriodRef)
	Else If @Table_Name = 'Users'
		Select @Code = (Select Max(Code) From Users Where OfficeDetailRef = @OfficeDetailRef)
	Else If @Table_Name = 'AccGroupCodeBook'
		Select @Code = (Select Max(Code) From AccGroupCodeBook Where OfficeDetailRef = @OfficeDetailRef)
	Else If @Table_Name = 'AccGeneralCodeBook'
		Select @Code = (Select Max(Code) From AccGeneralCodeBook Where AccGroupCodeBookRef = Cast(@kind As Bigint) And OfficeDetailRef = @OfficeDetailRef)
	Else If @Table_Name = 'AccAdjutantL1CodeBook'
		Select @Code = (Select Max(Code) From AccAdjutantL1CodeBook Where AccGeneralCodeBookRef = Cast(@kind As Bigint) And OfficeDetailRef = @OfficeDetailRef)
	Else If @Table_Name = 'AccEntityL1CodeBook'
		Select @Code = (Select Max(Code) From AccEntityL1CodeBook Where OfficeDetailRef = @OfficeDetailRef)
	Else If @Table_Name = 'AccEntityL2CodeBook'
		Select @Code = (Select Max(Code) From AccEntityL2CodeBook Where AccEntityL1CodeBookRef = Cast(@kind As Bigint) And OfficeDetailRef = @OfficeDetailRef)
	Else If @Table_Name = 'AccSecondEntityCodeBook'
		Select @Code = (Select Max(Code) From AccSecondEntityCodeBook Where OfficeDetailRef = @OfficeDetailRef)
	Else If @Table_Name = 'AccThirdEntityCodeBook'
		Select @Code = (Select Max(Code) From AccThirdEntityCodeBook Where OfficeDetailRef = @OfficeDetailRef)
	Else If @Table_Name = 'AccDocumentHeader'
	Begin
		If @kind = 'TempCode'
			Select @Code = (Select Max(TempCode) From AccDocumentHeader Where OfficeDetailRef = @OfficeDetailRef And OfficePeriodRef = @OfficePeriodRef)
		Else If @kind = 'FinalCode'
			Select @Code = (Select Max(FinalCode) From AccDocumentHeader Where OfficeDetailRef = @OfficeDetailRef And OfficePeriodRef = @OfficePeriodRef)
	End
	Else If @Table_Name = 'CashGetPay'
		Select @Code = (Select Max(Code) From CashGetPay  Where CashGetPayKindRef = @Kind And OfficeDetailRef = @OfficeDetailRef And OfficePeriodRef = @OfficePeriodRef)
	Else If @Table_Name = 'CheckGetPayHeader'
		Select @Code = (Select Max(Code) From CheckGetPayHeader  Where CheckPositionRef = @Kind And OfficeDetailRef = @OfficeDetailRef And OfficePeriodRef = @OfficePeriodRef)
	Else If @Table_Name = 'Bank'
		Select @Code = (Select Max(Code) From Bank Where OfficeDetailRef = @OfficeDetailRef)
	Else If @Table_Name = 'AccEntityKind'
		Select @Code = (Select Max(Code) From AccEntityKind Where OfficeDetailRef = @OfficeDetailRef)
	Else If @Table_Name = 'BankAccount'
		Select @Code = (Select Max(Code) From BankAccount Where OfficeDetailRef = @OfficeDetailRef)
	Else If @Table_Name = 'OfficeDetail'
		Select @Code = (Select Max(Code) From OfficeDetail)
	Else If @Table_Name = 'OfficePeriod'
		Select @Code = (Select Max(Code) From OfficePeriod Where OfficeDetailRef = @OfficeDetailRef)
	Else If @Table_Name = 'CheckBookHeader'
		Select @Code = (Select Max(Code) From CheckBookHeader Where OfficeDetailRef = @OfficeDetailRef)
	Else If @Table_Name = 'StorageCountHeader'
		Select @Code = (Select Max(Code) From StorageCountHeader Where OfficeDetailRef = @OfficeDetailRef And OfficePeriodRef = @OfficePeriodRef)
	Else If @Table_Name = 'GritProduct'
		Select @Code = (Select Max(Code) From GritProduct Where OfficeDetailRef = @OfficeDetailRef)
	Else If @Table_Name = 'GritFactor'
		Select @Code = (Select Max(Code) From GritFactor Where GritFactorKindRef = @Kind And OfficeDetailRef = @OfficeDetailRef And OfficePeriodRef = @OfficePeriodRef)
	Else If @Table_Name = 'CostBase'
		Select @Code = (Select Max(Code) From CostBase Where OfficeDetailRef = @OfficeDetailRef)
	Else If @Table_Name = 'CostCenter'
		Select @Code = (Select Max(Code) From CostCenter Where OfficeDetailRef = @OfficeDetailRef)
	Else If @Table_Name = 'CostCash'
		Select @Code = (Select Max(Code) From CostCash Where OfficeDetailRef = @OfficeDetailRef)
	Else If @Table_Name = 'CostFunds'
		Select @Code = (Select Max(Code) From CostFunds Where OfficeDetailRef = @OfficeDetailRef)
	Else If @Table_Name = 'CostCredit'
		Select @Code = (Select Max(Code) From CostCredit Where OfficeDetailRef = @OfficeDetailRef)
	Else If @Table_Name = 'CostHeader'
		Select @Code = (Select Max(Code) From CostHeader  Where OfficeDetailRef = @OfficeDetailRef And OfficePeriodRef = @OfficePeriodRef)
	Else If @Table_Name = 'Degree'
		Select @Code = (Select Max(Code) From Degree  Where OfficeDetailRef = @OfficeDetailRef)
	Else If @Table_Name = 'Getter_Or_Payer_Factor_Category'
		Select @Code = (Select Max(Code) From GetterOrPayerFactorCategory  Where OfficeDetailRef = @OfficeDetailRef)
	Else If @Table_Name = 'BIReportFile'
		Select @Code = (Select Max(Code) From BIReportFile  Where OfficeDetailRef = @OfficeDetailRef)
	Else If @Table_Name = 'FactorCategory'
		Select @Code = (Select Max(Code) From FactorCategory  Where Kind = Cast(@Kind As Smallint) And OfficeDetailRef = @OfficeDetailRef)
	Else If @Table_Name = 'PAY.JobCategory'
		Select @Code = (Select Max(Code) From PAY.JobCategory  Where OfficeDetailRef = @OfficeDetailRef)
	Else If @Table_Name = 'PAY.Job'
		Select @Code = (Select Max(Code) From PAY.Job  Where OfficeDetailRef = @OfficeDetailRef)
	Else If @Table_Name = 'PAY.JobLocation'
		Select @Code = (Select Max(Code) From PAY.JobLocation  Where OfficeDetailRef = @OfficeDetailRef)
	Else If @Table_Name = 'PAY.LoanType'
		Select @Code = (Select Max(Code) From PAY.LoanType  Where OfficeDetailRef = @OfficeDetailRef)
	Else If @Table_Name = 'PAY.TaxGroup'
		Select @Code = (Select Max(Code) From PAY.TaxGroup  Where OfficeDetailRef = @OfficeDetailRef)
	Else If @Table_Name = 'PAY.SSIOrg'
		Select @Code = (Select Max(Code) From PAY.SSIOrg  Where OfficeDetailRef = @OfficeDetailRef)
	Else If @Table_Name = 'PAY.SPIOrg'
		Select @Code = (Select Max(Code) From PAY.SPIOrg  Where OfficeDetailRef = @OfficeDetailRef)
	Else If @Table_Name = 'PAY.EmployeeTaxOrg'
		Select @Code = (Select Max(Code) From PAY.EmployeeTaxOrg  Where OfficeDetailRef = @OfficeDetailRef)
	Else If @Table_Name = 'Employee' 
		Select @Code = (Select Max(Cast(Code As Bigint)) From PAY.Employee Where OfficeDetailRef = @OfficeDetailRef)
	Else If @Table_Name = 'PAY.Factor'
		Select @Code = (Select Max(FactorCode) From PAY.FactorList  Where OfficeDetailRef = @OfficeDetailRef And FactorGroupType = Cast(@Kind As Smallint))
	Else If @Table_Name = 'PAY.Contract'
		Select @Code = (Select Max(ContractNumber) From PAY.Contract  Where OfficeDetailRef = @OfficeDetailRef)
	Else If @Table_Name = 'PAY.TaxTableHeader'
		Select @Code = (Select Max(Code) From PAY.TaxTableHeader  Where OfficeDetailRef = @OfficeDetailRef And OfficePeriodRef = @OfficePeriodRef)
	Else If @Table_Name = 'PaymentComputingHeader'
		Select @Code = (Select Max(Code) From PAY.PaymentComputingHeader  Where OfficeDetailRef = @OfficeDetailRef And OfficePeriodRef = @OfficePeriodRef)
	Else If @Table_Name = 'AST.Collectors'
		Select @Code = (Select Max(Code) From AST.Collectors  Where OfficeDetailRef = @OfficeDetailRef)
	Else If @Table_Name = 'AST.AssetType'
		Select @Code = (Select Max(Code) From AST.AssetType  Where OfficeDetailRef = @OfficeDetailRef)
	Else If @Table_Name = 'AST.AssetGroup'
		Select @Code = (Select Max(Code) From AST.AssetGroup  Where OfficeDetailRef = @OfficeDetailRef)
	Else If @Table_Name = 'AST.Asset'
		Select @Code = (Select Max(Code) From AST.Asset  Where OfficeDetailRef = @OfficeDetailRef)
	Else If @Table_Name = 'AssetDocHeader'
		Select @Code = (Select Max(Code) From AST.AssetDocHeader  Where AssetDocKindRef = @Kind And OfficeDetailRef = @OfficeDetailRef And OfficePeriodRef = @OfficePeriodRef)

	If @Code Is Null
		Set  @Code = 1
	Else
		Set  @Code = @Code+1 
	
	Return @Code

End
Go
--
--
--
--
--
--
--
-- ایجاد داده های پیش فرص اولیه برای همه دفاتر مالی و در جداول کاربران
Declare @RecorderRef Int
Declare @OfficeDetailRef Int
Declare @AssetGroupSerial Int

Declare Tmp_Cursor2 Cursor Local For Select Serial From OfficeDetail 
Open Tmp_Cursor2
Fetch Next From Tmp_Cursor2 Into @OfficeDetailRef
While @@FETCH_STATUS = 0
Begin
	Select @RecorderRef = RecorderRef From OfficePeriod Where OfficeDetailRef = @OfficeDetailRef
		
	Insert Into AST.AssetGroup (Code, FADescription, ENDescription, RecorderRef, RecordDate, OfficeDetailRef) values (dbo.new_Code('AST.AssetGroup','',@OfficeDetailRef,''), 'اثاثه و منصوبات اداری', '', @RecorderRef, dbo.Solar_Date_Converter(getdate()), @OfficeDetailRef) 
	Select @AssetGroupSerial = Scope_Identity() 
	Insert Into AST.AssetType (AssetGroupRef, Code, FADescription, ENDescription, RecorderRef, RecordDate, OfficeDetailRef) values (@AssetGroupSerial, dbo.new_Code('AST.AssetType','',@OfficeDetailRef,''), 'میز', '', @RecorderRef, dbo.Solar_Date_Converter(getdate()), @OfficeDetailRef) 
	Insert Into AST.AssetType (AssetGroupRef, Code, FADescription, ENDescription, RecorderRef, RecordDate, OfficeDetailRef) values (@AssetGroupSerial, dbo.new_Code('AST.AssetType','',@OfficeDetailRef,''), 'صندلی', '', @RecorderRef, dbo.Solar_Date_Converter(getdate()), @OfficeDetailRef) 
	Insert Into AST.AssetType (AssetGroupRef, Code, FADescription, ENDescription, RecorderRef, RecordDate, OfficeDetailRef) values (@AssetGroupSerial, dbo.new_Code('AST.AssetType','',@OfficeDetailRef,''), 'فایل', '', @RecorderRef, dbo.Solar_Date_Converter(getdate()), @OfficeDetailRef) 
	Insert Into AST.AssetType (AssetGroupRef, Code, FADescription, ENDescription, RecorderRef, RecordDate, OfficeDetailRef) values (@AssetGroupSerial, dbo.new_Code('AST.AssetType','',@OfficeDetailRef,''), 'کتابخانه', '', @RecorderRef, dbo.Solar_Date_Converter(getdate()), @OfficeDetailRef) 


	Insert Into AST.AssetGroup (Code, FADescription, ENDescription, RecorderRef, RecordDate, OfficeDetailRef) values (dbo.new_Code('AST.AssetGroup','',@OfficeDetailRef,''), 'ملزومات الکتریکی و الکترونیکی', '', @RecorderRef, dbo.Solar_Date_Converter(getdate()), @OfficeDetailRef) 
	Select @AssetGroupSerial = Scope_Identity() 
	Insert Into AST.AssetType (AssetGroupRef, Code, FADescription, ENDescription, RecorderRef, RecordDate, OfficeDetailRef) values (@AssetGroupSerial, dbo.new_Code('AST.AssetType','',@OfficeDetailRef,''), 'کامپیوتر', '', @RecorderRef, dbo.Solar_Date_Converter(getdate()), @OfficeDetailRef) 
	Insert Into AST.AssetType (AssetGroupRef, Code, FADescription, ENDescription, RecorderRef, RecordDate, OfficeDetailRef) values (@AssetGroupSerial, dbo.new_Code('AST.AssetType','',@OfficeDetailRef,''), 'پرینتر', '', @RecorderRef, dbo.Solar_Date_Converter(getdate()), @OfficeDetailRef) 
	Insert Into AST.AssetType (AssetGroupRef, Code, FADescription, ENDescription, RecorderRef, RecordDate, OfficeDetailRef) values (@AssetGroupSerial, dbo.new_Code('AST.AssetType','',@OfficeDetailRef,''), 'ماشین حساب', '', @RecorderRef, dbo.Solar_Date_Converter(getdate()), @OfficeDetailRef) 
	Insert Into AST.AssetType (AssetGroupRef, Code, FADescription, ENDescription, RecorderRef, RecordDate, OfficeDetailRef) values (@AssetGroupSerial, dbo.new_Code('AST.AssetType','',@OfficeDetailRef,''), 'ساعت', '', @RecorderRef, dbo.Solar_Date_Converter(getdate()), @OfficeDetailRef) 
	Insert Into AST.AssetType (AssetGroupRef, Code, FADescription, ENDescription, RecorderRef, RecordDate, OfficeDetailRef) values (@AssetGroupSerial, dbo.new_Code('AST.AssetType','',@OfficeDetailRef,''), 'تلویزیون', '', @RecorderRef, dbo.Solar_Date_Converter(getdate()), @OfficeDetailRef) 
	Insert Into AST.AssetType (AssetGroupRef, Code, FADescription, ENDescription, RecorderRef, RecordDate, OfficeDetailRef) values (@AssetGroupSerial, dbo.new_Code('AST.AssetType','',@OfficeDetailRef,''), 'سانترال', '', @RecorderRef, dbo.Solar_Date_Converter(getdate()), @OfficeDetailRef) 
	Insert Into AST.AssetType (AssetGroupRef, Code, FADescription, ENDescription, RecorderRef, RecordDate, OfficeDetailRef) values (@AssetGroupSerial, dbo.new_Code('AST.AssetType','',@OfficeDetailRef,''), 'گوشی تلفن', '', @RecorderRef, dbo.Solar_Date_Converter(getdate()), @OfficeDetailRef) 
	Insert Into AST.AssetType (AssetGroupRef, Code, FADescription, ENDescription, RecorderRef, RecordDate, OfficeDetailRef) values (@AssetGroupSerial, dbo.new_Code('AST.AssetType','',@OfficeDetailRef,''), 'دستگاه حضور و غیاب', '', @RecorderRef, dbo.Solar_Date_Converter(getdate()), @OfficeDetailRef) 

	Insert Into AST.AssetGroup (Code, FADescription, ENDescription, RecorderRef, RecordDate, OfficeDetailRef) values (dbo.new_Code('AST.AssetGroup','',@OfficeDetailRef,''), 'لوازم آبدارخانه', '', @RecorderRef, dbo.Solar_Date_Converter(getdate()), @OfficeDetailRef) 
	Select @AssetGroupSerial = Scope_Identity() 
	Insert Into AST.AssetType (AssetGroupRef, Code, FADescription, ENDescription, RecorderRef, RecordDate, OfficeDetailRef) values (@AssetGroupSerial, dbo.new_Code('AST.AssetType','',@OfficeDetailRef,''), 'گاز', '', @RecorderRef, dbo.Solar_Date_Converter(getdate()), @OfficeDetailRef) 
	Insert Into AST.AssetType (AssetGroupRef, Code, FADescription, ENDescription, RecorderRef, RecordDate, OfficeDetailRef) values (@AssetGroupSerial, dbo.new_Code('AST.AssetType','',@OfficeDetailRef,''), 'یخچال', '', @RecorderRef, dbo.Solar_Date_Converter(getdate()), @OfficeDetailRef) 
	Insert Into AST.AssetType (AssetGroupRef, Code, FADescription, ENDescription, RecorderRef, RecordDate, OfficeDetailRef) values (@AssetGroupSerial, dbo.new_Code('AST.AssetType','',@OfficeDetailRef,''), 'ماکروفر', '', @RecorderRef, dbo.Solar_Date_Converter(getdate()), @OfficeDetailRef) 

	Insert Into AST.AssetGroup (Code, FADescription, ENDescription, RecorderRef, RecordDate, OfficeDetailRef) values (dbo.new_Code('AST.AssetGroup','',@OfficeDetailRef,''), 'وسائط نقليه', '', @RecorderRef, dbo.Solar_Date_Converter(getdate()), @OfficeDetailRef) 
	Select @AssetGroupSerial = Scope_Identity() 

	Insert Into AST.AssetGroup (Code, FADescription, ENDescription, RecorderRef, RecordDate, OfficeDetailRef) values (dbo.new_Code('AST.AssetGroup','',@OfficeDetailRef,''), 'ابزار آلات', '', @RecorderRef, dbo.Solar_Date_Converter(getdate()), @OfficeDetailRef) 
	Select @AssetGroupSerial = Scope_Identity() 

	Insert Into AST.AssetGroup (Code, FADescription, ENDescription, RecorderRef, RecordDate, OfficeDetailRef) values (dbo.new_Code('AST.AssetGroup','',@OfficeDetailRef,''), 'ماشین آلات صنعتی', '', @RecorderRef, dbo.Solar_Date_Converter(getdate()), @OfficeDetailRef) 
	Select @AssetGroupSerial = Scope_Identity() 

	Fetch Next From Tmp_Cursor2 Into @OfficeDetailRef
End
Close Tmp_Cursor2
Deallocate Tmp_Cursor2
