emis-service/emis-biz/src/main/resources/mapper/EmisSettleBillMapper.xml
2024-12-27 10:57:25 +08:00

715 lines
50 KiB
XML

<?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.EmisSettleBillMapper">
<resultMap type="EmisSettleBill" id="EmisSettleBillResult" extends="com.xdadan.erp.emis.mapper.EmisBaseMapper.EmisBaseResult">
<result property="id" column="id" />
<result property="settleBillNo" column="settle_bill_no" />
<result property="settleBillName" column="settle_bill_name" />
<result property="settleType" column="settle_type" />
<result property="settleStartDate" column="settle_start_date" />
<result property="settleEndDate" column="settle_end_date" />
<result property="billMonth" column="bill_month" />
<result property="recMoney" column="rec_money" />
<result property="recedMoney" column="reced_money" />
<result property="invoicedMoney" column="invoiced_money" />
<result property="custNo" column="cust_no" />
<result property="custName" column="cust_name" />
<result property="customerCode" column="customer_code" />
<result property="customerName" column="customer_name" />
<result property="siteCode" column="site_code" />
<result property="siteName" column="site_name" />
<result property="satisfyMoney" column="satisfy_money" />
<result property="allowanceMoney" column="allowance_money" />
<result property="deductionMoney" column="deduction_money" />
<result property="otherMoney" column="other_money" />
<result property="satisfyReason" column="satisfy_reason" />
<result property="allowanceReason" column="allowance_reason" />
<result property="deductionReason" column="deduction_reason" />
<result property="otherReason" column="other_reason" />
<result property="openBillStatus" column="open_bill_status" />
<result property="paymentStatus" column="payment_status" />
<result property="chargeStatus" column="charge_status" />
<result property="sendPieceSum" column="send_piece_sum" />
<result property="pieceNumber" column="piece_number" />
<result property="feeWeight" column="fee_weight" />
<result property="uncollectedAmount" column="uncollected_amount" />
<result property="sendMoneySum" column="send_money_sum" />
<result property="refundAmount" column="refund_amount" />
<result property="refundMoney" column="refund_money" />
<result property="payee" column="payee" />
<result property="salesmen" column="salesmen" />
<result property="creditPeriod" column="credit_period" />
<result property="creditPeriodType" column="credit_period_type" />
<result property="settleDay" column="settle_day" />
<result property="paymentDueDate" column="payment_due_date" />
<result property="blSendOms" column="bl_send_oms" />
<result property="blConfirmCenter" column="bl_confirm_center" />
<result property="confirmCenterDate" column="confirm_center_date" />
<result property="confirmCenterNote" column="confirm_center_note" />
<result property="confirmCenterManCode" column="confirm_center_man_code" />
<result property="confirmCenterCode" column="confirm_center_code" />
<result property="blConfirmSite" column="bl_confirm_site" />
<result property="confirmSiteDate" column="confirm_site_date" />
<result property="confirmSiteManCode" column="confirm_site_man_code" />
<result property="confirmSiteNote" column="confirm_site_note" />
<result property="confirmSiteCode" column="confirm_site_code" />
<association property="confirmCenterManName" column="confirm_center_man_code" select="com.xdadan.erp.emis.mapper.EmisBaseMapper.selectEmpNameByCode"/>
<association property="confirmCenterName" column="confirm_center_code" select="com.xdadan.erp.emis.mapper.EmisBaseMapper.selectSiteNameByCode"/>
<association property="confirmSiteManName" column="confirm_site_man_code" select="com.xdadan.erp.emis.mapper.EmisBaseMapper.selectEmpNameByCode"/>
<association property="confirmSiteName" column="confirm_site_code" select="com.xdadan.erp.emis.mapper.EmisBaseMapper.selectSiteNameByCode"/>
</resultMap>
<resultMap type="BillPayStatInfo" id="BillPayStatInfoResult">
<result property="salesmen" column="salesmen" />
<result property="billMonth" column="billMonth" />
<result property="recPayMoney" column="recPayMoney" />
<result property="totalRecdPayMoney" column="totalRecdPayMoney" />
<result property="totalNoRecdPayMoney" column="totalNoRecdPayMoney" />
<result property="totalSatisfyMoney" column="totalSatisfyMoney" />
<result property="totalAllowanceMoney" column="totalAllowanceMoney" />
<result property="totalDeductionMoney" column="totalDeductionMoney" />
<result property="totalOtherMoney" column="totalOtherMoney" />
<result property="totalBillCount" column="totalBillCount" />
<result property="hasPayBillCount" column="hasPayBillCount" />
<result property="somePayBillCount" column="somePayBillCount" />
<result property="noPayBillCount" column="noPayBillCount" />
<result property="recdPayMoney" column="recdPayMoney" />
<result property="noRecdPayMoney" column="noRecdPayMoney" />
<result property="expiredRecdPayMoney" column="expiredRecdPayMoney" />
<result property="expiredNoRecdPayMoney" column="expiredNoRecdPayMoney" />
<result property="billPayRate" column="billPayRate" />
<result property="expireBillPayRate" column="expireBillPayRate" />
<result property="expireBillNoPayRate" column="expireBillNoPayRate" />
</resultMap>
<resultMap type="OpenBillStatInfo" id="OpenBillStatInfoResult">
<result property="salesmen" column="salesmen" />
<result property="billMonth" column="billMonth" />
<result property="totalBillCount" column="totalBillCount" />
<result property="hasOpenBillCount" column="hasOpenBillCount" />
<result property="someOpenBillCount" column="someOpenBillCount" />
<result property="noOpenBillCount" column="noOpenBillCount" />
<result property="noNeedOpenBillCount" column="noNeedOpenBillCount" />
<result property="normalOpenBillCount" column="normalOpenBillCount" />
<result property="expiredOpenBillCount" column="expiredOpenBillCount" />
<result property="expiredNoOpenBillCount" column="expiredNoOpenBillCount" />
<result property="normalOpenBillRate" column="normalOpenBillRate" />
<result property="expireOpenBillRate" column="expireOpenBillRate" />
</resultMap>
<select id="selectBillPayStatInfoList" parameterType="EmisSettleBill" resultMap="BillPayStatInfoResult">
select tba.salesmen,
tba.billMonth,
tba.recPayMoney,
tba.totalBillCount,
tba.totalRecdPayMoney,
tba.totalNoRecdPayMoney,
tba.totalSatisfyMoney,
tba.totalAllowanceMoney,
tba.totalDeductionMoney,
tba.totalOtherMoney,
tbb.hasPayBillCount,
tbb.somePayBillCount,
tbb.noPayBillCount,
ifnull(tbc.recdPayMoney,0) as recdPayMoney,
(tba.recPayMoney-ifnull(tbc.recdPayMoney,0)) as noRecdPayMoney,
ifnull(tbd.expiredRecdPayMoney,0) as expiredRecdPayMoney,
ifnull(tbe.expiredNoRecdPayMoney,0) as expiredNoRecdPayMoney
from (
select salesmen,bill_month as billMonth,
ROUND(sum(rec_money),2) as recPayMoney,
count(1) as totalBillCount,
ROUND(sum(reced_money),2) as totalRecdPayMoney,
ROUND(sum(rec_money-reced_money-satisfy_money-allowance_money-deduction_money-other_money),2) as totalNoRecdPayMoney,
ROUND(sum(satisfy_money),2) as totalSatisfyMoney,
ROUND(sum(allowance_money),2) as totalAllowanceMoney,
ROUND(sum(deduction_money-other_money),2) as totalDeductionMoney,
ROUND(sum(other_money),2) as totalOtherMoney
from emis_settle_bill a
<where>
a.del_flag='0'
<if test="salesmen != null and salesmen!='' "> and a.salesmen = #{salesmen}</if>
<if test="settleType != null and settleType != ''"> and a.settle_type= #{settleType}</if>
<if test="billMonth != null and billMonth!='' "> and a.bill_month = #{billMonth}</if>
<if test="openBillStatus != null and openBillStatus != ''"> and a.open_bill_status = #{openBillStatus}</if>
<if test="paymentStatus != null and paymentStatus != ''"> and a.payment_status = #{paymentStatus}</if>
<if test="params.privSiteCode != null and params.privSiteCode != '88888'">
and (
a.salesmen=#{params.privEmpName}
or a.payee=#{params.privEmpName}
or a.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>
group by salesmen,bill_month
) tba
left join (
select salesmen,bill_month as billMonth,
sum(IF(payment_status='1',1,0)) as hasPayBillCount,
sum(IF(payment_status='2',1,0)) as somePayBillCount,
sum(IF(payment_status='0',1,0)) as noPayBillCount
from emis_settle_bill a
<where>
a.del_flag='0'
<if test="salesmen != null and salesmen!='' "> and a.salesmen = #{salesmen}</if>
<if test="settleType != null and settleType != ''"> and a.settle_type= #{settleType}</if>
<if test="billMonth != null and billMonth!='' "> and a.bill_month = #{billMonth}</if>
<if test="openBillStatus != null and openBillStatus != ''"> and a.open_bill_status = #{openBillStatus}</if>
<if test="paymentStatus != null and paymentStatus != ''"> and a.payment_status = #{paymentStatus}</if>
<if test="params.privSiteCode != null and params.privSiteCode != '88888'">
and (
a.salesmen=#{params.privEmpName}
or a.payee=#{params.privEmpName}
or a.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>
group by salesmen,bill_month
) tbb on tba.salesmen=tbb.salesmen and tba.billMonth=tbb.billMonth
left join (
select a.salesmen,a.bill_month as billMonth,
sum(b.pay_money) as recdPayMoney
from emis_settle_bill a,emis_settle_pay_record b
<where>
a.del_flag='0' and b.del_flag='0' and a.settle_bill_no=b.settle_bill_no and b.create_time <![CDATA[ <= ]]> a.payment_due_date
<if test="salesmen != null and salesmen!='' "> and a.salesmen = #{salesmen}</if>
<if test="billMonth != null and billMonth!='' "> and a.bill_month = #{billMonth}</if>
<if test="openBillStatus != null and openBillStatus != ''"> and a.open_bill_status = #{openBillStatus}</if>
<if test="paymentStatus != null and paymentStatus != ''"> and a.payment_status = #{paymentStatus}</if>
<if test="params.privSiteCode != null and params.privSiteCode != '88888'">
and (
a.salesmen=#{params.privEmpName}
or a.payee=#{params.privEmpName}
or a.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>
group by salesmen,bill_month
) tbc on tba.salesmen=tbc.salesmen and tba.billMonth=tbc.billMonth
left join (
select a.salesmen,a.bill_month as billMonth,
sum(b.pay_money) as expiredRecdPayMoney
from emis_settle_bill a,emis_settle_pay_record b
<where>
a.del_flag='0' and b.del_flag='0' and a.settle_bill_no=b.settle_bill_no and b.create_time <![CDATA[ > ]]> a.payment_due_date
<if test="salesmen != null and salesmen!='' "> and a.salesmen = #{salesmen}</if>
<if test="settleType != null and settleType != ''"> and a.settle_type= #{settleType}</if>
<if test="billMonth != null and billMonth!='' "> and a.bill_month = #{billMonth}</if>
<if test="openBillStatus != null and openBillStatus != ''"> and a.open_bill_status = #{openBillStatus}</if>
<if test="paymentStatus != null and paymentStatus != ''"> and a.payment_status = #{paymentStatus}</if>
<if test="params.privSiteCode != null and params.privSiteCode != '88888'">
and (
a.salesmen=#{params.privEmpName}
or a.payee=#{params.privEmpName}
or a.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>
group by salesmen,bill_month
) tbd on tba.salesmen=tbd.salesmen and tba.billMonth=tbd.billMonth
left join (
select a.salesmen,a.bill_month as billMonth,
ROUND(sum(rec_money-reced_money),2) as expiredNoRecdPayMoney
from emis_settle_bill a
<where>
a.del_flag='0' and now() <![CDATA[ > ]]> a.payment_due_date
<if test="salesmen != null and salesmen!='' "> and a.salesmen = #{salesmen}</if>
<if test="settleType != null and settleType != ''"> and a.settle_type= #{settleType}</if>
<if test="billMonth != null and billMonth!='' "> and a.bill_month = #{billMonth}</if>
<if test="openBillStatus != null and openBillStatus != ''"> and a.open_bill_status = #{openBillStatus}</if>
<if test="paymentStatus != null and paymentStatus != ''"> and a.payment_status = #{paymentStatus}</if>
<if test="params.privSiteCode != null and params.privSiteCode != '88888'">
and (
a.salesmen=#{params.privEmpName}
or a.payee=#{params.privEmpName}
or a.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>
group by salesmen,bill_month
) tbe on tba.salesmen=tbe.salesmen and tba.billMonth=tbe.billMonth
where 1=1
<!-- 超期回款 -->
<if test="params.isHasExpirePay != null and params.isHasExpirePay=1 ">
and tba.expiredNoRecdPayMoney <![CDATA[ >= ]]> 0
</if>
</select>
<select id="selectOpenBillStatInfoList" parameterType="EmisSettleBill" resultMap="OpenBillStatInfoResult">
select tba.salesmen,
tba.billMonth,
tba.totalBillCount,
tbb.hasOpenBillCount,
tbb.someOpenBillCount,
tbb.noOpenBillCount,
tbb.noNeedOpenBillCount,
ifnull(tbc.normalOpenBillCount,0) as normalOpenBillCount,
ifnull(tbd.expiredOpenBillCount,0) as expiredOpenBillCount,
tbb.noOpenBillCount as expiredNoOpenBillCount
from (
select salesmen,bill_month as billMonth,
count(1) as totalBillCount
from emis_settle_bill a
<where>
a.del_flag='0'
<if test="salesmen != null and salesmen!='' "> and a.salesmen = #{salesmen}</if>
<if test="settleType != null and settleType != ''"> and a.settle_type= #{settleType}</if>
<if test="billMonth != null and billMonth!='' "> and a.bill_month = #{billMonth}</if>
<if test="openBillStatus != null and openBillStatus != ''"> and a.open_bill_status = #{openBillStatus}</if>
<if test="paymentStatus != null and paymentStatus != ''"> and a.payment_status = #{paymentStatus}</if>
<if test="params.privSiteCode != null and params.privSiteCode != '88888'">
and (
a.salesmen=#{params.privEmpName}
or a.payee=#{params.privEmpName}
or a.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>
group by salesmen,bill_month
) tba
left join (
select salesmen,bill_month as billMonth,
sum(IF(open_bill_status='1' or open_bill_status='4',1,0)) as hasOpenBillCount,
sum(IF(open_bill_status='2',1,0)) as someOpenBillCount,
sum(IF(open_bill_status='3',1,0)) as noNeedOpenBillCount,
sum(IF(open_bill_status='0',1,0)) as noOpenBillCount
from emis_settle_bill a
<where>
a.del_flag='0'
<if test="salesmen != null and salesmen!='' "> and a.salesmen = #{salesmen}</if>
<if test="settleType != null and settleType != ''"> and a.settle_type= #{settleType}</if>
<if test="billMonth != null and billMonth!='' "> and a.bill_month = #{billMonth}</if>
<if test="openBillStatus != null and openBillStatus != ''"> and a.open_bill_status = #{openBillStatus}</if>
<if test="paymentStatus != null and paymentStatus != ''"> and a.payment_status = #{paymentStatus}</if>
<if test="params.privSiteCode != null and params.privSiteCode != '88888'">
and (
a.salesmen=#{params.privEmpName}
or a.payee=#{params.privEmpName}
or a.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>
group by salesmen,bill_month
) tbb on tba.salesmen=tbb.salesmen and tba.billMonth=tbb.billMonth
left join (
select a.salesmen,a.bill_month as billMonth,
count(distinct a.settle_bill_no) as normalOpenBillCount
from emis_settle_bill a,emis_settle_invoice_record b
<where>
a.del_flag='0' and b.del_flag='0' and FIND_IN_SET(a.settle_bill_no,b.settle_bill_no) and b.create_time <![CDATA[ <= ]]> a.payment_due_date
<if test="salesmen != null and salesmen!='' "> and a.salesmen = #{salesmen}</if>
<if test="settleType != null and settleType != ''"> and a.settle_type= #{settleType}</if>
<if test="billMonth != null and billMonth!='' "> and a.bill_month = #{billMonth}</if>
<if test="openBillStatus != null and openBillStatus != ''"> and a.open_bill_status = #{openBillStatus}</if>
<if test="paymentStatus != null and paymentStatus != ''"> and a.payment_status = #{paymentStatus}</if>
<if test="params.privSiteCode != null and params.privSiteCode != '88888'">
and (
a.salesmen=#{params.privEmpName}
or a.payee=#{params.privEmpName}
or a.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>
group by salesmen,bill_month
) tbc on tba.salesmen=tbc.salesmen and tba.billMonth=tbc.billMonth
left join (
select a.salesmen,a.bill_month as billMonth,
count(distinct a.settle_bill_no) as expiredOpenBillCount
from emis_settle_bill a,emis_settle_invoice_record b
<where>
a.del_flag='0' and b.del_flag='0' and FIND_IN_SET(a.settle_bill_no,b.settle_bill_no) and b.create_time <![CDATA[ > ]]> a.payment_due_date
<if test="salesmen != null and salesmen!='' "> and a.salesmen = #{salesmen}</if>
<if test="settleType != null and settleType != ''"> and a.settle_type= #{settleType}</if>
<if test="billMonth != null and billMonth!='' "> and a.bill_month = #{billMonth}</if>
<if test="openBillStatus != null and openBillStatus != ''"> and a.open_bill_status = #{openBillStatus}</if>
<if test="paymentStatus != null and paymentStatus != ''"> and a.payment_status = #{paymentStatus}</if>
<if test="params.privSiteCode != null and params.privSiteCode != '88888'">
and (
a.salesmen=#{params.privEmpName}
or a.payee=#{params.privEmpName}
or a.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>
group by salesmen,bill_month
) tbd on tba.salesmen=tbd.salesmen and tba.billMonth=tbd.billMonth
</select>
<sql id="selectEmisSettleBillVo">
select id, settle_bill_no, settle_bill_name, settle_type, settle_start_date, settle_end_date, bill_month, rec_money, reced_money, invoiced_money, cust_no, cust_name, customer_code, customer_name, site_code, site_name, satisfy_money, allowance_money, deduction_money, other_money, satisfy_reason, allowance_reason, deduction_reason, other_reason, open_bill_status, payment_status, charge_status, send_piece_sum, piece_number, fee_weight, uncollected_amount, send_money_sum, refund_amount, refund_money, payee, salesmen, credit_period, credit_period_type, settle_day, payment_due_date, bl_send_oms, bl_confirm_center, confirm_center_date, confirm_center_note, confirm_center_man_code, confirm_center_code, bl_confirm_site, confirm_site_date, confirm_site_man_code, confirm_site_note, confirm_site_code, remark, del_flag, create_by, create_time, update_by, update_time, create_site, update_site from emis_settle_bill a
</sql>
<select id="selectEmisSettleBillList" parameterType="EmisSettleBill" resultMap="EmisSettleBillResult">
<include refid="selectEmisSettleBillVo"/>
<where>
del_flag='0'
<if test="id != null "> and id = #{id}</if>
<if test="settleBillNo != null and settleBillNo != ''"> and FIND_IN_SET(a.`settle_bill_no`,#{settleBillNo})</if>
<if test="settleBillName != null and settleBillName != ''"> and settle_bill_name like concat('%', #{settleBillName}, '%')</if>
<if test="settleType != null and settleType != ''"> and settle_type= #{settleType}</if>
<if test="settleStartDate != null "> and settle_start_date = #{settleStartDate}</if>
<if test="settleEndDate != null "> and settle_end_date = #{settleEndDate}</if>
<if test="billMonth != null and billMonth != ''"> and bill_month = #{billMonth}</if>
<if test="recMoney != null "> and rec_money = #{recMoney}</if>
<if test="recedMoney != null "> and reced_money = #{recedMoney}</if>
<if test="custNo != null and custNo != ''"> and cust_no = #{custNo}</if>
<if test="custName != null and custName != ''"> and cust_name like concat('%', #{custName}, '%')</if>
<if test="customerCode != null and customerCode != ''"> and customer_code = #{customerCode}</if>
<if test="customerName != null and customerName != ''"> and customer_name like concat('%', #{customerName}, '%')</if>
<if test="siteCode != null and siteCode != ''"> and site_code = #{siteCode}</if>
<if test="siteName != null and siteName != ''"> and site_name like concat('%', #{siteName}, '%')</if>
<if test="satisfyMoney != null "> and satisfy_money = #{satisfyMoney}</if>
<if test="allowanceMoney != null "> and allowance_money = #{allowanceMoney}</if>
<if test="deductionMoney != null "> and deduction_money = #{deductionMoney}</if>
<if test="otherMoney != null "> and other_money = #{otherMoney}</if>
<if test="satisfyReason != null and satisfyReason != ''"> and satisfy_reason = #{satisfyReason}</if>
<if test="allowanceReason != null and allowanceReason != ''"> and allowance_reason = #{allowanceReason}</if>
<if test="deductionReason != null and deductionReason != ''"> and deduction_reason = #{deductionReason}</if>
<if test="otherReason != null and otherReason != ''"> and other_reason = #{otherReason}</if>
<if test="openBillStatus != null and openBillStatus != ''"> and open_bill_status = #{openBillStatus}</if>
<if test="paymentStatus != null and paymentStatus != ''"> and payment_status = #{paymentStatus}</if>
<if test="chargeStatus != null and chargeStatus != ''"> and charge_status = #{chargeStatus}</if>
<if test="sendPieceSum != null "> and send_piece_sum = #{sendPieceSum}</if>
<if test="pieceNumber != null "> and piece_number = #{pieceNumber}</if>
<if test="feeWeight != null "> and fee_weight = #{feeWeight}</if>
<if test="uncollectedAmount != null "> and uncollected_amount = #{uncollectedAmount}</if>
<if test="sendMoneySum != null "> and send_money_sum = #{sendMoneySum}</if>
<if test="refundAmount != null "> and refund_amount = #{refundAmount}</if>
<if test="refundMoney != null "> and refund_money = #{refundMoney}</if>
<if test="payee != null and payee != ''"> and payee = #{payee}</if>
<if test="salesmen != null and salesmen != ''"> and salesmen = #{salesmen}</if>
<if test="blSendOms != null and blSendOms != ''"> and bl_send_oms = #{blSendOms}</if>
<if test="blConfirmCenter != null and blConfirmCenter != ''"> and bl_confirm_center = #{blConfirmCenter}</if>
<if test="confirmCenterDate != null "> and confirm_center_date = #{confirmCenterDate}</if>
<if test="confirmCenterNote != null and confirmCenterNote != ''"> and confirm_center_note = #{confirmCenterNote}</if>
<if test="confirmCenterManCode != null and confirmCenterManCode != ''"> and confirm_center_man_code = #{confirmCenterManCode}</if>
<if test="confirmCenterCode != null and confirmCenterCode != ''"> and confirm_center_code = #{confirmCenterCode}</if>
<if test="blConfirmSite != null and blConfirmSite != ''"> and bl_confirm_site = #{blConfirmSite}</if>
<if test="confirmSiteDate != null "> and confirm_site_date = #{confirmSiteDate}</if>
<if test="confirmSiteManCode != null and confirmSiteManCode != ''"> and confirm_site_man_code = #{confirmSiteManCode}</if>
<if test="confirmSiteNote != null and confirmSiteNote != ''"> and confirm_site_note like concat('%', #{confirmSiteNote}, '%')</if>
<if test="confirmSiteCode != null and confirmSiteCode != ''"> and confirm_site_code = #{confirmSiteCode}</if>
<if test="remark != null and remark != ''"> and remark like concat('%', #{remark}, '%')</if>
<if test="delFlag != null and delFlag != ''"> and del_flag = #{delFlag}</if>
<if test="createBy != null and createBy != ''"> and create_by = #{createBy}</if>
<if test="createTime != null "> and create_time = #{createTime}</if>
<if test="updateBy != null and updateBy != ''"> and update_by = #{updateBy}</if>
<if test="updateTime != null "> and update_time = #{updateTime}</if>
<if test="createSite != null and createSite != ''"> and create_site = #{createSite}</if>
<if test="updateSite != null and updateSite != ''"> and update_site = #{updateSite}</if>
<if test="creditPeriod != null "> and credit_period = #{creditPeriod}</if>
<if test="creditPeriodType != null and creditPeriodType != ''"> and credit_period_type=#{creditPeriodType}</if>
<if test="settleDay != null "> and settle_day = #{settleDay}</if>
<if test="paymentDueDate != null "> and payment_due_date = #{paymentDueDate}</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="params.canOpenBill != null and params.canOpenBill == 1">
and open_bill_status != '1'
</if>
<if test="params.noPayBill != null and params.noPayBill == 1">
and payment_status != '1'
</if>
<if test="params.billCode != null and params.billCode != ''">
and exists (
select 1 from emis_settle_sub_bill b
where a.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.privSiteCode != null and params.privSiteCode != '88888'">
and (
a.salesmen=#{params.privEmpName}
or a.payee=#{params.privEmpName}
or a.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="checkUnique" parameterType="EmisSettleBill" resultType="int">
select count(1) from emis_settle_bill a
where del_flag='0' and settle_bill_name = #{settleBillName} limit 1
</select>
<select id="selectEmisSettleBillById" parameterType="Long" resultMap="EmisSettleBillResult">
select id, settle_bill_no, settle_bill_name, settle_type, settle_start_date, settle_end_date, bill_month, rec_money, reced_money, invoiced_money, cust_no, cust_name, customer_code, customer_name, site_code, site_name, satisfy_money, allowance_money, deduction_money, other_money, satisfy_reason, allowance_reason, deduction_reason, other_reason, open_bill_status, payment_status, charge_status, send_piece_sum, piece_number, fee_weight, uncollected_amount, send_money_sum, refund_amount, refund_money, payee, salesmen, credit_period, credit_period_type, settle_day, payment_due_date, bl_send_oms, bl_confirm_center, confirm_center_date, confirm_center_note, confirm_center_man_code, confirm_center_code, bl_confirm_site, confirm_site_date, confirm_site_man_code, confirm_site_note, confirm_site_code, remark, del_flag, create_by, create_time, update_by, update_time, create_site, update_site
from emis_settle_bill a
where a.id = #{id}
</select>
<select id="selectSettleBillBySettleBillNo" parameterType="String" resultMap="EmisSettleBillResult">
select id, settle_bill_no, settle_bill_name, settle_type, settle_start_date, settle_end_date, bill_month, rec_money, reced_money, invoiced_money, cust_no, cust_name, customer_code, customer_name, site_code, site_name, satisfy_money, allowance_money, deduction_money, other_money, satisfy_reason, allowance_reason, deduction_reason, other_reason, open_bill_status, payment_status, charge_status, send_piece_sum, piece_number, fee_weight, uncollected_amount, send_money_sum, refund_amount, refund_money, payee, salesmen, credit_period, credit_period_type, settle_day, payment_due_date, bl_send_oms, bl_confirm_center, confirm_center_date, confirm_center_note, confirm_center_man_code, confirm_center_code, bl_confirm_site, confirm_site_date, confirm_site_man_code, confirm_site_note, confirm_site_code, remark, del_flag, create_by, create_time, update_by, update_time, create_site, update_site
from emis_settle_bill a
where a.settle_bill_no = #{settleBillNo} and del_flag='0'
</select>
<insert id="insertEmisSettleBill" parameterType="EmisSettleBill" useGeneratedKeys="true" keyProperty="id">
insert into emis_settle_bill
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="settleBillNo != null and settleBillNo != ''">settle_bill_no,</if>
<if test="settleBillName != null and settleBillName != ''">settle_bill_name,</if>
<if test="settleType != null and settleType != ''">settle_type,</if>
<if test="settleStartDate != null">settle_start_date,</if>
<if test="settleEndDate != null">settle_end_date,</if>
<if test="billMonth != null and billMonth != ''">bill_month,</if>
<if test="recMoney != null">rec_money,</if>
<if test="recedMoney != null">reced_money,</if>
<if test="invoicedMoney != null">invoiced_money,</if>
<if test="custNo != null and custNo != ''">cust_no,</if>
<if test="custName != null and custName != ''">cust_name,</if>
<if test="customerCode != null and customerCode != ''">customer_code,</if>
<if test="customerName != null and customerName != ''">customer_name,</if>
<if test="siteCode != null and siteCode != ''">site_code,</if>
<if test="siteName != null and siteName != ''">site_name,</if>
<if test="satisfyMoney != null">satisfy_money,</if>
<if test="allowanceMoney != null">allowance_money,</if>
<if test="deductionMoney != null">deduction_money,</if>
<if test="otherMoney != null">other_money,</if>
<if test="satisfyReason != null and satisfyReason != ''">satisfy_reason,</if>
<if test="allowanceReason != null and allowanceReason != ''">allowance_reason,</if>
<if test="deductionReason != null and deductionReason != ''">deduction_reason,</if>
<if test="otherReason != null and otherReason != ''">other_reason,</if>
<if test="openBillStatus != null and openBillStatus != ''">open_bill_status,</if>
<if test="paymentStatus != null and paymentStatus != ''">payment_status,</if>
<if test="chargeStatus != null and chargeStatus != ''">charge_status,</if>
<if test="sendPieceSum != null">send_piece_sum,</if>
<if test="pieceNumber != null">piece_number,</if>
<if test="feeWeight != null">fee_weight,</if>
<if test="uncollectedAmount != null">uncollected_amount,</if>
<if test="sendMoneySum != null">send_money_sum,</if>
<if test="refundAmount != null">refund_amount,</if>
<if test="refundMoney != null">refund_money,</if>
<if test="payee != null and payee != ''">payee,</if>
<if test="salesmen != null and salesmen != ''">salesmen,</if>
<if test="creditPeriod != null">credit_period,</if>
<if test="creditPeriodType != null and creditPeriodType != ''">credit_period_type,</if>
<if test="settleDay != null">settle_day,</if>
<if test="paymentDueDate != null">payment_due_date,</if>
<if test="blSendOms != null and blSendOms != ''">bl_send_oms,</if>
<if test="blConfirmCenter != null and blConfirmCenter != ''">bl_confirm_center,</if>
<if test="confirmCenterDate != null">confirm_center_date,</if>
<if test="confirmCenterNote != null and confirmCenterNote != ''">confirm_center_note,</if>
<if test="confirmCenterManCode != null and confirmCenterManCode != ''">confirm_center_man_code,</if>
<if test="confirmCenterCode != null and confirmCenterCode != ''">confirm_center_code,</if>
<if test="blConfirmSite != null and blConfirmSite != ''">bl_confirm_site,</if>
<if test="confirmSiteDate != null">confirm_site_date,</if>
<if test="confirmSiteManCode != null and confirmSiteManCode != ''">confirm_site_man_code,</if>
<if test="confirmSiteNote != null and confirmSiteNote != ''">confirm_site_note,</if>
<if test="confirmSiteCode != null and confirmSiteCode != ''">confirm_site_code,</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="settleBillNo != null and settleBillNo != ''">#{settleBillNo},</if>
<if test="settleBillName != null and settleBillName != ''">#{settleBillName},</if>
<if test="settleType != null and settleType != ''">#{settleType},</if>
<if test="settleStartDate != null">#{settleStartDate},</if>
<if test="settleEndDate != null">#{settleEndDate},</if>
<if test="billMonth != null and billMonth != ''">#{billMonth},</if>
<if test="recMoney != null">#{recMoney},</if>
<if test="recedMoney != null">#{recedMoney},</if>
<if test="invoicedMoney != null">#{invoicedMoney},</if>
<if test="custNo != null and custNo != ''">#{custNo},</if>
<if test="custName != null and custName != ''">#{custName},</if>
<if test="customerCode != null and customerCode != ''">#{customerCode},</if>
<if test="customerName != null and customerName != ''">#{customerName},</if>
<if test="siteCode != null and siteCode != ''">#{siteCode},</if>
<if test="siteName != null and siteName != ''">#{siteName},</if>
<if test="satisfyMoney != null">#{satisfyMoney},</if>
<if test="allowanceMoney != null">#{allowanceMoney},</if>
<if test="deductionMoney != null">#{deductionMoney},</if>
<if test="otherMoney != null">#{otherMoney},</if>
<if test="satisfyReason != null and satisfyReason != ''">#{satisfyReason},</if>
<if test="allowanceReason != null and allowanceReason != ''">#{allowanceReason},</if>
<if test="deductionReason != null and deductionReason != ''">#{deductionReason},</if>
<if test="otherReason != null and otherReason != ''">#{otherReason},</if>
<if test="openBillStatus != null and openBillStatus != ''">#{openBillStatus},</if>
<if test="paymentStatus != null and paymentStatus != ''">#{paymentStatus},</if>
<if test="chargeStatus != null and chargeStatus != ''">#{chargeStatus},</if>
<if test="sendPieceSum != null">#{sendPieceSum},</if>
<if test="pieceNumber != null">#{pieceNumber},</if>
<if test="feeWeight != null">#{feeWeight},</if>
<if test="uncollectedAmount != null">#{uncollectedAmount},</if>
<if test="sendMoneySum != null">#{sendMoneySum},</if>
<if test="refundAmount != null">#{refundAmount},</if>
<if test="refundMoney != null">#{refundMoney},</if>
<if test="payee != null and payee != ''">#{payee},</if>
<if test="salesmen != null and salesmen != ''">#{salesmen},</if>
<if test="creditPeriod != null">#{creditPeriod},</if>
<if test="creditPeriodType != null and creditPeriodType != ''">#{creditPeriodType},</if>
<if test="settleDay != null">#{settleDay},</if>
<if test="paymentDueDate != null">#{paymentDueDate},</if>
<if test="blSendOms != null and blSendOms != ''">#{blSendOms},</if>
<if test="blConfirmCenter != null and blConfirmCenter != ''">#{blConfirmCenter},</if>
<if test="confirmCenterDate != null">#{confirmCenterDate},</if>
<if test="confirmCenterNote != null and confirmCenterNote != ''">#{confirmCenterNote},</if>
<if test="confirmCenterManCode != null and confirmCenterManCode != ''">#{confirmCenterManCode},</if>
<if test="confirmCenterCode != null and confirmCenterCode != ''">#{confirmCenterCode},</if>
<if test="blConfirmSite != null and blConfirmSite != ''">#{blConfirmSite},</if>
<if test="confirmSiteDate != null">#{confirmSiteDate},</if>
<if test="confirmSiteManCode != null and confirmSiteManCode != ''">#{confirmSiteManCode},</if>
<if test="confirmSiteNote != null and confirmSiteNote != ''">#{confirmSiteNote},</if>
<if test="confirmSiteCode != null and confirmSiteCode != ''">#{confirmSiteCode},</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="updateEmisSettleBill" parameterType="EmisSettleBill">
update emis_settle_bill
<trim prefix="SET" suffixOverrides=",">
<if test="settleBillName != null and settleBillName != ''">settle_bill_name = #{settleBillName},</if>
<if test="settleType != null and settleType != ''">settle_type = #{settleType},</if>
<if test="settleStartDate != null">settle_start_date = #{settleStartDate},</if>
<if test="settleEndDate != null">settle_end_date = #{settleEndDate},</if>
<if test="billMonth != null and billMonth != ''">bill_month = #{billMonth},</if>
<if test="recMoney != null">rec_money = #{recMoney},</if>
<if test="recedMoney != null">reced_money = #{recedMoney},</if>
<if test="invoicedMoney != null">invoiced_money = #{invoicedMoney},</if>
<if test="custNo != null and custNo != ''">cust_no = #{custNo},</if>
<if test="custName != null and custName != ''">cust_name = #{custName},</if>
<if test="customerCode != null and customerCode != ''">customer_code = #{customerCode},</if>
<if test="customerName != null and customerName != ''">customer_name = #{customerName},</if>
<if test="siteCode != null and siteCode != ''">site_code = #{siteCode},</if>
<if test="siteName != null and siteName != ''">site_name = #{siteName},</if>
<if test="satisfyMoney != null">satisfy_money = #{satisfyMoney},</if>
<if test="allowanceMoney != null">allowance_money = #{allowanceMoney},</if>
<if test="deductionMoney != null">deduction_money = #{deductionMoney},</if>
<if test="otherMoney != null">other_money = #{otherMoney},</if>
<if test="satisfyReason != null and satisfyReason != ''">satisfy_reason = #{satisfyReason},</if>
<if test="allowanceReason != null and allowanceReason != ''">allowance_reason = #{allowanceReason},</if>
<if test="deductionReason != null and deductionReason != ''">deduction_reason = #{deductionReason},</if>
<if test="otherReason != null and otherReason != ''">other_reason = #{otherReason},</if>
<if test="openBillStatus != null and openBillStatus != ''">open_bill_status = #{openBillStatus},</if>
<if test="paymentStatus != null and paymentStatus != ''">payment_status = #{paymentStatus},</if>
<if test="chargeStatus != null and chargeStatus != ''">charge_status = #{chargeStatus},</if>
<if test="sendPieceSum != null">send_piece_sum = #{sendPieceSum},</if>
<if test="pieceNumber != null">piece_number = #{pieceNumber},</if>
<if test="feeWeight != null">fee_weight = #{feeWeight},</if>
<if test="uncollectedAmount != null">uncollected_amount = #{uncollectedAmount},</if>
<if test="sendMoneySum != null">send_money_sum = #{sendMoneySum},</if>
<if test="refundAmount != null">refund_amount = #{refundAmount},</if>
<if test="refundMoney != null">refund_money = #{refundMoney},</if>
<if test="payee != null and payee != ''">payee = #{payee},</if>
<if test="salesmen != null and salesmen != ''">salesmen = #{salesmen},</if>
<if test="creditPeriod != null">credit_period = #{creditPeriod},</if>
<if test="creditPeriodType != null and creditPeriodType != ''">credit_period_type = #{creditPeriodType},</if>
<if test="settleDay != null">settle_day = #{settleDay},</if>
<if test="paymentDueDate != null">payment_due_date = #{paymentDueDate},</if>
<if test="blSendOms != null and blSendOms != ''">bl_send_oms = #{blSendOms},</if>
<if test="blConfirmCenter != null and blConfirmCenter != ''">bl_confirm_center = #{blConfirmCenter},</if>
<if test="confirmCenterDate != null">confirm_center_date = #{confirmCenterDate},</if>
<if test="confirmCenterNote != null and confirmCenterNote != ''">confirm_center_note = #{confirmCenterNote},</if>
<if test="confirmCenterManCode != null and confirmCenterManCode != ''">confirm_center_man_code = #{confirmCenterManCode},</if>
<if test="confirmCenterCode != null and confirmCenterCode != ''">confirm_center_code = #{confirmCenterCode},</if>
<if test="blConfirmSite != null and blConfirmSite != ''">bl_confirm_site = #{blConfirmSite},</if>
<if test="confirmSiteDate != null">confirm_site_date = #{confirmSiteDate},</if>
<if test="confirmSiteManCode != null and confirmSiteManCode != ''">confirm_site_man_code = #{confirmSiteManCode},</if>
<if test="confirmSiteNote != null and confirmSiteNote != ''">confirm_site_note = #{confirmSiteNote},</if>
<if test="confirmSiteCode != null and confirmSiteCode != ''">confirm_site_code = #{confirmSiteCode},</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="deleteEmisSettleBillById" parameterType="Long">
update emis_settle_bill set del_flag='1' where id = #{id}
</delete>
<delete id="deleteEmisSettleBillByIds" parameterType="String">
update emis_settle_bill set del_flag='1' where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>