Esempio n. 1
0
        public static List <Graph.Edge> Holding(string ico, Relation.AktualnostType aktualnost)
        {
            DateTime?from = null;
            DateTime to   = DateTime.Now.Date.AddDays(1);

            switch (aktualnost)
            {
            case Relation.AktualnostType.Aktualni:
                from = to.AddDays(-1);
                break;

            case Relation.AktualnostType.Nedavny:
                from = to - Relation.NedavnyVztahDelka;
                break;

            case Relation.AktualnostType.Neaktualni:
            case Relation.AktualnostType.Libovolny:
                from = new DateTime(1950, 1, 1);
                break;

            default:
                break;
            }

            return(Holding(ico, from.Value, to, aktualnost));
        }
Esempio n. 2
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;
            }

            if (this.platnyZaznam)
            {
                if (!string.IsNullOrEmpty(this.Platce.ico) && icos.Contains(this.Platce.ico))
                {
                    return(true);
                }
                else
                {
                    foreach (var ss in this.Prijemce)
                    {
                        if (!string.IsNullOrEmpty(ss.ico) && icos.Contains(ss.ico))
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
Esempio n. 3
0
        public Analysis.OsobaStatistic Statistic(Relation.AktualnostType minAktualnost)
        {
            if (_vazbyStatisticsPerIco == null)
            {
                _vazbyStatisticsPerIco = new Analysis.OsobaStatistic(this, minAktualnost);
            }

            return(_vazbyStatisticsPerIco);
        }
Esempio n. 4
0
        public static List <Edge> vsechnyDcerineVazbyInternal(Lib.Data.Osoba person, int level, bool goDeep, Edge parent,
                                                              ExcludeDataCol excludeICO          = null, IEnumerable <int> excludeOsobaId = null, DateTime?datumOd = null, DateTime?datumDo = null,
                                                              Relation.AktualnostType aktualnost = Relation.AktualnostType.Libovolny)
        {
            if (excludeOsobaId == null)
            {
                excludeOsobaId = new int[] { }
            }
            ;

            string sql = @"select vazbakIco, vazbakOsobaId, datumOd, datumDo, typVazby, pojmenovaniVazby, podil from OsobaVazby 
                            where osobaId = @osobaId and
	(
		(datumOd <= @datumOd or @datumOd is null)
		OR (datumOd >= @datumOd and datumDo is null) 
	)
	and (datumDo >= @datumDo or datumDo is null or @datumDo is null)
";
            var    p   = new IDataParameter[] {
                new SqlParameter("osobaId", person.InternalId),
                new SqlParameter("datumOd", datumOd),
                new SqlParameter("datumDo", datumDo),
            };

            var relForPerson = GetChildrenRelations(sql, Node.NodeType.Person, person.InternalId.ToString(),
                                                    datumOd, datumDo,
                                                    p, level, goDeep, parent, excludeICO, aktualnost);

            var relForConnectedPersons = new List <Edge>();

            using (DbEntities db = new DbEntities())
            {
                var navazaneOsoby = db.OsobaVazby.Where(m => m.OsobaID == person.InternalId && m.VazbakOsobaId != null).ToList();
                if (navazaneOsoby.Count > 0)
                {
                    foreach (var ov in navazaneOsoby)
                    {
                        Edge parentRelFound = relForPerson
                                              .Where(r => r.To.Type == Node.NodeType.Person &&
                                                     r.To.Id == ov.VazbakOsobaId.Value.ToString())
                                              .FirstOrDefault();

                        if (!excludeOsobaId.Contains(ov.VazbakOsobaId.Value))
                        {
                            Osoba o = Osoby.GetById.Get(ov.VazbakOsobaId.Value);
                            excludeOsobaId = excludeOsobaId.Union(new int[] { ov.VazbakOsobaId.Value });
                            var rel = vsechnyDcerineVazbyInternal(o, level + 1, true, parentRelFound, excludeOsobaId: excludeOsobaId, aktualnost: aktualnost);
                            relForConnectedPersons = Edge.Merge(relForConnectedPersons, rel);
                        }
                    }
                }
            }

            var finalRel = Edge.Merge(relForConnectedPersons, relForPerson);

            return(finalRel);
        }
Esempio n. 5
0
        public static List <Edge> vsechnyDcerineVazbyInternal(string ico, int level, bool goDeep, Edge parent,
                                                              ExcludeDataCol excludeICO          = null, DateTime?datumOd = null, DateTime?datumDo = null,
                                                              Relation.AktualnostType aktualnost = Relation.AktualnostType.Libovolny)
        {
            string sql = @"select vazbakIco, datumOd, datumDo, typVazby, pojmenovaniVazby, podil from Firmavazby 
    where ico=@ico 
	and dbo.IsSomehowInInterval(@datumOd, @datumDo, datumOd, datumDo) = 1
";
            var    p   = new IDataParameter[] {
                new SqlParameter("ico", ico),
                new SqlParameter("datumOd", datumOd),
                new SqlParameter("datumDo", datumDo),
            };

            var rel = GetChildrenRelations(sql, Node.NodeType.Company, ico, datumOd, datumDo,
                                           p, level, goDeep, parent, excludeICO, aktualnost);

            return(rel);
        }
Esempio n. 6
0
 public void UpdateAktualnost()
 {
     if (this.RelTo.HasValue)
     {
         if ((DateTime.Now.Date - this.RelTo.Value).TotalDays < 0)
         {
             this.Aktualnost = Relation.AktualnostType.Aktualni;
         }
         else if ((DateTime.Now.Date - this.RelTo.Value).TotalDays < Relation.NedavnyVztahDelka.TotalDays)
         {
             this.Aktualnost = Relation.AktualnostType.Nedavny;
         }
         else
         {
             this.Aktualnost = Relation.AktualnostType.Neaktualni;
         }
     }
     else
     {
         Aktualnost = Relation.AktualnostType.Aktualni;
     }
 }
Esempio n. 7
0
 public Graph.Edge[] AktualniVazby(Relation.AktualnostType minAktualnost)
 {
     return(Relation.AktualniVazby(this.Vazby(), minAktualnost));
 }
        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
            });
        }
        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);
        }
Esempio n. 10
0
 public Relation[] AktualniVazby(Relation.AktualnostType minAktualnost)
 {
     return(Relation.AktualniVazby(this.Vazby, minAktualnost));
 }
Esempio n. 11
0
        public static Graph.Edge[] AktualniVazby(IEnumerable <Graph.Edge> allRelations, Relation.AktualnostType minAktualnost)
        {
            if (allRelations == null)
            {
                return new Graph.Edge[] { }
            }
            ;

            return(allRelations
                   .Where(m => m.Aktualnost >= minAktualnost)
                   .ToArray());
        }
Esempio n. 12
0
 public static RegistrSmluv CachedStatistics(Osoba os, Relation.AktualnostType aktualnost, int?obor)
 {
     return(_cache.Get((os, (int)aktualnost, obor)));
 }
Esempio n. 13
0
        public static List <Edge> GetChildrenRelations(string sql,
                                                       Node.NodeType nodeType, string nodeId, DateTime?datumOd, DateTime?datumDo,
                                                       IDataParameter[] parameters, int level, bool goDeep,
                                                       Edge parent, ExcludeDataCol excludeICO, decimal minPodil, Relation.AktualnostType aktualnost)
        {
            if (excludeICO == null)
            {
                excludeICO = new ExcludeDataCol();
            }

            string cnnStr = Devmasters.Config.GetWebConfigValue("CnnString");

            List <Edge> relations = new List <Edge>();

            if (level == 0 && parent == null)
            {
                //add root node / edge
                relations.Add(
                    new Edge()
                {
                    From = null,
                    Root = true,
                    To   = new Node()
                    {
                        Id = nodeId, Type = nodeType
                    },
                    RelFrom  = datumOd,
                    RelTo    = datumDo,
                    Distance = 0
                }
                    );
            }
            //get zakladni informace o subj.

            //find politician in the DB
            var db      = new Devmasters.PersistLib();
            var sqlCall = HlidacStatu.Lib.DirectDB.GetRawSql(System.Data.CommandType.Text, sql, parameters);
            //string sqlFirma = "select top 1 stav_subjektu from firma where ico = @ico";

            var ds = db.ExecuteDataset(cnnStr, System.Data.CommandType.Text, sqlCall, null);

            if (ds.Tables[0].Rows.Count > 0)
            {
                List <AngazovanostData> rows = new List <AngazovanostData>();
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    AngazovanostData angaz = null;
                    var ico = (string)dr["VazbakIco"];
                    if (string.IsNullOrEmpty(ico))
                    {
                        if (dr.Table.Columns.Contains("vazbakOsobaId"))
                        {
                            var vazbakOsobaId = (int?)PersistLib.IsNull(dr["vazbakOsobaId"], null);
                            if (vazbakOsobaId != null)
                            {
                                Osoba o = Osoby.GetById.Get(vazbakOsobaId.Value);
                                angaz = new AngazovanostData()
                                {
                                    subjId   = vazbakOsobaId.Value.ToString(),
                                    NodeType = Node.NodeType.Person,
                                    fromDate = (DateTime?)PersistLib.IsNull(dr["datumOd"], null),
                                    toDate   = (DateTime?)PersistLib.IsNull(dr["datumDo"], null),
                                    kod_ang  = Convert.ToInt32(dr["typVazby"]),
                                    descr    = (string)PersistLib.IsNull(dr["PojmenovaniVazby"], ""),
                                    podil    = (decimal?)PersistLib.IsNull(dr["podil"], null)
                                };
                            }
                        }
                    }
                    else
                    {
                        angaz = new AngazovanostData()
                        {
                            subjId   = ico,
                            subjname = "",
                            NodeType = Node.NodeType.Company,
                            fromDate = (DateTime?)PersistLib.IsNull(dr["datumOd"], null),
                            toDate   = (DateTime?)PersistLib.IsNull(dr["datumDo"], null),
                            kod_ang  = Convert.ToInt32(dr["typVazby"]),
                            descr    = (string)PersistLib.IsNull(dr["PojmenovaniVazby"], ""),
                            podil    = (decimal?)PersistLib.IsNull(dr["podil"], null)
                        };
                    }
                    rows.Add(angaz);
                }

                List <AngazovanostData> filteredRels = new List <AngazovanostData>();
                //delete vazby ve stejnem obdobi
                if (rows.Count > 0)
                {
                    //per ico
                    foreach (var gIco in rows.Select(m => m.subjId).Distinct())
                    {
                        var relsForIco = rows.Where(m => m.subjId == gIco);
                        //find longest, or separate relation
                        foreach (var r in relsForIco)
                        {
                            if (relsForIco
                                .Any(rr =>
                                     rr != r &&
                                     rr.fromDate < r.fromDate &&
                                     (rr.toDate > r.toDate || rr.toDate.HasValue == false)
                                     )
                                )
                            {
                                //skip
                            }
                            else
                            {
                                filteredRels.Add(r);
                            }
                        }
                    }
                }

                foreach (AngazovanostData ang in filteredRels.OrderBy(m => m.kod_ang))
                {
                    if (ang.kod_ang == 100) //souhrny (casove) vztah, zkontroluj, zda uz tam neni jiny vztah se stejnym rozsahem doby
                    {
                        if (
                            relations.Any(
                                r => r.To.Id == ang.subjId &&
                                r.To.Type == ang.NodeType &&
                                r.RelFrom == ang.fromDate &&
                                r.RelTo == ang.toDate
                                )
                            )
                        {
                            continue;
                        }
                    }
                    var rel = AngazovanostDataToEdge(ang,
                                                     new Node()
                    {
                        Type = nodeType, Id = nodeId
                    },
                                                     new Node()
                    {
                        Type = ang.NodeType, Id = ang.subjId
                    },
                                                     level + 1
                                                     );


                    if (excludeICO.Contains(rel))
                    {
                        continue;//skip to the next
                    }
                    if (rel.Aktualnost >= aktualnost)
                    {
                        relations.Add(rel);
                    }
                }
            }

            if (goDeep && relations.Count > 0)
            {
                level++;
                List <Edge> deeperRels  = new List <Edge>();
                List <Edge> excludeMore = new List <Edge>();
                if (parent != null)
                {
                    excludeMore = relations.ToList();
                }

                ////navazej na ten, ktery je nejdelsi
                //var parentRels = relations.GroupBy(x => new { x.To.Id }, (key, rels) =>
                //{
                //    DateTime? fromDate = rels.Any(m => m.FromDate == null) ? (DateTime?)null : rels.Min(m => m.FromDate);
                //    DateTime? toDate = rels.Any(m => m.ToDate == null) ? (DateTime?)null : rels.Max(m => m.ToDate);
                //    Relation bestRelation = Relation.GetLongestRelation(rels);

                //    return new
                //    {
                //        SubjIco = key.To.Id,
                //        FromDate = fromDate,
                //        ToDate = toDate,
                //        BestRelation = bestRelation,
                //    };

                //});



                foreach (var rel in relations.Where(m => m.Root == false))
                {
                    //old
                    deeperRels.AddRange(

                        vsechnyDcerineVazbyInternal(rel.To.Id, level, goDeep, rel,
                                                    excludeICO.AddItem(new ExcludeData(rel)),
                                                    rel.RelFrom, rel.RelTo, minPodil, aktualnost)
                        );
                }
                relations.AddRange(deeperRels);
            }

            if (level == 0)
            {
                //remove inactive companies from last branches
                //TODO
            }
            return(relations);
        }
Esempio n. 14
0
        public static List <Graph.Edge> Holding(string ico, DateTime datumOd, DateTime datumDo, Relation.AktualnostType aktualnost)
        {
            var vazby    = vsechnyDcerineVazbyInternal(ico, 9, true, null, datumOd: datumOd, datumDo: datumDo);
            var parents  = GetParentRelations(ico, vazby, 0, datumOd, datumDo);
            var rootNode = new Node()
            {
                Id = ico, Type = Node.NodeType.Company
            };

            if (parents?.Count() > 0)
            {
                if (vazby.Any(m => m.Root))
                {
                    if (vazby.Any(m => m.From == null && m.To.UniqId == rootNode.UniqId))
                    {
                        vazby = vazby
                                .Where(m => !(m.From == null && m.To.UniqId != rootNode.UniqId))
                                .ToList();
                    }
                }
            }
            var finalRel = Edge.Merge(parents.ToList(), vazby);

            return(finalRel);
        }
Esempio n. 15
0
        public static List <Edge> GetChildrenRelations(string sql,
                                                       Node.NodeType nodeType, string nodeId, DateTime?datumOd, DateTime?datumDo,
                                                       IDataParameter[] parameters, int level, bool goDeep,
                                                       Edge parent, ExcludeDataCol excludeICO, Relation.AktualnostType aktualnost)
        {
            if (excludeICO == null)
            {
                excludeICO = new ExcludeDataCol();
            }

            string cnnStr = Devmasters.Core.Util.Config.GetConfigValue("CnnString");

            List <Edge> relations = new List <Edge>();

            if (level == 0 && parent == null)
            {
                //add root node / edge
                relations.Add(
                    new Edge()
                {
                    From = null,
                    Root = true,
                    To   = new Node()
                    {
                        Id = nodeId, Type = nodeType
                    },
                    RelFrom  = datumOd,
                    RelTo    = datumDo,
                    Distance = 0
                }
                    );
            }
            //get zakladni informace o subj.

            //find politician in the DB
            var db      = new Devmasters.Core.PersistLib();
            var sqlCall = HlidacStatu.Lib.DirectDB.GetRawSql(System.Data.CommandType.Text, sql, parameters);
            //string sqlFirma = "select top 1 stav_subjektu from firma where ico = @ico";

            var ds = db.ExecuteDataset(cnnStr, System.Data.CommandType.Text, sqlCall, null);

            if (ds.Tables[0].Rows.Count > 0)
            {
                List <AngazovanostData> rows = new List <AngazovanostData>();
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    AngazovanostData angaz = null;
                    var ico = (string)dr["VazbakIco"];
                    if (string.IsNullOrEmpty(ico))
                    {
                        if (dr.Table.Columns.Contains("vazbakOsobaId"))
                        {
                            var vazbakOsobaId = (int?)PersistLib.IsNull(dr["vazbakOsobaId"], null);
                            if (vazbakOsobaId != null)
                            {
                                Osoba o = Osoby.GetById.Get(vazbakOsobaId.Value);
                                angaz = new AngazovanostData()
                                {
                                    subjId   = vazbakOsobaId.Value.ToString(),
                                    NodeType = Node.NodeType.Person,
                                    fromDate = (DateTime?)PersistLib.IsNull(dr["datumOd"], null),
                                    toDate   = (DateTime?)PersistLib.IsNull(dr["datumDo"], null),
                                    kod_ang  = Convert.ToInt32(dr["typVazby"]),
                                    descr    = (string)PersistLib.IsNull(dr["PojmenovaniVazby"], ""),
                                    podil    = (decimal?)PersistLib.IsNull(dr["podil"], null)
                                };
                            }
                        }
                    }
                    else
                    {
                        angaz = new AngazovanostData()
                        {
                            subjId   = ico,
                            subjname = "",
                            NodeType = Node.NodeType.Company,
                            fromDate = (DateTime?)PersistLib.IsNull(dr["datumOd"], null),
                            toDate   = (DateTime?)PersistLib.IsNull(dr["datumDo"], null),
                            kod_ang  = Convert.ToInt32(dr["typVazby"]),
                            descr    = (string)PersistLib.IsNull(dr["PojmenovaniVazby"], ""),
                            podil    = (decimal?)PersistLib.IsNull(dr["podil"], null)
                        };
                    }
                    rows.Add(angaz);
                }

                List <AngazovanostData> filteredRels = new List <AngazovanostData>();
                //delete vazby ve stejnem obdobi
                if (rows.Count > 0)
                {
                    //per ico
                    foreach (var gIco in rows.Select(m => m.subjId).Distinct())
                    {
                        var relsForIco = rows.Where(m => m.subjId == gIco);
                        //find longest, or separate relation
                        foreach (var r in relsForIco)
                        {
                            if (relsForIco
                                .Any(rr =>
                                     rr != r &&
                                     rr.fromDate < r.fromDate &&
                                     (rr.toDate > r.toDate || rr.toDate.HasValue == false)
                                     )
                                )
                            {
                                //skip
                            }
                            else
                            {
                                filteredRels.Add(r);
                            }
                        }
                    }
                }

                foreach (AngazovanostData ang in filteredRels.OrderBy(m => m.kod_ang))
                {
                    if (ang.kod_ang == 100) //souhrny (casove) vztah, zkontroluj, zda uz tam neni jiny vztah se stejnym rozsahem doby
                    {
                        if (
                            relations.Any(
                                r => r.To.Id == ang.subjId &&
                                r.To.Type == ang.NodeType &&
                                r.RelFrom == ang.fromDate &&
                                r.RelTo == ang.toDate
                                )
                            )
                        {
                            continue;
                        }
                    }
                    var rel = new Edge();

                    rel.From = new Node()
                    {
                        Type = nodeType, Id = nodeId
                    };
                    rel.To = new Node()
                    {
                        Type = ang.NodeType, Id = ang.subjId
                    };
                    rel.Distance = level + 1;

                    rel.RelFrom = (DateTime?)PersistLib.IsNull(ang.fromDate, null);
                    if (rel.RelFrom < minDate)
                    {
                        rel.RelFrom = null;
                    }

                    rel.RelTo = (DateTime?)PersistLib.IsNull(ang.toDate, null);
                    if (rel.RelTo < minDate)
                    {
                        rel.RelTo = null;
                    }
                    int kod_ang = ang.kod_ang;

                    /*
                     *     3  - prokura
                     *     4  - člen dozorčí rady
                     *     24 - spolecnik
                     *     5  - Jediný akcionář
                     *     1 - jednatel
                     *
                     */
                    rel.Descr = ang.descr;
                    Firma.RelationSimpleEnum relRelationship = Firma.RelationSimpleEnum.Jiny;
                    switch (kod_ang)
                    {
                    case 1:
                        relRelationship = Firma.RelationSimpleEnum.Statutarni_organ;
                        if (string.IsNullOrEmpty(rel.Descr))
                        {
                            rel.Descr = Firma.RelationSimpleEnum.Jednatel.ToNiceDisplayName();
                        }
                        break;

                    case 3:
                        relRelationship = Firma.RelationSimpleEnum.Statutarni_organ;
                        if (string.IsNullOrEmpty(rel.Descr))
                        {
                            rel.Descr = Firma.RelationSimpleEnum.Prokura.ToNiceDisplayName();
                        }
                        break;

                    case 4:
                    case 7:
                    case 2:
                    case 18:
                    case 25:
                    case 26:
                    case 28:
                    case 31:
                        relRelationship = Firma.RelationSimpleEnum.Statutarni_organ;
                        if (string.IsNullOrEmpty(rel.Descr))
                        {
                            rel.Descr = Firma.RelationSimpleEnum.Dozorci_rada.ToNiceDisplayName();
                        }
                        break;

                    case 33:
                    case 34:
                    case 35:
                        relRelationship = Firma.RelationSimpleEnum.Zakladatel;
                        if (string.IsNullOrEmpty(rel.Descr))
                        {
                            rel.Descr = Firma.RelationSimpleEnum.Dozorci_rada.ToNiceDisplayName();
                        }
                        break;

                    case 5:
                    case 9:
                    case 10:
                    case 15:
                    case 19:
                    case 24:
                        relRelationship = Firma.RelationSimpleEnum.Spolecnik;
                        if (string.IsNullOrEmpty(rel.Descr))
                        {
                            rel.Descr = Firma.RelationSimpleEnum.Spolecnik.ToNiceDisplayName();
                        }
                        break;

                    case 100:
                        relRelationship = Firma.RelationSimpleEnum.Souhrnny;
                        if (string.IsNullOrEmpty(rel.Descr))
                        {
                            rel.Descr = Firma.RelationSimpleEnum.Jednatel.ToNiceDisplayName();
                        }
                        break;

                    case 23:    //
                    case 29:    //
                    case 11:    //
                    case 12:    //
                    case 13:    //
                    case 16:    //
                    case 17:    //
                    case 37:    //
                    case 40:    //
                    case 41:    //
                    case 42:    //
                    case 99:
                        relRelationship = Firma.RelationSimpleEnum.Jiny;
                        break;

                    default:

                        if (kod_ang < 0)
                        {
                            relRelationship = (Firma.RelationSimpleEnum)kod_ang;
                        }
                        else
                        {
                            //rel.Relationship = Relation.RelationDescriptionEnum.Jednatel;
                            relRelationship = Firma.RelationSimpleEnum.Jiny;
                            if (string.IsNullOrEmpty(rel.Descr))
                            {
                                rel.Descr = Firma.RelationSimpleEnum.Jednatel.ToNiceDisplayName();
                            }
                        }
                        break;
                    }

                    if (excludeICO.Contains(rel))
                    {
                        continue;//skip to the next
                    }
                    if (string.IsNullOrEmpty(rel.Descr))
                    {
                        rel.Descr = relRelationship.ToNiceDisplayName();
                    }

                    rel.UpdateAktualnost();

                    if (rel.Aktualnost >= aktualnost)
                    {
                        relations.Add(rel);
                    }
                }
            }

            if (goDeep && relations.Count > 0)
            {
                level++;
                List <Edge> deeperRels  = new List <Edge>();
                List <Edge> excludeMore = new List <Edge>();
                if (parent != null)
                {
                    excludeMore = relations.ToList();
                }

                ////navazej na ten, ktery je nejdelsi
                //var parentRels = relations.GroupBy(x => new { x.To.Id }, (key, rels) =>
                //{
                //    DateTime? fromDate = rels.Any(m => m.FromDate == null) ? (DateTime?)null : rels.Min(m => m.FromDate);
                //    DateTime? toDate = rels.Any(m => m.ToDate == null) ? (DateTime?)null : rels.Max(m => m.ToDate);
                //    Relation bestRelation = Relation.GetLongestRelation(rels);

                //    return new
                //    {
                //        SubjIco = key.To.Id,
                //        FromDate = fromDate,
                //        ToDate = toDate,
                //        BestRelation = bestRelation,
                //    };

                //});



                foreach (var rel in relations.Where(m => m.Root == false))
                {
                    //old
                    deeperRels.AddRange(

                        vsechnyDcerineVazbyInternal(rel.To.Id, level, goDeep, rel,
                                                    excludeICO.AddItem(new ExcludeData(rel)),
                                                    rel.RelFrom, rel.RelTo, aktualnost)
                        );
                }
                relations.AddRange(deeperRels);
            }

            if (level == 0)
            {
                //remove inactive companies from last branches
                //TODO
            }
            return(relations);
        }