declare @IsClearProceedings bit --是否清除事项
Set @IsClearProceedings = '1'
declare @IsClearInfos bit --是否清除业务实体
Set @IsClearInfos = '0'
declare @IsClearConfigs bit --是否清除配置数据
Set @IsClearConfigs = '0'
if(@IsClearInfos='1')
Set @IsClearProceedings = '1'
/*工作单相关的“生产日志”、“生产绩效”*/
Delete PPM_ProduceTakeOver
Delete PPM_ProduceSendAndGet
Delete SYS_OperationLog
Delete PPM_UserAssign
/*清除业务单据(顺序不能乱动)*/
Delete HRM_AttendenceBillDetail
Delete HRM_AttendenceBill
Delete HRM_PunishBillDetail
Delete HRM_PunishBill
Delete HRM_RewardBillDetail
Delete HRM_RewardBill
Delete ASM_CounterBill
Delete ASM_MaintenanceBill
Delete ASM_AssertNumberStatus
Delete ASM_NumberBillWaste
Delete ASM_NumberBillDetail
Delete ASM_NumberBill
Delete CRM_BonusPointsExchangeBill
Delete CRM_FeedbackBill
Delete FAM_CredenceBillDetail
Delete FAM_CredenceBill
Delete FAM_IncomingBill
Delete FAM_OutgoingBill
Delete FAM_TransferBill
Delete INM_AntiInBillDetail
Delete INM_AntiInBill
Delete INM_CheckBillDetail
Delete INM_CheckBill
Delete INM_InBillDetail
Delete INM_InBill
Delete INM_MoveBillDetail
Delete INM_MoveBill
Delete INM_OutBillDetail
Delete INM_OutBill
Delete INM_PackagingBillDetail
Delete INM_PackagingBill
Delete INM_PlanBillDetail
Delete INM_PlanBill
Delete INM_UsedBillDetail
Delete INM_UsedBill
Delete RSM_SettleGatheringBillDetail
Delete RSM_SettleGatheringBill
Delete RSM_GatheringBill
Delete RSM_PaymentSpec
Delete RSM_PettyGatheringBill
Delete RSM_PreGatheringBill
Delete RSM_RefundmentBill
Delete PPM_ProblemBill
Delete PPM_ProduceFlowRecord
Delete PPM_JobBillDetailUserExec
Delete PPM_JobBillDetailUsedMaterial
Delete PPM_JobBillDetailNumericAssert
Delete PPM_JobBillDetail
Delete PPM_JobBill
Delete PPM_LogisticsBill
Delete PPM_OutSourcingBill
Delete SRM_SettlePaymentBillDetail
Delete SRM_SettlePaymentBill
Delete SRM_CashPaymentBill
Delete SRM_ChargeUpPaymentBill
Delete SRM_PrePaymentBill
Delete EPA_SMSGet
Delete EPA_SMSSend
/*更新所有的业务单据计数器*/
Update GSS_BillCoder Set CoderAutoCounter = 100,CoderCurDay = 0
Delete INM_MaterialStock --业务单据清除,库存数量必定为0。
Delete ASM_AssertNumberStatus
/*清除财务相关*/
Delete FAM_AccountHistory
Delete FAM_AccPCalendar
Delete FAM_Account Where Code like '1122001%' and Len(Code)=11
Delete FAM_Account Where Code like '1123001%' and Len(Code)=11
Delete FAM_Account Where Code like '2202001%' and Len(Code)=11
Delete FAM_Account Where Code like '2205001%' and Len(Code)=11
Update CRM_Customer Set ReceivableAccountCode = NULL, CreditLimited=0 ,CreditDays=0,DefaultBalanceMode='0',MonthlyCloseDay=0 Where ReceivableAccountCode IS NOT NULL
Update CRM_Customer Set PrereceivedAccountCode = NULL Where PrereceivedAccountCode IS NOT NULL
Update SRM_Supplier Set PrepayAccountCode = NULL Where PrepayAccountCode IS NOT NULL
Update SRM_Supplier Set PayableAccountCode = NULL Where PayableAccountCode IS NOT NULL
/*清除一些基本的运行标记*/
Update CRM_Customer Set Hot = -1,Acc4LastSubmitDateTime = Sys4CreateTime,Acc4LastContactDateTime = Sys4CreateTime
Delete SYS_SyncPushToBase
Delete SYS_SyncPushToShare
Delete SYS_SyncPushToShop
Update GSS_EMSDB Set ShopCode = 0,IsInitialized='0' Where Code = '000000'
Delete GSS_Shop
INSERT INTO [GSS_Shop]
([Id]
,[Code]
,[Name]
,[Address]
,[Phone]
,[Fax]
,[QQ]
,[ChargeUserCode]
,[Acc4ChargeUserName]
,[OpenDate]
,[IsLocked]
,[Sys4Version]
,[EMail]
,[Description])
VALUES
(NewId()
,0
,'总店'
,''
,''
,''
,''
,'0000'
,'管理员'
,getdate()
,'0'
,0
,''
,'')
if(@IsClearProceedings='1')
Begin
Delete PIM_Note
Delete PIM_Logy
Delete PIM_Mission
Delete PIM_WorkReport
Delete PIM_Inform
End
/*删除业务资料*/
if(@IsClearInfos='1')
Begin
Delete CRM_Card
Delete CRM_Linkman
Delete CRM_NegotiatedPrice
Delete CRM_GroupNegotiatedPrice
Delete CRM_IndividualCustomer
Delete CRM_Customer Where Code <> '000000'
Delete CRM_CustomerPoint
Delete SRM_Supplier
Delete SRM_SupplierBusiness
Delete ASM_AssertNumberStatus
Delete ASM_AssertNumberSpec
Delete ASM_Assert
Update GSS_InfoSpec Set Length=4,IsAutoPassUnHappyNumber='0',Step = 5 Where Code = 'Customer'
Update GSS_InfoSpec Set Length=4,IsAutoPassUnHappyNumber='0',Step = 5 Where Code = 'Supplier'
Update GSS_InfoSpec Set Length=4,IsAutoPassUnHappyNumber='0',Step = 5 Where Code = 'Material'
Update GSS_InfoSpec Set Length=4,IsAutoPassUnHappyNumber='0',Step = 5 Where Code = 'Assert'
Update GSS_InfoCoder Set Counter=1000 Where Code = 'Customer'
Update GSS_InfoCoder Set Counter=1000 Where Code = 'Supplier'
Update GSS_InfoCoder Set Counter=1000 Where Code = 'Material'
Update GSS_InfoCoder Set Counter=1000 Where Code = 'Assert'
End
if(@IsClearConfigs = '1')
Begin
Delete RSM_BusinessSpec
Delete RSM_BusinessSubUsedMaterial
Delete RSM_BusinessSubNumericAssert
Delete RSM_BusinessSub
Delete RSM_Business
Delete PPM_AssignSpec
End