下面脚本需要用户用备份账套反结账(最好是对每个卡片都进行改动保存一次)重新计提折旧修复了所有数据问题为前提的。

脚本是供不能反结账(有些客户要求不能跨年反结账或者 完全不能反任何一期数据的情况)或者怕财务数据会变化而不能反结账的情形(注意重新计提折旧凭证金额可能与以前凭证金额不一样了,那就说明以前计提是存在问题)。 脚本原理是通过反结账(可能加上重新改动保存凭证)重新计提折旧使计提折旧数据正确,把这部分正确的数据写入到不能反结账的正式账套中。

脚本以KIS专业版为原型研究,旗舰版和k3 基本可用(未严格测试),商贸版不能使用。

–select ‘alter table ‘+ object_name(parent_id )+’ disable trigger ‘+name ,* from sys.triggers where  object_name(parent_id ) like ‘t_fa%’

–select ‘alter table ‘+ object_name(parent_id )+’ enable trigger ‘+name ,* from sys.triggers where  object_name(parent_id ) like ‘t_fa%’

–select  ‘表 ‘+b.name+’ 的触发器 ‘+a.name+’ 被禁用了’ from sys.triggers  a left join sysobjects b on a.parent_id = b.id where  a.is_disabled =1

alter table t_FADeviceBill disable trigger t_FADeviceBill_AutoNumber

alter table t_FADeviceGroupItem disable trigger t_FADeviceGroupItem_AutoNumber

alter table t_FADeviceItemDefine disable trigger t_FADeviceItemDefine_AutoNumber

alter table t_FACardItemDefine disable trigger t_FaCardItemDefine_AutoNumber

alter table t_FAAlterMode disable trigger t_FaAlterMode_AutoNumber

alter table t_FAStatus disable trigger t_FaStatus_AutoNumber

alter table t_FAGroup disable trigger t_FAGroup_AutoNumber

alter table t_FALocation disable trigger t_FaLocation_AutoNumber

alter table t_FADeprMethod disable trigger t_DeprMethod_AutoNumber

alter table t_FAEconomyUse disable trigger t_EconomyUse_AutoNumber

alter table t_FAAlter disable trigger t_FAAlter_AutoNumber

alter table t_FABalance disable trigger t_FABalance_AutoNumber

alter table t_FADevice disable trigger t_FADevice_AutoNumber

alter table t_FAGroupItem disable trigger t_FAGroupItem_AutoNumber

–下面表的删除是有顺序的,不要改动

delete t_FABalCard

delete t_FABalCardItem

delete t_FABalDept

delete t_FABalDevice

delete t_FABalExpense

delete t_FABalOrgFor

delete t_FABalPurchase

delete t_FACard

delete t_FACardItem

delete t_FACardItemDefine

delete t_FACardMulAlter

delete t_FAClear

delete t_FaDeprFormulaItems

delete t_FADept

delete t_FADeptMulAlter

delete t_FADevice

delete t_FADeviceBill

delete t_FADeviceGroupItem

delete t_FADeviceItem

delete t_FADeviceItemDefine

delete t_FADeviceMulAlter

delete t_FAEconomyUse

delete t_FAExpense

delete t_FAExpenseDetailMulAlter

delete t_FAExpenseMulAlter

delete t_FAGroup

delete t_FAGroupItem

delete t_FAImage

delete t_FALocation

delete t_FAOrgFor

delete t_FAOrgForMulAlter

delete t_FAPurchase

delete t_FAPurchaseDetailMulAlter

delete t_FAPurchaseMulAlter

delete t_FARptSheetSchemeItems

delete t_FASchemes

delete t_FASchmFilter

delete t_FASchmOption

delete t_FASchmSort

delete t_FASchmSumItems

delete t_FAStatus

delete t_FaTmpCard

delete t_FAUserDeprRate

delete t_Favorities

delete t_Favorities_Goods

delete t_FAVoucher

delete t_FAAlter

delete t_FAAlterMode

delete t_FABalance

delete t_FADeprMethod

–下面表的插入是有顺序的,与删除顺序应该是不一样的。先插入的数据说明是基础数据,删除的时候就需要后面再删除

/* 生成插入语句使用表的顺序

t_FADeprMethod,t_FAAlterMode,t_FAStatus,t_FAGroup,t_FAGroupItem,t_FAImage,t_FALocation,t_FAAlter,t_FADept,t_FACardItemDefine,t_FACardMulAlter,t_FAClear,t_FaDeprFormulaItems,t_FADevice,t_FADeviceBill,t_FAEconomyUse,t_FADeptMulAlter,t_FASchemes,t_FASchmFilter,t_FASchmOption,t_FASchmSort,t_FASchmSumItems,t_FAUserDeprRate,t_Favorities,t_Favorities_Goods,t_FAVoucher,t_FADeviceGroupItem,t_FADeviceItem,t_FADeviceItemDefine,t_FADeviceMulAlter,t_FAExpense,t_FAExpenseDetailMulAlter,t_FAExpenseMulAlter,t_FAOrgFor,t_FAOrgForMulAlter,t_FAPurchase,t_FAPurchaseDetailMulAlter,t_FAPurchaseMulAlter,t_FARptSheetSchemeItems,t_FaTmpCard,t_FABalance,t_FACard,t_FACardItem,t_FABalCard,t_FABalCardItem,t_FABalDept,t_FABalDevice,t_FABalExpense,t_FABalOrgFor,t_FABalPurchase

*/

  –请在这里把上面/*  */内的表插入语句写入这里。没有插入语句将清空了所有固定数据,包括系统允许的基础数据,使用固定资产功能都将异常。注意插入语句的顺序按照上面的顺序。

alter table t_FADeviceBill enable trigger t_FADeviceBill_AutoNumber

alter table t_FADeviceGroupItem enable trigger t_FADeviceGroupItem_AutoNumber

alter table t_FADeviceItemDefine enable trigger t_FADeviceItemDefine_AutoNumber

alter table t_FACardItemDefine enable trigger t_FaCardItemDefine_AutoNumber

alter table t_FAAlterMode enable trigger t_FaAlterMode_AutoNumber

alter table t_FAStatus enable trigger t_FaStatus_AutoNumber

alter table t_FAGroup enable trigger t_FAGroup_AutoNumber

alter table t_FALocation enable trigger t_FaLocation_AutoNumber

alter table t_FADeprMethod enable trigger t_DeprMethod_AutoNumber

alter table t_FAEconomyUse enable trigger t_EconomyUse_AutoNumber

alter table t_FAAlter enable trigger t_FAAlter_AutoNumber

alter table t_FABalance enable trigger t_FABalance_AutoNumber

alter table t_FADevice enable trigger t_FADevice_AutoNumber

alter table t_FAGroupItem enable trigger t_FAGroupItem_AutoNumber

go