DELIMITER $$

ALTER ALGORITHM=UNDEFINED DEFINER=`apzl`@`%` SQL SECURITY DEFINER VIEW `apzl`.`vi_chargebackvoucherdetail` AS 
SELECT
  `lrp`.`ID`              AS `ID`,
  `lci`.`CONTRACT_NO`     AS `CONTRACT_NO`,
  `cif`.`customer_num`    AS `CUSTOMER_NUM`,
  `cif`.`customername`    AS `CUSTOMERNAME`,
  `lri`.`PLAN_LIST`       AS `PLAN_LIST`,
  `lri`.`HIRE_DATE`       AS `HIRE_DATE`,
  `lri`.`RENT`            AS `RENT`,
  `lri`.`CORPUS`          AS `CORPUS`,
  `lri`.`INTEREST`        AS `INTEREST`,
  `lri`.`PENALTY`         AS `PENALTY`,
  `lri`.`OWN_NUMBER`      AS `own_number`,
  (IFNULL(`lri`.`RENT`,0) + IFNULL(`lri`.`PENALTY`,0)) AS `SUMMONEY`,
  `ca`.`bank_name`        AS `BANK_NAME`,
  `ca`.`account`          AS `ACCOUNT`,
  `ca`.`acc_number`       AS `ACC_NUMBER`,
  `lri`.`ACCOUNTING_DATE` AS `ACCOUNTING_DATE`,
  `lri`.`ID`              AS `income_ID`,
  `lci`.`distributor_id`  AS `distributorid`,
  `lri`.`charge_way`      AS `CHANNEL`,
  `vss`.`ACHIEVED_DATE`   AS `ACHIEVED_DATE`
FROM ((((((`apzl`.`lc_rent_plan` `lrp`
        LEFT JOIN `apzl`.`lc_rent_income` `lri`
          ON (((`lri`.`CONTRACT_ID` = `lrp`.`CONTRACT_ID`)
               AND (`lri`.`PLAN_LIST` = `lrp`.`PLAN_LIST`))))
       LEFT JOIN `apzl`.`lb_contract_info` `lci`
         ON ((`lci`.`ID` = `lri`.`CONTRACT_ID`)))
      LEFT JOIN `apzl`.`lb_union_lessee` `lul`
        ON ((`lul`.`CONTRACT_ID` = `lci`.`ID`)))
     LEFT JOIN `apzl`.`customer_info` `cif`
       ON ((`cif`.`customerid` = `lul`.`CUSTOMER_ID`)))
    LEFT JOIN `apzl`.`customer_account` `ca`
      ON (((`ca`.`CONTRACT_ID` = `lci`.`ID`)
           AND (`ca`.`acc_type` = 'Debit'))))
   LEFT JOIN `apzl`.`verificationspare` `vss`
     ON ((`vss`.`SPARE_BATCH_NO` = CONVERT(`lri`.`SPARE_BATCH_NO` USING utf8))))
WHERE ((`lri`.`charge_way` = 'AutoBuckle')
        OR (`lri`.`charge_way` = 'WXUnionPay'))$$

DELIMITER ;