diff --git a/emis-biz/src/main/resources/mapper/EmisSettleBillMapper.xml b/emis-biz/src/main/resources/mapper/EmisSettleBillMapper.xml
index d1e658bee..c6780d11b 100644
--- a/emis-biz/src/main/resources/mapper/EmisSettleBillMapper.xml
+++ b/emis-biz/src/main/resources/mapper/EmisSettleBillMapper.xml
@@ -294,9 +294,89 @@
SELECT
a.settle_bill_no,
sum( ifnull(d.pay_money,0) ) AS totalPayMoney,
- sum( if(b.trade_date a.payment_due_date,ifnull(d.pay_money,0) ,0) ) AS recdMoneyIn,
- sum( if(a.settle_type='2' and a.credit_period = ]]> 30 and b.trade_date ]]> a.payment_due_date and b.trade_date ]]> a.payment_due_date and b.trade_date DATE_SUB( a.payment_due_date, INTERVAL (a.credit_period-60) DAY ),ifnull(d.pay_money,0) ,0) ) AS recdPayMoney60D,
- sum( if( (a.settle_type='2' and a.credit_period = ]]> 30 and b.trade_date ]]> a.payment_due_date and b.trade_date = ]]> DATE_SUB( a.payment_due_date, INTERVAL (a.credit_period-60) DAY ) ) or ( ( (a.settle_type='2' and a.credit_period 30) or a.settle_type='1' ) and b.trade_date ]]> a.payment_due_date ),ifnull(d.pay_money,0) ,0) ) AS recdPayMoneyGreat60D
+ sum(
+ case
+ when a.settle_type = '2'
+ and a.credit_period in (30,35,45,60,75,90)
+ and EXISTS(
+ SELECT 1
+ FROM emis_settle_invoice_record f
+ WHERE f.del_flag = '0'
+ AND f.settle_bill_no = a.settle_bill_no
+ AND f.bl_delay = '1'
+ AND f.apply_date
+ (
+ case
+ when a.credit_period in (30,35,45) then DATE_ADD(STR_TO_DATE(CONCAT(REPLACE(a.bill_month,'-',''),'01'),'%Y%m%d'), INTERVAL 2 MONTH)
+ when a.credit_period in (60,75) then DATE_ADD(STR_TO_DATE(CONCAT(REPLACE(a.bill_month,'-',''),'01'),'%Y%m%d'), INTERVAL 3 MONTH)
+ when a.credit_period = 90 then DATE_ADD(STR_TO_DATE(CONCAT(REPLACE(a.bill_month,'-',''),'01'),'%Y%m%d'), INTERVAL 4 MONTH)
+ else NULL
+ end
+ )
+ )
+ and b.trade_date
+ (
+ case
+ when a.credit_period in (30,35,45) then DATE_ADD(STR_TO_DATE(CONCAT(REPLACE(a.bill_month,'-',''),'01'),'%Y%m%d'), INTERVAL 3 MONTH)
+ when a.credit_period in (60,75) then DATE_ADD(STR_TO_DATE(CONCAT(REPLACE(a.bill_month,'-',''),'01'),'%Y%m%d'), INTERVAL 4 MONTH)
+ when a.credit_period = 90 then DATE_ADD(STR_TO_DATE(CONCAT(REPLACE(a.bill_month,'-',''),'01'),'%Y%m%d'), INTERVAL 5 MONTH)
+ else a.payment_due_date
+ end
+ )
+ then ifnull(d.pay_money,0)
+ when b.trade_date a.payment_due_date then ifnull(d.pay_money,0)
+ else 0
+ end
+ ) AS recdMoneyIn,
+ sum( if(
+ a.settle_type='2'
+ and a.credit_period = ]]> 30
+ and b.trade_date ]]> a.payment_due_date
+ and b.trade_date ]]> a.payment_due_date
+ and b.trade_date DATE_SUB( a.payment_due_date, INTERVAL (a.credit_period-60) DAY )
+ and NOT EXISTS (
+ SELECT 1
+ FROM emis_settle_invoice_record f
+ WHERE f.del_flag='0'
+ AND f.settle_bill_no = a.settle_bill_no
+ AND f.bl_delay = '1'
+ )
+ ,ifnull(d.pay_money,0) ,0) ) AS recdPayMoney60D,
+ sum(
+ case
+ when a.settle_type = '2'
+ and a.credit_period in (30,35,45,60,75,90)
+ and EXISTS(
+ SELECT 1
+ FROM emis_settle_invoice_record f
+ WHERE f.del_flag = '0'
+ AND f.settle_bill_no = a.settle_bill_no
+ AND f.bl_delay = '1'
+ AND f.apply_date
+ (
+ case
+ when a.credit_period in (30,35,45) then DATE_ADD(STR_TO_DATE(CONCAT(REPLACE(a.bill_month,'-',''),'01'),'%Y%m%d'), INTERVAL 2 MONTH)
+ when a.credit_period in (60,75) then DATE_ADD(STR_TO_DATE(CONCAT(REPLACE(a.bill_month,'-',''),'01'),'%Y%m%d'), INTERVAL 3 MONTH)
+ when a.credit_period = 90 then DATE_ADD(STR_TO_DATE(CONCAT(REPLACE(a.bill_month,'-',''),'01'),'%Y%m%d'), INTERVAL 4 MONTH)
+ else NULL
+ end
+ )
+ )
+ and b.trade_date = ]]>
+ (
+ case
+ when a.credit_period in (30,35,45) then DATE_ADD(STR_TO_DATE(CONCAT(REPLACE(a.bill_month,'-',''),'01'),'%Y%m%d'), INTERVAL 3 MONTH)
+ when a.credit_period in (60,75) then DATE_ADD(STR_TO_DATE(CONCAT(REPLACE(a.bill_month,'-',''),'01'),'%Y%m%d'), INTERVAL 4 MONTH)
+ when a.credit_period = 90 then DATE_ADD(STR_TO_DATE(CONCAT(REPLACE(a.bill_month,'-',''),'01'),'%Y%m%d'), INTERVAL 5 MONTH)
+ else a.payment_due_date
+ end
+ )
+ then ifnull(d.pay_money,0)
+ when (a.settle_type='2' and a.credit_period = ]]> 30 and b.trade_date ]]> a.payment_due_date and b.trade_date = ]]> DATE_SUB( a.payment_due_date, INTERVAL (a.credit_period-60) DAY ) ) or ( ( (a.settle_type='2' and a.credit_period 30) or a.settle_type='1' ) and b.trade_date ]]> a.payment_due_date )
+ then ifnull(d.pay_money,0)
+ else 0
+ end
+ ) AS recdPayMoneyGreat60D
FROM
emis_settle_bill a,
emis_settle_pay_record b,
@@ -833,9 +913,89 @@
SELECT
a.settle_bill_no,
sum( ifnull(d.pay_money,0) ) AS totalPayMoney,
- sum( if(b.trade_date a.payment_due_date,ifnull(d.pay_money,0) ,0) ) AS recdMoneyIn,
- sum( if(a.settle_type='2' and a.credit_period = ]]> 30 and b.trade_date ]]> a.payment_due_date and b.trade_date ]]> a.payment_due_date and b.trade_date DATE_SUB( a.payment_due_date, INTERVAL (a.credit_period-60) DAY ),ifnull(d.pay_money,0) ,0) ) AS recdPayMoney60D,
- sum( if( (a.settle_type='2' and a.credit_period = ]]> 30 and b.trade_date ]]> a.payment_due_date and b.trade_date = ]]> DATE_SUB( a.payment_due_date, INTERVAL (a.credit_period-60) DAY ) ) or ( ( (a.settle_type='2' and a.credit_period 30) or a.settle_type='1' ) and b.trade_date ]]> a.payment_due_date ),ifnull(d.pay_money,0) ,0) ) AS recdPayMoneyGreat60D
+ sum(
+ case
+ when a.settle_type = '2'
+ and a.credit_period in (30,35,45,60,75,90)
+ and EXISTS(
+ SELECT 1
+ FROM emis_settle_invoice_record f
+ WHERE f.del_flag = '0'
+ AND f.settle_bill_no = a.settle_bill_no
+ AND f.bl_delay = '1'
+ AND f.apply_date
+ (
+ case
+ when a.credit_period in (30,35,45) then DATE_ADD(STR_TO_DATE(CONCAT(REPLACE(a.bill_month,'-',''),'01'),'%Y%m%d'), INTERVAL 2 MONTH)
+ when a.credit_period in (60,75) then DATE_ADD(STR_TO_DATE(CONCAT(REPLACE(a.bill_month,'-',''),'01'),'%Y%m%d'), INTERVAL 3 MONTH)
+ when a.credit_period = 90 then DATE_ADD(STR_TO_DATE(CONCAT(REPLACE(a.bill_month,'-',''),'01'),'%Y%m%d'), INTERVAL 4 MONTH)
+ else NULL
+ end
+ )
+ )
+ and b.trade_date
+ (
+ case
+ when a.credit_period in (30,35,45) then DATE_ADD(STR_TO_DATE(CONCAT(REPLACE(a.bill_month,'-',''),'01'),'%Y%m%d'), INTERVAL 3 MONTH)
+ when a.credit_period in (60,75) then DATE_ADD(STR_TO_DATE(CONCAT(REPLACE(a.bill_month,'-',''),'01'),'%Y%m%d'), INTERVAL 4 MONTH)
+ when a.credit_period = 90 then DATE_ADD(STR_TO_DATE(CONCAT(REPLACE(a.bill_month,'-',''),'01'),'%Y%m%d'), INTERVAL 5 MONTH)
+ else a.payment_due_date
+ end
+ )
+ then ifnull(d.pay_money,0)
+ when b.trade_date a.payment_due_date then ifnull(d.pay_money,0)
+ else 0
+ end
+ ) AS recdMoneyIn,
+ sum( if(
+ a.settle_type='2'
+ and a.credit_period = ]]> 30
+ and b.trade_date ]]> a.payment_due_date
+ and b.trade_date ]]> a.payment_due_date
+ and b.trade_date DATE_SUB( a.payment_due_date, INTERVAL (a.credit_period-60) DAY )
+ and NOT EXISTS (
+ SELECT 1
+ FROM emis_settle_invoice_record f
+ WHERE f.del_flag='0'
+ AND f.settle_bill_no = a.settle_bill_no
+ AND f.bl_delay = '1'
+ )
+ ,ifnull(d.pay_money,0) ,0) ) AS recdPayMoney60D,
+ sum(
+ case
+ when a.settle_type = '2'
+ and a.credit_period in (30,35,45,60,75,90)
+ and EXISTS(
+ SELECT 1
+ FROM emis_settle_invoice_record f
+ WHERE f.del_flag = '0'
+ AND f.settle_bill_no = a.settle_bill_no
+ AND f.bl_delay = '1'
+ AND f.apply_date
+ (
+ case
+ when a.credit_period in (30,35,45) then DATE_ADD(STR_TO_DATE(CONCAT(REPLACE(a.bill_month,'-',''),'01'),'%Y%m%d'), INTERVAL 2 MONTH)
+ when a.credit_period in (60,75) then DATE_ADD(STR_TO_DATE(CONCAT(REPLACE(a.bill_month,'-',''),'01'),'%Y%m%d'), INTERVAL 3 MONTH)
+ when a.credit_period = 90 then DATE_ADD(STR_TO_DATE(CONCAT(REPLACE(a.bill_month,'-',''),'01'),'%Y%m%d'), INTERVAL 4 MONTH)
+ else NULL
+ end
+ )
+ )
+ and b.trade_date = ]]>
+ (
+ case
+ when a.credit_period in (30,35,45) then DATE_ADD(STR_TO_DATE(CONCAT(REPLACE(a.bill_month,'-',''),'01'),'%Y%m%d'), INTERVAL 3 MONTH)
+ when a.credit_period in (60,75) then DATE_ADD(STR_TO_DATE(CONCAT(REPLACE(a.bill_month,'-',''),'01'),'%Y%m%d'), INTERVAL 4 MONTH)
+ when a.credit_period = 90 then DATE_ADD(STR_TO_DATE(CONCAT(REPLACE(a.bill_month,'-',''),'01'),'%Y%m%d'), INTERVAL 5 MONTH)
+ else a.payment_due_date
+ end
+ )
+ then ifnull(d.pay_money,0)
+ when (a.settle_type='2' and a.credit_period = ]]> 30 and b.trade_date ]]> a.payment_due_date and b.trade_date = ]]> DATE_SUB( a.payment_due_date, INTERVAL (a.credit_period-60) DAY ) ) or ( ( (a.settle_type='2' and a.credit_period 30) or a.settle_type='1' ) and b.trade_date ]]> a.payment_due_date )
+ then ifnull(d.pay_money,0)
+ else 0
+ end
+ ) AS recdPayMoneyGreat60D
FROM
emis_settle_bill a,
emis_settle_pay_record b,
diff --git a/emis-biz/src/main/resources/mapper/EmisSettlePayRecordMapper.xml b/emis-biz/src/main/resources/mapper/EmisSettlePayRecordMapper.xml
index be3282d31..7edd839ad 100644
--- a/emis-biz/src/main/resources/mapper/EmisSettlePayRecordMapper.xml
+++ b/emis-biz/src/main/resources/mapper/EmisSettlePayRecordMapper.xml
@@ -332,13 +332,78 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
WHERE espbr.del_flag=0 and esb.del_flag=0
and espbr.settle_bill_no=esb.settle_bill_no
- and b.trade_date esb.payment_due_date
+ and (
+ ( esb.settle_type = '2'
+ and esb.credit_period in (30,35,45,60,75,90)
+ and EXISTS(
+ SELECT 1
+ FROM emis_settle_invoice_record f
+ WHERE f.del_flag = '0'
+ AND f.settle_bill_no = esb.settle_bill_no
+ AND f.bl_delay = '1'
+ AND f.apply_date
+ (
+ case
+ when esb.credit_period in (30,35,45) then DATE_ADD(STR_TO_DATE(CONCAT(REPLACE(esb.bill_month,'-',''),'01'),'%Y%m%d'), INTERVAL 2 MONTH)
+ when esb.credit_period in (60,75) then DATE_ADD(STR_TO_DATE(CONCAT(REPLACE(esb.bill_month,'-',''),'01'),'%Y%m%d'), INTERVAL 3 MONTH)
+ when esb.credit_period = 90 then DATE_ADD(STR_TO_DATE(CONCAT(REPLACE(esb.bill_month,'-',''),'01'),'%Y%m%d'), INTERVAL 4 MONTH)
+ else NULL
+ end
+ )
+ )
+ and b.trade_date
+ (
+ case
+ when esb.credit_period in (30,35,45) then DATE_ADD(STR_TO_DATE(CONCAT(REPLACE(esb.bill_month,'-',''),'01'),'%Y%m%d'), INTERVAL 3 MONTH)
+ when esb.credit_period in (60,75) then DATE_ADD(STR_TO_DATE(CONCAT(REPLACE(esb.bill_month,'-',''),'01'),'%Y%m%d'), INTERVAL 4 MONTH)
+ when esb.credit_period = 90 then DATE_ADD(STR_TO_DATE(CONCAT(REPLACE(esb.bill_month,'-',''),'01'),'%Y%m%d'), INTERVAL 5 MONTH)
+ else esb.payment_due_date
+ end
+ )
+ ) or b.trade_date esb.payment_due_date
+ )
- and ( esb.settle_type='2' and esb.credit_period = ]]> 30 and b.trade_date ]]> esb.payment_due_date and b.trade_date ]]> esb.payment_due_date and b.trade_date DATE_SUB( esb.payment_due_date, INTERVAL (esb.credit_period-60) DAY ) )
+ and ( esb.settle_type='2' and esb.credit_period = ]]> 30 and b.trade_date ]]> esb.payment_due_date and b.trade_date ]]> esb.payment_due_date and b.trade_date DATE_SUB( esb.payment_due_date, INTERVAL (esb.credit_period-60) DAY )
+ and NOT EXISTS (
+ SELECT 1
+ FROM emis_settle_invoice_record f
+ WHERE f.del_flag='0'
+ AND f.settle_bill_no = esb.settle_bill_no
+ AND f.bl_delay = '1'
+ ) )
- and ( ( esb.settle_type='2' and esb.credit_period = ]]> 30 and b.trade_date ]]> esb.payment_due_date and b.trade_date = ]]> DATE_SUB( esb.payment_due_date, INTERVAL (esb.credit_period-60) DAY ) ) or ( ( (esb.settle_type='2' and esb.credit_period 30) or esb.settle_type='1' ) and b.trade_date ]]> esb.payment_due_date ) )
+ and (
+ ( esb.settle_type = '2'
+ and esb.credit_period in (30,35,45,60,75,90)
+ and EXISTS(
+ SELECT 1
+ FROM emis_settle_invoice_record f
+ WHERE f.del_flag = '0'
+ AND f.settle_bill_no = esb.settle_bill_no
+ AND f.bl_delay = '1'
+ AND f.apply_date
+ (
+ case
+ when esb.credit_period in (30,35,45) then DATE_ADD(STR_TO_DATE(CONCAT(REPLACE(esb.bill_month,'-',''),'01'),'%Y%m%d'), INTERVAL 2 MONTH)
+ when esb.credit_period in (60,75) then DATE_ADD(STR_TO_DATE(CONCAT(REPLACE(esb.bill_month,'-',''),'01'),'%Y%m%d'), INTERVAL 3 MONTH)
+ when esb.credit_period = 90 then DATE_ADD(STR_TO_DATE(CONCAT(REPLACE(esb.bill_month,'-',''),'01'),'%Y%m%d'), INTERVAL 4 MONTH)
+ else NULL
+ end
+ )
+ )
+ and b.trade_date = ]]>
+ (
+ case
+ when esb.credit_period in (30,35,45) then DATE_ADD(STR_TO_DATE(CONCAT(REPLACE(esb.bill_month,'-',''),'01'),'%Y%m%d'), INTERVAL 3 MONTH)
+ when esb.credit_period in (60,75) then DATE_ADD(STR_TO_DATE(CONCAT(REPLACE(esb.bill_month,'-',''),'01'),'%Y%m%d'), INTERVAL 4 MONTH)
+ when esb.credit_period = 90 then DATE_ADD(STR_TO_DATE(CONCAT(REPLACE(esb.bill_month,'-',''),'01'),'%Y%m%d'), INTERVAL 5 MONTH)
+ else esb.payment_due_date
+ end
+ )
+ ) or ( ( esb.settle_type='2' and esb.credit_period = ]]> 30 and b.trade_date ]]> esb.payment_due_date and b.trade_date = ]]> DATE_SUB( esb.payment_due_date, INTERVAL (esb.credit_period-60) DAY ) ) or ( ( (esb.settle_type='2' and esb.credit_period 30) or esb.settle_type='1' ) and b.trade_date ]]> esb.payment_due_date ) )
+ )