DELIMITER $$

create ALGORITHM=UNDEFINED DEFINER=`apzl`@`%` SQL SECURITY DEFINER VIEW `vi_li_invoice_tj_leaseback` AS 
SELECT
  `lci`.`ID`            AS `contract_id`,
  `lci`.`CONTRACT_NO`   AS `contract_no`,
  `vib`.`plan_list`     AS `plan_list`,
  `vib`.`invoice_money` AS `invoice_money`,
  `cl`.`itemname`       AS `tax_type`,
  `vib`.`tax_no`        AS `tax_no`,
  `tci`.`code`          AS `tax_code`,
  `ca`.`CERTID`         AS `cert_id`,
  `ca`.`account`        AS `account`,
  `ca`.`acc_number`     AS `acc_number`,
  `ca`.`bank_name`      AS `bank_name`,
  `ca`.`MOBILE`         AS `telephone`,
  `ci`.`customertype`   AS `customer_type`,
  `ci`.`customername`   AS `customer_name`,
  `li`.`id`             AS `liti_id`,
  `li`.`status`         AS `invoice_status`,
  `li`.`fpdm`           AS `FPDM`,
  `li`.`fphm`           AS `FPHM`,
  `li`.`hztzdh`         AS `hztzdh`,
  `li`.`mxxh`           AS `mxxh`
FROM (((((((`apzl`.`vi_li_invoice_tj_base` `vib`
         LEFT JOIN `apzl`.`lb_contract_info` `lci`
           ON ((`vib`.`contract_id` = `lci`.`ID`)))
        LEFT JOIN `apzl`.`li_invoice_tj_info` `li`
          ON (((`li`.`status` = 'Y')
               AND (`li`.`contract_no` = `lci`.`CONTRACT_NO`)
               AND (`li`.`tax_type` = CONVERT(`vib`.`tax_no` USING gbk))
               AND (`li`.`plan_list` = CONVERT(`vib`.`plan_list` USING gbk)))))
       LEFT JOIN `apzl`.`lb_union_lessee` `lul`
         ON ((`lul`.`CONTRACT_ID` = `lci`.`ID`)))
      LEFT JOIN `apzl`.`customer_info` `ci`
        ON ((`ci`.`customerid` = `lul`.`CUSTOMER_ID`)))
     LEFT JOIN `apzl`.`customer_account` `ca`
       ON (((`ca`.`CONTRACT_ID` = `lul`.`CONTRACT_ID`))))
    LEFT JOIN `apzl`.`code_library` `cl`
      ON (((`cl`.`codeno` = 'tax_type')
           AND (`cl`.`itemno` = `vib`.`tax_no`))))
   LEFT JOIN `apzl`.`tax_code_info` `tci`
     ON ((`tci`.`tax_type` = `cl`.`itemno`)))
WHERE ((`vib`.`tax_no` IN('interest','penalty','feetype1','feetype4','feetype30'))
       AND (`lci`.`LEAS_FORM` = '02'))$$

DELIMITER ;