Esempio n. 1
0
        private void ProcessPositionTable(Table table, PublicServant currentDeclarant)
        {
            var rows  = table.Descendants <TableRow>().ToList();
            var cells = rows[0].Descendants <TableCell>().ToList();

            currentDeclarant.Occupation = cells[1].InnerText;
        }
Esempio n. 2
0
        private void ProcessIncomeTable(Table table, PublicServant person)
        {
            var rows = table.Descendants <TableRow>().ToList().Skip(1);

            foreach (var row in rows)
            {
                var cells      = row.Descendants <TableCell>().ToList();
                var incomeType = cells[1].InnerText.OnlyRussianLowercase();
                if (incomeType.StartsWith("декларированныйгодовойдоход"))
                {
                    var incomeRaw = cells[2].InnerText.Trim();
                    if (incomeRaw == "")
                    {
                        continue;
                    }
                    person.DeclaredYearlyIncomeRaw = incomeRaw;
                    person.DeclaredYearlyIncome    = DataHelper.ParseDeclaredIncome(incomeRaw, false);
                }
                else if (DataHelper.IsRelativeInfo(incomeType))
                {
                    var incomeRaw    = cells[2].InnerText.Trim();
                    var relationType = DataHelper.ParseRelationType(incomeType, false);
                    var relative     = new Relative();
                    relative.RelationType            = relationType;
                    relative.DeclaredYearlyIncomeRaw = incomeRaw;
                    relative.DeclaredYearlyIncome    = DataHelper.ParseDeclaredIncome(incomeRaw, false);
                    person.AddRelative(relative);
                }
            }
        }
Esempio n. 3
0
        public void ForgetThousandMultiplier(Declaration declaration)
        {
            // the incomes are so high, that we should not multiply incomes by 1000 although the
            // column title specify this multiplier
            List <Decimal> incomes = new List <Decimal>();

            foreach (PublicServant servant in declaration.PublicServants)
            {
                foreach (DataRow row in servant.DateRows)
                {
                    if (row.ColumnOrdering.ContainsField(DeclarationField.DeclaredYearlyIncomeThousands))
                    {
                        PublicServant dummy = new PublicServant();
                        if (ParseIncome(row, dummy, true))
                        {
                            if (dummy.DeclaredYearlyIncome != null)
                            {
                                incomes.Add(dummy.DeclaredYearlyIncome.Value);
                            }
                        }
                    }
                }
            }
            if (incomes.Count > 3)
            {
                incomes.Sort();
                Decimal medianIncome = incomes[incomes.Count / 2];
                if (medianIncome > 10000)
                {
                    declaration.Properties.IgnoreThousandMultipler = true;
                }
            }
        }
Esempio n. 4
0
        private PublicServant CreatePublicServant(TableHeader columnOrdering)
        {
            var currentDeclarant = new PublicServant();

            currentDeclarant.NameRaw  = GetPersonName();
            currentDeclarant.Ordering = columnOrdering;
            currentDeclarant.Index    = 1;
            return(currentDeclarant);
        }
Esempio n. 5
0
        private Relative GetPersonRelative(PublicServant person, RelationType relationType)
        {
            var foundRelatives = person.Relatives.Where(x => x.RelationType == relationType).ToList();

            if (foundRelatives.Count != 0)
            {
                return(foundRelatives[0]);
            }
            var relative = new Relative();

            relative.RelationType = relationType;
            person.AddRelative(relative);
            return(relative);
        }
Esempio n. 6
0
        public void CreateNewDeclarant(IAdapter adapter, DataRow row)
        {
            Logger.Debug("Declarant {0} at row {1}", row.PersonName, row.GetRowIndex());
            CurrentDeclarant = new PublicServant();
            InitDeclarantProperties(row);
            if (CurrentSection != null)
            {
                CurrentDeclarant.Department = CurrentSection.Name;
            }

            CurrentDeclarant.Index = row.GetPersonIndex();

            CurrentPerson = CurrentDeclarant;
            CurrentPerson.document_position = row.NameDocPosition;
            CurrentPerson.sheet_index       = _Declaration.Properties.SheetNumber;
            _Declaration.PublicServants.Add(CurrentDeclarant);
        }
Esempio n. 7
0
        private void ParseVehicleTable(Table table, PublicServant person)
        {
            var    rows = table.Descendants <TableRow>().ToList().Skip(1);
            string currentVehicleType = "";

            foreach (var row in rows)
            {
                var cells = row.Descendants <TableCell>().ToList();
                var text  = cells[0].InnerText;

                var gridSpan        = cells[0].TableCellProperties.GetFirstChild <GridSpan>();
                var mergedColsCount = (gridSpan == null) ? 1 : (int)gridSpan.Val;
                if (mergedColsCount > 1)
                {
                    currentVehicleType = text;
                    continue;
                }

                var textStr = cells[1].InnerText;
                if (textStr.OnlyRussianLowercase() == "неимеет")
                {
                    continue;
                }

                var ownerStr = cells[2].InnerText;
                var owners   = ownerStr.Split(",").ToList();

                foreach (var owner in owners)
                {
                    var vehicle = new Vehicle(textStr, currentVehicleType);

                    var relationType = DataHelper.ParseRelationType(owner, false);
                    if (DataHelper.IsRelativeInfo(owner))
                    {
                        var relative = GetPersonRelative(person, relationType);
                        relative.Vehicles.Add(vehicle);
                    }
                    else
                    {
                        person.Vehicles.Add(vehicle);
                    }
                }
            }
        }
Esempio n. 8
0
        private void ParseRealEstateTable(Table table, PublicServant person, string ownTypeByColumn)
        {
            var    rows = table.Descendants <TableRow>().ToList().Skip(1);
            string currentRealEstateType = "";

            foreach (var row in rows)
            {
                var cells           = row.Descendants <TableCell>().ToList();
                var gridSpan        = cells[0].TableCellProperties.GetFirstChild <GridSpan>();
                var mergedColsCount = (gridSpan == null) ? 1 : (int)gridSpan.Val;
                var text            = cells[0].InnerText;

                if (mergedColsCount > 1)
                {
                    currentRealEstateType = text;
                    continue;
                }

                var textStr = cells[1].InnerText;
                if (textStr.OnlyRussianLowercase() == "неимеет")
                {
                    continue;
                }
                var areaStr    = cells[2].InnerText;
                var countryStr = cells[3].InnerText;
                var ownerStr   = cells[4].InnerText;

                var owners = ownerStr.Split(",").ToList();
                var shares = owners.Where(x => x.Contains(" доля") || x.Contains(" доли")).ToList();
                owners = owners.Where(x => !(x.Contains(" доля") || x.Contains(" доли"))).ToList();

                if (shares.Count != owners.Count && shares.Count > 0)
                {
                    throw new SmartParserException("shares.Count != owners.Count in SovetFederaciiDocxScheme");
                }

                if (shares.Count < owners.Count)
                {
                    shares = Enumerable.Repeat <string>(null, owners.Count - shares.Count).ToList();
                }

                var zippedOwners = owners.Zip(shares);

                foreach (var pair in zippedOwners)
                {
                    var owner = pair.First;
                    var share = pair.Second;
                    var realEstateProperty = new RealEstateProperty
                    {
                        Text               = textStr,
                        square             = DataHelper.ParseSquare(areaStr),
                        type_raw           = currentRealEstateType,
                        square_raw         = ParserBase.NormalizeRawDecimalForTest(areaStr),
                        country_raw        = DataHelper.ParseCountry(countryStr),
                        own_type_by_column = ownTypeByColumn
                    };

                    if (share != default)
                    {
                        realEstateProperty.own_type_raw = share;
                    }

                    var relationType = DataHelper.ParseRelationType(owner, false);
                    if (DataHelper.IsRelativeInfo(owner))
                    {
                        var relative = GetPersonRelative(person, relationType);
                        relative.RealEstateProperties.Add(realEstateProperty);
                    }
                    else
                    {
                        person.RealEstateProperties.Add(realEstateProperty);
                    }
                }
            }
        }
Esempio n. 9
0
 public void FinishDeclarant()
 {
     CurrentDeclarant = null;
     CurrentPerson    = null;
 }
Esempio n. 10
0
        private void ParseOneDeclarantAndHisRelatives(bool ignoreThousandMultipler, PublicServant servant)
        {
            List <Person> declarantAndRelatives = new List <Person>()
            {
                servant
            };

            declarantAndRelatives.AddRange(servant.Relatives);

            foreach (Person person in declarantAndRelatives)
            {
                if (person is PublicServant)
                {
                    Logger.Debug("PublicServant: " + ((PublicServant)person).NameRaw.ReplaceEolnWithSpace());
                }
                bool foundIncomeInfo = false;

                List <DataRow> rows = new List <DataRow>();
                foreach (DataRow row in person.DateRows)
                {
                    if (row == null || row.Cells.Count == 0)
                    {
                        continue;
                    }

                    if (Adapter.IsExcel() &&
                        !row.IsEmpty(DeclarationField.StatePropertyType,
                                     DeclarationField.MixedRealEstateType,
                                     DeclarationField.OwnedRealEstateType) &&
                        row.IsEmpty(DeclarationField.MixedRealEstateSquare,
                                    DeclarationField.OwnedRealEstateSquare,
                                    DeclarationField.StatePropertySquare,
                                    DeclarationField.OwnedRealEstateCountry,
                                    DeclarationField.MixedRealEstateCountry,
                                    DeclarationField.StatePropertyCountry,
                                    DeclarationField.NameOrRelativeType) &&
                        rows.Count > 0)
                    {
                        Logger.Debug("Merge row to the last if state and square cell is empty");
                        rows.Last().Merge(row);
                    }
                    else
                    {
                        rows.Add(row);
                    }
                }


                foreach (var currRow in rows)
                {
                    if (!foundIncomeInfo)
                    {
                        if (ParseIncome(currRow, person, ignoreThousandMultipler))
                        {
                            TotalIncome    += person.DeclaredYearlyIncome == null ? 0 : person.DeclaredYearlyIncome.Value;
                            foundIncomeInfo = true;
                        }
                    }

                    ParseOwnedProperty(currRow, person);
                    ParseStateProperty(currRow, person);
                    ParseMixedProperty(currRow, person);

                    AddVehicle(currRow, person);
                }
            }
        }