|
|
@@ -25,11 +25,11 @@
|
|
|
a.pi_custname,
|
|
|
a.cu_type,
|
|
|
a.cu_sellername,
|
|
|
- a.saamount,
|
|
|
- a.netamount,
|
|
|
- a.costamount,
|
|
|
-SUM(a.netamount - a.costamount) as profit,
|
|
|
-(SUM(a.netamount - a.costamount)/IFNULL(netamount,SUM(netamount - costamount))) as profitpresent
|
|
|
+ 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
|
|
|
(
|
|
|
@@ -38,15 +38,15 @@ FROM
|
|
|
pi_custname,
|
|
|
cu_type,
|
|
|
cu_sellername,
|
|
|
- SUM(
|
|
|
- pd_sendprice * (pd_outqty - pd_inqty)
|
|
|
- ) AS saamount,
|
|
|
- SUM(
|
|
|
- pd_netprice * (pd_outqty - pd_inqty)
|
|
|
- ) AS netamount,
|
|
|
- SUM(
|
|
|
- pd_price * (pd_outqty - pd_inqty)
|
|
|
- ) AS costamount
|
|
|
+ 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,
|
|
|
@@ -61,13 +61,15 @@ FROM
|
|
|
</where>
|
|
|
and pi_id = pd_piid
|
|
|
AND pi_custid = cu_id and pi_status = '已审核' and
|
|
|
-prodinout.companyid= prodiodetail.companyid and prodiodetail.companyid = prodinout.companyid
|
|
|
+prodinout.companyid= prodiodetail.companyid
|
|
|
GROUP BY
|
|
|
pi_custcode,
|
|
|
pi_custname,
|
|
|
cu_type,
|
|
|
cu_sellername
|
|
|
- ) a GROUP BY
|
|
|
+ ) a
|
|
|
+ where saamount + netamount + costamount != 0
|
|
|
+ GROUP BY
|
|
|
a.pi_custcode,
|
|
|
a.pi_custname,
|
|
|
a.cu_type,
|
|
|
@@ -84,11 +86,11 @@ prodinout.companyid= prodiodetail.companyid and prodiodetail.companyid = prodino
|
|
|
a.pi_custname,
|
|
|
a.cu_type,
|
|
|
a.cu_sellername,
|
|
|
- a.saamount,
|
|
|
- a.netamount,
|
|
|
- a.costamount,
|
|
|
- SUM(a.netamount - a.costamount) as profit,
|
|
|
- (SUM(a.netamount - a.costamount)/IFNULL(netamount,SUM(netamount - costamount))) as profitpresent
|
|
|
+ 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
|
|
|
(
|
|
|
@@ -98,13 +100,13 @@ prodinout.companyid= prodiodetail.companyid and prodiodetail.companyid = prodino
|
|
|
cu_type,
|
|
|
cu_sellername,
|
|
|
SUM(
|
|
|
- pd_sendprice * (pd_outqty - pd_inqty)
|
|
|
+ IFNULL(pd_sendprice,0) * (IFNULL(pd_outqty,0) - IFNULL(pd_inqty,0))
|
|
|
) AS saamount,
|
|
|
SUM(
|
|
|
- pd_netprice * (pd_outqty - pd_inqty)
|
|
|
+ IFNULL(pd_netprice,0) * (IFNULL(pd_outqty,0) - IFNULL(pd_inqty,0))
|
|
|
) AS netamount,
|
|
|
SUM(
|
|
|
- pd_price * (pd_outqty - pd_inqty)
|
|
|
+ IFNULL(pd_price,0) * (IFNULL(pd_outqty,0) - IFNULL(pd_inqty,0))
|
|
|
) AS costamount
|
|
|
FROM
|
|
|
prodinout,
|
|
|
@@ -126,7 +128,8 @@ prodinout.companyid= prodiodetail.companyid and prodiodetail.companyid = prodino
|
|
|
pi_custname,
|
|
|
cu_type,
|
|
|
cu_sellername
|
|
|
- ) a GROUP BY
|
|
|
+ ) a
|
|
|
+ GROUP BY
|
|
|
a.pi_custcode,
|
|
|
a.pi_custname,
|
|
|
a.cu_type,
|