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

1230 lines
79 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.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="queryBillPayMonthList" parameterType="EmisSettleBill" resultType="map">
SELECT
bill_month as billMonth,
round(sum(rec_money),2) as recMoney,
round(sum(reced_money),2) as recedMoney,
(round(sum(rec_money),2)-round(sum(reced_money),2) ) as noRecedMoney
FROM emis_settle_bill
WHERE del_flag = '0'
GROUP BY bill_month
ORDER BY bill_month
</select>
<!-- 收款统计-PMS需求:379-->
<select id="queryPayBackStatList" parameterType="EmisSettleBill" resultType="map">
SELECT
tba.settle_bill_no AS settleBillNo,
tba.settle_bill_name as settleBillName,
tba.cust_no as custNo,
tba.cust_name as custName,
tba.customer_name as customerName,
tba.bill_month as billMonth,
tba.settle_type as settleType,
tba.open_bill_status as openBillStatus,
tba.payment_status as paymentStatus,
tba.settle_day as settleDay,
tba.send_piece_sum as sendPieceSum,
tba.credit_period as creditPeriod,
DATE(tba.payment_due_date) as paymentDueDate,
tba.rec_money as recMoney,
tba.reced_money as recedMoney,
tba.salesmen as salesmen,
tba.payee as payee,
tba.create_time as createTime,
tbc.satisfyMoney as satisfyMoney,
tbc.allowanceMoney as allowanceMoney,
tbc.deductionMoney as deductionMoney,
tbc.otherMoney as otherMoney,
tbc.totalOtherMoney as totalOtherMoney,
if( tbb.totalPayMoney > 0,tbb.totalPayMoney-tbc.totalOtherMoney, 0 ) AS totalPayMoney,
if( tbb.recdMoneyIn > 0,tbb.recdMoneyIn-tbc.totalOtherMoney,0) AS recdMoneyIn,
if( tbb.recdPayMoney60D > 0,tbb.recdPayMoney60D-tbc.totalOtherMoney,0) recdPayMoney60D,
if( tbb.recdPayMoneyGreat60D >0,tbb.recdPayMoneyGreat60D-tbc.totalOtherMoney,0) recdPayMoneyGreat60D,
( tba.rec_money - tba.reced_money - tbc.totalOtherMoney ) AS noRecMoney
FROM
(
SELECT
settle_bill_no,
settle_bill_name,
cust_no,
cust_name,
customer_name,
bill_month,
settle_type,
open_bill_status,
payment_status,
settle_day,
credit_period,
payment_due_date,
send_piece_sum,
rec_money,
reced_money,
satisfy_money,
allowance_money,
deduction_money,
other_money,
salesmen,
payee,
create_time
FROM
emis_settle_bill a
<where>
a.del_flag='0'
<if test="settleBillNo != null and settleBillNo != ''"> and FIND_IN_SET(a.`settle_bill_no`,#{settleBillNo})</if>
<if test="custNo != null and custNo != ''"> and a.cust_no = #{custNo}</if>
<if test="salesmen != null and salesmen!='' "> and a.salesmen = #{salesmen}</if>
<if test="payee != null and payee!='' "> and a.payee = #{payee}</if>
<if test="settleType != null and settleType != ''"> and a.settle_type= #{settleType}</if>
<if test="billMonth != null and billMonth!='' "> and FIND_IN_SET(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.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.beginTradeDate != null and params.beginTradeDate != ''">
and exists (
select 1 from emis_settle_pay_record espr,emis_settle_pay_bill_rel espbr
where espr.del_flag='0' and espbr.del_flag='0' and a.settle_bill_no=espr.settle_bill_no and espr.pay_id = espbr.pay_id
and espr.trade_date <![CDATA[ >= ]]> #{params.beginTradeDate}
)
</if>
<if test="params.endTradeDate != null and params.endTradeDate != ''">
and exists (
select 1 from emis_settle_pay_record espr,emis_settle_pay_bill_rel espbr
where espr.del_flag='0' and espbr.del_flag='0' and a.settle_bill_no=espr.settle_bill_no and espr.pay_id = espbr.pay_id
and espr.trade_date <![CDATA[ <= ]]> #{params.endTradeDate}
)
</if>
<if test="params.payCreateBy != null and params.payCreateBy != ''">
and exists (
select 1 from emis_settle_pay_record espr,emis_settle_pay_bill_rel espbr
where espr.del_flag='0' and espbr.del_flag='0' and a.settle_bill_no=espr.settle_bill_no and espr.pay_id = espbr.pay_id
and espr.create_by = #{params.payCreateBy}
)
</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>
) tba
LEFT JOIN (
SELECT
a.settle_bill_no,
sum( ifnull(d.pay_money,0) ) AS totalPayMoney,
sum( if(b.trade_date <![CDATA[ <= ]]> a.payment_due_date,ifnull(d.pay_money,0) ,0) ) AS recdMoneyIn,
sum( if(a.settle_type='2' and a.credit_period <![CDATA[ >= ]]> 30 and b.trade_date <![CDATA[ > ]]> a.payment_due_date and b.trade_date <![CDATA[ > ]]> a.payment_due_date and b.trade_date <![CDATA[ < ]]> DATE_SUB( a.payment_due_date, INTERVAL (a.credit_period-60) DAY ),ifnull(d.pay_money,0) ,0) ) AS recdPayMoney60D,
sum( if( (a.settle_type='2' and a.credit_period <![CDATA[ >= ]]> 30 and b.trade_date <![CDATA[ > ]]> a.payment_due_date and b.trade_date <![CDATA[ >= ]]> DATE_SUB( a.payment_due_date, INTERVAL (a.credit_period-60) DAY ) ) or ( ( (a.settle_type='2' and a.credit_period <![CDATA[ < ]]> 30) or a.settle_type='1' ) and b.trade_date <![CDATA[ > ]]> a.payment_due_date ),ifnull(d.pay_money,0) ,0) ) AS recdPayMoneyGreat60D
FROM
emis_settle_bill a,
emis_settle_pay_record b,
emis_settle_pay_bill_rel c,
emis_settle_pay_rel d,
emis_settle_sub_bill e
<where>
a.del_flag = '0'
AND b.del_flag = '0'
AND c.del_flag = '0'
and d.del_flag ='0'
AND a.settle_bill_no = c.settle_bill_no
and d.pay_id=b.pay_id
and d.bill_no=e.bill_code
and e.settle_bill_no=a.settle_bill_no
AND b.pay_id = c.pay_id
<if test="settleBillNo != null and settleBillNo != ''"> and FIND_IN_SET(a.`settle_bill_no`,#{settleBillNo})</if>
<if test="custNo != null and custNo != ''"> and a.cust_no = #{custNo}</if>
<if test="salesmen != null and salesmen!='' "> and a.salesmen = #{salesmen}</if>
<if test="payee != null and payee!='' "> and a.payee = #{payee}</if>
<if test="settleType != null and settleType != ''"> and a.settle_type= #{settleType}</if>
<if test="billMonth != null and billMonth!='' "> and FIND_IN_SET(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.billCode != null and params.billCode != ''">
and ( FIND_IN_SET(e.`bill_code`,#{params.billCode}) or e.bill_code like concat('%', #{params.billCode}, '%') )
</if>
<if test="params.payCreateBy != null and params.payCreateBy != ''">
and b.create_by = #{params.payCreateBy}
</if>
<if test="params.beginTradeDate != null and params.beginTradeDate != ''">
and b.trade_date <![CDATA[ >= ]]> #{params.beginTradeDate}
</if>
<if test="params.endTradeDate != null and params.endTradeDate != ''">
and b.trade_date <![CDATA[ <= ]]> #{params.endTradeDate}
</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 a.settle_bill_no
) tbb ON tba.settle_bill_no = tbb.settle_bill_no
LEFT JOIN (
SELECT
a.settle_bill_no,
sum( ifnull(b.satisfy_money,0) ) AS satisfyMoney,
sum( ifnull(b.allowance_money,0) ) AS allowanceMoney,
sum( ifnull(b.deduction_money,0) ) AS deductionMoney,
sum( ifnull(b.other_money,0) ) AS otherMoney,
sum(ifnull(b.satisfy_money,0)+ifnull(b.allowance_money,0)+ifnull(b.deduction_money,0)+ifnull(b.other_money,0) ) as totalOtherMoney
FROM
emis_settle_bill a,
emis_settle_pay_record b,
emis_settle_pay_bill_rel c
<where>
a.del_flag = '0'
AND b.del_flag = '0'
AND c.del_flag = '0'
AND a.settle_bill_no = c.settle_bill_no
AND b.pay_id = c.pay_id
<if test="settleBillNo != null and settleBillNo != ''"> and FIND_IN_SET(a.`settle_bill_no`,#{settleBillNo})</if>
<if test="custNo != null and custNo != ''"> and a.cust_no = #{custNo}</if>
<if test="salesmen != null and salesmen!='' "> and a.salesmen = #{salesmen}</if>
<if test="payee != null and payee!='' "> and a.payee = #{payee}</if>
<if test="settleType != null and settleType != ''"> and a.settle_type= #{settleType}</if>
<if test="billMonth != null and billMonth!='' "> and FIND_IN_SET(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.payCreateBy != null and params.payCreateBy != ''">
and b.create_by = #{params.payCreateBy}
</if>
<if test="params.beginTradeDate != null and params.beginTradeDate != ''">
and b.trade_date <![CDATA[ >= ]]> #{params.beginTradeDate}
</if>
<if test="params.endTradeDate != null and params.endTradeDate != ''">
and b.trade_date <![CDATA[ <= ]]> #{params.endTradeDate}
</if>
<if test="params.billCode != null and params.billCode != ''">
and b.pay_id in(
select pay_id from emis_settle_pay_rel espr
where espr.del_flag='0'
and FIND_IN_SET(espr.`bill_no`,#{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>
GROUP BY a.settle_bill_no
) tbc ON tba.settle_bill_no = tbc.settle_bill_no
</select>
<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)-ifnull(tbd.expiredRecdPayMoney,0)-tba.totalSatisfyMoney-tba.totalAllowanceMoney-tba.totalDeductionMoney-tba.totalOtherMoney ) as noRecdPayMoney,
ifnull(tbd.expiredRecdPayMoney,0) as expiredRecdPayMoney,
( ifnull(tbe.expiredNoRecdPayMoney,0) - tba.totalSatisfyMoney-tba.totalAllowanceMoney-tba.totalDeductionMoney-tba.totalOtherMoney ) 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.isNeedRecdPay != null and params.isNeedRecdPay == 1">
and tba.totalNoRecdPayMoney <![CDATA[ > ]]> 0
and (
ifnull( tbe.expiredNoRecdPayMoney, 0 ) <![CDATA[ > ]]> 0
or
( tba.recPayMoney - ifnull( tbc.recdPayMoney, 0 ) ) <![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
where 1=1
<if test="params.isNeedRecdInvoice != null and params.isNeedRecdInvoice == 1">
and tbb.noOpenBillCount <![CDATA[ > ]]> 0
</if>
</select>
<!-- 销售回款率统计-PMS需求:1610
销售回款率统计界面:
(1)数据来源于 财务收款统计界面 以 销售联系人 为主键,
(2)统计销售联系人的现金账单数、现金账单总金额、现金账期内收款金额(100%)总金额;
现金回款系数=现金账单账期内收款总金额(100%) / 现金账单 总金额 * 100%
(3)月结回款系数=月结100%回款系数+月结70%回款系数
月结100%回款系数 = 月结账期内收款总金额100% / 月结账单总金额 * 100%
月结70%回款系数 = 月结账期内收款总金额70% / 月结账单总金额 * 70%
-->
<select id="querySalesPayBackRateList" parameterType="EmisSettleBill" resultType="map">
SELECT
tbMA.salesmen,
tbMA.billMonth,
sum(if( tbMA.settleType=1,1, 0 ) ) AS totalMoneyBillCount,
sum(if( tbMA.settleType=1,tbMA.recMoney, 0 ) ) AS totalMoneyRecAmount,
sum(if( tbMA.settleType=1,tbMA.recdMoneyIn, 0 ) ) AS totalMoneyRecdIn,
round( sum(if( tbMA.settleType=1,tbMA.recdMoneyIn, 0 ) ) / sum(if( tbMA.settleType=1,tbMA.recMoney, 0 ) ),4 ) as totalMoneyRecdRate,
sum(if( tbMA.settleType=2,1, 0 ) ) AS totalMonthBillCount,
sum(if( tbMA.settleType=2,tbMA.recMoney, 0 ) ) AS totalMonthRecAmount,
sum(if( tbMA.settleType=2,tbMA.recdMoneyIn, 0 ) ) AS totalMonthRecdIn,
sum(if( tbMA.settleType=2,tbMA.recdPayMoney60D, 0 ) ) AS totalMonthRecd70,
round( sum(if( tbMA.settleType=2,tbMA.recdMoneyIn, 0 ) ) / sum(if( tbMA.settleType=2,tbMA.recMoney, 0 ) ),4 ) as totalMonthRecdInRate,
round( sum(if( tbMA.settleType=2,tbMA.recdPayMoney60D, 0 ) ) / sum(if( tbMA.settleType=2,tbMA.recMoney, 0 ) ),4 ) as totalMonthRecd70Rate,
ifnull(ecp.money,0) as moneyProfit,
ifnull(ecp.month_money,0) as monthProfit
from (
SELECT
tba.settle_bill_no AS settleBillNo,
tba.settle_bill_name as settleBillName,
tba.cust_no as custNo,
tba.cust_name as custName,
tba.customer_name as customerName,
tba.bill_month as billMonth,
tba.settle_type as settleType,
tba.open_bill_status as openBillStatus,
tba.payment_status as paymentStatus,
tba.settle_day as settleDay,
tba.send_piece_sum as sendPieceSum,
tba.credit_period as creditPeriod,
DATE(tba.payment_due_date) as paymentDueDate,
tba.rec_money as recMoney,
tba.reced_money as recedMoney,
tba.salesmen as salesmen,
tba.payee as payee,
tba.create_time as createTime,
tbc.satisfyMoney as satisfyMoney,
tbc.allowanceMoney as allowanceMoney,
tbc.deductionMoney as deductionMoney,
tbc.otherMoney as otherMoney,
tbc.totalOtherMoney as totalOtherMoney,
if( tbb.totalPayMoney > 0,tbb.totalPayMoney-tbc.totalOtherMoney, 0 ) AS totalPayMoney,
if( tbb.recdMoneyIn > 0,tbb.recdMoneyIn-tbc.totalOtherMoney,0) AS recdMoneyIn,
if( tbb.recdPayMoney60D > 0,tbb.recdPayMoney60D-tbc.totalOtherMoney,0) recdPayMoney60D,
if( tbb.recdPayMoneyGreat60D >0,tbb.recdPayMoneyGreat60D-tbc.totalOtherMoney,0) recdPayMoneyGreat60D,
( tba.rec_money - tba.reced_money - tbc.totalOtherMoney ) AS noRecMoney
FROM
(
SELECT
settle_bill_no,
settle_bill_name,
cust_no,
cust_name,
customer_name,
bill_month,
settle_type,
open_bill_status,
payment_status,
settle_day,
credit_period,
payment_due_date,
send_piece_sum,
rec_money,
reced_money,
satisfy_money,
allowance_money,
deduction_money,
other_money,
salesmen,
payee,
create_time
FROM
emis_settle_bill a
<where>
a.del_flag='0'
<if test="settleBillNo != null and settleBillNo != ''"> and FIND_IN_SET(a.`settle_bill_no`,#{settleBillNo})</if>
<if test="custNo != null and custNo != ''"> and a.cust_no = #{custNo}</if>
<if test="salesmen != null and salesmen!='' "> and a.salesmen = #{salesmen}</if>
<if test="payee != null and payee!='' "> and a.payee = #{payee}</if>
<if test="settleType != null and settleType != ''"> and a.settle_type= #{settleType}</if>
<if test="billMonth != null and billMonth!='' "> and FIND_IN_SET(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.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.beginTradeDate != null and params.beginTradeDate != ''">
and exists (
select 1 from emis_settle_pay_record espr,emis_settle_pay_bill_rel espbr
where espr.del_flag='0' and espbr.del_flag='0' and a.settle_bill_no=espr.settle_bill_no and espr.pay_id = espbr.pay_id
and espr.trade_date <![CDATA[ >= ]]> #{params.beginTradeDate}
)
</if>
<if test="params.endTradeDate != null and params.endTradeDate != ''">
and exists (
select 1 from emis_settle_pay_record espr,emis_settle_pay_bill_rel espbr
where espr.del_flag='0' and espbr.del_flag='0' and a.settle_bill_no=espr.settle_bill_no and espr.pay_id = espbr.pay_id
and espr.trade_date <![CDATA[ <= ]]> #{params.endTradeDate}
)
</if>
<if test="params.payCreateBy != null and params.payCreateBy != ''">
and exists (
select 1 from emis_settle_pay_record espr,emis_settle_pay_bill_rel espbr
where espr.del_flag='0' and espbr.del_flag='0' and a.settle_bill_no=espr.settle_bill_no and espr.pay_id = espbr.pay_id
and espr.create_by = #{params.payCreateBy}
)
</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>
) tba
LEFT JOIN (
SELECT
a.settle_bill_no,
sum( ifnull(d.pay_money,0) ) AS totalPayMoney,
sum( if(b.trade_date <![CDATA[ <= ]]> a.payment_due_date,ifnull(d.pay_money,0) ,0) ) AS recdMoneyIn,
sum( if(a.settle_type='2' and a.credit_period <![CDATA[ >= ]]> 30 and b.trade_date <![CDATA[ > ]]> a.payment_due_date and b.trade_date <![CDATA[ > ]]> a.payment_due_date and b.trade_date <![CDATA[ < ]]> DATE_SUB( a.payment_due_date, INTERVAL (a.credit_period-60) DAY ),ifnull(d.pay_money,0) ,0) ) AS recdPayMoney60D,
sum( if( (a.settle_type='2' and a.credit_period <![CDATA[ >= ]]> 30 and b.trade_date <![CDATA[ > ]]> a.payment_due_date and b.trade_date <![CDATA[ >= ]]> DATE_SUB( a.payment_due_date, INTERVAL (a.credit_period-60) DAY ) ) or ( ( (a.settle_type='2' and a.credit_period <![CDATA[ < ]]> 30) or a.settle_type='1' ) and b.trade_date <![CDATA[ > ]]> a.payment_due_date ),ifnull(d.pay_money,0) ,0) ) AS recdPayMoneyGreat60D
FROM
emis_settle_bill a,
emis_settle_pay_record b,
emis_settle_pay_bill_rel c,
emis_settle_pay_rel d,
emis_settle_sub_bill e
<where>
a.del_flag = '0'
AND b.del_flag = '0'
AND c.del_flag = '0'
and d.del_flag ='0'
AND a.settle_bill_no = c.settle_bill_no
and d.pay_id=b.pay_id
and d.bill_no=e.bill_code
and e.settle_bill_no=a.settle_bill_no
AND b.pay_id = c.pay_id
<if test="settleBillNo != null and settleBillNo != ''"> and FIND_IN_SET(a.`settle_bill_no`,#{settleBillNo})</if>
<if test="custNo != null and custNo != ''"> and a.cust_no = #{custNo}</if>
<if test="salesmen != null and salesmen!='' "> and a.salesmen = #{salesmen}</if>
<if test="payee != null and payee!='' "> and a.payee = #{payee}</if>
<if test="settleType != null and settleType != ''"> and a.settle_type= #{settleType}</if>
<if test="billMonth != null and billMonth!='' "> and FIND_IN_SET(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.billCode != null and params.billCode != ''">
and ( FIND_IN_SET(e.`bill_code`,#{params.billCode}) or e.bill_code like concat('%', #{params.billCode}, '%') )
</if>
<if test="params.payCreateBy != null and params.payCreateBy != ''">
and b.create_by = #{params.payCreateBy}
</if>
<if test="params.beginTradeDate != null and params.beginTradeDate != ''">
and b.trade_date <![CDATA[ >= ]]> #{params.beginTradeDate}
</if>
<if test="params.endTradeDate != null and params.endTradeDate != ''">
and b.trade_date <![CDATA[ <= ]]> #{params.endTradeDate}
</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 a.settle_bill_no
) tbb ON tba.settle_bill_no = tbb.settle_bill_no
LEFT JOIN (
SELECT
a.settle_bill_no,
sum( ifnull(b.satisfy_money,0) ) AS satisfyMoney,
sum( ifnull(b.allowance_money,0) ) AS allowanceMoney,
sum( ifnull(b.deduction_money,0) ) AS deductionMoney,
sum( ifnull(b.other_money,0) ) AS otherMoney,
sum(ifnull(b.satisfy_money,0)+ifnull(b.allowance_money,0)+ifnull(b.deduction_money,0)+ifnull(b.other_money,0) ) as totalOtherMoney
FROM
emis_settle_bill a,
emis_settle_pay_record b,
emis_settle_pay_bill_rel c
<where>
a.del_flag = '0'
AND b.del_flag = '0'
AND c.del_flag = '0'
AND a.settle_bill_no = c.settle_bill_no
AND b.pay_id = c.pay_id
<if test="settleBillNo != null and settleBillNo != ''"> and FIND_IN_SET(a.`settle_bill_no`,#{settleBillNo})</if>
<if test="custNo != null and custNo != ''"> and a.cust_no = #{custNo}</if>
<if test="salesmen != null and salesmen!='' "> and a.salesmen = #{salesmen}</if>
<if test="payee != null and payee!='' "> and a.payee = #{payee}</if>
<if test="settleType != null and settleType != ''"> and a.settle_type= #{settleType}</if>
<if test="billMonth != null and billMonth!='' "> and FIND_IN_SET(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.payCreateBy != null and params.payCreateBy != ''">
and b.create_by = #{params.payCreateBy}
</if>
<if test="params.beginTradeDate != null and params.beginTradeDate != ''">
and b.trade_date <![CDATA[ >= ]]> #{params.beginTradeDate}
</if>
<if test="params.endTradeDate != null and params.endTradeDate != ''">
and b.trade_date <![CDATA[ <= ]]> #{params.endTradeDate}
</if>
<if test="params.billCode != null and params.billCode != ''">
and b.pay_id in(
select pay_id from emis_settle_pay_rel espr
where espr.del_flag='0'
and FIND_IN_SET(espr.`bill_no`,#{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>
GROUP BY a.settle_bill_no
) tbc ON tba.settle_bill_no = tbc.settle_bill_no
) tbMA left join emis_commission_profit ecp on tbMA.salesmen=ecp.emp_name and tbMA.billMonth = ecp.bill_month
group by tbMA.salesmen,tbMA.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>
<select id="selectSettleBillBySettleBillNoList" parameterType="List" 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.del_flag='0' and a.settle_bill_no in
<foreach item="settleBillNo" collection="settleBillNoList" open="(" separator="," close=")">
#{settleBillNo}
</foreach>
</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>