交易视图

CREATE OR REPLACE VIEW SETT_VTRANSACTION
(id, serialno, officeid, currencyid, transno, transactiontypeid, operationtypeid, intereststart, execute, statusid, inputuserid, checkuserid, abstract, payclientid, payaccountid, payamount, receiveamount, receiveclientid, receiveaccountid, bankid, contractid, loanformid, depositno, newdepositno, payaccountno, payaccountname, receiveaccountno, receiveaccountname, payclientcode, payclientname, receiveclientcode, receiveclientname, declarationno, bankchequeno, source, applycode, commitionaccountcode, isdifoffice, payofficeid, receiveofficeid, parentofficeid, paybakaccountno, receivebakaccountno, oppcurrencyid, dtcleardate)
AS
select
ID, --交易ID
SerialNo,--序列号
OfficeID,--办事处ID
CurrencyID,--币种ID
TransNo,--交易号
TransactionTypeID,--交易类型
nOperationTypeID,--特殊交易子类型
InterestStart,--起息日
Execute,--执行日
StatusID,--状态ID
InputUserID,--录入人ID
CheckUserID,--复核人ID
Abstract,--摘要
PayClientID,--付款客户ID
PayAccountID,--付款帐户ID
PayAmount,--付款金额
ReceiveAmount,--收款金额
ReceiveClientID,--收款客户ID
ReceiveAccountID,--收款帐户ID
BankID,--开户行ID
ContractID,--合同ID
LoanFormID,--放款通知单ID
DepositNo,--存款单据号
NewDepositNo,--新存款单据号
PayAccountNo,--付款帐户编号
PayAccountName,--付款帐户名称
ReceiveAccountNo,--收款帐户编号
ReceiveAccountName,--收款帐户名称
PayClientCode,--付款客户编号
PayClientName,--付款客户名称
ReceiveClientCode,--收款客户编号
ReceiveClientName,--收款客户名称
DeclarationNo,----报单号
BankChequeNo, --银行支票号
Source,--数据来源(1柜台 2网银 3银行 4以上的见ep_extsystem)
ApplyCode,--申请指令编号
CommitionAccountCode,  --手续费帐户编号
Isdifoffice, --是否通存通兑
Payofficeid,--付方办事处
Receiveofficeid,--收方办事处
Parentofficeid, --总部ID
paybakaccountno, --付方备付金账号
receivebakaccountno, --收方备付金账号
oppcurrencyid,--对手币种ID
dtcleardate--清算日
from (
select a.ID ID, --交易ID
a.nSerialNo SerialNo,--序列号
a.nOfficeID OfficeID,--办事处ID
a.nCurrencyID CurrencyID,--币种ID
a.sTransNo TransNo,--交易号
a.nTransactionTypeID TransactionTypeID,--交易类型
a.nOperationTypeID,--特殊交易子类型
a.dtInterestStart InterestStart,--起息日
a.dtExecute Execute,--执行日
a.nStatusID StatusID,--状态ID
a.nInputUserID InputUserID,--录入人ID
a.nCheckUserID CheckUserID,--复核人ID
a.sAbstract Abstract,--摘要
d.ID PayClientID,--付款客户ID
a.nPayacCountID PayAccountID,--付款帐户ID
a.mPayAmount PayAmount,--付款金额
a.mReceiveAmount ReceiveAmount,--收款金额
e.ID ReceiveClientID,--收款客户ID
a.nReceiveAccountID ReceiveAccountID,--收款帐户ID
a.nBankID BankID,--开户行ID
a.nContractID ContractID,--合同ID
a.nLoanFormID LoanFormID,--放款通知单ID
a.sDepositNo DepositNo,--存款单据号
a.sNewDepositNo NewDepositNo,--新存款单据号
b.sAccountNo PayAccountNo,--付款帐户编号
b.sName PayAccountName,--付款帐户名称
c.sAccountNo ReceiveAccountNo,--收款帐户编号
c.sName ReceiveAccountName,--收款帐户名称
d.sCode PayClientCode,--付款客户编号
d.sName PayClientName,--付款客户名称
e.sCode ReceiveClientCode,--收款客户编号
e.sName ReceiveClientName,--收款客户名称
a.sDeclarationNo DeclarationNo,--报单号
a.sBankChequeNo BankChequeNo, --银行支票号
a.lSource Source,--数据来源(1柜台 2网银 3银行 4以上的见ep_extsystem)
a.sApplyCode ApplyCode,--申请指令编号
'' CommitionAccountCode,  --手续费帐户编号
a.Isdifoffice, --是否通存通兑
a.Payofficeid,--付方办事处
a.Receiveofficeid,--收方办事处
a.Parentofficeid, --总部ID
a.paybakaccountno, --付方备付金账号
a.receivebakaccountno, --收方备付金账号
a.oppcurrencyid,--对手币种ID
a.dtcleardate--清算日
from
(
  --定期/通知开立
  select ID,-1 nSerialNo,nOfficeID,nCurrencyID,sTransNo,nTransactionTypeID,-1 nOperationTypeID,dtInterestStart,dtExecute,nStatusID,nInputUserID,nCheckUserID,sAbstract,
     -1 nPayClientID,nCurrentAccountID nPayAccountID,mAmount mPayAmount,mAmount mReceiveAmount,-1 nReceiveClientID,nAccountID nReceiveAccountID,
      nBankID,-1 nContractID,-1 nLoanFormID,sDepositNo,'' sNewDepositNo,'' sDeclarationNo,'' sBankChequeNo,
      decode(nvl(sInstructionNo, ''), '', 1, (select decode(a.LSOURCE,-1,2,LSOURCE) from ob_financeinstr a where a.id=sInstructionNo)) lSource,sInstructionNo sApplyCode,
      -1 Isdifoffice,-1 Payofficeid,-1 Receiveofficeid,-1 Parentofficeid,
      '' paybakaccountno,'' receivebakaccountno,1 oppcurrencyid,dtExecute dtcleardate
  from Sett_TransOpenFixedDeposit
  union all
  --定期续期转存
  select ID,-1 nSerialNo,nOfficeID,nCurrencyID,sTransNo,nTransactionTypeID,-1 nOperationTypeID,dtInterestStart,dtExecute,nStatusID,nInputUserID,nCheckUserID,sAbstract,
     -1 nPayClientID,nAccountID nPayAccountID,mAmount mPayAmount,mAmount mReceiveAmount,-1 nReceiveClientID,nAccountID nReceiveAccountID,
     nCertificationBankID nBankID,-1 nContractID,-1 nLoanFormID,sDepositNo,sNewDepositNo,'' sDeclarationNo,'' sBankChequeNo,
     decode(nvl(sInstructionNo, ''), '', 1, (select decode(a.LSOURCE,-1,2,LSOURCE) from ob_financeinstr a where a.id=sInstructionNo)) lSource,sInstructionNo sApplyCode,
      -1 Isdifoffice,-1 Payofficeid,-1 Receiveofficeid,-1 Parentofficeid,
      '' paybakaccountno,'' receivebakaccountno,1 oppcurrencyid,dtExecute dtcleardate
  from Sett_TransFixedContinue
  union all
  --定期/通知支取
  select ID,-1 nSerialNo,nOfficeID,nCurrencyID,sTransNo,nTransactionTypeID,-1 nOperationTypeID,dtInterestStart,dtExecute,nStatusID,nInputUserID,nCheckUserID,sAbstract,
     -1 nPayClientID,nAccountID nPayAccountID,decode(mdrawamount,0,mamount,mdrawamount) mPayAmount,decode(mdrawamount,0,mamount,mdrawamount) mReceiveAmount,-1 nReceiveClientID,nCurrentAccountID nReceiveAccountID,
     nBankID,-1 nContractID,-1 nLoanFormID,sDepositNo,'' sNewDepositNo,'' sDeclarationNo,'' sBankChequeNo,
     decode(nvl(sInstructionNo, ''), '', 1, (select decode(a.LSOURCE,-1,2,LSOURCE) from ob_financeinstr a where a.id=sInstructionNo)) lSource,sInstructionNo sApplyCode,
      -1 Isdifoffice,-1 Payofficeid,-1 Receiveofficeid,-1 Parentofficeid,
      '' paybakaccountno,'' receivebakaccountno,1 oppcurrencyid,dtExecute dtcleardate
  from Sett_TransFixedWithDraw
  union all
    --保证金开立
  select ID,-1 nSerialNo,nOfficeID,nCurrencyID,sTransNo,nTransactionTypeID,-1 nOperationTypeID,dtInterestStart,dtExecute,nStatusID,nInputUserID,nCheckUserID,sAbstract,
     -1 nPayClientID,nCurrentAccountID nPayAccountID,mAmount mPayAmount,mAmount mReceiveAmount,nClientID nReceiveClientID,nAccountID nReceiveAccountID,
      nBankID,-1 nContractID,-1 nLoanFormID,sDepositNo,'' sNewDepositNo,'' sDeclarationNo,'' sBankChequeNo,
      decode(nvl(sInstructionNo,''),'',1,2) lSource,sInstructionNo sApplyCode,
      -1 Isdifoffice,-1 Payofficeid,-1 Receiveofficeid,-1 Parentofficeid,
      '' paybakaccountno,'' receivebakaccountno,1 oppcurrencyid,dtExecute dtcleardate
  from sett_transopenmargindeposit
  union all
    --保证金支取
   select ID,-1 nSerialNo,nOfficeID,nCurrencyID,sTransNo,nTransactionTypeID,-1 nOperationTypeID,dtInterestStart,dtExecute,nStatusID,nInputUserID,nCheckUserID,sAbstract,
    -1 nPayClientID,nAccountID nPayAccountID,decode(mdrawamount,0,mamount,mdrawamount) mPayAmount,decode(mdrawamount,0,mamount,mdrawamount) mReceiveAmount,-1 nReceiveClientID,nCurrentAccountID nReceiveAccountID,
      nBankID,-1 nContractID,-1 nLoanFormID,sDepositNo,'' sNewDepositNo,'' sDeclarationNo,'' sBankChequeNo,
      decode(nvl(sInstructionNo,''),'',1,2) lSource,sInstructionNo sApplyCode,
      -1 Isdifoffice,-1 Payofficeid,-1 Receiveofficeid,-1 Parentofficeid,
      '' paybakaccountno,'' receivebakaccountno,1 oppcurrencyid,dtExecute dtcleardate
  from sett_transmarginwithdraw
  union all
  --贴现发放
  select ID,-1 nSerialNo,nOfficeID,nCurrencyID,sTransNo,nTransactionTypeID,-1 nOperationTypeID,dtInterestStart,dtExecute,nStatusID,nInputUserID,nCheckUserID,sAbstract,
    -1 nPayClientID,nDiscountAccountID,mDiscountBillAmount mPayAmount,mDiscountBillAmount mReceiveAmount,-1 nReceiveClientID,nDepositAccountID nReceiveAccountID,
      nBankID,nDiscountContractID nContractID,nDiscountNoteID nLoanFormID,'' sDepositNo,'' sNewDepositNo,'' sDeclarationNo,'' sBankChequeNo,
      1 lSource,'' sApplyCode,-1 Isdifoffice,-1 Payofficeid,-1 Receiveofficeid,-1 Parentofficeid,
      '' paybakaccountno,'' receivebakaccountno,1 oppcurrencyid,dtExecute dtcleardate
  from Sett_TransGrantDiscount
  union all
  --贴现收回
  select ID,-1 nSerialNo,nOfficeID,nCurrencyID,sTransNo,nTransactionTypeID,-1 nOperationTypeID,dtInterestStart,dtExecute,nStatusID,nInputUserID,nCheckUserID,sAbstract,
    -1 nPayClientID,nDepositAccountID nPayAccountID,mAmount mPayAmount,mAmount mReceiveAmount,-1 nReceiveClientID,nDiscountAccountID nReceiveAccountID,
     -1 nBankID,nDiscountContractID nContractID,nDiscountNoteID nLoanFormID,'' sDepositNo,'' sNewDepositNo,'' sDeclarationNo,'' sBankChequeNo,
     1 lSource,'' sApplyCode,-1 Isdifoffice,-1 Payofficeid,-1 Receiveofficeid,-1 Parentofficeid,
      '' paybakaccountno,'' receivebakaccountno,1 oppcurrencyid,dtExecute dtcleardate
  from Sett_TransRepaymentDiscount
  union all
  --信托/委托贷款发放
  select ID,-1 nSerialNo,nOfficeID,nCurrencyID,sTransNo,nTransactionTypeID,-1 nOperationTypeID,dtInterestStart,dtExecute,nStatusID,nInputUserID,nCheckUserID,sAbstract,
    -1 nPayClientID,NCONSIGNDEPOSITACCOUNTID nPayAccountID,mAmount mPayAmount,mAmount mReceiveAmount,-1 nReceiveClientID,nDepositAccountID nReceiveAccountID,
      nBankID,nLoanContractID nContractID,nLoanNoteID nLoanFormID,'' sDepositNo,'' sNewDepositNo,'' sDeclarationNo,'' sBankChequeNo,
      1 lSource,'' sApplyCode,-1 Isdifoffice,-1 Payofficeid,-1 Receiveofficeid,-1 Parentofficeid,
      '' paybakaccountno,'' receivebakaccountno,1 oppcurrencyid,dtExecute dtcleardate
  from Sett_TransGrantLoan
  union all
  --信托/委托贷款收回
  select ID,nSerialNo nSerialNo,nOfficeID,nCurrencyID,sTransNo,nTransactionTypeID,-1 nOperationTypeID,dtInterestStart,dtExecute,nStatusID,nInputUserID,nCheckUserID,sAbstract,
    -1 nPayClientID,nDepositAccountID nPayAccountID,mAmount mPayAmount,mAmount mReceiveAmount,-1 nReceiveClientID,nconsigndepositaccountid nReceiveAccountID,
      nBankID,nLoanContractID nContractID,nLoanNoteID nLoanFormID,'' sDepositNo,'' sNewDepositNo,'' sDeclarationNo,'' sBankChequeNo,
      1 lSource,'' sApplyCode,-1 Isdifoffice,-1 Payofficeid,-1 Receiveofficeid,-1 Parentofficeid,
      '' paybakaccountno,'' receivebakaccountno,1 oppcurrencyid,dtExecute dtcleardate
  from Sett_TransRepaymentLoan where nTransactionTypeID <> 45
  union all
  --特殊交易
  select ID,-1 nSerialNo,nOfficeID,nCurrencyID,sTransNo,nTransactionTypeID,nOperationTypeID,dtInterestStart,dtExecute,nStatusID,nInputUserID,nCheckUserID,sAbstract,
    -1 nPayClientID,nPayAccountID,mPayAmount,mReceiveAmount,-1 nReceiveClientID,nReceiveAccountID,
      -1 nBankID,-1 nContractID,-1 nLoanFormID,'' sDepositNo,'' sNewDepositNo,sDeclarationNo,sBankChequeNo,
      1 lSource,'' sApplyCode,-1 Isdifoffice,-1 Payofficeid,-1 Receiveofficeid,-1 Parentofficeid,
      '' paybakaccountno,'' receivebakaccountno,1 oppcurrencyid,dtExecute dtcleardate
  from Sett_TransSpecialOperation
  union all
  --总帐类交易
  select ID,-1 nSerialNo,nOfficeID,nCurrencyID,sTransNo,nTransactionTypeID,-1 nOperationTypeID,dtInterestStart,dtExecute,nStatusID,nInputUserID,nCheckUserID,sAbstract,
    -1 nPayClientID,nAccountID nPayAccountID,(nvl(mAmount,0)+nvl(mOne,0)+nvl(mTwo,0)+nvl(mThree,0)+nvl(mFour,0))/2 mPayAmount,
    (nvl(mAmount,0)+nvl(mOne,0)+nvl(mTwo,0)+nvl(mThree,0)+nvl(mFour,0))/2 mReceiveAmount,-1 nReceiveClientID,-1 nReceiveAccountID,
      -1 nBankID,-1 nContractID,-1 nLoanFormID,'' sDepositNo,'' sNewDepositNo,'' sDeclarationNo,'' sBankChequeNo,
      1 lSource,'' sApplyCode,-1 Isdifoffice,-1 Payofficeid,-1 Receiveofficeid,-1 Parentofficeid,
      '' paybakaccountno,'' receivebakaccountno,1 oppcurrencyid,dtExecute dtcleardate
  from Sett_TransGeneralLedger
  union
  --交易费用处理
  select ID,-1 nSerialNo,nOfficeID,nCurrencyID,sTransNo,nTransactionTypeID,-1 nOperationTypeID,dtInterestStart,dtExecute,nStatusID,nInputUserID,nCheckUserID,sAbstract,
    -1 nPayClientID,nAccountID nPayAccountID,mAmount mPayAmount,mAmount mReceiveAmount,-1 nReceiveClientID,-1 nReceiveAccountID,
      nFeeBankID nBankID,-1 nContractID,-1 nLoanFormID,'' sDepositNo,'' sNewDepositNo,'' sDeclarationNo,'' sBankChequeNo,
      1 lSource,'' sApplyCode,-1 Isdifoffice,-1 Payofficeid,-1 Receiveofficeid,-1 Parentofficeid,
      '' paybakaccountno,'' receivebakaccountno,1 oppcurrencyid,dtExecute dtcleardate
  from sett_TransFee
  union all
  --活期结息记录
  select ID,-1 nSerialNo,nOfficeID,nCurrencyID,sTransNo,1 nTransactionTypeID,-1 nOperationTypeID,dtInterestStart,dtExecute,nStatusID,nInputUserID,nCheckUserID,sAbstract,
     -1 nPayClientID,nAccountID nPayAccountID,mInterest mPayAmount,mInterest mReceiveAmount,-1 nReceiveClientID,nReceiveInterestAccountID nReceiveAccountID,
      -1 nBankID,-1 nContractID,-1 nLoanFormID,'' sDepositNo,'' sNewDepositNo,'' sDeclarationNo,'' sBankChequeNo,
      1 lSource,'' sApplyCode,-1 Isdifoffice,-1 Payofficeid,-1 Receiveofficeid,-1 Parentofficeid,
      '' paybakaccountno,'' receivebakaccountno,1 oppcurrencyid,dtExecute dtcleardate
  from Sett_TransCurrentClearInterest
  union all
  --一付多收(收)
  select ID,nSerialNo nSerialNo,nOfficeID,nCurrencyID,sTransNo,nTransactionTypeID,-1 nOperationTypeID,dtInterestStart,dtExecute,nStatusID,nInputUserID,nCheckUserID,sAbstract,
        nPayClientID,-1 nPayAccountID,mAmount mPayAmount,mAmount mReceiveAmount,nReceiveClientID,nAccountID nReceiveAccountID,
       nBankID,-1 nContractID,-1 nLoanFormID,'' sDepositNo,'' sNewDepositNo,sDeclarationNo,'' sBankChequeNo,
       1 lSource,'' sApplyCode,-1 Isdifoffice,-1 Payofficeid,-1 Receiveofficeid,-1 Parentofficeid,
      '' paybakaccountno,'' receivebakaccountno,1 oppcurrencyid,dtExecute dtcleardate
  from sett_TransOnePayMultiReceive where nTypeID=8
  union all
  --一付多收(付)
  select ID,nSerialNo nSerialNo,nOfficeID,nCurrencyID,sTransNo,nTransactionTypeID,-1 nOperationTypeID,dtInterestStart,dtExecute,nStatusID,nInputUserID,nCheckUserID,sAbstract,
        nPayClientID,nAccountID nPayAccountID,mAmount mPayAmount,mAmount mReceiveAmount,nReceiveClientID,-1 nReceiveAccountID,
       nBankID,-1 nContractID,-1 nLoanFormID,'' sDepositNo,'' sNewDepositNo,sDeclarationNo,'' sBankChequeNo,
       1 lSource,'' sApplyCode,-1 Isdifoffice,-1 Payofficeid,-1 Receiveofficeid,-1 Parentofficeid,
      '' paybakaccountno,'' receivebakaccountno,1 oppcurrencyid,dtExecute dtcleardate
  from sett_TransOnePayMultiReceive where nTypeID=9
  union all
  --结息记录,金额加上智能利息
  select t.ID,-1 nSerialNo,t.nOfficeID,t.nCurrencyID,t.sTransNo,t.nTransactionTypeID,-1 nOperationTypeID,t.dtInterestSettlement dtInterestStart,t.dtExecute,t.nStatusID,t.nInputUserID nInputUserID,-1 nCheckUserID,t.sAbstract,
    -1 nPayClientID,t.nPayInterestAccountID nPayAccountID,(t.mInterest+t.mNegotiateInterest+decode(t.mintelligentinterest,null,0,t.mintelligentinterest)) mPayAmount,(t.mInterest+t.mNegotiateInterest+decode(t.mintelligentinterest,null,0,t.mintelligentinterest)) mReceiveAmount,-1 nReceiveClientID,nReceiveInterestAccountID nReceiveAccountID,
      -1 nBankID,pf.nContractID nContractID,sa.al_nLoanNoteID nLoanFormID,sa.af_sDepositNo sDepositNo,'' sNewDepositNo,'' sDeclarationNo,'' sBankChequeNo,
      1 lSource,'' sApplyCode,-1 Isdifoffice,-1 Payofficeid,-1 Receiveofficeid,-1 Parentofficeid,
      '' paybakaccountno,'' receivebakaccountno,1 oppcurrencyid,dtExecute dtcleardate
  from sett_TransInterestSettlement t,sett_SubAccount sa,loan_PayForm pf
  where t.nSubAccountID=sa.ID and sa.al_nLoanNoteID=pf.ID(+)
  union all
  --转贴现计提交易
  select s.id,-1 nSerialNo,s.nofficeid, s.ncurrencyid, s.stransno, s.ntransactiontypeid,-1 nOperationTypeID,s.dtintereststart,s.dtmake, s.nstatusid, s.nmakeuserid, -1 nCheckUserID, s.sabstract,
        -1 nPayClientID,-1 nPayAccountID,s.mpredrawinterest mPayAmount, s.mpredrawinterest mReceiveAmount, -1 nReceiveClientID, -1 nReceiveAccountID,
        -1 nBankID,c.id nContractID, s.nnoticeid nLoanFormID,'' sDepositNo,'' sNewDepositNo,'' sDeclarationNo,'' sBankChequeNo,
          1 lSource,'' sApplyCode,-1 Isdifoffice,-1 Payofficeid,-1 Receiveofficeid,-1 Parentofficeid,
          '' paybakaccountno,'' receivebakaccountno,1 oppcurrencyid,s.dtmake dtcleardate
  from sett_crainterestpredraw s,loan_contractform c,loan_discountcredence d
  where s.nnoticeid = d.id
  and d.ncontractid = c.id
  union all
  --转贴现卖出自动冲销
  select ID,-1 nSerialNo,OfficeID nOfficeID,CurrencyID nCurrencyID,TransNo sTransNo,TransactionTypeID nTransactionTypeID,-1 nOperationTypeID,InterestStartDate dtInterestStart,ExecuteDate dtExecute,
         StatusID nStatusID,InputUserID nInputUserID,CheckUserID nCheckUserID,Abstract sAbstract,
         ClientID nPayClientID,AccountID nPayAccountID,TotalAmount mPayAmount,TotalAmount mReceiveAmount,ClientID nReceiveClientID,AccountID nReceiveAccountID,
         -1 nBankID,ContractID nContractID,DueBillID nLoanFormID,'' sDepositNo,'' sNewDepositNo,'' sDeclarationNo,'' sBankChequeNo,
         1 lSource,'' sApplyCode,-1 Isdifoffice,-1 Payofficeid,-1 Receiveofficeid,-1 Parentofficeid,
         '' paybakaccountno,'' receivebakaccountno,1 oppcurrencyid,EXECUTEDATE dtcleardate
  from sett_TransAbatement
  union all
  --挂失、解挂、换发证书、冻结、解冻
  select ID,-1 nSerialNo,OfficeID nOfficeID,CurrencyID nCurrencyID,TransNo sTransNo,TransactionType nTransactionTypeID,-1 nOperationTypeID,
         Effectivedate dtInterestStart,ExecuteDate dtExecute,Status nStatusID,InputUserID nInputUserID,CheckUserID nCheckUserID,Abstract sAbstract,
        ClientID nPayClientID,AccountID nPayAccountID,FreezeAmount mPayAmount,FreezeAmount mReceiveAmount,ClientID nReceiveClientID,AccountID nReceiveAccountID,
       -1 nBankID,-1 nContractID,-1 nLoanFormID,OldDepositNo sDepositNo,NewDepositNo sNewDepositNo,'' sDeclarationNo,'' sBankChequeNo,
       1 lSource,'' sApplyCode,-1 Isdifoffice,-1 Payofficeid,-1 Receiveofficeid,-1 Parentofficeid,
      '' paybakaccountno,'' receivebakaccountno,1 oppcurrencyid,ExecuteDate dtcleardate
  from sett_reportlossorfreeze
  union all
  --表外业务
  select ID,-1 nSerialNo,OfficeID nOfficeID,CurrencyID nCurrencyID,TransNo sTransNo,TransactionType nTransactionTypeID,-1 nOperationTypeID,null dtInterestStart,
        ExecuteDate dtExecute,StatusID nStatusID,InputUserID nInputUserID,CheckUserID nCheckUserID,Abstract sAbstract,
        borrowClientID nPayClientID,loanAccountID nPayAccountID,Amount mPayAmount,Amount mReceiveAmount,consignClientID nReceiveClientID,consignAccountID nReceiveAccountID,
       -1 nBankID,ContractID nContractID,LoanNoteID nLoanFormID,'' sDepositNo,'' sNewDepositNo,'' sDeclarationNo,'' sBankChequeNo,
       1 lSource,'' sApplyCode,-1 Isdifoffice,-1 Payofficeid,-1 Receiveofficeid,-1 Parentofficeid,
      '' paybakaccountno,'' receivebakaccountno,1 oppcurrencyid,ExecuteDate dtcleardate
  from sett_offbalance
    union all
  --交易手续费收取
  select ID,-1 nSerialNo,OfficeID nOfficeID,CurrencyID nCurrencyID,TransNo sTransNo,TransactionTypeID nTransactionTypeID,-1 nOperationTypeID,
         ExecuteDate dtInterestStart,ExecuteDate dtExecute ,statusID nStatusID ,InputUserID nInputUserID,InputUserID nCheckUserID,Abstract sAbstract,
         -1 nPayClientID,accountID nPayAccountID,sum(CommissionAmount) mPayAmount,sum(CommissionAmount) mReceiveAmount,-1 nReceiveClientID,-1 nReceiveAccountID,
         -1 nBankID,-1 nContractID,-1 nLoanFormID,'' sDepositNo,'' sNewDepositNo,'' sDeclarationNo,'' sBankChequeNo,
         1 lSource,'' sApplyCode,-1 Isdifoffice,-1 Payofficeid,-1 Receiveofficeid,-1 Parentofficeid,
      '' paybakaccountno,'' receivebakaccountno,1 oppcurrencyid,ExecuteDate dtcleardate
    from sett_transcommission
    group by id,officeid,currencyid,transactiontypeid,accountid,executedate,inputuserid,
    statusid,transno,abstract
--外汇交易
     union all
                   SELECT id,
                          -1 nSerialNo,
                          NOFFICEID OfficeID,
                          NCURRENCYID CurrencyID,
                          STRANSNO TransNo,
                          NTRANSTYPEID TransactionTypeID,
                          -1 nOperationTypeID,
                          DTINTERESTSTART InterestStart,
                          DTEXECUTEDATE dtExecute,
                          NSTATUSID nStatusID,
                          NINPUTUSERID nInputUserID,
                          NCHECKUSERID nCheckUserID,
                          sAbstract sAbstract,
                          -1 nPayClientID,
                          decode(NTRANSTYPEID,1101,NFOREIGNACCOUNTID,1103,NFOREIGNACCOUNTID,1121,NFOREIGNACCOUNTID,1123,NFOREIGNACCOUNTID,
                             NRMBACCOUNTID) nPayAccountID,
  decode(NSTATUSID,3,MFACTRMBAMOUNT,8,MFACTRMBAMOUNT,21,MFACTRMBAMOUNT,22,MFACTRMBAMOUNT,MRMBAMOUNT ) mPayAmount,
  MAMOUNT  mReceiveAmount,
   -1 nReceiveClientID ,
   decode(NTRANSTYPEID,1101,NRMBACCOUNTID,1103,NRMBACCOUNTID,1121,NRMBACCOUNTID,1123,NRMBACCOUNTID,NFOREIGNACCOUNTID) nReceiveAccountID,
   -1  nBankID,
   -1 nContractID,
   -1 nLoanFormID,
   '' sDepositNo,
   ''sNewDepositNo,
   '' sDeclarationNo,'' sBankChequeNo,
         1 lSource,'' sApplyCode,-1 Isdifoffice,-1 Payofficeid,-1 Receiveofficeid,-1 Parentofficeid,
      '' paybakaccountno,'' receivebakaccountno,
   2 oppcurrencyid,
   dtcleardate
   from
       FE_TRANSFOREIGNEXCHANGE
   --平盘业务
   union all
   SELECT id,
                          -1 nSerialNo,
                          NOFFICEID OfficeID,
                          NCURRENCYID CurrencyID,
                          STRANSNO TransNo,
                          NTRANSTYPEID TransactionTypeID,
                          -1 nOperationTypeID,
                          DTEXECUTEDATE InterestStart,
                          DTEXECUTEDATE dtExecute,
                          NSTATUSID nStatusID,
                          NINPUTUSERID nInputUserID,
                          NCHECKUSERID nCheckUserID,
                          SABSTRACT sAbstract,
                          -1 nPayClientID,
                          -1 nPayAccountID,
   decode(NSTATUSID,3,MFACTRMBAMOUNT,8,MFACTRMBAMOUNT,21,MFACTRMBAMOUNT,22,MFACTRMBAMOUNT,MAMOUNT)  mPayAmount,
   MFAMOUNT mReceiveAmount,
   -1 nReceiveClientID ,
   -1 nReceiveAccountID,
   -1  nBankID,
   -1 nContractID,
   -1 nLoanFormID,
   '' sDepositNo,
   ''sNewDepositNo,
   '' sDeclarationNo,'' sBankChequeNo,
         1 lSource,'' sApplyCode,-1 Isdifoffice,-1 Payofficeid,-1 Receiveofficeid,-1 Parentofficeid,
      '' paybakaccountno,'' receivebakaccountno,
   2 oppcurrencyid,
   dtcleardate
   from
       fe_foreignbalance

) a,sett_Account b,sett_Account c,Client d,Client e
where a.nPayAccountID=b.ID(+) and  a.nReceiveAccountID=c.ID(+)
      and b.nClientID=d.ID(+) and c.nClientID=e.ID(+)

  --修改利息费用支付
  union all
    select a.ID ID, --交易ID
       a.nSerialNo SerialNo, --序列号
       a.nOfficeID OfficeID, --办事处ID
       a.nCurrencyID CurrencyID, --币种ID
       a.sTransNo TransNo, --交易号
       a.nTransactionTypeID TransactionTypeID, --交易类型
       a.nOperationTypeID, --特殊交易子类型
       a.dtInterestStart InterestStart, --起息日
       a.dtExecute Execute, --执行日
       a.nStatusID StatusID, --状态ID
       a.nInputUserID InputUserID, --录入人ID
       a.nCheckUserID CheckUserID, --复核人ID
       a.sAbstract Abstract, --摘要
       a.nclientid PayClientID, --付款客户ID
       a.nPayacCountID PayAccountID, --付款帐户ID
       a.mPayAmount PayAmount, --付款金额
       a.mReceiveAmount ReceiveAmount, --收款金额
       l.nconsignclientid ReceiveClientID, --收款客户ID
       a.nReceiveAccountID ReceiveAccountID, --收款帐户ID
       a.nBankID BankID, --开户行ID
       a.nContractID ContractID, --合同ID
       a.nLoanFormID LoanFormID, --放款通知单ID
       a.sDepositNo DepositNo, --存款单据号
       a.sNewDepositNo NewDepositNo, --新存款单据号
       b.sAccountNo PayAccountNo, --付款帐户编号
       b.sName PayAccountName, --付款帐户名称
       c.sAccountNo ReceiveAccountNo, --收款帐户编号
       c.sName ReceiveAccountName, --收款帐户名称
       d.sCode PayClientCode, --付款客户编号
       d.sName PayClientName, --付款客户名称
       e.sCode ReceiveClientCode, --收款客户编号
       e.sName ReceiveClientName, --收款客户名称
       a.sDeclarationNo DeclarationNo, --报单号
       a.sBankChequeNo BankChequeNo, --银行支票号
       a.lSource Source, --数据来源(1柜台 2网银 3银行 4以上的见ep_extsystem)
       a.sApplyCode ApplyCode, --申请指令编号
       f.saccountno CommitionAccountCode  --手续费帐户编号
       ,-1 Isdifoffice,-1 Payofficeid,-1 Receiveofficeid,-1 Parentofficeid,
      '' paybakaccountno,'' receivebakaccountno,1 oppcurrencyid,a.dtExecute dtcleardate
  from (
        select ID,
                nSerialNo nSerialNo,
                nOfficeID,
                nCurrencyID,
                sTransNo,
                nTransactionTypeID,
                -1 nOperationTypeID,
                dtInterestStart,
                dtExecute,
                nStatusID,
                nInputUserID,
                nCheckUserID,
                sAbstract,
                -1 nPayClientID,
                nPayInterestAccountID nPayAccountID,
                (mRealInterest + mRealCompoundInterest + mRealOverDueInterest +
                mRealSuretyFee + mRealCommission) mPayAmount,
                (mRealInterest + mRealCompoundInterest + mRealOverDueInterest +
                mRealSuretyFee + mRealCommission) mReceiveAmount,
                -1 nReceiveClientID,
                decode(nReceiveInterestAccountID,
                       '-1',
                       NRECEIVESUERTYFEEACCOUNTID,
                       nReceiveInterestAccountID) nReceiveAccountID,
                nBankID,
                nLoanContractID nContractID,
                nLoanNoteID nLoanFormID,
                '' sDepositNo,
                '' sNewDepositNo,
                '' sDeclarationNo,
                '' sBankChequeNo,
                1 lSource,
                '' sApplyCode,
                nclientid,
                NCOMMISSIONACCOUNTID
          from Sett_TransRepaymentLoan
         where nTransactionTypeID = 45
        ) a,
       sett_Account b,
       sett_Account c,
       Client d,
       Client e,
       sett_Account f,
       loan_contractForm l
 where a.nPayAccountID = b.ID(+)
   and a.nReceiveAccountID = c.ID(+)
   and a.NCOMMISSIONACCOUNTID = f.id(+)
   and b.nClientID = d.ID(+)
   and c.nClientID = e.ID(+)
   and a.nContractID = l.id
  union all
  select t.ID ID, --交易ID
  t.nSerialNo SerialNo,--序列号
  t.nOfficeID OfficeID,--办事处ID
  t.nCurrencyID CurrencyID,--币种ID
  t.sTransNo TransNo,--交易号
  t.nTransactionTypeID TransactionTypeID,--交易类型
  t.nOperationTypeID,--特殊交易子类型
  t.dtInterestStart InterestStart,--起息日
  t.dtExecute Execute,--执行日
  t.nStatusID StatusID,--状态ID
  t.nInputUserID InputUserID,--录入人ID
  t.nCheckUserID CheckUserID,--复核人ID
  t.sAbstract Abstract,--摘要
  d.ID PayClientID,--付款客户ID
  t.nPayacCountID PayAccountID,--付款帐户ID
  t.mPayAmount PayAmount,--付款金额
  t.mReceiveAmount ReceiveAmount,--收款金额
  -1 ReceiveClientID,--收款客户ID
  t.nReceiveAccountID ReceiveAccountID,--收款帐户ID
  t.nBankID BankID,--开户行ID
  t.nContractID ContractID,--合同ID
  t.nLoanFormID LoanFormID,--放款通知单ID
  t.sDepositNo DepositNo,--存款单据号
  t.sNewDepositNo NewDepositNo,--新存款单据号
  decode(t.nTransactionTypeID,1,t.sExtAccountNo,231,t.sExtAccountNo,232,t.sExtAccountNo,233,t.sExtAccountNo,b.sAccountNo) PayAccountNo,--付款帐户编号
  decode(t.nTransactionTypeID,1,t.sExtClientName,231,t.sExtClientName,232,t.sExtClientName,233,t.sExtClientName,b.sName) PayAccountName,--付款帐户名称
  decode(t.nTransactionTypeID,2,t.sExtAccountNo,221,t.sExtAccountNo,222,t.sExtAccountNo,c.sAccountNo) ReceiveAccountNo,--收款帐户编号
  decode(t.nTransactionTypeID,2,t.sExtClientName,221,t.sExtClientName,222,t.sExtClientName,c.sName) ReceiveAccountName,--收款帐户名称
  decode(t.nTransactionTypeID,1,'',231,'',232,'',233,'',d.sCode) PayClientCode,--付款客户编号
  decode(t.nTransactionTypeID,1,'',231,'',232,'',233,'',d.sName) PayClientName,--付款客户名称
  decode(t.nTransactionTypeID,2,'',221,'',222,'',e.sCode) ReceiveClientCode,--收款客户编号
  decode(t.nTransactionTypeID,2,'',221,'',222,'',e.sName) ReceiveClientName,--收款客户名称
  t.sDeclarationNo DeclarationNo,--报单号
  t.sBankChequeNo BankChequeNo,--银行支票号
  t.lSource Source,--数据来源(1柜台 2网银 3银行 4以上的见ep_extsystem)
  t.sApplyCode ApplyCode,--申请指令编号
  '' CommitionAccountCode  --手续费帐户编号
  ,t.Isdifoffice,t.Payofficeid,t.Receiveofficeid,t.Parentofficeid,
  '' paybakaccountno,'' receivebakaccountno,1 oppcurrencyid,t.dtExecute dtcleardate
  from
  --活期交易, 银行收款交易的付款方显示为外部账户,银行付款交易的收款方显示为外部账户
  (
select ID,-1 nSerialNo,nOfficeID,nCurrencyID,sTransNo,nTransactionTypeID,-1 nOperationTypeID,dtInterestStart,dtExecute,nStatusID,nInputUserID,nCheckUserID,sAbstract,
        nPayClientID,nPayAccountID,mAmount mPayAmount,mAmount mReceiveAmount,nReceiveClientID,nReceiveAccountID,
       nBankID,-1 nContractID,-1 nLoanFormID,'' sDepositNo,'' sNewDepositNo,sDeclarationNo,sBankChequeNo, sExtAccountNo,sExtClientName,
       decode(nvl(lSource,'-1'),'-1',decode(nvl(sInstructionNo,''),'',1,3),lSource) lSource,sApplyCode,
       nvl(Isdifoffice,-1) Isdifoffice,
       nvl(Payofficeid,-1) Payofficeid,
       nvl(Receiveofficeid,-1) Receiveofficeid,
       nvl(Parentofficeid,-1) Parentofficeid,
       (select liqdetail.sdebit from sett_liquidation liq,sett_liquidationdetail liqdetail
       where liq.id=liqdetail.nliquidationid
       and liq.stransno=Sett_TransCurrentDeposit.sTransno and liqdetail.nofficeid=1
       and liqdetail.nstatusid=1 and liq.statusid>0) paybakaccountno,
       (select liqdetail.scredit from sett_liquidation liq,sett_liquidationdetail liqdetail
       where liq.id=liqdetail.nliquidationid
       and liq.stransno=Sett_TransCurrentDeposit.sTransno and liqdetail.nofficeid=1
       and liqdetail.nstatusid=1 and liq.statusid>0) receivebakaccountno
  from Sett_TransCurrentDeposit

  )t,
    sett_Account b,sett_Account c,Client d,Client e
where t.nPayAccountID=b.ID(+) and  t.nReceiveAccountID=c.ID(+)
      and b.nClientID=d.ID(+) and c.nClientID=e.ID(+)
   )
;
 

发布了66 篇原创文章 · 获赞 19 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/hwq293/article/details/102911165