|
|
@@ -1540,7 +1540,10 @@
|
|
|
tmc.cus_id AS "cusId",
|
|
|
tmc.cus_code AS "cusCode",
|
|
|
tmc.cus_name AS "cusName",
|
|
|
- tmc.cus_phone AS "cusPhone"
|
|
|
+ tmc.cus_phone AS "cusPhone",
|
|
|
+ tmgs.sku_spec as "skuSpec",
|
|
|
+ concat ( sys.f_remove_zero ( T.item_qty ), tmgu.unit_name ) AS "itemQtyPiece",
|
|
|
+ dkic_b.f_box_piece ( tmgus.unit_name, tmgu.unit_name, T.BOX, T.piece ) AS "boxPiece"
|
|
|
FROM dkic_b.t_psi_order_item as t
|
|
|
inner join dkic_b.t_psi_order tpo on tpo.order_id = t.order_id
|
|
|
inner join dkic_b.t_mst_goods_sku tmgs on t.sku_id = tmgs.sku_id
|
|
|
@@ -1548,8 +1551,10 @@
|
|
|
left join dkic_b.t_mst_customer tmc on tmc.cus_id = tpo.cus_id
|
|
|
LEFT JOIN dkic_b.t_mst_goods_brand tmgb ON tmgb.brand_id = tmgs.brand_id
|
|
|
left join sys.t_data_kind as tdk3 on tpo.out_status = tdk3.kind_code
|
|
|
+ LEFT JOIN dkic_b.t_mst_unit AS tmgu ON tmgs.unit_id = tmgu.unit_id
|
|
|
+ LEFT JOIN dkic_b.t_mst_unit AS tmgus ON tmgs.sub_unit_id = tmgus.unit_id
|
|
|
<include refid="ConditionSaleItem"/>
|
|
|
- order by t.item_index
|
|
|
+ order by tpo.make_time,t.item_index
|
|
|
<if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
|
|
|
limit #{end} offset #{start}
|
|
|
</if>
|
|
|
@@ -1617,12 +1622,45 @@
|
|
|
<if test="cpId != null">
|
|
|
AND t.cp_id = #{cpId}
|
|
|
</if>
|
|
|
+ <if test="makeTimeStart != null and makeTimeEnd != null">
|
|
|
+ AND tpo.make_time >= #{makeTimeStart}::timestamp with time zone
|
|
|
+ AND tpo.make_time < #{makeTimeEnd}::timestamp with time zone + interval '1 day'
|
|
|
+ </if>
|
|
|
+ <if test="skuName != null and skuName != ''">
|
|
|
+ AND tmgs.sku_name like concat('%', my_ex.likequery(#{skuName}) , '%')
|
|
|
+ </if>
|
|
|
+ <if test="skuModel != null and skuModel != ''">
|
|
|
+ AND tmgs.sku_model like concat('%', my_ex.likequery(#{skuModel}) , '%')
|
|
|
+ </if>
|
|
|
+ <if test="brandName != null and brandName != ''">
|
|
|
+ AND tmgb.brand_name like concat('%', my_ex.likequery(#{brandName}) , '%')
|
|
|
+ </if>
|
|
|
+ <if test="whName != null and whName != ''">
|
|
|
+ AND tmw.wh_name like concat('%', my_ex.likequery(#{whName}) , '%')
|
|
|
+ </if>
|
|
|
+ <if test="nonStdCode != null and nonStdCode != ''">
|
|
|
+ AND t.non_std_code like concat('%', my_ex.likequery(#{nonStdCode}) , '%')
|
|
|
+ </if>
|
|
|
+ <if test="searchText !=null and searchText != ''">
|
|
|
+ AND (
|
|
|
+ tpo.order_no LIKE concat('%',my_ex.likequery(#{searchText}),'%')
|
|
|
+ or tmc.cus_phone LIKE concat('%',my_ex.likequery(#{searchText}),'%')
|
|
|
+ or tmc.cus_name LIKE concat('%',my_ex.likequery(#{searchText}),'%')
|
|
|
+ )
|
|
|
+ </if>
|
|
|
+ <if test="isFlgGift != null and isFlgGift == true">
|
|
|
+ AND t.flg_gift
|
|
|
+ </if>
|
|
|
+ <if test="isExtCo != null and isExtCo == true">
|
|
|
+ AND t.sku_id is null
|
|
|
+ </if>
|
|
|
</where>
|
|
|
</sql>
|
|
|
<select id="getSalesItemReportCount" resultType="java.lang.Long">
|
|
|
SELECT count(1)
|
|
|
FROM
|
|
|
dkic_b.t_psi_order_item t
|
|
|
+ inner join dkic_b.t_psi_order tpo on tpo.order_id = t.order_id
|
|
|
<include refid="ConditionSaleItem"/>
|
|
|
</select>
|
|
|
|
|
|
@@ -3014,8 +3052,144 @@
|
|
|
OR tmc.address_full LIKE concat('%',#{searchText},'%'))
|
|
|
</if>
|
|
|
<if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
|
|
|
- LIMIT #{pageSize} OFFSET #{currentPage}
|
|
|
+ limit #{end} offset #{start}
|
|
|
+ </if>
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <!--region 销售利润-->
|
|
|
+
|
|
|
+ <select id="getSaleProfit" resultType="java.util.Map">
|
|
|
+ select
|
|
|
+ t.outbound, t.inbound,
|
|
|
+ t.outbound - t.inbound "profit",
|
|
|
+ <include refid="getSaleProfitRate"/>
|
|
|
+ from (
|
|
|
+ select
|
|
|
+ <include refid="getSaleProfitInOutBound"/>
|
|
|
+ from dkic_b.t_psi_in_out_record tpr
|
|
|
+ where tpr.cp_id = #{cpId}
|
|
|
+ <if test="makeTimeStart != null and makeTimeEnd != null">
|
|
|
+ AND tpr.op_create_time >= #{makeTimeStart}::timestamp with time zone
|
|
|
+ AND tpr.op_create_time < #{makeTimeEnd}::timestamp with time zone + interval '1 day'
|
|
|
+ </if>
|
|
|
+ ) t
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <select id="getSaleProfitGroupByDate" resultType="java.util.Map">
|
|
|
+ select acc_date "accDate",
|
|
|
+ t.outbound - t.inbound "profit",
|
|
|
+ <include refid="getSaleProfitRate"/>
|
|
|
+ from (select
|
|
|
+ <if test="byDate==null or (byDate!=null and byDate=='false')">
|
|
|
+ to_char(acc_date, 'yyyy-mm') acc_date,
|
|
|
+ </if>
|
|
|
+ <if test="byDate!=null and byDate=='true'">
|
|
|
+ to_char(acc_date, 'mm-dd') acc_date,
|
|
|
+ </if>
|
|
|
+ <include refid="getSaleProfitInOutBound"/>
|
|
|
+ from dkic_b.t_psi_in_out_record tpr
|
|
|
+ <include refid="getSaleProfitCond"/>
|
|
|
+ group by
|
|
|
+ <if test="byDate==null or (byDate!=null and byDate=='false')">
|
|
|
+ to_char(acc_date, 'yyyy-mm')
|
|
|
+ </if>
|
|
|
+ <if test="byDate!=null and byDate=='true'">
|
|
|
+ to_char(acc_date, 'mm-dd')
|
|
|
</if>
|
|
|
+ ) t
|
|
|
+ order by t.acc_date
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <select id="getSaleProfitGroupByOrg" resultType="java.util.Map">
|
|
|
+ select tmo.org_name "orgName", tt.profit, tt."profitRate"
|
|
|
+ from (
|
|
|
+ select t.org_id,
|
|
|
+ t.outbound - t.inbound "profit",
|
|
|
+ <include refid="getSaleProfitRate"/>
|
|
|
+ from (select coalesce(tpi.org_id, tpo.org_id) org_id,
|
|
|
+ <include refid="getSaleProfitInOutBound"/>
|
|
|
+ from dkic_b.t_psi_in_out_record tpr
|
|
|
+ left join dkic_b.t_psi_inbound tpi on tpi.into_id = biznis_id
|
|
|
+ left join dkic_b.t_psi_outbound tpo on tpo.out_id = biznis_id
|
|
|
+ <include refid="getSaleProfitCond"/>
|
|
|
+ group by coalesce(tpi.org_id, tpo.org_id)) t
|
|
|
+ ) tt
|
|
|
+ left join dkic_b.t_mst_org tmo on tmo.org_id = tt.org_id
|
|
|
+ <include refid="getSaleProfitLimit"/>
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <select id="getSaleProfitGroupByStaff" resultType="java.util.Map">
|
|
|
+ select tms.staff_name "staffName", tt.profit, tt."profitRate"
|
|
|
+ from (
|
|
|
+ select t.staff_id,
|
|
|
+ t.outbound - t.inbound "profit",
|
|
|
+ <include refid="getSaleProfitRate"/>
|
|
|
+ from (select coalesce(tpi.staff_id, tpo.staff_id) staff_id,
|
|
|
+ <include refid="getSaleProfitInOutBound"/>
|
|
|
+ from dkic_b.t_psi_in_out_record tpr
|
|
|
+ left join dkic_b.t_psi_inbound tpi on tpi.into_id = biznis_id
|
|
|
+ left join dkic_b.t_psi_outbound tpo on tpo.out_id = biznis_id
|
|
|
+ <include refid="getSaleProfitCond"/>
|
|
|
+ group by coalesce(tpi.staff_id, tpo.staff_id)) t
|
|
|
+ ) tt
|
|
|
+ left join dkic_b.t_mst_staff tms on tms.staff_id = tt.staff_id
|
|
|
+ <include refid="getSaleProfitLimit"/>
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <select id="getSaleProfitGroupBySku" resultType="java.util.Map">
|
|
|
+ select tmgs.sku_name "skuName", tt.profit, tt."profitRate"
|
|
|
+ from (
|
|
|
+ select t.sku_id,
|
|
|
+ t.outbound - t.inbound "profit",
|
|
|
+ <include refid="getSaleProfitRate"/>
|
|
|
+ from (select sku_id sku_id,
|
|
|
+ <include refid="getSaleProfitInOutBound"/>
|
|
|
+ from dkic_b.t_psi_in_out_record tpr
|
|
|
+ <include refid="getSaleProfitCond"/>
|
|
|
+ group by sku_id) t
|
|
|
+ ) tt
|
|
|
+ left join dkic_b.t_mst_goods_sku tmgs on tmgs.sku_id = tt.sku_id
|
|
|
+ <include refid="getSaleProfitLimit"/>
|
|
|
</select>
|
|
|
|
|
|
+ <sql id="getSaleProfitInOutBound">
|
|
|
+ SUM(case biznis_type when 't_psi_outbound' then abs(tpr.into_amt) else 0 end) outbound,
|
|
|
+ SUM(case biznis_type when 't_psi_inbound' then abs(tpr.into_amt) else 0 end) inbound
|
|
|
+ </sql>
|
|
|
+
|
|
|
+ <sql id="getSaleProfitCond">
|
|
|
+ where tpr.cp_id = #{cpId}
|
|
|
+ <if test="makeTimeStart != null and makeTimeEnd != null">
|
|
|
+ AND tpr.op_create_time >= #{makeTimeStart}::timestamp with time zone
|
|
|
+ AND tpr.op_create_time < #{makeTimeEnd}::timestamp with time zone + interval '1 day'
|
|
|
+ </if>
|
|
|
+ </sql>
|
|
|
+
|
|
|
+ <sql id="getSaleProfitLimit">
|
|
|
+ <if test="orderBy != null and orderBy=='profitAsc'">
|
|
|
+ order by tt.profit
|
|
|
+ </if>
|
|
|
+ <if test="orderBy == null or orderBy=='profitDesc'">
|
|
|
+ order by tt.profit desc
|
|
|
+ </if>
|
|
|
+ <if test="orderBy != null and orderBy=='rateAsc'">
|
|
|
+ order by tt.profitRate
|
|
|
+ </if>
|
|
|
+ <if test="orderBy != null and orderBy=='rateDsc'">
|
|
|
+ order by tt.profitRate desc
|
|
|
+ </if>
|
|
|
+ <if test="limit!=null and limit">
|
|
|
+ limit 5
|
|
|
+ </if>
|
|
|
+ </sql>
|
|
|
+
|
|
|
+ <sql id="getSaleProfitRate">
|
|
|
+ case
|
|
|
+ when t.inbound = 0 then 0
|
|
|
+ else
|
|
|
+ round((t.outbound - t.inbound) / t.inbound * 100, 2)
|
|
|
+ end "profitRate"
|
|
|
+ </sql>
|
|
|
+
|
|
|
+ <!--endregion-->
|
|
|
</mapper>
|