public ActionResult Create(LedgerAccount ObjLedgerAccount) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); try { if (ModelState.IsValid) { db.LedgerAccounts.Add(ObjLedgerAccount); db.SaveChanges(); sb.Append("Sumitted"); return(Content(sb.ToString())); } else { foreach (var key in this.ViewData.ModelState.Keys) { foreach (var err in this.ViewData.ModelState[key].Errors) { sb.Append(err.ErrorMessage + "<br/>"); } } } } catch (Exception ex) { sb.Append("Error :" + ex.Message); } return(Content(sb.ToString())); }
public int SaveSaleOrder(SaleOrder SaleOrder, string Mode, LedgerAccount SelectedCustomer, LedgerAccount SelectedBankAccount, string ChequeNumber) { using (var transaction = Context.Database.BeginTransaction()) { try { if (SaleOrder.SaleOrderId < 1) { Context.SaleOrders.Add(SaleOrder); } else { Context.Entry(SaleOrder).State = EntityState.Modified; } var count = Context.SaveChanges(); SaveInLedger(SaleOrder, Mode, SelectedCustomer, SelectedBankAccount, ChequeNumber); transaction.Commit(); return(count); } catch (Exception ex) { transaction.Rollback(); throw ex; } } }
public override void Run(AccountingEntity entity, IDbContext dataContext) { var debtorAcct = new LedgerAccount() { AppTenantID = entity.AppTenantID, Ledger = dataContext.Set <Ledger>().Single(x => x.Code == "FIN"), LedgerAccountType = dataContext.Set <LedgerAccountType>().Single(x => x.Code == "D"), Name = "Contributions Due" }; var creditorAcct = new LedgerAccount() { AppTenantID = entity.AppTenantID, Ledger = dataContext.Set <Ledger>().Single(x => x.Code == "FIN"), LedgerAccountType = dataContext.Set <LedgerAccountType>().Single(x => x.Code == "C"), Name = "Services Payable" }; var expenseAcct = new LedgerAccount() { AppTenantID = entity.AppTenantID, Ledger = dataContext.Set <Ledger>().Single(x => x.Code == "FIN"), LedgerAccountType = dataContext.Set <LedgerAccountType>().Single(x => x.Code == "E"), Name = "General Expense" }; //entity.LedgerAccounts.Add(); var expenseTemplate = CreateExpenseTemplate(entity, dataContext, creditorAcct, expenseAcct); entity.JournalTemplates.Add(expenseTemplate); }
/// <summary> /// Adiciona Linhas de Debito e Credito ao Lancamento Manual informado /// </summary> /// <param name="journalEntries"></param> /// <param name="ledgerAccount"></param> /// <param name="value"></param> /// <param name="date"></param> /// <param name="obsLine"></param> /// <param name="profitCodeCdt"></param> /// <param name="profitCodeDbt"></param> /// <returns></returns> public int addJournalEntryLines(JournalEntries journalEntries, LedgerAccount ledgerAccount, double value, DateTime date, string obsLine, string profitCodeCdt = "", string profitCodeDbt = "") { int ret = 0; try { if (ledgerAccount.creditAccount.Equals("") || ledgerAccount.debitAccount.Equals("") || value == 0) { ret = -2; logger.log("Contas para Lancamento nao configuradas corretamente ou valor esta zerado: " + "\nConta Credito: " + ledgerAccount.creditAccount + "\nConta Debito: " + ledgerAccount.creditAccount + " Valor: " + value, Logger.LogType.WARNING, null, false); return(ret); } ret = addCreditJEL( journalEntries, ledgerAccount.creditAccount, ledgerAccount.debitAccount, ledgerAccount.creditAccount, value, obsLine, date, profitCodeCdt ); ret = addDebitJEL( journalEntries, ledgerAccount.debitAccount, ledgerAccount.creditAccount, ledgerAccount.debitAccount, value, obsLine, date, profitCodeDbt ); } catch (Exception e) { ret = -1; logger.log("Erro ao adicionar linhas no Lançamento Contábil Manual: " + journalEntries.JdtNum, Logger.LogType.ERROR, e); } return(ret); }
private void UpdateDisplayedLines() { DisplayedLines.Clear(); SetBeginningBalance(); _endingBalance = _beginningBalance; using (var context = new ERPContext()) { var lines = context.Ledger_Transaction_Lines .Include("LedgerAccount") .Include("LedgerTransaction") .Where(line => line.LedgerAccount.Name.Equals("Cash") && line.LedgerTransaction.Date.Equals(_date)) .ToList(); var account = new LedgerAccount { ID = -1, Name = "Sales Receipt", Class = "Asset" }; var transaction = new LedgerTransaction { ID = -1, Date = _date, Description = "Sales Receipt", Documentation = "Sales Receipt" }; var salesreceiptLine = new LedgerTransactionLine { LedgerTransaction = transaction, LedgerAccount = account, Seq = "Debit" }; foreach (var line in lines) { var lineVM = new LedgerTransactionLineVM { Model = line }; foreach (var oppositeLine in lineVM.OpposingLines) { if (!oppositeLine.Description.Equals("Sales Transaction Receipt")) { if (line.Seq == "Credit") { oppositeLine.Amount = -oppositeLine.Amount; } DisplayedLines.Add(new LedgerTransactionLineVM { Model = oppositeLine.Model, Balance = _beginningBalance + oppositeLine.Amount }); } else { salesreceiptLine.Amount += oppositeLine.Amount; } _endingBalance += oppositeLine.Amount; oppositeLine.Balance = _endingBalance; } } if (salesreceiptLine.Amount > 0) { DisplayedLines.Add(new LedgerTransactionLineVM { Model = salesreceiptLine, Balance = _endingBalance }); } } OnPropertyChanged("EndingBalance"); }
private static LedgerAccountBalance CreateSupplierLedgerAccountBalance(LedgerAccount ledgerAccount) { return(new LedgerAccountBalance { LedgerAccount = ledgerAccount, PeriodYear = UtilityMethods.GetCurrentDate().Year, }); }
public LedgerAccount GetLedgerAccountFromPersonId(int PersonId) { LedgerAccount account = (from L in db.LedgerAccount where L.PersonId == PersonId select L).FirstOrDefault(); return(account); }
public LedgerAccount GetLedgerAccountByPersondId(int PersonId) { LedgerAccount LedgerAccount = (from L in _LedgerAccountRepository.Instance where L.PersonId == PersonId select L).FirstOrDefault(); return(LedgerAccount); }
private static LedgerAccountBalance CreateSupplierLedgerAccountBalance(LedgerAccount ledgerAccount) { return new LedgerAccountBalance { LedgerAccount = ledgerAccount, PeriodYear = UtilityMethods.GetCurrentDate().Year, }; }
private void GetDebitCreditTotal(LedgerAccount LedgerAccount, DateTime interval, out decimal debitbalance, out decimal creditbalance) { debitbalance = LedgerGenerals.Where(b => b.LedgerAccountId == LedgerAccount.LedgerAccountId) .Where(a => a.JournalEntryDate.Date <= interval.Date) .Sum(b => b.Debit); creditbalance = LedgerGenerals.Where(b => b.LedgerAccountId == LedgerAccount.LedgerAccountId) .Where(a => a.JournalEntryDate.Date <= interval.Date) .Sum(b => b.Credit); }
protected override async Task Handle(Request request, CancellationToken cancellationToken) { var aggregate = new LedgerAccount(request.LedgerAccountId.Value, request.CommonName, request.AccountNumber); await session.Add(aggregate); await session.Commit(); }
private static LedgerGeneral CreateSupplierLedgerGeneral(LedgerAccount ledgerAccount) { return(new LedgerGeneral { LedgerAccount = ledgerAccount, PeriodYear = UtilityMethods.GetCurrentDate().Year, Period = UtilityMethods.GetCurrentDate().Month, }); }
private decimal CalculatePeriodLedgerAccountBalanceChange(LedgerAccount ledgerAccount, int year, int month) { var periodLedgerTransactionLines = _repository.Get <LedgerTransactionLine>(line => line.LedgerAccountId.Equals(ledgerAccount.Id) && line.LedgerTransaction.PostingDate.Year.Equals(year) && line.LedgerTransaction.PostingDate.Month.Equals(month)); return(LedgerAccountBalanceExtensions.CalculateLedgerTransactionLinesTotal(periodLedgerTransactionLines)); }
private void GetDebitCreditTotal(LedgerAccount LedgerAccount, out decimal debitbalance, out decimal creditbalance) { debitbalance = Ledgergenerals.Where(b => b.LedgerAccountId == LedgerAccount.LedgerAccountId) //.Where(a => a.JournalEntryDate.Date <= IncomeStatementDate.Date) .Sum(b => b.Debit); creditbalance = Ledgergenerals.Where(b => b.LedgerAccountId == LedgerAccount.LedgerAccountId) //.Where(a => a.JournalEntryDate.Date <= IncomeStatementDate.Date) .Sum(b => b.Credit); }
public AlertBack DeleteLedgerAccount([FromBody] LedgerAccount model, int id = 0) { AlertBack alert = new AlertBack(); ledgerAccountService.Delete(model); alert.status = "success"; alert.message = "Register Successfully"; return(alert); }
private static LedgerGeneral CreateSupplierLedgerGeneral(LedgerAccount ledgerAccount) { return new LedgerGeneral { LedgerAccount = ledgerAccount, PeriodYear = UtilityMethods.GetCurrentDate().Year, Period = UtilityMethods.GetCurrentDate().Month, }; }
public LedgerAccountDto GetLedgerAccount(string ledgerUID, int accountId) { Assertion.AssertObject(ledgerUID, "ledgerUID"); Assertion.Assert(accountId > 0, "accountId"); var ledger = Ledger.Parse(ledgerUID); LedgerAccount ledgerAccount = ledger.GetAccountWithId(accountId); return(LedgerMapper.MapAccount(ledgerAccount)); }
public async Task <int> SaveLedgerAccountAsync(LedgerAccount LedgerAccount) { if (LedgerAccount.LedgerAccountId < 1) { Context.LedgerAccounts.Add(LedgerAccount); } else { Context.Entry(LedgerAccount).State = EntityState.Modified; } return(await SaveAllAsync()); }
public int SaveLedgerAccount(LedgerAccount LedgerAccount) { if (LedgerAccount.AccountClassId < 1) { Context.LedgerAccounts.Add(LedgerAccount); } else { Context.Entry(LedgerAccount).State = System.Data.Entity.EntityState.Modified; } return(SaveAll()); }
//[Theory] public void ChequeReq_AccountNumberInvalid(int value) { LedgerAccount acct = generateValidLedgerAcocunt(); acct.Number = value; var validationContext = new ValidationContext(acct, null, null); var validationResults = new List <ValidationResult>(); var isValid = Validator.TryValidateObject(acct, validationContext, validationResults, true); Assert.False(isValid); }
/// <summary> /// Subscribe supplier with a company /// </summary> /// <param name="supplierId">Supplier Identifier</param> /// <param name="companyId">Company Identifier</param> public virtual void Subscribe(int supplierId, int companyId) { // if relationship already exists, activate it and exit var supplierSubscription = GetSupplierSubscription(supplierId, companyId); if (supplierSubscription != null) { if (supplierSubscription.IsActive) { throw new ArgumentException("Subscription already exists."); } supplierSubscription.IsActive = true; _repository.Save(); return; } var company = _repository.GetById <Company>(companyId, c => c.ChartOfAccounts); if (company == null) { throw new ArgumentException("Company does not exist."); } var supplier = _repository.GetById <Supplier>(supplierId); if (supplier == null) { throw new ArgumentException("Supplier does not exist."); } var ledgerAccount = new LedgerAccount { AccountNumber = _ledgerAccountService.GenerateNewAccountNumber(LedgerAccountGroup.AccountsPayable), Name = $"{company.Name} - {supplier.Name} Accounts Payable", Description = $"Amounts owed to {supplier.Name}", ChartOfAccountsId = company.ChartOfAccounts.Id, IsHidden = true, IsDefault = true, Type = LedgerAccountType.Liability, Group = LedgerAccountGroup.AccountsPayable }; supplierSubscription = new SupplierSubscription { CompanyId = companyId, SupplierId = supplierId, LedgerAccount = ledgerAccount }; _repository.Create(supplierSubscription); _repository.Save(); }
public void Can_add_ledgerAccount() { var coa = new ChartOfAccounts { CompanyId = 1 }; var ledgerAccount = new LedgerAccount { Id = 1 }; coa.LedgerAccounts.Add(ledgerAccount); Assert.Equal(1, coa.LedgerAccounts.Count); Assert.Equal(1, coa.LedgerAccounts.First().Id); }
// GET: /LedgerAccount/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } LedgerAccount ObjLedgerAccount = db.LedgerAccounts.Find(id); if (ObjLedgerAccount == null) { return(HttpNotFound()); } return(View(ObjLedgerAccount)); }
public ActionResult Edit(LedgerAccount ledgerAccount) { ModelState.Clear(); TryValidateModel(ledgerAccount); if (ModelState.IsValid) { ledgerRepository.SaveLedgerAccount(ledgerAccount); TempData["message"] = string.Format("{0} saved successfully", ledgerAccount.LedgerAccountName); CacheRepository.RefreshLedgerAccounts(); return(RedirectToAction("Index")); } SetMetaDataForForm(); return(View(ledgerAccount)); }
// GET: /LedgerAccount/MultiViewIndex/5 public ActionResult MultiViewIndex(int?id) { LedgerAccount ObjLedgerAccount = db.LedgerAccounts.Find(id); ViewBag.IsWorking = 0; if (id > 0) { ViewBag.IsWorking = id; ViewBag.LedgerAccountTypeId = new SelectList(db.LedgerAccountTypes, "Id", "Title", ObjLedgerAccount.LedgerAccountTypeId); ViewBag.ParentId = new SelectList(db.LedgerAccounts, "Id", "Title", ObjLedgerAccount.ParentId); ViewBag.UserId = new SelectList(db.Users, "Id", "Username", ObjLedgerAccount.UserId); } return(View(ObjLedgerAccount)); }
private RevenueVm GetRevenues(LedgerAccount LedgerAccount, decimal debitbalance, decimal creditbalance) { if (debitbalance == 0 && creditbalance == 0) { return(null); } decimal balance = 0; RevenueVm rvm = new RevenueVm(); rvm.LedgerAccountName = LedgerAccount.AccountName; balance = creditbalance - debitbalance; rvm.Amount = balance; TotalRevenueBalance += balance; return(rvm); }
private ExpenseVm GetExpenses(LedgerAccount LedgerAccount, decimal debitbalance, decimal creditbalance) { if (debitbalance == 0 && creditbalance == 0) { return(null); } decimal balance = 0; ExpenseVm evm = new ExpenseVm(); evm.LedgerAccountName = LedgerAccount.AccountName; balance = debitbalance - creditbalance; evm.Amount = balance; TotalExpenseBalance += balance; return(evm); }
public void InsertLedgerAccount() { try { Type LedgerAccountConstantsType = typeof(LedgerAccountConstants); System.Type[] ChildClassCollection = LedgerAccountConstantsType.GetNestedTypes(); foreach (System.Type ChildClass in ChildClassCollection) { int LedgerAccountId = (int)ChildClass.GetField("LedgerAccountId").GetRawConstantValue(); if (db.LedgerAccount.Find(LedgerAccountId) == null) { LedgerAccount LedgerAccount = new LedgerAccount(); LedgerAccount.LedgerAccountId = (int)ChildClass.GetField("LedgerAccountId").GetRawConstantValue(); LedgerAccount.LedgerAccountName = (string)ChildClass.GetField("LedgerAccountName").GetRawConstantValue(); LedgerAccount.LedgerAccountSuffix = (string)ChildClass.GetField("LedgerAccountSuffix").GetRawConstantValue(); LedgerAccount.LedgerAccountGroupId = (int)ChildClass.GetField("LedgerAccountGroupId").GetRawConstantValue(); LedgerAccount.IsActive = true; LedgerAccount.IsSystemDefine = true; LedgerAccount.CreatedBy = "System"; LedgerAccount.ModifiedBy = "System"; LedgerAccount.CreatedDate = System.DateTime.Now; LedgerAccount.ModifiedDate = System.DateTime.Now; LedgerAccount.ObjectState = Model.ObjectState.Added; db.LedgerAccount.Add(LedgerAccount); } else { LedgerAccount LedgerAccount = db.LedgerAccount.Find(LedgerAccountId); LedgerAccount.LedgerAccountName = (string)ChildClass.GetField("LedgerAccountName").GetRawConstantValue(); LedgerAccount.LedgerAccountSuffix = (string)ChildClass.GetField("LedgerAccountSuffix").GetRawConstantValue(); LedgerAccount.LedgerAccountGroupId = (int)ChildClass.GetField("LedgerAccountGroupId").GetRawConstantValue(); LedgerAccount.IsActive = true; LedgerAccount.IsSystemDefine = true; LedgerAccount.ModifiedBy = "System"; LedgerAccount.ModifiedDate = System.DateTime.Now; LedgerAccount.ObjectState = Model.ObjectState.Modified; db.LedgerAccount.Add(LedgerAccount); } db.SaveChanges(); } } catch (Exception ex) { string message = ex.Message; } }
static internal LedgerAccountDto MapAccount(LedgerAccount ledgerAccount) { return(new LedgerAccountDto { Id = ledgerAccount.Id, Ledger = ledgerAccount.Ledger.MapToNamedEntity(), Name = ledgerAccount.Name, Number = ledgerAccount.Number, Description = ledgerAccount.Description, Role = ledgerAccount.Role, AccountType = ledgerAccount.AccountType, DebtorCreditor = ledgerAccount.DebtorCreditor, Level = ledgerAccount.Level, CurrencyRules = ledgerAccount.CurrencyRules, SectorRules = ledgerAccount.SectorRules }); }
// GET: /LedgerAccount/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } LedgerAccount ObjLedgerAccount = db.LedgerAccounts.Find(id); if (ObjLedgerAccount == null) { return(HttpNotFound()); } ViewBag.LedgerAccountTypeId = new SelectList(db.LedgerAccountTypes, "Id", "Title", ObjLedgerAccount.LedgerAccountTypeId); ViewBag.ParentId = new SelectList(db.LedgerAccounts, "Id", "Title", ObjLedgerAccount.ParentId); ViewBag.UserId = new SelectList(db.Users, "Id", "Username", ObjLedgerAccount.UserId); return(View(ObjLedgerAccount)); }
/// <summary> /// Inserts a ledger account /// </summary> /// <param name="ledgerAccount">Ledger Account</param> public virtual void InsertLedgerAccount(LedgerAccount ledgerAccount) { if (!CommonHelper.GetFirstDigit((int)ledgerAccount.Group).Equals((int)ledgerAccount.Type)) { throw new ArgumentException("Ledger account group is not compatible with type"); } var coaLedgerAccounts = _repository.Get <LedgerAccount>(la => la.ChartOfAccountsId.Equals(ledgerAccount.ChartOfAccountsId)); if (coaLedgerAccounts.Any(account => account.Name.ToLowerInvariant().Equals(ledgerAccount.Name.ToLowerInvariant()))) { throw new ArgumentException("Ledger account name already exists."); } ledgerAccount.AccountNumber = GenerateNewAccountNumber(ledgerAccount.Group); _repository.Create(ledgerAccount); _repository.Save(); }
public ActionResult DeleteConfirmed(int id) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); try { LedgerAccount ObjLedgerAccount = db.LedgerAccounts.Find(id); db.LedgerAccounts.Remove(ObjLedgerAccount); db.SaveChanges(); sb.Append("Sumitted"); return(Content(sb.ToString())); } catch (Exception ex) { sb.Append("Error :" + ex.Message); } return(Content(sb.ToString())); }
private void UpdateDisplayedLines() { DisplayedLines.Clear(); SetBeginningBalance(); _endingBalance = _beginningBalance; using (var context = new ERPContext()) { var lines = context.Ledger_Transaction_Lines .Include("LedgerAccount") .Include("LedgerTransaction") .Where(line => line.LedgerAccount.Name.Equals("Cash") && line.LedgerTransaction.Date.Equals(_date)) .ToList(); var account = new LedgerAccount { ID = -1, Name = "Sales Receipt", Class = "Asset" }; var transaction = new LedgerTransaction { ID = -1, Date = _date, Description = "Sales Receipt", Documentation = "Sales Receipt" }; var salesreceiptLine = new LedgerTransactionLine { LedgerTransaction = transaction, LedgerAccount = account, Seq = "Debit" }; foreach (var line in lines) { var lineVM = new LedgerTransactionLineVM { Model = line }; foreach (var oppositeLine in lineVM.OpposingLines) { if (!oppositeLine.Description.Equals("Sales Transaction Receipt")) { if (line.Seq == "Credit") oppositeLine.Amount = -oppositeLine.Amount; DisplayedLines.Add(new LedgerTransactionLineVM { Model = oppositeLine.Model, Balance = _beginningBalance + oppositeLine.Amount }); } else salesreceiptLine.Amount += oppositeLine.Amount; _endingBalance += oppositeLine.Amount; oppositeLine.Balance = _endingBalance; } } if (salesreceiptLine.Amount > 0) DisplayedLines.Add(new LedgerTransactionLineVM { Model = salesreceiptLine, Balance = _endingBalance }); } OnPropertyChanged("EndingBalance"); }
private void CloseLiabilityOrRevenueAccount(LedgerAccount account, ERPContext context) { var periodYearBalances = account.LedgerAccountBalances.First(balance => balance.PeriodYear.Equals(UtilityMethods.GetCurrentDate().Year)); switch (Period) { case 1: if (!account.Class.Equals("Revenue")) periodYearBalances.Balance1 += periodYearBalances.BeginningBalance; periodYearBalances.Balance1 += account.LedgerGeneral.Credit - account.LedgerGeneral.Debit; account.LedgerGeneral.Debit = 0; account.LedgerGeneral.Credit = 0; break; case 2: if (!account.Class.Equals("Revenue")) periodYearBalances.Balance2 += periodYearBalances.Balance1; periodYearBalances.Balance2 += account.LedgerGeneral.Credit - account.LedgerGeneral.Debit; account.LedgerGeneral.Debit = 0; account.LedgerGeneral.Credit = 0; break; case 3: if (!account.Class.Equals("Revenue")) periodYearBalances.Balance3 += periodYearBalances.Balance2; periodYearBalances.Balance3 += account.LedgerGeneral.Credit - account.LedgerGeneral.Debit; account.LedgerGeneral.Debit = 0; account.LedgerGeneral.Credit = 0; break; case 4: if (!account.Class.Equals("Revenue")) periodYearBalances.Balance4 += periodYearBalances.Balance3; periodYearBalances.Balance4 += account.LedgerGeneral.Credit - account.LedgerGeneral.Debit; account.LedgerGeneral.Debit = 0; account.LedgerGeneral.Credit = 0; break; case 5: if (!account.Class.Equals("Revenue")) periodYearBalances.Balance5 += periodYearBalances.Balance4; periodYearBalances.Balance5 += account.LedgerGeneral.Credit - account.LedgerGeneral.Debit; account.LedgerGeneral.Debit = 0; account.LedgerGeneral.Credit = 0; break; case 6: if (!account.Class.Equals("Revenue")) periodYearBalances.Balance6 += periodYearBalances.Balance5; periodYearBalances.Balance6 += account.LedgerGeneral.Credit - account.LedgerGeneral.Debit; account.LedgerGeneral.Debit = 0; account.LedgerGeneral.Credit = 0; break; case 7: if (!account.Class.Equals("Revenue")) periodYearBalances.Balance7 += periodYearBalances.Balance6; periodYearBalances.Balance7 += account.LedgerGeneral.Credit - account.LedgerGeneral.Debit; account.LedgerGeneral.Debit = 0; account.LedgerGeneral.Credit = 0; break; case 8: if (!account.Class.Equals("Revenue")) periodYearBalances.Balance8 += periodYearBalances.Balance7; periodYearBalances.Balance8 += account.LedgerGeneral.Credit - account.LedgerGeneral.Debit; account.LedgerGeneral.Debit = 0; account.LedgerGeneral.Credit = 0; break; case 9: if (!account.Class.Equals("Revenue")) periodYearBalances.Balance9 += periodYearBalances.Balance8; periodYearBalances.Balance9 += account.LedgerGeneral.Credit - account.LedgerGeneral.Debit; account.LedgerGeneral.Debit = 0; account.LedgerGeneral.Credit = 0; break; case 10: if (!account.Class.Equals("Revenue")) periodYearBalances.Balance10 += periodYearBalances.Balance9; periodYearBalances.Balance10 += account.LedgerGeneral.Credit - account.LedgerGeneral.Debit; account.LedgerGeneral.Debit = 0; account.LedgerGeneral.Credit = 0; break; case 11: if (!account.Class.Equals("Revenue")) periodYearBalances.Balance11 += periodYearBalances.Balance10; periodYearBalances.Balance11 += account.LedgerGeneral.Credit - account.LedgerGeneral.Debit; account.LedgerGeneral.Debit = 0; account.LedgerGeneral.Credit = 0; break; case 12: if (!account.Class.Equals("Revenue")) periodYearBalances.Balance12 += periodYearBalances.Balance11; periodYearBalances.Balance12 += account.LedgerGeneral.Credit - account.LedgerGeneral.Debit; account.LedgerGeneral.Debit = 0; account.LedgerGeneral.Credit = 0; break; } context.SaveChanges(); }
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; } }
private void CreateNewAccount(ERPContext context) { LedgerAccount newAccount; if (_newEntryGroup.Equals("Bank")) { newAccount = new LedgerAccount { Name = _newEntryName, Class = "Asset", Notes = "Current Asset", LedgerAccountBalances = new ObservableCollection<LedgerAccountBalance>() }; } else if (_newEntryGroup.Equals("Operating Expense")) { newAccount = new LedgerAccount { Name = _newEntryName, Class = "Expense", Notes = "Operating Expense", LedgerAccountBalances = new ObservableCollection<LedgerAccountBalance>() }; } else if (_newEntryGroup.Equals("Accounts Receivable")) { newAccount = new LedgerAccount { Name = _newEntryName, Class = "Asset", Notes = "Accounts Receivable", LedgerAccountBalances = new ObservableCollection<LedgerAccountBalance>() }; } else if (_newEntryGroup.Equals("Accounts Payable")) { newAccount = new LedgerAccount { Name = _newEntryName, Class = "Liability", Notes = "Accounts Payable", LedgerAccountBalances = new ObservableCollection<LedgerAccountBalance>() }; } else { newAccount = new LedgerAccount { Name = _newEntryName, Class = "Expense", Notes = "Operating Expense", LedgerAccountBalances = new ObservableCollection<LedgerAccountBalance>() }; } var newAccountGeneralLedger = new LedgerGeneral { LedgerAccount = newAccount, PeriodYear = context.Ledger_General.First().PeriodYear, Period = context.Ledger_General.First().Period }; var newAccountBalances = new LedgerAccountBalance { LedgerAccount = newAccount, PeriodYear = context.Ledger_General.First().PeriodYear }; newAccount.LedgerGeneral = newAccountGeneralLedger; newAccount.LedgerAccountBalances.Add(newAccountBalances); context.Ledger_Accounts.Add(newAccount); }