private void AddEntryToDatabase() { using (var ts = new TransactionScope(TransactionScopeOption.Required)) { var context = new ERPContext(); var transaction = new LedgerTransaction(); if (!LedgerTransactionHelper.AddTransactionToDatabase(context, transaction, _newEntryDate, _newEntryDescription, _newEntryDescription)) { return; } context.SaveChanges(); LedgerTransactionHelper.AddTransactionLineToDatabase(context, transaction, _newEntryAccount.Name, _newEntrySequence, _newEntryAmount); LedgerTransactionHelper.AddTransactionLineToDatabase(context, transaction, _parentVM.SelectedBank.Name, _newEntrySequence == "Debit" ? "Credit" : "Debit", _newEntryAmount); context.SaveChanges(); ts.Complete(); } }
private static void CloseRevenueOrExpenseAccountToRetainedEarnings(LedgerAccount account, ERPContext context) { var retainedEarnings = context.Ledger_Accounts .Include("LedgerGeneral") .Include("LedgerAccountBalances") .Include("LedgerTransactionLines") .Single(e => e.Name.Equals("Retained Earnings")); if (account.Class.Equals("Expense")) { var amount = account.LedgerGeneral.Debit - account.LedgerGeneral.Credit; var transaction = new LedgerTransaction(); LedgerTransactionHelper.AddTransactionToDatabase(context, transaction, UtilityMethods.GetCurrentDate().Date, "Closing Entry", account.Name); context.SaveChanges(); LedgerTransactionHelper.AddTransactionLineToDatabase(context, transaction, account.Name, "Credit", amount); LedgerTransactionHelper.AddTransactionLineToDatabase(context, transaction, retainedEarnings.Name, "Debit", amount); account.LedgerGeneral.Credit -= amount; } else if (account.Class.Equals("Revenue")) { var amount = account.LedgerGeneral.Credit - account.LedgerGeneral.Debit; var transaction = new LedgerTransaction(); if (!LedgerTransactionHelper.AddTransactionToDatabase(context, transaction, UtilityMethods.GetCurrentDate().Date, "Closing Entry", account.Name)) { return; } context.SaveChanges(); LedgerTransactionHelper.AddTransactionLineToDatabase(context, transaction, account.Name, "Debit", amount); LedgerTransactionHelper.AddTransactionLineToDatabase(context, transaction, retainedEarnings.Name, "Credit", amount); account.LedgerGeneral.Debit -= amount; } }