create view vi_business_summary as SELECT O.ID                                                                                        AS ID,
       T.ITEMNAME                                                                                  AS CONTRACT_STATUS,
       LPI.PROJECT_NO                                                                              AS PROJECT_NO,
       O.CONTRACT_NO                                                                               AS CONTRACT_NO,
       O.CONTRACT_NUMBER                                                                           AS CONTRACT_NUMBER,
       LUL.CUSTOMER_NAME                                                                           AS CUSTOMER_NAME,
       LEC.FRAME_NUMBER                                                                            AS FRAME_NUMBER,
       CP.MOBILE                                                                                   AS MOBILE,
       CF.NAME                                                                                     AS NAME,
       LEC.VNDR_NAME                                                                               AS VNDR_NAME,
       LFI.APPLYPAY_DATE                                                                           AS APPLYPAY_DATE,
       (CASE WHEN (O.CONTRACT_STATUS = '21') THEN (LCC.START_DATE = NULL) ELSE LCC.START_DATE END) AS START_DATE,
       X.OBJECTTYPE                                                                                AS OBJECTTYPE,
       X.OBJECTNO                                                                                  AS OBJECTNO,
       X.PHASETYPE                                                                                 AS PHASETYPE,
       X.APPLYTYPE                                                                                 AS APPLYTYPE,
       X.FLOWNO                                                                                    AS FLOWNO,
       X.FLOWNAME                                                                                  AS FLOWNAME,
       X.PHASENO                                                                                   AS PHASENO,
       BO.INPUTTIME                                                                                AS INPUTTIME
FROM ((((((((((APZL.LB_CONTRACT_INFO O LEFT JOIN APZL.LB_PROJECT_INFO LPI ON ((convert(O.PROJECT_ID USING UTF8) = LPI.ID))) LEFT JOIN (
    SELECT max(BO.INPUTTIME) AS INPUTTIME, BO.CONTRACT_ID AS CONTRACT_ID
    FROM APZL.FLOW_BUSSINESS_OBJECT BO
    WHERE (BO.FLOW_NAME = '付款申请(汽车)')
    GROUP BY BO.CONTRACT_ID
) BO ON ((BO.CONTRACT_ID = O.ID))) LEFT JOIN APZL.LB_UNION_LESSEE LUL ON ((convert(O.PROJECT_ID USING UTF8) = convert(LUL.PROJECT_ID USING UTF8)))) LEFT JOIN APZL.CUSTOMER_PERSON CP ON ((CP.CUSTOMERID = LUL.CUSTOMER_ID))) LEFT JOIN APZL.CUSTOMER_FAMILY CF ON ((
        (convert(O.PROJECT_ID USING UTF8) = convert(CF.PROJECT_ID USING UTF8)) AND
        (CF.PARTNER_ = 'Y')))) LEFT JOIN APZL.LB_EQUIPMENT_CAR LEC ON ((convert(O.PROJECT_ID USING UTF8) = LEC.PROJECT_ID))) LEFT JOIN (
    SELECT APZL.LC_FUND_INCOME.CONTRACT_ID        AS CONTRACT_ID,
           min(APZL.LC_FUND_INCOME.PROJECT_ID)    AS PROJECT_ID,
           max(APZL.LC_FUND_INCOME.APPLYPAY_DATE) AS APPLYPAY_DATE,
           APZL.LC_FUND_INCOME.FACT_DATE          AS FACT_DATE
    FROM APZL.LC_FUND_INCOME
    WHERE ((APZL.LC_FUND_INCOME.FEE_TYPE = 'feetype10') AND (APZL.LC_FUND_INCOME.SETTLE_METHOD = 'settlemethod11'))
    GROUP BY APZL.LC_FUND_INCOME.CONTRACT_ID
) LFI ON ((convert(O.PROJECT_ID USING UTF8) = convert(LFI.PROJECT_ID USING UTF8)))) LEFT JOIN APZL.LC_CALC_CONDITION LCC ON ((convert(O.ID USING UTF8) = convert(LCC.CONTRACT_ID USING UTF8)))) LEFT JOIN (
    SELECT FB.PROJ_ID    AS PROJ_ID,
           FO.OBJECTTYPE AS OBJECTTYPE,
           FO.OBJECTNO   AS OBJECTNO,
           FO.PHASETYPE  AS PHASETYPE,
           FO.APPLYTYPE  AS APPLYTYPE,
           FO.FLOWNO     AS FLOWNO,
           FO.FLOWNAME   AS FLOWNAME,
           FO.PHASENO    AS PHASENO,
           FB.INPUTTIME  AS INPUTTIME
    FROM (APZL.FLOW_OBJECT FO
    LEFT JOIN APZL.FLOW_BUSSINESS_OBJECT FB ON ((FO.OBJECTNO = FB.FLOW_UNID)))
    WHERE FO.OBJECTNO IN (
        SELECT max(F.OBJECTNO)
        FROM (APZL.FLOW_OBJECT F
        LEFT JOIN APZL.FLOW_BUSSINESS_OBJECT B ON ((F.OBJECTNO = B.FLOW_UNID)))
        GROUP BY B.PROJ_ID
    )
) X ON ((convert(X.PROJ_ID USING UTF8) = LPI.ID)))
LEFT JOIN (
    SELECT BS.CONTRACT_NUMBER AS CONTRACT_NUMBER, BS.INPUTTIME AS INPUTTIME, CL.ITEMNAME AS ITEMNAME
    FROM (APZL.BUSINESS_STATUS BS
    LEFT JOIN APZL.CODE_LIBRARY CL ON (((CL.ITEMNO = BS.BUSINESS_STATUS) AND (CL.CODENO = 'BusinessStatus'))))
    WHERE ((length(BS.CONTRACT_NUMBER) > 13) AND BS.INPUTTIME IN (
        SELECT max(B.INPUTTIME)
        FROM APZL.BUSINESS_STATUS B
        WHERE ((B.CONTRACT_NUMBER IS NOT NULL) AND (B.CONTRACT_NUMBER <> '') AND (length(B.CONTRACT_NUMBER) > 13))
        GROUP BY B.CONTRACT_NUMBER
    ))
    GROUP BY BS.CONTRACT_NUMBER
) T ON ((convert(T.CONTRACT_NUMBER USING UTF8) = convert(O.CONTRACT_NUMBER USING UTF8))))
WHERE (O.BUSINESSTYPE = 1)
ORDER BY T.INPUTTIME DESC;

-- comment on column vi_business_summary.ID not supported: 编号

-- comment on column vi_business_summary.PROJECT_NO not supported: 项目编号

-- comment on column vi_business_summary.CONTRACT_NO not supported: 合同号

-- comment on column vi_business_summary.CONTRACT_NUMBER not supported: 业务合同号

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

-- comment on column vi_business_summary.FRAME_NUMBER not supported: 车架号

-- comment on column vi_business_summary.mobile not supported: 手机号

-- comment on column vi_business_summary.NAME not supported: 姓名

-- comment on column vi_business_summary.VNDR_NAME not supported: 供应商

-- comment on column vi_business_summary.APPLYPAY_DATE not supported: 申请支付日期

-- comment on column vi_business_summary.OBJECTTYPE not supported: 对象类型

-- comment on column vi_business_summary.OBJECTNO not supported: 对象编号

-- comment on column vi_business_summary.PHASETYPE not supported: 阶段类型

-- comment on column vi_business_summary.APPLYTYPE not supported: 申请类型

-- comment on column vi_business_summary.FLOWNO not supported: 当前流程号

-- comment on column vi_business_summary.FLOWNAME not supported: 当前流程名称

-- comment on column vi_business_summary.PHASENO not supported: 当前阶段号

-- comment on column vi_business_summary.inputTime not supported: 创建时间

