public IHttpActionResult PostFirmy(Firmy firmy)
        {
            db.Firmy.Add(firmy);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = firmy.IdFirmy }, firmy));
        }
Exemple #2
0
        public void SaveDetailsTest()
        {
            // Metoda 1
            Firmy  firmy  = new Firmy();
            string nazwa  = "firma testowa";
            string adres  = "chmaja";
            string miasto = "rzeszow";
            string kod    = "35-021";
            string bank   = "pko";
            string konto  = "111111111111111";
            int    result = firmy.SaveDetails(nazwa, adres, miasto, kod, bank, konto);


            Assert.IsTrue(result > 0);



            // Metoda 2
            Firmy  firmy2  = new Firmy();
            string nazwa2  = "firma testowa";
            string adres2  = null;
            string miasto2 = "rzeszow";
            string kod2    = null;
            string bank2   = null;
            string konto2  = "111111111111111";
            int    result2 = firmy2.SaveDetails(nazwa2, adres2, miasto2, kod2, bank2, konto2);


            Assert.IsTrue(result2 <= 0);
        }
Exemple #3
0
 private void buttonSave_Click(object sender, RoutedEventArgs e)
 {
     if (textBoxFirma.Text == "" || textBoxFirma.Text.Trim() == "")
     {
         MessageBox.Show("Wprowadź nazwę nadwozia.");
         return;
     }
     else
     {
         try
         {
             Firmy fir = new Firmy {
                 Firma = textBoxFirma.Text
             };
             baza.Firmy.InsertOnSubmit(fir);
             baza.SubmitChanges();
             MessageBox.Show("Poprawnie wprowadzono firmę.");
         }
         catch
         {
             MessageBox.Show("Wystąpił błąd.");
         }
         this.Close();
     }
 }
        public IHttpActionResult PutFirmy(int id, Firmy firmy)
        {
            if (id != firmy.IdFirmy)
            {
                return(BadRequest());
            }

            db.Entry(firmy).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FirmyExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        private void buttonRemoveCompany_Click(object sender, RoutedEventArgs e)
        {
            if (gridCompanies.SelectedIndex == -1)
            {
                MessageBox.Show("Zaznacz wiersz!");
            }
            else
            {
                MessageBoxResult result = MessageBox.Show("Czy jesteś pewien usunięcia danego rekordu?", "Pytanie", MessageBoxButton.YesNo, MessageBoxImage.Question);
                if (result == MessageBoxResult.Yes)
                {
                    int final = 0;
                    try
                    {
                        Firmy body = gridCompanies.SelectedItem as Firmy;
                        final = body.ID_COMPANY;
                    }
                    catch { MessageBox.Show("Zaznacz wiersz!"); }

                    var query = (from p in baza.Firmy
                                 where p.ID_COMPANY == final
                                 select p).FirstOrDefault();
                    if (query != null)
                    {
                        baza.Firmy.DeleteOnSubmit(query);
                        baza.SubmitChanges();
                        Load();
                    }
                }
                else
                {
                }
            }
        }
Exemple #6
0
        private IEnumerable <string> _getPreviewTopValueFromItem(Newtonsoft.Json.Linq.JObject item, bool fromAllTopValues = false)
        {
            List <string> topTxts = new List <string>();
            List <string> texts   = new List <string>();
            var           props   = GetMappingList("ICO");

            foreach (var prop in props)
            {
                var    o = item.SelectTokens(prop).FirstOrDefault();
                string t = "";
                if (o != null && o.GetType() == typeof(JValue))
                {
                    t = o.Value <string>() ?? "";
                }
                //var t = ((string)Dynamitey.Dynamic.InvokeGetChain(item, prop)) ?? "";
                if (HlidacStatu.Util.DataValidators.CheckCZICO(t))
                {
                    Firma f = Firmy.Get(t);
                    if (f.Valid)
                    {
                        topTxts.Add(f.JmenoBezKoncovky() + ":");
                        if (!fromAllTopValues)
                        {
                            break;
                        }
                    }
                }
            }

            props = GetMappingList("Osobaid");
            foreach (var prop in props)
            {
                var    o = item.SelectTokens(prop).FirstOrDefault();
                string t = "";
                if (o != null && o.GetType() == typeof(JValue))
                {
                    t = o.Value <string>() ?? "";
                }
                //var t = ((string)Dynamitey.Dynamic.InvokeGetChain(item, prop)) ?? "";
                if (!string.IsNullOrEmpty(t))
                {
                    Osoba os = Osoby.GetByNameId.Get(t);
                    if (os != null)
                    {
                        topTxts.Add(os.FullName() + ": ");
                        if (!fromAllTopValues)
                        {
                            break;
                        }
                    }
                }
            }

            return(topTxts);
        }
        public IHttpActionResult GetFirmy(int id)
        {
            Firmy firmy = db.Firmy.Find(id);

            if (firmy == null)
            {
                return(NotFound());
            }

            return(Ok(firmy));
        }
Exemple #8
0
        public Calculator(string ico)
        {
            this.Ico = ico;

            this.urad = Firmy.Get(this.Ico);
            if (urad.Valid == false)
            {
                throw new ArgumentOutOfRangeException("invalid ICO");
            }

            kindex = KIndexData.GetDirect(ico);
        }
Exemple #9
0
        private bool TryGetCompany(string id, out Firma firma, out ActionResult actionResult)
        {
            firma = null;

            if (string.IsNullOrWhiteSpace(id))
            {
                actionResult = RedirectToAction("Index");
                return(false);
            }

            string ico = Util.ParseTools.NormalizeIco(id);

            if (string.IsNullOrEmpty(ico))
            {
                actionResult = RedirectToAction("Report", new { id = "1" });;
                return(false);
            }

            firma = Firmy.Get(ico);

            if (!Firma.IsValid(firma))
            {
                if (Util.DataValidators.IsFirmaIcoZahranicni(ico))
                {
                    actionResult = View("Subjekt_zahranicni", new Firma()
                    {
                        ICO = ico, Jmeno = ico
                    });
                }
                else
                {
                    if (!Util.DataValidators.CheckCZICO(ico))
                    {
                        actionResult = View("Subjekt_err_spatneICO");
                    }
                    else
                    {
                        actionResult = View("Subjekt_err_nezname");
                    }
                }
                return(false);
            }
            if (Util.DataValidators.IsFirmaIcoZahranicni(ico))
            {
                actionResult = View("Subjekt_zahranicni", firma);
                return(false);
            }

            actionResult = View("Index", firma);
            return(true);
        }
        public IHttpActionResult DeleteFirmy(int id)
        {
            Firmy firmy = db.Firmy.Find(id);

            if (firmy == null)
            {
                return(NotFound());
            }

            db.Firmy.Remove(firmy);
            db.SaveChanges();

            return(Ok(firmy));
        }
Exemple #11
0
        public KIndexData.Annual FinalCalculationKIdx(KIndexData.Annual ret, bool forceCalculateAllYears)
        {
            decimal smlouvyZaRok = (decimal)urad.StatistikaRegistruSmluv()[ret.Rok].PocetSmluv;

            CalculateKIndex(ret);

            if (
                ret.Statistika.PocetSmluvSeSoukromymSubj >= Consts.MinSmluvPerYear
                ||
                ret.Statistika.CelkovaHodnotaSmluvSeSoukrSubj >= Consts.MinSumSmluvPerYear
                ||
                (ret.Statistika.CelkovaHodnotaSmluvSeSoukrSubj + ret.Statistika.PrumernaHodnotaSmluvSeSoukrSubj * ret.Statistika.PocetSmluvBezCenySeSoukrSubj) >= Consts.MinSumSmluvPerYear
                )
            {
                ret.KIndexReady  = true;
                ret.KIndexIssues = null;
            }
            else if (Firmy.Get(this.Ico).MusiPublikovatDoRS() == false)
            {
                if (forceCalculateAllYears == false)
                {
                    ret.KIndexReady  = false;
                    ret.KIndexIssues = new string[] { $"K-Index spočítán, ale organizace ze zákona nemusí do registru smluv publikovat. Publikuje pouze dobrovolně, proto K-Index nezveřejňujeme." };
                }
                else
                {
                    ret.KIndexReady  = true;
                    ret.KIndexIssues = new string[] { $"Organizace ze zákona nemusí do registru smluv publikovat. Publikuje pouze dobrovolně, nad rámec zákona." };
                }
            }
            else
            {
                if (forceCalculateAllYears == false)
                {
                    ret.KIndexReady  = false;
                    ret.KIndexIssues = new string[] { $"K-Index nespočítán. Méně než {Consts.MinSmluvPerYear} smluv za rok nebo malý objem smluv." };
                }
                else
                {
                    ret.KIndexReady  = true;
                    ret.KIndexIssues = new string[] { $"Organizace má méně smluv nebo objem smluv než určuje metodika. Pro výpočet a publikaci byla aplikována výjimka." };
                }
            }


            ret.LastUpdated = DateTime.Now;

            return(ret);
        }
        //todo: What are we going to do with this?
        public ActionResult Debug(string id, string ico = "", int?rok = null)
        {
            if (!Framework.HtmlExtensions.ShowKIndex(this.User))
            {
                return(Redirect("/"));
            }
            if (
                !(this.User.IsInRole("Admin") || this.User.IsInRole("KIndex"))
                )
            {
                return(Redirect("/"));
            }

            if (string.IsNullOrEmpty(id))
            {
                return(View("Debug.Start"));
            }

            if (Util.DataValidators.CheckCZICO(Util.ParseTools.NormalizeIco(id)))
            {
                KIndexData kdata = KIndex.Get(Util.ParseTools.NormalizeIco(id));
                ViewBag.ICO = id;
                return(View("Debug", kdata));
            }
            else if (id?.ToLower() == "porovnat")
            {
                List <KIndexData> kdata = new List <KIndexData>();

                foreach (var i in ico.Split(new char[] { ' ', ',', ';' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    var f = Firmy.Get(Util.ParseTools.NormalizeIco(i));
                    if (f.Valid)
                    {
                        var kidx = KIndex.Get(Util.ParseTools.NormalizeIco(i));
                        if (kidx != null)
                        {
                            kdata.Add(kidx);
                        }
                    }
                }
                return(View("Debug.Porovnat", kdata));
            }
            else
            {
                return(NotFound());
            }
        }
Exemple #13
0
        public static IEnumerable <string> AllIcoInRS(bool includedIcosInHoldings = false)
        {
            using (PersistLib p = new PersistLib())
            {
                string sql = @"select ico from Firma where IsInRS = 1";

                var res = p.ExecuteDataset(cnnStr, System.Data.CommandType.Text, sql, null);

                if (res.Tables.Count > 0 && res.Tables[0].Rows.Count > 0)
                {
                    var allIcos = res.Tables[0]
                                  .AsEnumerable()
                                  .Where(r => Devmasters.TextUtil.IsNumeric((string)r["ICO"]))
                                  .Select(r => (string)r["ICO"])
                                  .ToArray();
                    if (includedIcosInHoldings == false)
                    {
                        return(allIcos);
                    }
                    else
                    {
                        HashSet <string> holdingIcos = new HashSet <string>();
                        foreach (var i in allIcos)
                        {
                            if (!holdingIcos.Contains(i))
                            {
                                holdingIcos.Add(i);
                            }
                            Firma f = Firmy.Get(i);
                            foreach (var hi in f.IcosInHolding(Relation.AktualnostType.Nedavny))
                            {
                                if (!holdingIcos.Contains(hi))
                                {
                                    holdingIcos.Add(hi);
                                }
                            }
                        }
                        return(holdingIcos);
                    }
                }
                else
                {
                    return new string[] { }
                };
            }
        }
        public ActionResult Porovnat(string id, int?rok = null)
        {
            if (!Framework.HtmlExtensions.ShowKIndex(this.User))
            {
                //todo: přidat base view, kde pokud nebude žádná hodnota v id, tak zobrazíme základní porovnání
                return(Redirect("/"));
            }

            rok = Consts.FixKindexYear(rok);
            ViewBag.SelectedYear = rok;

            var results = new List <SubjectWithKIndexAnnualData>();

            if (string.IsNullOrWhiteSpace(id))
            {
                return(View(results));
            }


            foreach (var i in id.Split(new char[] { ' ', ',', ';' }, StringSplitOptions.RemoveEmptyEntries))
            {
                var f = Firmy.Get(Util.ParseTools.NormalizeIco(i));
                if (f.Valid)
                {
                    SubjectWithKIndexAnnualData data = new SubjectWithKIndexAnnualData()
                    {
                        Ico   = f.ICO,
                        Jmeno = f.Jmeno
                    };
                    try
                    {
                        data.PopulateWithAnnualData(rok.Value);
                    }
                    catch (Exception)
                    {
                        // chybí ičo v objeku data
                        continue;
                    }
                    results.Add(data);
                }
            }


            return(View(results));
        }
Exemple #15
0
        internal void Remove(TableBase table)
        {
            switch (table)
            {
            case Firma f:
                f.MainPerson = null;
                SaveChanges();
                while (f.SubTable.Any())
                {
                    Remove(f.SubTable.First());
                }
                Firmy.Remove(f);
                break;

            case Divizia d:
                d.MainPerson = null;
                SaveChanges();
                while (d.SubTable.Any())
                {
                    Remove(d.SubTable.First());
                }
                Divizie.Remove(d);
                break;

            case Projekt p:
                p.MainPerson = null;
                SaveChanges();
                while (p.SubTable.Any())
                {
                    Remove(p.SubTable.First());
                }
                Projekty.Remove(p);
                break;

            case Oddelenie o:
                o.MainPerson = null;
                SaveChanges();
                Oddelenia.Remove(o);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
        public ActionResult RecalculateFeedback(string email, string txt, string url, string data)
        {
            // create a task, so user doesn't have to wait for anything
            System.Threading.Tasks.Task.Run(() =>
            {
                var f = Firmy.Get(Util.ParseTools.NormalizeIco(data));
                if (f.Valid)
                {
                    try
                    {
                        //string connectionString = Devmasters.Config.GetWebConfigValue("RabbitMqConnectionString");
                        //if (string.IsNullOrWhiteSpace(connectionString))
                        //    throw new Exception("Missing RabbitMqConnectionString");

                        //var message = new Q.Messages.RecalculateKindex()
                        //{
                        //    Comment = txt,
                        //    Created = DateTime.Now,
                        //    Ico = f.ICO,
                        //    User = this.User.Identity.Name
                        //};

                        //Q.Publisher.QuickPublisher.Publish(message, connectionString);

                        string body = $@"
Žádost o rekalkulaci K-Indexu z hlidacstatu.cz.

Pro firmu:{f.ICO}
Od uzivatele:{email} [{this.User.Identity.Name}] (Emaily by se zde měli shodovat)
ke stránce:{url}

text zpravy: {txt}";
                        Util.SMTPTools.SendSimpleMailToPodpora("Žádost o rekalkulaci K-indexu", body, email);
                    }
                    catch (Exception ex)
                    {
                        Util.Consts.Logger.Fatal($"Problem with SMTP. Message={ex}");
                    }
                }
            });
            return(Content(""));
        }
Exemple #17
0
        public IActionResult AddCompany()
        {
            Firmy  firmy  = new Firmy();
            string nazwa  = HttpContext.Request.Form["txtNazwa"].ToString();
            string adres  = HttpContext.Request.Form["txtAdres"].ToString();
            string miasto = HttpContext.Request.Form["txtMiasto"].ToString();
            string kod    = HttpContext.Request.Form["txtKod"].ToString();
            string bank   = HttpContext.Request.Form["txtBank"].ToString();
            string konto  = HttpContext.Request.Form["txtKonto"].ToString();
            int    result = firmy.SaveDetails(nazwa, adres, miasto, kod, bank, konto);

            if (result > 0)
            {
                HttpContext.Session.SetString("NowaFirmaInfo", "Firma zostala dodana poprawnie");
            }
            else
            {
                HttpContext.Session.SetString("NowaFirmaInfo", "Bład");
            }
            return(RedirectToAction("Index"));
        }
        public JsonResult KindexForIco(string id, int?rok = null)
        {
            rok = Consts.FixKindexYear(rok);
            var f = Firmy.Get(Util.ParseTools.NormalizeIco(id));

            if (f.Valid)
            {
                var kidx = KIndex.Get(Util.ParseTools.NormalizeIco(id));

                if (kidx != null)
                {
                    var radky = kidx.ForYear(rok.Value).KIndexVypocet.Radky
                                .Select(r => new
                    {
                        VelicinaName = r.VelicinaName,
                        Label        = KIndexData.KindexImageIcon(KIndexData.DetailInfo.KIndexLabelForPart(r.VelicinaPart, r.Hodnota),
                                                                  "height: 25px",
                                                                  showNone: true,
                                                                  KIndexData.KIndexCommentForPart(r.VelicinaPart, kidx.ForYear(rok.Value))),
                        Value = r.Hodnota.ToString("F2")
                    }).ToList();

                    var result = new
                    {
                        UniqueId = Guid.NewGuid(),
                        Ico      = kidx.Ico,
                        Jmeno    = Devmasters.TextUtil.ShortenText(kidx.Jmeno, 55),
                        Kindex   = KIndexData.KindexImageIcon(kidx.ForYear(rok.Value).KIndexLabel,
                                                              "height: 40px",
                                                              showNone: true),
                        Radky       = radky,
                        KindexReady = kidx.ForYear(rok.Value).KIndexReady
                    };

                    return(Json(result, JsonRequestBehavior.AllowGet));
                }
            }
            return(Json(null, JsonRequestBehavior.AllowGet));
        }
Exemple #19
0
        internal void Add(TableBase table)
        {
            switch (table)
            {
            case Firma f:
                Firmy.Add(f);
                break;

            case Divizia d:
                Divizie.Add(d);
                break;

            case Projekt p:
                Projekty.Add(p);
                break;

            case Oddelenie o:
                Oddelenia.Add(o);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Exemple #20
0
 public EditCompany(Firmy x)
 {
     InitializeComponent();
     this.x = x;
     Load();
 }
Exemple #21
0
        ComplexStatisticDefaultReportColumns <T>(HlidacStatu.Util.RenderData.MaxScale scale,
                                                 int?minDateYear = null, int?maxDateYear = null)
        {
            minDateYear = minDateYear ?? HlidacStatu.Lib.Analysis.BasicDataPerYear.UsualFirstYear;
            maxDateYear = maxDateYear ?? DateTime.Now.Year;

            var coreColumns = new List <ReportDataSource <KeyValuePair <string, HlidacStatu.Lib.Analysis.ComplexStatistic <T> > > .Column>();

            coreColumns.Add(
                new ReportDataSource <KeyValuePair <string, HlidacStatu.Lib.Analysis.ComplexStatistic <T> > > .Column()
            {
                Id         = "Title",
                Name       = "Plátci",
                HtmlRender = (s) =>
                {
                    var f = Firmy.Get(s.Key);
                    return(string.Format("<a href='{0}'>{1}</a>", f.GetUrl(false), f.Jmeno));
                },
                OrderValueRender = (s) => HlidacStatu.Lib.Data.Firmy.GetJmeno(s.Key),
                ValueRender      = (s) => HlidacStatu.Lib.Data.Firmy.GetJmeno(s.Key),
                TextRender       = (s) => HlidacStatu.Lib.Data.Firmy.GetJmeno(s.Key)
            });

            for (int y = minDateYear.Value; y <= maxDateYear.Value; y++)
            {
                int year = y;
                coreColumns.Add(
                    new ReportDataSource <KeyValuePair <string, HlidacStatu.Lib.Analysis.ComplexStatistic <T> > > .Column()
                {
                    Id               = "Cena_Y_" + year,
                    Name             = $"Smlouvy {year} v {scale.ToNiceDisplayName()} Kč",
                    HtmlRender       = (s) => HlidacStatu.Util.RenderData.ShortNicePrice(s.Value.BasicStatPerYear[year].CelkemCena, mena: "", html: true, showDecimal: HlidacStatu.Util.RenderData.ShowDecimalVal.Show, exactScale: scale, hideSuffix: true),
                    OrderValueRender = (s) => HlidacStatu.Util.RenderData.OrderValueFormat(s.Value.BasicStatPerYear[year].CelkemCena),
                    TextRender       = (s) => HlidacStatu.Util.RenderData.ShortNicePrice(s.Value.BasicStatPerYear[year].CelkemCena, mena: "", html: false, showDecimal: HlidacStatu.Util.RenderData.ShowDecimalVal.Show, exactScale: scale, hideSuffix: true),
                    ValueRender      = (s) => s.Value.BasicStatPerYear[year].CelkemCena,
                    CssClass         = "number"
                }
                    );
                coreColumns.Add(
                    new ReportDataSource <KeyValuePair <string, HlidacStatu.Lib.Analysis.ComplexStatistic <T> > > .Column()
                {
                    Id               = "Pocet_Y_" + year,
                    Name             = $"Počet smluv v {year} ",
                    HtmlRender       = (s) => HlidacStatu.Util.RenderData.NiceNumber(s.Value.BasicStatPerYear[year].Pocet, html: true),
                    OrderValueRender = (s) => HlidacStatu.Util.RenderData.OrderValueFormat(s.Value.BasicStatPerYear[year].Pocet),
                    TextRender       = (s) => HlidacStatu.Util.RenderData.NiceNumber(s.Value.BasicStatPerYear[year].Pocet, html: false),
                    ValueRender      = (s) => s.Value.BasicStatPerYear[year].Pocet,
                    CssClass         = "number"
                }
                    );
                coreColumns.Add(
                    new ReportDataSource <KeyValuePair <string, HlidacStatu.Lib.Analysis.ComplexStatistic <T> > > .Column()
                {
                    Id               = "PercentBezCeny_Y_" + year,
                    Name             = $"Smluv bez ceny za {year} v %",
                    HtmlRender       = (s) => s.Value.RatingPerYear.Data[year].PercentBezCeny.ToString("P2"),
                    OrderValueRender = (s) => HlidacStatu.Util.RenderData.OrderValueFormat(s.Value.RatingPerYear.Data[year].PercentBezCeny),
                    ValueRender      = (s) => (s.Value.RatingPerYear.Data[year].PercentBezCeny * 100).ToString(HlidacStatu.Util.Consts.enCulture),
                    TextRender       = (s) => s.Value.RatingPerYear.Data[year].PercentBezCeny.ToString("P2"),
                    CssClass         = "number"
                });
                coreColumns.Add(
                    new ReportDataSource <KeyValuePair <string, HlidacStatu.Lib.Analysis.ComplexStatistic <T> > > .Column()
                {
                    Id               = "PercentSPolitiky_Y_" + year,
                    Name             = $"Smluv bez ceny za {year} v %",
                    HtmlRender       = (s) => s.Value.RatingPerYear.Data[year].PercentSPolitiky.ToString("P2"),
                    OrderValueRender = (s) => HlidacStatu.Util.RenderData.OrderValueFormat(s.Value.RatingPerYear.Data[year].PercentSPolitiky),
                    ValueRender      = (s) => (s.Value.RatingPerYear.Data[year].PercentSPolitiky * 100).ToString(HlidacStatu.Util.Consts.enCulture),
                    TextRender       = (s) => s.Value.RatingPerYear.Data[year].PercentSPolitiky.ToString("P2"),
                    CssClass         = "number"
                });
                coreColumns.Add(
                    new ReportDataSource <KeyValuePair <string, HlidacStatu.Lib.Analysis.ComplexStatistic <T> > > .Column()
                {
                    Id               = "SumKcSPolitiky_Y_" + year,
                    Name             = $"Smluv bez ceny za {year} v %",
                    HtmlRender       = (s) => s.Value.RatingPerYear.Data[year].SumKcSPolitiky.ToString("P2"),
                    OrderValueRender = (s) => HlidacStatu.Util.RenderData.OrderValueFormat(s.Value.RatingPerYear.Data[year].SumKcSPolitiky),
                    ValueRender      = (s) => (s.Value.RatingPerYear.Data[year].SumKcSPolitiky * 100).ToString(HlidacStatu.Util.Consts.enCulture),
                    TextRender       = (s) => s.Value.RatingPerYear.Data[year].SumKcSPolitiky.ToString("P2"),
                    CssClass         = "number"
                });

                if (year > minDateYear)
                {
                    coreColumns.Add(
                        new ReportDataSource <KeyValuePair <string, HlidacStatu.Lib.Analysis.ComplexStatistic <T> > > .Column()
                    {
                        Id               = "CenaChangePercent_Y_" + year,
                        Name             = $"Změna hodnoty smlouvy {year - 1}-{year}",
                        HtmlRender       = (s) => s.Value.BasicStatPerYear.YearChange(year).CenaChangePercentToSymbolString(true),
                        OrderValueRender = (s) => HlidacStatu.Util.RenderData.OrderValueFormat(s.Value.BasicStatPerYear.YearChange(year).CenaChangePerc),
                        ValueRender      = (s) => (s.Value.BasicStatPerYear.YearChange(year).CenaChangePerc * 100).ToString(HlidacStatu.Util.Consts.enCulture),
                        TextRender       = (s) => (s.Value.BasicStatPerYear.YearChange(year).CenaChangePerc).ToString("P2"),
                        CssClass         = "number"
                    }
                        );
                }
            }
            ;
            coreColumns.Add(
                new ReportDataSource <KeyValuePair <string, HlidacStatu.Lib.Analysis.ComplexStatistic <T> > > .Column()
            {
                Id               = "CenaCelkem",
                Name             = $"Smlouvy 2016-18 v {scale.ToNiceDisplayName()} Kč",
                HtmlRender       = (s) => HlidacStatu.Util.RenderData.ShortNicePrice(s.Value.BasicStatPerYear.Summary.CelkemCena, mena: "", html: true, showDecimal: HlidacStatu.Util.RenderData.ShowDecimalVal.Show, exactScale: scale, hideSuffix: true),
                OrderValueRender = (s) => HlidacStatu.Util.RenderData.OrderValueFormat(s.Value.BasicStatPerYear.Summary.CelkemCena),
                CssClass         = "number"
            });

            return(coreColumns);
        }
Exemple #22
0
        public static IEnumerable <Statistics> Calculate(string[] forIcos = null, bool futureKIDX = false)
        {
            var client = ES.Manager.GetESClient_KIndex();

            //if (!string.IsNullOrEmpty(Devmasters.Config.GetWebConfigValue("UseKindexTemp")))
            if (futureKIDX)
            {
                client = ES.Manager.GetESClient_KIndexTemp();
            }

            int[] calculationYears = Consts.ToCalculationYears;
            Func <int, int, Nest.ISearchResponse <Lib.Analysis.KorupcniRiziko.KIndexData> > searchfnc = null;

            if (forIcos != null)
            {
                searchfnc = (size, page) =>
                {
                    return(client.Search <Lib.Analysis.KorupcniRiziko.KIndexData>(a => a
                                                                                  .Size(size)
                                                                                  .From(page * size)
                                                                                  .Query(q => q.Terms(t => t.Field(f => f.Ico).Terms(forIcos)))
                                                                                  .Scroll("10m")
                                                                                  ));
                };
            }
            else
            {
                searchfnc = (size, page) =>
                {
                    return(client.Search <Lib.Analysis.KorupcniRiziko.KIndexData>(a => a
                                                                                  .Size(size)
                                                                                  .From(page * size)
                                                                                  .Query(q => q.MatchAll())
                                                                                  .Scroll("10m")
                                                                                  ));
                };
            };

            List <Lib.Analysis.KorupcniRiziko.KIndexData> data = new List <Analysis.KorupcniRiziko.KIndexData>();

            Lib.Searching.Tools.DoActionForQuery <Lib.Analysis.KorupcniRiziko.KIndexData>(client,
                                                                                          searchfnc,
                                                                                          (hit, param) =>
            {
                if (hit.Source.roky.Any(m => m.KIndexReady))
                {
                    data.Add(hit.Source);
                }


                return(new Devmasters.Batch.ActionOutputData()
                {
                    CancelRunning = false, Log = null
                });
            }, null, Devmasters.Batch.Manager.DefaultOutputWriter, Devmasters.Batch.Manager.DefaultProgressWriter,
                                                                                          false, prefix: "GET data ");


            List <Statistics> stats = new List <Statistics>();

            foreach (var year in calculationYears)
            {
                var datayear = data
                               .Where(m => (forIcos == null || forIcos?.Contains(m.Ico) == true))
                               .Select(m => new { ic = m.Ico, data = m.ForYear(year) })
                               .Where(y => y != null && y.data != null && y.data.KIndexReady)
                               .ToDictionary(k => k.ic, v => v.data);

                if (datayear.Count == 0)
                {
                    continue;
                }

                var stat = new Statistics()
                {
                    Rok = year
                };
                //poradi
                stat.SubjektOrderedListKIndexAsc = datayear
                                                   .Where(m => m.Value.KIndexReady)
                                                   .Select(m => {
                    var company = Firmy.Get(m.Key);
                    return(m.Key, m.Value.KIndex, company.KrajId);
                })
                                                   .OrderBy(m => m.KIndex)
                                                   .ToList();
                foreach (KIndexData.KIndexParts part in Enum.GetValues(typeof(KIndexData.KIndexParts)))
                {
                    stat.SubjektOrderedListPartsAsc.Add(part, datayear
                                                        .Where(m => m.Value.KIndexReady)
                                                        .Where(m => m.Value.KIndexVypocet.Radky.Any(r => r.VelicinaPart == part))
                                                        .Select(m => {
                        var company = Firmy.Get(m.Key);
                        return(m.Key, m.Value.KIndexVypocet.Radky.First(r => r.VelicinaPart == part).Hodnota, company.KrajId);
                    })
                                                        .OrderBy(m => m.Hodnota)
                                                        .ToList()
                                                        );
                }

                //prumery
                stat.AverageKindex = datayear.Average(m => m.Value.KIndex);

                stat.AverageParts = new KIndexData.VypocetDetail();
                List <KIndexData.VypocetDetail.Radek> radky = new List <KIndexData.VypocetDetail.Radek>();
                foreach (KIndexData.KIndexParts part in Enum.GetValues(typeof(KIndexData.KIndexParts)))
                {
                    decimal val = datayear
                                  .Select(m => m.Value.KIndexVypocet.Radky
                                          .FirstOrDefault(r => r.Velicina == (int)part))
                                  .Where(a => a != null)
                                  .Average(a => a.Hodnota);

                    KIndexData.VypocetDetail.Radek radek = new KIndexData.VypocetDetail.Radek(part, val, KIndexData.DetailInfo.DefaultKIndexPartKoeficient(part));
                    radky.Add(radek);
                }
                stat.AverageParts = new KIndexData.VypocetDetail()
                {
                    Radky = radky.ToArray()
                };


                //percentily
                stat.PercentileKIndex = new Dictionary <int, decimal>();
                stat.PercentileParts  = new Dictionary <int, KIndexData.VypocetDetail>();


                foreach (var perc in Percentiles)
                {
                    stat.PercentileKIndex.Add(perc,
                                              HlidacStatu.Util.MathTools.PercentileCont(perc / 100m, datayear.Select(m => m.Value.KIndex))
                                              );

                    radky = new List <KIndexData.VypocetDetail.Radek>();
                    foreach (KIndexData.KIndexParts part in Enum.GetValues(typeof(KIndexData.KIndexParts)))
                    {
                        decimal val = HlidacStatu.Util.MathTools.PercentileCont(perc / 100m,
                                                                                datayear
                                                                                .Select(m => m.Value.KIndexVypocet.Radky.FirstOrDefault(r => r.Velicina == (int)part))
                                                                                .Where(m => m != null)
                                                                                .Select(m => m.Hodnota)
                                                                                );
                        KIndexData.VypocetDetail.Radek radek = new KIndexData.VypocetDetail.Radek(part, val, KIndexData.DetailInfo.DefaultKIndexPartKoeficient(part));
                        radky.Add(radek);
                    }
                    stat.PercentileParts.Add(perc, new KIndexData.VypocetDetail()
                    {
                        Radky = radky.ToArray()
                    });
                }

                stats.Add(stat);
            } //year

            return(stats);
        }
Exemple #23
0
        public IEnumerable <SmlouvyForIndex> GetSmlouvy(string query)
        {
            Func <int, int, Nest.ISearchResponse <Lib.Data.Smlouva> > searchFunc = (size, page) =>
            {
                return(Lib.ES.Manager.GetESClient().Search <Lib.Data.Smlouva>(a => a
                                                                              .Size(size)
                                                                              .Source(ss => ss.Excludes(sml => sml.Field(ff => ff.Prilohy)))
                                                                              .From(page * size)
                                                                              .Query(q => Lib.Data.Smlouva.Search.GetSimpleQuery(query))
                                                                              .Scroll("1m")
                                                                              ));
            };

            List <smlouvaStat> smlStat = new List <smlouvaStat>();

            Searching.Tools.DoActionForQuery <Lib.Data.Smlouva>(Lib.ES.Manager.GetESClient(),
                                                                searchFunc,
                                                                (h, o) =>
            {
                Smlouva s = h.Source;
                if (s != null)
                {
                    foreach (var prij in s.Prijemce)
                    {
                        if (prij.ico == s.Platce.ico)
                        {
                            continue;
                        }
                        Firma f = Firmy.Get(prij.ico);
                        if (f.Valid && f.PatrimStatuAlespon25procent())
                        {
                            continue;
                        }

                        string dodavatel = prij.ico;
                        if (string.IsNullOrWhiteSpace(dodavatel))
                        {
                            dodavatel = prij.nazev;
                        }
                        if (string.IsNullOrWhiteSpace(dodavatel))
                        {
                            dodavatel = "neznamy";
                        }

                        smlStat.Add(new smlouvaStat()
                        {
                            Id            = s.Id,
                            IcoDodavatele = dodavatel,
                            CastkaSDPH    = Math.Abs((decimal)s.CalculatedPriceWithVATinCZK / (decimal)s.Prijemce.Length),
                            Podepsano     = s.datumUzavreni,
                            Rok           = s.datumUzavreni.Year,
                            ULimitu       = s.Hint?.SmlouvaULimitu ?? 0,
                            Obory         = s.GetRelevantClassification()
                                            .OrderByDescending(oo => oo.ClassifProbability)
                                            .Select(m => m.TypeValue).ToArray()
                        });;
                    }
                }

                return(new Devmasters.Batch.ActionOutputData());
            }, null,
                                                                null, null,
                                                                false, blockSize: 100);

            IEnumerable <SmlouvyForIndex> smlouvy = smlStat
                                                    .Select(m => new SmlouvyForIndex(m.IcoDodavatele, m.CastkaSDPH, m.ULimitu, m.Obory))
                                                    .OrderByDescending(m => m.HodnotaSmlouvy) //just better debug
                                                    .ToArray();                               //just better debug

            return(smlouvy);
        }
Exemple #24
0
        public ActionResult TransparentniUctyFullExport()
        {
            string login = "";
            List <BankovniPolozkaForExport> items = new List <BankovniPolozkaForExport>();

            if (Framework.ApiAuth.IsApiAuth(this, parameters: new Framework.ApiCall.CallParameter[] { new Framework.ApiCall.CallParameter("TransparentniUctyFullExport", "") }).Authentificated)
            {
                if (!string.IsNullOrEmpty(this.User?.Identity?.Name))
                {
                    login = this.User?.Identity?.Name;
                }
                if (login == "*****@*****.**" || login == "*****@*****.**" || login == "*****@*****.**")
                {
                    HlidacStatu.Lib.ES.SearchTools.DoActionForAll <HlidacStatu.Lib.Data.TransparentniUcty.BankovniPolozka>(
                        (t, obj) =>
                    {
                        var bp = t.Source;

                        Osoba o = null;
                        Firma f = null;
                        if (bp.Comments.Any(m => m.Type == HlidacStatu.Lib.Data.TransparentniUcty.BankovniPolozka.Comment.Types.VazbaNaOsobu))
                        {
                            o = Osoby.GetById.Get(
                                bp.Comments
                                .Where(m => m.Type == HlidacStatu.Lib.Data.TransparentniUcty.BankovniPolozka.Comment.Types.VazbaNaOsobu)
                                .First()
                                .ValueInt);
                        }
                        if (bp.Comments.Any(m => m.Type == HlidacStatu.Lib.Data.TransparentniUcty.BankovniPolozka.Comment.Types.VazbaNaFirmu))
                        {
                            f = Firmy.Get(
                                bp.Comments
                                .Where(m => m.Type == HlidacStatu.Lib.Data.TransparentniUcty.BankovniPolozka.Comment.Types.VazbaNaFirmu)
                                .First()
                                .ValueInt);
                            if (f.Valid == false)
                            {
                                f = null;
                            }
                        }


                        BankovniPolozkaForExport bpe = new Controllers.ApiV1Controller.BankovniPolozkaForExport();
                        bpe.Transaction          = bp;
                        bpe.Transaction.Comments = null;
                        if (o != null)
                        {
                            bpe.FoundPerson = new BankovniPolozkaForExport.xOsoba()
                            {
                                Jmeno     = o.Jmeno,
                                NameId    = o.NameId,
                                Narozeni  = o.Narozeni,
                                Prijmeni  = o.Prijmeni,
                                TitulPred = o.TitulPred,
                                TitulPo   = o.TitulPo
                            }
                        }
                        ;

                        if (f != null)
                        {
                            bpe.FoundCompany = new BankovniPolozkaForExport.xFirma()
                            {
                                ICO   = f.ICO,
                                Jmeno = f.Jmeno
                            }
                        }
                        ;

                        items.Add(bpe);

                        return(new Devmasters.Core.Batch.ActionOutputData());
                    }, null,
                        null, new Devmasters.Core.Batch.ActionProgressWriter(1f).Write,
                        false,
                        elasticClient: HlidacStatu.Lib.ES.Manager.GetESClient_Ucty(),
                        blockSize: 50)
                    ;
                }
            }
            return(Content(Newtonsoft.Json.JsonConvert.SerializeObject(items, Newtonsoft.Json.Formatting.None), "application/json"));
        }
Exemple #25
0
        ComplexStatisticDefaultReportColumns <T>(HlidacStatu.Util.RenderData.MaxScale scale,
                                                 int?minDateYear = null, int?maxDateYear = null, string query = null)
        {
            minDateYear = minDateYear ?? HlidacStatu.Lib.Analysis.BasicDataPerYear.UsualFirstYear;
            maxDateYear = maxDateYear ?? DateTime.Now.Year;

            var coreColumns = new List <ReportDataSource <KeyValuePair <string, Lib.Analytics.StatisticsPerYear <Data.Smlouva.Statistics.Data> > > .Column>();

            coreColumns.Add(
                new ReportDataSource <KeyValuePair <string, Lib.Analytics.StatisticsPerYear <Data.Smlouva.Statistics.Data> > > .Column()
            {
                Id         = "Title",
                Name       = "Plátci",
                HtmlRender = (s) =>
                {
                    var f       = Firmy.Get(s.Key);
                    string html = string.Format("<a href='{0}'>{1}</a>", f.GetUrl(false), f.Jmeno);
                    if (!string.IsNullOrEmpty(query))
                    {
                        html += $" /<span class='small'>ukázat&nbsp;<a href='/hledat?q={System.Net.WebUtility.UrlEncode(Searching.Query.ModifyQueryAND("ico:" + f.ICO, query))}'>smlouvy</a></span>/";
                    }
                    return(html);
                },
                OrderValueRender = (s) => HlidacStatu.Lib.Data.Firmy.GetJmeno(s.Key),
                ValueRender      = (s) => HlidacStatu.Lib.Data.Firmy.GetJmeno(s.Key),
                TextRender       = (s) => HlidacStatu.Lib.Data.Firmy.GetJmeno(s.Key)
            });

            for (int y = minDateYear.Value; y <= maxDateYear.Value; y++)
            {
                int year = y;
                coreColumns.Add(
                    new ReportDataSource <KeyValuePair <string, Lib.Analytics.StatisticsPerYear <Data.Smlouva.Statistics.Data> > > .Column()
                {
                    Id               = "Cena_Y_" + year,
                    Name             = $"Smlouvy {year} v {scale.ToNiceDisplayName()} Kč",
                    HtmlRender       = (s) => HlidacStatu.Util.RenderData.ShortNicePrice(s.Value[year].CelkovaHodnotaSmluv, mena: "", html: true, showDecimal: HlidacStatu.Util.RenderData.ShowDecimalVal.Show, exactScale: scale, hideSuffix: true),
                    OrderValueRender = (s) => HlidacStatu.Util.RenderData.OrderValueFormat(s.Value[year].CelkovaHodnotaSmluv),
                    TextRender       = (s) => HlidacStatu.Util.RenderData.ShortNicePrice(s.Value[year].CelkovaHodnotaSmluv, mena: "", html: false, showDecimal: HlidacStatu.Util.RenderData.ShowDecimalVal.Show, exactScale: scale, hideSuffix: true),
                    ValueRender      = (s) => s.Value[year].CelkovaHodnotaSmluv,
                    CssClass         = "number"
                }
                    );
                coreColumns.Add(
                    new ReportDataSource <KeyValuePair <string, Lib.Analytics.StatisticsPerYear <Data.Smlouva.Statistics.Data> > > .Column()
                {
                    Id               = "Pocet_Y_" + year,
                    Name             = $"Počet smluv v {year} ",
                    HtmlRender       = (s) => HlidacStatu.Util.RenderData.NiceNumber(s.Value[year].PocetSmluv, html: true),
                    OrderValueRender = (s) => HlidacStatu.Util.RenderData.OrderValueFormat(s.Value[year].PocetSmluv),
                    TextRender       = (s) => HlidacStatu.Util.RenderData.NiceNumber(s.Value[year].PocetSmluv, html: false),
                    ValueRender      = (s) => s.Value[year].PocetSmluv,
                    CssClass         = "number"
                }
                    );
                coreColumns.Add(
                    new ReportDataSource <KeyValuePair <string, Lib.Analytics.StatisticsPerYear <Data.Smlouva.Statistics.Data> > > .Column()
                {
                    Id               = "PercentBezCeny_Y_" + year,
                    Name             = $"Smluv bez ceny za {year} v %",
                    HtmlRender       = (s) => s.Value[year].PercentSmluvBezCeny.ToString("P2"),
                    OrderValueRender = (s) => HlidacStatu.Util.RenderData.OrderValueFormat(s.Value[year].PercentSmluvBezCeny),
                    ValueRender      = (s) => (s.Value[year].PercentSmluvBezCeny * 100).ToString(HlidacStatu.Util.Consts.enCulture),
                    TextRender       = (s) => s.Value[year].PercentSmluvBezCeny.ToString("P2"),
                    CssClass         = "number"
                });
                coreColumns.Add(
                    new ReportDataSource <KeyValuePair <string, Lib.Analytics.StatisticsPerYear <Data.Smlouva.Statistics.Data> > > .Column()
                {
                    Id               = "PercentSPolitiky_Y_" + year,
                    Name             = $"% smluv s politiky v {year} ",
                    HtmlRender       = (s) => s.Value[year].PercentSmluvPolitiky.ToString("P2"),
                    OrderValueRender = (s) => HlidacStatu.Util.RenderData.OrderValueFormat(s.Value[year].PercentSmluvPolitiky),
                    ValueRender      = (s) => (s.Value[year].PercentSmluvPolitiky * 100).ToString(HlidacStatu.Util.Consts.enCulture),
                    TextRender       = (s) => s.Value[year].PercentSmluvPolitiky.ToString("P2"),
                    CssClass         = "number"
                });
                coreColumns.Add(
                    new ReportDataSource <KeyValuePair <string, Lib.Analytics.StatisticsPerYear <Data.Smlouva.Statistics.Data> > > .Column()
                {
                    Id               = "SumKcSPolitiky_Y_" + year,
                    Name             = $"Hodnota smluv s politiky za {year}",
                    HtmlRender       = (s) => s.Value[year].SumKcSmluvSponzorujiciFirmy.ToString("P2"),
                    OrderValueRender = (s) => HlidacStatu.Util.RenderData.OrderValueFormat(s.Value[year].SumKcSmluvSponzorujiciFirmy),
                    ValueRender      = (s) => (s.Value[year].SumKcSmluvSponzorujiciFirmy * 100).ToString(HlidacStatu.Util.Consts.enCulture),
                    TextRender       = (s) => s.Value[year].SumKcSmluvSponzorujiciFirmy.ToString("P2"),
                    CssClass         = "number"
                });

                if (year > minDateYear)
                {
                    coreColumns.Add(
                        new ReportDataSource <KeyValuePair <string, Lib.Analytics.StatisticsPerYear <Data.Smlouva.Statistics.Data> > > .Column()
                    {
                        Id         = "CenaChangePercent_Y_" + year,
                        Name       = $"Změna hodnoty smlouvy {year - 1}-{year}",
                        HtmlRender = (s) => s.Value.ChangeBetweenYears(year, m => m.CelkovaHodnotaSmluv).percentage.HasValue?
                                     Util.RenderData.ChangeValueSymbol(s.Value.ChangeBetweenYears(year, m => m.CelkovaHodnotaSmluv).percentage.Value, true) :
                                     "",
                        OrderValueRender = (s) => HlidacStatu.Util.RenderData.OrderValueFormat(s.Value.ChangeBetweenYears(year, m => m.CelkovaHodnotaSmluv).percentage ?? 0),
                        ValueRender      = (s) => s.Value.ChangeBetweenYears(year, m => m.CelkovaHodnotaSmluv).percentage.HasValue ?
                                           (s.Value.ChangeBetweenYears(year, m => m.CelkovaHodnotaSmluv).percentage.Value * 100).ToString(HlidacStatu.Util.Consts.enCulture) :
                                           "",
                        TextRender = (s) => s.Value.ChangeBetweenYears(year, m => m.CelkovaHodnotaSmluv).percentage.HasValue ?
                                     (s.Value.ChangeBetweenYears(year, m => m.CelkovaHodnotaSmluv).percentage.Value).ToString("P2") :
                                     "",
                        CssClass = "number"
                    }
                        );
                }
            }
            ;
            coreColumns.Add(
                new ReportDataSource <KeyValuePair <string, Lib.Analytics.StatisticsPerYear <Data.Smlouva.Statistics.Data> > > .Column()
            {
                Id               = "CenaCelkem",
                Name             = $"Smlouvy 2016-{DateTime.Now.Year} v {scale.ToNiceDisplayName()} Kč",
                HtmlRender       = (s) => HlidacStatu.Util.RenderData.ShortNicePrice(s.Value.Sum(m => m.CelkovaHodnotaSmluv), mena: "", html: true, showDecimal: HlidacStatu.Util.RenderData.ShowDecimalVal.Show, exactScale: scale, hideSuffix: true),
                OrderValueRender = (s) => HlidacStatu.Util.RenderData.OrderValueFormat(s.Value.Sum(m => m.CelkovaHodnotaSmluv)),
                CssClass         = "number"
            });

            return(coreColumns);
        }
Exemple #26
0
        public static Lib.Data.Firma FirmaInText(string text)
        {
            if (string.IsNullOrEmpty(text))
            {
                return(null);
            }

            string value = Devmasters.TextUtil.RemoveDiacritics(TextUtil.NormalizeToBlockText(text).ToLower());

            foreach (var k in Firma.Koncovky.Select(m => m.ToLower()).OrderByDescending(m => m.Length))
            {
                if (value.Contains(k))
                {
                    value = value.Replace(k, k.Replace(' ', (char)160)); //nahrad mezery char(160) - non breaking space, aby to tvorilo 1 slovo
                }
                else if (k.EndsWith(".") && value.EndsWith(k.Substring(0, k.Length - 1)))
                {
                    value = value.Replace(k.Substring(0, k.Length - 1), k.Replace(' ', (char)160)); //nahrad mezery char(160) - non breaking space, aby to tvorilo 1 slovo
                }
            }
            //find company name
            string[] words = value.Split(new char[] { ' ', ',', ';' }, StringSplitOptions.RemoveEmptyEntries);

            //get back space instead of #160
            words = words.Select(m => m.Replace((char)160, ' ')).ToArray();

            for (int firstWord = 0; firstWord < words.Length; firstWord++)
            {
                for (int skipWord = 0; skipWord < words.Length - firstWord; skipWord++)
                {
                    string[] cutWords = words.Skip(firstWord)               //preskoc slovo na zacatku
                                        .Reverse().Skip(skipWord).Reverse() // a ubirej od konce
                                        .ToArray();
                    string wordCombination = cutWords.Aggregate((f, s) => f + " " + s);
                    string koncovka;
                    string firmaBezKoncovky = Lib.Data.Firma.JmenoBezKoncovkyFull(wordCombination, out koncovka);
                    string simpleName       = Devmasters.TextUtil.RemoveDiacritics(firmaBezKoncovky).ToLower().Trim();
                    //+ "|" + koncovka;


                    if (firmaBezKoncovky.Length > 3 &&
                        StaticData.FirmyNazvyOnlyAscii.Get().ContainsKey(simpleName)
                        )
                    {
                        //nasel jsem ico?
                        foreach (var ico in StaticData.FirmyNazvyOnlyAscii.Get()[simpleName])
                        {
                            Firma f = Firmy.Get(ico); //TODO StaticData.FirmyNazvyAscii.Get()[simpleName]);
                            if (f.Valid)
                            {
                                var firmaFromText = TextUtil.ReplaceDuplicates(System.Text.RegularExpressions.Regex.Replace(wordCombination, @"[,;_""']", " ", defaultRegexOptions), ' ');
                                var firmaFromDB   = TextUtil.ReplaceDuplicates(System.Text.RegularExpressions.Regex.Replace(f.Jmeno, @"[,;_""']", " ", defaultRegexOptions), ' ');
                                var rozdil        = LevenshteinDistanceCompute(
                                    TextUtil.RemoveDiacritics(firmaFromDB).ToLower(),
                                    firmaFromText.ToLower()
                                    );
                                var fKoncovka = f.KoncovkaFirmy();
                                var nextWord  = "";
                                if (firstWord + cutWords.Length < words.Length - 1)
                                {
                                    nextWord = words[firstWord + cutWords.Length];
                                }

                                if (string.IsNullOrEmpty(fKoncovka))
                                {
                                    return(f);
                                }
                                if (!string.IsNullOrEmpty(fKoncovka) && LevenshteinDistanceCompute(cutWords.Last(), fKoncovka) < 2)
                                {
                                    return(f);
                                }
                                if (!string.IsNullOrEmpty(fKoncovka) && LevenshteinDistanceCompute(nextWord, fKoncovka) < 2)
                                {
                                    return(f);
                                }
                            }
                        }
                        //looking for next
                        //return null;
                    }
                }
            }

            return(null);
        }
Exemple #27
0
        public InfoFact[] InfoFacts()
        {
            lock (lockInfoObj)
            {
                if (_infofacts == null)
                {
                    List <InfoFact> f = new List <InfoFact>();

                    string hlavni = $"Veřejná zakázka od <b>{Devmasters.TextUtil.ShortenText(this.Zadavatel?.Jmeno, 60)}</b>"
                                    + (this.DatumUverejneni.HasValue
                                ? " vyhlášena dne " + DatumUverejneni.Value.ToShortDateString()
                                : ". "
                                       );
                    if (this.Dodavatele.Count() == 0)
                    {
                        hlavni += $"";
                    }
                    else if (this.Dodavatele.Count() == 1)
                    {
                        hlavni += $"Zakázku vyhrál <b>{this.Dodavatele[0].Jmeno}</b>. ";
                    }
                    else if (this.Dodavatele.Count() > 1)
                    {
                        hlavni += $"Zakázku vyhrál <b>{this.Dodavatele[0].Jmeno}</b> a další. ";
                    }
                    if (this.KonecnaHodnotaBezDPH.HasValue && this.KonecnaHodnotaBezDPH != 0)
                    {
                        hlavni += $"Konečná hodnota zakázky je <b>{HlidacStatu.Util.RenderData.NicePrice(this.KonecnaHodnotaBezDPH.Value, mena: this.KonecnaHodnotaMena ?? "Kč")}</b>.";
                    }
                    else if (this.OdhadovanaHodnotaBezDPH.HasValue && this.OdhadovanaHodnotaBezDPH != 0)
                    {
                        hlavni += $"Odhadovaná hodnota zakázky je <b>{HlidacStatu.Util.RenderData.NicePrice(this.OdhadovanaHodnotaBezDPH.Value, mena: this.OdhadovanaHodnotaMena ?? "Kč")}</b>.";
                    }

                    f.Add(new InfoFact(hlavni, InfoFact.ImportanceLevel.Summary));

                    //sponzori
                    foreach (var subj in this.Dodavatele.Union(new HlidacStatu.Lib.Data.VZ.VerejnaZakazka.Subject[] { this.Zadavatel }))
                    {
                        if (subj != null)
                        {
                            var firma = HlidacStatu.Lib.Data.Firmy.Get(subj.ICO);
                            if (firma.Valid && firma.IsSponzor() && firma.JsemSoukromaFirma())
                            {
                                f.Add(new InfoFact(
                                          $"{firma.Jmeno}: " +
                                          string.Join("<br />",
                                                      firma.Sponzoring()
                                                      .OrderByDescending(s => s.DarovanoDne)
                                                      .Select(s => s.ToHtml())
                                                      .Take(2)),
                                          InfoFact.ImportanceLevel.Medium)
                                      );
                            }
                        }
                    }


                    //politici
                    foreach (var ss in this.Dodavatele)
                    {
                        if (!string.IsNullOrEmpty(ss.ICO) && HlidacStatu.Lib.StaticData.FirmySVazbamiNaPolitiky_nedavne_Cache.Get().SoukromeFirmy.ContainsKey(ss.ICO))
                        {
                            var politici = StaticData.FirmySVazbamiNaPolitiky_nedavne_Cache.Get().SoukromeFirmy[ss.ICO];
                            if (politici.Count > 0)
                            {
                                var sPolitici = Osoby.GetById.Get(politici[0]).FullNameWithYear();
                                if (politici.Count == 2)
                                {
                                    sPolitici = sPolitici + " a " + Osoby.GetById.Get(politici[1]).FullNameWithYear();
                                }
                                else if (politici.Count == 3)
                                {
                                    sPolitici = sPolitici
                                                + ", "
                                                + Osoby.GetById.Get(politici[1]).FullNameWithYear()
                                                + " a "
                                                + Osoby.GetById.Get(politici[2]).FullNameWithYear();
                                }
                                else if (politici.Count > 3)
                                {
                                    sPolitici = sPolitici
                                                + ", "
                                                + Osoby.GetById.Get(politici[1]).FullNameWithYear()
                                                + ", "
                                                + Osoby.GetById.Get(politici[2]).FullNameWithYear()
                                                + " a další";
                                }
                                f.Add(new InfoFact($"V dodavateli {Firmy.GetJmeno(ss.ICO)} se "
                                                   + Devmasters.Lang.Plural.Get(politici.Count()
                                                                                , " angažuje jedna politicky angažovaná osoba - "
                                                                                , " angažují {0} politicky angažované osoby - "
                                                                                , " angažuje {0} politicky angažovaných osob - ")
                                                   + sPolitici + "."
                                                   , InfoFact.ImportanceLevel.Medium)
                                      );
                            }
                        }
                    }

                    _infofacts = f.OrderByDescending(o => o.Level).ToArray();
                }
            }
            return(_infofacts);
        }
 private void editFirma(Firmy id)
 {
     this.CreateView(new FirmaEditViewModel(id.F_FirmaId));
 }