Пример #1
0
        public decimal?GetWartoscZakupuAbak(EnovaContext ec)
        {
            var podrzedny = this.RelacjeHandloweNadrzedny.Where(r => r.Definicja.ID == 3).Select(r => r.Podrzedny).FirstOrDefault();

            if (podrzedny != null)
            {
                decimal?zakup = 0;
                foreach (var pozycja in podrzedny.PozycjeDokHan.ToList())
                {
                    var tmp = ec.Features.Where(f => f.ParentType == "PozycjeDokHan" && f.Parent == pozycja.ID && f.Name == "Prowizja").Select(f => f.Data).FirstOrDefault();
                    if (tmp == null || string.IsNullOrEmpty(tmp.Trim()))
                    {
                        zakup += ec.Obroty.Where(o => o.RozchodDokument.ID == podrzedny.ID && o.RozchodPozycjaIdent == pozycja.Ident).Sum(o => o.PrzychodWartosc);
                    }
                    else
                    {
                        double?ilosc = ec.Obroty.Where(o => o.RozchodDokument.ID == podrzedny.ID && o.RozchodPozycjaIdent == pozycja.Ident).Sum(p => p.IloscValue);
                        if (ilosc != null)
                        {
                            zakup += decimal.Parse(tmp.Trim().Replace('.', ',')) * (decimal)ilosc;
                        }
                    }
                }
                return(zakup);
            }
            return(null);
        }
Пример #2
0
        public override void ApplyFeatureFilter(FeatureDef featureDef, string value)
        {
            if (DataContext != null)
            {
                Enova.Business.Old.DB.EnovaContext dc = DataContext as Enova.Business.Old.DB.EnovaContext;
                string name = featureDef.Name;

                if (featureDef.IsTree)
                {
                    BaseQuery = (ObjectQuery <TowarRow>)(from t in query
                                                         from f in dc.Features
                                                         where t.ID == f.Parent && f.ParentType == "Towary" && f.Name == name && f.Data.StartsWith(value)
                                                         group t by t.ID into ut
                                                         select ut.FirstOrDefault());
                }
                else
                {
                    BaseQuery = (ObjectQuery <TowarRow>)(from t in query
                                                         from f in dc.Features
                                                         where t.ID == f.Parent && f.ParentType == "Towary" && f.Name == name && f.Data == value
                                                         select t);
                }
            }
            base.ApplyFeatureFilter(featureDef, value);
        }
Пример #3
0
        public decimal GetRabat(EnovaContext ec, string towarKod)
        {
            decimal rabat = this.Rabat != null ? this.Rabat.Value : 0;

            var features = (from f in ec.Features
                            join t in ec.Towary on
                            new { ParentType = f.ParentType, Parent = f.Parent } equals
                            new { ParentType = "Towary", Parent = t.ID }
                            where t.Kod == towarKod
                            select f).ToList();

            foreach (var feature in features)
            {
                var fdef = ec.FeatureDefs.Where(fd => fd.TableName == "Towary" && fd.Name == feature.Name).FirstOrDefault();
                if (fdef != null && fdef.Group == true && fdef.StrictDictionary == true)
                {
                    var dict = ec.DictionarySet.Where(d => d.Category == "F." + fdef.Dictionary && d.Value == feature.Data).FirstOrDefault();
                    if (dict != null)
                    {
                        var cenaGrupowa = this.CenyGrupowe.Where(cg => cg.GrupaTowarowa.ID == dict.ID).FirstOrDefault();
                        if (cenaGrupowa != null && cenaGrupowa.RabatZdefiniowany == true)
                        {
                            rabat = cenaGrupowa.Rabat.Value;
                        }
                    }
                }
            }

            return(rabat);
        }
Пример #4
0
        public bool SaveChanges()
        {
            EnovaContext dc = ContextManager.DataContext;

            if (this.EntityState == EntityState.Detached || this.EntityState == EntityState.Added)
            {
                if (this.EntityState == EntityState.Detached)
                {
                    dc.AddToDictionarySet(this);
                }

                if (Enova.Business.Old.DB.Web.User.LoginedUser.EnovaOperator != null)
                {
                    ChangeInfo ci = new ChangeInfo()
                    {
                        Operator    = Enova.Business.Old.DB.Web.User.LoginedUser.EnovaOperator,
                        SourceGuid  = this.Guid,
                        SourceTable = "Dictionary",
                        Type        = 1,
                        Time        = DateTime.Now,
                        Info        = string.Empty
                    };
                    dc.AddToChangeInfos(ci);
                }
            }

            dc.SaveChanges();

            return(true);
        }
Пример #5
0
        private void deleteDictionary(EnovaContext dc, Dictionary dic)
        {
            var sub = dc.DictionarySet.Where(d => d.ParentID == this.ID).ToList();

            foreach (var s in sub)
            {
                deleteDictionary(dc, s);
            }

            dc.DeleteObject(this);

            if (Enova.Business.Old.DB.Web.User.LoginedUser.EnovaOperator != null)
            {
                ChangeInfo ci = new ChangeInfo()
                {
                    Operator    = Enova.Business.Old.DB.Web.User.LoginedUser.EnovaOperator,
                    SourceGuid  = this.Guid,
                    SourceTable = "Dictionary",
                    Type        = 4,
                    Time        = DateTime.Now,
                    Info        = this.Value,
                };

                dc.AddToChangeInfos(ci);
            }
        }
Пример #6
0
        public bool DeleteRecord()
        {
            EnovaContext dc = ContextManager.DataContext;

            deleteDictionary(dc, this);

            dc.SaveChanges();

            return(true);
        }
Пример #7
0
        public decimal?GetDochodAbak(EnovaContext ec)
        {
            decimal?zakup = GetWartoscZakupuAbak(ec);

            if (zakup != null)
            {
                return(this.SumaNetto - zakup);
            }
            return(null);
        }
Пример #8
0
        public string GetSuffix(EnovaContext dc)
        {
            var feature = GetFeatures(dc, "SUFFIX").FirstOrDefault();

            if (feature != null)
            {
                return(feature.Data);
            }
            return(string.Empty);
        }
Пример #9
0
        public decimal?GetProwizja(EnovaContext ec, decimal procent)
        {
            decimal?dochod = GetDochodAbak(ec);

            if (dochod != null)
            {
                return(decimal.Round(dochod.Value * procent, 2));
            }
            return(null);
        }
Пример #10
0
        public DateTime?GetDataRozliczenia(EnovaContext ec)
        {
            decimal?rozliczono = this.GetPlatnosci(ec).Sum(p => p.KwotaRozliczonaValue);

            if (rozliczono == this.SumaBrutto)
            {
                return(this.GetPlatnosci(ec).Max(p => p.DataRozliczenia));
            }
            return(null);
        }
Пример #11
0
        public static decimal GetRabat(EnovaContext ec, Guid kontrahentGuid, string towarKod)
        {
            Kontrahent kontrahent = ec.Kontrahenci.Where(k => k.Guid == kontrahentGuid).FirstOrDefault();

            if (kontrahent != null)
            {
                return(kontrahent.GetRabat(ec, towarKod));
            }
            return(0);
        }
Пример #12
0
        private void inicjujAlgorytmZaokraglania(EnovaContext ec)
        {
            var        f     = GetFeatures(ec, "ALG_ZAOK_OBR").FirstOrDefault();
            MethodInfo minfo = null;

            if (f != null && !string.IsNullOrEmpty(f.Data.Trim()))
            {
                minfo = ToMethod(f.Data, new Type[] { typeof(double) }, new string[] { "ilosc" }, typeof(double));
            }
            algorytmyZaogrąglaniaObrotów[this.ID] = minfo;
        }
Пример #13
0
 public bool GetOgraniczenieSprzedazyWlaczone(EnovaContext dc)
 {
     if (dc != null)
     {
         Feature feature = this.Features.Where(f => f.Name == "OGRANICZENIE SPRZEDAŻY").FirstOrDefault();
         if (feature != null && feature.Data.Trim() == "1")
         {
             return(true);
         }
     }
     return(false);
 }
Пример #14
0
        public bool GetNowosc(EnovaContext dc)
        {
            var feature = GetFeatures(dc, "NOWOŚĆ").FirstOrDefault();

            if (feature != null)
            {
                if (feature.Data.Trim() == "1")
                {
                    return(true);
                }
            }
            return(false);
        }
Пример #15
0
 public int GetOraniczenieSprzedazyStan(EnovaContext dc)
 {
     if (dc != null)
     {
         Feature feature = this.Features.Where(f => f.Name == "STAN MAGAZYNU").FirstOrDefault();
         int     i       = 0;
         if (feature != null && int.TryParse(feature.Data, out i))
         {
             return(i);
         }
     }
     return(0);
 }
Пример #16
0
        public Towar GetTowarObliczObrotyZ(EnovaContext dc)
        {
            var feature = dc.Features.Where(f => f.ParentType == "Towary" && f.Parent == this.ID && f.Name == "OBLICZ OBROTY Z").FirstOrDefault();

            if (feature != null)
            {
                int id = 0;
                if (int.TryParse(feature.Data.Trim(), out id))
                {
                    return(dc.Towary.Where(t => t.ID == id).FirstOrDefault());
                }
            }
            return(null);
        }
Пример #17
0
        public double GetProcentObrotow(EnovaContext dc)
        {
            var feature = GetFeatures(dc, "PROCENT OBROTÓW").FirstOrDefault();

            if (feature != null)
            {
                double d;
                if (double.TryParse(feature.Data.Replace('.', ','), out d))
                {
                    return(d == 0 ? 1 : d);
                }
            }
            return(1);
        }
Пример #18
0
 public void SetOgraniczenieSprzedazyStan(EnovaContext ec, Web.WebContext lc, int stanMagazynu)
 {
     if (ec != null)
     {
         Feature feature = this.Features.Where(f => f.Name == "STAN MAGAZYNU").FirstOrDefault();
         if (feature != null)
         {
             feature.Data = stanMagazynu.ToString();
             ec.SaveChanges();
             if (stanMagazynu <= 0)
             {
                 this.UstawDostepnosc(ec, lc, false);
             }
         }
     }
 }
Пример #19
0
        public bool ZaokragnijObroty(EnovaContext ec, ref double ilosc)
        {
            if (!algorytmyZaogrąglaniaObrotów.ContainsKey(this.ID))
            {
                inicjujAlgorytmZaokraglania(ec);
            }

            MethodInfo minfo = algorytmyZaogrąglaniaObrotów[this.ID];

            if (minfo != null)
            {
                ilosc = (double)minfo.Invoke(null, new object[] { ilosc });
                return(true);
            }
            return(false);
        }
Пример #20
0
        public bool DeleteRecord()
        {
            if (Enova.Business.Old.DB.Web.User.LoginedUser.CheckPerissions(true, null))
            {
                EnovaContext dc = Enova.Business.Old.Core.ContextManager.DataContext;
                dc.DeleteObject(this);
                foreach (var fe in dc.Features.Where(f => f.ParentType == "Kontrahenci" && f.Parent == this.ID).ToList())
                {
                    dc.DeleteObject(fe);
                }

                Operator op = null;
                if (!string.IsNullOrEmpty(Enova.Business.Old.DB.Web.User.LoginedUser.EnovaOperatorLogin))
                {
                    op = dc.OperatorByName(Enova.Business.Old.DB.Web.User.LoginedUser.EnovaOperatorLogin);
                }
                else
                {
                    op = dc.OperatorByName(Enova.Business.Old.DB.Web.User.LoginedUser.Login);
                }

                if (op != null)
                {
                    dc.AddToChangeInfos(new ChangeInfo()
                    {
                        Operator    = op,
                        SourceGuid  = this.Guid,
                        SourceTable = "Kontrahenci",
                        Type        = (int)Enova.Business.Old.Types.ChangeInfoType.Deleted,
                        Time        = DateTime.Now,
                        Info        = this.Nazwa + " (" + this.Kod + ")"
                    });
                }

                foreach (var k in this.KontaktyOsoby)
                {
                    if (k.EntityState != EntityState.Deleted && k.EntityState != EntityState.Detached)
                    {
                        ContextManager.DataContext.DeleteObject(k);
                    }
                }

                dc.SaveChanges();
            }
            return(true);
        }
Пример #21
0
        public decimal?GetPotracenia(EnovaContext ec, decimal procent)
        {
            DateTime termin = TerminGraniczny;

            if (DateTime.Now < termin)
            {
                return(null);
            }
            var feature = GetFeatures(ec).Where(f => f.Name == "NIE LICZ POTRACEN").FirstOrDefault();

            if (feature == null || feature.Data.Trim() == "0")
            {
                decimal?prowizja = GetProwizja(ec, procent);
                if (prowizja != null)
                {
                    decimal rozliczono = 0;
                    foreach (var platnosc in GetPlatnosci(ec).ToList())
                    {
                        if (platnosc.Rozliczenia.Count() > 0)
                        {
                            decimal?zaplata = platnosc.Rozliczenia.Where(r => r.Data <= termin).Sum(r => r.KwotaZaplatyValue);
                            if (zaplata != null)
                            {
                                rozliczono += zaplata.Value;
                            }
                        }
                    }
                    if (rozliczono < SumaBrutto)
                    {
                        decimal pozostalo    = SumaBrutto.Value - rozliczono;
                        decimal pr           = pozostalo / SumaBrutto.Value;
                        decimal dopotracenia = decimal.Round(prowizja.Value * pr, 2);
                        int     rm           = DateTime.Now.Month - termin.Month;
                        if (rm > 3)
                        {
                            return(dopotracenia);
                        }
                        return(decimal.Round(dopotracenia * rm * 25 / 100, 2));
                    }
                }
            }
            return(null);
        }
Пример #22
0
        public Feature SetFeature(EnovaContext dc, string name, string data, string dataKey = null, int lp = 0)
        {
            dataKey = dataKey == null ? data : dataKey;
            var feature = this.GetFeature(dc, name, lp);

            if (feature == null)
            {
                feature = new Feature()
                {
                    Lp         = lp,
                    Name       = name,
                    Parent     = this.ID,
                    ParentType = "Towary"
                };
                dc.Features.AddObject(feature);
            }
            feature.DataKey = dataKey;
            feature.Data    = data;
            return(feature);
        }
Пример #23
0
        private void loadData()
        {
            Enova.Business.Old.DB.EnovaContext dc = Enova.Business.Old.Core.ContextManager.DataContext;
            if (dc != null && !string.IsNullOrEmpty(TableName))
            {
                this.treeView.Nodes.Clear();
                this.treeView.Nodes.Add(new FeatureTreeNode(new FeatureDef()
                {
                    Name = "Wszystko", ID = 0
                }));
                var features = dc.FeatureDefs.Where(f => f.TableName == TableName && f.StrictDictionary == true && f.Group == true)
                               .OrderBy(f => f.Name).ToList();

                foreach (var f in features)
                {
                    this.treeView.Nodes.Add(new FeatureTreeNode(f));
                }
                treeView.SelectedNode = treeView.Nodes[0];
            }
        }
Пример #24
0
            protected static IEnumerable GetNames(EnovaContext dc, bool podrzędne)
            {
                HandelModule  instance = HandelModule.GetInstance(dc);
                List <string> c        = new List <string>();

                foreach (DefRelacjiHandlowej handlowej in (IEnumerable)instance.DefRelHandlowych)
                {
                    throw new Exception("Brak w nowej bazie DefrelHandlowej.definicjaPodrzednego");

                    /*
                     * if ((!(bool)handlowej.Blokada && !(bool)handlowej.DefinicjaNadrzednego.Blokada) && !(bool)handlowej.DefinicjaPodrzednego.Blokada)
                     * {
                     *  c.Add(podrzędne ? handlowej.ZPodrzednego.Nazwa : handlowej.ZNadrzednego.Nazwa);
                     * }
                     */
                }
                ArrayList list = new ArrayList(c);

                list.Sort();
                return(list);
            }
Пример #25
0
        public bool DeleteRecord()
        {
            EnovaContext dc = Enova.Business.Old.Core.ContextManager.DataContext;

            dc.DeleteObject(this);

            if (Enova.Business.Old.DB.Web.User.LoginedUser.EnovaOperator != null)
            {
                ChangeInfo ci = new ChangeInfo()
                {
                    Operator    = Enova.Business.Old.DB.Web.User.LoginedUser.EnovaOperator,
                    SourceGuid  = this.Guid,
                    SourceTable = "FeatureDefs",
                    Type        = 4,
                    Time        = DateTime.Now,
                    Info        = this.Name + " (" + this.TableName + ")"
                };
                dc.AddToChangeInfos(ci);
            }

            dc.SaveChanges();

            return(true);
        }
Пример #26
0
 public EnovaModule(DB.EnovaContext dc, string name) : base(dc, name)
 {
 }
Пример #27
0
 public ObjectQuery <Feature> GetFeatures(EnovaContext ec)
 {
     return(ec.Features.Where(f => f.ParentType == "DokHandlowe" && f.Parent == this.ID) as ObjectQuery <Feature>);
 }
Пример #28
0
 public ObjectQuery <Platnosc> GetPlatnosci(EnovaContext ec)
 {
     return((ObjectQuery <Platnosc>)ec.Platnosci.Where(p => p.DokumentType == "DokHandlowe" && p.DokumentID == this.ID));
 }
Пример #29
0
 public static IEnumerable GetNames(EnovaContext dc)
 {
     return(PozycjaDokHandlowego.PozycjeSubTable.GetNames(dc, true));
 }
Пример #30
0
 public DateTime?GetTermin(EnovaContext ec)
 {
     return(this.GetPlatnosci(ec).Max(p => p.Termin));
 }