LogikalProfile.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. using InABox.Core;
  2. using InABox.Integration.Logikal;
  3. using System;
  4. using System.Collections.Generic;
  5. namespace PRSDesktop.Integrations.Logikal
  6. {
  7. public class LogikalProfile : LogikalBOMItem, ILogikalProfile
  8. {
  9. public double Length { get; set; }
  10. public double PaintPerimeter { get; set; }
  11. public double AnodizePerimeter { get; set; }
  12. public double MillCost { get; set; }
  13. public string Group { get; set; }
  14. public string Supplier { get; set; }
  15. public string? Finish { get; set; }
  16. public override void ValidateQuery(string sql, List<string> errors)
  17. {
  18. base.ValidateQuery(sql, errors);
  19. ValidateField(sql, nameof(Length), errors);
  20. ValidateField(sql, nameof(Finish), errors);
  21. ValidateField(sql, nameof(Group), errors);
  22. ValidateField(sql, nameof(Supplier), errors);
  23. ValidateField(sql, nameof(PaintPerimeter), errors);
  24. ValidateField(sql, nameof(AnodizePerimeter), errors);
  25. ValidateField(sql, nameof(MillCost), errors);
  26. }
  27. public static String DesignSQL =
  28. $@"select
  29. p.[ArticleCode_BaseNumber] as [{nameof(Code)}],
  30. p.[description] as [{nameof(Description)}],
  31. upper(case c.[ColorTypeSupplier]
  32. when -1 then
  33. case coalesce(c.[PowderID],'')
  34. when '' then c.[ColorName]
  35. else case coalesce(c.[Thickness],'')
  36. when '' then c.[PowderID]
  37. else printf('%s-%s',c.[PowderID],c.[Thickness])
  38. end
  39. end
  40. else c.[ColorName]
  41. end) as [{nameof(Finish)}],
  42. p.[length_output] as [{nameof(Length)}],
  43. p.Perimeter as [{nameof(AnodizePerimeter)}],
  44. p.[PerimeterBoundaryBox] as [{nameof(PaintPerimeter)}],
  45. p.[Amount] as [{nameof(Quantity)}],
  46. case p.[ArticleType] when 1 then 'Profiles' when 2 then 'Profiles' when 5 then 'Gasket' when 7 then 'Gasket' when 8 then 'Components' when 16 then 'Components' when 18 then 'Components' when 30 then 'Fills' else '???' end as [{nameof(Group)}],
  47. p.[Price] as [{nameof(Cost)}],
  48. (p.[PriceGross]-p.[PriceCoating]) as [{nameof(MillCost)}],
  49. coalesce(s.[CustomerNo],s.[ActiveTitle]) as [{nameof(Supplier)}]
  50. from
  51. profiles p
  52. left outer join colors c2
  53. on trim(c2.[colorname]) = trim(Substr(p.[articlecode_ordercode],Instr(p.[articlecode_ordercode], '.') + 1))
  54. left outer join colors c
  55. on c.[colorid] = coalesce(c2.[ColorID],p.[lk_ColorID])
  56. join
  57. insertions i on p.[insertionid] = i.[insertionid]
  58. join
  59. elevations e on i.[elevationid] = e.[elevationid]
  60. left outer join
  61. suppliers s on p.[LK_SupplierID] = s.[SupplierID]";
  62. public static String BillOfMaterialsSQL =
  63. $@"select
  64. sum(p.[Amount]) as [{nameof(Quantity)}],
  65. case p.[ArticleType] when 2 then 'Profiles' when 5 then 'Gasket' when 8 then 'Components' when 30 then 'Fills' else '???' end as [{nameof(Group)}],
  66. coalesce(s.[CustomerNo],s.[ActiveTitle]) as [{nameof(Supplier)}],
  67. p.[ArticleCode_BaseNumber] as [{nameof(Code)}],
  68. p.[description] as [{nameof(Description)}],
  69. p.Perimeter as [{nameof(AnodizePerimeter)}],
  70. p.[PerimeterBoundaryBox] as [{nameof(PaintPerimeter)}],
  71. upper(case c.[ColorTypeSupplier]
  72. when -1 then
  73. case coalesce(c.[PowderID],'')
  74. when '' then c.[ColorName]
  75. else case coalesce(c.[Thickness],'')
  76. when '' then c.[PowderID]
  77. else printf('%s-%s',c.[PowderID],c.[Thickness])
  78. end
  79. end
  80. else c.[ColorName]
  81. end) as [{nameof(Finish)}],
  82. p.[Length] as [{nameof(Length)}],
  83. (p.[PriceGross]-p.[PriceCoating])*p.[Length] as [{nameof(MillCost)}],
  84. p.[PriceGross]*p.[Length] as [{nameof(Cost)}]
  85. from
  86. profilebars p
  87. left outer join
  88. colors c on p.[lk_colorid] = c.[colorid]
  89. left outer join
  90. suppliers s on p.[SupplierID] = s.[SupplierID]
  91. group by
  92. p.[ArticleCode],
  93. p.[Description],
  94. p.[Length],
  95. c.[ColorName],
  96. p.[ArticleType],
  97. coalesce(s.[CustomerNo],s.[ActiveTitle]),
  98. (p.[PriceGross]-p.[PriceCoating])*p.[Length],
  99. p.[Perimeter],
  100. p.[PerimeterBoundaryBox],
  101. p.[PriceGross]*p.[Length]
  102. ";
  103. }
  104. /* BillOf Materials
  105. select
  106. sum(p.[Amount]) as [{nameof(Quantity)}],
  107. d.[DiscountGroup] as [{nameof(Group)}],
  108. coalesce(s.[CustomerNo],s.[ActiveTitle]) as [{nameof(Supplier)}],
  109. p.[ArticleCode] as [{nameof(Code)}],
  110. p.[description] as [{nameof(Description)}],
  111. p.Perimeter as [{nameof(AnodizePerimeter)}],
  112. p.[PerimeterBoundaryBox] as [{nameof(PaintPerimeter)}],
  113. c.[ColorName] as [{nameof(Finish)}],
  114. p.[Length] as [{nameof(Length)}],
  115. (p.[PriceGross]-p.[PriceCoating])*p.[Length] as [{nameof(MillCost)}],
  116. p.[PriceGross]*p.[Length] as [{nameof(Cost)}]
  117. from
  118. profilebars p
  119. left outer join
  120. colors c on p.[lk_colorid] = c.[colorid]
  121. join
  122. estimationdiscounts d on p.[LK_DiscountId] = d.[EstimationDiscountID]
  123. left outer join
  124. suppliers s on p.[SupplierID] = s.[SupplierID]
  125. group by
  126. p.[ArticleCode],
  127. p.[Description],
  128. p.[Length],
  129. c.[ColorName],
  130. d.[DiscountGroup],
  131. coalesce(s.[CustomerNo],s.[ActiveTitle]),
  132. (p.[PriceGross]-p.[PriceCoating])*p.[Length],
  133. p.[Perimeter],
  134. p.[PerimeterBoundaryBox],
  135. p.[PriceGross]*p.[Length]
  136. */
  137. /* Designs
  138. */
  139. }