|
@@ -0,0 +1,48 @@
|
|
|
|
+
|
|
|
|
+select crc.id '合同ID', maintainer_sd.id '所属门店ID', maintainer_sd.name '所属门店', hhr.address '房源地址', mt_emp.name '合同维护人',
|
|
|
|
+ cri.name '租客姓名', crc.begin_time '合同开始日期', crc.end_time '合同结束日期',
|
|
|
|
+ crc.quite_date '退租日期', crc.terminate_type '退租类型', crc.cancel_info '退租原因',
|
|
|
|
+ case when JSON_EXTRACT(crc.`cancel_info`, '$.paymentAccountType')=1 then '银联'
|
|
|
|
+ when JSON_EXTRACT(crc.`cancel_info`, '$.paymentAccountType')=2 then '支付宝'
|
|
|
|
+ when JSON_EXTRACT(crc.`cancel_info`, '$.paymentAccountType')=3 then '微信' end '退款途径',
|
|
|
|
+ REPLACE(REPLACE(JSON_EXTRACT(crc.`cancel_info`, '$.paymentAccount'), '"', ''), 'null', '') '退款账号',
|
|
|
|
+ CONCAT(REPLACE(REPLACE(JSON_EXTRACT(crc.`cancel_info`, '$.bankName'), '"', ''), 'null', ''), REPLACE(REPLACE(JSON_EXTRACT(crc.`cancel_info`, '$.bankNumber'), '"', ''), 'null', '')) '银行行号和开户银行',
|
|
|
|
+ REPLACE(REPLACE(JSON_EXTRACT(crc.`cancel_info`, '$.reason'), '"', ''), 'null', '') '退租备注',
|
|
|
|
+ REPLACE(REPLACE(JSON_EXTRACT(crc.`cancel_info`, '$.rejectName'), '"', ''), 'null', '') '退租操作人',
|
|
|
|
+ REPLACE(REPLACE(JSON_EXTRACT(crc.`cancel_info`, '$.rejectTime'), '"', ''), 'null', '') '退租时间',
|
|
|
|
+ _total.应收 '应收账单',
|
|
|
|
+ _total.应付 '应付账单',
|
|
|
|
+ _total.应付-_total.应收 '应退款金额',
|
|
|
|
+ _detail.info '财务退款备注',
|
|
|
|
+ IF(_flow_status.avg_status is null, '', IF(_flow_status.avg_status=1, '待审核', IF(_flow_status.avg_status=3, '审核通过', '部分审核通过'))) '审核状态',
|
|
|
|
+ IF(_flow_status.avg_status is null, '', IF(_flow_status.avg_status=3, '已退款', IF(_flow_status.avg_status>1, '已部分退款', '未退款'))) '退款信息'
|
|
|
|
+from yuxin_contract.cont_renter_contract crc
|
|
|
|
+left join yuxin_house.hse_house_room hhr on hhr.is_delete=0 and hhr.id=crc.house_id
|
|
|
|
+left join yuxin_setting.setting_employee_dept maintainer_ed on maintainer_ed.emp_id=crc.maintainer_id and maintainer_ed.is_delete=0
|
|
|
|
+left join yuxin_setting.setting_department maintainer_sd on maintainer_sd.id=maintainer_ed.dept_id and maintainer_sd.is_delete=0
|
|
|
|
+left join yuxin_setting.setting_employee_info mt_emp on mt_emp.id=crc.maintainer_id and mt_emp.is_delete=0
|
|
|
|
+left join yuxin_contract.cont_renter_info cri on cri.is_delete=0 and cri.customer_type=1 and cri.contract_id=crc.id
|
|
|
|
+left join (
|
|
|
|
+ select bd.biz_id,
|
|
|
|
+ SUM(IF(bd.fee_direction=1,0,1)*bd.original_money) '应付',
|
|
|
|
+ SUM(IF(bd.fee_direction=1,0,1)*bd.occurred_money) '已付',
|
|
|
|
+ SUM(IF(bd.fee_direction=1,1,0)*bd.original_money) '应收',
|
|
|
|
+ SUM(IF(bd.fee_direction=1,1,0)*bd.occurred_money) '已收'
|
|
|
|
+ from yuxin_finance.fin_finance_bill_detail bd
|
|
|
|
+ where bd.is_valid=1 and bd.is_delete=0 and bd.biz_type=2
|
|
|
|
+ group by bd.biz_id
|
|
|
|
+) _total on _total.biz_id= crc.id
|
|
|
|
+left join (
|
|
|
|
+ select bd.biz_id, GROUP_CONCAT(CONCAT(sd.name, bd.original_money)) 'info'
|
|
|
|
+ from yuxin_finance.fin_finance_bill_detail bd
|
|
|
|
+ left join yuxin_setting.setting_dictionary sd on sd.id=bd.fee_subject_id
|
|
|
|
+ where bd.is_valid=1 and bd.is_delete=0 and bd.biz_type=2 and bd.fee_direction=2
|
|
|
|
+ group by bd.biz_id
|
|
|
|
+) _detail on _detail.biz_id=crc.id
|
|
|
|
+left join (
|
|
|
|
+ select bf.biz_id, avg(bf.audit_status) 'avg_status'
|
|
|
|
+ from yuxin_finance.fin_finance_bill_flow bf
|
|
|
|
+ where bf.is_delete=0 and bf.biz_type=2 and bf.bill_type=2
|
|
|
|
+ group by bf.biz_id
|
|
|
|
+) _flow_status on _flow_status.biz_id=crc.id
|
|
|
|
+where crc.contract_status=3 and crc.is_delete=0
|