Beispiel #1
0
        private static OcrTransaction CreateOcrTransaction(DateTime statementDate, GroupCollection groups)
        {
            string postedDateStr      = groups[1].Value.Trim() + " " + statementDate.Year;
            string transactionDateStr = groups[2].Value.Trim() + " " + statementDate.Year;

            DateTime?postedDate      = JLPParserV1.GetTransactionDate(postedDateStr);
            DateTime?transactionDate = JLPParserV1.GetTransactionDate(transactionDateStr);

            if (postedDate.HasValue && transactionDate.HasValue)
            {
                if (postedDate.Value > statementDate)
                {
                    postedDate = postedDate.Value.AddYears(-1);
                }
                if (transactionDate.Value > statementDate)
                {
                    transactionDate = transactionDate.Value.AddYears(-1);
                }
            }
            postedDateStr      = (postedDate.HasValue) ? postedDate.Value.ToShortDateString() : postedDateStr;
            transactionDateStr = (transactionDate.HasValue) ? transactionDate.Value.ToShortDateString() : transactionDateStr;

            var result = new OcrTransaction()
            {
                PostedDate      = postedDateStr,
                TransactionDate = transactionDateStr,
                Name            = groups[3].Value.Trim(),
                Amount          = groups[4].Value.Trim(),
                Credit          = groups[5].Value.Trim(),
                Note            = groups[6].Value.Trim()
            };

            return(result);
        }
Beispiel #2
0
        private static Transaction CreateTransaction(OcrTransaction ocrTransaction)
        {
            DateTime?       postedDate      = JLPParserV1.GetTransactionDate(ocrTransaction.PostedDate);
            DateTime?       transactionDate = JLPParserV1.GetTransactionDate(ocrTransaction.PostedDate);
            string          name            = ocrTransaction.Name;
            TransactionType txType          = JLPParserV1.GetTransactionType(ocrTransaction.Credit);
            decimal?        amount          = ocrTransaction.Amount.TryAsDecimal();

            if (txType == TransactionType.DEBIT)
            {
                amount = 0 - amount;
            }

            Transaction result = null;

            if (postedDate.HasValue && transactionDate.HasValue && String.IsNullOrWhiteSpace(name) == false && amount.HasValue)
            {
                result = new Transaction()
                {
                    TxType          = txType,
                    PostedDate      = postedDate.Value,
                    TransactionDate = transactionDate.Value,
                    Name            = name,
                    Note            = ocrTransaction.Note,
                    Amount          = amount.Value
                };
            }
            return(result);
        }
Beispiel #3
0
        private static void GetTransactions(Statement statement, string text)
        {
            var ocrTransactions = JLPParserV1.GetOcrTransactions(statement.StatementDate, text);

            foreach (var ocrTransaction in ocrTransactions)
            {
                var transaction = CreateTransaction(ocrTransaction);

                var ocrResult = new OcrResult()
                {
                    OcrTx = ocrTransaction,
                    Tx    = transaction
                };
                statement.OcrResults.Add(ocrResult);
            }
        }
Beispiel #4
0
        private static Statement ProcessFile(AppContext ctx, string path)
        {
            Statement result = null;

            try
            {
                string text = GetText(ctx, path);

                result = JLPParserV1.GetStatement(text, path);
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.ToString());
                Console.Error.WriteLine($"Failed to process \"{path}\": {ex.Message}");
                Console.WriteLine("Details: ");
                Console.WriteLine(ex.ToString());
            }
            return(result);
        }