create view vi_paymentcertificate as SELECT O.ID              AS ID,
       O.CONTRACT_NUMBER AS CONTRACT_NUMBER,
       O.CUSTOMER_ID     AS CUSTOMER_ID,
       O.CUSTOMER_NAME   AS CUSTOMER_NAME,
       O.COLLECT_STATUS  AS COLLECT_STATUS,
       O.COLLECT_MSG     AS COLLECT_MSG,
       O.PLAN_LIST       AS PLAN_LIST,
       O.PLAN_DATE       AS PLAN_DATE,
       O.FACT_RENT       AS FACT_RENT,
       O.FACT_CORPUS     AS FACT_CORPUS,
       O.FACT_INTEREST   AS FACT_INTEREST,
       O.RENT            AS RENT,
       O.CORPUS          AS CORPUS,
       O.INTEREST        AS INTEREST,
       LRI.PENALTY       AS PENALTY,
       O.BANK_NAME       AS BANK_NAME,
       O.ACCOUNT         AS ACCOUNT,
       O.ACC_NUMBER      AS ACC_NUMBER,
       O.CUSTOMER_NUM    AS CUSTOMER_NUM,
       O.CUSTOMERNAME    AS CUSTOMERNAME
FROM (((
    SELECT LCRP.ID                                                           AS ID,
           LCRP.CONTRACT_ID                                                  AS CONTRACT_ID,
           LCI.CONTRACT_NUMBER                                               AS CONTRACT_NUMBER,
           CIF.CUSTOMER_NUM                                                  AS CUSTOMER_NUM,
           CIF.CUSTOMERNAME                                                  AS CUSTOMERNAME,
           LUL.CUSTOMER_ID                                                   AS CUSTOMER_ID,
           LUL.CUSTOMER_NAME                                                 AS CUSTOMER_NAME,
           LCRP.PLAN_LIST                                                    AS PLAN_LIST,
           LCRP.PLAN_DATE                                                    AS PLAN_DATE,
           LCRP.RENT                                                         AS FACT_RENT,
           LCRP.CORPUS                                                       AS FACT_CORPUS,
           LCRP.INTEREST                                                     AS FACT_INTEREST,
           ((LCRP.RENT - `nvl`(LCFI.RENT, 0)) + `nvl`(VIRP.PENALTY_OVER, 0)) AS RENT,
           (LCRP.CORPUS - `nvl`(LCFI.CORPUS, 0))                             AS CORPUS,
           (LCRP.INTEREST - `nvl`(LCFI.INTEREST, 0))                         AS INTEREST,
           `nvl`(VIRP.PENALTY_OVER, 0)                                       AS PENALTY,
           CAT.BANK_NAME                                                     AS BANK_NAME,
           CAT.ACCOUNT                                                       AS ACCOUNT,
           CAT.ACC_NUMBER                                                    AS ACC_NUMBER,
           CAT.MOBILE                                                        AS MOBILE,
           ifnull(CAT.SIGN_STATUS, 'N')                                      AS SIGN_STATUS,
           ifnull(LCRP.AUDIT_STATE, 'N')                                     AS AUDIT_STATE,
           ifnull(LCRP.COLLECT_STATUS, '未收款')                                AS COLLECT_STATUS,
           ifnull(LCRP.COLLECT_MSG, '')                                      AS COLLECT_MSG,
           LCRP.FAILURE_TIME                                                 AS FAILURE_TIME,
           LCRP.FAILURE_REASON                                               AS FAILURE_REASON,
           LCRP.BATCH_STATUS                                                 AS BATCH_STATUS,
           LCRP.BATCH_NO                                                     AS BATCH_NO,
           LCRP.BATCH_SN                                                     AS BATCH_SN
    FROM ((((((APZL.LC_RENT_PLAN LCRP LEFT JOIN (
        SELECT APZL.LC_RENT_INCOME.PAYMENT_NUMBER       AS PAYMENT_NUMBER,
               APZL.LC_RENT_INCOME.PLAN_LIST            AS PLAN_LIST,
               APZL.LC_RENT_INCOME.PLAN_ID              AS PLAN_ID,
               sum(APZL.LC_RENT_INCOME.RENT)            AS RENT,
               sum(APZL.LC_RENT_INCOME.CORPUS)          AS CORPUS,
               sum(APZL.LC_RENT_INCOME.INTEREST)        AS INTEREST,
               sum(APZL.LC_RENT_INCOME.PENALTY)         AS PENALTY,
               sum(APZL.LC_RENT_INCOME.CORPUS_ADJUST)   AS CORPUS_ADJUST,
               sum(APZL.LC_RENT_INCOME.INTEREST_ADJUST) AS INTEREST_ADJUST,
               sum(APZL.LC_RENT_INCOME.PENALTY_ADJUST)  AS PENALTY_ADJUST
        FROM APZL.LC_RENT_INCOME
        WHERE (APZL.LC_RENT_INCOME.ROLL_BACK = '0')
        GROUP BY APZL.LC_RENT_INCOME.PAYMENT_NUMBER, APZL.LC_RENT_INCOME.PLAN_LIST, APZL.LC_RENT_INCOME.PLAN_ID
    ) LCFI ON (((LCRP.PAYMENT_NUMBER = LCFI.PAYMENT_NUMBER) AND (LCRP.PLAN_LIST = LCFI.PLAN_LIST) AND
                (LCRP.ID = LCFI.PLAN_ID)))) LEFT JOIN APZL.VI_LC_RENT_PLAN VIRP ON ((VIRP.ID = LCRP.ID))) LEFT JOIN APZL.LB_CONTRACT_INFO LCI ON ((LCI.ID = LCRP.CONTRACT_ID))) LEFT JOIN APZL.LB_UNION_LESSEE LUL ON ((LUL.CONTRACT_ID = LCI.ID))) LEFT JOIN APZL.CUSTOMER_INFO CIF ON ((CIF.CUSTOMERID = LUL.CUSTOMER_ID)))
    LEFT JOIN (
        SELECT DISTINCT APZL.CUSTOMER_ACCOUNT.BANK_NAME   AS BANK_NAME,
                        APZL.CUSTOMER_ACCOUNT.ACCOUNT     AS ACCOUNT,
                        APZL.CUSTOMER_ACCOUNT.ACC_NUMBER  AS ACC_NUMBER,
                        APZL.CUSTOMER_ACCOUNT.CUSTOMERID  AS CUSTOMERID,
                        APZL.CUSTOMER_ACCOUNT.ACC_TYPE    AS ACC_TYPE,
                        APZL.CUSTOMER_ACCOUNT.MOBILE      AS MOBILE,
                        APZL.CUSTOMER_ACCOUNT.SIGN_STATUS AS SIGN_STATUS,
                        APZL.CUSTOMER_ACCOUNT.CONTRACT_ID AS CONTRACT_ID
        FROM APZL.CUSTOMER_ACCOUNT
    ) CAT ON (((CAT.CUSTOMERID = LUL.CUSTOMER_ID) AND (CAT.ACC_TYPE = 'Debit') AND (CAT.CONTRACT_ID = LCRP.CONTRACT_ID))))
    WHERE (LCI.CONTRACT_STATUS = '31')
)
      ) O
LEFT JOIN APZL.LC_RENT_INCOME LRI ON (((LRI.CONTRACT_ID = O.CONTRACT_ID) AND (LRI.PLAN_LIST = O.PLAN_LIST))))
WHERE ((date_format(O.PLAN_DATE, '%Y/%m/%d') <= date_format(sysdate(), '%Y/%m/%d')) AND (O.COLLECT_STATUS IN ('手工收款', '批量收款')) AND (NOT (O.ID IN (
    SELECT APZL.LV_RENT_INCOME.INCOME_ID
    FROM APZL.LV_RENT_INCOME
))) AND (NOT (O.ID IN (
    SELECT APZL.LV_RENT_INCOME2.INCOME_ID
    FROM APZL.LV_RENT_INCOME2
))) AND (NOT (O.ID IN (
    SELECT APZL.LV_PENALTY_INCOME.INCOME_ID
    FROM APZL.LV_PENALTY_INCOME
))));

-- comment on column vi_paymentcertificate.id not supported: 标识

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

-- comment on column vi_paymentcertificate.customer_id not supported: 承租人编号

-- comment on column vi_paymentcertificate.CUSTOMER_NAME not supported: 承租人名称

-- comment on column vi_paymentcertificate.plan_list not supported: 期次

-- comment on column vi_paymentcertificate.plan_date not supported: 计划日期

-- comment on column vi_paymentcertificate.fact_rent not supported: 租金

-- comment on column vi_paymentcertificate.fact_corpus not supported: 财务本金

-- comment on column vi_paymentcertificate.fact_interest not supported: 财务租息

-- comment on column vi_paymentcertificate.penalty not supported: 回笼罚息

-- comment on column vi_paymentcertificate.bank_name not supported: 开户银行

-- comment on column vi_paymentcertificate.account not supported: 帐户名称

-- comment on column vi_paymentcertificate.acc_number not supported: 银行账号

-- comment on column vi_paymentcertificate.customer_num not supported: 客户编码

-- comment on column vi_paymentcertificate.customername not supported: 客户名称

