You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

149 lines
7.3 KiB

SELECT DISTINCT
a.ID,
a.POCode,
a.Sequence,
CONVERT(NVARCHAR(50), a.CreateDateTime, 23) AS PODate,
a.VenCode,
ven.VenName,
a.CreatePerson,
a.POType,
a.InvCode,
c.INVNAME,
c.INVDESC,
es.ProjectCode,
a.UnitPrice,
a.Quantity,
CASE WHEN a.ReleaseState = '1' THEN '已发布' ELSE '未发布' END AS ReleaseState,
CONVERT(NVARCHAR(50), a.PlanArriveDate, 23) AS PreArriveDate,
CONVERT(NVARCHAR(50), a.ArriveDate, 23) AS ArriveDate,
CONVERT(NVARCHAR(50), a.DeliveryDate, 23) AS Free5,
a.WorkPoint,
b.WorkPointName,
a.ArriveUser,
a.DeliveryUser,
c.INVSTD,
CAST(cc.RECEIVEQTY AS DECIMAL(18, 3)) AS LJDH,
ff.TransQTY AS JLRK,
ISNULL(gg.NGQTY, 0) AS RefuseLotQty,
ISNULL(hh.returnqty, 0) AS BackLotQty,
a.EATTRIBUTE11,
a.EATTRIBUTE12,
a.EATTRIBUTE13,
a.EATTRIBUTE14,
a.EATTRIBUTE15,
a.EATTRIBUTE16,
a.EATTRIBUTE17,
ii.TMQty,
jj.ASNQty,
kk.insQty,
ll.ConQty,
mm.NOAsnQty,
nn.DnQty,
oo.NOInqty
FROM
dbo.ICSPurchaseOrder a
LEFT JOIN dbo.Sys_WorkPoint b ON a.WorkPoint = b.WorkPointCode
LEFT JOIN dbo.ICSINVENTORY c ON a.InvCode = c.INVCODE AND a.WorkPoint = c.WorkPoint
LEFT JOIN dbo.ICSVendor ven ON a.VenCode = ven.VenCode
LEFT JOIN dbo.ICSExtension es ON a.ExtensionID = es.ID
-- 累计到货数量
LEFT JOIN (
SELECT cc.TransCode, cc.TransSequence, bb.InvCode, SUM(aa.Quantity) AS RECEIVEQTY
FROM ICSASNdetail aa
LEFT JOIN ICSInventoryLot bb ON aa.LotNo = bb.LotNo AND aa.WorkPoint = bb.WorkPoint
LEFT JOIN ICSInventoryLotDetail cc ON bb.LOTNO = cc.LotNO
GROUP BY cc.TransCode, cc.TransSequence, bb.InvCode
) cc ON a.pocode = cc.TransCode AND a.Sequence = cc.TransSequence
-- 累计入库数量
LEFT JOIN (
SELECT cc.TransCode, cc.TransSequence, dd.InvCode AS ItemCODE, SUM(ee.Quantity) AS TransQTY
FROM ICSInventoryLot dd
LEFT JOIN ICSInventoryLotDetail cc ON dd.LOTNO = cc.LotNO
LEFT JOIN ICSWareHouseLotInfolog ee ON dd.LotNO = ee.LotNO
WHERE ee.BusinessCode = '1'
GROUP BY cc.TransCode, cc.TransSequence, dd.InvCode
) ff ON a.pocode = ff.TransCode AND a.Sequence = ff.TransSequence
-- 拒收数量
LEFT JOIN (
SELECT c.TransCode, c.TransSequence, SUM(ISNULL(a.UnqualifiedQuantity, 0)) AS NGQTY, a.WorkPoint
FROM ICSInspection a
LEFT JOIN ICSInventoryLot b ON a.LotNo = b.lotno AND a.WorkPoint = b.WorkPoint
LEFT JOIN ICSInventoryLotDetail c ON b.LOTNO = c.LotNO AND b.WorkPoint = c.WorkPoint
GROUP BY c.TransCode, c.TransSequence, b.EATTRIBUTE2, a.WorkPoint
HAVING b.EATTRIBUTE2 IS NULL
) gg ON a.POCode = gg.TransCode AND a.Sequence = gg.TransSequence AND a.WorkPoint = gg.WorkPoint
-- 已退货数量
LEFT JOIN (
SELECT n.POCode, n.Sequence, SUM(ISNULL(a.Quantity, 0)) AS returnqty
FROM ICSDeliveryNotice a
INNER JOIN ICSPurchaseOrder n ON a.POID = n.POID AND a.PODetailID = n.PODetailID AND a.WorkPoint = n.WorkPoint
GROUP BY n.POCode, n.Sequence, a.DNType
HAVING a.DNType = '2'
) hh ON a.POCode = hh.POCode AND a.Sequence = hh.Sequence
-- 累计包装数量
LEFT JOIN (
SELECT SUM(a.Quantity) AS TMQty, b.TransCode, b.TransSequence, a.WorkPoint
FROM dbo.ICSInventoryLot a
LEFT JOIN dbo.ICSInventoryLotDetail b ON a.LotNo = b.LotNo AND a.WorkPoint = b.WorkPoint
GROUP BY b.TransCode, b.TransSequence, a.WorkPoint
) ii ON ii.TransCode = a.PoCode AND ii.TransSequence = a.Sequence AND a.WorkPoint = ii.WorkPoint
-- 累计送货数量
LEFT JOIN (
SELECT SUM(a.Quantity) AS ASNQty, b.TransCode, b.TransSequence, b.WorkPoint
FROM dbo.ICSASNDetail a
LEFT JOIN dbo.ICSInventoryLotDetail b ON a.LotNo = b.LotNo AND a.WorkPoint = b.WorkPoint
GROUP BY b.TransCode, b.TransSequence, b.WorkPoint
) jj ON a.PoCode = jj.TransCode AND a.Sequence = jj.TransSequence AND a.WorkPoint = jj.WorkPoint
-- 已检验未入库
LEFT JOIN (
SELECT SUM(a.Quantity) AS insQty, b.TransCode, b.TransSequence, b.WorkPoint
FROM dbo.ICSInspection a
LEFT JOIN dbo.ICSInventoryLotDetail b ON a.LotNo = b.LotNo AND a.WorkPoint = b.WorkPoint
LEFT JOIN dbo.ICSWareHouseLotInfoLog c ON b.LotNo = c.LotNo AND b.WorkPoint = c.WorkPoint
WHERE c.LotNo IS NULL
GROUP BY b.TransCode, b.TransSequence, b.WorkPoint
) kk ON a.PoCode = kk.TransCode AND a.Sequence = kk.TransSequence AND a.WorkPoint = kk.WorkPoint
-- 已包装未组托数量
LEFT JOIN (
SELECT SUM(a.Quantity) AS ConQty, b.TransCode, b.TransSequence, a.WorkPoint
FROM dbo.ICSInventoryLot a
LEFT JOIN dbo.ICSInventoryLotDetail b ON a.LotNo = b.LotNo AND a.WorkPoint = b.WorkPoint
LEFT JOIN dbo.ICSContainerLot c ON b.LotNo = c.LotNo AND b.WorkPoint = c.WorkPoint
LEFT JOIN dbo.ICSContainer d ON c.ContainerID = d.ID AND c.WorkPoint = d.WorkPoint
WHERE d.ContainerCode IS NULL
GROUP BY b.TransCode, b.TransSequence, a.WorkPoint
) ll ON a.PoCode = ll.TransCode AND a.Sequence = ll.TransSequence AND a.WorkPoint = ll.WorkPoint
-- 已包装未送货数量
LEFT JOIN (
SELECT SUM(a.Quantity) AS NOAsnQty, b.TransCode, b.TransSequence, a.WorkPoint
FROM dbo.ICSInventoryLot a
LEFT JOIN dbo.ICSInventoryLotDetail b ON a.LotNo = b.LotNo AND a.WorkPoint = b.WorkPoint
LEFT JOIN dbo.ICSContainerLot c ON b.LotNo = c.LotNo AND b.WorkPoint = c.WorkPoint
LEFT JOIN dbo.ICSContainer d ON c.ContainerID = d.ID AND c.WorkPoint = d.WorkPoint
LEFT JOIN dbo.ICSASNDetail e ON a.LotNo = e.LotNo AND a.WorkPoint = e.WorkPoint
WHERE e.LotNo IS NULL
GROUP BY b.TransCode, b.TransSequence, a.WorkPoint
) mm ON a.PoCode = mm.TransCode AND a.Sequence = mm.TransSequence AND a.WorkPoint = mm.WorkPoint
-- 已送货未到货数量
LEFT JOIN (
SELECT SUM(a.Quantity) AS DnQty, c.TransCode, c.TransSequence, a.WorkPoint
FROM dbo.ICSASNDetail a
LEFT JOIN dbo.ICSASN b ON a.ASNCode = b.ASNCode AND a.WorkPoint = b.WorkPoint
LEFT JOIN dbo.ICSInventoryLotDetail c ON a.LotNo = c.LotNo AND a.WorkPoint = c.WorkPoint
LEFT JOIN dbo.ICSDeliveryNotice d ON b.ASNCode = d.ASNCode AND b.WorkPoint = d.WorkPoint AND d.DNType = '1'
WHERE d.ASNCode IS NULL
GROUP BY c.TransCode, c.TransSequence, a.WorkPoint
) nn ON a.PoCode = nn.TransCode AND a.Sequence = nn.TransSequence AND a.WorkPoint = nn.WorkPoint
-- 已到货未检验数量
LEFT JOIN (
SELECT SUM(a.Quantity) AS NOInqty, e.TransCode, e.TransSequence, a.WorkPoint
FROM dbo.ICSDeliveryNotice a
LEFT JOIN dbo.ICSASNDetail b ON a.ASNCode = b.ASNCode AND a.WorkPoint = b.WorkPoint
LEFT JOIN dbo.ICSInspection c ON b.LotNo = c.LotNo AND b.WorkPoint = c.WorkPoint
LEFT JOIN dbo.ICSInventory d ON c.InvCode = d.InvCode AND c.WorkPoint = d.WorkPoint
LEFT JOIN dbo.ICSInventoryLotDetail e ON c.LotNo = e.LotNo AND c.WorkPoint = e.WorkPoint
WHERE c.LotNo IS NULL AND d.InvIQC = '1'
GROUP BY e.TransCode, e.TransSequence, a.WorkPoint
) oo ON a.PoCode = oo.TransCode AND a.Sequence = oo.TransSequence AND a.WorkPoint = oo.WorkPoint
WHERE
1 = 1 and ReleaseState = '1' AND a.WorkPoint='UFDATA_106_2019'