create view vi_actual_fund_plan as SELECT LCI.ID                                                                              AS ID,
       LCI.CONTRACT_NUMBER                                                                 AS CONTRACT_NUMBER,
       LCI.PRODUCT_ID                                                                      AS PRODUCT_ID,
       PSL.PAYTYPE                                                                         AS PAYTYPE,
       LUL.CUSTOMER_NAME                                                                   AS CUSTOMER_NAME,
       LFI.ID                                                                              AS PLAN_ID,
       LFI.PAYMENT_NUMBER                                                                  AS PAYMENT_NUMBER,
       (CASE WHEN (DR.ISRENTER = 'Y') THEN LUL.CUSTOMER_NAME ELSE DI.DISTRIBUTOR_NAME END) AS OBJECTNAME,
       LFI.SETTLE_METHOD                                                                   AS SETTLE_METHOD,
       LFI.FACT_MONEY                                                                      AS FACT_MONEY,
       LFI.FACT_DATE                                                                       AS FACT_DATE,
       UI.USERNAME                                                                         AS USERNAME,
       OI.ORGNAME                                                                          AS ORGNAME,
       LCIOI.ORGNAME                                                                       AS CHANNEL_NAME,
       LFI.BANK                                                                            AS BANK,
       LFI.ACCOUNT                                                                         AS ACCOUNT,
       LFI.FACT_OBJECT                                                                     AS FACT_OBJECT,
       LFI.ACC_NUMBER                                                                      AS ACC_NUMBER,
       DA.OPEN_BANK                                                                        AS CLIENT_BANK,
       DA.ACCOUNT                                                                          AS CLIENT_ACCOUNT,
       DA.ACC_NUMBER                                                                       AS CLIENT_ACCNUMBER,
       LCI.PROJECT_ID                                                                      AS PROJECT_ID,
       (
           SELECT sum(`nvl`(VLFP.OVERMONEY, 0)) FROM APZL.VI_LC_FUND_PLAN VLFP WHERE (VLFP.CONTRACT_ID = LCI.ID)
       )                                                                                   AS OVERMONEY,
       lci.subjectname 						AS 							subjectName
FROM ((((((((((APZL.LB_CONTRACT_INFO LCI LEFT JOIN APZL.PRD_SPECIFIC_LIBRARY PSL ON ((LCI.PRODUCT_ID= PSL.PRODUCTID))) LEFT JOIN APZL.LB_UNION_LESSEE LUL ON (((LUL.CONTRACT_ID = LCI.ID) AND (LUL.IS_MAIN = 'Y')))) LEFT JOIN APZL.LC_FUND_INCOME LFI ON ((
        (LFI.CONTRACT_ID = LCI.ID) AND (LFI.FEE_TYPE = 'feetype10') AND
        (LFI.SETTLE_METHOD <> 'settlemethod11')))) LEFT JOIN APZL.DISTRIBUTOR_RECEIVABLES DR ON ((DR.CONTRACT_ID = LCI.ID))) LEFT JOIN APZL.DISTRIBUTOR_INFO DI ON (((DI.ID = LFI.FACT_OBJECT) AND ((CASE WHEN (DR.ISRENTER = 'Y') THEN 2 ELSE 1 END) = 1)))) LEFT JOIN APZL.CUSTOMER_INFO CI ON ((
        (CI.CUSTOMERID = LFI.FACT_OBJECT) AND
        ((CASE WHEN (DR.ISRENTER = 'Y') THEN 2 ELSE 1 END) = 2)))) LEFT JOIN APZL.USER_INFO UI ON ((UI.USERID = LFI.APPLY_PERSON))) LEFT JOIN APZL.ORG_INFO OI ON ((OI.ORGID = LFI.APPLY_DEPT))) LEFT JOIN APZL.ORG_INFO LCIOI ON ((LCIOI.ORGID = LCI.INPUTORGID)))
LEFT JOIN APZL.DISTRIBUTOR_ACCOUNT DA ON ((if(isnull(LFI.DISTRIBUTOR_ID), LCI.DISTRIBUTOR_ID, LFI.DISTRIBUTOR_ID) = DA.DISTRIBUTOR_ID)))
WHERE ((LCI.CONTRACT_STATUS = '21') AND (LCI.BUSINESSTYPE = '1') AND (LFI.PAY_STATUS = 'apply_pass') AND (DA.IS_MAIN = 'Y') AND (NOT (exists(SELECT 1
                                                                                                                                             FROM APZL.LC_FUND_INCOME_TEMP
                                                                                                                                             WHERE ((APZL.LC_FUND_INCOME_TEMP.PLAN_ID = LFI.PLAN_ID) AND
                                                                                                                                                    (APZL.LC_FUND_INCOME_TEMP.IS_FLOWING = '0'))))));

-- comment on column vi_actual_fund_plan.id not supported: 编号

-- comment on column vi_actual_fund_plan.contract_number not supported: 业务合同号

-- comment on column vi_actual_fund_plan.product_id not supported: 产品ID

-- comment on column vi_actual_fund_plan.payType not supported: 放款方式

-- comment on column vi_actual_fund_plan.customer_name not supported: 承租人名称

-- comment on column vi_actual_fund_plan.plan_id not supported: 标识

-- comment on column vi_actual_fund_plan.payment_number not supported: 投放编号

-- comment on column vi_actual_fund_plan.settle_method not supported: 结算方式

-- comment on column vi_actual_fund_plan.fact_money not supported: 收支金额

-- comment on column vi_actual_fund_plan.fact_date not supported: 收支日期

-- comment on column vi_actual_fund_plan.username not supported: 用户姓名

-- comment on column vi_actual_fund_plan.orgname not supported: 机构名称

-- comment on column vi_actual_fund_plan.channel_name not supported: 机构名称

-- comment on column vi_actual_fund_plan.bank not supported: 银行名称

-- comment on column vi_actual_fund_plan.ACCOUNT not supported: 帐户名称

-- comment on column vi_actual_fund_plan.FACT_OBJECT not supported: 收支对象

-- comment on column vi_actual_fund_plan.ACC_NUMBER not supported: 银行帐号

-- comment on column vi_actual_fund_plan.CLIENT_BANK not supported: 开户银行

-- comment on column vi_actual_fund_plan.CLIENT_ACCOUNT not supported: 账户名称

-- comment on column vi_actual_fund_plan.CLIENT_ACCNUMBER not supported: 银行帐号

-- comment on column vi_actual_fund_plan.project_id not supported: 项目编号

