create view vi_lc_rent_plan as SELECT LCF.ID                                                                                                                                AS ID,
       LBC.PROJECT_ID                                                                                                                        AS PROJECT_ID,
       LBC.ID                                                                                                                                AS CONTRACT_ID,
       LCCS.PLAN_STATUS                                                                                                                      AS CONTRACT_STATUS,
       LBC.CONTRACT_NUMBER                                                                                                                   AS CONTRACT_NUMBER,
       LCF.PAYMENT_NUMBER                                                                                                                    AS PAYMENT_NUMBER,
       ifnull(LBU.CUSTOMERNAME, '')                                                                                                          AS CUSTOMERNAME,
       LBC.PROJECT_NAME                                                                                                                      AS PROJECT_NAME,
       LCF.PLAN_LIST                                                                                                                         AS PLAN_LIST,
       LCF.PLAN_DATE                                                                                                                         AS PLAN_DATE,
       LCF.RENT                                                                                                                              AS RENT,
       LCF.CORPUS                                                                                                                            AS CORPUS,
       LCF.INTEREST                                                                                                                          AS INTEREST,
       `getRentPenalty`(LCF.PAYMENT_NUMBER, LCF.PLAN_LIST, date_format(now(), '%Y/%m/%d'))                                                   AS PENALTY,
       (ifnull(LCFD.RENT, 0) + ifnull(LCFI.RENT, 0))                                                                                         AS FACT_RENT,
       (ifnull(LCFD.CORPUS, 0) + ifnull(LCFI.CORPUS, 0))                                                                                     AS FACT_CORPUS,
       (ifnull(LCFD.INTEREST, 0) + ifnull(LCFI.INTEREST, 0))                                                                                 AS FACT_INTEREST,
       (ifnull(LCFD.PENALTY, 0) + ifnull(LCFI.PENALTY, 0))                                                                                   AS FACT_PENALTY,
       (ifnull(LCFD.CORPUS_ADJUST, 0) + ifnull(LCFI.CORPUS_ADJUST, 0))                                                                       AS CORPUS_ADJUST,
       (ifnull(LCFD.INTEREST_ADJUST, 0) + ifnull(LCFI.INTEREST_ADJUST, 0))                                                                   AS INTEREST_ADJUST,
       (ifnull(LCFD.PENALTY_ADJUST, 0) + ifnull(LCFI.PENALTY_ADJUST, 0))                                                                     AS PENALTY_ADJUST,
       (LCF.RENT - (ifnull(LCFD.RENT, 0) + ifnull(LCFI.RENT, 0)))                                                                            AS RENT_OVER,
       (LCF.CORPUS - (((ifnull(LCFD.CORPUS, 0) + ifnull(LCFI.CORPUS, 0)) + ifnull(LCFD.CORPUS_ADJUST, 0)) +
                      ifnull(LCFI.CORPUS_ADJUST, 0)))                                                                                        AS CORPUS_OVER,
       (LCF.INTEREST - (((ifnull(LCFD.INTEREST, 0) + ifnull(LCFI.INTEREST, 0)) + ifnull(LCFD.INTEREST_ADJUST, 0)) +
                        ifnull(LCFI.INTEREST_ADJUST, 0)))                                                                                    AS INTEREST_OVER,
       round((`getRentPenalty`(LCF.PAYMENT_NUMBER, LCF.PLAN_LIST, date_format(now(), '%Y/%m/%d')) -
              ((ifnull(LCFD.PENALTY, 0) + ifnull(LCFI.PENALTY, 0)) + (ifnull(LCFD.PENALTY_ADJUST, 0) + ifnull(LCFI.PENALTY_ADJUST, 0)))),
             2)                                                                                                                              AS PENALTY_OVER,
       (CASE
            WHEN (((ifnull(LCFD.RENT, 0) + ifnull(LCFI.RENT, 0)) = LCF.RENT) AND (round(
                                                                                          (`getRentPenalty`(LCF.PAYMENT_NUMBER, LCF.PLAN_LIST, date_format(now(), '%Y/%m/%d')) -
                                                                                           ((ifnull(LCFD.PENALTY, 0) + ifnull(LCFI.PENALTY, 0)) +
                                                                                            (ifnull(LCFD.PENALTY_ADJUST, 0) + ifnull(LCFI.PENALTY_ADJUST, 0)))),
                                                                                          2) = '0.00')) THEN '已回笼'
            WHEN ((ifnull(LCFD.RENT, 0) + ifnull(LCFI.RENT, 0)) > 0) THEN '部分回笼'
            ELSE '未回笼' END)                                                                                                                  AS PLANSTATUS
FROM (((((APZL.LC_RENT_PLAN LCF LEFT JOIN APZL.LB_CONTRACT_INFO LBC ON ((LCF.CONTRACT_ID = LBC.ID))) LEFT JOIN APZL.LC_CALC_CONDITION_STATUS LCCS ON ((LCCS.PAYMENT_NUMBER = LCF.PAYMENT_NUMBER))) LEFT JOIN APZL.LB_UNION_LESSEE_TRANSFER LBU ON ((LCF.CONTRACT_ID = LBU.CONTRACT_ID))) LEFT JOIN APZL.LC_RENT_INCOME_TRANSFER LCFD ON (((LCF.PAYMENT_NUMBER = LCFD.PAYMENT_NUMBER) AND (LCF.PLAN_LIST = LCFD.PLAN_LIST))))
LEFT JOIN APZL.LC_RENT_INCOME_TEMP_TRANSFER LCFI ON (((LCF.PAYMENT_NUMBER = LCFI.PAYMENT_NUMBER) AND (LCF.PLAN_LIST = LCFI.PLAN_LIST))));

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

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

-- comment on column vi_lc_rent_plan.contract_id not supported: 编号

-- comment on column vi_lc_rent_plan.contract_status not supported: 状态

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

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

-- comment on column vi_lc_rent_plan.project_name not supported: 项目名称

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

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

-- comment on column vi_lc_rent_plan.rent not supported: 租金

-- comment on column vi_lc_rent_plan.corpus not supported: 财务本金

-- comment on column vi_lc_rent_plan.interest not supported: 财务租息

