예제 #1
0
        private decimal ParseAmount(string line, StatementItemsPositions positions)
        {
            var amount = GetValue(line, positions.Castka).Trim();

            return(ParseTools.FromTextToDecimal(amount.Trim())
                   ?? throw new ApplicationException(
                       $"Amount on line '{line}' on position {positions.Castka} could not be read ({amount})"));
        }
예제 #2
0
        private List <IBankovniPolozka> ParseStatement(string textFile, DateTime date, string sourceUrl)
        {
            var statementItems = new List <IBankovniPolozka>();
            var data           = File.ReadAllLines(textFile);
            var item           = (StatementItemRecord)null;
            var overview       = new StatementOverview();
            var positions      = new StatementItemsPositions();

            foreach (var line in data)
            {
                if (string.IsNullOrEmpty(line))
                {
                    continue;
                }
                if (line.Contains("Změna úrokové sazby"))
                {
                    continue;
                }

                if (line.StartsWith("Počet kreditních položek"))
                {
                    overview.CreditItems = int.Parse(ItemsPattern.Match(GetValue(line, CreditItemsPosition)).Groups[1].Value);
                    if (!line.Contains(OpeningBalanceText))
                    {
                        continue;
                    }
                }
                if (line.StartsWith("Počet debetních položek"))
                {
                    overview.DebitItems = int.Parse(ItemsPattern.Match(GetValue(line, DebitItemsPosition)).Groups[1].Value);
                    continue;
                }
                if (line.Contains(OpeningBalanceText))
                {
                    overview.OpeningBalance = ParseTools.FromTextToDecimal(GetValue(line, new PositionIndex(line.IndexOf(OpeningBalanceText, SC) + OpeningBalanceText.Length + 1, default(int?)))) ?? 0;
                    continue;
                }
                if (line.Trim().StartsWith(FinalBalanceText))
                {
                    overview.FinalBalance = ParseTools.FromTextToDecimal(GetValue(line, new PositionIndex(line.IndexOf(FinalBalanceText, SC) + FinalBalanceText.Length + 1, default(int?)))) ?? 0;
                    continue;
                }

                if (line.StartsWith("Datum"))
                {
                    DefineItemsPositionsForFirstLine(positions, line);
                    continue;
                }
                if (line.StartsWith("Valuta"))
                {
                    DefineItemsPositionsForSecondLine(positions, line);
                    continue;
                }

                if (item != null && (line[0] != ' ' || line.Trim().StartsWith("Převádí se") || line.Trim().StartsWith("Konec výpisu")))
                {
                    statementItems.Add(item.ToBankPolozka(date, Ucet, sourceUrl));
                    item = null;
                }

                if (StatementItemPattern.IsMatch(line))
                {
                    item = CreateStatementItem(line, positions);
                }
                else if (item != null && string.IsNullOrEmpty(item.ZpravaProPrijemce) && AccountNumberPattern.IsMatch(line))
                {
                    UpdateStatementItem(item, line, positions);
                }
                else if (item != null)
                {
                    item.ZpravaProPrijemce += (string.IsNullOrEmpty(item.ZpravaProPrijemce)
                                                                                                  ? string.Empty
                                                                                                  : Environment.NewLine) + line.Trim();
                }
            }

            ValidateParsedItems(sourceUrl, overview, statementItems);

            return(statementItems);
        }