emis-service/emis-biz/src/main/resources/mapper/EmisSettleInvoiceChRecordMapper.xml

878 lines
54 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.xdadan.erp.emis.mapper.EmisSettleInvoiceChRecordMapper">
<resultMap type="EmisSettleInvoiceChRecord" id="EmisSettleInvoiceChRecordResult" extends="com.xdadan.erp.emis.mapper.EmisBaseMapper.EmisBaseResult">
<result property="id" column="id" />
<result property="reqNo" column="req_no" />
<result property="applySeqNo" column="apply_seq_no" />
<result property="blEcinv" column="bl_ecinv" />
<result property="invoiceType" column="invoice_type" />
<result property="realInvoiceType" column="real_invoice_type" />
<result property="companyName" column="company_name" />
<result property="companyTaxNo" column="company_tax_no" />
<result property="companyTel" column="company_tel" />
<result property="companyAddress" column="company_address" />
<result property="bankName" column="bank_name" />
<result property="bankAccNo" column="bank_acc_no" />
<result property="contact" column="contact" />
<result property="phone" column="phone" />
<result property="taxRate" column="tax_rate" />
<result property="openMoney" column="open_money" />
<result property="email" column="email" />
<result property="salerCompanyName" column="saler_company_name" />
<result property="salerCompanyTaxNo" column="saler_company_tax_no" />
<result property="salerCompanyTel" column="saler_company_tel" />
<result property="salerCompanyAddress" column="saler_company_address" />
<result property="salerBankName" column="saler_bank_name" />
<result property="salerBankAccNo" column="saler_bank_acc_no" />
<result property="salerContact" column="saler_contact" />
<result property="salerPhone" column="saler_phone" />
<result property="salerChecker" column="saler_checker" />
<result property="salerPayee" column="saler_payee" />
<result property="invoiceNo" column="invoice_no" />
<result property="filePath" column="file_path" />
<result property="qrPath" column="qr_path" />
<result property="opManCode" column="op_man_code" />
<result property="opDate" column="op_date" />
<result property="opSiteCode" column="op_site_code" />
<result property="openChId" column="open_ch_id" />
<result property="openChStatus" column="open_ch_status" />
<result property="openChStatusDesc" column="open_ch_status_desc" />
<result property="openComCode" column="open_com_code" />
<result property="extData" column="ext_data" />
<result property="sendMonth" column="send_month" />
<result property="settleType" column="settle_type" />
<result property="openBillRemark" column="open_bill_remark" />
<result property="payDays" column="pay_days" />
<association property="billMonth" column="apply_seq_no" select="com.xdadan.erp.emis.mapper.EmisBaseMapper.selectBillMonthByApplySeqNo"/>
<association property="billCode" column="apply_seq_no" select="com.xdadan.erp.emis.mapper.EmisBaseMapper.selectBillCodeByApplySeqNo"/>
<association property="salesmen" column="apply_seq_no" select="com.xdadan.erp.emis.mapper.EmisBaseMapper.selectSalesmenByApplySeqNo"/>
<association property="applyManName" column="apply_seq_no" select="com.xdadan.erp.emis.mapper.EmisBaseMapper.selectApplyManNameByApplySeqNo"/>
<association property="applyRemark" column="apply_seq_no" select="com.xdadan.erp.emis.mapper.EmisBaseMapper.selectApplyRemarkByApplySeqNo"/>
</resultMap>
<resultMap type="EmisSettleInvoiceChRecord" id="EmisSettleInvoiceChRecordListResult" extends="com.xdadan.erp.emis.mapper.EmisBaseMapper.EmisBaseResultAll">
<result property="id" column="id" />
<result property="reqNo" column="req_no" />
<result property="applySeqNo" column="apply_seq_no" />
<result property="blEcinv" column="bl_ecinv" />
<result property="invoiceType" column="invoice_type" />
<result property="realInvoiceType" column="real_invoice_type" />
<result property="companyName" column="company_name" />
<result property="companyTaxNo" column="company_tax_no" />
<result property="companyTel" column="company_tel" />
<result property="companyAddress" column="company_address" />
<result property="bankName" column="bank_name" />
<result property="bankAccNo" column="bank_acc_no" />
<result property="contact" column="contact" />
<result property="phone" column="phone" />
<result property="taxRate" column="tax_rate" />
<result property="openMoney" column="open_money" />
<result property="email" column="email" />
<result property="salerCompanyName" column="saler_company_name" />
<result property="salerCompanyTaxNo" column="saler_company_tax_no" />
<result property="salerCompanyTel" column="saler_company_tel" />
<result property="salerCompanyAddress" column="saler_company_address" />
<result property="salerBankName" column="saler_bank_name" />
<result property="salerBankAccNo" column="saler_bank_acc_no" />
<result property="salerContact" column="saler_contact" />
<result property="salerPhone" column="saler_phone" />
<result property="salerChecker" column="saler_checker" />
<result property="salerPayee" column="saler_payee" />
<result property="invoiceNo" column="invoice_no" />
<result property="filePath" column="file_path" />
<result property="qrPath" column="qr_path" />
<result property="opManCode" column="op_man_code" />
<result property="opDate" column="op_date" />
<result property="opSiteCode" column="op_site_code" />
<result property="openChId" column="open_ch_id" />
<result property="openChStatus" column="open_ch_status" />
<result property="openChStatusDesc" column="open_ch_status_desc" />
<result property="openComCode" column="open_com_code" />
<result property="extData" column="ext_data" />
<result property="sendMonth" column="send_month" />
<result property="settleType" column="settle_type" />
<result property="openBillRemark" column="open_bill_remark" />
<result property="payDays" column="pay_days" />
<result property="billMonth" column="bill_month" />
<result property="billCode" column="bill_code" />
<result property="salesmen" column="salesmen" />
<result property="applyManName" column="apply_man_name" />
<result property="applyRemark" column="apply_remark" />
</resultMap>
<sql id="selectEmisSettleInvoiceChRecordVo">
select id, req_no, apply_seq_no, bl_ecinv, invoice_type, real_invoice_type, company_name, company_tax_no, company_tel, company_address, bank_name, bank_acc_no, contact, phone, tax_rate, open_money, email, saler_company_name, saler_company_tax_no, saler_company_tel, saler_company_address, saler_bank_name, saler_bank_acc_no, saler_contact, saler_phone, saler_checker, saler_payee, invoice_no, file_path, qr_path, op_man_code, op_date, op_site_code, open_ch_id, open_ch_status, open_ch_status_desc, open_com_code, ext_data, remark, del_flag, create_by, create_time, update_by, update_time, create_site, update_site from emis_settle_invoice_ch_record
</sql>
<select id="selectEmisSettleInvoiceChRecordList" parameterType="EmisSettleInvoiceChRecord" resultMap="EmisSettleInvoiceChRecordResult">
select id, req_no, apply_seq_no, bl_ecinv, invoice_type, real_invoice_type, company_name, company_tax_no, company_tel, company_address, bank_name, bank_acc_no, contact, phone, tax_rate, open_money, email, saler_company_name, saler_company_tax_no, saler_company_tel, saler_company_address, saler_bank_name, saler_bank_acc_no, saler_contact, saler_phone, saler_checker, saler_payee, invoice_no, file_path, qr_path, op_man_code, op_date, op_site_code, open_ch_id, open_ch_status, open_ch_status_desc, open_com_code, ext_data, remark, del_flag, create_by, create_time, update_by, update_time, create_site, update_site
from emis_settle_invoice_ch_record a
<where>
del_flag='0'
<if test="id != null "> and id = #{id}</if>
<if test="reqNo != null and reqNo != ''"> and req_no = #{reqNo}</if>
<if test="applySeqNo != null and applySeqNo != ''"> and apply_seq_no = #{applySeqNo}</if>
<if test="blEcinv != null and blEcinv != ''"> and bl_ecinv = #{blEcinv}</if>
<if test="invoiceType != null and invoiceType != ''"> and invoice_type = #{invoiceType}</if>
<if test="realInvoiceType != null and realInvoiceType != ''"> and real_invoice_type = #{realInvoiceType}</if>
<if test="companyName != null and companyName != ''"> and company_name = #{companyName}</if>
<if test="companyTaxNo != null and companyTaxNo != ''"> and company_tax_no = #{companyTaxNo}</if>
<if test="companyTel != null and companyTel != ''"> and company_tel = #{companyTel}</if>
<if test="companyAddress != null and companyAddress != ''"> and company_address = #{companyAddress}</if>
<if test="bankName != null and bankName != ''"> and bank_name = #{bankName}</if>
<if test="bankAccNo != null and bankAccNo != ''"> and bank_acc_no = #{bankAccNo}</if>
<if test="contact != null and contact != ''"> and contact = #{contact}</if>
<if test="phone != null and phone != ''"> and phone = #{phone}</if>
<if test="taxRate != null and taxRate != ''"> and tax_rate = #{taxRate}</if>
<if test="openMoney != null "> and open_money = #{openMoney}</if>
<if test="email != null and email != ''"> and email = #{email}</if>
<if test="salerCompanyName != null and salerCompanyName != ''"> and saler_company_name = #{salerCompanyName}</if>
<if test="salerCompanyTaxNo != null and salerCompanyTaxNo != ''"> and saler_company_tax_no = #{salerCompanyTaxNo}</if>
<if test="salerCompanyTel != null and salerCompanyTel != ''"> and saler_company_tel = #{salerCompanyTel}</if>
<if test="salerCompanyAddress != null and salerCompanyAddress != ''"> and saler_company_address = #{salerCompanyAddress}</if>
<if test="salerBankName != null and salerBankName != ''"> and saler_bank_name = #{salerBankName}</if>
<if test="salerBankAccNo != null and salerBankAccNo != ''"> and saler_bank_acc_no = #{salerBankAccNo}</if>
<if test="salerContact != null and salerContact != ''"> and saler_contact = #{salerContact}</if>
<if test="salerPhone != null and salerPhone != ''"> and saler_phone = #{salerPhone}</if>
<if test="invoiceNo != null and invoiceNo != ''"> and invoice_no = #{invoiceNo}</if>
<if test="filePath != null and filePath != ''"> and file_path like concat('%', #{filePath}, '%')</if>
<if test="qrPath != null and qrPath != ''"> and qr_path like concat('%', #{qrPath}, '%')</if>
<if test="opManCode != null and opManCode != ''"> and op_man_code = #{opManCode}</if>
<if test="opDate != null "> and op_date = #{opDate}</if>
<if test="opSiteCode != null and opSiteCode != ''"> and op_site_code = #{opSiteCode}</if>
<if test="openChId != null and openChId != ''"> and open_ch_id = #{openChId}</if>
<if test="openChStatus != null and openChStatus != ''"> and open_ch_status = #{openChStatus}</if>
<if test="openChStatusDesc != null and openChStatusDesc != ''"> and open_ch_status_desc like concat('%', #{openChStatusDesc}, '%')</if>
<if test="openComCode != null and openComCode != ''"> and open_com_code = #{openComCode}</if>
<if test="extData != null and extData != ''"> and ext_data like concat('%', #{extData}, '%')</if>
<if test="remark != null and remark != ''"> and remark like concat('%', #{remark}, '%')</if>
<if test="delFlag != null and delFlag != ''"> and del_flag like concat('%', #{delFlag}, '%')</if>
<if test="createBy != null and createBy != ''"> and create_by like concat('%', #{createBy}, '%')</if>
<if test="createTime != null "> and create_time = #{createTime}</if>
<if test="updateBy != null and updateBy != ''"> and update_by like concat('%', #{updateBy}, '%')</if>
<if test="updateTime != null "> and update_time = #{updateTime}</if>
<if test="createSite != null and createSite != ''"> and create_site like concat('%', #{createSite}, '%')</if>
<if test="updateSite != null and updateSite != ''"> and update_site like concat('%', #{updateSite}, '%')</if>
<if test="params.beginCreateTime != null and params.beginCreateTime != ''">
and create_time <![CDATA[ >= ]]> #{params.beginCreateTime}
</if>
<if test="params.endCreateTime != null and params.endCreateTime != ''">
and create_time <![CDATA[ <= ]]> #{params.endCreateTime}
</if>
<!-- 客户编号查询条件 -->
<if test="custNo != null and params.custNo != ''">
and EXISTS (
select 1 from emis_settle_invoice_rel ir
inner join emis_waybill w on w.bill_code = ir.bill_no and w.del_flag = '0'
where ir.del_flag = '0' and a.apply_seq_no = ir.apply_seq_no
and w.cust_no = #{custNo}
)
</if>
<!-- 收款人查询条件 -->
<if test="payee != null and params.payee != ''">
and EXISTS (
select 1 from emis_settle_invoice_bill_rel ibr
inner join emis_settle_bill b on b.settle_bill_no = ibr.settle_bill_no and b.del_flag = '0'
where ibr.del_flag = '0' and a.apply_seq_no = ibr.apply_seq_no
and b.payee = #{payee}
)
</if>
<!-- 业务员查询条件 -->
<if test="salesmen != null and params.salesmen != ''">
and EXISTS (
select 1 from emis_settle_invoice_bill_rel ibr
inner join emis_settle_bill b on b.settle_bill_no = ibr.settle_bill_no and b.del_flag = '0'
where ibr.del_flag = '0' and a.apply_seq_no = ibr.apply_seq_no
and b.salesmen = #{salesmen}
)
</if>
<!-- 账单月份查询条件 -->
<if test="billMonth != null and params.billMonth != ''">
and EXISTS (
select 1 from emis_settle_invoice_bill_rel ibr
inner join emis_settle_bill b on b.settle_bill_no = ibr.settle_bill_no and b.del_flag = '0'
where ibr.del_flag = '0' and a.apply_seq_no = ibr.apply_seq_no
and b.bill_month = #{billMonth}
)
</if>
<!-- 付款状态查询条件 -->
<if test="paymentStatus != null and params.paymentStatus != ''">
and EXISTS (
select 1 from emis_settle_invoice_bill_rel ibr
inner join emis_settle_pay_bill_rel pbr on pbr.settle_bill_no = ibr.settle_bill_no
inner join emis_settle_pay_record pr on pr.pay_id = pbr.pay_id
where ibr.del_flag = '0' and a.apply_seq_no = ibr.apply_seq_no
and pr.pay_status = #{paymentStatus}
)
</if>
<if test="params.billCode != null and params.billCode != ''">
and EXISTS(
select 1 from
emis_settle_invoice_rel rel
where a.apply_seq_no=rel.apply_seq_no and
rel.del_flag = '0'
and FIND_IN_SET(rel.bill_no, REPLACE(#{params.billCode}, '\n', ','))
)
<!--
AND apply_seq_no IN (
SELECT x1.apply_seq_no FROM
emis_settle_invoice_record x1,
emis_settle_bill x2
WHERE
x1.del_flag = '0'
AND x2.del_flag = '0'
AND FIND_IN_SET( x2.settle_bill_no, x1.settle_bill_no )
AND exists (
select 1 from emis_settle_sub_bill b
where x2.settle_bill_no=b.settle_bill_no
and ( FIND_IN_SET(b.`bill_code`,#{params.billCode}) or b.bill_code like concat('%', #{params.billCode}, '%') )
)
)
-->
</if>
<if test="params.settleBillNo != null and params.settleBillNo != ''">
<!--
AND apply_seq_no IN (
SELECT x1.apply_seq_no FROM emis_settle_invoice_record x1,emis_settle_bill x2
WHERE x1.del_flag = '0' AND x2.del_flag = '0'
AND FIND_IN_SET( x2.settle_bill_no, x1.settle_bill_no )
AND x2.settle_bill_no=#{params.settleBillNo}
)
-->
and EXISTS(
select 1 from emis_settle_invoice_bill_rel x3
where x3.del_flag = '0'
and a.apply_seq_no=x3.apply_seq_no
and FIND_IN_SET(x3.settle_bill_no, REPLACE(#{params.settleBillNo}, '\n', ','))
)
</if>
<if test="params.privSiteCode != null and params.privSiteCode != '88888'">
and EXISTS(
select 1 from emis_settle_bill x2,emis_settle_invoice_bill_rel x3
where x2.del_flag = '0' and x3.del_flag = '0'
and a.apply_seq_no=x3.apply_seq_no and x2.settle_bill_no=x3.settle_bill_no
AND (
x2.salesmen = #{params.privEmpName}
OR x2.payee = #{params.privEmpName}
OR x2.salesmen IN (
SELECT salesmen
FROM emis_salesmen_rel esr
where esr.del_flag='0' and esr.bl_open='1'
and now() <![CDATA[ >= ]]> esr.start_date and now() <![CDATA[ <= ]]> esr.end_date
and esr.sales_ass = #{params.privEmpName}
)
)
)
<!--
AND apply_seq_no IN (
SELECT x1.apply_seq_no FROM
emis_settle_invoice_record x1,
emis_settle_bill x2
WHERE x1.del_flag = '0' AND x2.del_flag = '0'
AND FIND_IN_SET( x2.settle_bill_no, x1.settle_bill_no )
AND exists (
select 1 from emis_settle_sub_bill b
where x2.settle_bill_no=b.settle_bill_no
and ( b.salesmen=#{params.privEmpName} or b.payee=#{params.privEmpName}
or b.salesmen in(select salesmen from emis_salesmen_rel esr where esr.del_flag='0' and esr.bl_open='1' and now() <![CDATA[ >= ]]> esr.start_date and now() <![CDATA[ <= ]]> esr.end_date and esr.sales_ass=#{params.privEmpName})
)
)
) -->
</if>
</where>
order by create_time desc
</select>
<select id="selectEmisSettleInvoiceChRecordListAll" parameterType="EmisSettleInvoiceChRecord" resultMap="EmisSettleInvoiceChRecordListResult">
SELECT
a.*,
bi.bill_month,
bi.bill_code,
si.salesmen,
si.apply_man_name,
si.apply_remark,
smi.send_month,
bri.settle_type,
bri.open_bill_remark,
pdi.pay_days,
cu.emp_name as create_by_name,
uu.emp_name as update_by_name,
cs.site_name as create_site_name,
us.site_name as update_site_name
FROM emis_settle_invoice_ch_record a
LEFT JOIN (
SELECT
bd.id,
GROUP_CONCAT(DISTINCT DATE_FORMAT(w.send_date, '%Y%m') ORDER BY w.send_date) as bill_month,
GROUP_CONCAT(DISTINCT w.bill_code ORDER BY w.bill_code) as bill_code
FROM emis_settle_invoice_ch_record bd
LEFT JOIN emis_settle_invoice_rel ir ON ir.apply_seq_no = bd.apply_seq_no AND ir.del_flag = '0'
LEFT JOIN emis_waybill w ON w.bill_code = ir.bill_no AND w.del_flag = '0'
WHERE bd.del_flag = '0'
GROUP BY bd.id
) bi ON bi.id = a.id
LEFT JOIN (
SELECT
bd.id,
GROUP_CONCAT(DISTINCT esb.salesmen) as salesmen,
MAX(user.emp_name) as apply_man_name,
MAX(record.remark) as apply_remark
FROM emis_settle_invoice_ch_record bd
LEFT JOIN emis_settle_invoice_record record ON record.apply_seq_no = bd.apply_seq_no AND record.del_flag = '0'
LEFT JOIN sys_user user ON user.user_id = record.create_by AND user.del_flag = '0'
LEFT JOIN emis_settle_invoice_bill_rel ibr ON ibr.apply_seq_no = bd.apply_seq_no AND ibr.del_flag = '0'
LEFT JOIN emis_settle_bill esb ON esb.settle_bill_no = ibr.settle_bill_no AND esb.del_flag = '0'
WHERE bd.del_flag = '0'
GROUP BY bd.id
) si ON si.id = a.id
LEFT JOIN (
SELECT
bd.id,
GROUP_CONCAT(DISTINCT CONCAT(SUBSTRING(DATE_FORMAT(w.send_date, '%Y'), 3, 2), DATE_FORMAT(w.send_date, '%m'))) as send_month
FROM emis_settle_invoice_ch_record bd
LEFT JOIN emis_settle_invoice_rel ir ON ir.apply_seq_no = bd.apply_seq_no AND ir.del_flag = '0'
LEFT JOIN emis_waybill w ON w.bill_code = ir.bill_no AND w.del_flag = '0'
WHERE bd.del_flag = '0'
GROUP BY bd.id
) smi ON smi.id = a.id
LEFT JOIN (
SELECT
bd.id,
GROUP_CONCAT(DISTINCT
CONCAT(
DATE_FORMAT(pr.trade_date, '%m/%d'),
' 已付(',
CASE pr.pay_type
WHEN '1' THEN '企业微信收款'
WHEN '2' THEN '工行汇款3890'
WHEN '3' THEN '微信支付'
WHEN '4' THEN '支付宝'
WHEN '5' THEN '其他'
WHEN '6' THEN '招行付款'
ELSE pr.pay_type
END,
')'
)
) as pay_days
FROM emis_settle_invoice_ch_record bd
LEFT JOIN emis_settle_invoice_bill_rel ibr ON ibr.apply_seq_no = bd.apply_seq_no AND ibr.del_flag = '0'
LEFT JOIN emis_settle_pay_bill_rel pbr ON ibr.settle_bill_no = pbr.settle_bill_no
LEFT JOIN emis_settle_pay_record pr ON pr.pay_id = pbr.pay_id
WHERE bd.del_flag = '0'
GROUP BY bd.id
) pdi ON pdi.id = a.id
LEFT JOIN (
SELECT
bd.id,
b.settle_type,
CASE
WHEN b.settle_type = '2' THEN
GROUP_CONCAT(DISTINCT
CONCAT(
CONCAT(SUBSTRING(DATE_FORMAT(w.send_date, '%Y'), 3, 2), DATE_FORMAT(w.send_date, '%m ')),
b.cust_name
) SEPARATOR '-'
)
ELSE
GROUP_CONCAT(DISTINCT
CONCAT(
DATE_FORMAT(w.send_date, '%m%d '),
w.send_company
) SEPARATOR '-'
)
END as open_bill_remark
FROM emis_settle_invoice_ch_record bd
LEFT JOIN emis_settle_invoice_rel ir ON ir.apply_seq_no = bd.apply_seq_no AND ir.del_flag = '0'
LEFT JOIN emis_waybill w ON w.bill_code = ir.bill_no AND w.del_flag = '0'
LEFT JOIN emis_settle_invoice_bill_rel ibr ON ibr.apply_seq_no = bd.apply_seq_no AND ibr.del_flag = '0'
LEFT JOIN emis_settle_bill b ON b.settle_bill_no = ibr.settle_bill_no AND b.del_flag = '0'
WHERE bd.del_flag = '0'
GROUP BY bd.id, b.settle_type
) bri ON bri.id = a.id
LEFT JOIN sys_user cu ON cu.user_id = a.create_by AND cu.del_flag = '0'
LEFT JOIN sys_user uu ON uu.user_id = a.update_by AND uu.del_flag = '0'
LEFT JOIN emis_site cs ON cs.site_code = a.create_site AND cs.del_flag = '0'
LEFT JOIN emis_site us ON us.site_code = a.update_site AND us.del_flag = '0'
WHERE a.del_flag = '0'
<if test="id != null">AND a.id = #{id}</if>
<if test="reqNo != null and reqNo != ''">AND a.req_no = #{reqNo}</if>
<if test="applySeqNo != null and applySeqNo != ''">AND a.apply_seq_no = #{applySeqNo}</if>
<if test="blEcinv != null and blEcinv != ''">AND a.bl_ecinv = #{blEcinv}</if>
<if test="invoiceType != null and invoiceType != ''">AND a.invoice_type = #{invoiceType}</if>
<if test="realInvoiceType != null and realInvoiceType != ''"> and a.real_invoice_type = #{realInvoiceType}</if>
<if test="companyName != null and companyName != ''">AND a.company_name = #{companyName}</if>
<if test="companyTaxNo != null and companyTaxNo != ''"> and a.company_tax_no = #{companyTaxNo}</if>
<if test="companyTel != null and companyTel != ''"> and a.company_tel = #{companyTel}</if>
<if test="companyAddress != null and companyAddress != ''"> and a.company_address = #{companyAddress}</if>
<if test="bankName != null and bankName != ''"> and a.bank_name = #{bankName}</if>
<if test="bankAccNo != null and bankAccNo != ''"> and a.bank_acc_no = #{bankAccNo}</if>
<if test="contact != null and contact != ''"> and a.contact = #{contact}</if>
<if test="phone != null and phone != ''"> and a.phone = #{phone}</if>
<if test="taxRate != null and taxRate != ''"> and a.tax_rate = #{taxRate}</if>
<if test="openMoney != null "> and a.open_money = #{openMoney}</if>
<if test="email != null and email != ''"> and a.email = #{email}</if>
<if test="salerCompanyName != null and salerCompanyName != ''"> and a.saler_company_name = #{salerCompanyName}</if>
<if test="salerCompanyTaxNo != null and salerCompanyTaxNo != ''"> and a.saler_company_tax_no = #{salerCompanyTaxNo}</if>
<if test="salerCompanyTel != null and salerCompanyTel != ''"> and a.saler_company_tel = #{salerCompanyTel}</if>
<if test="salerCompanyAddress != null and salerCompanyAddress != ''"> and a.saler_company_address = #{salerCompanyAddress}</if>
<if test="salerBankName != null and salerBankName != ''"> and a.saler_bank_name = #{salerBankName}</if>
<if test="salerBankAccNo != null and salerBankAccNo != ''"> and a.saler_bank_acc_no = #{salerBankAccNo}</if>
<if test="salerContact != null and salerContact != ''"> and a.saler_contact = #{salerContact}</if>
<if test="salerPhone != null and salerPhone != ''"> and a.saler_phone = #{salerPhone}</if>
<if test="invoiceNo != null and invoiceNo != ''"> and a.invoice_no = #{invoiceNo}</if>
<if test="filePath != null and filePath != ''"> and a.file_path like concat('%', #{filePath}, '%')</if>
<if test="qrPath != null and qrPath != ''"> and a.qr_path like concat('%', #{qrPath}, '%')</if>
<if test="opManCode != null and opManCode != ''"> and a.op_man_code = #{opManCode}</if>
<if test="opDate != null "> and a.op_date = #{opDate}</if>
<if test="opSiteCode != null and opSiteCode != ''"> and a.op_site_code = #{opSiteCode}</if>
<if test="openChId != null and openChId != ''"> and a.open_ch_id = #{openChId}</if>
<if test="openChStatus != null and openChStatus != ''"> and a.open_ch_status = #{openChStatus}</if>
<if test="openChStatusDesc != null and openChStatusDesc != ''"> and a.open_ch_status_desc like concat('%', #{openChStatusDesc}, '%')</if>
<if test="openComCode != null and openComCode != ''"> and a.open_com_code = #{openComCode}</if>
<if test="extData != null and extData != ''"> and a.ext_data like concat('%', #{extData}, '%')</if>
<if test="remark != null and remark != ''"> and a.remark like concat('%', #{remark}, '%')</if>
<if test="delFlag != null and delFlag != ''"> and a.del_flag like concat('%', #{delFlag}, '%')</if>
<if test="createBy != null and createBy != ''"> and a.create_by like concat('%', #{createBy}, '%')</if>
<if test="createTime != null "> and a.create_time = #{createTime}</if>
<if test="updateBy != null and updateBy != ''"> and a.update_by like concat('%', #{updateBy}, '%')</if>
<if test="updateTime != null "> and a.update_time = #{updateTime}</if>
<if test="createSite != null and createSite != ''"> and a.create_site like concat('%', #{createSite}, '%')</if>
<if test="updateSite != null and updateSite != ''"> and a.update_site like concat('%', #{updateSite}, '%')</if>
<if test="params.beginCreateTime != null and params.beginCreateTime != ''">
AND a.create_time >= STR_TO_DATE(#{params.beginCreateTime}, '%Y-%m-%d')
</if>
<if test="params.endCreateTime != null and params.endCreateTime != ''">
AND a.create_time <![CDATA[ <= ]]> DATE_ADD(STR_TO_DATE(#{params.endCreateTime}, '%Y-%m-%d'), INTERVAL 1 DAY)
</if>
<if test="params.billCode != null and params.billCode != ''">
and EXISTS(
select 1 from
emis_settle_invoice_rel rel
where a.apply_seq_no=rel.apply_seq_no and
rel.del_flag = '0'
and FIND_IN_SET(rel.bill_no, REPLACE(#{params.billCode}, '\n', ','))
)
</if>
<if test="params.settleBillNo != null and params.settleBillNo != ''">
AND EXISTS (
SELECT 1
FROM emis_settle_invoice_bill_rel x3
WHERE x3.del_flag = '0'
AND a.apply_seq_no = x3.apply_seq_no
and FIND_IN_SET(x3.settle_bill_no, REPLACE(#{params.settleBillNo}, '\n', ','))
)
</if>
<if test="params.privSiteCode != null and params.privSiteCode != '88888'">
AND EXISTS (
SELECT 1
FROM emis_settle_bill x2
INNER JOIN emis_settle_invoice_bill_rel x3 ON x2.settle_bill_no = x3.settle_bill_no
WHERE x2.del_flag = '0'
AND x3.del_flag = '0'
AND a.apply_seq_no = x3.apply_seq_no
AND (
x2.salesmen = #{params.privEmpName}
OR x2.payee = #{params.privEmpName}
OR EXISTS (
SELECT 1
FROM emis_salesmen_rel esr
WHERE esr.del_flag = '0'
AND esr.bl_open = '1'
AND esr.sales_ass = #{params.privEmpName}
AND x2.salesmen = esr.salesmen
AND CURRENT_TIMESTAMP BETWEEN esr.start_date AND esr.end_date
)
)
)
</if>
<!-- 客户编号查询条件 -->
<if test="custNo != null and params.custNo != ''">
and EXISTS (
select 1 from emis_settle_invoice_rel ir
inner join emis_waybill w on w.bill_code = ir.bill_no and w.del_flag = '0'
where ir.del_flag = '0' and a.apply_seq_no = ir.apply_seq_no
and w.cust_no = #{custNo}
)
</if>
<!-- 收款人查询条件 -->
<if test="payee != null and params.payee != ''">
and EXISTS (
select 1 from emis_settle_invoice_bill_rel ibr
inner join emis_settle_bill b on b.settle_bill_no = ibr.settle_bill_no and b.del_flag = '0'
where ibr.del_flag = '0' and a.apply_seq_no = ibr.apply_seq_no
and b.payee = #{payee}
)
</if>
<!-- 业务员查询条件 -->
<if test="salesmen != null and params.salesmen != ''">
and EXISTS (
select 1 from emis_settle_invoice_bill_rel ibr
inner join emis_settle_bill b on b.settle_bill_no = ibr.settle_bill_no and b.del_flag = '0'
where ibr.del_flag = '0' and a.apply_seq_no = ibr.apply_seq_no
and b.salesmen = #{salesmen}
)
</if>
<!-- 账单月份查询条件 -->
<if test="billMonth != null and params.billMonth != ''">
and EXISTS (
select 1 from emis_settle_invoice_bill_rel ibr
inner join emis_settle_bill b on b.settle_bill_no = ibr.settle_bill_no and b.del_flag = '0'
where ibr.del_flag = '0' and a.apply_seq_no = ibr.apply_seq_no
and b.bill_month = #{billMonth}
)
</if>
<!-- 付款状态查询条件 -->
<if test="paymentStatus != null and params.paymentStatus != ''">
and EXISTS (
select 1 from emis_settle_invoice_bill_rel ibr
inner join emis_settle_pay_bill_rel pbr on pbr.settle_bill_no = ibr.settle_bill_no
inner join emis_settle_pay_record pr on pr.pay_id = pbr.pay_id
where ibr.del_flag = '0' and a.apply_seq_no = ibr.apply_seq_no
and pr.pay_status = #{paymentStatus}
)
</if>
group by a.id
ORDER BY a.create_time DESC
</select>
<select id="checkHasSendToHx" parameterType="EmisSettleInvoiceChRecord" resultType="int">
select count(1) from emis_settle_invoice_ch_record
where del_flag='0'
and apply_seq_no = #{applySeqNo}
and open_ch_status != 0
limit 1
</select>
<select id="checkUnique" parameterType="EmisSettleInvoiceChRecord" resultType="int">
select count(1) from emis_settle_invoice_ch_record
where del_flag='0'
and id = #{id}
and req_no = #{reqNo}
and apply_seq_no = #{applySeqNo}
and bl_ecinv = #{blEcinv}
and invoice_type = #{invoiceType}
and real_invoice_type = #{realInvoiceType}
and company_name = #{companyName}
and company_tax_no = #{companyTaxNo}
and company_tel = #{companyTel}
and company_address = #{companyAddress}
and bank_name = #{bankName}
and bank_acc_no = #{bankAccNo}
and contact = #{contact}
and phone = #{phone}
and tax_rate = #{taxRate}
and open_money = #{openMoney}
and email = #{email}
and saler_company_name = #{salerCompanyName}
and saler_company_tax_no = #{salerCompanyTaxNo}
and saler_company_tel = #{salerCompanyTel}
and saler_company_address = #{salerCompanyAddress}
and saler_bank_name = #{salerBankName}
and saler_bank_acc_no = #{salerBankAccNo}
and saler_contact = #{salerContact}
and saler_phone = #{salerPhone}
and invoice_no = #{invoiceNo}
and file_path = #{filePath}
and qr_path = #{qrPath}
and op_man_code = #{opManCode}
and op_date = #{opDate}
and op_site_code = #{opSiteCode}
and open_ch_id = #{openChId}
and open_ch_status = #{openChStatus}
and open_ch_status_desc = #{openChStatusDesc}
and open_com_code = #{openComCode}
and ext_data = #{extData}
and remark = #{remark}
and del_flag = #{delFlag}
and create_by = #{createBy}
and create_time = #{createTime}
and update_by = #{updateBy}
and update_time = #{updateTime}
and create_site = #{createSite}
and update_site = #{updateSite}
limit 1
</select>
<select id="selectEmisSettleInvoiceChRecordById" parameterType="Long" resultMap="EmisSettleInvoiceChRecordResult">
select id, req_no, apply_seq_no, bl_ecinv, invoice_type, real_invoice_type, company_name, company_tax_no, company_tel, company_address, bank_name, bank_acc_no, contact, phone, tax_rate, open_money, email, saler_company_name, saler_company_tax_no, saler_company_tel, saler_company_address, saler_bank_name, saler_bank_acc_no, saler_contact, saler_phone, saler_checker, saler_payee, invoice_no, file_path, qr_path, op_man_code, op_date, op_site_code, open_ch_id, open_ch_status, open_ch_status_desc, open_com_code, ext_data, remark, del_flag, create_by, create_time, update_by, update_time, create_site, update_site
from emis_settle_invoice_ch_record a
where a.id = #{id}
</select>
<select id="selectEmisSettleInvoiceChRecordByReqNo" parameterType="String" resultMap="EmisSettleInvoiceChRecordResult">
select id, req_no, apply_seq_no, bl_ecinv, invoice_type, real_invoice_type, company_name, company_tax_no, company_tel, company_address, bank_name, bank_acc_no, contact, phone, tax_rate, open_money, email, saler_company_name, saler_company_tax_no, saler_company_tel, saler_company_address, saler_bank_name, saler_bank_acc_no, saler_contact, saler_phone, saler_checker, saler_payee, invoice_no, file_path, qr_path, op_man_code, op_date, op_site_code, open_ch_id, open_ch_status, open_ch_status_desc, open_com_code, ext_data, remark, del_flag, create_by, create_time, update_by, update_time, create_site, update_site
from emis_settle_invoice_ch_record a
where a.req_no = #{ReqNo}
</select>
<select id="selectWaitQueryStatusList" parameterType="String" resultMap="EmisSettleInvoiceChRecordResult">
select id, req_no, apply_seq_no, bl_ecinv, invoice_type, real_invoice_type, company_name, company_tax_no, company_tel, company_address, bank_name, bank_acc_no, contact, phone, tax_rate, open_money, email, saler_company_name, saler_company_tax_no, saler_company_tel, saler_company_address, saler_bank_name, saler_bank_acc_no, saler_contact, saler_phone, saler_checker, saler_payee, invoice_no, file_path, qr_path, op_man_code, op_date, op_site_code, open_ch_id, open_ch_status, open_ch_status_desc, open_com_code, ext_data, remark, del_flag, create_by, create_time, update_by, update_time, create_site, update_site
from emis_settle_invoice_ch_record a
where a.del_flag='0' and a.open_ch_status != '2' and a.invoice_type !='manual'
</select>
<insert id="insertEmisSettleInvoiceChRecord" parameterType="EmisSettleInvoiceChRecord" useGeneratedKeys="true" keyProperty="id">
insert into emis_settle_invoice_ch_record
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="reqNo != null and reqNo != ''">req_no,</if>
<if test="applySeqNo != null and applySeqNo != ''">apply_seq_no,</if>
<if test="blEcinv != null and blEcinv != ''">bl_ecinv,</if>
<if test="invoiceType != null and invoiceType != ''">invoice_type,</if>
<if test="realInvoiceType != null and realInvoiceType != ''">real_invoice_type,</if>
<if test="companyName != null and companyName != ''">company_name,</if>
<if test="companyTaxNo != null and companyTaxNo != ''">company_tax_no,</if>
<if test="companyTel != null and companyTel != ''">company_tel,</if>
<if test="companyAddress != null and companyAddress != ''">company_address,</if>
<if test="bankName != null and bankName != ''">bank_name,</if>
<if test="bankAccNo != null and bankAccNo != ''">bank_acc_no,</if>
<if test="contact != null and contact != ''">contact,</if>
<if test="phone != null and phone != ''">phone,</if>
<if test="taxRate != null and taxRate != ''">tax_rate,</if>
<if test="openMoney != null">open_money,</if>
<if test="email != null and email != ''">email,</if>
<if test="salerCompanyName != null and salerCompanyName != ''">saler_company_name,</if>
<if test="salerCompanyTaxNo != null and salerCompanyTaxNo != ''">saler_company_tax_no,</if>
<if test="salerCompanyTel != null and salerCompanyTel != ''">saler_company_tel,</if>
<if test="salerCompanyAddress != null and salerCompanyAddress != ''">saler_company_address,</if>
<if test="salerBankName != null and salerBankName != ''">saler_bank_name,</if>
<if test="salerBankAccNo != null and salerBankAccNo != ''">saler_bank_acc_no,</if>
<if test="salerContact != null and salerContact != ''">saler_contact,</if>
<if test="salerPhone != null and salerPhone != ''">saler_phone,</if>
<if test="salerChecker != null and salerChecker != ''">saler_checker,</if>
<if test="salerPayee != null and salerPayee != ''">saler_payee,</if>
<if test="invoiceNo != null and invoiceNo != ''">invoice_no,</if>
<if test="filePath != null and filePath != ''">file_path,</if>
<if test="qrPath != null and qrPath != ''">qr_path,</if>
<if test="opManCode != null and opManCode != ''">op_man_code,</if>
<if test="opDate != null">op_date,</if>
<if test="opSiteCode != null and opSiteCode != ''">op_site_code,</if>
<if test="openChId != null and openChId != ''">open_ch_id,</if>
<if test="openChStatus != null and openChStatus != ''">open_ch_status,</if>
<if test="openChStatusDesc != null and openChStatusDesc != ''">open_ch_status_desc,</if>
<if test="openComCode != null and openComCode != ''">open_com_code,</if>
<if test="extData != null and extData != ''">ext_data,</if>
<if test="remark != null and remark != ''">remark,</if>
<if test="delFlag != null and delFlag != ''">del_flag,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="updateBy != null and updateBy != ''">update_by,</if>
<if test="updateTime != null">update_time,</if>
<if test="createSite != null and createSite != ''">create_site,</if>
<if test="updateSite != null and updateSite != ''">update_site,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="reqNo != null and reqNo != ''">#{reqNo},</if>
<if test="applySeqNo != null and applySeqNo != ''">#{applySeqNo},</if>
<if test="blEcinv != null and blEcinv != ''">#{blEcinv},</if>
<if test="invoiceType != null and invoiceType != ''">#{invoiceType},</if>
<if test="realInvoiceType != null and realInvoiceType != ''">#{realInvoiceType},</if>
<if test="companyName != null and companyName != ''">#{companyName},</if>
<if test="companyTaxNo != null and companyTaxNo != ''">#{companyTaxNo},</if>
<if test="companyTel != null and companyTel != ''">#{companyTel},</if>
<if test="companyAddress != null and companyAddress != ''">#{companyAddress},</if>
<if test="bankName != null and bankName != ''">#{bankName},</if>
<if test="bankAccNo != null and bankAccNo != ''">#{bankAccNo},</if>
<if test="contact != null and contact != ''">#{contact},</if>
<if test="phone != null and phone != ''">#{phone},</if>
<if test="taxRate != null and taxRate != ''">#{taxRate},</if>
<if test="openMoney != null">#{openMoney},</if>
<if test="email != null and email != ''">#{email},</if>
<if test="salerCompanyName != null and salerCompanyName != ''">#{salerCompanyName},</if>
<if test="salerCompanyTaxNo != null and salerCompanyTaxNo != ''">#{salerCompanyTaxNo},</if>
<if test="salerCompanyTel != null and salerCompanyTel != ''">#{salerCompanyTel},</if>
<if test="salerCompanyAddress != null and salerCompanyAddress != ''">#{salerCompanyAddress},</if>
<if test="salerBankName != null and salerBankName != ''">#{salerBankName},</if>
<if test="salerBankAccNo != null and salerBankAccNo != ''">#{salerBankAccNo},</if>
<if test="salerContact != null and salerContact != ''">#{salerContact},</if>
<if test="salerPhone != null and salerPhone != ''">#{salerPhone},</if>
<if test="salerChecker != null and salerChecker != ''">#{salerChecker},</if>
<if test="salerPayee != null and salerPayee != ''">#{salerPayee},</if>
<if test="invoiceNo != null and invoiceNo != ''">#{invoiceNo},</if>
<if test="filePath != null and filePath != ''">#{filePath},</if>
<if test="qrPath != null and qrPath != ''">#{qrPath},</if>
<if test="opManCode != null and opManCode != ''">#{opManCode},</if>
<if test="opDate != null">#{opDate},</if>
<if test="opSiteCode != null and opSiteCode != ''">#{opSiteCode},</if>
<if test="openChId != null and openChId != ''">#{openChId},</if>
<if test="openChStatus != null and openChStatus != ''">#{openChStatus},</if>
<if test="openChStatusDesc != null and openChStatusDesc != ''">#{openChStatusDesc},</if>
<if test="openComCode != null and openComCode != ''">#{openComCode},</if>
<if test="extData != null and extData != ''">#{extData},</if>
<if test="remark != null and remark != ''">#{remark},</if>
<if test="delFlag != null and delFlag != ''">#{delFlag},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateBy != null and updateBy != ''">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="createSite != null and createSite != ''">#{createSite},</if>
<if test="updateSite != null and updateSite != ''">#{updateSite},</if>
</trim>
</insert>
<update id="updateEmisSettleInvoiceChRecord" parameterType="EmisSettleInvoiceChRecord">
update emis_settle_invoice_ch_record
<trim prefix="SET" suffixOverrides=",">
<if test="reqNo != null and reqNo != ''">req_no = #{reqNo},</if>
<if test="applySeqNo != null and applySeqNo != ''">apply_seq_no = #{applySeqNo},</if>
<if test="blEcinv != null and blEcinv != ''">bl_ecinv = #{blEcinv},</if>
<if test="invoiceType != null and invoiceType != ''">invoice_type = #{invoiceType},</if>
<if test="realInvoiceType != null and realInvoiceType != ''">real_invoice_type = #{realInvoiceType},</if>
<if test="companyName != null and companyName != ''">company_name = #{companyName},</if>
<if test="companyTaxNo != null and companyTaxNo != ''">company_tax_no = #{companyTaxNo},</if>
<if test="companyTel != null and companyTel != ''">company_tel = #{companyTel},</if>
<if test="companyAddress != null and companyAddress != ''">company_address = #{companyAddress},</if>
<if test="bankName != null and bankName != ''">bank_name = #{bankName},</if>
<if test="bankAccNo != null and bankAccNo != ''">bank_acc_no = #{bankAccNo},</if>
<if test="contact != null and contact != ''">contact = #{contact},</if>
<if test="phone != null and phone != ''">phone = #{phone},</if>
<if test="taxRate != null and taxRate != ''">tax_rate = #{taxRate},</if>
<if test="openMoney != null">open_money = #{openMoney},</if>
<if test="email != null and email != ''">email = #{email},</if>
<if test="salerCompanyName != null and salerCompanyName != ''">saler_company_name = #{salerCompanyName},</if>
<if test="salerCompanyTaxNo != null and salerCompanyTaxNo != ''">saler_company_tax_no = #{salerCompanyTaxNo},</if>
<if test="salerCompanyTel != null and salerCompanyTel != ''">saler_company_tel = #{salerCompanyTel},</if>
<if test="salerCompanyAddress != null and salerCompanyAddress != ''">saler_company_address = #{salerCompanyAddress},</if>
<if test="salerBankName != null and salerBankName != ''">saler_bank_name = #{salerBankName},</if>
<if test="salerBankAccNo != null and salerBankAccNo != ''">saler_bank_acc_no = #{salerBankAccNo},</if>
<if test="salerContact != null and salerContact != ''">saler_contact = #{salerContact},</if>
<if test="salerPhone != null and salerPhone != ''">saler_phone = #{salerPhone},</if>
<if test="salerChecker != null and salerChecker != ''">saler_checker = #{salerChecker},</if>
<if test="salerPayee != null and salerPayee != ''">saler_payee = #{salerPayee},</if>
<if test="invoiceNo != null and invoiceNo != ''">invoice_no = #{invoiceNo},</if>
<if test="filePath != null and filePath != ''">file_path = #{filePath},</if>
<if test="qrPath != null and qrPath != ''">qr_path = #{qrPath},</if>
<if test="opManCode != null and opManCode != ''">op_man_code = #{opManCode},</if>
<if test="opDate != null">op_date = #{opDate},</if>
<if test="opSiteCode != null and opSiteCode != ''">op_site_code = #{opSiteCode},</if>
<if test="openChId != null and openChId != ''">open_ch_id = #{openChId},</if>
<if test="openChStatus != null and openChStatus != ''">open_ch_status = #{openChStatus},</if>
<if test="openChStatusDesc != null and openChStatusDesc != ''">open_ch_status_desc = #{openChStatusDesc},</if>
<if test="openComCode != null and openComCode != ''">open_com_code = #{openComCode},</if>
<if test="extData != null and extData != ''">ext_data = #{extData},</if>
<if test="remark != null and remark != ''">remark = #{remark},</if>
<if test="delFlag != null and delFlag != ''">del_flag = #{delFlag},</if>
<if test="createBy != null and createBy != ''">create_by = #{createBy},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
<if test="createSite != null and createSite != ''">create_site = #{createSite},</if>
<if test="updateSite != null and updateSite != ''">update_site = #{updateSite},</if>
</trim>
where id = #{id}
</update>
<delete id="deleteEmisSettleInvoiceChRecordById" parameterType="Long">
update emis_settle_invoice_ch_record set del_flag='1' where id = #{id}
</delete>
<delete id="deleteEmisSettleInvoiceChRecordByIds" parameterType="String">
update emis_settle_invoice_ch_record set del_flag='1' where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
<select id="selectExtraFieldsByApplySeqNos" resultMap="EmisSettleInvoiceChRecordResult">
SELECT
a.id,
a.apply_seq_no,
(
SELECT GROUP_CONCAT(DISTINCT CONCAT(SUBSTRING(DATE_FORMAT(w.send_date, '%Y'), 3, 2), DATE_FORMAT(w.send_date, '%m')))
FROM emis_settle_invoice_ch_record bd
LEFT JOIN emis_settle_invoice_rel ir ON ir.apply_seq_no = bd.apply_seq_no AND ir.del_flag = '0'
LEFT JOIN emis_waybill w ON w.bill_code = ir.bill_no AND w.del_flag = '0'
WHERE bd.apply_seq_no = a.apply_seq_no AND bd.del_flag = '0'
) as send_month,
(
SELECT b.settle_type
FROM emis_settle_invoice_ch_record bd
LEFT JOIN emis_settle_invoice_bill_rel ibr ON ibr.apply_seq_no = bd.apply_seq_no AND ibr.del_flag = '0'
LEFT JOIN emis_settle_bill b ON b.settle_bill_no = ibr.settle_bill_no AND b.del_flag = '0'
WHERE bd.apply_seq_no = a.apply_seq_no AND bd.del_flag = '0'
LIMIT 1
) as settle_type,
(
SELECT
CASE
WHEN b.settle_type = '2' THEN
GROUP_CONCAT(DISTINCT
CONCAT(
CONCAT(SUBSTRING(DATE_FORMAT(w.send_date, '%Y'), 3, 2), DATE_FORMAT(w.send_date, '%m ')),
b.cust_name
) SEPARATOR '-'
)
ELSE
GROUP_CONCAT(DISTINCT
CONCAT(
DATE_FORMAT(w.send_date, '%m%d '),
w.send_company
) SEPARATOR '-'
)
END
FROM emis_settle_invoice_ch_record bd
LEFT JOIN emis_settle_invoice_rel ir ON ir.apply_seq_no = bd.apply_seq_no AND ir.del_flag = '0'
LEFT JOIN emis_waybill w ON w.bill_code = ir.bill_no AND w.del_flag = '0'
LEFT JOIN emis_settle_invoice_bill_rel ibr ON ibr.apply_seq_no = bd.apply_seq_no AND ibr.del_flag = '0'
LEFT JOIN emis_settle_bill b ON b.settle_bill_no = ibr.settle_bill_no AND b.del_flag = '0'
WHERE bd.apply_seq_no = a.apply_seq_no AND bd.del_flag = '0'
) as open_bill_remark,
(
SELECT GROUP_CONCAT(DISTINCT
CONCAT(
DATE_FORMAT(pr.trade_date, '%m/%d'),
' 已付(',
CASE pr.pay_type
WHEN '1' THEN '企业微信收款'
WHEN '2' THEN '工行汇款3890'
WHEN '3' THEN '微信支付'
WHEN '4' THEN '支付宝'
WHEN '5' THEN '其他'
WHEN '6' THEN '招行付款'
ELSE pr.pay_type
END,
')'
)
)
FROM emis_settle_invoice_ch_record bd
LEFT JOIN emis_settle_invoice_bill_rel ibr ON ibr.apply_seq_no = bd.apply_seq_no AND ibr.del_flag = '0'
LEFT JOIN emis_settle_pay_bill_rel pbr ON ibr.settle_bill_no = pbr.settle_bill_no
LEFT JOIN emis_settle_pay_record pr ON pr.pay_id = pbr.pay_id
WHERE bd.apply_seq_no = a.apply_seq_no AND bd.del_flag = '0'
) as pay_days
FROM emis_settle_invoice_ch_record a
WHERE a.del_flag = '0'
AND a.apply_seq_no IN
<foreach collection="applySeqNoList" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</select>
</mapper>