Advertisement
isotonicq

Untitled

Apr 20th, 2021
618
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.06 KB | None | 0 0
  1. using BST.LionMarrodentWorkers.UI.Kontrahenci.Extenders;
  2. using Soneta.Business;
  3. using Soneta.CRM;
  4. using Soneta.Towary;
  5. using Soneta.Types;
  6.  
  7. [assembly: Worker(typeof(CzDiscountExtender))]
  8.  
  9. namespace BST.LionMarrodentWorkers.UI.Kontrahenci.Extenders
  10. {
  11.     public sealed class CzDiscountExtender : ISessionable
  12.     {
  13.         //Context
  14.         [Context] public Kontrahent Counterparty { get; set; }
  15.         [Context] public Session Session { get; set; }
  16.        
  17.         //Public - get - properties
  18.         public Percent FlatDiscount => Counterparty?.Rabat ?? Percent.Zero;
  19.         public ViewInfo Group => GetGroupDiscounts();
  20.         public ViewInfo Manufacturer => GetManufacturerDiscounts();
  21.         public ViewInfo Individual => GetIndividualDiscounts();
  22.         public ViewInfo Periodic => GetPeriodicDiscounts();
  23.  
  24.         //Private - methods
  25.         private ViewInfo GetGroupDiscounts()
  26.         {
  27.             ViewInfo vi = new ViewInfo();
  28.  
  29.             vi.CreateView += (sender, args) =>
  30.             {
  31.                 args.View = TowaryModule.GetInstance(args.Session).CenyGrupowe
  32.                     .WgKontrahent[Counterparty][x => x.RabatZdefiniowany && x.GrupaTowarowa.Category == "F.CZ_GroupOfGood"]
  33.                     .CreateView();
  34.             };
  35.            
  36.             return vi;
  37.         }
  38.  
  39.         private ViewInfo GetManufacturerDiscounts()
  40.         {
  41.             ViewInfo vi = new ViewInfo();
  42.            
  43.             vi.CreateView += (sender, args) =>
  44.             {
  45.                 args.View = TowaryModule.GetInstance(args.Session).CenyGrupowe
  46.                     .WgKontrahent[Counterparty][x => x.RabatZdefiniowany && x.GrupaTowarowa.Category == "F.CZ_Manufacture"]
  47.                     .CreateView();
  48.             };
  49.            
  50.             return vi;        
  51.         }
  52.        
  53.         private ViewInfo GetIndividualDiscounts()
  54.         {
  55.             ViewInfo vi = new ViewInfo();
  56.            
  57.             vi.CreateView += (sender, args) =>
  58.             {
  59.                 args.View = TowaryModule.GetInstance(Session).CenyIndywidualne
  60.                     .WgKontrahent[Counterparty]
  61.                     .CreateView();
  62.             };
  63.            
  64.             return vi;
  65.         }
  66.        
  67.         private ViewInfo GetPeriodicDiscounts()
  68.         {
  69.             ViewInfo vi = new ViewInfo();
  70.            
  71.             vi.CreateView += (sender, args) =>
  72.             {
  73.                 RowCondition rc = new FieldCondition.Equal("PrzecenaOkresowa.Zatwierdzona", true);
  74.                 rc &= new FieldCondition.LessEqual("PrzecenaOkresowa.Okres.From", Date.Today);
  75.                 rc &= new FieldCondition.GreaterEqual("PrzecenaOkresowa.Okres.To", Date.Today);
  76.                 rc &= new RowCondition.Or(new FieldCondition.Null("PrzecenaOkresowa.Kontrahent", true),
  77.                     new FieldCondition.Equal("PrzecenaOkresowa.Kontrahent.Guid", Counterparty.Guid));
  78.  
  79.                 args.View = TowaryModule.GetInstance(Session).PrzecenyOkresTwr.WgTowar[rc].CreateView();
  80.             };
  81.            
  82.             return vi;
  83.         }
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement