LogikalProfile.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 colors c2
  88. on trim(c2.[colorname]) = trim(Substr(p.[articlecode_ordercode],Instr(p.[articlecode_ordercode], '.') + 1))
  89. left outer join colors c
  90. on c.[colorid] = coalesce(c2.[ColorID],p.[lk_ColorID])
  91. left outer join
  92. suppliers s on p.[SupplierID] = s.[SupplierID]
  93. group by
  94. p.[ArticleCode],
  95. p.[Description],
  96. p.[Length],
  97. c.[ColorName],
  98. p.[ArticleType],
  99. coalesce(s.[CustomerNo],s.[ActiveTitle]),
  100. (p.[PriceGross]-p.[PriceCoating])*p.[Length],
  101. p.[Perimeter],
  102. p.[PerimeterBoundaryBox],
  103. p.[PriceGross]*p.[Length]
  104. ";
  105. }
  106. /* BillOf Materials
  107. select
  108. sum(p.[Amount]) as [{nameof(Quantity)}],
  109. d.[DiscountGroup] as [{nameof(Group)}],
  110. coalesce(s.[CustomerNo],s.[ActiveTitle]) as [{nameof(Supplier)}],
  111. p.[ArticleCode] as [{nameof(Code)}],
  112. p.[description] as [{nameof(Description)}],
  113. p.Perimeter as [{nameof(AnodizePerimeter)}],
  114. p.[PerimeterBoundaryBox] as [{nameof(PaintPerimeter)}],
  115. c.[ColorName] as [{nameof(Finish)}],
  116. p.[Length] as [{nameof(Length)}],
  117. (p.[PriceGross]-p.[PriceCoating])*p.[Length] as [{nameof(MillCost)}],
  118. p.[PriceGross]*p.[Length] as [{nameof(Cost)}]
  119. from
  120. profilebars p
  121. left outer join
  122. colors c on p.[lk_colorid] = c.[colorid]
  123. join
  124. estimationdiscounts d on p.[LK_DiscountId] = d.[EstimationDiscountID]
  125. left outer join
  126. suppliers s on p.[SupplierID] = s.[SupplierID]
  127. group by
  128. p.[ArticleCode],
  129. p.[Description],
  130. p.[Length],
  131. c.[ColorName],
  132. d.[DiscountGroup],
  133. coalesce(s.[CustomerNo],s.[ActiveTitle]),
  134. (p.[PriceGross]-p.[PriceCoating])*p.[Length],
  135. p.[Perimeter],
  136. p.[PerimeterBoundaryBox],
  137. p.[PriceGross]*p.[Length]
  138. */
  139. /* Designs
  140. */
  141. }