Преглед на файлове

把科目明细拆分为多行

Ping преди 1 година
родител
ревизия
4fccec1e4b
променени са 1 файла, в които са добавени 9 реда и са изтрити 5 реда
  1. 9 5
      退房业务报表.sql

+ 9 - 5
退房业务报表.sql

@@ -1,15 +1,16 @@
-
-select crc.id '合同ID', maintainer_sd.id '所属门店ID', maintainer_sd.name '所属门店', hhr.address '房源地址', mt_emp.name '合同维护人',
+select crc.tenant_id, crc.id '合同ID', hhb.dept_id '房源所属门店ID', house_sd.name '房源所属门店', 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 '退租类型', 
 	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`, '$.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.kind '费用科目',
 	_total.应收 '应收账单',
 	_total.应付 '应付账单',
 	_total.应付-_total.应收 '应退款金额',
@@ -17,20 +18,23 @@ select crc.id '合同ID', maintainer_sd.id '所属门店ID', maintainer_sd.name
 	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_base hhb on hhb.is_delete=0 and hhb.id=crc.house_id
+left join yuxin_setting.setting_department house_sd on house_sd.id=hhb.dept_id and house_sd.is_delete=0
 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,
+    select bd.biz_id, sd.name 'kind',
     	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
+	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
-    group by bd.biz_id
+    group by bd.biz_id,sd.name
 ) _total on _total.biz_id= crc.id
 left join (
 	select bd.biz_id, GROUP_CONCAT(CONCAT(sd.name, bd.original_money)) 'info'