|
|
@@ -20,125 +20,58 @@
|
|
|
</sql>
|
|
|
|
|
|
<select id="selectByCondition" parameterType="java.lang.Long" resultMap="BaseResultMap">
|
|
|
- SELECT
|
|
|
- a.pi_custcode,
|
|
|
- a.pi_custname,
|
|
|
- a.cu_type,
|
|
|
- a.cu_sellername,
|
|
|
- IFNULL(a.saamount*a.pi_rate,0) as saamount,
|
|
|
- IFNULL(a.netamount*a.pi_rate,0) as netamount,
|
|
|
- IFNULL(a.costamount*a.pi_rate,0) as costamount,
|
|
|
- IFNULL(SUM(a.netamount*a.pi_rate - a.costamount*a.pi_rate),0) as profit,
|
|
|
- IFNULL((SUM(a.netamount*a.pi_rate - a.costamount*a.pi_rate)/IFNULL(a.netamount*a.pi_rate,SUM(a.netamount*a.pi_rate - a.costamount*a.pi_rate))),0) as profitpresent
|
|
|
-
|
|
|
-FROM
|
|
|
- (
|
|
|
- SELECT
|
|
|
- pi_rate,
|
|
|
- pi_custcode,
|
|
|
- pi_custname,
|
|
|
- cu_type,
|
|
|
- cu_sellername,
|
|
|
- SUM(
|
|
|
- IFNULL(pd_sendprice,0) * (IFNULL(pd_outqty,0) - IFNULL(pd_inqty,0))
|
|
|
- ) AS saamount,
|
|
|
- SUM(
|
|
|
- IFNULL(pd_netprice,0) * (IFNULL(pd_outqty,0) - IFNULL(pd_inqty,0))
|
|
|
- ) AS netamount,
|
|
|
- SUM(
|
|
|
- IFNULL(pd_price,0) * (IFNULL(pd_outqty,0) - IFNULL(pd_inqty,0))
|
|
|
- ) AS costamount
|
|
|
- FROM
|
|
|
- prodinout,
|
|
|
- prodiodetail,
|
|
|
- customer
|
|
|
- <where>
|
|
|
- <if test="con != null">
|
|
|
- ${con}
|
|
|
- </if>
|
|
|
- <if test="companyId != null">
|
|
|
- and prodinout.companyid = #{companyId}
|
|
|
- </if>
|
|
|
- </where>
|
|
|
- and pi_id = pd_piid
|
|
|
- AND pi_custid = cu_id and pi_status = '已审核' and
|
|
|
-prodinout.companyid= prodiodetail.companyid
|
|
|
- GROUP BY
|
|
|
- pi_custcode,
|
|
|
- pi_custname,
|
|
|
- cu_type,
|
|
|
- cu_sellername,
|
|
|
- pi_rate
|
|
|
- ) a
|
|
|
- where saamount + netamount + costamount != 0
|
|
|
- GROUP BY
|
|
|
- a.pi_rate,
|
|
|
- a.pi_custcode,
|
|
|
- a.pi_custname,
|
|
|
- a.cu_type,
|
|
|
- a.cu_sellername
|
|
|
- ORDER BY a.pi_custname asc,a.pi_custname desc
|
|
|
+ select
|
|
|
+ cu_type,
|
|
|
+ pi_custid,
|
|
|
+ pi_custcode,
|
|
|
+ pi_custname,
|
|
|
+ sum(pd_sendprice*pi_rate) as saamount,
|
|
|
+ sum(pd_price) as costamount,
|
|
|
+ sum(pd_sendprice*pi_rate)-sum(pd_price) as profit,
|
|
|
+ (sum(pd_sendprice*pi_rate)-sum(pd_price) )/sum(pd_sendprice*pi_rate) as profitpresent
|
|
|
+ from prodiodetail
|
|
|
+ left join prodinout on pd_piid=pi_Id
|
|
|
+ left join customer on cu_id = pi_custid
|
|
|
+ <where>
|
|
|
+ <if test="con != null">
|
|
|
+ ${con}
|
|
|
+ </if>
|
|
|
+ <if test="companyId != null">
|
|
|
+ and prodinout.companyid = #{companyId}
|
|
|
+ </if>
|
|
|
+ and pi_class in('出货单','销售退货单')
|
|
|
+ </where>
|
|
|
+ group by pi_custid,pi_custcode,pi_custname,cu_type
|
|
|
+ ORDER BY pi_custname asc
|
|
|
</select>
|
|
|
|
|
|
<select id="selectCalculateFields" resultType="string">
|
|
|
SELECT ${fields}
|
|
|
- FROM
|
|
|
- (
|
|
|
- SELECT
|
|
|
- a.pi_custcode,
|
|
|
- a.pi_custname,
|
|
|
- a.cu_type,
|
|
|
- a.cu_sellername,
|
|
|
- IFNULL(a.saamount,0) as saamount,
|
|
|
- IFNULL(a.netamount,0) as netamount,
|
|
|
- IFNULL(a.costamount,0) as costamount,
|
|
|
- IFNULL(SUM(a.netamount - a.costamount),0) as profit,
|
|
|
- IFNULL((SUM(a.netamount - a.costamount)/IFNULL(a.netamount,SUM(a.netamount - a.costamount))),0) as profitpresent
|
|
|
- FROM
|
|
|
- (
|
|
|
- SELECT
|
|
|
+ from(
|
|
|
+ select
|
|
|
+ cu_type,
|
|
|
+ pi_custid,
|
|
|
pi_custcode,
|
|
|
pi_custname,
|
|
|
- cu_type,
|
|
|
- cu_sellername,
|
|
|
- SUM( (IFNULL( pd_sendprice, 0 ) * ( IFNULL( pd_outqty, 0 ) - IFNULL( pd_inqty, 0 ) )) * ifnull(cr_rate,1) ) AS saamount,
|
|
|
- SUM(
|
|
|
- IFNULL(pd_netprice,0) * (IFNULL(pd_outqty,0) - IFNULL(pd_inqty,0))
|
|
|
- ) AS netamount,
|
|
|
- SUM(
|
|
|
- IFNULL(pd_price,0) * (IFNULL(pd_outqty,0) - IFNULL(pd_inqty,0))
|
|
|
- ) AS costamount
|
|
|
- FROM
|
|
|
- prodinout,
|
|
|
- prodiodetail,
|
|
|
- customer,
|
|
|
- currencys
|
|
|
+ sum(pd_sendprice*pi_rate) as saamount,
|
|
|
+ sum(pd_price) as costamount,
|
|
|
+ sum(pd_sendprice*pi_rate)-sum(pd_price) as profit,
|
|
|
+ (sum(pd_sendprice*pi_rate)-sum(pd_price) )/sum(pd_sendprice*pi_rate) as profitpresent
|
|
|
+ from prodiodetail
|
|
|
+ left join prodinout on pd_piid=pi_Id
|
|
|
+ left join customer on cu_id = pi_custid
|
|
|
<where>
|
|
|
<if test="con != null">
|
|
|
${con}
|
|
|
</if>
|
|
|
<if test="companyId != null">
|
|
|
- and prodinout.companyid = #{companyId}
|
|
|
+ and prodinout.companyid = #{companyId}
|
|
|
</if>
|
|
|
+ and pi_class in('出货单','销售退货单')
|
|
|
</where>
|
|
|
- AND pi_id = pd_piid
|
|
|
- AND pi_custid = cu_id
|
|
|
- AND pi_status = '已审核'
|
|
|
- AND prodinout.companyid= prodiodetail.companyid
|
|
|
- AND prodiodetail.companyid = prodinout.companyid
|
|
|
- AND currencys.cr_name = prodinout.pi_currency
|
|
|
- AND currencys.companyid = prodinout.companyid
|
|
|
- GROUP BY
|
|
|
- pi_custcode,
|
|
|
- pi_custname,
|
|
|
- cu_type,
|
|
|
- cu_sellername
|
|
|
+ group by pi_custid,pi_custcode,pi_custname,cu_type
|
|
|
+ ORDER BY pi_custname asc
|
|
|
) a
|
|
|
- GROUP BY
|
|
|
- a.pi_custcode,
|
|
|
- a.pi_custname,
|
|
|
- a.cu_type,
|
|
|
- a.cu_sellername)b
|
|
|
</select>
|
|
|
|
|
|
</mapper>
|