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.

148 lines
7.3 KiB

4 days ago
  1. SELECT DISTINCT
  2. a.ID,
  3. a.POCode,
  4. a.Sequence,
  5. CONVERT(NVARCHAR(50), a.CreateDateTime, 23) AS PODate,
  6. a.VenCode,
  7. ven.VenName,
  8. a.CreatePerson,
  9. a.POType,
  10. a.InvCode,
  11. c.INVNAME,
  12. c.INVDESC,
  13. es.ProjectCode,
  14. a.UnitPrice,
  15. a.Quantity,
  16. CASE WHEN a.ReleaseState = '1' THEN '已发布' ELSE '未发布' END AS ReleaseState,
  17. CONVERT(NVARCHAR(50), a.PlanArriveDate, 23) AS PreArriveDate,
  18. CONVERT(NVARCHAR(50), a.ArriveDate, 23) AS ArriveDate,
  19. CONVERT(NVARCHAR(50), a.DeliveryDate, 23) AS Free5,
  20. a.WorkPoint,
  21. b.WorkPointName,
  22. a.ArriveUser,
  23. a.DeliveryUser,
  24. c.INVSTD,
  25. CAST(cc.RECEIVEQTY AS DECIMAL(18, 3)) AS LJDH,
  26. ff.TransQTY AS JLRK,
  27. ISNULL(gg.NGQTY, 0) AS RefuseLotQty,
  28. ISNULL(hh.returnqty, 0) AS BackLotQty,
  29. a.EATTRIBUTE11,
  30. a.EATTRIBUTE12,
  31. a.EATTRIBUTE13,
  32. a.EATTRIBUTE14,
  33. a.EATTRIBUTE15,
  34. a.EATTRIBUTE16,
  35. a.EATTRIBUTE17,
  36. ii.TMQty,
  37. jj.ASNQty,
  38. kk.insQty,
  39. ll.ConQty,
  40. mm.NOAsnQty,
  41. nn.DnQty,
  42. oo.NOInqty
  43. FROM
  44. dbo.ICSPurchaseOrder a
  45. LEFT JOIN dbo.Sys_WorkPoint b ON a.WorkPoint = b.WorkPointCode
  46. LEFT JOIN dbo.ICSINVENTORY c ON a.InvCode = c.INVCODE AND a.WorkPoint = c.WorkPoint
  47. LEFT JOIN dbo.ICSVendor ven ON a.VenCode = ven.VenCode
  48. LEFT JOIN dbo.ICSExtension es ON a.ExtensionID = es.ID
  49. -- 累计到货数量
  50. LEFT JOIN (
  51. SELECT cc.TransCode, cc.TransSequence, bb.InvCode, SUM(aa.Quantity) AS RECEIVEQTY
  52. FROM ICSASNdetail aa
  53. LEFT JOIN ICSInventoryLot bb ON aa.LotNo = bb.LotNo AND aa.WorkPoint = bb.WorkPoint
  54. LEFT JOIN ICSInventoryLotDetail cc ON bb.LOTNO = cc.LotNO
  55. GROUP BY cc.TransCode, cc.TransSequence, bb.InvCode
  56. ) cc ON a.pocode = cc.TransCode AND a.Sequence = cc.TransSequence
  57. -- 累计入库数量
  58. LEFT JOIN (
  59. SELECT cc.TransCode, cc.TransSequence, dd.InvCode AS ItemCODE, SUM(ee.Quantity) AS TransQTY
  60. FROM ICSInventoryLot dd
  61. LEFT JOIN ICSInventoryLotDetail cc ON dd.LOTNO = cc.LotNO
  62. LEFT JOIN ICSWareHouseLotInfolog ee ON dd.LotNO = ee.LotNO
  63. WHERE ee.BusinessCode = '1'
  64. GROUP BY cc.TransCode, cc.TransSequence, dd.InvCode
  65. ) ff ON a.pocode = ff.TransCode AND a.Sequence = ff.TransSequence
  66. -- 拒收数量
  67. LEFT JOIN (
  68. SELECT c.TransCode, c.TransSequence, SUM(ISNULL(a.UnqualifiedQuantity, 0)) AS NGQTY, a.WorkPoint
  69. FROM ICSInspection a
  70. LEFT JOIN ICSInventoryLot b ON a.LotNo = b.lotno AND a.WorkPoint = b.WorkPoint
  71. LEFT JOIN ICSInventoryLotDetail c ON b.LOTNO = c.LotNO AND b.WorkPoint = c.WorkPoint
  72. GROUP BY c.TransCode, c.TransSequence, b.EATTRIBUTE2, a.WorkPoint
  73. HAVING b.EATTRIBUTE2 IS NULL
  74. ) gg ON a.POCode = gg.TransCode AND a.Sequence = gg.TransSequence AND a.WorkPoint = gg.WorkPoint
  75. -- 已退货数量
  76. LEFT JOIN (
  77. SELECT n.POCode, n.Sequence, SUM(ISNULL(a.Quantity, 0)) AS returnqty
  78. FROM ICSDeliveryNotice a
  79. INNER JOIN ICSPurchaseOrder n ON a.POID = n.POID AND a.PODetailID = n.PODetailID AND a.WorkPoint = n.WorkPoint
  80. GROUP BY n.POCode, n.Sequence, a.DNType
  81. HAVING a.DNType = '2'
  82. ) hh ON a.POCode = hh.POCode AND a.Sequence = hh.Sequence
  83. -- 累计包装数量
  84. LEFT JOIN (
  85. SELECT SUM(a.Quantity) AS TMQty, b.TransCode, b.TransSequence, a.WorkPoint
  86. FROM dbo.ICSInventoryLot a
  87. LEFT JOIN dbo.ICSInventoryLotDetail b ON a.LotNo = b.LotNo AND a.WorkPoint = b.WorkPoint
  88. GROUP BY b.TransCode, b.TransSequence, a.WorkPoint
  89. ) ii ON ii.TransCode = a.PoCode AND ii.TransSequence = a.Sequence AND a.WorkPoint = ii.WorkPoint
  90. -- 累计送货数量
  91. LEFT JOIN (
  92. SELECT SUM(a.Quantity) AS ASNQty, b.TransCode, b.TransSequence, b.WorkPoint
  93. FROM dbo.ICSASNDetail a
  94. LEFT JOIN dbo.ICSInventoryLotDetail b ON a.LotNo = b.LotNo AND a.WorkPoint = b.WorkPoint
  95. GROUP BY b.TransCode, b.TransSequence, b.WorkPoint
  96. ) jj ON a.PoCode = jj.TransCode AND a.Sequence = jj.TransSequence AND a.WorkPoint = jj.WorkPoint
  97. -- 已检验未入库
  98. LEFT JOIN (
  99. SELECT SUM(a.Quantity) AS insQty, b.TransCode, b.TransSequence, b.WorkPoint
  100. FROM dbo.ICSInspection a
  101. LEFT JOIN dbo.ICSInventoryLotDetail b ON a.LotNo = b.LotNo AND a.WorkPoint = b.WorkPoint
  102. LEFT JOIN dbo.ICSWareHouseLotInfoLog c ON b.LotNo = c.LotNo AND b.WorkPoint = c.WorkPoint
  103. WHERE c.LotNo IS NULL
  104. GROUP BY b.TransCode, b.TransSequence, b.WorkPoint
  105. ) kk ON a.PoCode = kk.TransCode AND a.Sequence = kk.TransSequence AND a.WorkPoint = kk.WorkPoint
  106. -- 已包装未组托数量
  107. LEFT JOIN (
  108. SELECT SUM(a.Quantity) AS ConQty, b.TransCode, b.TransSequence, a.WorkPoint
  109. FROM dbo.ICSInventoryLot a
  110. LEFT JOIN dbo.ICSInventoryLotDetail b ON a.LotNo = b.LotNo AND a.WorkPoint = b.WorkPoint
  111. LEFT JOIN dbo.ICSContainerLot c ON b.LotNo = c.LotNo AND b.WorkPoint = c.WorkPoint
  112. LEFT JOIN dbo.ICSContainer d ON c.ContainerID = d.ID AND c.WorkPoint = d.WorkPoint
  113. WHERE d.ContainerCode IS NULL
  114. GROUP BY b.TransCode, b.TransSequence, a.WorkPoint
  115. ) ll ON a.PoCode = ll.TransCode AND a.Sequence = ll.TransSequence AND a.WorkPoint = ll.WorkPoint
  116. -- 已包装未送货数量
  117. LEFT JOIN (
  118. SELECT SUM(a.Quantity) AS NOAsnQty, b.TransCode, b.TransSequence, a.WorkPoint
  119. FROM dbo.ICSInventoryLot a
  120. LEFT JOIN dbo.ICSInventoryLotDetail b ON a.LotNo = b.LotNo AND a.WorkPoint = b.WorkPoint
  121. LEFT JOIN dbo.ICSContainerLot c ON b.LotNo = c.LotNo AND b.WorkPoint = c.WorkPoint
  122. LEFT JOIN dbo.ICSContainer d ON c.ContainerID = d.ID AND c.WorkPoint = d.WorkPoint
  123. LEFT JOIN dbo.ICSASNDetail e ON a.LotNo = e.LotNo AND a.WorkPoint = e.WorkPoint
  124. WHERE e.LotNo IS NULL
  125. GROUP BY b.TransCode, b.TransSequence, a.WorkPoint
  126. ) mm ON a.PoCode = mm.TransCode AND a.Sequence = mm.TransSequence AND a.WorkPoint = mm.WorkPoint
  127. -- 已送货未到货数量
  128. LEFT JOIN (
  129. SELECT SUM(a.Quantity) AS DnQty, c.TransCode, c.TransSequence, a.WorkPoint
  130. FROM dbo.ICSASNDetail a
  131. LEFT JOIN dbo.ICSASN b ON a.ASNCode = b.ASNCode AND a.WorkPoint = b.WorkPoint
  132. LEFT JOIN dbo.ICSInventoryLotDetail c ON a.LotNo = c.LotNo AND a.WorkPoint = c.WorkPoint
  133. LEFT JOIN dbo.ICSDeliveryNotice d ON b.ASNCode = d.ASNCode AND b.WorkPoint = d.WorkPoint AND d.DNType = '1'
  134. WHERE d.ASNCode IS NULL
  135. GROUP BY c.TransCode, c.TransSequence, a.WorkPoint
  136. ) nn ON a.PoCode = nn.TransCode AND a.Sequence = nn.TransSequence AND a.WorkPoint = nn.WorkPoint
  137. -- 已到货未检验数量
  138. LEFT JOIN (
  139. SELECT SUM(a.Quantity) AS NOInqty, e.TransCode, e.TransSequence, a.WorkPoint
  140. FROM dbo.ICSDeliveryNotice a
  141. LEFT JOIN dbo.ICSASNDetail b ON a.ASNCode = b.ASNCode AND a.WorkPoint = b.WorkPoint
  142. LEFT JOIN dbo.ICSInspection c ON b.LotNo = c.LotNo AND b.WorkPoint = c.WorkPoint
  143. LEFT JOIN dbo.ICSInventory d ON c.InvCode = d.InvCode AND c.WorkPoint = d.WorkPoint
  144. LEFT JOIN dbo.ICSInventoryLotDetail e ON c.LotNo = e.LotNo AND c.WorkPoint = e.WorkPoint
  145. WHERE c.LotNo IS NULL AND d.InvIQC = '1'
  146. GROUP BY e.TransCode, e.TransSequence, a.WorkPoint
  147. ) oo ON a.PoCode = oo.TransCode AND a.Sequence = oo.TransSequence AND a.WorkPoint = oo.WorkPoint
  148. WHERE
  149. 1 = 1 and ReleaseState = '1' AND a.WorkPoint='UFDATA_106_2019'