demand: TMS系统 - 客户账单管理 - 收款明细查询 - 查询返回字段增加账单编号、运单号、账单金额、开票金额、开票状态、备注特殊逻辑处理
committer: heyu
This commit is contained in:
parent
551510b4e3
commit
2ceb092cb7
@ -654,16 +654,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<!-- 根据支付ID列表获取开票金额 -->
|
<!-- 根据支付ID列表获取开票金额 -->
|
||||||
<select id="getInvoiceAmountsByPayIds" parameterType="java.util.List" resultType="map">
|
<select id="getInvoiceAmountsByPayIds" parameterType="java.util.List" resultType="map">
|
||||||
select
|
select
|
||||||
espr.pay_id,
|
espbr.pay_id,
|
||||||
SUM(esir.apply_money) as total_amount
|
SUM(esir.money) as total_amount
|
||||||
from emis_settle_pay_record espr
|
from emis_settle_pay_bill_rel espbr
|
||||||
left join emis_settle_invoice_record esir on espr.settle_bill_no = esir.settle_bill_no
|
left join emis_settle_sub_bill essb on espbr.settle_bill_no = essb.settle_bill_no
|
||||||
where espr.del_flag = '0' and esir.del_flag = '0' and esir.invoice_status = '2'
|
left join emis_settle_invoice_rel esir on essb.bill_code = esir.bill_no
|
||||||
and espr.pay_id in
|
left join emis_settle_invoice_record esir_record on esir.apply_seq_no = esir_record.apply_seq_no
|
||||||
|
where espbr.del_flag = '0' and essb.del_flag = '0' and esir.del_flag = '0' and esir_record.del_flag = '0'
|
||||||
|
and esir_record.invoice_status = '2'
|
||||||
|
and espbr.pay_id in
|
||||||
<foreach collection="list" item="payId" open="(" separator="," close=")">
|
<foreach collection="list" item="payId" open="(" separator="," close=")">
|
||||||
#{payId}
|
#{payId}
|
||||||
</foreach>
|
</foreach>
|
||||||
group by espr.pay_id
|
group by espbr.pay_id
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<!-- 根据支付ID列表获取开票状态 -->
|
<!-- 根据支付ID列表获取开票状态 -->
|
||||||
@ -671,82 +674,77 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
select
|
select
|
||||||
pay_id,
|
pay_id,
|
||||||
CONCAT_WS(';',
|
CONCAT_WS(';',
|
||||||
-- 1. 已开票记录(若存在则拼接,否则为NULL)
|
-- 1. 已开票记录(按日期+公司分组)
|
||||||
GROUP_CONCAT(
|
GROUP_CONCAT(
|
||||||
CASE WHEN op_date IS NOT NULL THEN -- 只拼接明细行
|
CASE WHEN invoice_date IS NOT NULL THEN
|
||||||
CONCAT(
|
CONCAT(
|
||||||
DATE_FORMAT(op_date, '%m%d'),
|
DATE_FORMAT(invoice_date, '%m%d'),
|
||||||
'已开票',
|
'已开票',
|
||||||
CASE
|
CASE
|
||||||
WHEN total_amount = FLOOR(total_amount) THEN CAST(FLOOR(total_amount) AS CHAR)
|
WHEN invoice_amount = FLOOR(invoice_amount) THEN CAST(FLOOR(invoice_amount) AS CHAR)
|
||||||
ELSE TRIM(TRAILING '0' FROM TRIM(TRAILING '.' FROM CAST(total_amount AS CHAR)))
|
ELSE TRIM(TRAILING '0' FROM TRIM(TRAILING '.' FROM CAST(invoice_amount AS CHAR)))
|
||||||
END,
|
END,
|
||||||
' ',
|
' ',
|
||||||
company_name
|
company_name
|
||||||
)
|
)
|
||||||
END
|
END
|
||||||
ORDER BY op_date
|
ORDER BY invoice_date
|
||||||
SEPARATOR ';'
|
SEPARATOR ';'
|
||||||
),
|
),
|
||||||
-- 2. 剩余未开金额(从汇总行提取计算)
|
-- 2. 剩余未开金额
|
||||||
CASE
|
CASE
|
||||||
WHEN (MAX(bill_amount) - MAX(invoice_amount)) > 0
|
WHEN (bill_amount - total_invoice_amount) > 0
|
||||||
THEN CONCAT('剩余未开',
|
THEN CONCAT('剩余未开',
|
||||||
CASE
|
CASE
|
||||||
WHEN (MAX(bill_amount) - MAX(invoice_amount)) = FLOOR(MAX(bill_amount) - MAX(invoice_amount))
|
WHEN (bill_amount - total_invoice_amount) = FLOOR(bill_amount - total_invoice_amount)
|
||||||
THEN CAST(FLOOR(MAX(bill_amount) - MAX(invoice_amount)) AS CHAR)
|
THEN CAST(FLOOR(bill_amount - total_invoice_amount) AS CHAR)
|
||||||
ELSE TRIM(TRAILING '0' FROM TRIM(TRAILING '.' FROM CAST((MAX(bill_amount) - MAX(invoice_amount)) AS CHAR)))
|
ELSE TRIM(TRAILING '0' FROM TRIM(TRAILING '.' FROM CAST((bill_amount - total_invoice_amount) AS CHAR)))
|
||||||
END, '元')
|
END, '元')
|
||||||
ELSE ''
|
ELSE ''
|
||||||
END
|
END
|
||||||
) as status
|
) as status
|
||||||
from (
|
from (
|
||||||
-- 子查询1:已开票明细行(按日期分组)
|
-- 子查询1:已开票明细行(按日期+公司分组)
|
||||||
select
|
select
|
||||||
espr.pay_id,
|
espbr.pay_id,
|
||||||
esir.op_date,
|
DATE(esir_record.op_date) as invoice_date,
|
||||||
SUM(esir.apply_money) as total_amount,
|
SUM(esir.money) as invoice_amount,
|
||||||
GROUP_CONCAT(DISTINCT esir.company_name SEPARATOR ' ') as company_name,
|
GROUP_CONCAT(DISTINCT esir_record.company_name SEPARATOR ' ') as company_name,
|
||||||
0 as total_invoiced_amount, -- 明细行不参与汇总计算
|
0 as total_invoice_amount,
|
||||||
0 as bill_amount,
|
0 as bill_amount
|
||||||
0 as invoice_amount
|
from emis_settle_pay_bill_rel espbr
|
||||||
from emis_settle_pay_record espr
|
left join emis_settle_sub_bill essb on espbr.settle_bill_no = essb.settle_bill_no
|
||||||
left join emis_settle_pay_bill_rel espbr on espr.pay_id = espbr.pay_id
|
left join emis_settle_invoice_rel esir on essb.bill_code = esir.bill_no
|
||||||
left join emis_settle_invoice_record esir on espbr.settle_bill_no = esir.settle_bill_no
|
left join emis_settle_invoice_record esir_record on esir.apply_seq_no = esir_record.apply_seq_no
|
||||||
where espr.del_flag = '0'
|
where espbr.del_flag = '0' and essb.del_flag = '0' and esir.del_flag = '0' and esir_record.del_flag = '0'
|
||||||
and espbr.del_flag = '0'
|
and esir_record.invoice_status = '2'
|
||||||
and esir.del_flag = '0'
|
and espbr.pay_id in
|
||||||
and esir.invoice_status = '2'
|
|
||||||
and espr.pay_id in
|
|
||||||
<foreach collection="list" item="payId" open="(" separator="," close=")">
|
<foreach collection="list" item="payId" open="(" separator="," close=")">
|
||||||
#{payId}
|
#{payId}
|
||||||
</foreach>
|
</foreach>
|
||||||
group by espr.pay_id, esir.op_date
|
group by espbr.pay_id, DATE(esir_record.op_date), esir_record.company_name
|
||||||
|
|
||||||
UNION ALL
|
UNION ALL
|
||||||
|
|
||||||
-- 子查询2:汇总行(计算总开票金额和账单金额)
|
-- 子查询2:汇总行(计算总开票金额和账单金额)
|
||||||
select
|
select
|
||||||
espr.pay_id,
|
espbr.pay_id,
|
||||||
NULL as op_date, -- 汇总行无日期,用于区分
|
NULL as invoice_date,
|
||||||
0 as total_amount,
|
0 as invoice_amount,
|
||||||
'' as company_name,
|
'' as company_name,
|
||||||
SUM(CASE WHEN esir.invoice_status = '2' THEN esir.apply_money ELSE 0 END) as total_invoiced_amount,
|
SUM(CASE WHEN esir_record.invoice_status = '2' THEN esir.money ELSE 0 END) as total_invoice_amount,
|
||||||
MAX(esb.rec_money) as bill_amount,
|
MAX(esb.rec_money) as bill_amount
|
||||||
SUM(CASE WHEN esir.invoice_status = '2' THEN esir.apply_money ELSE 0 END) as invoice_amount
|
from emis_settle_pay_bill_rel espbr
|
||||||
from emis_settle_pay_record espr
|
left join emis_settle_sub_bill essb on espbr.settle_bill_no = essb.settle_bill_no
|
||||||
left join emis_settle_pay_bill_rel espbr on espr.pay_id = espbr.pay_id
|
|
||||||
left join emis_settle_bill esb on espbr.settle_bill_no = esb.settle_bill_no
|
left join emis_settle_bill esb on espbr.settle_bill_no = esb.settle_bill_no
|
||||||
left join emis_settle_invoice_record esir on espbr.settle_bill_no = esir.settle_bill_no
|
left join emis_settle_invoice_rel esir on essb.bill_code = esir.bill_no
|
||||||
where espr.del_flag = '0'
|
left join emis_settle_invoice_record esir_record on esir.apply_seq_no = esir_record.apply_seq_no
|
||||||
and espbr.del_flag = '0'
|
where espbr.del_flag = '0' and essb.del_flag = '0' and esb.del_flag = '0' and esir.del_flag = '0' and esir_record.del_flag = '0'
|
||||||
and esb.del_flag = '0'
|
and espbr.pay_id in
|
||||||
and esir.del_flag = '0'
|
|
||||||
and espr.pay_id in
|
|
||||||
<foreach collection="list" item="payId" open="(" separator="," close=")">
|
<foreach collection="list" item="payId" open="(" separator="," close=")">
|
||||||
#{payId}
|
#{payId}
|
||||||
</foreach>
|
</foreach>
|
||||||
group by espr.pay_id
|
group by espbr.pay_id
|
||||||
) invoice_summary
|
) invoice_summary
|
||||||
group by pay_id
|
group by pay_id
|
||||||
</select>
|
</select>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user