Merge branch 'test' into feauture-20261104
# Conflicts: # bms-back/bms-system/src/main/java/com/bms/price/service/impl/PrcProfitReportServiceImpl.java
This commit is contained in:
@@ -11,7 +11,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="customerCodeDw" column="customer_code_dw" />
|
||||
<result property="creditCode" column="credit_code" />
|
||||
<result property="customerType" column="customer_type" />
|
||||
<result property="areaType" column="area_type" />
|
||||
<result property="customerArea" column="customer_area" />
|
||||
<result property="isEnable" column="is_enable" />
|
||||
<result property="salesUserId" column="sales_user_id" />
|
||||
<result property="salesUser" column="sales_user" />
|
||||
@@ -45,7 +45,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<!-- 账户余额/外币余额统一取 ctr_customer_account 余额表(CNY 为本币,其余为外币),不取 ctr_customer 冗余列 -->
|
||||
<!-- 信用额度=总额度+额外额度-已用额度-->
|
||||
<sql id="selectBmsCustomerVo">
|
||||
select c.customer_id, c.customer_code, c.customer_name, c.customer_code_dw, c.credit_code, c.customer_type, c.area_type,
|
||||
select c.customer_id, c.customer_code, c.customer_name, c.customer_code_dw, c.credit_code, c.customer_type, c.customer_area,
|
||||
c.is_enable,
|
||||
case when su.user_id is not null then cast(su.user_id as char) else null end as sales_user_id,
|
||||
su.nick_name as sales_user, c.ed, c.zq, c.settlement_user_id, c.settlement_user,
|
||||
@@ -92,7 +92,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</if>
|
||||
<if test="creditCode != null and creditCode != ''"> and c.credit_code = #{creditCode}</if>
|
||||
<if test="customerType != null and customerType != ''"> and c.customer_type = #{customerType}</if>
|
||||
<if test="areaType != null and areaType != ''"> and c.area_type = #{areaType}</if>
|
||||
<if test="customerArea != null and customerArea != ''"> and c.customer_area = #{customerArea}</if>
|
||||
<if test="isEnable != null and isEnable != ''"> and c.is_enable = #{isEnable}</if>
|
||||
<if test="salesUserId != null and salesUserId != ''"> and c.sales_user_id = #{salesUserId}</if>
|
||||
<if test="salesUser != null and salesUser != ''"> and su.nick_name = #{salesUser}</if>
|
||||
@@ -317,7 +317,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="customerCodeDw != null">customer_code_dw,</if>
|
||||
<if test="creditCode != null">credit_code,</if>
|
||||
<if test="customerType != null">customer_type,</if>
|
||||
<if test="areaType != null">area_type,</if>
|
||||
<if test="customerArea != null">customer_area,</if>
|
||||
<if test="isEnable != null">is_enable,</if>
|
||||
<if test="salesUserId != null">sales_user_id,</if>
|
||||
<if test="salesUser != null">sales_user,</if>
|
||||
@@ -350,7 +350,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="customerCodeDw != null">#{customerCodeDw},</if>
|
||||
<if test="creditCode != null">#{creditCode},</if>
|
||||
<if test="customerType != null">#{customerType},</if>
|
||||
<if test="areaType != null">#{areaType},</if>
|
||||
<if test="customerArea != null">#{customerArea},</if>
|
||||
<if test="isEnable != null">#{isEnable},</if>
|
||||
<if test="salesUserId != null">#{salesUserId},</if>
|
||||
<if test="salesUser != null">#{salesUser},</if>
|
||||
@@ -387,7 +387,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="customerCodeDw != null">customer_code_dw = #{customerCodeDw},</if>
|
||||
<if test="creditCode != null">credit_code = #{creditCode},</if>
|
||||
<if test="customerType != null">customer_type = #{customerType},</if>
|
||||
area_type = #{areaType},
|
||||
customer_area = #{customerArea},
|
||||
<if test="isEnable != null">is_enable = #{isEnable},</if>
|
||||
sales_user_id = #{salesUserId},
|
||||
sales_user = #{salesUser},
|
||||
|
||||
@@ -30,6 +30,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
del_flag, create_by, sales_user_id, source_sales_code
|
||||
<if test="customerCodeDw != null">, customer_code_dw</if>
|
||||
<if test="customerType != null">, customer_type</if>
|
||||
<if test="customerArea != null">, customer_area</if>
|
||||
<if test="salesUser != null">, sales_user</if>
|
||||
<if test="settlementUser != null">, settlement_user</if>
|
||||
<if test="serviceUser != null">, service_user</if>
|
||||
@@ -46,6 +47,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
'0', #{createBy}, #{salesUserId}, #{sourceSalesCode}
|
||||
<if test="customerCodeDw != null">, #{customerCodeDw}</if>
|
||||
<if test="customerType != null">, #{customerType}</if>
|
||||
<if test="customerArea != null">, #{customerArea}</if>
|
||||
<if test="salesUser != null">, #{salesUser}</if>
|
||||
<if test="settlementUser != null">, #{settlementUser}</if>
|
||||
<if test="serviceUser != null">, #{serviceUser}</if>
|
||||
@@ -66,6 +68,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="customerName != null">, customer_name = #{customerName}</if>
|
||||
<if test="customerCodeDw != null">, customer_code_dw = #{customerCodeDw}</if>
|
||||
<if test="customerType != null">, customer_type = #{customerType}</if>
|
||||
<if test="customerArea != null">, customer_area = #{customerArea}</if>
|
||||
, sales_user_id = #{salesUserId}
|
||||
, source_sales_code = #{sourceSalesCode}
|
||||
<if test="salesUser != null">, sales_user = #{salesUser}</if>
|
||||
|
||||
@@ -10,7 +10,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
BELONG_SALER, BELONG_SALER_NAME, SETTLEMENT_MAN, SERVICE_MAN,
|
||||
REMARK, WEIGHT_LIMIT, CREDIT_LIMIT, TEMP_AMOUNT,
|
||||
ACCOUNT_AMOUNT, EUR_AMOUNT,
|
||||
CUSTOMER_TYPE, CUSTOMER_BALANCE_MODE, BL_OPEN,
|
||||
CUSTOMER_TYPE, CUSTOMER_AREA, CUSTOMER_BALANCE_MODE, BL_OPEN,
|
||||
CREATE_DATE, GMT_CREATE
|
||||
FROM WEISHI_USER.TAB_CUSTOMER
|
||||
</select>
|
||||
|
||||
@@ -66,7 +66,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="query.endTime != null and query.endTime != ''">
|
||||
AND o.PICKUP_DATE <= TO_DATE(#{query.endTime}, 'YYYY-MM-DD HH24:MI:SS')
|
||||
</if>
|
||||
AND o.BL_PICKUP = 1
|
||||
<choose>
|
||||
<when test="query.blPickup != null">
|
||||
AND o.BL_PICKUP = #{query.blPickup}
|
||||
</when>
|
||||
<!-- <otherwise>-->
|
||||
<!-- AND o.BL_PICKUP = 1-->
|
||||
<!-- </otherwise>-->
|
||||
</choose>
|
||||
<if test="query.orderStatuses != null and query.orderStatuses.size() > 0">
|
||||
AND o.ORDER_STATUS IN
|
||||
<foreach collection="query.orderStatuses" item="st" open="(" separator="," close=")">
|
||||
@@ -123,8 +130,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
o.TRACK_ID,
|
||||
o.CUSTOMER_CODE,
|
||||
o.CUSTOMER_NAME,
|
||||
o.PRODUCT_CODE,
|
||||
o.PRODUCT_NAME,
|
||||
<!-- List "产品" shows LINE_* (same as billing match), not PRODUCT_* floor name. -->
|
||||
o.LINE_CODE AS PRODUCT_CODE,
|
||||
o.LINE_NAME AS PRODUCT_NAME,
|
||||
o.PRODUCT_FLOOR_CODE,
|
||||
o.COUNTRY,
|
||||
o.COUNTRY_NAME,
|
||||
@@ -273,7 +281,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<foreach collection="batch" item="bid" open="(" separator="," close=")">
|
||||
#{bid}
|
||||
</foreach>
|
||||
AND o.BL_PICKUP = 1
|
||||
<choose>
|
||||
<when test="blPickup != null">
|
||||
AND o.BL_PICKUP = #{blPickup}
|
||||
</when>
|
||||
<!-- <otherwise>-->
|
||||
<!-- AND o.BL_PICKUP = 1-->
|
||||
<!-- </otherwise>-->
|
||||
</choose>
|
||||
AND o.ORDER_STATUS IN (3, 4, 5, 6, 7, 8, 11)
|
||||
<if test="customerCodes != null and customerCodes.size() > 0">
|
||||
AND o.CUSTOMER_CODE IN
|
||||
|
||||
@@ -519,6 +519,37 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
limit 1
|
||||
</select>
|
||||
|
||||
<!-- Gap between bands (e.g. 1.001 between 0-1 and 1.01-2): next higher weight_min. -->
|
||||
<select id="selectFixedNextBandUp" resultMap="PrcPriceSetDetailResult">
|
||||
<include refid="selectPrcPriceSetDetailVo"/>
|
||||
where psv_id = #{psvId}
|
||||
and ifnull(is_del, '0') = '0'
|
||||
and product_code = #{productCode}
|
||||
and weight_min is not null
|
||||
and weight_min > #{weight}
|
||||
<choose>
|
||||
<when test="countryCode != null and countryCode != ''">
|
||||
and upper(ifnull(country_code,'')) = upper(#{countryCode})
|
||||
</when>
|
||||
<when test="countryName != null and countryName != ''">
|
||||
and country_name = #{countryName}
|
||||
</when>
|
||||
<otherwise>
|
||||
and 1 = 0
|
||||
</otherwise>
|
||||
</choose>
|
||||
<choose>
|
||||
<when test="zoneCode != null and zoneCode != ''">
|
||||
and upper(ifnull(zone_code,'')) = upper(#{zoneCode})
|
||||
</when>
|
||||
<otherwise>
|
||||
and (zone_code is null or zone_code = '')
|
||||
</otherwise>
|
||||
</choose>
|
||||
order by weight_min asc, psd_id asc
|
||||
limit 1
|
||||
</select>
|
||||
|
||||
<select id="countZonedByPsvProductCountry" resultType="int">
|
||||
select count(1)
|
||||
from prc_price_set_detail
|
||||
|
||||
@@ -10,6 +10,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="priceSetName" column="price_set_name" />
|
||||
<result property="priceSetNote" column="price_set_note" />
|
||||
<result property="setType" column="set_type" />
|
||||
<result property="setCategory" column="set_category" />
|
||||
<result property="defaultDiscount" column="default_discount" />
|
||||
<result property="defaultType" column="default_type" />
|
||||
<result property="calculateSign" column="calculate_sign" />
|
||||
@@ -26,7 +27,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
|
||||
<sql id="selectPrcPriceSetVo">
|
||||
select s.price_set_id, s.price_set_code, s.price_set_name, s.price_set_note,
|
||||
s.set_type, s.default_discount, s.default_type, s.calculate_sign,
|
||||
s.set_type, ifnull(s.set_category, 'PACKAGE') as set_category,
|
||||
s.default_discount, s.default_type, s.calculate_sign,
|
||||
s.status, s.tms_id,
|
||||
s.created_by, s.create_time, s.updated_by, s.update_time,
|
||||
(select count(distinct p.product_code)
|
||||
@@ -52,7 +54,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
|
||||
<select id="selectPrcPriceSetHeaderById" parameterType="Long" resultMap="PrcPriceSetResult">
|
||||
select s.price_set_id, s.price_set_code, s.price_set_name, s.price_set_note,
|
||||
s.set_type, s.default_discount, s.default_type, s.calculate_sign,
|
||||
s.set_type, ifnull(s.set_category, 'PACKAGE') as set_category,
|
||||
s.default_discount, s.default_type, s.calculate_sign,
|
||||
s.status, s.tms_id,
|
||||
s.created_by, s.create_time, s.updated_by, s.update_time,
|
||||
null as product_count, null as customer_count, null as bound_customers
|
||||
@@ -66,6 +69,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="setType != null and setType != ''">
|
||||
AND s.set_type = #{setType}
|
||||
</if>
|
||||
<if test="setCategory != null and setCategory != ''">
|
||||
AND ifnull(s.set_category, 'PACKAGE') = #{setCategory}
|
||||
</if>
|
||||
<if test="status != null and status != ''">
|
||||
AND s.status = #{status}
|
||||
</if>
|
||||
@@ -126,6 +132,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="tmsId != null">
|
||||
AND tms_id = #{tmsId}
|
||||
</if>
|
||||
<if test="setCategory != null and setCategory != ''">
|
||||
AND ifnull(set_category, 'PACKAGE') = #{setCategory}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<insert id="insertPrcPriceSet" parameterType="PrcPriceSet" useGeneratedKeys="true" keyProperty="priceSetId">
|
||||
@@ -134,6 +143,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="priceSetName != null and priceSetName != ''">price_set_name,</if>
|
||||
<if test="priceSetNote != null">price_set_note,</if>
|
||||
<if test="setType != null and setType != ''">set_type,</if>
|
||||
<if test="setCategory != null and setCategory != ''">set_category,</if>
|
||||
<if test="defaultDiscount != null">default_discount,</if>
|
||||
<if test="defaultType != null">default_type,</if>
|
||||
<if test="calculateSign != null">calculate_sign,</if>
|
||||
@@ -146,6 +156,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="priceSetName != null and priceSetName != ''">#{priceSetName},</if>
|
||||
<if test="priceSetNote != null">#{priceSetNote},</if>
|
||||
<if test="setType != null and setType != ''">#{setType},</if>
|
||||
<if test="setCategory != null and setCategory != ''">#{setCategory},</if>
|
||||
<if test="defaultDiscount != null">#{defaultDiscount},</if>
|
||||
<if test="defaultType != null">#{defaultType},</if>
|
||||
<if test="calculateSign != null">#{calculateSign},</if>
|
||||
@@ -163,6 +174,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="priceSetName != null and priceSetName != ''">price_set_name = #{priceSetName},</if>
|
||||
<if test="priceSetNote != null">price_set_note = #{priceSetNote},</if>
|
||||
<if test="setType != null and setType != ''">set_type = #{setType},</if>
|
||||
<if test="setCategory != null and setCategory != ''">set_category = #{setCategory},</if>
|
||||
default_discount = #{defaultDiscount},
|
||||
<if test="defaultType != null">default_type = #{defaultType},</if>
|
||||
<if test="calculateSign != null">calculate_sign = #{calculateSign},</if>
|
||||
|
||||
@@ -119,6 +119,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<sql id="profitReportFromAndWhere">
|
||||
from prc_income_bill i
|
||||
inner join prc_order_bill p on p.bill_id = i.bill_id
|
||||
<if test="customerArea != null and customerArea != ''">
|
||||
left join ctr_customer c on c.customer_id = p.customer_id and c.del_flag = '0'
|
||||
</if>
|
||||
<!-- 提成表关联暂停使用,毛利报表不再依赖提成配置。
|
||||
left join prc_profit_commission_rate cr
|
||||
on cr.belong_saler_code = i.belong_saler_code and cr.status = '0'
|
||||
@@ -126,6 +129,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<where>
|
||||
<!-- 不将未匹配产品、国家或重量段的计费失败订单纳入毛利报表;保留历史空值(按成功处理)。 -->
|
||||
and (p.billing_fail_status is null or p.billing_fail_status not in (1, 2, 3))
|
||||
<if test="customerArea != null and customerArea != ''">
|
||||
and c.customer_area = #{customerArea}
|
||||
</if>
|
||||
<if test="beginBizDate != null">
|
||||
and p.biz_date >= #{beginBizDate}
|
||||
</if>
|
||||
@@ -194,8 +200,25 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
<!-- 红线毛利 = 产品价 - 红线价;红线毛利率 = 红线毛利 / 红线价 * 100%。汇总先逐单计算再求和。 -->
|
||||
<!-- 广州缺少有效销售价或红线价时不计算毛利;计费失败留下的双零占位也不参与计算。 -->
|
||||
<sql id="guangzhouProfitAvailable">
|
||||
i.sales_amount is not null and i.redline_amount is not null
|
||||
and not (coalesce(p.billing_fail_status, 0) in (23, 24, 25) and i.sales_amount = 0 and i.redline_amount = 0)
|
||||
</sql>
|
||||
|
||||
<sql id="profitExpressions">
|
||||
<choose>
|
||||
<when test="profitRule == 'GUANGZHOU'">
|
||||
null as cost_amount, i.redline_amount,
|
||||
null as redline_gross_profit, null as redline_gross_margin_rate,
|
||||
i.sales_amount,
|
||||
case when <include refid="guangzhouProfitAvailable"/>
|
||||
then i.sales_amount - i.redline_amount else null end as sales_gross_profit,
|
||||
case when <include refid="guangzhouProfitAvailable"/> and i.sales_amount != 0
|
||||
then round((i.sales_amount - i.redline_amount) * 100 / i.sales_amount, 4)
|
||||
else null end as sales_gross_margin_rate
|
||||
</when>
|
||||
<otherwise>
|
||||
i.product_amount as cost_amount,
|
||||
i.redline_amount,
|
||||
case when i.product_amount is not null and i.redline_amount is not null
|
||||
@@ -207,11 +230,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
then i.sales_amount - i.product_amount else null end as sales_gross_profit,
|
||||
case when i.product_amount is not null and i.sales_amount is not null and i.sales_amount != 0
|
||||
then round((i.sales_amount - i.product_amount) * 100 / i.sales_amount, 4) else null end as sales_gross_margin_rate
|
||||
<!-- 提成比例与金额计算暂停使用;恢复时包含前置逗号。
|
||||
, cr.commission_rate,
|
||||
case when cr.commission_rate is not null and i.product_amount is not null and i.sales_amount is not null
|
||||
then round((i.sales_amount - i.product_amount) * cr.commission_rate / 100, 4) else null end as commission_amount
|
||||
-->
|
||||
</otherwise>
|
||||
</choose>
|
||||
</sql>
|
||||
|
||||
<select id="selectOrderRows" resultMap="PrcProfitReportOrderResult">
|
||||
@@ -228,9 +248,28 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
order by p.biz_date desc, p.bill_id desc
|
||||
</select>
|
||||
|
||||
<select id="selectProductRows" resultMap="PrcProfitReportProductResult">
|
||||
select p.product_code, p.product_name, p.country_code, p.country_name,
|
||||
i.currency, count(*) as order_count,
|
||||
<!-- 汇总和产品维度使用同一套逐单有效数据计算,毛利率按有效销售额加权。 -->
|
||||
<sql id="profitAggregateExpressions">
|
||||
<choose>
|
||||
<when test="profitRule == 'GUANGZHOU'">
|
||||
null as cost_amount,
|
||||
sum(i.redline_amount) as redline_amount,
|
||||
null as redline_gross_profit, null as redline_gross_margin_rate,
|
||||
sum(i.sales_amount) as sales_amount,
|
||||
sum(case when <include refid="guangzhouProfitAvailable"/>
|
||||
then i.sales_amount - i.redline_amount else null end) as sales_gross_profit,
|
||||
case when sum(case when <include refid="guangzhouProfitAvailable"/>
|
||||
then i.sales_amount else null end) is null
|
||||
or sum(case when <include refid="guangzhouProfitAvailable"/>
|
||||
then i.sales_amount else null end) = 0
|
||||
then null
|
||||
else round(sum(case when <include refid="guangzhouProfitAvailable"/>
|
||||
then i.sales_amount - i.redline_amount else null end) * 100 /
|
||||
sum(case when <include refid="guangzhouProfitAvailable"/>
|
||||
then i.sales_amount else null end), 4)
|
||||
end as sales_gross_margin_rate
|
||||
</when>
|
||||
<otherwise>
|
||||
sum(i.product_amount) as cost_amount,
|
||||
sum(i.redline_amount) as redline_amount,
|
||||
sum(case when i.product_amount is not null and i.redline_amount is not null
|
||||
@@ -260,12 +299,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
sum(case when i.product_amount is not null and i.sales_amount is not null
|
||||
then i.sales_amount else null end), 4)
|
||||
end as sales_gross_margin_rate
|
||||
<!-- 提成金额与未计算订单数暂停使用。
|
||||
sum(case when cr.commission_rate is not null and i.product_amount is not null and i.sales_amount is not null
|
||||
then (i.sales_amount - i.product_amount) * cr.commission_rate / 100 else null end) as commission_amount,
|
||||
sum(case when cr.commission_rate is null or i.product_amount is null or i.sales_amount is null
|
||||
then 1 else 0 end) as commission_missing_order_count,
|
||||
-->
|
||||
</otherwise>
|
||||
</choose>
|
||||
</sql>
|
||||
|
||||
<select id="selectProductRows" resultMap="PrcProfitReportProductResult">
|
||||
select p.product_code, p.product_name, p.country_code, p.country_name,
|
||||
i.currency, count(*) as order_count,
|
||||
<include refid="profitAggregateExpressions"/>
|
||||
<include refid="profitReportFromAndWhere"/>
|
||||
group by p.product_code, p.product_name, p.country_code, p.country_name, i.currency
|
||||
order by p.product_code, p.country_code, i.currency
|
||||
@@ -273,41 +314,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
|
||||
<select id="selectSummary" resultMap="PrcProfitReportSummaryResult">
|
||||
select i.currency, count(*) as order_count,
|
||||
sum(i.product_amount) as cost_amount,
|
||||
sum(i.redline_amount) as redline_amount,
|
||||
sum(case when i.product_amount is not null and i.redline_amount is not null
|
||||
then i.product_amount - i.redline_amount else null end) as redline_gross_profit,
|
||||
case when sum(case when i.product_amount is not null and i.redline_amount is not null
|
||||
then i.redline_amount else null end) is null
|
||||
or sum(case when i.product_amount is not null and i.redline_amount is not null
|
||||
then i.redline_amount else null end) = 0
|
||||
then null
|
||||
else round(
|
||||
sum(case when i.product_amount is not null and i.redline_amount is not null
|
||||
then i.product_amount - i.redline_amount else null end) * 100 /
|
||||
sum(case when i.product_amount is not null and i.redline_amount is not null
|
||||
then i.redline_amount else null end), 4)
|
||||
end as redline_gross_margin_rate,
|
||||
sum(i.sales_amount) as sales_amount,
|
||||
sum(case when i.product_amount is not null and i.sales_amount is not null
|
||||
then i.sales_amount - i.product_amount else null end) as sales_gross_profit,
|
||||
case when sum(case when i.product_amount is not null and i.sales_amount is not null
|
||||
then i.sales_amount else null end) is null
|
||||
or sum(case when i.product_amount is not null and i.sales_amount is not null
|
||||
then i.sales_amount else null end) = 0
|
||||
then null
|
||||
else round(
|
||||
sum(case when i.product_amount is not null and i.sales_amount is not null
|
||||
then i.sales_amount - i.product_amount else null end) * 100 /
|
||||
sum(case when i.product_amount is not null and i.sales_amount is not null
|
||||
then i.sales_amount else null end), 4)
|
||||
end as sales_gross_margin_rate
|
||||
<!-- 提成汇总计算暂停使用;恢复时包含前置逗号。
|
||||
, sum(case when cr.commission_rate is not null and i.product_amount is not null and i.sales_amount is not null
|
||||
then (i.sales_amount - i.product_amount) * cr.commission_rate / 100 else null end) as commission_amount,
|
||||
sum(case when cr.commission_rate is null or i.product_amount is null or i.sales_amount is null
|
||||
then 1 else 0 end) as commission_missing_order_count
|
||||
-->
|
||||
<include refid="profitAggregateExpressions"/>
|
||||
<include refid="profitReportFromAndWhere"/>
|
||||
<if test="arBillStatus != null and arBillStatus != ''">
|
||||
and p.ar_bill_status = #{arBillStatus}
|
||||
|
||||
Reference in New Issue
Block a user