Advertisement
isotonicq

Untitled

Feb 9th, 2021
564
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.05 KB | None | 0 0
  1. using System.Linq;
  2. using BST.LionMarrodentWorkers.Extensions;
  3. using BST.LionMarrodentWorkers.Triggery;
  4. using Soneta.Business;
  5. using Soneta.Business.Db;
  6. using Soneta.Handel;
  7. using Soneta.Towary;
  8. using Soneta.Types;
  9.  
  10. [assembly: ModuleType("DiscountTriggerModule", typeof(DiscountTriggerModule), 4, "", 0)]
  11.  
  12. namespace BST.LionMarrodentWorkers.Triggery
  13. {
  14.     public sealed class DiscountTriggerModule : Module
  15.     {
  16.         //CTOR
  17.         public DiscountTriggerModule(Session session) : base(session)
  18.         {
  19.             DiscountTrigger trigger = new DiscountTrigger();
  20.         }
  21.     }
  22.  
  23.     public sealed class DiscountTrigger
  24.     {
  25.         //CTOR
  26.         static DiscountTrigger()
  27.         {
  28.             HandelModule.PozycjaDokHandlowegoSchema.AddTowarAfterEdit(ProductEdit);
  29.         }
  30.        
  31.         //Private
  32.         private static void ProductEdit(HandelModule.PozycjaDokHandlowegoRow row)
  33.         {
  34.             if (row.Session.Login.Operator.Features.GetBool("CZ_User") && row.Dokument.Bufor && row.Towar != null && row.Dokument.Kontrahent != null)
  35.             {
  36.                 if (row.Towar.HlavniSkupina() && row.Dokument.IsCzechSaleOrder())
  37.                 {
  38.                     row.Rabat = Percent.Zero;
  39.                 }
  40.                 else
  41.                 {
  42.                           //Variables
  43.                     BusinessModule bm = BusinessModule.GetInstance(row.Session);
  44.                     TowaryModule tm = TowaryModule.GetInstance(row.Session);
  45.                     Percent max = Percent.Zero;
  46.                    
  47.                     //Check product group
  48.                     DictionaryItem item = bm.Dictionary.CreateView()
  49.                         ?.OriginalSubTable[new FieldCondition.Equal("Category", "F.CZ_GroupOfGood")]
  50.                         ?.Cast<DictionaryItem>()
  51.                         ?.FirstOrDefault(x=> x.Value == row.Towar.Features.GetString("CZ_GroupOfGoods").Replace(@"\", string.Empty));
  52.                    
  53.                     if (item != null)
  54.                     {
  55.                         SubTable<CenaGrupowa> discounts = tm.CenyGrupowe.WgGrupaTowarowa[item, row.Dokument.Kontrahent];
  56.                    
  57.                         if (discounts != null && discounts.Any())
  58.                         {
  59.                             Percent tempMax = discounts.Max(x => x.Rabat);
  60.                    
  61.                             if (tempMax > max)
  62.                             {
  63.                                 max = tempMax;
  64.                             }
  65.                         }
  66.                     }
  67.                    
  68.                     //Check manufacturer
  69.                     DictionaryItem item2 =  bm.Dictionary.CreateView()
  70.                         ?.OriginalSubTable[new FieldCondition.Equal("Category", "F.CZ_Manufacture")]
  71.                         ?.Cast<DictionaryItem>()
  72.                         ?.FirstOrDefault(x=> x.Value == row.Towar.Features.GetString("CZ_Manufacturer").Replace(@"\", string.Empty));
  73.  
  74.                     if (item2 != null)
  75.                     {
  76.                         SubTable<CenaGrupowa> discounts = tm.CenyGrupowe.WgGrupaTowarowa[item2, row.Dokument.Kontrahent];
  77.                    
  78.                         if (discounts != null && discounts.Any())
  79.                         {
  80.                             Percent tempMax = discounts.Max(x => x.Rabat);
  81.                    
  82.                             if (tempMax > max)
  83.                             {
  84.                                 max = tempMax;
  85.                             }
  86.                         }
  87.                     }
  88.  
  89.                     //Check period general
  90.                     RowCondition rc = new FieldCondition.GreaterEqual("PrzecenaOkresowa.Okres.To", row.Dokument.Data);
  91.                     rc &= new FieldCondition.LessEqual("PrzecenaOkresowa.Okres.From", row.Dokument.Data);
  92.                     rc &= new FieldCondition.Null("PrzecenaOkresowa.Kontrahent", true);
  93.  
  94.                     SubTable<PrzecenaOkresowaTowaru> discounts2 = tm.PrzecenyOkresTwr.WgTowar[row.Towar][rc];
  95.  
  96.                     if (discounts2 != null && discounts2.Any)
  97.                     {
  98.                         foreach (PrzecenaOkresowaTowaru discount in discounts2)
  99.                         {
  100.                             if (discount.Rabat > max)
  101.                             {
  102.                                 max = discount.Rabat;
  103.                             }
  104.                         }
  105.                     }
  106.                    
  107.                     //Check manufacturer and period individual
  108.                     RowCondition rc2 = new FieldCondition.GreaterEqual("Okres.To", row.Dokument.Data);
  109.                     rc2 &= new FieldCondition.LessEqual("Okres.From", row.Dokument.Data);
  110.                    
  111.                     SubTable<PrzecenaOkresowa> discounts3 = tm.PrzecenyOkres.WgKontrahent[row.Dokument.Kontrahent][rc2];
  112.                    
  113.                     if (discounts3 != null && discounts3.Any)
  114.                     {
  115.                         foreach (PrzecenaOkresowa discount in discounts3)
  116.                         {
  117.                             SubTable<PrzecenaOkresowaTowaru> productDiscounts = discount.PrzecenyTowarow[new FieldCondition.Equal("Towar.Guid", row.Towar.Guid)];
  118.                    
  119.                             if (!productDiscounts.Any) continue;
  120.                    
  121.                             Percent tempMax = productDiscounts.Max(x => x.Rabat);
  122.                    
  123.                             if (tempMax > max)
  124.                             {
  125.                                 max = tempMax;
  126.                             }
  127.                         }
  128.                     }
  129.  
  130.                     if (row.Dokument.Kontrahent != null && row.Dokument.Kontrahent.Rabat > max)
  131.                     {
  132.                         max = row.Dokument.Kontrahent.Rabat;
  133.                     }
  134.                    
  135.                     if (max != Percent.Zero && row.Rabat != max)
  136.                     {
  137.                         row.Rabat = max;
  138.                     }
  139.                 }
  140.             }
  141.         }
  142.     }
  143. }
  144.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement