create view vi_jtfentan as SELECT LCI.CONTRACT_NO                                                                                                         AS CONTRACT_NO,
       T.RENT_LIST                                                                                                             AS RENT_LIST,
       T.END_DATE                                                                                                              AS END_DATE,
       T.ACCRUED_DATE                                                                                                          AS ACCRUED_DATE,
       T.LEFTINTEREST                                                                                                          AS LEFTINTEREST,
       ifnull(round(T.INTEREST, 2), 0)                                                                                         AS INTERESTBUHAN,
       ifnull(round((T.INTEREST * (CASE WHEN (LCI.LEAS_FORM = '01') THEN 1.16 ELSE 1.06 END)), 2), 0)                          AS INTERESTHAN,
       ifnull((round((T.INTEREST * (CASE WHEN (LCI.LEAS_FORM = '01') THEN 1.16 ELSE 1.06 END)), 2) - round(T.INTEREST, 2)), 0) AS INTERESTSHUIJIN,
       `getRemainInterest`(T.PAYMENT_NUMBER, T.RENT_LIST, 'interest')                                                          AS REMAIN_INTEREST,
       round((T.INTEREST / M.SUMINTEREST), 6)                                                                                  AS RATE,
       ifnull(round(T.FEE, 2), 0)                                                                                              AS FEEBUHAN,
       ifnull(round((T.FEE * (CASE WHEN (LCI.LEAS_FORM = '01') THEN 1.16 ELSE 1.06 END)), 2), 0)                               AS FEEHAN,
       ifnull((round((T.FEE * (CASE WHEN (LCI.LEAS_FORM = '01') THEN 1.16 ELSE 1.06 END)), 2) - round(T.FEE, 2)), 0)           AS FEESHUIJIN,
       `getRemainInterest`(T.PAYMENT_NUMBER, T.RENT_LIST, 'fee')                                                               AS REMAIN_FEE,
       ifnull(round(T.DISCOUNT, 2), 0)                                                                                         AS DISCOUNTBUHAN,
       ifnull(round((T.DISCOUNT * (CASE WHEN (LCI.LEAS_FORM = '01') THEN 1.16 ELSE 1.06 END)), 2), 0)                          AS DISCOUNTHAN,
       ifnull((round((T.DISCOUNT * (CASE WHEN (LCI.LEAS_FORM = '01') THEN 1.16 ELSE 1.06 END)), 2) - round(T.DISCOUNT, 2)), 0) AS DISCOUNTSHUIJIN,
       ifnull(`getRemainInterest`(T.PAYMENT_NUMBER, T.RENT_LIST, 'discount'), 0)                                               AS REMAIN_DISCOUNT
FROM ((APZL.CONTRACT_RENT_MONTH T LEFT JOIN APZL.LB_CONTRACT_INFO LCI ON ((LCI.ID = T.CONTRACT_ID)))
LEFT JOIN (
    SELECT APZL.CONTRACT_RENT_MONTH.CONTRACT_ID AS CONTRACT_ID, sum(APZL.CONTRACT_RENT_MONTH.INTEREST) AS SUMINTEREST
    FROM APZL.CONTRACT_RENT_MONTH
    GROUP BY APZL.CONTRACT_RENT_MONTH.CONTRACT_ID
) M ON ((M.CONTRACT_ID = LCI.ID)))
WHERE (LCI.BUSINESSTYPE = '1');

-- comment on column vi_jtfentan.contract_no not supported: 合同号

-- comment on column vi_jtfentan.rent_list not supported: 期项

-- comment on column vi_jtfentan.end_date not supported: 计提结束日

-- comment on column vi_jtfentan.accrued_date not supported: 计提月

-- comment on column vi_jtfentan.leftinterest not supported: 剩余租息

