|
|
@@ -205,6 +205,12 @@
|
|
|
WHERE
|
|
|
1=1
|
|
|
AND NOT EXISTS ( SELECT 1 FROM ins_ply_income_invoice_link ipil WHERE ipil.income_id = ipi.id )
|
|
|
+ <if test = "receivableQueryVo.ids != null and receivableQueryVo.ids.size > 0">
|
|
|
+ AND ipi.id in
|
|
|
+ <foreach collection="receivableQueryVo.ids" item="id" open="(" separator="," close=")">
|
|
|
+ #{id}
|
|
|
+ </foreach>
|
|
|
+ </if>
|
|
|
<if test="receivableQueryVo.queryType != null and receivableQueryVo.queryType == 1">
|
|
|
AND ipi.supervise_settlement = 0
|
|
|
</if>
|
|
|
@@ -296,6 +302,9 @@
|
|
|
<if test="receivableQueryVo.signingTimeStart != null and receivableQueryVo.signingTimeStart != ''">
|
|
|
AND ipi.signing_time between #{receivableQueryVo.signingTimeStart} and #{receivableQueryVo.signingTimeEnd}
|
|
|
</if>
|
|
|
+ <if test="receivableQueryVo.agreementType != null and receivableQueryVo.agreementType != ''">
|
|
|
+ AND ipi.agreement_type = #{receivableQueryVo.agreementType}
|
|
|
+ </if>
|
|
|
</select>
|
|
|
|
|
|
<select id="getSuperviseJyExcelDtos" resultType="com.jzg.commons.entity.finance.dto.ExportSuperviseJyExcelDto">
|
|
|
@@ -308,7 +317,7 @@
|
|
|
io.entry_status as entryStatus,
|
|
|
ipi.license_no as licenseNo,
|
|
|
(ipi.jq_receivable_premium + ipi.sy_receivable_premium + ipi.jy_receivable_premium) as receivableAmount,
|
|
|
- ipi.product_name as productName,
|
|
|
+ io.product_name as productName,
|
|
|
iocui.name AS insuredPerson,
|
|
|
ipi.jy_premium as jqPremium,
|
|
|
ipi.jy_supervise_costs_proportion as jqSuperviseCostsProportion,
|
|
|
@@ -362,27 +371,33 @@
|
|
|
<if test="receivableQueryVo.signingTimeStart != null and receivableQueryVo.signingTimeStart != ''">
|
|
|
AND ipi.signing_time between #{receivableQueryVo.signingTimeStart} and #{receivableQueryVo.signingTimeEnd}
|
|
|
</if>
|
|
|
+ <if test="receivableQueryVo.agreementType != null and receivableQueryVo.agreementType != ''">
|
|
|
+ AND ipi.agreement_type = #{receivableQueryVo.agreementType}
|
|
|
+ </if>
|
|
|
</select>
|
|
|
|
|
|
- <select id="getSuperviseSettlementExcelDtos" resultType="com.jzg.commons.entity.finance.dto.ExportSuperviseSettlementExcelDto">
|
|
|
+ <select id="superviseSettlementExcelDtos" resultType="com.jzg.commons.entity.finance.dto.ExportSuperviseSettlementExcelDto">
|
|
|
select
|
|
|
- ipiis.id as settlementId,
|
|
|
- ipiis.invoice_id as invoiceId,
|
|
|
- ipi.company_name as companyName,
|
|
|
- ipii.invoice_type as invoiceType,
|
|
|
- ipii.invoice_party as invoiceParty,
|
|
|
- ipii.tax_point as taxPoint,
|
|
|
- ipiis.actual_received_amount as actualReceivedAmount,
|
|
|
- ipiis.receive_payment_date as receivePaymentDate,
|
|
|
- ipiis.create_by as createBy,
|
|
|
- ipiis.create_time as createTime
|
|
|
+ ipiis.id as settlementId,
|
|
|
+ ipiis.invoice_id as invoiceId,
|
|
|
+ io.company_name as companyName,
|
|
|
+ ipii.invoice_type as invoiceType,
|
|
|
+ ipii.invoice_party as invoiceParty,
|
|
|
+ ipii.tax_point as taxPoint,
|
|
|
+ ipiis.actual_received_amount as actualReceivedAmount,
|
|
|
+ ipiis.receive_payment_date as receivePaymentDate,
|
|
|
+ ipiis.create_by as createBy,
|
|
|
+ ipiis.create_time as createTime,
|
|
|
+ ipiisf.file_id as fileId
|
|
|
FROM
|
|
|
- ins_ply_income_invoice_settlement ipiis
|
|
|
+ ins_ply_income_invoice_settlement ipiis
|
|
|
+ LEFT JOIN ins_ply_income_invoice_settlement_file ipiisf ON ipiisf.settlement_id = ipiis.id
|
|
|
LEFT JOIN ins_ply_income_invoice ipii ON ipii.id = ipiis.invoice_id
|
|
|
LEFT JOIN ins_ply_income_invoice_link ipil ON ipil.invoice_id = ipiis.invoice_id
|
|
|
LEFT JOIN ins_ply_income ipi ON ipi.id = ipil.income_id
|
|
|
+ LEFT JOIN ins_orders io ON ipi.order_no = io.id
|
|
|
WHERE
|
|
|
- 1=1
|
|
|
+ 1=1
|
|
|
<if test="settlementQueryVo.settlementIds != null and settlementQueryVo.settlementIds != ''">
|
|
|
AND ipiis.id IN
|
|
|
<foreach collection="settlementQueryVo.settlementIds" item="settlementId" open="(" separator="," close=")">
|
|
|
@@ -390,13 +405,49 @@
|
|
|
</foreach>
|
|
|
</if>
|
|
|
<if test="settlementQueryVo.invoiceTypes != null and settlementQueryVo.invoiceTypes != ''">
|
|
|
- AND ipi.invoice_type IN
|
|
|
+ AND ipii.invoice_type IN
|
|
|
<foreach collection="settlementQueryVo.invoiceTypes" item="invoiceType" open="(" separator="," close=")">
|
|
|
#{invoiceType}
|
|
|
</foreach>
|
|
|
</if>
|
|
|
+ <if test="settlementQueryVo.agreementType != null and settlementQueryVo.agreementType != ''">
|
|
|
+ AND ipii.agreement_type = #{agreementType}
|
|
|
+ </if>
|
|
|
</select>
|
|
|
|
|
|
+<!-- <select id="getSuperviseSettlementExcelDtos" resultType="com.jzg.commons.entity.finance.dto.ExportSuperviseSettlementExcelDto">-->
|
|
|
+<!-- select-->
|
|
|
+<!-- ipiis.id as settlementId,-->
|
|
|
+<!-- ipiis.invoice_id as invoiceId,-->
|
|
|
+<!-- ipi.company_name as companyName,-->
|
|
|
+<!-- ipii.invoice_type as invoiceType,-->
|
|
|
+<!-- ipii.invoice_party as invoiceParty,-->
|
|
|
+<!-- ipii.tax_point as taxPoint,-->
|
|
|
+<!-- ipiis.actual_received_amount as actualReceivedAmount,-->
|
|
|
+<!-- ipiis.receive_payment_date as receivePaymentDate,-->
|
|
|
+<!-- ipiis.create_by as createBy,-->
|
|
|
+<!-- ipiis.create_time as createTime-->
|
|
|
+<!-- FROM-->
|
|
|
+<!-- ins_ply_income_invoice_settlement ipiis-->
|
|
|
+<!-- LEFT JOIN ins_ply_income_invoice ipii ON ipii.id = ipiis.invoice_id-->
|
|
|
+<!-- LEFT JOIN ins_ply_income_invoice_link ipil ON ipil.invoice_id = ipiis.invoice_id-->
|
|
|
+<!-- LEFT JOIN ins_ply_income ipi ON ipi.id = ipil.income_id-->
|
|
|
+<!-- WHERE-->
|
|
|
+<!-- 1=1-->
|
|
|
+<!-- <if test="settlementQueryVo.settlementIds != null and settlementQueryVo.settlementIds != ''">-->
|
|
|
+<!-- AND ipiis.id IN-->
|
|
|
+<!-- <foreach collection="settlementQueryVo.settlementIds" item="settlementId" open="(" separator="," close=")">-->
|
|
|
+<!-- #{settlementId}-->
|
|
|
+<!-- </foreach>-->
|
|
|
+<!-- </if>-->
|
|
|
+<!-- <if test="settlementQueryVo.invoiceTypes != null and settlementQueryVo.invoiceTypes != ''">-->
|
|
|
+<!-- AND ipi.invoice_type IN-->
|
|
|
+<!-- <foreach collection="settlementQueryVo.invoiceTypes" item="invoiceType" open="(" separator="," close=")">-->
|
|
|
+<!-- #{invoiceType}-->
|
|
|
+<!-- </foreach>-->
|
|
|
+<!-- </if>-->
|
|
|
+<!-- </select>-->
|
|
|
+
|
|
|
<select id="getSuperviseSettlementDetailExcelDtos" resultType="com.jzg.commons.entity.finance.dto.ExportSuperviseSettlementDetailExcelDto">
|
|
|
select
|
|
|
ipiis.id as settlementId, -- 结算记录编号
|
|
|
@@ -416,6 +467,9 @@
|
|
|
ipi.sy_premium as syPremium, -- 商业保费
|
|
|
ipi.sy_supervise_costs_proportion as sySuperviseCostsProportion, -- 商业手续费比例
|
|
|
ipi.sy_policy_no as syPolicyNo, -- 商业保单号
|
|
|
+ ipi.jy_premium as jyPremium, -- 非车保费
|
|
|
+ ipi.jy_supervise_costs_proportion as jySuperviseCostsProportion, -- 非车手续费比例
|
|
|
+ ipi.jy_policy_no as jyPolicyNo, -- 非车保单号
|
|
|
ipi.tax_premium as taxPremium, -- 车船税
|
|
|
ipii.create_by as invoicePerson, -- 开票人
|
|
|
ipii.create_time as invoiceTime, -- 开票时间
|
|
|
@@ -436,7 +490,7 @@
|
|
|
</foreach>
|
|
|
</if>
|
|
|
<if test="settlementQueryVo.invoiceTypes != null and settlementQueryVo.invoiceTypes != ''">
|
|
|
- AND ipi.invoice_type IN
|
|
|
+ AND ipii.invoice_type IN
|
|
|
<foreach collection="settlementQueryVo.invoiceTypes" item="invoiceType" open="(" separator="," close=")">
|
|
|
#{invoiceType}
|
|
|
</foreach>
|
|
|
@@ -456,6 +510,9 @@
|
|
|
<if test="settlementQueryVo.settlementTimeStart != null and settlementQueryVo.settlementTimeStart != ''">
|
|
|
AND ipiis.create_time between #{settlementQueryVo.signingTimeStart} and #{settlementQueryVo.signingTimeEnd}
|
|
|
</if>
|
|
|
+ <if test="settlementQueryVo.agreementType != null and settlementQueryVo.agreementType != ''">
|
|
|
+ AND ipii.agreement_type = #{settlementQueryVo.agreementType}
|
|
|
+ </if>
|
|
|
</select>
|
|
|
|
|
|
<select id="getSuperviseSettlementDetailJyExcelDtos" resultType="com.jzg.commons.entity.finance.dto.ExportSuperviseSettlementDetailJyExcelDto">
|
|
|
@@ -494,7 +551,7 @@
|
|
|
</foreach>
|
|
|
</if>
|
|
|
<if test="settlementQueryVo.invoiceTypes != null and settlementQueryVo.invoiceTypes != ''">
|
|
|
- AND ipi.invoice_type IN
|
|
|
+ AND ipii.invoice_type IN
|
|
|
<foreach collection="settlementQueryVo.invoiceTypes" item="invoiceType" open="(" separator="," close=")">
|
|
|
#{invoiceType}
|
|
|
</foreach>
|
|
|
@@ -514,6 +571,9 @@
|
|
|
<if test="settlementQueryVo.settlementTimeStart != null and settlementQueryVo.settlementTimeStart != ''">
|
|
|
AND ipiis.create_time between #{settlementQueryVo.signingTimeStart} and #{settlementQueryVo.signingTimeEnd}
|
|
|
</if>
|
|
|
+ <if test="settlementQueryVo.agreementType != null and settlementQueryVo.agreementType != ''">
|
|
|
+ AND ipi.agreement_type = #{settlementQueryVo.agreementType}
|
|
|
+ </if>
|
|
|
</select>
|
|
|
|
|
|
<select id="getOtherExcelDtos" resultType="com.jzg.commons.entity.finance.dto.ExportOtherExcelDto">
|
|
|
@@ -526,7 +586,7 @@
|
|
|
io.entry_status as entryStatus,
|
|
|
ipi.license_no as licenseNo,
|
|
|
(ipi.jq_other_costs_premiums + ipi.sy_other_costs_premiums + ipi.jy_other_costs_premiums) as receivableAmount,
|
|
|
- ipi.product_name as productName,
|
|
|
+ io.product_name as productName,
|
|
|
iocui.name AS insuredPerson,
|
|
|
ipi.jq_premium as jqPremium,
|
|
|
ipi.jq_other_costs_proportion as jqSuperviseCostsProportion,
|
|
|
@@ -540,12 +600,21 @@
|
|
|
ipi.create_time as createTime,
|
|
|
ipi.contact_person as contactPerson
|
|
|
FROM ins_ply_income ipi
|
|
|
- LEFT JOIN ins_order io ON ipi.order_no = io.order_no
|
|
|
+ LEFT JOIN ins_orders io ON ipi.order_no = io.id
|
|
|
LEFT JOIN ins_orders_car_user_info iocui ON ipi.order_no = iocui.order_no and iocui.policy_person_type = '3'
|
|
|
LEFT JOIN ins_orders_risk ior1 ON ipi.order_no = ior1.order_no and ior1.risk_code = '0507'
|
|
|
LEFT JOIN ins_orders_risk ior2 ON ipi.order_no = ior2.order_no and ior2.risk_code = '0510'
|
|
|
WHERE
|
|
|
1=1
|
|
|
+ <if test="receivableQueryVo.queryType != null and receivableQueryVo.queryType == 1">
|
|
|
+ AND ipi.supervise_settlement = 0
|
|
|
+ </if>
|
|
|
+ <if test="receivableQueryVo.queryType!= null and receivableQueryVo.queryType == 2">
|
|
|
+ AND ipi.other_settlement = 1
|
|
|
+ </if>
|
|
|
+ <if test="receivableQueryVo.queryType!= null and (receivableQueryVo.queryType == 3 or receivableQueryVo.queryType == 4)">
|
|
|
+ AND ipi.jy_premium != 0
|
|
|
+ </if>
|
|
|
<if test="receivableQueryVo.licenseNo != null and receivableQueryVo.licenseNo != ''">
|
|
|
and ipi.licenseNo = #{receivableQueryVo.licenseNo}
|
|
|
</if>
|
|
|
@@ -585,12 +654,21 @@
|
|
|
ior2.start_date as syStartDate,
|
|
|
ipi.create_time as createTime
|
|
|
FROM ins_ply_income ipi
|
|
|
- LEFT JOIN ins_order io ON ipi.order_no = io.order_no
|
|
|
+ LEFT JOIN ins_orders io ON ipi.order_no = io.order_no
|
|
|
LEFT JOIN ins_orders_car_user_info iocui ON ipi.order_no = iocui.order_no and iocui.policy_person_type = '3'
|
|
|
LEFT JOIN ins_orders_risk ior1 ON ipi.order_no = ior1.order_no and ior1.risk_code = '0507'
|
|
|
LEFT JOIN ins_orders_risk ior2 ON ipi.order_no = ior2.order_no and ior2.risk_code = '0510'
|
|
|
WHERE
|
|
|
1=1
|
|
|
+ <if test="receivableQueryVo.queryType != null and receivableQueryVo.queryType == 1">
|
|
|
+ AND ipi.supervise_settlement = 0
|
|
|
+ </if>
|
|
|
+ <if test="receivableQueryVo.queryType!= null and receivableQueryVo.queryType == 2">
|
|
|
+ AND ipi.other_settlement = 1
|
|
|
+ </if>
|
|
|
+ <if test="receivableQueryVo.queryType!= null and (receivableQueryVo.queryType == 3 or receivableQueryVo.queryType == 4)">
|
|
|
+ AND ipi.jy_premium != 0
|
|
|
+ </if>
|
|
|
<if test="receivableQueryVo.licenseNo != null and receivableQueryVo.licenseNo != ''">
|
|
|
and ipi.licenseNo = #{receivableQueryVo.licenseNo}
|
|
|
</if>
|
|
|
@@ -637,11 +715,14 @@
|
|
|
</foreach>
|
|
|
</if>
|
|
|
<if test="settlementQueryVo.invoiceTypes != null and settlementQueryVo.invoiceTypes != ''">
|
|
|
- AND ipi.invoice_type IN
|
|
|
+ AND ipii.invoice_type IN
|
|
|
<foreach collection="settlementQueryVo.invoiceTypes" item="invoiceType" open="(" separator="," close=")">
|
|
|
#{invoiceType}
|
|
|
</foreach>
|
|
|
</if>
|
|
|
+ <if test="settlementQueryVo.agreementType != null and settlementQueryVo.agreementType != ''">
|
|
|
+ AND ipii.agreement_type = #{settlementQueryVo.agreementType}
|
|
|
+ </if>
|
|
|
</select>
|
|
|
|
|
|
<select id="getOtherSettlementDetailExcelDtos" resultType="com.jzg.commons.entity.finance.dto.ExportOtherSettlementDetailExcelDto">
|
|
|
@@ -683,7 +764,7 @@
|
|
|
</foreach>
|
|
|
</if>
|
|
|
<if test="settlementQueryVo.invoiceTypes != null and settlementQueryVo.invoiceTypes != ''">
|
|
|
- AND ipi.invoice_type IN
|
|
|
+ AND ipii.invoice_type IN
|
|
|
<foreach collection="settlementQueryVo.invoiceTypes" item="invoiceType" open="(" separator="," close=")">
|
|
|
#{invoiceType}
|
|
|
</foreach>
|
|
|
@@ -701,7 +782,10 @@
|
|
|
AND ipiis.create_by = #{settlementQueryVo.settlementPerson}
|
|
|
</if>
|
|
|
<if test="settlementQueryVo.settlementTimeStart != null and settlementQueryVo.settlementTimeStart != ''">
|
|
|
- AND ipiis.create_time between #{receivableQueryVo.signingTimeStart} and #{receivableQueryVo.signingTimeEnd}
|
|
|
+ AND ipiis.create_time between #{settlementQueryVo.signingTimeStart} and #{settlementQueryVo.signingTimeEnd}
|
|
|
+ </if>
|
|
|
+ <if test="settlementQueryVo.agreementType != null and settlementQueryVo.agreementType != ''">
|
|
|
+ AND ipi.agreement_type = #{settlementQueryVo.agreementType}
|
|
|
</if>
|
|
|
</select>
|
|
|
|
|
|
@@ -741,7 +825,7 @@
|
|
|
</foreach>
|
|
|
</if>
|
|
|
<if test="settlementQueryVo.invoiceTypes != null and settlementQueryVo.invoiceTypes != ''">
|
|
|
- AND ipi.invoice_type IN
|
|
|
+ AND ipii.invoice_type IN
|
|
|
<foreach collection="settlementQueryVo.invoiceTypes" item="invoiceType" open="(" separator="," close=")">
|
|
|
#{invoiceType}
|
|
|
</foreach>
|
|
|
@@ -761,6 +845,9 @@
|
|
|
<if test="settlementQueryVo.settlementTimeStart != null and settlementQueryVo.settlementTimeStart != ''">
|
|
|
AND ipiis.create_time between #{settlementQueryVo.signingTimeStart} and #{settlementQueryVo.signingTimeEnd}
|
|
|
</if>
|
|
|
+ <if test="settlementQueryVo.agreementType != null and settlementQueryVo.agreementType != ''">
|
|
|
+ AND ipi.agreement_type = #{settlementQueryVo.agreementType}
|
|
|
+ </if>
|
|
|
</select>
|
|
|
|
|
|
<select id="getReceivableCompany" resultType="com.jzg.commons.entity.po.EsmInsCompany">
|
|
|
@@ -850,7 +937,9 @@
|
|
|
<result column="company_id" property="companyId"/>
|
|
|
<result column="company_name" property="companyName"/>
|
|
|
<result column="total_receivable" property="totalReceivable"/>
|
|
|
+ <result column="total_follow_fee" property="totalFollowFee"/>
|
|
|
<result column="supervise_fee" property="superviseFee"/>
|
|
|
+ <result column="follow_fee" property="followFee"/>
|
|
|
<result column="invoiced_amount" property="invoicedAmount"/>
|
|
|
<result column="settled_amount" property="settledAmount"/>
|
|
|
<result column="un_invoiced_amount" property="unInvoicedAmount"/>
|
|
|
@@ -864,14 +953,14 @@
|
|
|
eic.name as company_name,
|
|
|
COALESCE(SUM(ipi.jq_receivable_premium + ipi.sy_receivable_premium + ipi.jy_receivable_premium), 0) as total_receivable,
|
|
|
COALESCE(SUM(ipi.jq_supervise_costs_premiums + ipi.sy_supervise_costs_premiums + ipi.jy_supervise_costs_premiums), 0) as supervise_fee,
|
|
|
--- COALESCE(SUM(fee_summary.total_commission), 0) as 佣金总和,
|
|
|
+ COALESCE(SUM(ipi.jq_other_costs_premiums + ipi.sy_other_costs_premiums + ipi.jy_other_costs_premiums), 0) as follow_fee,
|
|
|
COALESCE(SUM(invoice_summary.total_invoice), 0) as invoiced_amount,
|
|
|
--- COALESCE(SUM(fee_summary.total_commission) - SUM(invoice_summary.total_invoice), 0) as un_invoiced_amount,
|
|
|
+ COALESCE(SUM(fee_summary.total_commission) - SUM(invoice_summary.total_invoice), 0) as un_invoiced_amount,
|
|
|
COALESCE(SUM(invoice_summary.settled_invoice), 0) as settled_amount,
|
|
|
COALESCE(SUM(invoice_summary.unsettled_invoice), 0) as un_settled_amount
|
|
|
FROM
|
|
|
esm_ins_company eic
|
|
|
- LEFT JOIN ins_ply_income ipi ON eic.id = ipi.company_id
|
|
|
+ LEFT JOIN ins_ply_income ipi ON eic.id = ipi.company_id and ipi.agreement_type = #{settlementReportQueryVo.agreementType}
|
|
|
LEFT JOIN (
|
|
|
SELECT
|
|
|
ipiil.income_id,
|
|
|
@@ -881,23 +970,29 @@
|
|
|
FROM ins_ply_income_invoice_link ipiil
|
|
|
LEFT JOIN ins_ply_income_invoice ipii
|
|
|
ON ipii.id = ipiil.invoice_id
|
|
|
- AND ipii.invoice_type IN
|
|
|
+ <where>
|
|
|
<if test="settlementReportQueryVo.invoiceTypes != null and settlementReportQueryVo.invoiceTypes.size() > 0">
|
|
|
- <foreach item="item" collection="settlementReportQueryVo.invoiceTypes" separator="," open="(" close=")" index="">
|
|
|
- #{item}
|
|
|
- </foreach>
|
|
|
+ AND ipii.invoice_type IN
|
|
|
+ <foreach item="item" collection="settlementReportQueryVo.invoiceTypes" separator="," open="(" close=")">
|
|
|
+ #{item}
|
|
|
+ </foreach>
|
|
|
+ </if>
|
|
|
+ <if test="settlementReportQueryVo.status != null and settlementReportQueryVo.status != ''">
|
|
|
+ and ipii.status = #{settlementReportQueryVo.status}
|
|
|
</if>
|
|
|
+ </where>
|
|
|
GROUP BY ipiil.income_id
|
|
|
) invoice_summary ON invoice_summary.income_id = ipi.id
|
|
|
--- LEFT JOIN (
|
|
|
--- SELECT
|
|
|
--- ifo.order_no,
|
|
|
--- SUM(DISTINCT (ifo.jq_commission_premium + ifo.sy_commission_premium + ifo.jy_commission_premium)) as total_commission
|
|
|
--- FROM ins_fee_orders ifo
|
|
|
--- GROUP BY ifo.order_no
|
|
|
--- ) fee_summary ON ipi.order_no = fee_summary.order_no
|
|
|
WHERE
|
|
|
- eic.parent_id = 0
|
|
|
+ eic.parent_id = 0
|
|
|
+ <if test="settlementReportQueryVo.companyId != null and settlementReportQueryVo.companyId != ''">
|
|
|
+ and eic.id = #{settlementReportQueryVo.companyId}
|
|
|
+ </if>
|
|
|
+ <if test="settlementReportQueryVo.startTime != null and settlementReportQueryVo.startTime != ''">
|
|
|
+ AND ipi.signing_time BETWEEN #{settlementReportQueryVo.startTime} AND #{settlementReportQueryVo.endTime}
|
|
|
+ AND (invoice_summary.invoiceTime BETWEEN #{settlementReportQueryVo.startTime} AND #{settlementReportQueryVo.endTime}
|
|
|
+ OR invoice_summary.invoiceTime IS NULL)
|
|
|
+ </if>
|
|
|
GROUP BY
|
|
|
eic.id,
|
|
|
eic.name;
|
|
|
@@ -911,12 +1006,11 @@
|
|
|
COALESCE(SUM(ipi.jq_receivable_premium + ipi.sy_receivable_premium + ipi.jy_receivable_premium), 0) as total_receivable,
|
|
|
COALESCE(SUM(ipi.jq_supervise_costs_premiums + ipi.sy_supervise_costs_premiums + ipi.jy_supervise_costs_premiums), 0) as supervise_fee,
|
|
|
COALESCE(SUM(invoice_summary.total_invoice), 0) as invoiced_amount,
|
|
|
--- COALESCE(SUM(fee_summary.total_commission) - SUM(invoice_summary.total_invoice), 0) as un_invoiced_amount,
|
|
|
COALESCE(SUM(invoice_summary.settled_invoice), 0) as settled_amount,
|
|
|
COALESCE(SUM(invoice_summary.unsettled_invoice), 0) as un_settled_amount
|
|
|
FROM
|
|
|
esm_ins_company eic
|
|
|
- LEFT JOIN ins_ply_income ipi ON eic.id = ipi.company_id
|
|
|
+ LEFT JOIN ins_ply_income ipi ON eic.id = ipi.company_id and ipi.agreement_type = #{settlementReportQueryVo.agreementType}
|
|
|
LEFT JOIN (
|
|
|
SELECT
|
|
|
ipiil.income_id,
|
|
|
@@ -924,25 +1018,34 @@
|
|
|
SUM(CASE WHEN ipii.status = 1 THEN ipii.receivable_supervise_premium ELSE 0 END) as settled_invoice,
|
|
|
SUM(CASE WHEN ipii.status = 0 THEN ipii.receivable_supervise_premium ELSE 0 END) as unsettled_invoice
|
|
|
FROM ins_ply_income_invoice_link ipiil
|
|
|
- LEFT JOIN ins_ply_income_invoice ipii
|
|
|
- ON ipii.id = ipiil.invoice_id
|
|
|
- AND ipii.invoice_type IN
|
|
|
- <if test="invoiceTypes != null and !invoiceTypes.isEmpty()">
|
|
|
- <foreach item="item" collection="invoiceTypes" open="(" separator="," close=")">
|
|
|
- #{item}
|
|
|
- </foreach>
|
|
|
- </if>
|
|
|
+ LEFT JOIN ins_ply_income_invoice ipii
|
|
|
+ ON ipii.id = ipiil.invoice_id
|
|
|
+ <where>
|
|
|
+ <if test="settlementReportQueryVo.invoiceTypes != null and settlementReportQueryVo.invoiceTypes.size() > 0">
|
|
|
+ AND ipii.invoice_type IN
|
|
|
+ <foreach item="item" collection="settlementReportQueryVo.invoiceTypes" separator="," open="(" close=")">
|
|
|
+ #{item}
|
|
|
+ </foreach>
|
|
|
+ </if>
|
|
|
+ <if test="settlementReportQueryVo.status != null and settlementReportQueryVo.status != ''">
|
|
|
+ and ipii.status = #{settlementReportQueryVo.status}
|
|
|
+ </if>
|
|
|
+ </where>
|
|
|
GROUP BY ipiil.income_id
|
|
|
) invoice_summary ON invoice_summary.income_id = ipi.id
|
|
|
--- LEFT JOIN (
|
|
|
--- SELECT
|
|
|
--- ifo.order_no,
|
|
|
--- SUM(DISTINCT (ifo.jq_commission_premium + ifo.sy_commission_premium + ifo.jy_commission_premium)) as total_commission
|
|
|
--- FROM ins_fee_orders ifo
|
|
|
--- GROUP BY ifo.order_no
|
|
|
--- ) fee_summary ON ipi.order_no = fee_summary.order_no
|
|
|
WHERE
|
|
|
eic.parent_id = #{parentId}
|
|
|
+ <if test="settlementReportQueryVo.companyId != null and settlementReportQueryVo.companyId != ''">
|
|
|
+ and eic.id = #{settlementReportQueryVo.companyId}
|
|
|
+ </if>
|
|
|
+ <if test="settlementReportQueryVo.startTime != null and settlementReportQueryVo.startTime != ''">
|
|
|
+ AND ipi.signing_time BETWEEN #{settlementReportQueryVo.startTime} AND #{settlementReportQueryVo.endTime}
|
|
|
+ AND (invoice_summary.invoiceTime BETWEEN #{settlementReportQueryVo.startTime} AND #{settlementReportQueryVo.endTime}
|
|
|
+ OR invoice_summary.invoiceTime IS NULL)
|
|
|
+ </if>
|
|
|
+ <if test="settlementReportQueryVo.status != null and settlementReportQueryVo.status != ''">
|
|
|
+ AND ipi.status = #{settlementReportQueryVo.status}
|
|
|
+ </if>
|
|
|
GROUP BY
|
|
|
eic.id,
|
|
|
eic.name;
|
|
|
@@ -966,4 +1069,46 @@
|
|
|
eic.id;
|
|
|
</select>
|
|
|
|
|
|
+ <select id="getReceiverSettlementReport" resultType="com.jzg.commons.entity.finance.dto.ReceiverSettlementReportDto">
|
|
|
+ SELECT
|
|
|
+ ipi.contact_person AS receiver,
|
|
|
+ ipi.company_name AS companyName,
|
|
|
+ -- 原有的应收费用合计
|
|
|
+ SUM(ipi.jq_supervise_costs_premiums + ipi.sy_supervise_costs_premiums + ipi.jy_supervise_costs_premiums) AS superviseFee,
|
|
|
+ SUM(ipi.jq_other_costs_premiums + ipi.sy_other_costs_premiums + ipi.jy_other_costs_premiums) AS followFee,
|
|
|
+ SUM(
|
|
|
+ (ipi.jq_supervise_costs_premiums + ipi.sy_supervise_costs_premiums + ipi.jy_supervise_costs_premiums) +
|
|
|
+ (ipi.jq_other_costs_premiums + ipi.sy_other_costs_premiums + ipi.jy_other_costs_premiums)
|
|
|
+ ) AS totalReceivable,
|
|
|
+ -- 已结算费用统计
|
|
|
+ SUM(CASE WHEN ipii.`status` = 1 AND ipii.invoice_type in (1,3) THEN ipii.receivable_supervise_premium ELSE 0 END) AS settledSuperviseFee,
|
|
|
+ SUM(CASE WHEN ipii.`status` = 1 AND ipii.invoice_type in (2,4) THEN ipii.receivable_supervise_premium ELSE 0 END) AS settledFollowFee,
|
|
|
+ SUM(CASE WHEN ipii.`status` = 1 AND ipii.invoice_type IN (1,2) THEN ipii.receivable_supervise_premium ELSE 0 END) AS settledAmount,
|
|
|
+ -- 未结算费用统计
|
|
|
+ SUM(CASE WHEN ipii.`status` = 0 AND ipii.invoice_type in (1,3) THEN ipii.receivable_supervise_premium ELSE 0 END) AS unSettledSuperviseFee,
|
|
|
+ SUM(CASE WHEN ipii.`status` = 0 AND ipii.invoice_type in (2,4) THEN ipii.receivable_supervise_premium ELSE 0 END) AS unSettledFollowFee,
|
|
|
+ SUM(CASE WHEN ipii.`status` = 0 AND ipii.invoice_type IN (1,2) THEN ipii.receivable_supervise_premium ELSE 0 END) AS unSettledAmount
|
|
|
+ FROM
|
|
|
+ ins_ply_income ipi
|
|
|
+ LEFT JOIN ins_ply_income_invoice_link ipil
|
|
|
+ ON ipi.id = ipil.income_id
|
|
|
+ LEFT JOIN ins_ply_income_invoice ipii
|
|
|
+ ON ipil.invoice_id = ipii.id
|
|
|
+ where ipi.agreement_type = '1'
|
|
|
+ <if test="settlementReportQueryVo.companyId != null and settlementReportQueryVo.companyId != ''">
|
|
|
+ and ipi.company_id = #{settlementReportQueryVo.companyId}
|
|
|
+ </if>
|
|
|
+ <if test="settlementReportQueryVo.receiver != null and settlementReportQueryVo.receiver != ''">
|
|
|
+ and ipi.contact_person = #{settlementReportQueryVo.receiver}
|
|
|
+ </if>
|
|
|
+ <if test="settlementReportQueryVo.startTime != null and settlementReportQueryVo.startTime != ''">
|
|
|
+ and ipi.signing_time BETWEEN #{settlementReportQueryVo.startTime} AND #{settlementReportQueryVo.endTime}
|
|
|
+ and (ipii.invoice_time BETWEEN #{settlementReportQueryVo.startTime} AND #{settlementReportQueryVo.endTime}
|
|
|
+ OR ipii.invoice_time IS NULL)
|
|
|
+ </if>
|
|
|
+ GROUP BY
|
|
|
+ ipi.contact_person,
|
|
|
+ ipi.company_name
|
|
|
+ </select>
|
|
|
+
|
|
|
</mapper>
|