合同应收实收报表.sql 2.3 KB

12345678910111213141516171819202122232425262728
  1. select
  2. crc.tenant_id,
  3. hhb.dept_id '房源所属门店ID', house_sd.name '房源所属门店名称', hhr.address '房源地址', hhr.house_area '房源面积',
  4. crc_sd.id '合同所属门店/部门ID', crc_sd.name '合同所属门店/部门',
  5. crc.id '合同ID', crc.contract_no '合同编号', cri.name '租客姓名', cri.phone '租客手机号',
  6. sd.name '费用类型', detail.original_money '费用金额', detail.attribution_type '费用承担方',
  7. detail.begin_time '费用周期(开始)', detail.end_time '费用周期(结束)',
  8. detail.fee_status '收付款状态', detail.predict_time '应收付时间', detail.overdue '逾期天数', detail.practical_time '实收付时间',
  9. detail.payment_account_type '支付方式', detail.payment_account '支付账号', detail.affirm_emp_id '账单经办人ID', affirm_emp.name '账单经办人',
  10. detail.affirm_time '账单提交时间'
  11. from yuxin_contract.cont_renter_contract crc
  12. left join yuxin_house.hse_house_room hhr on hhr.is_delete=0 and hhr.id=crc.house_id
  13. left join yuxin_house.hse_house_base hhb on hhb.is_delete=0 and hhb.id=crc.house_id
  14. left join yuxin_setting.setting_department house_sd on house_sd.id=hhb.dept_id and house_sd.is_delete=0
  15. left join yuxin_house.hse_community hc on hc.id=hhb.community_id and hc.is_delete=0
  16. left join yuxin_setting.setting_employee_dept crc_ed on crc_ed.emp_id=crc.maintainer_id and crc_ed.is_delete=0
  17. left join yuxin_setting.setting_department crc_sd on crc_sd.id=crc_ed.dept_id and crc_sd.is_delete=0
  18. left join yuxin_contract.cont_renter_info cri on cri.is_delete=0 and cri.customer_type=1 and cri.contract_id=crc.id
  19. left join (
  20. select bd.biz_id, bd.fee_subject_id, bd.original_money, bd.attribution_type, bd.begin_time, bd.end_time,
  21. bd.fee_status, bd.predict_time, bd.practical_time,
  22. bd.payment_account_type, bd.payment_account, bd.affirm_emp_id, bd.affirm_time,
  23. if(bd.practical_time>bd.predict_time, DATEDIFF(bd.practical_time, bd.predict_time)+1, '-') 'overdue'
  24. from yuxin_finance.fin_finance_bill_detail bd
  25. where bd.is_valid=1 and bd.is_delete=0 and bd.biz_type=2 and bd.fee_direction=1
  26. ) detail on detail.biz_id=crc.id
  27. left join yuxin_setting.setting_dictionary sd on sd.id=detail.fee_subject_id
  28. left join yuxin_setting.setting_employee_info affirm_emp on affirm_emp.id=detail.affirm_emp_id and affirm_emp.is_delete=0