Пример #1
0
        public void WhenIRecordATransactionOnLedger(string reference, string ledgerName, Table table)
        {
            var ledger             = this.cc.GetContext().Ledgers.FirstOrDefault(o => o.Name == ledgerName);
            var transactionService = new TransactionService(this.cc.GetContext());
            var accountService     = new TAccountService(cc.GetContext());
            var trans = transactionService.CreateTransaction(ledger);

            foreach (var r in table.Rows)
            {
                var     creditStr       = r["Credit"];
                var     debitStr        = r["Debit"];
                var     creditAmountStr = r["Amount Credit"];
                var     debitAmountStr  = r["Amount Debit"];
                decimal?creditAmount    = null;
                decimal?debitAmount     = null;
                if (!string.IsNullOrWhiteSpace(creditAmountStr))
                {
                    creditAmount = decimal.Parse(creditAmountStr);
                }
                if (!string.IsNullOrWhiteSpace(debitAmountStr))
                {
                    debitAmount = decimal.Parse(debitAmountStr);
                }

                var debitAccount  = accountService.GetAccountByNumber(ledger, debitStr);
                var creditAccount = accountService.GetAccountByNumber(ledger, creditStr);

                transactionService.AddEntryToTransaction(
                    trans,
                    debitAccount,
                    creditAccount,
                    debitAmount,
                    creditAmount
                    );
            }

            this.cc.GetContext().SaveChanges();

            this.cc.ObjectBag["transaction-" + reference] = trans;
        }