LogikalComponent.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using InABox.Integration.Logikal;
  2. using System;
  3. using System.Collections.Generic;
  4. namespace PRSDesktop.Integrations.Logikal
  5. {
  6. public class LogikalComponent : LogikalBOMItem, ILogikalComponent
  7. {
  8. public string Group { get; set; }
  9. public string Supplier { get; set; }
  10. public string Finish { get; set; }
  11. public double PackSize { get; set; }
  12. public override void ValidateQuery(string sql, List<string> errors)
  13. {
  14. base.ValidateQuery(sql, errors);
  15. ValidateField(sql, nameof(Group), errors);
  16. ValidateField(sql, nameof(Supplier), errors);
  17. ValidateField(sql, nameof(Finish), errors);
  18. ValidateField(sql, nameof(PackSize), errors);
  19. }
  20. public static String SQL =
  21. $@"select
  22. a.[ArticleCode_BaseNumber] as [{nameof(Code)}],
  23. a.[description] as [{nameof(Description)}],
  24. upper(case c.[ColorTypeSupplier]
  25. when -1 then
  26. case coalesce(c.[PowderID],'')
  27. when '' then c.[ColorName]
  28. else case coalesce(c.[Thickness],'')
  29. when '' then c.[PowderID]
  30. else printf('%s-%s',c.[PowderID],c.[Thickness])
  31. end
  32. end
  33. else c.[ColorName]
  34. end) as [{nameof(Finish)}],
  35. a.[pusize] as [{nameof(PackSize)}],
  36. case a.[ArticleType]
  37. when 1 then 'Profiles'
  38. when 2 then 'Profiles'
  39. when 5 then 'Gasket'
  40. when 7 then 'Gasket'
  41. when 8 then 'Components'
  42. when 16 then 'Components'
  43. when 18 then 'Components'
  44. when 30 then 'Fills'
  45. else '???'
  46. end as [{nameof(Group)}],
  47. coalesce(s.[CustomerNo],s.[ActiveTitle]) as [{nameof(Supplier)}],
  48. sum(a.[units]/a.[pusize]) as [{nameof(Quantity)}],
  49. a.[Price]*a.[pusize] as [{nameof(Cost)}]
  50. from
  51. articles a
  52. join
  53. insertions i on a.[insertionid] = i.[insertionid]
  54. join
  55. elevations e on i.[elevationid] = e.[elevationid]
  56. left outer join
  57. suppliers s on a.[LK_SupplierID] = s.[SupplierID]
  58. left outer join colors c2
  59. on trim(c2.[colorname]) = trim(Substr(a.[articlecode_ordercode],Instr(a.[articlecode_ordercode], '.') + 1))
  60. left outer join colors c
  61. on c.[colorid] = coalesce(c2.[ColorID],a.[lk_ColorID])
  62. where
  63. a.[ArticleType] not in (5,7)
  64. group by
  65. a.[ArticleCode_BaseNumber],
  66. a.[description],
  67. a.[Price],
  68. a.[ArticleType],
  69. coalesce(s.[CustomerNo],s.[ActiveTitle])";
  70. }
  71. /*
  72. select
  73. a.[ArticleCode_BaseNumber] as [{nameof(Code)}],
  74. a.[description] as [{nameof(Description)}],
  75. a.[pusize] as [{nameof(PackSize)}],
  76. d.[DiscountGroup] as [{nameof(Group)}],
  77. coalesce(s.[CustomerNo],s.[ActiveTitle]) as [{nameof(Supplier)}],
  78. sum(a.[units]/a.[pusize]) as [{nameof(Quantity)}],
  79. a.[Price]*a.[pusize] as [{nameof(Cost)}]
  80. from
  81. articles a
  82. join
  83. insertions i on a.[insertionid] = i.[insertionid]
  84. join
  85. elevations e on i.[elevationid] = e.[elevationid]
  86. join
  87. estimationdiscounts d on a.[LK_DiscountID] = d.[EstimationDiscountID]
  88. left outer join
  89. suppliers s on a.[LK_SupplierID] = s.[SupplierID]
  90. where
  91. a.[ArticleType] not in (5,7)
  92. group by
  93. a.[ArticleCode_BaseNumber],
  94. a.[description],
  95. a.[Price],
  96. d.[DiscountGroup],
  97. coalesce(s.[CustomerNo],s.[ActiveTitle])
  98. */
  99. }