-- خط زیر را غیر فعال کردم تا در هنگام به روز رسانی مکانیزه، در صورتی که نام دینابیس چیز دیگری بود، خطایی رخ ندهد
-- ولی در هنگام به روز رسانی های دستی حتما باید به دیتابیس جاری توجه شود
--Use [ATNDB]
--Select * From [ATNDBTest].dbo.SystemParameters Where SubjectKey In('Application_Version', 'Database_Version')

Alter Table [ATNDB].dbo.Users Disable Trigger Users_SetEmptyPassword
Alter Table [ATNDB].dbo.AccDocumentHeader Disable Trigger AccDocumentHeader_TimeStamp_Update
Alter Table [ATNDB].dbo.AccDocumentDetail Disable Trigger AccDocumentDetail_ComputeTotalSum
Alter Table [ATNDB].dbo.FactorHeader Disable Trigger FactorHeader_TimeStamp_Update
Alter Table [ATNDB].dbo.CheckGetPayHeader Disable Trigger CheckGetPayHeader_TimeStamp_Update
Alter Table [ATNDB].dbo.CashGetPay Disable Trigger CashGetPay_Compute_FactorCashSettlementCheckBridge
Alter Table [ATNDB].dbo.CashGetPay Disable Trigger CashGetPay_TimeStamp_Update
Alter Table [ATNDB].dbo.CostHeader Disable Trigger CostHeader_TimeStamp_Update
Alter Table [ATNDB].dbo.StorageCountHeader Disable Trigger StorageCountHeader_TimeStamp_Update
Alter Table [ATNDB].dbo.GritFactor Disable Trigger GritFactor_TimeStamp_Update
Alter Table [ATNDB].PAY.PaymentComputingHeader Disable Trigger PaymentComputingHeader_TimeStamp_Update
Alter Table [ATNDB].PAY.LoanPaybackPlanHeader Disable Trigger LoanPaybackPlan_Header_TimeStamp_Update
Alter Table [ATNDB].AST.AssetDocHeader Disable Trigger AssetDoc_Header_TimeStamp_Update
Alter Table [ATNDB].POM.WorkDetailTask Disable Trigger WorkDetailTask_TimeStamp_Update

----------------------------------------------------------------------------------------------------
Exec [ATNDB].dbo.__Delete_All_Tables_Content
----------------------------------------------------------------------------------------------------
Insert Into [ATNDB].dbo.Users (Serial, Code, Name, Password, Active, Permition, Warehouses, Brokers, RecorderRef, RecordDate, OfficeDetailRef)
	                  Select Serial, Code, Name, Password, Active, Permition, Warehouses, Brokers, RecorderRef, RecordDate, OfficeDetailRef 
					  From [ATNDBTest].dbo.Users 
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].dbo.Roles On 
Insert Into [ATNDB].dbo.Roles (Serial, Code, FADescription, ENDescription, Permition, Warehouses, Brokers, RecorderRef, RecordDate, EditorRef, EditDate, Comment, OfficeDetailRef)
	                  Select Serial, Code, FADescription, ENDescription, Permition, Warehouses, Brokers, RecorderRef, RecordDate, EditorRef, EditDate, Comment, OfficeDetailRef 
					  From [ATNDBTest].dbo.Roles 
Set Identity_Insert [ATNDB].dbo.Roles Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].dbo.RolePerUser On 
Insert Into [ATNDB].dbo.RolePerUser (Serial, UserRef, RoleRef)
	                        Select Serial, UserRef, RoleRef 
					        From [ATNDBTest].dbo.RolePerUser 
Set Identity_Insert [ATNDB].dbo.RolePerUser Off
----------------------------------------------------------------------------------------------------
Insert Into [ATNDB].dbo.OfficeDetail (Serial, Code, OfficeName, OfficeEnName, Phone1, Phone2, Fax, Address, PostCode, RegisterationDate, RegisterationNo, EconomicCode, TaxMemoryID, TaxFolderUrl, TaxPrivateKey, TaxPublicKey, TaxCSR, SSN, ActiveOffice, RecorderRef, RecordDate, comment)
							 Select Serial, Code, OfficeName, OfficeEnName, Phone1, Phone2, Fax, Address, PostCode, RegisterationDate, RegisterationNo, EconomicCode, TaxMemoryID, TaxFolderUrl, TaxPrivateKey, TaxPublicKey, TaxCSR, SSN, ActiveOffice, RecorderRef, RecordDate, comment
							 From [ATNDBTest].dbo.OfficeDetail
Insert Into [ATNDB].dbo.OfficePeriod (Serial, Code, PeriodName, StartDate, EndDate, InaugurationAccDocumentSerial, CloseTemporaryAccountsAccDocumentSerial, ConclusionAccDocumentSerial, PreviousOfficePeriodSerial, RecorderRef, RecordDate, ActivePeriod, ReadOnlyPeriod, Comment, OfficeDetailRef)
							 Select Serial, Code, PeriodName, StartDate, EndDate, InaugurationAccDocumentSerial, CloseTemporaryAccountsAccDocumentSerial, ConclusionAccDocumentSerial, PreviousOfficePeriodSerial, RecorderRef, RecordDate, ActivePeriod, ReadOnlyPeriod, Comment, OfficeDetailRef
							From [ATNDBTest].dbo.OfficePeriod
----------------------------------------------------------------------------------------------------
Insert Into [ATNDB].dbo.SpecialWords Select * From [ATNDBTest].dbo.SpecialWords
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].dbo.TaxApiTransactionLog On
Insert Into [ATNDB].dbo.TaxApiTransactionLog (Serial, Id, LockSerial, MemoryId, OfficeDetailName, FactorHeaderSerial, TaxFactorKind, TaxReferenceId, TaxUniqueId, TaxFolderUrl, Timestamp)
									 Select Serial, Id, LockSerial, MemoryId, OfficeDetailName, FactorHeaderSerial, TaxFactorKind, TaxReferenceId, TaxUniqueId, TaxFolderUrl, Timestamp
									 From [ATNDBTest].dbo.TaxApiTransactionLog
Set Identity_Insert [ATNDB].dbo.TaxApiTransactionLog Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].dbo.License On
Insert Into [ATNDB].dbo.License (Serial, Id, LockSerial, UserKey, ActivationCode, ClientName, MemoryId, ActivationDate, ActivationDate_Miladi, ExpirationDate, ExpirationDate_Miladi, LicenseValidityDurationInMonth, LicenseValidityDurationInDays)
						Select Serial, Id, LockSerial, UserKey, ActivationCode, ClientName, MemoryId, ActivationDate, ActivationDate_Miladi, ExpirationDate, ExpirationDate_Miladi, LicenseValidityDurationInMonth, LicenseValidityDurationInDays
						From [ATNDBTest].dbo.License
Set Identity_Insert [ATNDB].dbo.License Off
----------------------------------------------------------------------------------------------------
Insert Into [ATNDB].dbo.SystemParametersPerOfficeDetail Select * From [ATNDBTest].dbo.SystemParametersPerOfficeDetail
Insert Into [ATNDB].dbo.SystemParametersPerOfficePeriod Select * From [ATNDBTest].dbo.SystemParametersPerOfficePeriod
----------------------------------------------------------------------------------------------------
Insert Into [ATNDB].dbo.ReportMargin Select * From [ATNDBTest].dbo.ReportMargin
Insert Into [ATNDB].dbo.ReportHeader Select * From [ATNDBTest].dbo.ReportHeader
Insert Into [ATNDB].dbo.FactorFooter Select * From [ATNDBTest].dbo.FactorFooter
Insert Into [ATNDB].dbo.FactorReportTemplate Select * From [ATNDBTest].dbo.FactorReportTemplate
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].dbo.ComponentProperty On 
Insert Into [ATNDB].dbo.ComponentProperty (Serial, UserRef, ComponentName, Property, OfficeDetailRef)
	                              Select Serial, UserRef, ComponentName, Property, OfficeDetailRef 
					              From [ATNDBTest].dbo.ComponentProperty 
Set Identity_Insert [ATNDB].dbo.ComponentProperty Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].dbo.UserActionLog On 
Insert Into [ATNDB].dbo.UserActionLog (Serial,UserRef,UserKey,ComputerName,Date,Time,SystemsOperationRef,SystemsDataRef,OfficeDetailRef,OfficePeriodRef) 
	                          Select Serial,UserRef,UserKey,ComputerName,Date,Time,SystemsOperationRef,SystemsDataRef,OfficeDetailRef,OfficePeriodRef 
						      From [ATNDBTest].dbo.UserActionLog 
Set Identity_Insert [ATNDB].dbo.UserActionLog Off
----------------------------------------------------------------------------------------------------
Insert Into [ATNDB].dbo.AccEntityKind Select * From [ATNDBTest].dbo.AccEntityKind
----------------------------------------------------------------------------------------------------
Insert Into [ATNDB].dbo.AccGroupCodeBook Select * From [ATNDBTest].dbo.AccGroupCodeBook
Insert Into [ATNDB].dbo.AccGeneralCodeBook Select * From [ATNDBTest].dbo.AccGeneralCodeBook
Insert Into [ATNDB].dbo.AccAdjutantL1CodeBook Select * From [ATNDBTest].dbo.AccAdjutantL1CodeBook
Insert Into [ATNDB].dbo.AccEntityL1CodeBook Select * From [ATNDBTest].dbo.AccEntityL1CodeBook
Insert Into [ATNDB].dbo.AccEntityL2CodeBook Select * From [ATNDBTest].dbo.AccEntityL2CodeBook
Insert Into [ATNDB].dbo.AccSecondEntityCodeBook Select * From [ATNDBTest].dbo.AccSecondEntityCodeBook
Insert Into [ATNDB].dbo.AccThirdEntityCodeBook Select * From [ATNDBTest].dbo.AccThirdEntityCodeBook
----------------------------------------------------------------------------------------------------
Insert Into [ATNDB].dbo.AccAdjutantL1Bridge Select * From [ATNDBTest].dbo.AccAdjutantL1Bridge
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].dbo.AccDocumentHeader On 
Insert Into [ATNDB].dbo.AccDocumentHeader (Serial,TempCode,FinalCode,FADes,ENDes,Mechanize,SubSystemRef,EffectiveDate,TotalSum,Balance,RecorderRef,RecordDate,EditorRef,EditDate,VerifierRef,VerificationDate,Appendix,Description,OfficeDetailRef,OfficePeriodRef,RowVersion, Tag) 
	                              Select Serial,TempCode,FinalCode,FADes,ENDes,Mechanize,SubSystemRef,EffectiveDate,TotalSum,Balance,RecorderRef,RecordDate,EditorRef,EditDate,VerifierRef,VerificationDate,Appendix,Description,OfficeDetailRef,OfficePeriodRef,RowVersion, Tag From [ATNDBTest].dbo.AccDocumentHeader 
Set Identity_Insert [ATNDB].dbo.AccDocumentHeader Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].dbo.AccDocumentDetail On 
Insert Into [ATNDB].dbo.AccDocumentDetail (Serial,AccDocumentHeaderRef,FADetail,ENDetail,Debit,Credit,DebitInForeignCurrency,CreditInForeignCurrency,AccAdjutantL1CodeBookRef,AccEntityL1CodeBookRef,AccEntityL2CodeBookRef,AccSecondEntityCodeBookRef,AccThirdEntityCodeBookRef, Tag)
	                              Select Serial,AccDocumentHeaderRef,FADetail,ENDetail,Debit,Credit,DebitInForeignCurrency,CreditInForeignCurrency,AccAdjutantL1CodeBookRef,AccEntityL1CodeBookRef,AccEntityL2CodeBookRef,AccSecondEntityCodeBookRef,AccThirdEntityCodeBookRef, Tag From [ATNDBTest].dbo.AccDocumentDetail
Set Identity_Insert [ATNDB].dbo.AccDocumentDetail Off 
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].dbo.AccDocumentAppendix On 
Insert Into [ATNDB].dbo.AccDocumentAppendix (Serial,AccDocumentHeaderRef,DocImg,Tag)
	                                Select Serial,AccDocumentHeaderRef,DocImg,Tag From [ATNDBTest].dbo.AccDocumentAppendix
Set Identity_Insert [ATNDB].dbo.AccDocumentAppendix Off 
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].dbo.UnitWeight On 
Insert Into [ATNDB].dbo.UnitWeight (Serial, Code, FADes, ENDes, RecorderRef, RecordDate, EditorRef, EditDate, OfficeDetailRef, Tag)
                           Select Serial, Code, FADes, ENDes, RecorderRef, RecordDate, EditorRef, EditDate, OfficeDetailRef, Tag From [ATNDBTest].dbo.UnitWeight
Set Identity_Insert [ATNDB].dbo.UnitWeight Off 
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].dbo.PartCluster On 
Insert Into [ATNDB].dbo.PartCluster (Serial, Code, PartClusterRef, FADescription, ENDescription, Comment, RecorderRef, RecordDate, EditorRef, EditDate, OfficeDetailRef, Tag)
                            Select Serial, Code, PartClusterRef, FADescription, ENDescription, Comment, RecorderRef, RecordDate, EditorRef, EditDate, OfficeDetailRef, Tag From [ATNDBTest].dbo.PartCluster
Set Identity_Insert [ATNDB].dbo.PartCluster Off 
----------------------------------------------------------------------------------------------------
Insert Into [ATNDB].dbo.Degree Select * From [ATNDBTest].dbo.Degree
Insert Into [ATNDB].dbo.Storages Select * From [ATNDBTest].dbo.Storages
Insert Into [ATNDB].dbo.Groups Select * From [ATNDBTest].dbo.Groups
Insert Into [ATNDB].dbo.Units Select * From [ATNDBTest].dbo.Units
Insert Into [ATNDB].dbo.Warehouse Select * From [ATNDBTest].dbo.Warehouse
----------------------------------------------------------------------------------------------------
Insert Into [ATNDB].dbo.Part (Serial, Code, Name, ENName, StorageRef, PartClusterRef, GroupRef, UnitRef, SubUnit1Ref, SubUnit1Ratio, SubUnit2Ref, SubUnit2Ratio, SaleVat, SaleToll, BuyVat, BuyToll, UnitWeight, UnitWeightRef, OEM, PartID, Barcode, BarcodeImg, PartImg, AddedTaxInBuy, AddedTaxInSales, AddedTaxOnProfit, Active, RecorderRef, RecordDate, EditorRef, EditDate, PartKindRef, Reserve, Remain, Orders, MaxRemain, MinRemain, ShelfNo, PartBuyPriceKindRef, BuyUnitPrice, BuyUnitPriceInForeignCurrency, SaleDependToBuy, PartProfitPercentKindRef, PartSalePriceScopeRef, ForeignCurrencyForBuy, ForeignCurrencyForSale, Comment, OfficeDetailRef, Tag)
					 Select Serial, Code, Name, ENName, StorageRef, PartClusterRef, GroupRef, UnitRef, SubUnit1Ref, SubUnit1Ratio, SubUnit2Ref, SubUnit2Ratio, SaleVat, SaleToll, BuyVat, BuyToll, UnitWeight, UnitWeightRef, OEM, PartID, Barcode, BarcodeImg, PartImg, AddedTaxInBuy, AddedTaxInSales, AddedTaxOnProfit, Active, RecorderRef, RecordDate, EditorRef, EditDate, PartKindRef, Reserve, Remain, Orders, MaxRemain, MinRemain, ShelfNo, PartBuyPriceKindRef, BuyUnitPrice, BuyUnitPriceInForeignCurrency, SaleDependToBuy, PartProfitPercentKindRef, PartSalePriceScopeRef, ForeignCurrencyForBuy, ForeignCurrencyForSale, Comment, OfficeDetailRef, Tag
					 From [ATNDBTest].dbo.Part
----------------------------------------------------------------------------------------------------
Insert Into [ATNDB].dbo.PartWarehouseBridge Select * From [ATNDBTest].dbo.PartWarehouseBridge
Insert Into [ATNDB].dbo.PartGroupsBridge Select * From [ATNDBTest].dbo.PartGroupsBridge
Insert Into [ATNDB].dbo.PartSalePrice Select * From [ATNDBTest].dbo.PartSalePrice
----------------------------------------------------------------------------------------------------
Insert Into [ATNDB].dbo.PartProductRawMaterialHeader Select * From [ATNDBTest].dbo.PartProductRawMaterialHeader
Insert Into [ATNDB].dbo.PartProductRawMaterialDetail Select * From [ATNDBTest].dbo.PartProductRawMaterialDetail
----------------------------------------------------------------------------------------------------
Insert Into [ATNDB].dbo.GetterOrPayerFactorCategory Select * From [ATNDBTest].dbo.GetterOrPayerFactorCategory
----------------------------------------------------------------------------------------------------
--Set Identity_Insert [ATNDB].dbo.GetterOrPayerFactor On
Insert Into [ATNDB].dbo.GetterOrPayerFactor (Serial, Code, GetterOrPayerFactorTypeRef, GetterOrPayerFactorPatternRef, CityRef, Location, PersonOrCompany, FAFirstName, ENFirstName, FALastName, ENLastName, Branch, KindRef, GetterOrPayerFactorCategoryRef, Active, Manager, DegreeRef, Address, PostCode, Email, Website, RegNo, SSN, EconomicCode, Tel1, Tel2, Fax, Mobile, BankName, OffshootCode, OffshootName, BankAccountNo, IBAN, BankAddress, AccEntityL1CodeBookRef, AccEntityL2CodeBookRef, AccountMaximum, SaleProfitPercent, SaleRebatePercent, RecorderRef, RecordDate, EditorRef, EditDate, Description, OfficeDetailRef, Tag)
                                    Select Serial, Code, GetterOrPayerFactorTypeRef, GetterOrPayerFactorPatternRef, CityRef, Location, PersonOrCompany, FAFirstName, ENFirstName, FALastName, ENLastName, Branch, KindRef, GetterOrPayerFactorCategoryRef, Active, Manager, DegreeRef, Address, PostCode, Email, Website, RegNo, SSN, EconomicCode, Tel1, Tel2, Fax, Mobile, BankName, OffshootCode, OffshootName, BankAccountNo, IBAN, BankAddress, AccEntityL1CodeBookRef, AccEntityL2CodeBookRef, AccountMaximum, SaleProfitPercent, SaleRebatePercent, RecorderRef, RecordDate, EditorRef, EditDate, Description, OfficeDetailRef, Tag
									From [ATNDBTest].dbo.GetterOrPayerFactor
--Set Identity_Insert [ATNDB].dbo.GetterOrPayerFactor Off
----------------------------------------------------------------------------------------------------
Insert Into [ATNDB].dbo.Broker Select * From [ATNDBTest].dbo.Broker
----------------------------------------------------------------------------------------------------
Insert Into [ATNDB].dbo.ReturnReasons Select * From [ATNDBTest].dbo.ReturnReasons
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].dbo.FactorCategory On 
Insert Into [ATNDB].dbo.FactorCategory (Serial,Code,FADes,ENDes,Kind,RecorderRef,RecordDate,EditorRef,EditDate,OfficeDetailRef, Tag)
			                   Select Serial,Code,FADes,ENDes,Kind,RecorderRef,RecordDate,EditorRef,EditDate,OfficeDetailRef, Tag 
							   From [ATNDBTest].dbo.FactorCategory
Set Identity_Insert [ATNDB].dbo.FactorCategory Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].dbo.FactorHeader On 
Insert Into [ATNDB].dbo.FactorHeader (Serial,Code,FactorKindRef,AccDocumentHeaderRefOnVerification,AccDocumentHeaderRefOnUpdating,GetterOrPayerFactorRef,ControlNo,WarehouseRef,BasedDoc,FactorCategoryRef,EffectiveDate,EffectiveTime,RecorderRef,RecordDate,EditorRef,EditDate,EditRowVersion,NumberOfEdits,VerifierRef,VerificationDate,UpdatingUserRef,UpdatingDate,VAT,Toll,Cost2th,Rebate,RebateRound,SumRebateInFactorDetail,BrokerRef,SaleBrokerPercent,SaleBrokerPrice,BrokerPercentTypeRef,TotalPaid,TotalPaidInForeignCurrency, Sum_TotalPrice,Sum_TotalPriceInForeignCurrency,Sum_TotalPriceForTax,Sum_TotalPriceForTaxInForeignCurrency,ForeignCurrencyFactor,ForeignCurrencySymbolRef,PayDate,PayDay,PaymentMethod,BaselessSettlement,WarehouseNotifyDateTime,WarehouseVerificationCode,WarehouseVerificationDate,WarehouseVerificationUserRef,WarehousePrintDateTime,WarehouseExitDateTime,WarehousePrintRowVersion,WarehousePrintedCounter,Mechanize,Description,OfficeDetailRef,OfficePeriodRef,RowVersion, Tag) 
	                           Select Serial,Code,FactorKindRef,AccDocumentHeaderRefOnVerification,AccDocumentHeaderRefOnUpdating,GetterOrPayerFactorRef,ControlNo,WarehouseRef,BasedDoc,FactorCategoryRef,EffectiveDate,EffectiveTime,RecorderRef,RecordDate,EditorRef,EditDate,EditRowVersion,NumberOfEdits,VerifierRef,VerificationDate,UpdatingUserRef,UpdatingDate,VAT,Toll,Cost2th,Rebate,RebateRound,SumRebateInFactorDetail,BrokerRef,SaleBrokerPercent,SaleBrokerPrice,BrokerPercentTypeRef,TotalPaid,TotalPaidInForeignCurrency, Sum_TotalPrice,Sum_TotalPriceInForeignCurrency,Sum_TotalPriceForTax,Sum_TotalPriceForTaxInForeignCurrency,ForeignCurrencyFactor,ForeignCurrencySymbolRef,PayDate,PayDay,PaymentMethod,BaselessSettlement,WarehouseNotifyDateTime,WarehouseVerificationCode,WarehouseVerificationDate,WarehouseVerificationUserRef,WarehousePrintDateTime,WarehouseExitDateTime,WarehousePrintRowVersion,WarehousePrintedCounter,Mechanize,Description,OfficeDetailRef,OfficePeriodRef,RowVersion, Tag 
				               From [ATNDBTest].dbo.FactorHeader 
Set Identity_Insert [ATNDB].dbo.FactorHeader Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].dbo.FactorHistory On
Insert Into [ATNDB].dbo.FactorHistory (Serial, FactorHeaderRef, Timestamp, HeaderHistory, DetailHistory)
							  Select Serial, FactorHeaderRef, Timestamp, HeaderHistory, DetailHistory
							  From [ATNDBTest].dbo.FactorHistory
Set Identity_Insert [ATNDB].dbo.FactorHistory Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].dbo.FactorTaxpayer On
Insert Into [ATNDB].dbo.FactorTaxpayer (Serial, FactorHeaderRef, FactorTaxStatusRef, FactorID, TaxUniqueId, TaxFactorKindRef, TaxReferenceId, TaxSenderRef, TaxSendDate, TaxSendError, TaxSendWarning, TaxSendDateRowVersion, LastState, OfficeDetailRef, OfficePeriodRef, Tag)
							   Select Serial, FactorHeaderRef, FactorTaxStatusRef, FactorID, TaxUniqueId, TaxFactorKindRef, TaxReferenceId, TaxSenderRef, TaxSendDate, TaxSendError, TaxSendWarning, TaxSendDateRowVersion, LastState, OfficeDetailRef, OfficePeriodRef, Tag
							   From [ATNDBTest].dbo.FactorTaxpayer
Set Identity_Insert [ATNDB].dbo.FactorTaxpayer Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].dbo.FactorExtendedOption On 
Insert Into [ATNDB].dbo.FactorExtendedOption (Serial,FactorHeaderRef,Expression1,Expression2,Expression3,Expression4,Expression5) 
	                                 Select Serial,FactorHeaderRef,Expression1,Expression2,Expression3,Expression4,Expression5 
						             From [ATNDBTest].dbo.FactorExtendedOption 
Set Identity_Insert [ATNDB].dbo.FactorExtendedOption Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].dbo.FactorDetail On 
Insert Into [ATNDB].dbo.FactorDetail (Serial,FactorHeaderRef,PartRef,Quantity,SubUnit1Qty,SubUnit2Qty,UnitPrice,ApprovedUnitPrice,TotalPrice,TotalPrice2,TotalPrice3,BuyUnitPriceInPartTable,UnitPriceInForeignCurrency,ApprovedUnitPriceInForeignCurrency,TotalPriceInForeignCurrency,BuyUnitPriceInForeignCurrencyInPartTable,RebatePricePerUnit,RebatePrice,RebatePercent, RebateForEachRow, VATForEachRow, TollForEachRow, Description, Tag) 
	                         Select Serial,FactorHeaderRef,PartRef,Quantity,SubUnit1Qty,SubUnit2Qty,UnitPrice,ApprovedUnitPrice,TotalPrice,TotalPrice2,TotalPrice3,BuyUnitPriceInPartTable,UnitPriceInForeignCurrency,ApprovedUnitPriceInForeignCurrency,TotalPriceInForeignCurrency,BuyUnitPriceInForeignCurrencyInPartTable,RebatePricePerUnit,RebatePrice,RebatePercent, RebateForEachRow, VATForEachRow, TollForEachRow, Description, Tag 
					      From [ATNDBTest].dbo.FactorDetail 
Set Identity_Insert [ATNDB].dbo.FactorDetail Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].dbo.FactorAccCode On 
Insert Into [ATNDB].dbo.FactorAccCode (Serial,FactorHeaderRef,FactorDetailRef,SystemAccCodeDefaultBaseRef,DebitAccGroupCodeBookRef,DebitAccGeneralCodeBookRef,DebitAccAdjutantL1CodeBookRef,DebitAccEntityL1CodeBookRef,DebitAccEntityL2CodeBookRef,CreditAccGroupCodeBookRef,CreditAccGeneralCodeBookRef,CreditAccAdjutantL1CodeBookRef,CreditAccEntityL1CodeBookRef,CreditAccEntityL2CodeBookRef) 
	                          Select Serial,FactorHeaderRef,FactorDetailRef,SystemAccCodeDefaultBaseRef,DebitAccGroupCodeBookRef,DebitAccGeneralCodeBookRef,DebitAccAdjutantL1CodeBookRef,DebitAccEntityL1CodeBookRef,DebitAccEntityL2CodeBookRef,CreditAccGroupCodeBookRef,CreditAccGeneralCodeBookRef,CreditAccAdjutantL1CodeBookRef,CreditAccEntityL1CodeBookRef,CreditAccEntityL2CodeBookRef 
						      From [ATNDBTest].dbo.FactorAccCode 
Set Identity_Insert [ATNDB].dbo.FactorAccCode Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].dbo.WarehouseNoteTitle On 
Insert Into [ATNDB].dbo.WarehouseNoteTitle (Serial, Code, FADescription, ENDescription, DefaultValue, RecorderRef, RecordDate, EditorRef, EditDate, OfficeDetailRef, Tag)
	                          Select Serial, Code, FADescription, ENDescription, DefaultValue, RecorderRef, RecordDate, EditorRef, EditDate, OfficeDetailRef, Tag
						      From [ATNDBTest].dbo.WarehouseNoteTitle 
Set Identity_Insert [ATNDB].dbo.WarehouseNoteTitle Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].dbo.WarehouseNoteTitlePerDoc On 
Insert Into [ATNDB].dbo.WarehouseNoteTitlePerDoc (Serial, WarehouseNoteTitleRef, FactorHeaderRef, Value, Tag) 
	                          Select Serial, WarehouseNoteTitleRef, FactorHeaderRef, Value, Tag
						      From [ATNDBTest].dbo.WarehouseNoteTitlePerDoc 
Set Identity_Insert [ATNDB].dbo.WarehouseNoteTitlePerDoc Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].dbo.FactorDetailAndItselfBridge On 
Insert Into [ATNDB].dbo.FactorDetailAndItselfBridge (Serial,MasterFactorDetailRef,DetailFactorDetailRef,Quantity,Option1) 
	                                        Select Serial,MasterFactorDetailRef,DetailFactorDetailRef,Quantity,Option1 
						                    From [ATNDBTest].dbo.FactorDetailAndItselfBridge 
Set Identity_Insert [ATNDB].dbo.FactorDetailAndItselfBridge Off
----------------------------------------------------------------------------------------------------
Insert Into [ATNDB].dbo.FactorUpdate Select * From [ATNDBTest].dbo.FactorUpdate
Insert Into [ATNDB].dbo.FactorProductAndRawMaterialBridge Select * From [ATNDBTest].dbo.FactorProductAndRawMaterialBridge
Insert Into [ATNDB].dbo.OfficePeriodFactorHeaderBridge Select * From [ATNDBTest].dbo.OfficePeriodFactorHeaderBridge
----------------------------------------------------------------------------------------------------
Insert Into [ATNDB].dbo.GritProduct Select * From [ATNDBTest].dbo.GritProduct
Insert Into [ATNDB].dbo.GritSalePrice Select * From [ATNDBTest].dbo.GritSalePrice
----------------------------------------------------------------------------------------------------
--Set Identity_Insert [ATNDB].dbo.GritFactor On
Insert Into [ATNDB].dbo.GritFactor (Serial, Code, AccDocumentHeaderRefOnVerification, AccDocumentHeaderRefOnUpdating, GetterOrPayerFactorRef, GritFactorKindRef, FactorHeaderRef, ControlNo, EffectiveDate, EffectiveTime, GritCashAndCreditRef, LicensePlate, EmptyWeight, GrossWeight, GritProductRef, Quantity, UnitPrice, ApprovedUnitPrice, TotalPrice, BuyUnitPriceInProductTable, VAT, Toll, Cost, Rebate, TotalPaid, PayDate, RecorderRef, RecordDate, EditorRef, EditDate, NumberOfEdits, FactorHistory, VerifierRef, VerificationDate, UpdatingUserRef, UpdatingDate, Description, OfficeDetailRef, OfficePeriodRef, RowVersion, Tag)
						   Select Serial, Code, AccDocumentHeaderRefOnVerification, AccDocumentHeaderRefOnUpdating, GetterOrPayerFactorRef, GritFactorKindRef, FactorHeaderRef, ControlNo, EffectiveDate, EffectiveTime, GritCashAndCreditRef, LicensePlate, EmptyWeight, GrossWeight, GritProductRef, Quantity, UnitPrice, ApprovedUnitPrice, TotalPrice, BuyUnitPriceInProductTable, VAT, Toll, Cost, Rebate, TotalPaid, PayDate, RecorderRef, RecordDate, EditorRef, EditDate, NumberOfEdits, FactorHistory, VerifierRef, VerificationDate, UpdatingUserRef, UpdatingDate, Description, OfficeDetailRef, OfficePeriodRef, RowVersion, Tag
						   From [ATNDBTest].dbo.GritFactor																																																																																																																												 
--Set Identity_Insert [ATNDB].dbo.GritFactor Off
----------------------------------------------------------------------------------------------------
Insert Into [ATNDB].dbo.GritFactorAccCode Select * From [ATNDBTest].dbo.GritFactorAccCode
----------------------------------------------------------------------------------------------------
Insert Into [ATNDB].dbo.StorageCountHeader Select * From [ATNDBTest].dbo.StorageCountHeader
Insert Into [ATNDB].dbo.StorageCountDetail Select * From [ATNDBTest].dbo.StorageCountDetail 
----------------------------------------------------------------------------------------------------
Insert Into [ATNDB].dbo.SystemAccCodeDefaultPerOffice Select * From [ATNDBTest].dbo.SystemAccCodeDefaultPerOffice
Insert Into [ATNDB].dbo.SystemAccCodeDefaultPerPart Select * From [ATNDBTest].dbo.SystemAccCodeDefaultPerPart
----------------------------------------------------------------------------------------------------
Insert Into [ATNDB].dbo.Bank Select * From [ATNDBTest].dbo.Bank
Insert Into [ATNDB].dbo.BankAccount Select * From [ATNDBTest].dbo.BankAccount
----------------------------------------------------------------------------------------------------
Insert Into [ATNDB].dbo.CheckBookHeader Select * From [ATNDBTest].dbo.CheckBookHeader
Insert Into [ATNDB].dbo.CheckBookDetail Select * From [ATNDBTest].dbo.CheckBookDetail
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].dbo.CheckType On 
Insert Into [ATNDB].dbo.CheckType (Serial, Code, FADes, ENDes, RecorderRef, RecordDate, EditorRef, EditDate, OfficeDetailRef, Tag) 
	                        Select Serial, Code, FADes, ENDes, RecorderRef, RecordDate, EditorRef, EditDate, OfficeDetailRef, Tag 
						    From [ATNDBTest].dbo.CheckType 
Set Identity_Insert [ATNDB].dbo.CheckType Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].dbo.CheckStakeholder On
Insert Into [ATNDB].dbo.CheckStakeholder (Serial, Code, FADes, ENDes, SSN, RecorderRef, RecordDate, EditorRef, EditDate, OfficeDetailRef)
	                               Select Serial, Code, FADes, ENDes, SSN, RecorderRef, RecordDate, EditorRef, EditDate, OfficeDetailRef
					               From [ATNDBTest].dbo.CheckStakeholder
Set Identity_Insert [ATNDB].dbo.CheckStakeholder Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].dbo.CheckGetPayHeader On 
Insert Into [ATNDB].dbo.CheckGetPayHeader (Serial,code,CheckPositionRef,GetterOrPayerRef,AccDocumentHeaderRef,Detail,EffectiveDate,RecorderRef,RecordDate,EditorRef,EditDate,VerifierRef,VerificationDate,Totality,Description,OfficeDetailRef,OfficePeriodRef,RowVersion) 
	                                Select Serial,code,CheckPositionRef,GetterOrPayerRef,AccDocumentHeaderRef,Detail,EffectiveDate,RecorderRef,RecordDate,EditorRef,EditDate,VerifierRef,VerificationDate,Totality,Description,OfficeDetailRef,OfficePeriodRef,RowVersion 
						            From [ATNDBTest].dbo.CheckGetPayHeader 
Set Identity_Insert [ATNDB].dbo.CheckGetPayHeader Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].dbo.CheckGetPayDetail On 
Insert Into [ATNDB].dbo.CheckGetPayDetail (Serial, CheckBookDetailRef, CheckPositionRef, CheckNo, IssueDate, MatureDate, Amount, BankRef, CheckTypeRef, CheckStakeholderRef, CheckOwnerName, SayadCode, BranchCode, BranchName, AccountCode, Detail, Lock) 
	                                Select Serial, CheckBookDetailRef, CheckPositionRef, CheckNo, IssueDate, MatureDate, Amount, BankRef, CheckTypeRef, CheckStakeholderRef, CheckOwnerName, SayadCode, BranchCode, BranchName, AccountCode, Detail, Lock 
						            From [ATNDBTest].dbo.CheckGetPayDetail 
Set Identity_Insert [ATNDB].dbo.CheckGetPayDetail Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].dbo.CheckGetPayBridge On 
Insert Into [ATNDB].dbo.CheckGetPayBridge (Serial,CheckGetPayHeaderRef,CheckGetPayDetailRef,DebitAccGroupCodeBookRef,DebitAccGeneralCodeBookRef,DebitAccAdjutantL1CodeBookRef,DebitAccEntityL1CodeBookRef,DebitAccEntityL2CodeBookRef,CreditAccGroupCodeBookRef,CreditAccGeneralCodeBookRef,CreditAccAdjutantL1CodeBookRef,CreditAccEntityL1CodeBookRef,CreditAccEntityL2CodeBookRef) 
	                                Select Serial,CheckGetPayHeaderRef,CheckGetPayDetailRef,DebitAccGroupCodeBookRef,DebitAccGeneralCodeBookRef,DebitAccAdjutantL1CodeBookRef,DebitAccEntityL1CodeBookRef,DebitAccEntityL2CodeBookRef,CreditAccGroupCodeBookRef,CreditAccGeneralCodeBookRef,CreditAccAdjutantL1CodeBookRef,CreditAccEntityL1CodeBookRef,CreditAccEntityL2CodeBookRef 
						            From [ATNDBTest].dbo.CheckGetPayBridge 
Set Identity_Insert [ATNDB].dbo.CheckGetPayBridge Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].dbo.CashGetPay On 
Insert Into [ATNDB].dbo.CashGetPay (Serial,Code,AccDocumentHeaderRef,GetterOrPayerRef,CashGetPayKindRef,Detail,EffectiveDate,RecorderRef,RecordDate,EditorRef,EditDate,VerifierRef,VerificationDate,Amount,AmountInForeignCurrency,ForeignCurrencySymbolRef,BankAccountRef,ReceiptNo,Description,DebitAccGroupCodeBookRef,DebitAccGeneralCodeBookRef,DebitAccAdjutantL1CodeBookRef,DebitAccEntityL1CodeBookRef,DebitAccEntityL2CodeBookRef,CreditAccGroupCodeBookRef,CreditAccGeneralCodeBookRef,CreditAccAdjutantL1CodeBookRef,CreditAccEntityL1CodeBookRef,CreditAccEntityL2CodeBookRef,OfficeDetailRef,OfficePeriodRef,RowVersion) 
	                         Select Serial,Code,AccDocumentHeaderRef,GetterOrPayerRef,CashGetPayKindRef,Detail,EffectiveDate,RecorderRef,RecordDate,EditorRef,EditDate,VerifierRef,VerificationDate,Amount,AmountInForeignCurrency,ForeignCurrencySymbolRef,BankAccountRef,ReceiptNo,Description,DebitAccGroupCodeBookRef,DebitAccGeneralCodeBookRef,DebitAccAdjutantL1CodeBookRef,DebitAccEntityL1CodeBookRef,DebitAccEntityL2CodeBookRef,CreditAccGroupCodeBookRef,CreditAccGeneralCodeBookRef,CreditAccAdjutantL1CodeBookRef,CreditAccEntityL1CodeBookRef,CreditAccEntityL2CodeBookRef,OfficeDetailRef,OfficePeriodRef,RowVersion 
						     From [ATNDBTest].dbo.CashGetPay 
Set Identity_Insert [ATNDB].dbo.CashGetPay Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].dbo.FactorCashSettlementCheckBridge On 
Insert Into [ATNDB].dbo.FactorCashSettlementCheckBridge (Serial,FactorHeaderRef,GritFactorRef,CashGetPayRef,CashGetPayAmount,SettlementGetPayRef,SettlementGetPayAmount,SettlementWithAccountGetPayRef,SettlementWithAccountGetPayAmount,CheckGetPayHeaderRef,CheckGetPayAmount) 
	                                              Select Serial,FactorHeaderRef,GritFactorRef,CashGetPayRef,CashGetPayAmount,SettlementGetPayRef,SettlementGetPayAmount,SettlementWithAccountGetPayRef,SettlementWithAccountGetPayAmount,CheckGetPayHeaderRef,CheckGetPayAmount 
						                          From [ATNDBTest].dbo.FactorCashSettlementCheckBridge 
Set Identity_Insert [ATNDB].dbo.FactorCashSettlementCheckBridge Off
----------------------------------------------------------------------------------------------------
Insert Into [ATNDB].dbo.CostBase Select * From [ATNDBTest].dbo.CostBase
Insert Into [ATNDB].dbo.CostCash Select * From [ATNDBTest].dbo.CostCash
Insert Into [ATNDB].dbo.CostFunds Select * From [ATNDBTest].dbo.CostFunds
Insert Into [ATNDB].dbo.CostCredit Select * From [ATNDBTest].dbo.CostCredit
Insert Into [ATNDB].dbo.CostCenter Select * From [ATNDBTest].dbo.CostCenter
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].dbo.CostHeader On 
Insert Into [ATNDB].dbo.CostHeader (Serial,Code,AccDocumentHeaderRef,FADes,ENDes,EffectiveDate,TotalAmount,TotalAmountInForeignCurrency,ForeignCurrencySymbolRef,RecorderRef,RecordDate,EditorRef,EditDate,VerifierRef,VerificationDate,Comment,OfficeDetailRef,OfficePeriodRef,RowVersion) 
	                       Select Serial,Code,AccDocumentHeaderRef,FADes,ENDes,EffectiveDate,TotalAmount,TotalAmountInForeignCurrency,ForeignCurrencySymbolRef,RecorderRef,RecordDate,EditorRef,EditDate,VerifierRef,VerificationDate,Comment,OfficeDetailRef,OfficePeriodRef,RowVersion 
						   From [ATNDBTest].dbo.CostHeader 
Set Identity_Insert [ATNDB].dbo.CostHeader Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].dbo.CostDetail On 
Insert Into [ATNDB].dbo.CostDetail (Serial,CostHeaderRef,CostBaseRef,CostCenterRef,CostPayKindRef,CostPayRef,Amount,AmountInForeignCurrency,ExtendedOption,DebitAccGroupCodeBookRef,DebitAccGeneralCodeBookRef,DebitAccAdjutantL1CodeBookRef,DebitAccEntityL1CodeBookRef,DebitAccEntityL2CodeBookRef,CreditAccGroupCodeBookRef,CreditAccGeneralCodeBookRef,CreditAccAdjutantL1CodeBookRef,CreditAccEntityL1CodeBookRef,CreditAccEntityL2CodeBookRef) 
	                       Select Serial,CostHeaderRef,CostBaseRef,CostCenterRef,CostPayKindRef,CostPayRef,Amount,AmountInForeignCurrency,ExtendedOption,DebitAccGroupCodeBookRef,DebitAccGeneralCodeBookRef,DebitAccAdjutantL1CodeBookRef,DebitAccEntityL1CodeBookRef,DebitAccEntityL2CodeBookRef,CreditAccGroupCodeBookRef,CreditAccGeneralCodeBookRef,CreditAccAdjutantL1CodeBookRef,CreditAccEntityL1CodeBookRef,CreditAccEntityL2CodeBookRef 
						   From [ATNDBTest].dbo.CostDetail 
Set Identity_Insert [ATNDB].dbo.CostDetail Off
----------------------------------------------------------------------------------------------------
----------------------------------------- حـقوق و دستمزد  -----------------------------------------
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].PAY.SSIOrg On
Insert Into [ATNDB].PAY.SSIOrg (Serial, Code, FADes, ENDes, WorkhouseCode, WorkhouseName, WorkhouseAddress, Employer, PaymanCode, TaxFreePersonsCount, InsuranceRate, CommissionRate, HardAndHarmfulJobRate, AccEntityL1CodeBookRef, AccEntityL2CodeBookRef, RecorderRef, RecordDate, EditorRef, EditDate, Comment, OfficeDetailRef)
	                     Select Serial, Code, FADes, ENDes, WorkhouseCode, WorkhouseName, WorkhouseAddress, Employer, PaymanCode, TaxFreePersonsCount, InsuranceRate, CommissionRate, HardAndHarmfulJobRate, AccEntityL1CodeBookRef, AccEntityL2CodeBookRef, RecorderRef, RecordDate, EditorRef, EditDate, Comment, OfficeDetailRef
					     From [ATNDBTest].PAY.SSIOrg
Set Identity_Insert [ATNDB].PAY.SSIOrg Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].PAY.SPIOrg On
Insert Into [ATNDB].PAY.SPIOrg (Serial, Code, FADes, ENDes, FileNumber, AccEntityL1CodeBookRef, AccEntityL2CodeBookRef, RecorderRef, RecordDate, EditorRef, EditDate, Comment, OfficeDetailRef)
	                   Select Serial, Code, FADes, ENDes, FileNumber, AccEntityL1CodeBookRef, AccEntityL2CodeBookRef, RecorderRef, RecordDate, EditorRef, EditDate, Comment, OfficeDetailRef
					   From [ATNDBTest].PAY.SPIOrg
Set Identity_Insert [ATNDB].PAY.SPIOrg Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].PAY.EmployeeTaxOrg On
Insert Into [ATNDB].PAY.EmployeeTaxOrg (Serial, Code, FADes, ENDes, FileNumber, EmployeeTaxAdjustmentRef, AccEntityL1CodeBookRef, AccEntityL2CodeBookRef, RecorderRef, RecordDate, EditorRef, EditDate, Comment, OfficeDetailRef)
	                           Select Serial, Code, FADes, ENDes, FileNumber, EmployeeTaxAdjustmentRef, AccEntityL1CodeBookRef, AccEntityL2CodeBookRef, RecorderRef, RecordDate, EditorRef, EditDate, Comment, OfficeDetailRef
					           From [ATNDBTest].PAY.EmployeeTaxOrg
Set Identity_Insert [ATNDB].PAY.EmployeeTaxOrg Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].PAY.JobCategory On
Insert Into [ATNDB].PAY.JobCategory (Serial, Code, FADes, ENDes, RecorderRef, RecordDate, EditorRef, EditDate, OfficeDetailRef)
	                        Select Serial, Code, FADes, ENDes, RecorderRef, RecordDate, EditorRef, EditDate, OfficeDetailRef
					        From [ATNDBTest].PAY.JobCategory
Set Identity_Insert [ATNDB].PAY.JobCategory Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].PAY.Job On
Insert Into [ATNDB].PAY.Job (Serial, Code, FADes, ENDes, JobCategoryRef, SSI_JobCode, RecorderRef, RecordDate, EditorRef, EditDate, Comment, OfficeDetailRef)
	                Select Serial, Code, FADes, ENDes, JobCategoryRef, SSI_JobCode, RecorderRef, RecordDate, EditorRef, EditDate, Comment, OfficeDetailRef
			        From [ATNDBTest].PAY.Job
Set Identity_Insert [ATNDB].PAY.Job Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].PAY.JobLocation On
Insert Into [ATNDB].PAY.JobLocation (Serial, Code, FADes, ENDes, RecorderRef, RecordDate, EditorRef, EditDate, OfficeDetailRef)
	                        Select Serial, Code, FADes, ENDes, RecorderRef, RecordDate, EditorRef, EditDate, OfficeDetailRef
					        From [ATNDBTest].PAY.JobLocation
Set Identity_Insert [ATNDB].PAY.JobLocation Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].PAY.TaxGroup On
Insert Into [ATNDB].PAY.TaxGroup (Serial, Code, FADes, ENDes, RecorderRef, RecordDate, EditorRef, EditDate, OfficeDetailRef)
	                     Select Serial, Code, FADes, ENDes, RecorderRef, RecordDate, EditorRef, EditDate, OfficeDetailRef
					     From [ATNDBTest].PAY.TaxGroup
Set Identity_Insert [ATNDB].PAY.TaxGroup Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].PAY.TaxTableHeader On
Insert Into [ATNDB].PAY.TaxTableHeader (Serial, Code, FADes, ENDes, TaxGroupRef, Comment, RecorderRef, RecordDate, EditorRef, EditDate, OfficePeriodRef, OfficeDetailRef)
	                           Select Serial, Code, FADes, ENDes, TaxGroupRef, Comment, RecorderRef, RecordDate, EditorRef, EditDate, OfficePeriodRef, OfficeDetailRef
					           From [ATNDBTest].PAY.TaxTableHeader
Set Identity_Insert [ATNDB].PAY.TaxTableHeader Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].PAY.TaxTableDetail On
Insert Into [ATNDB].PAY.TaxTableDetail (Serial, TaxTableHeaderRef, FromAmount, ToAmount, Rate, PartialAmount, CurrentRowTotalAmount)
	                           Select Serial, TaxTableHeaderRef, FromAmount, ToAmount, Rate, PartialAmount, CurrentRowTotalAmount
					           From [ATNDBTest].PAY.TaxTableDetail
Set Identity_Insert [ATNDB].PAY.TaxTableDetail Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].PAY.Factor On
Insert Into [ATNDB].PAY.Factor (Serial, Code, Symbol, FADes, ENDes, FactorGroupRef, FactorCategoryRef, FactorClassRef, Periority, Formula, IncludedSSI, IncludedTax, TaxMethod, TaxPercent, AccAdjutantL1CodeBookRef, Active, RecorderRef, RecordDate, EditorRef, EditDate, Comment, OfficeDetailRef)
	                     Select Serial, Code, Symbol, FADes, ENDes, FactorGroupRef, FactorCategoryRef, FactorClassRef, Periority, Formula, IncludedSSI, IncludedTax, TaxMethod, TaxPercent, AccAdjutantL1CodeBookRef, Active, RecorderRef, RecordDate, EditorRef, EditDate, Comment, OfficeDetailRef
					     From [ATNDBTest].PAY.Factor
Set Identity_Insert [ATNDB].PAY.Factor Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].PAY.LoanType On
Insert Into [ATNDB].PAY.LoanType (Serial, Code, FADes, ENDes, Active, FactorRef, AccAdjutantL1CodeBookRef, RecorderRef, RecordDate, EditorRef, EditDate, Comment, OfficeDetailRef)
	                     Select Serial, Code, FADes, ENDes, Active, FactorRef, AccAdjutantL1CodeBookRef, RecorderRef, RecordDate, EditorRef, EditDate, Comment, OfficeDetailRef
					     From [ATNDBTest].PAY.LoanType
Set Identity_Insert [ATNDB].PAY.LoanType Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].PAY.Employee On
Insert Into [ATNDB].PAY.Employee (Serial, FAFirstName, ENFirstName, FALastName, ENLastName, FAFatherName, ENFatherName, SSN, BirthCertificateNo, BirthCertificateSerial, BirthCertificateRegPlace, BirthDate, BirthPlace, SexRef, Nationality, Religion, ReligionSect, MilitaryRef, EmployeeStatusRef, MarriageRef, MarriageDate, ChildNumber, Sponsorship, Disability, SpecificDisease, Code, SSINumber, SPINumber, SSIRecordInDays, Picture, AccEntityL1CodeBookRef, AccEntityL2CodeBookRef, Active, Comment, RecorderRef, RecordDate, EditorRef, EditDate, OfficeDetailRef)
	                     Select Serial, FAFirstName, ENFirstName, FALastName, ENLastName, FAFatherName, ENFatherName, SSN, BirthCertificateNo, BirthCertificateSerial, BirthCertificateRegPlace, BirthDate, BirthPlace, SexRef, Nationality, Religion, ReligionSect, MilitaryRef, EmployeeStatusRef, MarriageRef, MarriageDate, ChildNumber, Sponsorship, Disability, SpecificDisease, Code, SSINumber, SPINumber, SSIRecordInDays, Picture, AccEntityL1CodeBookRef, AccEntityL2CodeBookRef, Active, Comment, RecorderRef, RecordDate, EditorRef, EditDate, OfficeDetailRef
					     From [ATNDBTest].PAY.Employee
Set Identity_Insert [ATNDB].PAY.Employee Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].PAY.EmployeeWorkExperience On
Insert Into [ATNDB].PAY.EmployeeWorkExperience (Serial, EmployeeRef, Department, Post, StartDate, EndDate, Duration, LatestSalary, ReasonForLeavingWork, Comment)
	                                   Select Serial, EmployeeRef, Department, Post, StartDate, EndDate, Duration, LatestSalary, ReasonForLeavingWork, Comment
					                   From [ATNDBTest].PAY.EmployeeWorkExperience
Set Identity_Insert [ATNDB].PAY.EmployeeWorkExperience Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].PAY.EmployeeRelatedPeople On
Insert Into [ATNDB].PAY.EmployeeRelatedPeople (Serial, EmployeeRef, Name, Relation, ContactTitleRef, Data, Comment)
	                                  Select Serial, EmployeeRef, Name, Relation, ContactTitleRef, Data, Comment
					                  From [ATNDBTest].PAY.EmployeeRelatedPeople
Set Identity_Insert [ATNDB].PAY.EmployeeRelatedPeople Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].PAY.EmployeeCourse On
Insert Into [ATNDB].PAY.EmployeeCourse (Serial, EmployeeRef, UniversityName, CourseDescription, CourseStartDate, CourseEndDate, CourseDuration, CourseCertificationRef, CourseScore, Comment)
	                           Select Serial, EmployeeRef, UniversityName, CourseDescription, CourseStartDate, CourseEndDate, CourseDuration, CourseCertificationRef, CourseScore, Comment
					            From [ATNDBTest].PAY.EmployeeCourse
Set Identity_Insert [ATNDB].PAY.EmployeeCourse Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].PAY.EmployeeCommunicationMethod On
Insert Into [ATNDB].PAY.EmployeeCommunicationMethod (Serial, EmployeeRef, ContactTitleRef, Data)
	                                        Select Serial, EmployeeRef, ContactTitleRef, Data
					                        From [ATNDBTest].PAY.EmployeeCommunicationMethod
Set Identity_Insert [ATNDB].PAY.EmployeeCommunicationMethod Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].PAY.EmployeeBank On
Insert Into [ATNDB].PAY.EmployeeBank (Serial, EmployeeRef, BankName, OffshootCode, OffshootName, BankAccountNo, BankCardNo, IBAN)
	                         Select Serial, EmployeeRef, BankName, OffshootCode, OffshootName, BankAccountNo, BankCardNo, IBAN
					         From [ATNDBTest].PAY.EmployeeBank
Set Identity_Insert [ATNDB].PAY.EmployeeBank Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].PAY.Contract On
Insert Into [ATNDB].PAY.Contract (Serial, ContractTypeRef, ContractStartDate, ContractEndDate, EmployeeRef, ContractNumber, Comment, EmploymentTypeRef, EmploymentStartDate, EmploymentEndDate, JobRef, JobLocationRef, CostCenterRef, TaxGroupRef, EmployeeTaxOrgRef, TaxFreeHomeLoan, IncludedSSI, SSIOrgRef, HardAndHarmfulJob, UnemploymentInsuranceExemption, EmployerInsuranceContribution, IncludedSPI, SPIOrgRef, ContractLetter, ContractLetterPrintDate, AppointmentLetter, AppointmentLetterPrintDate, RecorderRef, RecordDate, EditorRef, EditDate, OfficeDetailRef)
						 Select Serial, ContractTypeRef, ContractStartDate, ContractEndDate, EmployeeRef, ContractNumber, Comment, EmploymentTypeRef, EmploymentStartDate, EmploymentEndDate, JobRef, JobLocationRef, CostCenterRef, TaxGroupRef, EmployeeTaxOrgRef, TaxFreeHomeLoan, IncludedSSI, SSIOrgRef, HardAndHarmfulJob, UnemploymentInsuranceExemption, EmployerInsuranceContribution, IncludedSPI, SPIOrgRef, ContractLetter, ContractLetterPrintDate, AppointmentLetter, AppointmentLetterPrintDate, RecorderRef, RecordDate, EditorRef, EditDate, OfficeDetailRef
						 From [ATNDBTest].PAY.Contract
Set Identity_Insert [ATNDB].PAY.Contract Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].PAY.ContractFactor On
Insert Into [ATNDB].PAY.ContractFactor (Serial, ContractRef, FactorRef, Amount)
	                           Select Serial, ContractRef, FactorRef, Amount
					           From [ATNDBTest].PAY.ContractFactor
Set Identity_Insert [ATNDB].PAY.ContractFactor Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].PAY.MonthlyFactorPerEmployee On
Insert Into [ATNDB].PAY.MonthlyFactorPerEmployee (Serial, Category, EmployeeRef, FactorRef, Value, MonthIndexRef, OfficePeriodRef, OfficeDetailRef)
	                                     Select Serial, Category, EmployeeRef, FactorRef, Value, MonthIndexRef, OfficePeriodRef, OfficeDetailRef
					                     From [ATNDBTest].PAY.MonthlyFactorPerEmployee
Set Identity_Insert [ATNDB].PAY.MonthlyFactorPerEmployee Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].PAY.PaymentComputingHeader On
Insert Into [ATNDB].PAY.PaymentComputingHeader (Serial, Code, PaymentComputingKindRef, AccDocumentHeaderRef, Year, MonthIndexRef, DaysOfMonth, EffectiveDate, NumberOfEmployee, Description, RecorderRef, RecordDate, EditorRef, EditDate, VerifierRef, VerificationDate, SettlementAccDocumentHeaderRef, SettlementRecorderRef, SettlementDate, OfficeDetailRef, OfficePeriodRef, RowVersion)
	                                   Select Serial, Code, PaymentComputingKindRef, AccDocumentHeaderRef, Year, MonthIndexRef, DaysOfMonth, EffectiveDate, NumberOfEmployee, Description, RecorderRef, RecordDate, EditorRef, EditDate, VerifierRef, VerificationDate, SettlementAccDocumentHeaderRef, SettlementRecorderRef, SettlementDate, OfficeDetailRef, OfficePeriodRef, RowVersion
					                   From [ATNDBTest].PAY.PaymentComputingHeader
Set Identity_Insert [ATNDB].PAY.PaymentComputingHeader Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].PAY.PaymentComputingDetail On
Insert Into [ATNDB].PAY.PaymentComputingDetail (Serial, PaymentComputingHeaderRef, ComputingCode, ComputingName, ContractRef, EmployeeRef, Periority, FactorRef, FADes, ENDes, DebitAccAdjutantL1CodeBookRef, DebitAccEntityL1CodeBookRef, DebitAccEntityL2CodeBookRef, CreditAccAdjutantL1CodeBookRef, CreditAccEntityL1CodeBookRef, CreditAccEntityL2CodeBookRef, Amount)
	                                   Select Serial, PaymentComputingHeaderRef, ComputingCode, ComputingName, ContractRef, EmployeeRef, Periority, FactorRef, FADes, ENDes, DebitAccAdjutantL1CodeBookRef, DebitAccEntityL1CodeBookRef, DebitAccEntityL2CodeBookRef, CreditAccAdjutantL1CodeBookRef, CreditAccEntityL1CodeBookRef, CreditAccEntityL2CodeBookRef, Amount
					                   From [ATNDBTest].PAY.PaymentComputingDetail
Set Identity_Insert [ATNDB].PAY.PaymentComputingDetail Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].PAY.LoanPaybackPlanHeader On
Insert Into [ATNDB].PAY.LoanPaybackPlanHeader (Serial, Code, LoanTypeRef, EmployeeRef, AccDocumentHeaderRef, EffectiveDate, InstallmentStartDate, InstallmentEndDate, InstallmentPeriodDuration, LoanDurationInMonth, LoanDurationInDay, LoanAmount, WagePercent, WageAmount, InterestPercent, InterestAmount, FineExemptDuration, FinePercent, FineAmount, TotalAmount, PaidAmount, RemainAmount, TotalInstallment, PaidInstallment, RemainInstallment, DelayedInstallment, InstallmentRoundDigit, InstallmentRound_FirstOrLast, Comment, RecorderRef, RecordDate, EditorRef, EditDate, VerifierRef, VerificationDate, OfficePeriodRef, OfficeDetailRef, RowVersion)
									  Select Serial, Code, LoanTypeRef, EmployeeRef, AccDocumentHeaderRef, EffectiveDate, InstallmentStartDate, InstallmentEndDate, InstallmentPeriodDuration, LoanDurationInMonth, LoanDurationInDay, LoanAmount, WagePercent, WageAmount, InterestPercent, InterestAmount, FineExemptDuration, FinePercent, FineAmount, TotalAmount, PaidAmount, RemainAmount, TotalInstallment, PaidInstallment, RemainInstallment, DelayedInstallment, InstallmentRoundDigit, InstallmentRound_FirstOrLast, Comment, RecorderRef, RecordDate, EditorRef, EditDate, VerifierRef, VerificationDate, OfficePeriodRef, OfficeDetailRef, RowVersion
									  From [ATNDBTest].PAY.LoanPaybackPlanHeader
Set Identity_Insert [ATNDB].PAY.LoanPaybackPlanHeader Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].PAY.LoanPaybackPlanDetail On
Insert Into [ATNDB].PAY.LoanPaybackPlanDetail (Serial, LoanPaybackPlanHeaderRef, MatureDate, InstallmentAmount, WageAmount, InterestAmount, FineAmount, TotalAmount, Description)
									  Select Serial, LoanPaybackPlanHeaderRef, MatureDate, InstallmentAmount, WageAmount, InterestAmount, FineAmount, TotalAmount, Description
									  From [ATNDBTest].PAY.LoanPaybackPlanDetail
Set Identity_Insert [ATNDB].PAY.LoanPaybackPlanDetail Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].PAY.LoanPaybackPlanPayment On
Insert Into [ATNDB].PAY.LoanPaybackPlanPayment (Serial, LoanPaybackPlanDetailRef, PaidAmount, PayDate, PaymentType, AccDocumentHeaderRef)
									   Select Serial, LoanPaybackPlanDetailRef, PaidAmount, PayDate, PaymentType, AccDocumentHeaderRef
									   From [ATNDBTest].PAY.LoanPaybackPlanPayment
Set Identity_Insert [ATNDB].PAY.LoanPaybackPlanPayment Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].PAY.LoanPaybackPlanAccCode On
Insert Into [ATNDB].PAY.LoanPaybackPlanAccCode (Serial, LoanPaybackPlanHeaderRef, LoanPaybackPlanPaymentRef, SystemAccCodeDefaultBaseRef, DebitAccAdjutantL1CodeBookRef, DebitAccEntityL1CodeBookRef, DebitAccEntityL2CodeBookRef, DebitAccSecondEntityCodeBookRef, DebitAccThirdEntityCodeBookRef, CreditAccAdjutantL1CodeBookRef, CreditAccEntityL1CodeBookRef, CreditAccEntityL2CodeBookRef, CreditAccSecondEntityCodeBookRef, CreditAccThirdEntityCodeBookRef)
                                       Select Serial, LoanPaybackPlanHeaderRef, LoanPaybackPlanPaymentRef, SystemAccCodeDefaultBaseRef, DebitAccAdjutantL1CodeBookRef, DebitAccEntityL1CodeBookRef, DebitAccEntityL2CodeBookRef, DebitAccSecondEntityCodeBookRef, DebitAccThirdEntityCodeBookRef, CreditAccAdjutantL1CodeBookRef, CreditAccEntityL1CodeBookRef, CreditAccEntityL2CodeBookRef, CreditAccSecondEntityCodeBookRef, CreditAccThirdEntityCodeBookRef
									   From [ATNDBTest].PAY.LoanPaybackPlanAccCode
Set Identity_Insert [ATNDB].PAY.LoanPaybackPlanAccCode Off
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------- هـوش تجاری بیلان -----------------------------------------
----------------------------------------------------------------------------------------------------
Insert Into [ATNDB].dbo.BIReportFile Select * From [ATNDBTest].dbo.BIReportFile
----------------------------------------------------------------------------------------------------
---------------------------------------------- اموال -----------------------------------------------
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].AST.Collectors On
Insert Into [ATNDB].AST.Collectors (Serial, Code, FADescription, ENDescription, Comment, RecorderRef, RecordDate, EditorRef, EditDate, OfficeDetailRef, Tag)
						     Select Serial, Code, FADescription, ENDescription, Comment, RecorderRef, RecordDate, EditorRef, EditDate, OfficeDetailRef, Tag
						     From [ATNDBTest].AST.Collectors
Set Identity_Insert [ATNDB].AST.Collectors Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].AST.AssetGroup On
Insert Into [ATNDB].AST.AssetGroup (Serial, Code, FADescription, ENDescription, Comment, RecorderRef, RecordDate, EditorRef, EditDate, OfficeDetailRef, Tag)
							 Select Serial, Code, FADescription, ENDescription, Comment, RecorderRef, RecordDate, EditorRef, EditDate, OfficeDetailRef, Tag
							 From [ATNDBTest].AST.AssetGroup
Set Identity_Insert [ATNDB].AST.AssetGroup Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].AST.AssetType On
Insert Into [ATNDB].AST.AssetType (Serial, AssetGroupRef, Code, FADescription, ENDescription, Comment, RecorderRef, RecordDate, EditorRef, EditDate, OfficeDetailRef, Tag)
                            Select Serial, AssetGroupRef, Code, FADescription, ENDescription, Comment, RecorderRef, RecordDate, EditorRef, EditDate, OfficeDetailRef, Tag
                            From [ATNDBTest].AST.AssetType
Set Identity_Insert [ATNDB].AST.AssetType Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].AST.AssetDocHeader On
Insert Into [ATNDB].AST.AssetDocHeader (Serial, Code, AssetDocKindRef, AccDocumentHeaderRef, SupplierRef, CostCenterRef, CollectorRef, LocationRef, EffectiveDate, Vat, TotalBuyUnitPrice, TotalDepreciation, TotalAccumulatedDepreciation, TotalBookValue, TotalResidualValue, TotalExpansionOrOverhaul, TotalTakeOut, TotalProfitOrLoss, ForeignCurrencyFactor, ForeignCurrencySymbolRef, RecorderRef, RecordDate, EditorRef, EditDate, VerifierRef, VerificationDate, Comment, OfficeDetailRef, OfficePeriodRef, RowVersion, Tag)
                                 Select Serial, Code, AssetDocKindRef, AccDocumentHeaderRef, SupplierRef, CostCenterRef, CollectorRef, LocationRef, EffectiveDate, Vat, TotalBuyUnitPrice, TotalDepreciation, TotalAccumulatedDepreciation, TotalBookValue, TotalResidualValue, TotalExpansionOrOverhaul, TotalTakeOut, TotalProfitOrLoss, ForeignCurrencyFactor, ForeignCurrencySymbolRef, RecorderRef, RecordDate, EditorRef, EditDate, VerifierRef, VerificationDate, Comment, OfficeDetailRef, OfficePeriodRef, RowVersion, Tag
                                 From [ATNDBTest].AST.AssetDocHeader
Set Identity_Insert [ATNDB].AST.AssetDocHeader Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].AST.Asset On
Insert Into [ATNDB].AST.Asset (Serial, AssetTypeRef, Code, OldCode, FADescription, ENDescription, OEM, UnitRef, AssetComment, LatestAssetPlate, LatestLocationRef, LatestCollectorRef, LatestEmployeeRef, LatestCostCenterRef, OperationDate, OperationAssetDocRef, DepreciationType, DepreciationValue, Active, InactiveRate, BuyUnitPrice, NetValue, AccumulatedDepreciation, BookValue, ResidualValue, Barcode, BarcodeImg, AssetImg, RecorderRef, RecordDate, EditorRef, EditDate, OfficeDetailRef, Tag)
                        Select Serial, AssetTypeRef, Code, OldCode, FADescription, ENDescription, OEM, UnitRef, AssetComment, LatestAssetPlate, LatestLocationRef, LatestCollectorRef, LatestEmployeeRef, LatestCostCenterRef, OperationDate, OperationAssetDocRef, DepreciationType, DepreciationValue, Active, InactiveRate, BuyUnitPrice, NetValue, AccumulatedDepreciation, BookValue, ResidualValue, Barcode, BarcodeImg, AssetImg, RecorderRef, RecordDate, EditorRef, EditDate, OfficeDetailRef, Tag
                        From [ATNDBTest].AST.Asset
Set Identity_Insert [ATNDB].AST.Asset Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].AST.AssetDocDetail On
Insert Into [ATNDB].AST.AssetDocDetail (Serial, AssetDocHeaderRef, AssetRef, BuyUnitPrice, Depreciation, AccumulatedDepreciation, OldAccumulatedDepreciation, BookValue, OldBookValue, ResidualValue, OldResidualValue, ExpansionOrOverhaul, TakeOutValue, ProfitOrLoss, BuyDate, OperationDate, ExpansionOrOverhaulDate, TakeOutDate, OldCostCenterRef, NewCostCenterRef, OldLocationRef, NewLocationRef, OldEmployeeRef, NewEmployeeRef, OldAssetPlate, NewAssetPlate, Tag)
                                 Select Serial, AssetDocHeaderRef, AssetRef, BuyUnitPrice, Depreciation, AccumulatedDepreciation, OldAccumulatedDepreciation, BookValue, OldBookValue, ResidualValue, OldResidualValue, ExpansionOrOverhaul, TakeOutValue, ProfitOrLoss, BuyDate, OperationDate, ExpansionOrOverhaulDate, TakeOutDate, OldCostCenterRef, NewCostCenterRef, OldLocationRef, NewLocationRef, OldEmployeeRef, NewEmployeeRef, OldAssetPlate, NewAssetPlate, Tag
                                 From [ATNDBTest].AST.AssetDocDetail
Set Identity_Insert [ATNDB].AST.AssetDocDetail Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].AST.AssetDocAccCode On
Insert Into [ATNDB].AST.AssetDocAccCode (Serial, AssetDocHeaderRef, AssetDocDetailRef, SystemAccCodeDefaultBaseRef, DebitAccAdjutantL1CodeBookRef, DebitAccEntityL1CodeBookRef, DebitAccEntityL2CodeBookRef, DebitAccSecondEntityCodeBookRef, DebitAccThirdEntityCodeBookRef, CreditAccAdjutantL1CodeBookRef, CreditAccEntityL1CodeBookRef, CreditAccEntityL2CodeBookRef, CreditAccSecondEntityCodeBookRef, CreditAccThirdEntityCodeBookRef)
                                  Select Serial, AssetDocHeaderRef, AssetDocDetailRef, SystemAccCodeDefaultBaseRef, DebitAccAdjutantL1CodeBookRef, DebitAccEntityL1CodeBookRef, DebitAccEntityL2CodeBookRef, DebitAccSecondEntityCodeBookRef, DebitAccThirdEntityCodeBookRef, CreditAccAdjutantL1CodeBookRef, CreditAccEntityL1CodeBookRef, CreditAccEntityL2CodeBookRef, CreditAccSecondEntityCodeBookRef, CreditAccThirdEntityCodeBookRef
                                  From [ATNDBTest].AST.AssetDocAccCode
Set Identity_Insert [ATNDB].AST.AssetDocAccCode Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].AST.SystemAccCodeDefaultPerAssetGroup On
Insert Into [ATNDB].AST.SystemAccCodeDefaultPerAssetGroup (Serial, AssetGroupRef, SystemAccCodeDefaultBaseRef, DebitAccAdjutantL1CodeBookRef, DebitAccEntityL1CodeBookRef, DebitAccEntityL2CodeBookRef, DebitAccSecondEntityCodeBookRef, DebitAccThirdEntityCodeBookRef, CreditAccAdjutantL1CodeBookRef, CreditAccEntityL1CodeBookRef, CreditAccEntityL2CodeBookRef, CreditAccSecondEntityCodeBookRef, CreditAccThirdEntityCodeBookRef)
                                                    Select Serial, AssetGroupRef, SystemAccCodeDefaultBaseRef, DebitAccAdjutantL1CodeBookRef, DebitAccEntityL1CodeBookRef, DebitAccEntityL2CodeBookRef, DebitAccSecondEntityCodeBookRef, DebitAccThirdEntityCodeBookRef, CreditAccAdjutantL1CodeBookRef, CreditAccEntityL1CodeBookRef, CreditAccEntityL2CodeBookRef, CreditAccSecondEntityCodeBookRef, CreditAccThirdEntityCodeBookRef
                                                    From [ATNDBTest].AST.SystemAccCodeDefaultPerAssetGroup
Set Identity_Insert [ATNDB].AST.SystemAccCodeDefaultPerAssetGroup Off
----------------------------------------------------------------------------------------------------
----------------------------------------------- POM ------------------------------------------------
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].POM.IntroductionMethod On
Insert Into [ATNDB].POM.IntroductionMethod (Serial, Code, FADescription, ENDescription, Comment, RecorderRef, RecordDate, EditorRef, EditDate, OfficeDetailRef, Tag)
									 Select Serial, Code, FADescription, ENDescription, Comment, RecorderRef, RecordDate, EditorRef, EditDate, OfficeDetailRef, Tag
									 From [ATNDBTest].POM.IntroductionMethod
Set Identity_Insert [ATNDB].POM.IntroductionMethod Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].POM.ContactMainGroup On
Insert Into [ATNDB].POM.ContactMainGroup (Serial, Code, FADescription, ENDescription, Comment, RecorderRef, RecordDate, EditorRef, EditDate, OfficeDetailRef, Tag)
								   Select Serial, Code, FADescription, ENDescription, Comment, RecorderRef, RecordDate, EditorRef, EditDate, OfficeDetailRef, Tag
								   From [ATNDBTest].POM.ContactMainGroup
Set Identity_Insert [ATNDB].POM.ContactMainGroup Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].POM.ContactSubGroup On
Insert Into [ATNDB].POM.ContactSubGroup (Serial, Code, FADescription, ENDescription, Comment, RecorderRef, RecordDate, EditorRef, EditDate, OfficeDetailRef, Tag)
								  Select Serial, Code, FADescription, ENDescription, Comment, RecorderRef, RecordDate, EditorRef, EditDate, OfficeDetailRef, Tag
								  From [ATNDBTest].POM.ContactSubGroup
Set Identity_Insert [ATNDB].POM.ContactSubGroup Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].POM.ContactCategory On
Insert Into [ATNDB].POM.ContactCategory (Serial, Code, FADescription, ENDescription, Comment, RecorderRef, RecordDate, EditorRef, EditDate, OfficeDetailRef, Tag)
								  Select Serial, Code, FADescription, ENDescription, Comment, RecorderRef, RecordDate, EditorRef, EditDate, OfficeDetailRef, Tag
								  From [ATNDBTest].POM.ContactCategory
Set Identity_Insert [ATNDB].POM.ContactCategory Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].POM.ActivityField On
Insert Into [ATNDB].POM.ActivityField (Serial, Code, FADescription, ENDescription, Comment, RecorderRef, RecordDate, EditorRef, EditDate, OfficeDetailRef, Tag)
								Select Serial, Code, FADescription, ENDescription, Comment, RecorderRef, RecordDate, EditorRef, EditDate, OfficeDetailRef, Tag
								From [ATNDBTest].POM.ActivityField
Set Identity_Insert [ATNDB].POM.ActivityField Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].POM.Contact On
Insert Into [ATNDB].POM.Contact (Serial, Code, PersonOrCompany, FAFirstName, ENFirstName, FALastName, ENLastName, ContactMainGroupRef, ContactSubGroupRef, ContactCategoryRef, CityRef, Location, ContactTypeRef, IntroductionMethodRef, BrokerRef, ActivityFieldRef, AccEntityL1CodeBookRef, AccEntityL2CodeBookRef, AccountMaximum, Active, Description, RecorderRef, RecordDate, EditorRef, EditDate, OfficeDetailRef, Tag)
						  Select Serial, Code, PersonOrCompany, FAFirstName, ENFirstName, FALastName, ENLastName, ContactMainGroupRef, ContactSubGroupRef, ContactCategoryRef, CityRef, Location, ContactTypeRef, IntroductionMethodRef, BrokerRef, ActivityFieldRef, AccEntityL1CodeBookRef, AccEntityL2CodeBookRef, AccountMaximum, Active, Description, RecorderRef, RecordDate, EditorRef, EditDate, OfficeDetailRef, Tag
						  From [ATNDBTest].POM.Contact
Set Identity_Insert [ATNDB].POM.Contact Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].POM.RelatedInformation On
Insert Into [ATNDB].POM.RelatedInformation (Serial, Code, RelatedInformationTypeRef, FADescription, ENDescription, Comment, RecorderRef, RecordDate, EditorRef, EditDate, OfficeDetailRef, Tag)
									 Select Serial, Code, RelatedInformationTypeRef, FADescription, ENDescription, Comment, RecorderRef, RecordDate, EditorRef, EditDate, OfficeDetailRef, Tag
									 From [ATNDBTest].POM.RelatedInformation
Set Identity_Insert [ATNDB].POM.RelatedInformation Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].POM.RelatedInformationPerContact On
Insert Into [ATNDB].POM.RelatedInformationPerContact (Serial, RelatedInformationRef, ContactRef, Value, Tag)
											   Select Serial, RelatedInformationRef, ContactRef, Value, Tag
											   From [ATNDBTest].POM.RelatedInformationPerContact
Set Identity_Insert [ATNDB].POM.RelatedInformationPerContact Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].POM.RelatedPersonPerContact On
Insert Into [ATNDB].POM.RelatedPersonPerContact (Serial, ContactRef, Name, Relation, ContactTitleRef, Data, Comment, Tag)
										  Select Serial, ContactRef, Name, Relation, ContactTitleRef, Data, Comment, Tag
										  From [ATNDBTest].POM.RelatedPersonPerContact
Set Identity_Insert [ATNDB].POM.RelatedPersonPerContact Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].POM.Project On
Insert Into [ATNDB].POM.Project (Serial, Code, ProjectRef, FADescription, ENDescription, ManagerRef, StartDate, DeadlineDate, EstimationDay, EstimationHour, EstimationMinute, EstimationSecond, Comment, AccSecondEntityCodeBookRef, AccountMaximum, Active, RecorderRef, RecordDate, EditorRef, EditDate, OfficeDetailRef, Tag)
						  Select Serial, Code, ProjectRef, FADescription, ENDescription, ManagerRef, StartDate, DeadlineDate, EstimationDay, EstimationHour, EstimationMinute, EstimationSecond, Comment, AccSecondEntityCodeBookRef, AccountMaximum, Active, RecorderRef, RecordDate, EditorRef, EditDate, OfficeDetailRef, Tag
						  From [ATNDBTest].POM.Project
Set Identity_Insert [ATNDB].POM.Project Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].POM.WorkflowType On
Insert Into [ATNDB].POM.WorkflowType (Serial, Code, FADescription, ENDescription, RecorderRef, RecordDate, EditorRef, EditDate, OfficeDetailRef)
							   Select Serial, Code, FADescription, ENDescription, RecorderRef, RecordDate, EditorRef, EditDate, OfficeDetailRef
							   From [ATNDBTest].POM.WorkflowType
Set Identity_Insert [ATNDB].POM.WorkflowType Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].POM.Workflow On
Insert Into [ATNDB].POM.Workflow (Serial, Code, FADescription, ENDescription, WorkflowTypeRef, Active, DurationDay, DurationHour, DurationMinute, DurationSecond, Cost, Comment, RecorderRef, RecordDate, EditorRef, EditDate, OfficeDetailRef, Tag)
						   Select Serial, Code, FADescription, ENDescription, WorkflowTypeRef, Active, DurationDay, DurationHour, DurationMinute, DurationSecond, Cost, Comment, RecorderRef, RecordDate, EditorRef, EditDate, OfficeDetailRef, Tag
						   From [ATNDBTest].POM.Workflow
Set Identity_Insert [ATNDB].POM.Workflow Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].POM.SystemAccCodeDefaultPerWorkflow On
Insert Into [ATNDB].POM.SystemAccCodeDefaultPerWorkflow (Serial, WorkflowRef, SystemAccCodeDefaultBaseRef, DebitAccAdjutantL1CodeBookRef, DebitAccEntityL1CodeBookRef, DebitAccEntityL2CodeBookRef, DebitAccSecondEntityCodeBookRef, DebitAccThirdEntityCodeBookRef, CreditAccAdjutantL1CodeBookRef, CreditAccEntityL1CodeBookRef, CreditAccEntityL2CodeBookRef, CreditAccSecondEntityCodeBookRef, CreditAccThirdEntityCodeBookRef)
												  Select Serial, WorkflowRef, SystemAccCodeDefaultBaseRef, DebitAccAdjutantL1CodeBookRef, DebitAccEntityL1CodeBookRef, DebitAccEntityL2CodeBookRef, DebitAccSecondEntityCodeBookRef, DebitAccThirdEntityCodeBookRef, CreditAccAdjutantL1CodeBookRef, CreditAccEntityL1CodeBookRef, CreditAccEntityL2CodeBookRef, CreditAccSecondEntityCodeBookRef, CreditAccThirdEntityCodeBookRef
												  From [ATNDBTest].POM.SystemAccCodeDefaultPerWorkflow
Set Identity_Insert [ATNDB].POM.SystemAccCodeDefaultPerWorkflow Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].POM.Task On
Insert Into [ATNDB].POM.Task (Serial, WorkflowRef, TaskProgressStateRef, FADescription, ENDescription, ProgressPercent, Tag)
					   Select Serial, WorkflowRef, TaskProgressStateRef, FADescription, ENDescription, ProgressPercent, Tag
					   From [ATNDBTest].POM.Task
Set Identity_Insert [ATNDB].POM.Task Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].POM.WorkHeader On
Insert Into [ATNDB].POM.WorkHeader (Serial, Code, WorkKindRef, AccDocumentHeaderRef, ProjectRef, ControlNo, EffectiveDate, WorkHeaderPlannedDate, WorkHeaderStartDate, WorkHeaderEndDate, WorkHeaderDurationDay, WorkHeaderDurationHour, WorkHeaderDurationMinute, WorkHeaderDurationSecond, WorkHeaderProgressPercent, WorkHeaderCost, Vat, Toll, RecorderRef, RecordDate, EditorRef, EditDate, VerifierRef, VerificationDate, WorkHeaderComment, OfficeDetailRef, OfficePeriodRef, RowVersion, Tag)
							 Select Serial, Code, WorkKindRef, AccDocumentHeaderRef, ProjectRef, ControlNo, EffectiveDate, WorkHeaderPlannedDate, WorkHeaderStartDate, WorkHeaderEndDate, WorkHeaderDurationDay, WorkHeaderDurationHour, WorkHeaderDurationMinute, WorkHeaderDurationSecond, WorkHeaderProgressPercent, WorkHeaderCost, Vat, Toll, RecorderRef, RecordDate, EditorRef, EditDate, VerifierRef, VerificationDate, WorkHeaderComment, OfficeDetailRef, OfficePeriodRef, RowVersion, Tag
							 From [ATNDBTest].POM.WorkHeader
Set Identity_Insert [ATNDB].POM.WorkHeader Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].POM.WorkDetail On
Insert Into [ATNDB].POM.WorkDetail (Serial, WorkHeaderRef, WorkflowRef, WorkDetailPlannedDate, WorkDetailStartDate, WorkDetailEndDate, WorkDetailDurationDay, WorkDetailDurationHour, WorkDetailDurationMinute, WorkDetailDurationSecond, WorkDetailCost, WorkDetailProgressPercent, WorkflowProgressPercent, WorkflowStarterRef, StartTaskRef, WorkDetailComment, Tag)
							 Select Serial, WorkHeaderRef, WorkflowRef, WorkDetailPlannedDate, WorkDetailStartDate, WorkDetailEndDate, WorkDetailDurationDay, WorkDetailDurationHour, WorkDetailDurationMinute, WorkDetailDurationSecond, WorkDetailCost, WorkDetailProgressPercent, WorkflowProgressPercent, WorkflowStarterRef, StartTaskRef, WorkDetailComment, Tag
							 From [ATNDBTest].POM.WorkDetail
Set Identity_Insert [ATNDB].POM.WorkDetail Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].POM.WorkAccCode On
Insert Into [ATNDB].POM.WorkAccCode (Serial, WorkHeaderRef, WorkDetailRef, SystemAccCodeDefaultBaseRef, DebitAccAdjutantL1CodeBookRef, DebitAccEntityL1CodeBookRef, DebitAccEntityL2CodeBookRef, DebitAccSecondEntityCodeBookRef, DebitAccThirdEntityCodeBookRef, CreditAccAdjutantL1CodeBookRef, CreditAccEntityL1CodeBookRef, CreditAccEntityL2CodeBookRef, CreditAccSecondEntityCodeBookRef, CreditAccThirdEntityCodeBookRef)
							  Select Serial, WorkHeaderRef, WorkDetailRef, SystemAccCodeDefaultBaseRef, DebitAccAdjutantL1CodeBookRef, DebitAccEntityL1CodeBookRef, DebitAccEntityL2CodeBookRef, DebitAccSecondEntityCodeBookRef, DebitAccThirdEntityCodeBookRef, CreditAccAdjutantL1CodeBookRef, CreditAccEntityL1CodeBookRef, CreditAccEntityL2CodeBookRef, CreditAccSecondEntityCodeBookRef, CreditAccThirdEntityCodeBookRef
							  From [ATNDBTest].POM.WorkAccCode
Set Identity_Insert [ATNDB].POM.WorkAccCode Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].POM.WorkHeaderContacts On
Insert Into [ATNDB].POM.WorkHeaderContacts (Serial, WorkHeaderRef, ContactRef, Tag)
								     Select Serial, WorkHeaderRef, ContactRef, Tag
								     From [ATNDBTest].POM.WorkHeaderContacts
Set Identity_Insert [ATNDB].POM.WorkHeaderContacts Off
----------------------------------------------------------------------------------------------------
Set Identity_Insert [ATNDB].POM.WorkDetailTask On
Insert Into [ATNDB].POM.WorkDetailTask (Serial, WorkHeaderRef, WorkDetailRef, WorkHeaderContactsRef, TaskRef, TaskPriorityRef, TaskPlannedDate, TaskStartDate, TaskEndDate, TaskDurationDay, TaskDurationHour, TaskDurationMinute, TaskDurationSecond, TaskProgressPercent, TaskCost, TaskExecutorRef, RepetitionNumber, WorkDetailTaskComment, RowVersion, Tag)
								 Select Serial, WorkHeaderRef, WorkDetailRef, WorkHeaderContactsRef, TaskRef, TaskPriorityRef, TaskPlannedDate, TaskStartDate, TaskEndDate, TaskDurationDay, TaskDurationHour, TaskDurationMinute, TaskDurationSecond, TaskProgressPercent, TaskCost, TaskExecutorRef, RepetitionNumber, WorkDetailTaskComment, RowVersion, Tag
								 From [ATNDBTest].POM.WorkDetailTask
Set Identity_Insert [ATNDB].POM.WorkDetailTask Off
----------------------------------------------------------------------------------------------------

Alter Table [ATNDB].POM.WorkDetailTask Enable Trigger WorkDetailTask_TimeStamp_Update
Alter Table [ATNDB].AST.AssetDocHeader Enable Trigger AssetDoc_Header_TimeStamp_Update
Alter Table [ATNDB].PAY.LoanPaybackPlanHeader Enable Trigger LoanPaybackPlan_Header_TimeStamp_Update
Alter Table [ATNDB].PAY.PaymentComputingHeader Enable Trigger PaymentComputingHeader_TimeStamp_Update
Alter Table [ATNDB].dbo.AccDocumentHeader Enable Trigger AccDocumentHeader_TimeStamp_Update
Alter Table [ATNDB].dbo.AccDocumentDetail Enable Trigger AccDocumentDetail_ComputeTotalSum
Alter Table [ATNDB].dbo.FactorHeader Enable Trigger FactorHeader_TimeStamp_Update
Alter Table [ATNDB].dbo.CheckGetPayHeader Enable Trigger CheckGetPayHeader_TimeStamp_Update
Alter Table [ATNDB].dbo.CashGetPay Enable Trigger CashGetPay_Compute_FactorCashSettlementCheckBridge
Alter Table [ATNDB].dbo.CashGetPay Enable Trigger CashGetPay_TimeStamp_Update
Alter Table [ATNDB].dbo.CostHeader Enable Trigger CostHeader_TimeStamp_Update
Alter Table [ATNDB].dbo.StorageCountHeader Enable Trigger StorageCountHeader_TimeStamp_Update
Alter Table [ATNDB].dbo.GritFactor Enable Trigger GritFactor_TimeStamp_Update
Alter Table [ATNDB].dbo.Users Enable Trigger Users_SetEmptyPassword

-- ریست کردن کلید جداول برای برطرف کردن خطاهای احتمالی
DBCC CheckIdent('[ATNDB].dbo.License')
DBCC CheckIdent('[ATNDB].dbo.TaxApiTransactionLog')
DBCC CheckIdent('[ATNDB].dbo.UserActionLog')
DBCC CheckIdent('[ATNDB].dbo.RolePerUser')
DBCC CheckIdent('[ATNDB].dbo.ComponentProperty')
DBCC CheckIdent('[ATNDB].dbo.AccDocumentHeader')
DBCC CheckIdent('[ATNDB].dbo.AccDocumentDetail')
DBCC CheckIdent('[ATNDB].dbo.AccDocumentAppendix')
DBCC CheckIdent('[ATNDB].dbo.UnitWeight')
DBCC CheckIdent('[ATNDB].dbo.PartCluster')
DBCC CheckIdent('[ATNDB].dbo.FactorCategory')
DBCC CheckIdent('[ATNDB].dbo.FactorHeader')
DBCC CheckIdent('[ATNDB].dbo.FactorExtendedOption')
DBCC CheckIdent('[ATNDB].dbo.FactorDetail')
DBCC CheckIdent('[ATNDB].dbo.FactorAccCode')
DBCC CheckIdent('[ATNDB].dbo.WarehouseNoteTitle')
DBCC CheckIdent('[ATNDB].dbo.WarehouseNoteTitlePerDoc')
DBCC CheckIdent('[ATNDB].dbo.FactorDetailAndItselfBridge')
DBCC CheckIdent('[ATNDB].dbo.CheckGetPayHeader')
DBCC CheckIdent('[ATNDB].dbo.CheckGetPayDetail')
DBCC CheckIdent('[ATNDB].dbo.CheckGetPayBridge')
DBCC CheckIdent('[ATNDB].dbo.CashGetPay')
DBCC CheckIdent('[ATNDB].dbo.CheckType')
DBCC CheckIdent('[ATNDB].dbo.CheckStakeholder')
DBCC CheckIdent('[ATNDB].dbo.FactorCashSettlementCheckBridge')
DBCC CheckIdent('[ATNDB].dbo.CostHeader')
DBCC CheckIdent('[ATNDB].dbo.CostDetail')
DBCC CheckIdent('[ATNDB].PAY.SSIOrg')
DBCC CheckIdent('[ATNDB].PAY.SPIOrg')
DBCC CheckIdent('[ATNDB].PAY.EmployeeTaxOrg')
DBCC CheckIdent('[ATNDB].PAY.JobCategory')
DBCC CheckIdent('[ATNDB].PAY.Job')
DBCC CheckIdent('[ATNDB].PAY.JobLocation')
DBCC CheckIdent('[ATNDB].PAY.TaxGroup')
DBCC CheckIdent('[ATNDB].PAY.TaxTableHeader')
DBCC CheckIdent('[ATNDB].PAY.TaxTableDetail')
DBCC CheckIdent('[ATNDB].PAY.Factor')
DBCC CheckIdent('[ATNDB].PAY.LoanType')
DBCC CheckIdent('[ATNDB].PAY.Employee')
DBCC CheckIdent('[ATNDB].PAY.EmployeeWorkExperience')
DBCC CheckIdent('[ATNDB].PAY.EmployeeRelatedPeople')
DBCC CheckIdent('[ATNDB].PAY.EmployeeCourse')
DBCC CheckIdent('[ATNDB].PAY.EmployeeCommunicationMethod')
DBCC CheckIdent('[ATNDB].PAY.EmployeeBank')
DBCC CheckIdent('[ATNDB].PAY.Contract')
DBCC CheckIdent('[ATNDB].PAY.ContractFactor')
DBCC CheckIdent('[ATNDB].PAY.MonthlyFactorPerEmployee')
DBCC CheckIdent('[ATNDB].PAY.PaymentComputingHeader')
DBCC CheckIdent('[ATNDB].PAY.PaymentComputingDetail')
DBCC CheckIdent('[ATNDB].PAY.LoanPaybackPlanHeader')
DBCC CheckIdent('[ATNDB].PAY.LoanPaybackPlanDetail')
DBCC CheckIdent('[ATNDB].PAY.LoanPaybackPlanPayment')
DBCC CheckIdent('[ATNDB].PAY.LoanPaybackPlanAccCode')
DBCC CheckIdent('[ATNDB].AST.Collectors')
DBCC CheckIdent('[ATNDB].AST.AssetGroup')
DBCC CheckIdent('[ATNDB].AST.AssetType')
DBCC CheckIdent('[ATNDB].AST.AssetDocHeader')
DBCC CheckIdent('[ATNDB].AST.Asset')
DBCC CheckIdent('[ATNDB].AST.AssetDocDetail')
DBCC CheckIdent('[ATNDB].AST.AssetDocAccCode')
DBCC CheckIdent('[ATNDB].AST.SystemAccCodeDefaultPerAssetGroup')
DBCC CheckIdent('[ATNDB].POM.IntroductionMethod')
DBCC CheckIdent('[ATNDB].POM.ContactMainGroup')
DBCC CheckIdent('[ATNDB].POM.ContactSubGroup')
DBCC CheckIdent('[ATNDB].POM.ContactCategory')
DBCC CheckIdent('[ATNDB].POM.ActivityField')
DBCC CheckIdent('[ATNDB].POM.Contact')
DBCC CheckIdent('[ATNDB].POM.RelatedInformation')
DBCC CheckIdent('[ATNDB].POM.RelatedInformationPerContact')
DBCC CheckIdent('[ATNDB].POM.RelatedPersonPerContact')
DBCC CheckIdent('[ATNDB].POM.Project')
DBCC CheckIdent('[ATNDB].POM.WorkflowType')
DBCC CheckIdent('[ATNDB].POM.Workflow')
DBCC CheckIdent('[ATNDB].POM.SystemAccCodeDefaultPerWorkflow')
DBCC CheckIdent('[ATNDB].POM.Task')
DBCC CheckIdent('[ATNDB].POM.WorkHeader')
DBCC CheckIdent('[ATNDB].POM.WorkDetail')
DBCC CheckIdent('[ATNDB].POM.WorkAccCode')
DBCC CheckIdent('[ATNDB].POM.WorkDetailTask')

-- باز کردن چکهای قفل شده احتمالی در سیستم
Update [ATNDB].dbo.CheckGetPayDetail Set Lock = 0 Where Lock = 1
Update [ATNDB].dbo.CheckBookDetail Set Lock = 0 Where Lock = 1

-- آپدیت آمار جداول و ایندکسها جهت بالا رفتن سرعت کویری ها
Exec sp_updatestats

-- فعال کردن سی ال آر دات نت
EXEC sp_configure 'clr enabled' , '1'
Reconfigure 

-- بعد از بازیابی دیتابیس جدید، باید این گزینه مجددا فعال گردد
USE [ATNDB]
ALTER DATABASE [ATNDB] SET TRUSTWORTHY ON;
Exec sp_changedbowner 'sa'

-- بازسازی ایندکسهای برخی جداول سنگین و پرکاربرد
Alter Index All On [ATNDB].dbo.AccDocumentDetail Rebuild With (FillFactor = 80)
Alter Index All On [ATNDB].dbo.AccDocumentHeader Rebuild With (FillFactor = 80)
Alter Index All On [ATNDB].dbo.AccEntityL1CodeBook Rebuild With (FillFactor = 80)
Alter Index All On [ATNDB].dbo.AccEntityL2CodeBook Rebuild With (FillFactor = 80)
Alter Index All On [ATNDB].dbo.AccSecondEntityCodeBook Rebuild With (FillFactor = 80)
Alter Index All On [ATNDB].dbo.AccThirdEntityCodeBook Rebuild With (FillFactor = 80)

Alter Index All On [ATNDB].dbo.CashGetPay Rebuild With (FillFactor = 80)
Alter Index All On [ATNDB].dbo.CheckGetPayHeader Rebuild With (FillFactor = 80)
Alter Index All On [ATNDB].dbo.CheckGetPayDetail Rebuild With (FillFactor = 80)
Alter Index All On [ATNDB].dbo.CheckGetPayBridge Rebuild With (FillFactor = 80)

Alter Index All On [ATNDB].dbo.CostHeader Rebuild With (FillFactor = 80)
Alter Index All On [ATNDB].dbo.CostDetail Rebuild With (FillFactor = 80)

Alter Index All On [ATNDB].dbo.FactorHeader Rebuild With (FillFactor = 80)
Alter Index All On [ATNDB].dbo.FactorDetail Rebuild With (FillFactor = 80)
Alter Index All On [ATNDB].dbo.FactorAccCode Rebuild With (FillFactor = 80)
Alter Index All On [ATNDB].dbo.FactorCashSettlementCheckBridge Rebuild With (FillFactor = 80)
Alter Index All On [ATNDB].dbo.FactorDetailAndItselfBridge Rebuild With (FillFactor = 80)
Alter Index All On [ATNDB].dbo.FactorProductAndRawMaterialBridge Rebuild With (FillFactor = 80)
Alter Index All On [ATNDB].dbo.FactorExtendedOption Rebuild With (FillFactor = 80)
Alter Index All On [ATNDB].dbo.FactorHistory Rebuild With (FillFactor = 80)

Alter Index All On [ATNDB].dbo.GetterOrPayerFactor Rebuild With (FillFactor = 80)
Alter Index All On [ATNDB].dbo.Part Rebuild With (FillFactor = 80)
Alter Index All On [ATNDB].dbo.PartSalePrice Rebuild With (FillFactor = 80)
Alter Index All On [ATNDB].dbo.PartWarehouseBridge Rebuild With (FillFactor = 80)

Alter Index All On [ATNDB].dbo.StorageCountDetail Rebuild With (FillFactor = 80)
Alter Index All On [ATNDB].dbo.StorageCountHeader Rebuild With (FillFactor = 80)

Alter Index All On [ATNDB].dbo.GritFactor Rebuild With (FillFactor = 80)
Alter Index All On [ATNDB].dbo.GritFactorAccCode Rebuild With (FillFactor = 80)



/*
-- با استفاده از دستورات زیر یک سری رشته تولید می شود که می توان رشته های تولید شده را 
--  با دستورات اصلی بالا در نوت پد++ مقایسه کرد تا مطمئن شویم داده همه ستونهای جداول در
-- منتقل می شوند. این دستورات فقط برای حقوق و دستمزد نوشته شده ولی با اندکی تغییر برای
--                                                               بقیه جداول قابل تعمیم است
--
--
-- حذف و ایجاد یک جدول جهت نگهداری نام تیبلهای مورد نظر
Use [ATNDB]
Go
If Exists(SELECT * FROM INFORMATION_SCHEMA.TABLES Where TABLE_SCHEMA = 'dbo' And TABLE_TYPE = 'BASE TABLE' And TABLE_NAME = 'TableList') Drop Table dbo.TableList 
Create Table dbo.TableList(
	TABLE_NAME Varchar(Max) Not Null)
GO
Insert Into TableList (TABLE_NAME) Values ('SSIOrg')
Insert Into TableList (TABLE_NAME) Values ('SPIOrg')
Insert Into TableList (TABLE_NAME) Values ('EmployeeTaxOrg')
Insert Into TableList (TABLE_NAME) Values ('JobCategory')
Insert Into TableList (TABLE_NAME) Values ('Job')
Insert Into TableList (TABLE_NAME) Values ('JobLocation')
Insert Into TableList (TABLE_NAME) Values ('TaxGroup')
Insert Into TableList (TABLE_NAME) Values ('TaxTableHeader')
Insert Into TableList (TABLE_NAME) Values ('TaxTableDetail')
Insert Into TableList (TABLE_NAME) Values ('Factor')
Insert Into TableList (TABLE_NAME) Values ('LoanType')
Insert Into TableList (TABLE_NAME) Values ('Employee')
Insert Into TableList (TABLE_NAME) Values ('EmployeeWorkExperience')
Insert Into TableList (TABLE_NAME) Values ('EmployeeRelatedPeople')
Insert Into TableList (TABLE_NAME) Values ('EmployeeCourse')
Insert Into TableList (TABLE_NAME) Values ('EmployeeCommunicationMethod')
Insert Into TableList (TABLE_NAME) Values ('EmployeeBank')
Insert Into TableList (TABLE_NAME) Values ('Contract')
Insert Into TableList (TABLE_NAME) Values ('ContractFactor')
Insert Into TableList (TABLE_NAME) Values ('MonthlyFactorPerEmployee')
Insert Into TableList (TABLE_NAME) Values ('PaymentComputingHeader')
Insert Into TableList (TABLE_NAME) Values ('PaymentComputingDetail')
Insert Into TableList (TABLE_NAME) Values ('LoanPaybackPlanHeader')
Insert Into TableList (TABLE_NAME) Values ('LoanPaybackPlanDetail')
Insert Into TableList (TABLE_NAME) Values ('LoanPaybackPlanPayment')
Insert Into TableList (TABLE_NAME) Values ('LoanPaybackPlanAccCode')
GO
Print Char(13) + Char(10) + Char(13) + Char(10) + Char(13) + Char(10) + Char(13) + Char(10)
Go


Declare @TABLE_NAME Varchar(Max) = ''
Declare @COLUMN_NAME Varchar(Max) = ''
Declare @ColList Varchar(Max) = ''

-- برداشتن لیست جداول منتخب
Declare Tbl_Cursor Cursor Local For Select TABLE_NAME FROM TableList
Open Tbl_Cursor
Fetch Next From Tbl_Cursor Into @TABLE_NAME
While @@FETCH_STATUS = 0
Begin
	--
	-- برداشتن لیست ستونها
	Set @ColList = ''
	Declare Col_Cursor Cursor Local For Select COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA='PAY' And TABLE_NAME = @TABLE_NAME Order by ORDINAL_POSITION
	Open Col_Cursor
	Fetch Next From Col_Cursor Into @COLUMN_NAME
	While @@FETCH_STATUS = 0
	Begin
		Set @ColList = @ColList + Case When Ltrim(Rtrim(@ColList)) <> '' Then ', ' Else '' End + @COLUMN_NAME
		Fetch Next From Col_Cursor Into @COLUMN_NAME
	End
	Close Col_Cursor
	Deallocate Col_Cursor

	-- چاپ دستورات مورد نظر
	Print
	'Set Identity_Insert [ATNDB].PAY.' + @TABLE_NAME + ' On' + Char(13) + Char(10) +
	'Insert Into [ATNDB].PAY.' + @TABLE_NAME + ' (' + @ColList + ')' + Char(13) + Char(10) +
	'Select ' + @ColList + Char(13) + Char(10) + 
	'From [ATNDBTest].PAY.' + @TABLE_NAME +  Char(13) + Char(10) +
	'Set Identity_Insert [ATNDB].PAY.' + @TABLE_NAME + ' Off' + Char(13) + Char(10) +
	'----------------------------------------------------------------------------------------------------'
	-- استخراج نام جدول بعدی
	Fetch Next From Tbl_Cursor Into @TABLE_NAME
End
Close Tbl_Cursor
Deallocate Tbl_Cursor

Drop Table dbo.TableList 
*/








/*

-- با استفاده از دستورات زیر یک سری رشته تولید می شود که می توان رشته های تولید شده را 
--  با دستورات اصلی بالا در نوت پد++ مقایسه کرد تا مطمئن شویم داده همه ستونهای جداول در
-- منتقل می شوند. این دستورات فقط برای امــــــــوال نوشته شده ولی با اندکی تغییر برای
--                                                               بقیه جداول قابل تعمیم است
--
--
-- حذف و ایجاد یک جدول جهت نگهداری نام تیبلهای مورد نظر
Use [ATNDB]
Go
If Exists(SELECT * FROM INFORMATION_SCHEMA.TABLES Where TABLE_SCHEMA = 'dbo' And TABLE_TYPE = 'BASE TABLE' And TABLE_NAME = 'TableList') Drop Table dbo.TableList 
Create Table dbo.TableList(
	TABLE_NAME Varchar(Max) Not Null)
GO
Insert Into TableList (TABLE_NAME) Values ('Collectors')
Insert Into TableList (TABLE_NAME) Values ('AssetGroup')
Insert Into TableList (TABLE_NAME) Values ('AssetType')
Insert Into TableList (TABLE_NAME) Values ('AssetDocHeader')
Insert Into TableList (TABLE_NAME) Values ('Asset')
Insert Into TableList (TABLE_NAME) Values ('AssetDocDetail')
Insert Into TableList (TABLE_NAME) Values ('AssetDocAccCode')
Insert Into TableList (TABLE_NAME) Values ('SystemAccCodeDefaultPerAssetGroup')

GO
Print Char(13) + Char(10) + Char(13) + Char(10) + Char(13) + Char(10) + Char(13) + Char(10)
Go


Declare @TABLE_NAME Varchar(Max) = ''
Declare @COLUMN_NAME Varchar(Max) = ''
Declare @ColList Varchar(Max) = ''

-- برداشتن لیست جداول منتخب
Declare Tbl_Cursor Cursor Local For Select TABLE_NAME FROM TableList
Open Tbl_Cursor
Fetch Next From Tbl_Cursor Into @TABLE_NAME
While @@FETCH_STATUS = 0
Begin
	--
	-- برداشتن لیست ستونها
	Set @ColList = ''
	Declare Col_Cursor Cursor Local For Select COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA='AST' And TABLE_NAME = @TABLE_NAME Order by ORDINAL_POSITION
	Open Col_Cursor
	Fetch Next From Col_Cursor Into @COLUMN_NAME
	While @@FETCH_STATUS = 0
	Begin
		Set @ColList = @ColList + Case When Ltrim(Rtrim(@ColList)) <> '' Then ', ' Else '' End + @COLUMN_NAME
		Fetch Next From Col_Cursor Into @COLUMN_NAME
	End
	Close Col_Cursor
	Deallocate Col_Cursor

	-- چاپ دستورات مورد نظر
	Print
	'Set Identity_Insert [ATNDB].AST.' + @TABLE_NAME + ' On' + Char(13) + Char(10) +
	'Insert Into [ATNDB].AST.' + @TABLE_NAME + ' (' + @ColList + ')' + Char(13) + Char(10) +
	'Select ' + @ColList + Char(13) + Char(10) + 
	'From [ATNDBTest].AST.' + @TABLE_NAME +  Char(13) + Char(10) +
	'Set Identity_Insert [ATNDB].AST.' + @TABLE_NAME + ' Off' + Char(13) + Char(10) +
	'----------------------------------------------------------------------------------------------------'
	-- استخراج نام جدول بعدی
	Fetch Next From Tbl_Cursor Into @TABLE_NAME
End
Close Tbl_Cursor
Deallocate Tbl_Cursor

Drop Table dbo.TableList 
*/











/*

-- با استفاده از دستورات زیر یک سری رشته تولید می شود که می توان رشته های تولید شده را 
--  با دستورات اصلی بالا در نوت پد++ مقایسه کرد تا مطمئن شویم داده همه ستونهای جداول در
-- منتقل می شوند. این دستورات فقط برای (ســـی آر ام) نوشته شده ولی با اندکی تغییر برای
--                                                               بقیه جداول قابل تعمیم است
--
--
-- حذف و ایجاد یک جدول جهت نگهداری نام تیبلهای مورد نظر
Use [ATNDB]
Go
If Exists(SELECT * FROM INFORMATION_SCHEMA.TABLES Where TABLE_SCHEMA = 'dbo' And TABLE_TYPE = 'BASE TABLE' And TABLE_NAME = 'TableList') Drop Table dbo.TableList 
Create Table dbo.TableList(
	TABLE_NAME Varchar(Max) Not Null)
GO
Insert Into TableList (TABLE_NAME) Values ('IntroductionMethod')
Insert Into TableList (TABLE_NAME) Values ('ContactMainGroup')
Insert Into TableList (TABLE_NAME) Values ('ContactSubGroup')
Insert Into TableList (TABLE_NAME) Values ('ContactCategory')
Insert Into TableList (TABLE_NAME) Values ('ActivityField')
Insert Into TableList (TABLE_NAME) Values ('Contact')
Insert Into TableList (TABLE_NAME) Values ('RelatedInformation')
Insert Into TableList (TABLE_NAME) Values ('RelatedInformationPerContact')
Insert Into TableList (TABLE_NAME) Values ('RelatedPersonPerContact')
Insert Into TableList (TABLE_NAME) Values ('Project')
Insert Into TableList (TABLE_NAME) Values ('WorkflowType')
Insert Into TableList (TABLE_NAME) Values ('Workflow')
Insert Into TableList (TABLE_NAME) Values ('SystemAccCodeDefaultPerWorkflow')
Insert Into TableList (TABLE_NAME) Values ('Task')
Insert Into TableList (TABLE_NAME) Values ('WorkHeader')
Insert Into TableList (TABLE_NAME) Values ('WorkDetail')
Insert Into TableList (TABLE_NAME) Values ('WorkAccCode')
Insert Into TableList (TABLE_NAME) Values ('WorkDetailTask')
GO
Print Char(13) + Char(10) + Char(13) + Char(10) + Char(13) + Char(10) + Char(13) + Char(10)
Go


Declare @TABLE_NAME Varchar(Max) = ''
Declare @COLUMN_NAME Varchar(Max) = ''
Declare @ColList Varchar(Max) = ''

-- برداشتن لیست جداول منتخب
Declare Tbl_Cursor Cursor Local For Select TABLE_NAME FROM TableList
Open Tbl_Cursor
Fetch Next From Tbl_Cursor Into @TABLE_NAME
While @@FETCH_STATUS = 0
Begin
	--
	-- برداشتن لیست ستونها
	Set @ColList = ''
	Declare Col_Cursor Cursor Local For Select COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA='POM' And TABLE_NAME = @TABLE_NAME Order by ORDINAL_POSITION
	Open Col_Cursor
	Fetch Next From Col_Cursor Into @COLUMN_NAME
	While @@FETCH_STATUS = 0
	Begin
		Set @ColList = @ColList + Case When Ltrim(Rtrim(@ColList)) <> '' Then ', ' Else '' End + @COLUMN_NAME
		Fetch Next From Col_Cursor Into @COLUMN_NAME
	End
	Close Col_Cursor
	Deallocate Col_Cursor

	-- چاپ دستورات مورد نظر
	Print
	'Set Identity_Insert [ATNDB].POM.' + @TABLE_NAME + ' On' + Char(13) + Char(10) +
	'Insert Into [ATNDB].POM.' + @TABLE_NAME + ' (' + @ColList + ')' + Char(13) + Char(10) +
	'Select ' + @ColList + Char(13) + Char(10) + 
	'From [ATNDBTest].POM.' + @TABLE_NAME +  Char(13) + Char(10) +
	'Set Identity_Insert [ATNDB].POM.' + @TABLE_NAME + ' Off' + Char(13) + Char(10) +
	'----------------------------------------------------------------------------------------------------'
	-- استخراج نام جدول بعدی
	Fetch Next From Tbl_Cursor Into @TABLE_NAME
End
Close Tbl_Cursor
Deallocate Tbl_Cursor

Drop Table dbo.TableList 
*/
