DELIMITER $$

ALTER ALGORITHM=UNDEFINED DEFINER=`apzl`@`%` SQL SECURITY DEFINER VIEW `vi_lc_fund_plan` AS 
SELECT
  `lcf`.`ID`              AS `id`,
  `lbc`.`CONTRACT_NUMBER` AS `contract_number`,
  `lbc`.`PROJECT_ID`      AS `project_id`,
  `lbc`.`ID`              AS `contract_id`,
  lbc.businesstype        AS  businesstype,
  lbc.subjectid           AS  subjectid,
  `lbc`.`CONTRACT_STATUS` AS `contract_status`,
  `lcf`.`PAYMENT_NUMBER`  AS `payment_number`,
  `lbc`.`PROJECT_NAME`    AS `project_name`,
  IFNULL(`lbu`.`customername`,'') AS `customername`,
  `lcf`.`PAY_TYPE`        AS `pay_type`,
  `lcf`.`FEE_TYPE`        AS `fee_type`,
  `lcf`.`PLAN_LIST`       AS `plan_list`,
  `lcf`.`PLAN_DATE`       AS `plan_date`,
  `lcf`.`PLAN_MONEY`      AS `plan_money`,
  (IFNULL(`lcfd`.`fact_money`,0) + IFNULL(`lcfi`.`fact_money`,0)) AS `fact_money`,
  (IFNULL(`lcfi`.`fee_adjust`,0) + IFNULL(`lcfd`.`fee_adjust`,0)) AS `fee_adjust`,
  (((IFNULL(`lcfd`.`fact_money`,0) + IFNULL(`lcfi`.`fact_money`,0)) + IFNULL(`lcfi`.`fee_adjust`,0)) + IFNULL(`lcfd`.`fee_adjust`,0)) AS `allfact_money`,
  (`lcf`.`PLAN_MONEY` - (((IFNULL(`lcfd`.`fact_money`,0) + IFNULL(`lcfi`.`fact_money`,0)) + IFNULL(`lcfi`.`fee_adjust`,0)) + IFNULL(`lcfd`.`fee_adjust`,0))) AS `overmoney`
FROM ((((`lc_fund_plan` `lcf`
      LEFT JOIN `lb_contract_info` `lbc`
        ON ((`lcf`.`CONTRACT_ID` = CONVERT(`lbc`.`ID` USING utf8))))
     LEFT JOIN `lb_union_lessee_f_transfer` `lbu`
       ON ((`lcf`.`CONTRACT_ID` = CONVERT(`lbu`.`contract_id` USING utf8))))
    LEFT JOIN `lc_fund_income_transfer` `lcfd`
      ON (((`lcf`.`PAYMENT_NUMBER` = `lcfd`.`payment_number`)
           AND (`lcf`.`PAY_TYPE` = `lcfd`.`pay_type`)
           AND (`lcf`.`FEE_TYPE` = `lcfd`.`fee_type`)
           AND (`lcf`.`PLAN_LIST` = `lcfd`.`plan_list`))))
   LEFT JOIN `lc_fund_income_temp_transfer` `lcfi`
     ON (((`lcf`.`PAYMENT_NUMBER` = `lcfi`.`payment_number`)
          AND (`lcf`.`PAY_TYPE` = `lcfi`.`pay_type`)
          AND (`lcf`.`FEE_TYPE` = `lcfi`.`fee_type`)
          AND (`lcf`.`PLAN_LIST` = `lcfi`.`plan_list`))))$$

DELIMITER ;