2020-12-08 11.54.sql 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. USE [befri_Goldhoo]
  2. GO
  3. /****** Object: View [shop_order].[V_PurchaseOrderLine] Script Date: 2020/12/8 11:22:51 ******/
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8. ALTER VIEW [shop_order].[V_PurchaseOrderLine]
  9. AS
  10. SELECT pol.PurchaseOrderLineId ,
  11. pol.PurchaseOrderId ,
  12. pol.InventoryType ,
  13. pol.ImageItemId ,
  14. pol.CombtItemId ,
  15. pol.CombtItemNumber ,
  16. pol.CombtItemName ,
  17. pol.InventoryId ,
  18. pol.InventoryNumber ,
  19. pol.InventoryName ,
  20. pol.Spec ,
  21. pol.Length ,
  22. pol.Width ,
  23. pol.Height ,
  24. pol.Uom ,
  25. pol.Quantity ,
  26. ISNULL(cl.ClosedQuantity, 0) ClosedQuantity ,
  27. ISNULL(cl.ClosedTime, 0) ClosedTime ,
  28. pol.RemainQty ,
  29. pol.Price ,
  30. pol.Freight ,
  31. pol.IsUrgent ,
  32. pol.IsAllotype ,
  33. pol.IsSpecial ,
  34. pol.SpecialSpec ,
  35. pol.SpecialFare ,
  36. pol.ApprovedIdea ,
  37. pol.Closed ,
  38. pol.ClosedBy ,
  39. pol.ClosedOn ,
  40. pol.ClosedReason ,
  41. pol.LineStatus ,
  42. vtm.Text AS LineStatusText ,
  43. pol.VersionNumber ,
  44. pol.Description ,
  45. vimi.ThumbnailUrl AS MasterImageUrl ,
  46. vimi.HandledUrl ,
  47. cAcc.DiscountCoef AS ClearanceDiscountCoef ,
  48. cAcc.Quantity AS ClearanceWhQty ,
  49. dAcc.DiscountCoef AS DiscountDiscountCoef ,
  50. dAcc.Quantity AS DiscountWhQty ,
  51. item.PriceType
  52. FROM shop_order.PurchaseOrderLine AS pol
  53. INNER JOIN basedata.Inventory item ON item.InventoryId = pol.InventoryId
  54. LEFT OUTER JOIN basedata.V_InventoryMasterImage AS vimi ON pol.ImageItemId = vimi.InventoryId
  55. LEFT OUTER JOIN dbo.ValueTextMap AS vtm ON vtm.Value = pol.LineStatus
  56. AND vtm.TableName = 'shop_order.PurchaseOrderLine'
  57. AND vtm.FieldName = 'LineStatus'
  58. LEFT JOIN clearance.ClearanceAcc cAcc ON pol.InventoryId = cAcc.InventoryId
  59. LEFT JOIN Discount.DiscountAcc dAcc ON pol.InventoryId = dAcc.InventoryId
  60. LEFT JOIN ( SELECT COUNT(1) ClosedTime ,
  61. VoucherId PurchaseOrderLineId ,
  62. SUM(Quantity) ClosedQuantity
  63. FROM [dbo].[VoucherProcess]
  64. WHERE tableName = 'shop_order.PurchaseOrderLine'
  65. GROUP BY VoucherId
  66. ) cl ON cl.PurchaseOrderLineId = pol.PurchaseOrderLineId
  67. GO