V6Profile.cs 3.1 KB

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