public void AddJournalEntry(JournalEntryHeader journalEntry) { var glEntry = new GeneralLedgerHeader() { Date = journalEntry.Date, DocumentType = Core.Domain.DocumentTypes.JournalEntry, Description = journalEntry.Memo, CreatedBy = journalEntry.CreatedBy, CreatedOn = journalEntry.CreatedOn, ModifiedBy = journalEntry.ModifiedBy, ModifiedOn = journalEntry.ModifiedOn, }; foreach (var je in journalEntry.JournalEntryLines) { glEntry.GeneralLedgerLines.Add(new GeneralLedgerLine() { AccountId = je.AccountId, DrCr = je.DrCr, Amount = je.Amount, CreatedBy = journalEntry.CreatedBy, CreatedOn = journalEntry.CreatedOn, ModifiedBy = journalEntry.ModifiedBy, ModifiedOn = journalEntry.ModifiedOn, }); } if (ValidateGeneralLedgerEntry(glEntry)) { journalEntry.GeneralLedgerHeader = glEntry; _journalEntryRepo.Insert(journalEntry); } }
public static bool NoLineAmountIsEqualToZero(GeneralLedgerHeader glHeader) { decimal totalDebit = glHeader.GeneralLedgerLines.Where(d => d.DrCr == Core.Domain.TransactionTypes.Dr).Sum(d => d.Amount); decimal totalCredit = glHeader.GeneralLedgerLines.Where(d => d.DrCr == Core.Domain.TransactionTypes.Cr).Sum(d => d.Amount); if (totalDebit == 0) return false; if (totalCredit == 0) return false; return true; }
public GeneralLedgerHeader CreateGeneralLedgerHeader(DocumentTypes documentType, DateTime date, string description) { var entry = new GeneralLedgerHeader() { DocumentType = documentType, Date = date, Description = description, }; return entry; }
public void UpdateJournalEntry(JournalEntryHeader journalEntry, bool posted = false) { if (posted) { journalEntry.Posted = posted; if (journalEntry.GeneralLedgerHeaderId == 0) { var glEntry = new GeneralLedgerHeader() { Date = DateTime.Now, DocumentType = Core.Domain.DocumentTypes.JournalEntry, Description = journalEntry.Memo, }; foreach (var je in journalEntry.JournalEntryLines) { glEntry.GeneralLedgerLines.Add(new GeneralLedgerLine() { Account = GetAccounts().Where(a => a.Id == je.AccountId).FirstOrDefault(), AccountId = je.AccountId, DrCr = je.DrCr, Amount = je.Amount, }); } if (ValidateGeneralLedgerEntry(glEntry)) { journalEntry.GeneralLedgerHeader = glEntry; } } } _journalEntryRepo.Update(journalEntry); //var glEntry = _generalLedgerRepository.Table.Where(gl => gl.Id == journalEntry.GeneralLedgerHeaderId).FirstOrDefault(); //glEntry.Date = journalEntry.Date; //foreach (var je in journalEntry.JournalEntryLines) //{ // if (glEntry.GeneralLedgerLines.Any(l => l.AccountId == je.AccountId)) // { // var existingLine = glEntry.GeneralLedgerLines.Where(l => l.AccountId == je.AccountId).FirstOrDefault(); // existingLine.Amount = je.Amount; // existingLine.DrCr = je.DrCr; // } // else // { // glEntry.GeneralLedgerLines.Add(new GeneralLedgerLine() // { // AccountId = je.AccountId, // DrCr = je.DrCr, // Amount = je.Amount, // }); // } //} //if (ValidateGeneralLedgerEntry(glEntry) && glEntry.ValidateAccountingEquation()) //{ // journalEntry.GeneralLedgerHeader = glEntry; // _journalEntryRepo.Update(journalEntry); //} }
public bool ValidateGeneralLedgerEntry(GeneralLedgerHeader glEntry) { if (!FinancialHelper.DrCrEqualityValidated(glEntry)) throw new InvalidOperationException("Debit/Credit are not equal."); if (!FinancialHelper.NoLineAmountIsEqualToZero(glEntry)) throw new InvalidOperationException("One or more line(s) amount is zero."); var fiscalYear = CurrentFiscalYear(); if (fiscalYear == null || !FinancialHelper.InRange(glEntry.Date, fiscalYear.StartDate, fiscalYear.EndDate) || !FinancialHelper.InRange(DateTime.Now, fiscalYear.StartDate, fiscalYear.EndDate)) throw new InvalidOperationException("Date is out of range. Must within financial year."); //var duplicateAccounts = glEntry.GeneralLedgerLines.GroupBy(gl => gl.AccountId).Where(gl => gl.Count() > 1); //if (duplicateAccounts.Count() > 0) // throw new InvalidOperationException("Duplicate account id in a collection."); foreach (var account in glEntry.GeneralLedgerLines) if (!_accountRepo.GetById(account.AccountId).CanPost()) throw new InvalidOperationException("One of the account is not valid for posting"); //if(!glEntry.ValidateAccountingEquation()) // throw new InvalidOperationException("One of the account not equal."); return true; }
public void SaveGeneralLedgerEntry(GeneralLedgerHeader entry) { if (ValidateGeneralLedgerEntry(entry)) { try { _generalLedgerRepository.Insert(entry); } catch { } } }
public static bool NoDuplicateAccountInLines(GeneralLedgerHeader glHeader) { //TODO: implement logic. Do not allow duplicate account in gl lines return true; }
public static bool DrCrEqualityValidated(GeneralLedgerHeader glHeader) { decimal totalDebit = glHeader.GeneralLedgerLines.Where(d => d.DrCr == Core.Domain.TransactionTypes.Dr).Sum(d => d.Amount); decimal totalCredit = glHeader.GeneralLedgerLines.Where(d => d.DrCr == Core.Domain.TransactionTypes.Cr).Sum(d => d.Amount); return (totalDebit - totalCredit) == 0; }
public GeneralLedgerHeader CreateGeneralLedgerHeader(DocumentTypes documentType, DateTime date, string description) { var entry = new GeneralLedgerHeader() { DocumentType = documentType, Date = date, Description = description, CreatedBy = Thread.CurrentPrincipal.Identity.Name, CreatedOn = DateTime.Now, ModifiedBy = Thread.CurrentPrincipal.Identity.Name, ModifiedOn = DateTime.Now }; return entry; }