示例#1
0
        /// <inheritdoc />
        /// <summary>
        /// Reads the bank report.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>Response.</returns>
        public override ReadReportResponse ReadReport(ReadReportRequest request)
        {
            var response = new ReadReportResponse {
                FilePath = request.FilePath
            };
            var lines = ReportSource.GetLines(request.FilePath);

            foreach (var line in lines)
            {
                var row = line.ToString();
                if (!response.BalanceIsRead)
                {
                    decimal balance;
                    if (DetermineBalance(row, out balance))
                    {
                        response.Balance = balance;
                    }
                }
                if (string.IsNullOrEmpty(response.SourceId))
                {
                    response.SourceId = DetermineSourceId(row);
                }
                var columns = GetReportColumns(row);
                if (columns.Length >= MaxColumnCount)
                {
                    var transaction = DetermineTransaction(columns);
                    if (transaction != null)
                    {
                        response.Transactions.Add(transaction);
                    }
                }
            }
            return(response);
        }
示例#2
0
        public override ReadReportResponse ReadReport(ReadReportRequest request)
        {
            var response = new ReadReportResponse {
                FilePath     = request.FilePath,
                Transactions = new List <ReadTransaction>()
            };
            var source = ReportSource.GetLines(request.FilePath);
            var list   = ((string[])source).ToList();

            for (var row = 0; row < list.Count; row++)
            {
                var line = list[row];
                if (string.IsNullOrEmpty(response.SourceId))
                {
                    response.SourceId = DetermineSourceId(line);
                }
                if (line == TransactionBegin)
                {
                    var transaction = new ReadTransaction();
                    for (var i = 1; i < MaxRecipRowsCount && row + i < list.Count; i++)
                    {
                        line = list[row + i];
                        decimal amount;
                        if (ParseAmmount(line, TransactionAmountPosted, out amount) ||
                            ParseAmmount(line, TransactionAmount, out amount))
                        {
                            transaction.Amount        = amount;
                            transaction.DirectionType = amount < 0
                                                                ? DirectionType.Expense
                                                                : DirectionType.Incoming;
                        }
                        if (line.StartsWith(TransactionDate))
                        {
                            transaction.DateIn = DateTime.Parse(line.Replace(TransactionDate, ""));
                        }
                        if (line.StartsWith(TransactionNumber))
                        {
                            var number = line.Replace(TransactionNumber, "");
                            transaction.Comment += $"#{number}: ";
                        }
                        if (line.StartsWith(TransactionDescription))
                        {
                            transaction.Comment += line.Replace(TransactionDescription, "");
                        }
                        if (line.StartsWith(TransactionEnd))
                        {
                            response.Transactions.Add(transaction);
                            row += i;
                            break;
                        }
                    }
                }
            }
            return(response);
        }
示例#3
0
 /// <summary>
 /// Reads the bank report.
 /// </summary>
 /// <param name="request">The request.</param>
 /// <returns>Response.</returns>
 public abstract ReadReportResponse ReadReport(ReadReportRequest request);