Beispiel #1
0
 public ActionResult SubjektHlidac(string Id)
 {
     if (string.IsNullOrWhiteSpace(Id))
     {
         return(NotFound("/", "Pokračovat na titulní straně"));
     }
     HlidacStatu.Lib.Data.Firma model = HlidacStatu.Lib.Data.Firmy.Get(Id);
     if (model == null || !Firma.IsValid(model))
     {
         return(NotFound("/", "Pokračovat na titulní straně"));
     }
     else
     {
         var aktualnost = HlidacStatu.Lib.Data.Relation.AktualnostType.Nedavny;
         ViewBag.Aktualnost = aktualnost;
         return(View(model));
     }
 }
Beispiel #2
0
        private static List <Autocomplete> LoadCompanies()
        {
            // Kod_PF < 110  - cokoliv co nejsou fyzické osoby, podnikatelé
            // Podnikatelé nejsou zařazeni, protože je jich poté moc a vznikají tam duplicity

            string sql     = "select Jmeno, ICO from Firma where IsInRS = 1 AND LEN(ico) = 8 AND Kod_PF > 110;";
            var    results = DirectDB.GetList <string, string>(sql)
                             .Select(f => Firma.FromIco(f.Item2))
                             .AsParallel()
                             .Select(f => new Autocomplete()
            {
                Id           = $"ico:{f.ICO}",
                Text         = f.Jmeno,
                Type         = f.JsemOVM() ? "úřad" : "firma",
                Description  = FixKraj(f.KrajId),
                ImageElement = "<i class='fas fa-industry-alt'></i>"
            }).ToList();

            return(results);
        }
Beispiel #3
0
        public bool JeSmlouva_S_VazbouNaPolitiky(Relation.AktualnostType aktualnost)
        {
            var icos = ico_s_VazbouPolitik;

            if (aktualnost == Relation.AktualnostType.Nedavny)
            {
                icos = ico_s_VazbouPolitikNedavne;
            }
            if (aktualnost == Relation.AktualnostType.Aktualni)
            {
                icos = ico_s_VazbouPolitikAktualni;
            }
            Firma f = null;

            if (this.platnyZaznam)
            {
                f = Firmy.Get(this.Platce.ico);
                if (f.Valid && !f.PatrimStatu())
                {
                    if (!string.IsNullOrEmpty(this.Platce.ico) && icos.Contains(this.Platce.ico))
                    {
                        return(true);
                    }
                }

                foreach (var ss in this.Prijemce)
                {
                    f = Firmy.Get(ss.ico);
                    if (f.Valid && !f.PatrimStatu())
                    {
                        if (!string.IsNullOrEmpty(ss.ico) && icos.Contains(ss.ico))
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
Beispiel #4
0
                private static VZ Create(Firma f)
                {
                    Dictionary <int, Lib.Analysis.BasicData> _calc_SeZasadnimNedostatkem = Lib.ES.QueryGrouped.SmlouvyPerYear($"ico:{f.ICO} and chyby:zasadni", Lib.Analytics.Consts.RegistrSmluvYearsList);

                    Dictionary <int, Lib.Analysis.BasicData> _calc_UzavrenoOVikendu = Lib.ES.QueryGrouped.SmlouvyPerYear($"ico:{f.ICO} AND (hint.denUzavreni:>0)", Lib.Analytics.Consts.RegistrSmluvYearsList);

                    Dictionary <int, Lib.Analysis.BasicData> _calc_ULimitu = Lib.ES.QueryGrouped.SmlouvyPerYear($"ico:{f.ICO} AND ( hint.smlouvaULimitu:>0 )", Lib.Analytics.Consts.RegistrSmluvYearsList);

                    Dictionary <int, Lib.Analysis.BasicData> _calc_NovaFirmaDodavatel = Lib.ES.QueryGrouped.SmlouvyPerYear($"ico:{f.ICO} AND ( hint.pocetDniOdZalozeniFirmy:>-50 AND hint.pocetDniOdZalozeniFirmy:<30 )", Lib.Analytics.Consts.RegistrSmluvYearsList);


                    Dictionary <int, VZ.Data> data = new Dictionary <int, VZ.Data>();

                    foreach (var year in Lib.Analytics.Consts.RegistrSmluvYearsList)
                    {
                        //var stat = f.Statistic().RatingPerYear[year];
                        data.Add(year, new VZ.Data()
                        {
                        }
                                 );
                    }

                    return(new VZ(f.ICO, data));
                }
        public static AnalysisCalculation.VazbyFiremNaUradyStat UradyObchodujiciSFirmami_s_vazbouNaPolitiky(Relation.AktualnostType aktualnost, bool showProgress = false)
        {
            HlidacStatu.Lib.Data.AnalysisCalculation.VazbyFiremNaPolitiky vazbyNaPolitiky = null;
            List <Lib.Data.FirmaEvent> sponzorujiciFirmy = null;

            QueryContainer qc = null;

            switch (aktualnost)
            {
            case HlidacStatu.Lib.Data.Relation.AktualnostType.Aktualni:
                vazbyNaPolitiky = StaticData.FirmySVazbamiNaPolitiky_aktualni_Cache.Get();
                qc = new QueryContainerDescriptor <HlidacStatu.Lib.Data.Smlouva>().Term(t => t.Field(f => f.SVazbouNaPolitikyAktualni).Value(true));
                sponzorujiciFirmy = StaticData.SponzorujiciFirmy_Nedavne.Get();
                break;

            case HlidacStatu.Lib.Data.Relation.AktualnostType.Nedavny:
                vazbyNaPolitiky = StaticData.FirmySVazbamiNaPolitiky_nedavne_Cache.Get();
                qc = new QueryContainerDescriptor <HlidacStatu.Lib.Data.Smlouva>().Term(t => t.Field(f => f.SVazbouNaPolitikyNedavne).Value(true));
                sponzorujiciFirmy = StaticData.SponzorujiciFirmy_Nedavne.Get();
                break;

            case HlidacStatu.Lib.Data.Relation.AktualnostType.Neaktualni:
            case HlidacStatu.Lib.Data.Relation.AktualnostType.Libovolny:
                vazbyNaPolitiky = StaticData.FirmySVazbamiNaPolitiky_vsechny_Cache.Get();
                qc = new QueryContainerDescriptor <HlidacStatu.Lib.Data.Smlouva>().Term(t => t.Field(f => f.SVazbouNaPolitiky).Value(true));
                sponzorujiciFirmy = StaticData.SponzorujiciFirmy_Vsechny.Get();
                break;
            }


            Func <int, int, Nest.ISearchResponse <Lib.Data.Smlouva> > searchFunc = null;

            searchFunc = (size, page) =>
            {
                return(Lib.ES.Manager.GetESClient().Search <Lib.Data.Smlouva>(a => a
                                                                              .Size(size)
                                                                              .From(page * size)
                                                                              .Source(m => m.Excludes(e => e.Field(o => o.Prilohy)))
                                                                              .Query(q => qc)
                                                                              .Scroll("5m")
                                                                              ));
            };


            //TODO predelat z projeti vsech smluv na hledani pres vsechna ICO  v RS, vybrani statnich firem,
            //a dohlednai jejich statistiky vuci jednotlivym ostatnim firmam v RS
            Dictionary <string, Analysis.BasicDataForSubject <List <Analysis.BasicData <string> > > > uradyStatni = new Dictionary <string, Analysis.BasicDataForSubject <List <Analysis.BasicData <string> > > >();
            Dictionary <string, Analysis.BasicDataForSubject <List <Analysis.BasicData <string> > > > uradySoukr  = new Dictionary <string, Analysis.BasicDataForSubject <List <Analysis.BasicData <string> > > >();
            object lockObj = new object();

            Lib.ES.SearchTools.DoActionForQuery <Lib.Data.Smlouva>(Lib.ES.Manager.GetESClient(), searchFunc,
                                                                   (hit, param) =>
            {
                Lib.Data.Smlouva s = hit.Source;
                List <string> icos = new List <string>();
                try
                {
                    var objednatelIco = s.Platce.ico;
                    if (!string.IsNullOrEmpty(objednatelIco))
                    {
                        Firma ff = Firmy.Get(objednatelIco);
                        if (!ff.Valid || !ff.PatrimStatu())
                        {
                            goto end;
                        }

                        //vsichni prijemci smlouvy statniho subjektu
                        icos.AddRange(s.Prijemce.Select(m => m.ico).Where(m => !string.IsNullOrEmpty(m)).Distinct());

                        lock (lockObj)
                        {
                            foreach (var ico in icos)
                            {
                                if (vazbyNaPolitiky.SoukromeFirmy.ContainsKey(ico) || sponzorujiciFirmy.Any(m => m.ICO == ico))
                                {
                                    if (!uradySoukr.ContainsKey(objednatelIco))
                                    {
                                        uradySoukr.Add(objednatelIco, new Analysis.BasicDataForSubject <List <Analysis.BasicData <string> > >());
                                        uradySoukr[objednatelIco].Ico = objednatelIco;
                                    }
                                    uradySoukr[objednatelIco].Add(1, s.CalculatedPriceWithVATinCZK);
                                    if (!uradySoukr[objednatelIco].Detail.Any(m => m.Item == ico))
                                    {
                                        uradySoukr[objednatelIco].Detail.Add(new Analysis.BasicData <string>()
                                        {
                                            Item = ico, CelkemCena = s.CalculatedPriceWithVATinCZK, Pocet = 1
                                        });
                                    }
                                    else
                                    {
                                        var item = uradySoukr[objednatelIco].Detail.First(m => m.Item == ico);
                                        item.Add(1, s.CalculatedPriceWithVATinCZK);
                                    }
                                }
                                else if (vazbyNaPolitiky.StatniFirmy.ContainsKey(ico))
                                {
                                    if (!uradyStatni.ContainsKey(objednatelIco))
                                    {
                                        uradyStatni.Add(objednatelIco, new Analysis.BasicDataForSubject <List <Analysis.BasicData <string> > >());
                                        uradyStatni[objednatelIco].Ico = objednatelIco;
                                    }
                                    uradyStatni[objednatelIco].Add(1, s.CalculatedPriceWithVATinCZK);
                                    if (!uradyStatni[objednatelIco].Detail.Any(m => m.Item == ico))
                                    {
                                        uradyStatni[objednatelIco].Detail.Add(new Analysis.BasicData <string>()
                                        {
                                            Item = ico, CelkemCena = s.CalculatedPriceWithVATinCZK, Pocet = 1
                                        });
                                    }
                                    else
                                    {
                                        var item = uradyStatni[objednatelIco].Detail.First(m => m.Item == ico);
                                        item.Add(1, s.CalculatedPriceWithVATinCZK);
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    HlidacStatu.Util.Consts.Logger.Error("ERROR UradyObchodujiciSFirmami_s_vazbouNaPolitiky", e);
                }

                end:
                return(new Devmasters.Core.Batch.ActionOutputData()
                {
                    CancelRunning = false, Log = null
                });
            }, null,
                                                                   showProgress ? Devmasters.Core.Batch.Manager.DefaultOutputWriter : (Action <string>)null,
                                                                   showProgress ? new Devmasters.Core.Batch.ActionProgressWriter().Write : (Action <ActionProgressData>)null
                                                                   , true
                                                                   , prefix: "UradyObchodujiciSFirmami_s_vazbouNaPolitiky " + aktualnost.ToNiceDisplayName()
                                                                   );


            AnalysisCalculation.VazbyFiremNaUradyStat ret = new VazbyFiremNaUradyStat();
            ret.SoukromeFirmy = uradySoukr
                                .Where(m => m.Value.Pocet > 0)
                                .Select(kv => kv.Value)
                                .OrderByDescending(o => o.Pocet);

            return(ret);
        }
Beispiel #6
0
            public static Analytics.StatisticsSubjectPerYear <Smlouva.Statistics.Data> CalculateStats(Firma f, int?obor)
            {
                StatisticsSubjectPerYear <Smlouva.Statistics.Data> res = null;

                if (obor.HasValue && obor != 0)
                {
                    res = new StatisticsSubjectPerYear <Smlouva.Statistics.Data>(
                        f.ICO,
                        Smlouva.Statistics.Calculate($"ico:{f.ICO} AND oblast:{Smlouva.SClassification.Classification.ClassifSearchQuery(obor.Value)}")
                        );
                }
                else
                {
                    res = new StatisticsSubjectPerYear <Smlouva.Statistics.Data>(
                        f.ICO,
                        Smlouva.Statistics.Calculate($"ico:{f.ICO}")
                        );
                }

                return(res);
            }
Beispiel #7
0
 public static Analytics.StatisticsSubjectPerYear <Smlouva.Statistics.Data> CachedStatistics(Firma firma, int?obor)
 {
     return(_cache.Get((firma, obor)));
 }
Beispiel #8
0
        public static IEnumerable <IcoSmlouvaMinMax> GetFirmyCasovePodezreleZalozene(Action <string> logOutputFunc = null, Action <ActionProgressData> progressOutputFunc = null)
        {
            HlidacStatu.Util.Consts.Logger.Debug("GetFirmyCasovePodezreleZalozene - getting all ico");
            var allIcos = Lib.Data.External.FirmyDB.AllIcoInRS();
            Dictionary <string, AnalysisCalculation.IcoSmlouvaMinMax> firmy = new Dictionary <string, AnalysisCalculation.IcoSmlouvaMinMax>();
            object lockFirmy = new object();
            var    client    = HlidacStatu.Lib.ES.Manager.GetESClient();
            AggregationContainerDescriptor <HlidacStatu.Lib.Data.Smlouva> aggs = new AggregationContainerDescriptor <HlidacStatu.Lib.Data.Smlouva>()
                                                                                 .Min("minDate", m => m
                                                                                      .Field(f => f.datumUzavreni)
                                                                                      );


            HlidacStatu.Util.Consts.Logger.Debug("GetFirmyCasovePodezreleZalozene - getting first smlouva for all ico from ES");
            Devmasters.Batch.Manager.DoActionForAll <string, object>(allIcos,
                                                                     (ico, param) =>
            {
                Firma ff = Firmy.Get(ico);
                if (Firma.IsValid(ff))
                {
                    if (ff.PatrimStatu()) //statni firmy tam nechci
                    {
                        return(new Devmasters.Batch.ActionOutputData()
                        {
                            CancelRunning = false, Log = null
                        });
                    }
                    else
                    {
                        var res = HlidacStatu.Lib.Data.Smlouva.Search.SimpleSearch("ico:" + ico, 0, 0, HlidacStatu.Lib.Data.Smlouva.Search.OrderResult.FastestForScroll, aggs, exactNumOfResults: true);
                        if (res.ElasticResults.Aggregations.Count > 0)
                        {
                            var epoch = ((Nest.ValueAggregate)res.ElasticResults.Aggregations.First().Value).Value;
                            if (epoch.HasValue)
                            {
                                var mindate = Devmasters.DT.Util.FromEpochTimeToUTC((long)epoch / 1000);

                                lock (lockFirmy)
                                {
                                    if (firmy.ContainsKey(ico))
                                    {
                                        if (firmy[ico].minUzavreni.HasValue == false)
                                        {
                                            firmy[ico].minUzavreni = mindate;
                                        }
                                        else if (firmy[ico].minUzavreni.Value > mindate)
                                        {
                                            firmy[ico].minUzavreni = mindate;
                                        }
                                    }
                                    else
                                    {
                                        firmy.Add(ico, new AnalysisCalculation.IcoSmlouvaMinMax()
                                        {
                                            ico         = ico,
                                            minUzavreni = Devmasters.DT.Util.FromEpochTimeToUTC((long)epoch / 1000)
                                        });
                                    }
                                    if (ff.Datum_Zapisu_OR.HasValue)
                                    {
                                        firmy[ico].vznikIco = ff.Datum_Zapisu_OR.Value;
                                        firmy[ico].jmeno    = ff.Jmeno;
                                    }
                                }
                            }
                        }
                    }
                }
                return(new Devmasters.Batch.ActionOutputData()
                {
                    CancelRunning = false, Log = null
                });
            },
                                                                     null,
                                                                     logOutputFunc ?? Devmasters.Batch.Manager.DefaultOutputWriter,
                                                                     progressOutputFunc ?? new Devmasters.Batch.ActionProgressWriter(0.1f).Write,
                                                                     true
                                                                     );


            //List<string> privateCompanyIcos = new List<string>();
            ////filter statni firmy && add vznik

            //Devmasters.Batch.Manager.DoActionForAll<string, object>(firmy.Keys,
            //(ico, param) =>
            //{
            //    Firma ff = Firmy.Get(ico);
            //    if (Firma.IsValid(ff))
            //    {
            //        if (ff.PatrimStatu()) //statni firmy tam nechci
            //        {
            //            return new Devmasters.Batch.ActionOutputData() { CancelRunning = false, Log = null };
            //        }
            //        else
            //        {
            //            if (ff.Datum_Zapisu_OR.HasValue)
            //            {
            //                firmy[ico].vznikIco = ff.Datum_Zapisu_OR.Value;
            //                firmy[ico].jmeno = ff.Jmeno;
            //                privateCompanyIcos.Add(ico);
            //            }
            //        }
            //    }

            //    return new Devmasters.Batch.ActionOutputData() { CancelRunning = false, Log = null };
            //},
            //null,
            //Devmasters.Batch.Manager.DefaultOutputWriter,
            //new Devmasters.Batch.ActionProgressWriter(1f).Write,
            //true, maxDegreeOfParallelism: 5
            //);

            HlidacStatu.Util.Consts.Logger.Debug("GetFirmyCasovePodezreleZalozene - filter with close dates");

            DateTime minDate = new DateTime(1990, 01, 01);
            var      badF    = firmy
                               .Select(m => m.Value)
                               .Where(f => f.minUzavreni > minDate)
                               .Where(f => f.days.HasValue && f.days.Value < 60)
                               .OrderBy(f => f.days.Value)
                               .ToArray();

            //.Take(100)

            HlidacStatu.Util.Consts.Logger.Debug($"GetFirmyCasovePodezreleZalozene - returning {badF.Count()} records.");

            return(badF);
        }
Beispiel #9
0
 public FirmaInElastic(Firma f)
 {
     this.Ico   = f.ICO;
     this.Jmeno = f.Jmeno;
 }
 public static Analytics.StatisticsSubjectPerYear <RegistrSmluv> Create(Firma f, int?obor)
 {
     if (obor.HasValue)
     {
         return(Create($"ico:{f.ICO} AND oblast:{Smlouva.SClassification.Classification.ClassifSearchQuery(obor.Value)}"));
     }
     else
     {
         return(Create($"ico:{f.ICO}"));
     }
 }
Beispiel #11
0
                public static VZ Get(Firma f)
                {
                    //add cache logic

                    return(instanceByIco.Get(f.ICO));
                }
Beispiel #12
0
        private static Firma getByDS(string key)
        {
            var o = Firma.FromDS(key);

            return(o ?? nullObj);
        }
Beispiel #13
0
        public bool UpdateSubj(Smlouva.Subjekt subj, Smlouva _item, string path)
        {
            bool changed = false;
            var  zahr    = Util.DataValidators.ZahranicniAdresa(subj.adresa);

            if (!string.IsNullOrEmpty(zahr) && !string.IsNullOrEmpty(subj.ico))
            {
                var currPref = Devmasters.RegexUtil.GetRegexGroupValue(subj.ico, @"^(?<pref>\w{2}-).{1,}", "pref");
                if (string.IsNullOrEmpty(currPref))
                {
                    //NENI PREFIX, DOPLN HO
                    string newico = zahr + "-" + subj.ico;
                    _item.Enhancements = _item.Enhancements.AddOrUpdate(new Enhancement("Doplněno zahraniční ID subjektu. Doplněn prefix před ID firmy", "", path + ".ico", newico, subj.ico, this));
                    subj.ico           = newico;
                    changed            = true;
                }
                else if (currPref != zahr)
                {
                    //je jiny PREFIX, uprav ho
                    string newico = zahr + subj.ico.Substring(2);
                    _item.Enhancements = _item.Enhancements.AddOrUpdate(new Enhancement("Upraveno zahraniční ID subjektu. Doplněn prefix před ID firmy", "", path + ".ico", zahr + "-" + subj.ico, subj.ico, this));
                    subj.ico           = newico;
                    changed            = true;
                }
            }
            else
            {
                var currPref2 = Devmasters.RegexUtil.GetRegexGroupValue(subj.ico, @"^(?<pref>\w{2}-).{1,}", "pref");
                if (!string.IsNullOrEmpty(currPref2) && subj.ico != null)
                {
                    subj.ico = subj.ico.Replace(currPref2, "");
                    changed  = true;
                }
            }
            //check formal valid ICO
            string ico = subj.ico;

            if (!string.IsNullOrEmpty(ico) &&
                !Devmasters.TextUtil.IsNumeric(ico) &&
                Util.DataValidators.IsZahranicniAdresa(subj.adresa) == false
                )
            {
                //neco spatne v ICO
                ico = System.Text.RegularExpressions.Regex.Replace(ico.ToUpper(), @"[^0-9\-.,]", string.Empty);
                if (Util.DataValidators.CheckCZICO(ico))
                {
                    _item.Enhancements = _item.Enhancements.AddOrUpdate(new Enhancement("Opraveno IČO subjektu", "", path + ".ico", subj.ico, ico, this));
                    subj.ico           = ico;
                    changed            = true;
                }
            }

            if (string.IsNullOrEmpty(subj.ico) &&
                !string.IsNullOrEmpty(subj.datovaSchranka) &&
                Util.DataValidators.IsZahranicniAdresa(subj.adresa) == false
                )
            {
                HlidacStatu.Lib.Data.Firma f = HlidacStatu.Lib.Data.Firma.FromDS(subj.datovaSchranka, true);
                if (Firma.IsValid(f))
                {
                    subj.ico           = f.ICO;
                    _item.Enhancements = _item.Enhancements.AddOrUpdate(new Enhancement("Doplněno IČO subjektu", "", path + ".ico", "", f.ICO, this));
                    changed            = true;
                }
            }
            else if (!string.IsNullOrEmpty(subj.ico) && string.IsNullOrEmpty(subj.datovaSchranka))
            {
                HlidacStatu.Lib.Data.Firma f = HlidacStatu.Lib.Data.Firma.FromIco(subj.ico, true);
                if (Firma.IsValid(f) && f.DatovaSchranka != null && f.DatovaSchranka.Length > 0)
                {
                    subj.datovaSchranka = f.DatovaSchranka[0];
                    _item.Enhancements  = _item.Enhancements.AddOrUpdate(new Enhancement("Doplněna datová schránka subjektu", "", path + ".datovaScranka", "", f.DatovaSchranka[0], this));
                    changed             = true;
                }
            }
            else if (string.IsNullOrEmpty(subj.ico) &&
                     string.IsNullOrEmpty(subj.datovaSchranka) &&
                     !string.IsNullOrEmpty(subj.nazev) &&
                     Util.DataValidators.IsZahranicniAdresa(subj.adresa) == false
                     )
            {
                //based on name
                //simple compare now
                if (Lib.Data.Firma.Koncovky.Any(m => subj.nazev.Contains(m)))
                {
                    Lib.Data.Firma f = Lib.Data.Firma.FromName(subj.nazev, true);
                    if (Firma.IsValid(f))
                    {
                        subj.ico            = f.ICO;
                        subj.datovaSchranka = f.DatovaSchranka.Length > 0 ? f.DatovaSchranka[0] : "";
                        _item.Enhancements  = _item.Enhancements.AddOrUpdate(new Enhancement("Doplněno IČO subjektu", "", path + ".ico", "", f.ICO, this));
                        if (f.DatovaSchranka.Length > 0)
                        {
                            _item.Enhancements = _item.Enhancements.AddOrUpdate(new Enhancement("Doplněna datová schránka subjektu", "", path + ".datovaSchranka", "", f.DatovaSchranka[0], this));
                        }
                        changed = true;
                    }
                    else
                    {
                        //malinko uprav nazev, zrus koncovku  aposledni carku
                        string modifNazev = Lib.Data.Firma.JmenoBezKoncovky(subj.nazev);


                        f = Lib.Data.Firma.FromName(modifNazev, true);
                        if (Firma.IsValid(f))
                        {
                            subj.ico            = f.ICO;
                            subj.datovaSchranka = f.DatovaSchranka.Length > 0 ? f.DatovaSchranka[0] : "";
                            _item.Enhancements  = _item.Enhancements.AddOrUpdate(new Enhancement("Doplněno IČO subjektu", "", path + ".ico", "", f.ICO, this));
                            if (f.DatovaSchranka.Length > 0)
                            {
                                _item.Enhancements = _item.Enhancements.AddOrUpdate(new Enhancement("Doplněna datová schránka subjektu", "", path + ".datovaSchranka", "", f.DatovaSchranka[0], this));
                            }
                            changed = true;
                        }
                    }
                }
            }
            if (string.IsNullOrEmpty(subj.nazev) && !string.IsNullOrEmpty(subj.ico))
            {
                //dopln chybejici jmeno
                HlidacStatu.Lib.Data.Firma f = HlidacStatu.Lib.Data.Firma.FromIco(subj.ico, true);
                if (Firma.IsValid(f))
                {
                    subj.nazev         = f.Jmeno;
                    _item.Enhancements = _item.Enhancements.AddOrUpdate(new Enhancement("Doplněn Název subjektu", "", path + ".nazev", "", f.ICO, this));
                    changed            = true;
                }
            }
            if (string.IsNullOrEmpty(subj.adresa) && !string.IsNullOrEmpty(subj.ico))
            {
                //dopln chybejici jmeno
                var fm = HlidacStatu.Lib.Data.External.Merk.FromIcoFull(subj.ico);
                if (fm != null)
                {
                    subj.adresa        = fm.address.street + " " + fm.address.number + ", " + fm.address.municipality;
                    _item.Enhancements = _item.Enhancements.AddOrUpdate(new Enhancement("Doplněna adresa subjektu", "", path + ".nazev", "", subj.ico, this));
                    changed            = true;
                }
            }

            return(changed);
        }
Beispiel #14
0
                public static Analytics.StatisticsSubjectPerYear <Statistics.Dotace> Create(Firma f)
                {
                    var dotaceService = new Data.Dotace.DotaceService();
                    var dotaceFirmy   = dotaceService.GetDotaceForIco(f.ICO);

                    // doplnit počty dotací
                    var statistiky = dotaceFirmy.GroupBy(d => d.DatumPodpisu?.Year)
                                     .ToDictionary(g => g.Key ?? 0,
                                                   g => new Statistics.Dotace()
                    {
                        PocetDotaci = g.Count()
                    }
                                                   );

                    var cerpani = dotaceFirmy
                                  .SelectMany(d => d.Rozhodnuti)
                                  .SelectMany(r => r.Cerpani);

                    var dataYearly = cerpani
                                     .GroupBy(c => c.GuessedYear)
                                     .ToDictionary(g => g.Key ?? 0,
                                                   g => (CelkemCerpano: g.Sum(c => c.CastkaSpotrebovana ?? 0),
                                                         PocetCerpani: g.Count(c => c.CastkaSpotrebovana.HasValue))
                                                   );

                    foreach (var dy in dataYearly)
                    {
                        if (!statistiky.TryGetValue(dy.Key, out var yearstat))
                        {
                            yearstat = new Statistics.Dotace();
                            statistiky.Add(dy.Key, yearstat);
                        }

                        yearstat.CelkemCerpano = dy.Value.CelkemCerpano;
                        yearstat.PocetCerpani  = dy.Value.PocetCerpani;
                    }


                    return(new Analytics.StatisticsSubjectPerYear <Statistics.Dotace>(f.ICO, statistiky));
                }
        public static VazbyFiremNaPolitiky LoadFirmySVazbamiNaPolitiky(Relation.AktualnostType aktualnostVztahu, bool showProgress = false)
        {
            Dictionary <string, List <int> > pol_SVazbami             = new Dictionary <string, List <int> >();
            Dictionary <string, List <int> > pol_SVazbami_StatniFirmy = new Dictionary <string, List <int> >();

            Devmasters.Core.Batch.Manager.DoActionForAll <Osoba>(StaticData.Politici.Get(),
                                                                 (p) =>
            {
                var vazby = p.AktualniVazby(aktualnostVztahu);
                if (vazby != null && vazby.Count() > 0)
                {
                    foreach (var v in vazby)
                    {
                        if (!string.IsNullOrEmpty(v.To.Id))
                        {
                            //check if it's GovType company
                            Firma f = Firmy.Get(v.To.Id);
                            //if (f == null)
                            //{
                            //    f = External.GovData.FromIco(v.To.Id);
                            //    if (f == null)
                            //        continue; //unknown company, skip
                            //}
                            if (!Firma.IsValid(f))
                            {
                                continue; //unknown company, skip
                            }
                            if (f.PatrimStatu())
                            {
                                //Gov Company
                                if (pol_SVazbami_StatniFirmy.ContainsKey(v.To.Id))
                                {
                                    var pol = pol_SVazbami_StatniFirmy[v.To.Id];
                                    if (!pol.Any(m => m == p.InternalId))
                                    {
                                        pol.Add(p.InternalId);
                                    }
                                }
                                else
                                {
                                    pol_SVazbami_StatniFirmy.Add(v.To.Id, new List <int>());
                                    pol_SVazbami_StatniFirmy[v.To.Id].Add(p.InternalId);
                                }
                            }
                            else
                            {
                                //private company
                                if (pol_SVazbami.ContainsKey(v.To.Id))
                                {
                                    var pol = pol_SVazbami[v.To.Id];
                                    if (!pol.Any(m => m == p.InternalId))
                                    {
                                        pol.Add(p.InternalId);
                                    }
                                }
                                else
                                {
                                    pol_SVazbami.Add(v.To.Id, new List <int>());
                                    pol_SVazbami[v.To.Id].Add(p.InternalId);
                                }
                            }
                        }
                    }
                }
                return(new Devmasters.Core.Batch.ActionOutputData()
                {
                    CancelRunning = false, Log = null
                });
            },
                                                                 showProgress ? Devmasters.Core.Batch.Manager.DefaultOutputWriter : (Action <string>)null,
                                                                 showProgress ? new Devmasters.Core.Batch.ActionProgressWriter().Write : (Action <ActionProgressData>)null,
                                                                 false
                                                                 , prefix: "LoadFirmySVazbamiNaPolitiky " + aktualnostVztahu.ToNiceDisplayName()
                                                                 );

            return(new VazbyFiremNaPolitiky()
            {
                SoukromeFirmy = pol_SVazbami, StatniFirmy = pol_SVazbami_StatniFirmy
            });
        }
Beispiel #16
0
            public static Lib.Data.Search.GeneralResult <Firma> SimpleSearch(string query, int page, int size)
            {
                List <Firma> found = new List <Firma>();

                string modifQ = Lib.Searching.SimpleQueryCreator
                                .GetSimpleQuery(query, new Searching.Rules.IRule[] { new Searching.Rules.Firmy_OVMKategorie() })
                                .FullQuery();

                string[] specifiedIcosInQuery = Devmasters.RegexUtil.GetRegexGroupValues(modifQ, @"(ico\w{0,11}\: \s? (?<ic>\d{3,8}))", "ic");
                if (specifiedIcosInQuery != null && specifiedIcosInQuery.Length > 0)
                {
                    foreach (var ic in specifiedIcosInQuery.Skip((page - 1) * size).Take(size))
                    {
                        Firma f = Firmy.Get(ic);
                        if (f.Valid)
                        {
                            ///nalezene ICO
                            found.Add(f);
                        }
                    }
                    if (found.Count() > 0)
                    {
                        return new Data.Search.GeneralResult <Firma>(query, specifiedIcosInQuery.Count(), found, size, true)
                               {
                                   Page = page
                               }
                    }
                    ;
                }



                //
                modifQ = Regex.Replace(modifQ, "(ico:|icoprijemce:|icoplatce:|icododavatel:|icozadavatel:)", "ico:", regexQueryOption);

                modifQ = Regex.Replace(modifQ, "(jmenoPrijemce:|jmenoPlatce:|jmenododavatel:|jmenozadavatel:)", "jmeno:", regexQueryOption);

                //modifQ = System.Text.RegularExpressions.Regex.Replace(modifQ, "\\s(AND|OR)\\s", " ", regexQueryOption);

                page = page - 1;
                if (page < 0)
                {
                    page = 0;
                }

                if (page * size >= MaxResultWindow) //elastic limit
                {
                    page = 0; size = 0;             //return nothing
                }


                var qc = GetSimpleQuery(query);
                //var qc = new QueryContainerDescriptor<Lib.Data.Smlouva>()
                //    .QueryString(qs => qs
                //        .Query(modifQ)
                //        .DefaultOperator(Operator.And)
                //    );

                ISearchResponse <FirmaInElastic> res = null;

                try
                {
                    res = ES.Manager.GetESClient_Firmy()
                          .Search <FirmaInElastic>(s => s
                                                   .Size(size)
                                                   .From(page * size)
                                                   .TrackTotalHits(size == 0 ? true : (bool?)null)
                                                   .Query(q => qc)
                                                   );

                    if (res.IsValid)
                    {
                        foreach (var i in res.Hits)
                        {
                            found.Add(Firmy.Get(i.Source.Ico));
                        }
                        return(new Data.Search.GeneralResult <Firma>(query, res.Total, found, size, true)
                        {
                            Page = page
                        });
                    }
                    else
                    {
                        Lib.ES.Manager.LogQueryError <FirmaInElastic>(res, query);
                        return(new Data.Search.GeneralResult <Firma>(query, 0, found, size, false)
                        {
                            Page = page
                        });
                    }
                }
                catch (Exception e)
                {
                    if (res != null && res.ServerError != null)
                    {
                        Lib.ES.Manager.LogQueryError <FirmaInElastic>(res, query);
                    }
                    else
                    {
                        HlidacStatu.Util.Consts.Logger.Error("", e);
                    }
                    throw;
                }
                //return new Data.Search.GeneralResult<Firma>(query, 0, found, size, false) { Page = page };
            }
        public static IEnumerable <IcoSmlouvaMinMax> GetFirmyCasovePodezreleZalozene(Action <string> logOutputFunc = null, Action <ActionProgressData> progressOutputFunc = null)
        {
            var allIcos = Lib.Data.External.FirmyDB.AllIcoInRS();
            Dictionary <string, AnalysisCalculation.IcoSmlouvaMinMax> firmy = new Dictionary <string, AnalysisCalculation.IcoSmlouvaMinMax>();
            object lockFirmy = new object();
            var    client    = HlidacStatu.Lib.ES.Manager.GetESClient();
            AggregationContainerDescriptor <HlidacStatu.Lib.Data.Smlouva> aggs = new AggregationContainerDescriptor <HlidacStatu.Lib.Data.Smlouva>()
                                                                                 .Min("minDate", m => m
                                                                                      .Field(f => f.datumUzavreni)
                                                                                      );


            Devmasters.Core.Batch.Manager.DoActionForAll <string, object>(allIcos,
                                                                          (ico, param) =>
            {
                var res = HlidacStatu.Lib.ES.SearchTools.SimpleSearch("ico:" + ico, 0, 0, HlidacStatu.Lib.ES.SearchTools.OrderResult.FastestForScroll, aggs);
                if (res.Result.Aggregations.Count > 0)
                {
                    var epoch = ((Nest.ValueAggregate)res.Result.Aggregations.First().Value).Value;
                    if (epoch.HasValue)
                    {
                        var mindate = Devmasters.Core.DateTimeUtil.FromEpochTimeToUTC((long)epoch / 1000);

                        lock (lockFirmy)
                        {
                            if (firmy.ContainsKey(ico))
                            {
                                if (firmy[ico].minUzavreni.HasValue == false)
                                {
                                    firmy[ico].minUzavreni = mindate;
                                }
                                else if (firmy[ico].minUzavreni.Value > mindate)
                                {
                                    firmy[ico].minUzavreni = mindate;
                                }
                            }
                            else
                            {
                                firmy.Add(ico, new AnalysisCalculation.IcoSmlouvaMinMax()
                                {
                                    ico         = ico,
                                    minUzavreni = Devmasters.Core.DateTimeUtil.FromEpochTimeToUTC((long)epoch / 1000)
                                });
                            }
                        }
                    }
                }

                return(new Devmasters.Core.Batch.ActionOutputData()
                {
                    CancelRunning = false, Log = null
                });
            },
                                                                          null,
                                                                          logOutputFunc ?? Devmasters.Core.Batch.Manager.DefaultOutputWriter,
                                                                          progressOutputFunc ?? new Devmasters.Core.Batch.ActionProgressWriter(0.1f).Write,
                                                                          true
                                                                          );


            List <string> privateCompanyIcos = new List <string>();

            //filter statni firmy && add vznik

            Devmasters.Core.Batch.Manager.DoActionForAll <string, object>(firmy.Keys,
                                                                          (ico, param) =>
            {
                Firma ff = Firmy.Get(ico);
                if (Firma.IsValid(ff))
                {
                    if (ff.PatrimStatu()) //statni firmy tam nechci
                    {
                        return(new Devmasters.Core.Batch.ActionOutputData()
                        {
                            CancelRunning = false, Log = null
                        });
                    }
                    else
                    {
                        if (ff.Datum_Zapisu_OR.HasValue)
                        {
                            firmy[ico].vznikIco = ff.Datum_Zapisu_OR.Value;
                            firmy[ico].jmeno    = ff.Jmeno;
                            privateCompanyIcos.Add(ico);
                        }
                    }
                }

                return(new Devmasters.Core.Batch.ActionOutputData()
                {
                    CancelRunning = false, Log = null
                });
            },
                                                                          null,
                                                                          Devmasters.Core.Batch.Manager.DefaultOutputWriter,
                                                                          new Devmasters.Core.Batch.ActionProgressWriter(1f).Write,
                                                                          true, maxDegreeOfParallelism: 5
                                                                          );


            DateTime minDate = new DateTime(1990, 01, 01);
            var      badF    = firmy
                               .Where(kv => privateCompanyIcos.Contains(kv.Key))
                               .Select(m => m.Value)
                               .Where(f => f.minUzavreni > minDate)
                               .Where(f => f.days.HasValue && f.days.Value < 60)
                               .OrderBy(f => f.days.Value);

            //.Take(100)

            return(badF);
        }
Beispiel #18
0
        public void Update(ref Smlouva item)
        {
            //return; //DOTO
            //check missing DS/ICO

            Lib.Data.Smlouva.Subjekt subj = item.Platce;
            //check formal valid ICO
            string ico = subj.ico;

            if (!string.IsNullOrEmpty(ico) && !Devmasters.Core.TextUtil.IsNumeric(ico))
            {
                //neco spatne v ICO
                ico = System.Text.RegularExpressions.Regex.Replace(ico.ToUpper(), @"[^0-9\-.,]", string.Empty);
                item.Enhancements = item.Enhancements.AddOrUpdate(new Enhancement("Opraveno IČO subjektu", "", "platce.ico", subj.ico, ico, this));
                subj.ico          = ico;
            }

            if (string.IsNullOrEmpty(subj.ico) && !string.IsNullOrEmpty(subj.datovaSchranka))
            {
                HlidacStatu.Lib.Data.Firma f = HlidacStatu.Lib.Data.Firma.FromDS(subj.datovaSchranka, true);
                if (Firma.IsValid(f))
                {
                    item.Platce.ico   = f.ICO;
                    item.Enhancements = item.Enhancements.AddOrUpdate(new Enhancement("Doplněno IČO subjektu", "", "platce.ico", "", f.ICO, this));
                }
            }
            else if (!string.IsNullOrEmpty(subj.ico) && string.IsNullOrEmpty(subj.datovaSchranka))
            {
                HlidacStatu.Lib.Data.Firma f = HlidacStatu.Lib.Data.Firma.FromIco(subj.ico, true);
                if (Firma.IsValid(f) && f.DatovaSchranka != null && f.DatovaSchranka.Length > 0)
                {
                    item.Platce.datovaSchranka = f.DatovaSchranka[0];
                    item.Enhancements          = item.Enhancements.AddOrUpdate(new Enhancement("Doplněna datová schránka subjektu", "", "platce.datovaSchranka", "", f.DatovaSchranka[0], this));
                }
            }
            else if (string.IsNullOrEmpty(subj.ico) && string.IsNullOrEmpty(subj.datovaSchranka) && !string.IsNullOrEmpty(subj.nazev))
            {
                //based on name
                //simple compare now
                if (Lib.Data.Firma.Koncovky.Any(m => subj.nazev.Contains(m)))
                {
                    Lib.Data.Firma f = Lib.Data.Firma.FromName(subj.nazev, true);
                    if (Firma.IsValid(f))
                    {
                        item.Platce.ico            = f.ICO;
                        item.Platce.datovaSchranka = f.DatovaSchranka.Length > 0 ? f.DatovaSchranka[0] : "";
                        item.Enhancements          = item.Enhancements.AddOrUpdate(new Enhancement("Doplněno IČO subjektu", "", "Platce.ico", "", f.ICO, this));
                        if (f.DatovaSchranka.Length > 0)
                        {
                            item.Enhancements = item.Enhancements.AddOrUpdate(new Enhancement("Doplněna datová schránka subjektu", "", "Platce.datovaSchranka", "", f.DatovaSchranka[0], this));
                        }
                    }
                    else
                    {
                        //malinko uprav nazev, zrus koncovku  aposledni carku
                        string modifNazev = Lib.Data.Firma.JmenoBezKoncovky(subj.nazev);


                        f = Lib.Data.Firma.FromName(modifNazev, true);
                        if (Firma.IsValid(f))
                        {
                            item.Platce.ico            = f.ICO;
                            item.Platce.datovaSchranka = f.DatovaSchranka.Length > 0 ? f.DatovaSchranka[0] : "";
                            item.Enhancements          = item.Enhancements.AddOrUpdate(new Enhancement("Doplněno IČO subjektu", "", "Platce.ico", "", f.ICO, this));
                            if (f.DatovaSchranka.Length > 0)
                            {
                                item.Enhancements = item.Enhancements.AddOrUpdate(new Enhancement("Doplněna datová schránka subjektu", "", "Platce.datovaSchranka", "", f.DatovaSchranka[0], this));
                            }
                        }
                    }
                }
            }
            if (string.IsNullOrEmpty(subj.nazev) && !string.IsNullOrEmpty(subj.ico))
            {
                //dopln chybejici jmeno a adresu
                HlidacStatu.Lib.Data.Firma f = HlidacStatu.Lib.Data.Firma.FromIco(subj.ico, true);
                if (Firma.IsValid(f))
                {
                    subj.nazev        = f.Jmeno;
                    item.Enhancements = item.Enhancements.AddOrUpdate(new Enhancement("Doplněn Název subjektu", "", "Platce.nazev", "", f.ICO, this));
                }
            }


            for (int i = 0; i < item.Prijemce.Count(); i++)
            {
                Smlouva.Subjekt ss = item.Prijemce[i];
                ico = ss.ico;
                if (!string.IsNullOrEmpty(ico) && !Devmasters.Core.TextUtil.IsNumeric(ico))
                {
                    //neco spatne v ICO
                    ico = System.Text.RegularExpressions.Regex.Replace(ico.ToUpper(), @"[^A-Z0-9\-.,]", string.Empty);
                    item.Enhancements = item.Enhancements.AddOrUpdate(new Enhancement("Opraveno IČO subjektu", "", "item.Prijemce[" + i.ToString() + "].ico", ss.ico, ico, this));
                    ss.ico            = ico;
                }

                if (string.IsNullOrEmpty(ss.ico) && !string.IsNullOrEmpty(ss.datovaSchranka))
                {
                    HlidacStatu.Lib.Data.Firma f = HlidacStatu.Lib.Data.Firma.FromDS(ss.datovaSchranka, true);
                    if (Firma.IsValid(f))
                    {
                        item.Prijemce[i].ico = f.ICO;
                        item.Enhancements    = item.Enhancements.AddOrUpdate(new Enhancement("Doplněno IČO smluvní strany", "", "Prijemce[" + i.ToString() + "].ico", "", f.ICO, this));
                    }
                }
                else if (!string.IsNullOrEmpty(ss.ico) && string.IsNullOrEmpty(ss.datovaSchranka))
                {
                    HlidacStatu.Lib.Data.Firma f = HlidacStatu.Lib.Data.Firma.FromIco(ss.ico, true);
                    if (Firma.IsValid(f) && f.DatovaSchranka != null && f.DatovaSchranka.Length > 0)
                    {
                        item.Prijemce[i].datovaSchranka = f.DatovaSchranka[0];
                        item.Enhancements = item.Enhancements.AddOrUpdate(new Enhancement("Doplněna datová schránka smluvní strany", "", "item.Prijemce[" + i.ToString() + "].datovaSchranka", "", f.DatovaSchranka[0], this));
                    }
                }
                else if (string.IsNullOrEmpty(ss.ico) && string.IsNullOrEmpty(ss.datovaSchranka) && !string.IsNullOrEmpty(ss.nazev))
                {
                    //based on name
                    //simple compare now
                    if (Lib.Data.Firma.Koncovky.Any(m => ss.nazev.Contains(m)))
                    {
                        Lib.Data.Firma f = Lib.Data.Firma.FromName(ss.nazev, true);
                        if (Firma.IsValid(f))
                        {
                            item.Prijemce[i].ico            = f.ICO;
                            item.Prijemce[i].datovaSchranka = f.DatovaSchranka.Length > 0 ? f.DatovaSchranka[0] : "";
                            item.Enhancements = item.Enhancements.AddOrUpdate(new Enhancement("Doplněno IČO smluvní strany", "", "item.Prijemce[" + i.ToString() + "].ico", "", f.ICO, this));
                            if (f.DatovaSchranka.Length > 0)
                            {
                                item.Enhancements = item.Enhancements.AddOrUpdate(new Enhancement("Doplněna datová schránka smluvní strany", "", "item.Prijemce[" + i.ToString() + "].datovaSchranka", "", f.DatovaSchranka[0], this));
                            }
                        }
                        else
                        {
                            //malinko uprav nazev, zrus koncovku  aposledni carku
                            string modifNazev = Lib.Data.Firma.JmenoBezKoncovky(ss.nazev);


                            f = Lib.Data.Firma.FromName(modifNazev, true);
                            if (Firma.IsValid(f))
                            {
                                item.Prijemce[i].ico            = f.ICO;
                                item.Prijemce[i].datovaSchranka = f.DatovaSchranka.Length > 0 ? f.DatovaSchranka[0] : "";
                                item.Enhancements = item.Enhancements.AddOrUpdate(new Enhancement("Doplněno IČO subjektu", "", "item.Prijemce[" + i.ToString() + "].ico", "", f.ICO, this));
                                if (f.DatovaSchranka.Length > 0)
                                {
                                    item.Enhancements = item.Enhancements.AddOrUpdate(new Enhancement("Doplněna datová schránka subjektu", "", "item.Prijemce[" + i.ToString() + "].datovaSchranka", "", f.DatovaSchranka[0], this));
                                }
                            }
                        }
                    }
                }
                if (string.IsNullOrEmpty(ss.nazev) && !string.IsNullOrEmpty(ss.ico))
                {
                    //dopln chybejici jmeno a adresu
                    HlidacStatu.Lib.Data.Firma f = HlidacStatu.Lib.Data.Firma.FromIco(ss.ico, true);
                    if (Firma.IsValid(f))
                    {
                        item.Prijemce[i].nazev = f.Jmeno;
                        item.Enhancements      = item.Enhancements.AddOrUpdate(new Enhancement("Doplněn název subjektu", "", "Platce.Prijemce[" + i.ToString() + "].nazev", "", f.Jmeno, this));
                    }
                }
            }
        }
Beispiel #19
0
 public string JmenoBezKoncovky()
 {
     return(Firma.JmenoBezKoncovky(this.Jmeno));
 }
                public static Analytics.StatisticsSubjectPerYear <Statistics.Dotace> Create(Firma f)
                {
                    var dotaceService = new Data.Dotace.DotaceService();
                    var dotaceFirmy   = dotaceService.GetDotaceForIco(f.ICO);

                    var cerpani = dotaceFirmy
                                  .SelectMany(d => d.Rozhodnuti)
                                  .SelectMany(r => r.Cerpani);

                    var dataYearly = cerpani
                                     .GroupBy(c => c.GuessedYear)
                                     .ToDictionary(g => g.Key ?? 0,
                                                   g => new Statistics.Dotace()
                    {
                        CelkemCerpano = g.Sum(c => c.CastkaSpotrebovana ?? 0),
                        PocetCerpani  = g.Count(c => c.CastkaSpotrebovana.HasValue)
                    });

                    // doplnit počty dotací
                    foreach (int year in dataYearly.Keys)
                    {
                        int pocetDotaci = dotaceFirmy.Count(d => (d.DatumPodpisu?.Year ?? 0) == year);
                        dataYearly[year].PocetDotaci = pocetDotaci;
                    }

                    return(new Analytics.StatisticsSubjectPerYear <Statistics.Dotace>(f.ICO, dataYearly));
                }