fm_clean.sql 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  1. ---------------------------------------[EAS6.0][资金管理]-------------
  2. -------------------1出纳管理
  3. --收款单
  4. --付款单
  5. --调拨单
  6. --现金日记帐
  7. --银行日记帐
  8. --现金盘点单
  9. --银行对帐单
  10. --银行(现金)日记帐余额表
  11. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from t_cas_receivingbill where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  12. delete from T_BOT_RELATION where FDestObjectID in (select FID from t_cas_receivingbill where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  13. delete from t_cas_receivingbill where FCompanyID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime);
  14. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from t_cas_paymentbill where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  15. delete from T_BOT_RELATION where FDestObjectID in (select FID from t_cas_paymentbill where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  16. delete from t_cas_paymentbill where FCompanyID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime);
  17. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_CAS_FundsMoveBill where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  18. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_CAS_FundsMoveBill where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  19. --源单id
  20. update t_cas_receivingbillentry set fsourcebillid=null
  21. where fsourcebillid in (select FID from T_FS_SettlementBill where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  22. update t_cas_receivingbill set fsourcebillid=null
  23. where fsourcebillid in (select FID from T_FS_SettlementBill where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  24. update t_cas_paymentbillentry set fsourcebillid=null
  25. where fsourcebillid in (select FID from T_FS_SettlementBill where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  26. update t_cas_paymentbill set fsourcebillid=null
  27. where fsourcebillid in (select FID from T_FS_SettlementBill where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  28. delete from T_CAS_FundsMoveBill where FCompanyID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime);
  29. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_CAS_Journal where FCOMPANYID in ($ORGID) and FPeriodId in ($FPERIOD_ID));
  30. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_CAS_Journal where FCOMPANYID in ($ORGID) and FPeriodId in ($FPERIOD_ID));
  31. delete from T_CAS_Journal where FCompanyID in ($ORGID) and FPeriodId in ($FPERIOD_ID);
  32. delete from T_CAS_CashCount where FCompanyID in ($ORGID) and (FCountedDate>=$endtime or FCountedDate<$starttime);
  33. delete from T_CAS_BankStatement where FCompanyID in ($ORGID) and FPeriodId in ($FPERIOD_ID);
  34. delete from T_CAS_JournalBalance where FCompanyID in ($ORGID) and FPeriodId in ($FPERIOD_ID);
  35. ---------------------2资金结算
  36. --对外付款单
  37. --对外收款单
  38. --对内收款单
  39. --对内付款单
  40. --跨行对外付款单
  41. --跨行对外收款单
  42. --跨行对内付款单
  43. --跨行对内收款单
  44. --内部手续费
  45. --外部手续费
  46. --内部账户余额(明细)表
  47. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_FS_SettlementBill where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  48. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_FS_SettlementBill where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  49. delete from T_FS_SettlementBill where FCompanyID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime);
  50. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_FE_FeeBill where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  51. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_FE_FeeBill where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  52. delete from T_FE_FeeBill where FCompanyID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime);
  53. delete from T_FS_SubsidiaryLedger where FCompanyID in ($ORGID) and (FDate>=$endtime or FDate<$starttime);
  54. delete from T_FS_SummaryLedger where FCompanyID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime);
  55. ----------------------3资金划拨
  56. --上划单
  57. --下拨单
  58. --子账户余额(明细)表
  59. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_FS_TransUpBill where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  60. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_FS_TransUpBill where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  61. delete from T_FS_TransUpBill where FCompanyID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime);
  62. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_FS_TransDownBill where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  63. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_FS_TransDownBill where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  64. delete from T_FS_TransDownBill where FCompanyID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime);
  65. delete from T_CAS_SubAcctJournal where FCompanyID in ($ORGID) and FPeriodId in ($FPERIOD_ID);
  66. delete from T_CAS_SubAccountBalance where FCompanyID in ($ORGID) and FPeriodId in ($FPERIOD_ID);
  67. --------------------4票据管理
  68. --付款支票
  69. --领用公司领用记录
  70. delete from T_BOT_RELATION where FSRCOBJECTID in (select fid from T_NT_Cheque where FApplyRecID in (select fid from T_NT_ChequeAppRec where FApplyCompanyID in ($ORGID) and (FApplyDate>=$endtime or FApplyDate<$starttime)));
  71. delete from T_BOT_RELATION where FDestObjectID in (select fid from T_NT_Cheque where FApplyRecID in (select fid from T_NT_ChequeAppRec where FApplyCompanyID in ($ORGID) and (FApplyDate>=$endtime or FApplyDate<$starttime)));
  72. delete from T_NT_Cheque where FApplyRecID in (select fid from T_NT_ChequeAppRec where FApplyCompanyID in ($ORGID) and (FApplyDate>=$endtime or FApplyDate<$starttime));
  73. delete from T_NT_ChequeAppRec where FApplyCompanyID in ($ORGID) and (FApplyDate>=$endtime or FApplyDate<$starttime);
  74. --保管公司
  75. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_NT_Cheque where FKeepCompanyID in ($ORGID) and (FPurDate>=$endtime or FPurDate<$starttime));
  76. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_NT_Cheque where FKeepCompanyID in ($ORGID) and (FPurDate>=$endtime or FPurDate<$starttime));
  77. delete from T_NT_Cheque where FKeepCompanyID in ($ORGID) and (FPurDate>=$endtime or FPurDate<$starttime);
  78. --登记公司
  79. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_NT_Cheque where FCOMPANYID in ($ORGID) and (FPurDate>=$endtime or FPurDate<$starttime));
  80. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_NT_Cheque where FCOMPANYID in ($ORGID) and (FPurDate>=$endtime or FPurDate<$starttime));
  81. delete from T_NT_Cheque where FCompanyID in ($ORGID) and (FPurDate>=$endtime or FPurDate<$starttime);
  82. --收款支票
  83. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_NT_RecCheque')
  84. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_NT_RecCheque where FCOMPANYID in ($ORGID) and (FFReceiveDate0>=$endtime or FFReceiveDate0<$starttime));
  85. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_NT_RecCheque')
  86. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_NT_RecCheque where FCOMPANYID in ($ORGID) and (FFReceiveDate0>=$endtime or FFReceiveDate0<$starttime));
  87. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_NT_RecCheque')
  88. delete from T_NT_RecCheque where FCompanyID in ($ORGID) and (FFReceiveDate0>=$endtime or FFReceiveDate0<$starttime);
  89. ----电汇单
  90. --收款票据
  91. --付款票据
  92. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_NT_ReceiptBill where FCOMPANYID in ($ORGID) and (FReceiptDate>=$endtime or FReceiptDate<$starttime));
  93. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_NT_ReceiptBill where FCOMPANYID in ($ORGID) and (FReceiptDate>=$endtime or FReceiptDate<$starttime));
  94. delete from T_NT_ReceiptBill where FCompanyID in ($ORGID) and (FReceiptDate>=$endtime or FReceiptDate<$starttime);
  95. --应收票据
  96. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_NT_ReceivableBill where FCOMPANYID in ($ORGID) and (FTakeDate>=$endtime or FTakeDate<$starttime));
  97. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_NT_ReceivableBill where FCOMPANYID in ($ORGID) and (FTakeDate>=$endtime or FTakeDate<$starttime));
  98. delete from T_NT_ReceivableBill where FCompanyID in ($ORGID) and (FTakeDate>=$endtime or FTakeDate<$starttime);
  99. --源单id
  100. update t_nt_ReceivableBill set fsourcebillid=null
  101. where fsourcebillid in (select FID from T_NT_EndorsementBill where FCOMPANYID in ($ORGID) and (FEndorseDate>=$endtime or FEndorseDate<$starttime));
  102. --应付票据
  103. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_NT_PayableBill where FCOMPANYID in ($ORGID) and (FIssueDate>=$endtime or FIssueDate<$starttime));
  104. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_NT_PayableBill where FCOMPANYID in ($ORGID) and (FIssueDate>=$endtime or FIssueDate<$starttime));
  105. delete from T_NT_PayableBill where FCompanyID in ($ORGID) and (FIssueDate>=$endtime or FIssueDate<$starttime);
  106. --背书单
  107. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_NT_EndorsementBill where FCOMPANYID in ($ORGID) and (FEndorseDate>=$endtime or FEndorseDate<$starttime));
  108. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_NT_EndorsementBill where FCOMPANYID in ($ORGID) and (FEndorseDate>=$endtime or FEndorseDate<$starttime));
  109. delete from T_NT_EndorsementBill where FCompanyID in ($ORGID) and (FEndorseDate>=$endtime or FEndorseDate<$starttime);
  110. --贴现单
  111. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_NT_DiscountBill where FCOMPANYID in ($ORGID) and (FDiscountDate>=$endtime or FDiscountDate<$starttime));
  112. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_NT_DiscountBill where FCOMPANYID in ($ORGID) and (FDiscountDate>=$endtime or FDiscountDate<$starttime));
  113. delete from T_NT_DiscountBill where FCompanyID in ($ORGID) and (FDiscountDate>=$endtime or FDiscountDate<$starttime);
  114. --收款单 出纳收款单
  115. --质押单
  116. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_FIN_Wage where FCOMPANYID in ($ORGID) and (FIssueDate>=$endtime or FIssueDate<$starttime));
  117. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_FIN_Wage where FCOMPANYID in ($ORGID) and (FIssueDate>=$endtime or FIssueDate<$starttime));
  118. delete from T_FIN_Wage where FCompanyID in ($ORGID) and (FIssueDate>=$endtime or FIssueDate<$starttime);
  119. --退票单
  120. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_NT_ReturnBill where FCOMPANYID in ($ORGID) and (FReturnDate>=$endtime or FReturnDate<$starttime));
  121. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_NT_ReturnBill where FCOMPANYID in ($ORGID) and (FReturnDate>=$endtime or FReturnDate<$starttime));
  122. delete from T_NT_ReturnBill where FCompanyID in ($ORGID) and (FReturnDate>=$endtime or FReturnDate<$starttime);
  123. --转付单
  124. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_NT_PayableTransferBill where FCOMPANYID in ($ORGID) and (FTransferDate>=$endtime or FTransferDate<$starttime));
  125. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_NT_PayableTransferBill where FCOMPANYID in ($ORGID) and (FTransferDate>=$endtime or FTransferDate<$starttime));
  126. delete from T_NT_PayableTransferBill where FCompanyID in ($ORGID) and (FTransferDate>=$endtime or FTransferDate<$starttime);
  127. --兑付单 (借款、信用证)还款单
  128. -------------5投资管理
  129. --委托贷款单
  130. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_CL_ConsignmentLoanBill where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  131. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_CL_ConsignmentLoanBill where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  132. delete from T_CL_ConsignmentLoanBill where FCompanyID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime);
  133. --委托展期单
  134. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_CL_ConsignLoanExtBill where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  135. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_CL_ConsignLoanExtBill where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  136. delete from T_CL_ConsignLoanExtBill where FCompanyID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime);
  137. --委托还款单
  138. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_CL_ConsingnRepaymentBill where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  139. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_CL_ConsingnRepaymentBill where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  140. delete from T_CL_ConsingnRepaymentBill where FCompanyID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime);
  141. --资金往来单
  142. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_FT_FundTransferBill where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  143. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_FT_FundTransferBill where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  144. delete from T_FT_FundTransferBill where FCompanyID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime);
  145. --资金往来展期单
  146. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_FT_FundTransferExtBill')
  147. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_FT_FundTransferExtBill where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  148. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_FT_FundTransferExtBill')
  149. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_FT_FundTransferExtBill where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  150. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_FT_FundTransferExtBill')
  151. delete from T_FT_FundTransferExtBill where FCompanyID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime);
  152. --资金往来委托展期单
  153. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_CL_ConsignLoanExtBill where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  154. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_CL_ConsignLoanExtBill where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  155. delete from T_CL_ConsignLoanExtBill where FCompanyID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime);
  156. --资金往来还款单
  157. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_FT_FundTransferRepayBill where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  158. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_FT_FundTransferRepayBill where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  159. delete from T_FT_FundTransferRepayBill where FCompanyID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime);
  160. --银行定期(通知)存款申请单
  161. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_TD_TimeDepositApply where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  162. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_TD_TimeDepositApply where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  163. delete from T_TD_TimeDepositApply where FCompanyID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime);
  164. --银行定期(通知)存款
  165. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_TD_TimeDepositBill where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  166. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_TD_TimeDepositBill where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  167. delete from T_TD_TimeDepositBill where FCompanyID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime);
  168. --银行定期(通知)存款解活单
  169. If exists (select * from KSQL_USERCOLUMNS where KSQL_COL_NAME ='FMyBizDate' and KSQL_COL_TABNAME='T_TD_UnTimeDepositBill')
  170. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_TD_UnTimeDepositBill where FCOMPANYID in ($ORGID) and (FMyBizDate>=$endtime or FMyBizDate<$starttime));
  171. If exists (select * from KSQL_USERCOLUMNS where KSQL_COL_NAME ='FMyBizDate' and KSQL_COL_TABNAME='T_TD_UnTimeDepositBill')
  172. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_TD_UnTimeDepositBill where FCOMPANYID in ($ORGID) and (FMyBizDate>=$endtime or FMyBizDate<$starttime));
  173. If exists (select * from KSQL_USERCOLUMNS where KSQL_COL_NAME ='FMyBizDate' and KSQL_COL_TABNAME='T_TD_UnTimeDepositBill')
  174. delete from T_TD_UnTimeDepositBill where FCompanyID in ($ORGID) and (FMyBizDate>=$endtime or FMyBizDate<$starttime);
  175. --企业贷款单
  176. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_IVT_ChLoan')
  177. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_IVT_ChLoan where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  178. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_IVT_ChLoan')
  179. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_IVT_ChLoan where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  180. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_IVT_ChLoan')
  181. delete from T_IVT_ChLoan where FCompanyID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime);
  182. --企业贷款展期单
  183. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_IVT_CHLoanExtendBill')
  184. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_IVT_CHLoanExtendBill where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  185. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_IVT_CHLoanExtendBill')
  186. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_IVT_CHLoanExtendBill where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  187. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_IVT_CHLoanExtendBill')
  188. delete from T_IVT_CHLoanExtendBill where FCompanyID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime);
  189. --企业贷款还款单
  190. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_IVT_EntRepaymentBill')
  191. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_IVT_EntRepaymentBill where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  192. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_IVT_EntRepaymentBill')
  193. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_IVT_EntRepaymentBill where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  194. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_IVT_EntRepaymentBill')
  195. delete from T_IVT_EntRepaymentBill where FCompanyID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime);
  196. --(股票投资单)
  197. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_SK_StockInvestBill')
  198. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_SK_StockInvestBill where FCOMPANYID in ($ORGID) and (FExchangeDate>=$endtime or FExchangeDate<$starttime));
  199. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_SK_StockInvestBill')
  200. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_SK_StockInvestBill where FCOMPANYID in ($ORGID) and (FExchangeDate>=$endtime or FExchangeDate<$starttime));
  201. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_SK_StockInvestBill')
  202. delete from T_SK_StockInvestBill where FCompanyID in ($ORGID) and (FExchangeDate>=$endtime or FExchangeDate<$starttime);
  203. --(股东代码)
  204. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_SK_Stockholder')
  205. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_SK_Stockholder where FCurCompanyID in ($ORGID) and (FCreateTime>=$endtime or FCreateTime<$starttime));
  206. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_SK_Stockholder')
  207. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_SK_Stockholder where FCurCompanyID in ($ORGID) and (FCreateTime>=$endtime or FCreateTime<$starttime));
  208. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_SK_Stockholder')
  209. delete from T_SK_Stockholder where FCurCompanyID in ($ORGID) and (FCreateTime>=$endtime or FCreateTime<$starttime);
  210. --股票库存初始化
  211. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_SK_FundSettleBill')
  212. delete from T_SK_FundSettleBill where FCompanyID in ($ORGID) and (FCreateTime>=$endtime or FCreateTime<$starttime);
  213. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_SK_StockSettleBill')
  214. delete from T_SK_StockSettleBill where FCompanyID in ($ORGID) and (FCreateTime>=$endtime or FCreateTime<$starttime);
  215. -----------6融资管理
  216. --授信额度
  217. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_FIN_CreditLimit where FCOMPANYID in ($ORGID) and (FIssueDate>=$endtime or FIssueDate<$starttime));
  218. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_FIN_CreditLimit where FCOMPANYID in ($ORGID) and (FIssueDate>=$endtime or FIssueDate<$starttime));
  219. delete from T_FIN_CreditLimit where FCompanyID in ($ORGID) and (FIssueDate>=$endtime or FIssueDate<$starttime);
  220. --抵质押物
  221. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_FIN_Wage where FCOMPANYID in ($ORGID) and (FIssueDate>=$endtime or FIssueDate<$starttime));
  222. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_FIN_Wage where FCOMPANYID in ($ORGID) and (FIssueDate>=$endtime or FIssueDate<$starttime));
  223. delete from T_FIN_Wage where FCompanyID in ($ORGID) and (FIssueDate>=$endtime or FIssueDate<$starttime);
  224. delete from T_FIN_WageEntry where FParentID in (select FID from T_FIN_Wage where FCOMPANYID in ($ORGID) and (FIssueDate>=$endtime or FIssueDate<$starttime));
  225. --借款申请单
  226. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_FIN_LoanApplyBill where FCOMPANYID in ($ORGID) and (FApplyDate>=$endtime or FApplyDate<$starttime));
  227. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_FIN_LoanApplyBill where FCOMPANYID in ($ORGID) and (FApplyDate>=$endtime or FApplyDate<$starttime));
  228. delete from T_FIN_LoanApplyBill where FCompanyID in ($ORGID) and (FApplyDate>=$endtime or FApplyDate<$starttime);
  229. --信用证
  230. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_FIN_LetterOfCredit where FCOMPANYID in ($ORGID) and (FIssueDate>=$endtime or FIssueDate<$starttime));
  231. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_FIN_LetterOfCredit where FCOMPANYID in ($ORGID) and (FIssueDate>=$endtime or FIssueDate<$starttime));
  232. delete from T_FIN_LetterOfCredit where FCompanyID in ($ORGID) and (FIssueDate>=$endtime or FIssueDate<$starttime);
  233. --信用证手续费
  234. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_FIN_FeeManage')
  235. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_FIN_FeeManage where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  236. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_FIN_FeeManage')
  237. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_FIN_FeeManage where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  238. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_FIN_FeeManage')
  239. delete from T_FIN_FeeManage where FCompanyID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime);
  240. --信用证改证
  241. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_FIN_ModifyLetter')
  242. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_FIN_ModifyLetter where FCOMPANYID in ($ORGID) and (FModifyDate>=$endtime or FModifyDate<$starttime));
  243. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_FIN_ModifyLetter')
  244. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_FIN_ModifyLetter where FCOMPANYID in ($ORGID) and (FModifyDate>=$endtime or FModifyDate<$starttime));
  245. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_FIN_ModifyLetter')
  246. delete from T_FIN_ModifyLetter where FCompanyID in ($ORGID) and (FModifyDate>=$endtime or FModifyDate<$starttime);
  247. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_FIN_ModifyLetter')
  248. delete from T_FIN_ModifyLetterEntry where FParentID in (select FID from T_FIN_ModifyLetter where FCOMPANYID in ($ORGID) and (FModifyDate>=$endtime or FModifyDate<$starttime));
  249. --借款单
  250. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_FIN_Loan where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  251. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_FIN_Loan where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  252. delete from T_FIN_Loan where FCompanyID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime);
  253. --借款展期单
  254. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_FIN_LoanDefer where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  255. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_FIN_LoanDefer where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  256. delete from T_FIN_LoanDefer where FCompanyID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime);
  257. --(借款、信用证)还款单
  258. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_FIN_Repayment where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  259. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_FIN_Repayment where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  260. delete from T_FIN_Repayment where FCompanyID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime);
  261. --企业定期(通知)存款单
  262. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_FIN_CompDepositAccountBill where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  263. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_FIN_CompDepositAccountBill where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  264. delete from T_FIN_CompDepositAccountBill where FCompanyID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime);
  265. --企业定期(通知)解活单
  266. If exists (select * from KSQL_USERCOLUMNS where KSQL_COL_NAME ='FBizDate' and KSQL_COL_TABNAME='T_FIN_UnTimeDepositBill')
  267. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_FIN_UnTimeDepositBill where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  268. If exists (select * from KSQL_USERCOLUMNS where KSQL_COL_NAME ='FBizDate' and KSQL_COL_TABNAME='T_FIN_UnTimeDepositBill')
  269. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_FIN_UnTimeDepositBill where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  270. If exists (select * from KSQL_USERCOLUMNS where KSQL_COL_NAME ='FBizDate' and KSQL_COL_TABNAME='T_FIN_UnTimeDepositBill')
  271. delete from T_FIN_UnTimeDepositBill where FCompanyID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime);
  272. ---------------7或有负债
  273. --银行保函
  274. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_CTL_LetterOfGuarantee')
  275. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_CTL_LetterOfGuarantee where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  276. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_CTL_LetterOfGuarantee')
  277. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_CTL_LetterOfGuarantee where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  278. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_CTL_LetterOfGuarantee')
  279. delete from T_CTL_LetterOfGuarantee where FCompanyID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime);
  280. --银行保函改函
  281. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_CTL_LetOfGuarantee where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  282. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_CTL_LetOfGuarantee where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  283. delete from T_CTL_LetOfGuarantee where FCompanyID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime);
  284. delete from T_CTL_LetOfGuaranteeEntry where FParentID in (select FID from T_CTL_LetOfGuarantee where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  285. --银行保函手续费
  286. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_CTL_FeeForGuarantee where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  287. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_CTL_FeeForGuarantee where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  288. delete from T_CTL_FeeForGuarantee where FCompanyID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime);
  289. --银行保理
  290. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_CTL_BankFactor')
  291. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_CTL_BankFactor where FFICompanyID in ($ORGID) and (FIssueDate>=$endtime or FIssueDate<$starttime));
  292. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_CTL_BankFactor')
  293. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_CTL_BankFactor where FFICompanyID in ($ORGID) and (FIssueDate>=$endtime or FIssueDate<$starttime));
  294. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_CTL_BankFactor')
  295. delete from T_CTL_BankFactor where FFICompanyID in ($ORGID) and (FIssueDate>=$endtime or FIssueDate<$starttime);
  296. --担保单
  297. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_CTL_AssureBill')
  298. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_CTL_AssureBill where FCOMPANYID in ($ORGID) and (FBeginDate>=$endtime or FBeginDate<$starttime));
  299. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_CTL_AssureBill')
  300. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_CTL_AssureBill where FCOMPANYID in ($ORGID) and (FBeginDate>=$endtime or FBeginDate<$starttime));
  301. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_CTL_AssureBill')
  302. delete from T_CTL_AssureBill where FCompanyID in ($ORGID) and (FBeginDate>=$endtime or FBeginDate<$starttime);
  303. -----------------8资金监控
  304. --受限存款单
  305. delete from T_MNT_DepositInControl where FCompanyID in ($ORGID) and (FBeginDate>=$endtime or FBeginDate<$starttime);
  306. --资金存量单
  307. delete from T_MNT_CashInventory where FCompanyID in ($ORGID) and (FCreateTime>=$endtime or FCreateTime<$starttime);
  308. -----------------9银企互联
  309. --银行付款单
  310. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_BE_BankPayingBill where FCOMPANYID in ($ORGID) and (FSubmitTime>=$endtime or FSubmitTime<$starttime));
  311. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_BE_BankPayingBill where FCOMPANYID in ($ORGID) and (FSubmitTime>=$endtime or FSubmitTime<$starttime));
  312. delete from T_BE_BankPayingBill where FCompanyID in ($ORGID) and (FSubmitTime>=$endtime or FSubmitTime<$starttime);
  313. --银行上划单
  314. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_BE_BankTransUpBill where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  315. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_BE_BankTransUpBill where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  316. delete from T_BE_BankTransUpBill where FCompanyID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime);
  317. delete from T_BE_BankTransUpBillEntry where FParentID in (select FID from T_BE_BankTransUpBill where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  318. --银行下拨单
  319. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_BE_BankTransDownBill where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  320. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_BE_BankTransDownBill where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  321. delete from T_BE_BankTransDownBill where FCompanyID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime);
  322. delete from T_BE_BankTransDownBillEntry where FParentID in (select FID from T_BE_BankTransDownBill where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  323. --银行账户交易余额(明细)表
  324. delete from T_BE_TransDetail where FCompanyID in ($ORGID) and (FBizTime>=$endtime or FBizTime<$starttime);
  325. delete from T_BE_AccountBankBalance where FCompanyID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime);
  326. --------------------10利息管理
  327. --内部利息单
  328. --外部利息单
  329. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_INT_AccrualBill where FCOMPANYID in ($ORGID) and (FBeginDate>=$endtime or FBeginDate<$starttime));
  330. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_INT_AccrualBill where FCOMPANYID in ($ORGID) and (FBeginDate>=$endtime or FBeginDate<$starttime));
  331. delete from T_INT_AccrualBill where FCompanyID in ($ORGID) and (FBeginDate>=$endtime or FBeginDate<$starttime);
  332. delete from T_INT_AccrualBillEntry where FParentID in (select FID from T_INT_AccrualBill where FCOMPANYID in ($ORGID) and (FBeginDate>=$endtime or FBeginDate<$starttime));
  333. --借款利息
  334. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_FIN_LoanInterest where FCOMPANYID in ($ORGID) and (FBeginDate>=$endtime or FBeginDate<$starttime));
  335. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_FIN_LoanInterest where FCOMPANYID in ($ORGID) and (FBeginDate>=$endtime or FBeginDate<$starttime));
  336. delete from T_FIN_LoanInterest where FCompanyID in ($ORGID) and (FBeginDate>=$endtime or FBeginDate<$starttime);
  337. delete from T_FIN_LoanInterestEntry where FParentID in (select FID from T_FIN_LoanInterest where FCOMPANYID in ($ORGID) and (FBeginDate>=$endtime or FBeginDate<$starttime));
  338. --企业贷款利息
  339. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_IVT_LoanInterestBill')
  340. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_IVT_LoanInterestBill where FCOMPANYID in ($ORGID) and (FBeginDate>=$endtime or FBeginDate<$starttime));
  341. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_IVT_LoanInterestBill')
  342. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_IVT_LoanInterestBill where FCOMPANYID in ($ORGID) and (FBeginDate>=$endtime or FBeginDate<$starttime));
  343. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_IVT_LoanInterestBill')
  344. delete from T_IVT_LoanInterestBill where FCompanyID in ($ORGID) and (FBeginDate>=$endtime or FBeginDate<$starttime);
  345. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_IVT_LoanInterestBillEntry')
  346. delete from T_IVT_LoanInterestBillEntry where FParentID in (select FID from T_IVT_LoanInterestBill where FCOMPANYID in ($ORGID) and (FBeginDate>=$endtime or FBeginDate<$starttime));
  347. --委托贷款利息
  348. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_CL_ConsignLoanIntBill where FCOMPANYID in ($ORGID) and (FStartDate>=$endtime or FStartDate<$starttime));
  349. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_CL_ConsignLoanIntBill where FCOMPANYID in ($ORGID) and (FStartDate>=$endtime or FStartDate<$starttime));
  350. delete from T_CL_ConsignLoanIntBill where FCompanyID in ($ORGID) and (FStartDate>=$endtime or FStartDate<$starttime);
  351. --银行定期利息
  352. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_TD_IntReceivedBill where FCOMPANYID in ($ORGID) and (FEffectiveDate>=$endtime or FEffectiveDate<$starttime));
  353. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_TD_IntReceivedBill where FCOMPANYID in ($ORGID) and (FEffectiveDate>=$endtime or FEffectiveDate<$starttime));
  354. delete from T_TD_IntReceivedBill where FCompanyID in ($ORGID) and (FEffectiveDate>=$endtime or FEffectiveDate<$starttime);
  355. --企业定期利息
  356. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_FIN_CompIntReceivedBill where FCOMPANYID in ($ORGID) and (FEffectiveDate>=$endtime or FEffectiveDate<$starttime));
  357. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_FIN_CompIntReceivedBill where FCOMPANYID in ($ORGID) and (FEffectiveDate>=$endtime or FEffectiveDate<$starttime));
  358. delete from T_FIN_CompIntReceivedBill where FCompanyID in ($ORGID) and (FEffectiveDate>=$endtime or FEffectiveDate<$starttime);
  359. --资金往来利息
  360. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_FT_FundTransferInterestBill where FCOMPANYID in ($ORGID) and (FStartDate>=$endtime or FStartDate<$starttime));
  361. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_FT_FundTransferInterestBill where FCOMPANYID in ($ORGID) and (FStartDate>=$endtime or FStartDate<$starttime));
  362. delete from T_FT_FundTransferInterestBill where FCompanyID in ($ORGID) and (FStartDate>=$endtime or FStartDate<$starttime);
  363. --委托贷款利息调整单
  364. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_CL_CLRateAdjustmentBill where FCOMPANYID in ($ORGID) and (FAdjustDate>=$endtime or FAdjustDate<$starttime));
  365. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_CL_CLRateAdjustmentBill where FCOMPANYID in ($ORGID) and (FAdjustDate>=$endtime or FAdjustDate<$starttime));
  366. delete from T_CL_CLRateAdjustmentBill where FCompanyID in ($ORGID) and (FAdjustDate>=$endtime or FAdjustDate<$starttime);
  367. --借款利息调整单
  368. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_FIN_LoanAdjustInterest where FCOMPANYID in ($ORGID) and (FAdjustDate>=$endtime or FAdjustDate<$starttime));
  369. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_FIN_LoanAdjustInterest where FCOMPANYID in ($ORGID) and (FAdjustDate>=$endtime or FAdjustDate<$starttime));
  370. delete from T_FIN_LoanAdjustInterest where FCompanyID in ($ORGID) and (FAdjustDate>=$endtime or FAdjustDate<$starttime);
  371. --资金往来利率调整单
  372. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_FT_FundTransRateAdjustBill where FCOMPANYID in ($ORGID) and (FAdjustDate>=$endtime or FAdjustDate<$starttime));
  373. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_FT_FundTransRateAdjustBill where FCOMPANYID in ($ORGID) and (FAdjustDate>=$endtime or FAdjustDate<$starttime));
  374. delete from T_FT_FundTransRateAdjustBill where FCompanyID in ($ORGID) and (FAdjustDate>=$endtime or FAdjustDate<$starttime);
  375. ---------------11资金预测
  376. --预计资金流动单
  377. delete from T_MNT_ForecastedBlockingFlow where FCompanyID in ($ORGID) and (FExpectedDate>=$endtime or FExpectedDate<$starttime);
  378. ---------------12同业往来
  379. --同业拆入单
  380. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_IBT_InnerFinBorIn')
  381. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_IBT_InnerFinBorIn where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  382. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_IBT_InnerFinBorIn')
  383. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_IBT_InnerFinBorIn where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  384. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_IBT_InnerFinBorIn')
  385. delete from T_IBT_InnerFinBorIn where FCompanyID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime);
  386. --同业拆出单
  387. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_IBT_InnerFinBorOut')
  388. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_IBT_InnerFinBorOut where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  389. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_IBT_InnerFinBorOut')
  390. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_IBT_InnerFinBorOut where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  391. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_IBT_InnerFinBorOut')
  392. delete from T_IBT_InnerFinBorOut where FCompanyID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime);
  393. --同业拆入还款单
  394. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_IBT_InnerBorrowingReturnIn')
  395. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_IBT_InnerBorrowingReturnIn where FCOMPANYID in ($ORGID) and (FReturnDate>=$endtime or FReturnDate<$starttime));
  396. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_IBT_InnerBorrowingReturnIn')
  397. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_IBT_InnerBorrowingReturnIn where FCOMPANYID in ($ORGID) and (FReturnDate>=$endtime or FReturnDate<$starttime));
  398. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_IBT_InnerBorrowingReturnIn')
  399. delete from T_IBT_InnerBorrowingReturnIn where FCompanyID in ($ORGID) and (FReturnDate>=$endtime or FReturnDate<$starttime);
  400. --同业拆出还款单
  401. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_IBT_InnerBorrowingReturnOut')
  402. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_IBT_InnerBorrowingReturnOut where FCOMPANYID in ($ORGID) and (FReturnDate>=$endtime or FReturnDate<$starttime));
  403. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_IBT_InnerBorrowingReturnOut')
  404. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_IBT_InnerBorrowingReturnOut where FCOMPANYID in ($ORGID) and (FReturnDate>=$endtime or FReturnDate<$starttime));
  405. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_IBT_InnerBorrowingReturnOut')
  406. delete from T_IBT_InnerBorrowingReturnOut where FCompanyID in ($ORGID) and (FReturnDate>=$endtime or FReturnDate<$starttime);
  407. --信贷资产出让单
  408. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_IBT_CredAsstTransOut')
  409. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_IBT_CredAsstTransOut where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  410. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_IBT_CredAsstTransOut')
  411. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_IBT_CredAsstTransOut where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  412. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_IBT_CredAsstTransOut')
  413. delete from T_IBT_CredAsstTransOut where FCompanyID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime);
  414. --信贷资产受让单
  415. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_IBT_CredAsstTransIn')
  416. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_IBT_CredAsstTransIn where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  417. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_IBT_CredAsstTransIn')
  418. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_IBT_CredAsstTransIn where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  419. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_IBT_CredAsstTransIn')
  420. delete from T_IBT_CredAsstTransIn where FCompanyID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime);
  421. --信贷资产出让回购单
  422. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_IBT_CreditAssRetOut')
  423. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_IBT_CreditAssRetOut where FCOMPANYID in ($ORGID) and (FReturnDate>=$endtime or FReturnDate<$starttime));
  424. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_IBT_CreditAssRetOut')
  425. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_IBT_CreditAssRetOut where FCOMPANYID in ($ORGID) and (FReturnDate>=$endtime or FReturnDate<$starttime));
  426. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_IBT_CreditAssRetOut')
  427. delete from T_IBT_CreditAssRetOut where FCompanyID in ($ORGID) and (FReturnDate>=$endtime or FReturnDate<$starttime);
  428. --信贷资产受让回购单
  429. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_IBT_CreditAssRetIn')
  430. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_IBT_CreditAssRetIn where FCOMPANYID in ($ORGID) and (FReturnDate>=$endtime or FReturnDate<$starttime));
  431. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_IBT_CreditAssRetIn')
  432. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_IBT_CreditAssRetIn where FCOMPANYID in ($ORGID) and (FReturnDate>=$endtime or FReturnDate<$starttime));
  433. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_IBT_CreditAssRetIn')
  434. delete from T_IBT_CreditAssRetIn where FCompanyID in ($ORGID) and (FReturnDate>=$endtime or FReturnDate<$starttime);
  435. --票据转贴出单
  436. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_IBT_BillRediscountOut')
  437. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_IBT_BillRediscountOut where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  438. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_IBT_BillRediscountOut')
  439. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_IBT_BillRediscountOut where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  440. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_IBT_BillRediscountOut')
  441. delete from T_IBT_BillRediscountOut where FCompanyID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime);
  442. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_IBT_BillRediscountOut')
  443. delete from T_IBT_BillRediscountOutEntry where FParentID in (select FID from T_IBT_BillRediscountOut where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  444. --票据转贴入单
  445. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_IBT_BillRediscountIn')
  446. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_IBT_BillRediscountIn where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  447. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_IBT_BillRediscountIn')
  448. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_IBT_BillRediscountIn where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  449. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_IBT_BillRediscountIn')
  450. delete from T_IBT_BillRediscountIn where FCompanyID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime);
  451. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_IBT_BillRediscountIn')
  452. delete from T_IBT_BillRediscountInEntry where FParentID in (select FID from T_IBT_BillRediscountIn where FCOMPANYID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime));
  453. --票据转贴出回购单
  454. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_IBT_BillRedRetOut')
  455. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_IBT_BillRedRetOut where FCOMPANYID in ($ORGID) and (FReturnDate>=$endtime or FReturnDate<$starttime));
  456. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_IBT_BillRedRetOut')
  457. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_IBT_BillRedRetOut where FCOMPANYID in ($ORGID) and (FReturnDate>=$endtime or FReturnDate<$starttime));
  458. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_IBT_BillRedRetOut')
  459. delete from T_IBT_BillRedRetOut where FCompanyID in ($ORGID) and (FReturnDate>=$endtime or FReturnDate<$starttime);
  460. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_IBT_BillRedRetOut')
  461. delete from T_IBT_BillRedRetOutEntry where FParentID in (select FID from T_IBT_BillRedRetOut where FCOMPANYID in ($ORGID) and (FReturnDate>=$endtime or FReturnDate<$starttime));
  462. --票据转贴入回购单
  463. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_IBT_BillRedRetIn')
  464. delete from T_BOT_RELATION where FSRCOBJECTID in (select FID from T_IBT_BillRedRetIn where FCOMPANYID in ($ORGID) and (FReturnDate>=$endtime or FReturnDate<$starttime));
  465. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_IBT_BillRedRetIn')
  466. delete from T_BOT_RELATION where FDestObjectID in (select FID from T_IBT_BillRedRetIn where FCOMPANYID in ($ORGID) and (FReturnDate>=$endtime or FReturnDate<$starttime));
  467. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_IBT_BillRedRetIn')
  468. delete from T_IBT_BillRedRetIn where FCompanyID in ($ORGID) and (FReturnDate>=$endtime or FReturnDate<$starttime);
  469. IF EXISTS (SELECT * FROM KSQL_USERTABLES WHERE KSQL_TABNAME='T_IBT_BillRedRetIn')
  470. delete from T_IBT_BillRedRetInEntry where FParentID in (select FID from T_IBT_BillRedRetIn where FCOMPANYID in ($ORGID) and (FReturnDate>=$endtime or FReturnDate<$starttime));
  471. ----------------13基础资料
  472. --1、 选择清理公司后,需将清理公司对应的银行账户全部删除;
  473. --delete from T_BD_AccountBanks where FCompanyID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime);
  474. --子账户
  475. --delete from T_CAS_SubAccount where FCompanyID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime);
  476. --内部账户
  477. --delete from T_FS_InnerAccount where FCompanyID in ($ORGID) and (FBizDate>=$endtime or FBizDate<$starttime);
  478. update T_FIN_FeeManage set FFiVouchered=0 where FFiVouchered is null;
  479. IF NOT EXISTS (SELECT * FROM KSQL_USERCOLUMNS WHERE KSQL_COL_NAME ='FFiVouchered' AND KSQL_COL_TABNAME='T_FIN_FeeManage' and ksql_col_default is not null)
  480. ALTER TABLE T_FIN_FeeManage ADD DEFAULT 0 for FFiVouchered;