V6Profile.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using System;
  2. using System.Collections.Generic;
  3. using InABox.Integration.V6;
  4. namespace PRSDesktop.Integrations.V6
  5. {
  6. public class V6Profile : V6BOMItem, IV6Profile
  7. {
  8. public double Length { get; set; }
  9. public double PaintPerimeter { get; set; }
  10. public double AnodizePerimeter { get; set; }
  11. public double MillCost { get; set; }
  12. public string Group { get; set; }
  13. public string Supplier { get; set; }
  14. public string Finish { get; set; }
  15. public override void ValidateQuery(string sql, List<string> errors)
  16. {
  17. base.ValidateQuery(sql, errors);
  18. ValidateField(sql, nameof(Length), errors);
  19. ValidateField(sql, nameof(Finish), errors);
  20. ValidateField(sql, nameof(Group), errors);
  21. ValidateField(sql, nameof(PaintPerimeter), errors);
  22. ValidateField(sql, nameof(AnodizePerimeter), errors);
  23. ValidateField(sql, nameof(MillCost), errors);
  24. ValidateField(sql, nameof(Supplier), errors);
  25. }
  26. public static String BillOfMaterialsSQL = $@"
  27. select
  28. e.EXTN_CODE as {nameof(Code)},
  29. e.DESCR as {nameof(Description)},
  30. f.FINCOL_CODE as {nameof(Finish)},
  31. '' as {nameof(Group)},
  32. '' as {nameof(Supplier)},
  33. bb.bar_length as {nameof(Length)},
  34. bb.bars as {nameof(Quantity)},
  35. bb.cost as {nameof(Cost)}
  36. from
  37. bom_cutplan bc
  38. join extn e on bc.EXTN_LIB_ID = e.EXTN_LIB_ID
  39. and bc.EXTN_ID = e.EXTN_ID
  40. join fincol f on bc.FINCOL_LIB_ID = f.FINCOL_LIB_ID
  41. and bc.FINCOL_ID = f.FINCOL_ID
  42. join (
  43. select
  44. BOM_CUTPLAN_ID,
  45. BAR_LENGTH,
  46. COST * bar_length as cost,
  47. count(*) as bars
  48. from
  49. bom_bar
  50. group by
  51. BOM_CUTPLAN_ID,
  52. bar_length,
  53. cost
  54. ) bb on bb.BOM_CUTPLAN_ID = bc.BOM_CUTPLAN_ID
  55. join (
  56. select
  57. distinct bcp.BOM_CUTPLAN_ID,
  58. q.QUOTE_ID,
  59. q.quote_num,
  60. q.QUOTE_NUM_SUFF,
  61. q.quote_vers
  62. from
  63. bom_cutplan_piece bcp
  64. join bom_piece bp on bcp.BOM_PIECE_ID = bp.BOM_PIECE_ID
  65. join quote_item qi on bp.QUOTE_ITEM_ID = qi.QUOTE_ITEM_ID
  66. join quote q on qi.QUOTE_ID = q.QUOTE_ID
  67. and qi.quote_vers_start <= q.quote_vers and qi.quote_vers_stop >= q.quote_vers
  68. ) q on q.BOM_CUTPLAN_ID = bc.BOM_CUTPLAN_ID
  69. where 1=1
  70. UNION
  71. SELECT
  72. e.extn_code as {nameof(Code)},
  73. e.descr as {nameof(Description)},
  74. f.FINCOL_CODE as {nameof(Finish)},
  75. bp.piece_length as {nameof(Length)},
  76. sum(bp.piece_count) as {nameof(Quantity)},
  77. bp.COST as {nameof(Cost)}
  78. FROM bom_piece bp
  79. join fincol f on bp.FINCOL_LIB_ID = f.FINCOL_LIB_ID and bp.FINCOL_ID = f.FINCOL_ID
  80. join extn e on e.extn_lib_id = bp.EXTN_LIB_ID and e.extn_id = bp.extn_id
  81. join quote_item qi on bp.QUOTE_ITEM_ID = qi.QUOTE_ITEM_ID
  82. join quote q on qi.quote_id = q.quote_id
  83. where 1=1
  84. and qi.quote_vers_start <= q.quote_vers and qi.quote_vers_stop >= q.quote_vers
  85. and bp.PIECE_TAG='C'
  86. group by e.extn_code, e.descr, f.FINCOL_CODE, bp.PIECE_LENGTH, bp.cost
  87. ";
  88. public static String DesignSQL = $@"
  89. select
  90. e.extn_code as {nameof(Code)},
  91. e.descr as {nameof(Description)},
  92. fc.fincol_code as {nameof(Finish)},
  93. round(bp.piece_length,2,1) as {nameof(Length)},
  94. e.cost_length * round(bp.piece_length,2,1) as {nameof(Cost)},
  95. sum(bp.PIECE_COUNT) as {nameof(Quantity)}
  96. from
  97. bom_piece bp
  98. join
  99. quote_item qi on bp.quote_item_id = qi.quote_item_id
  100. left outer join
  101. fincol fc on bp.fincol_lib_id = fc.fincol_lib_id and bp.fincol_id = fc.fincol_id
  102. join
  103. extn e on bp.extn_lib_id = e.extn_lib_id and bp.extn_id = e.extn_id
  104. where
  105. 1=1
  106. group by
  107. e.extn_code,
  108. e.descr,
  109. fc.fincol_code,
  110. bp.piece_length,
  111. e.cost_length
  112. ";
  113. }
  114. }