public bool PostLedger() { Console.WriteLine("> {0} Post {2} [{1}]", DateTime.Now.ToLongTimeString(), this.ReadyForPost.Count(), this.transactionType.ToString()); this.UnPostLedger(); var trLedger = new LedgerGroup() { Id = Guid.NewGuid(), TransactionDate = organization.DataItems.FirstDate, TransactionName = "Open Entry", TransactionNo = 0, TransactionType = transactionType }; erpNodeDBContext.LedgerGroups.Add(trLedger); this.ReadyForPost.ForEach(a => { trLedger.AddDebit(a, a.OpeningDebitBalance); trLedger.AddCredit(a, a.OpeningCreditBalance); a.PostStatus = LedgerPostStatus.Posted; }); var result = trLedger.FinalValidate(); if (result == false) { this.erpNodeDBContext.LedgerGroups.Remove(trLedger); } this.erpNodeDBContext.SaveChanges(); return(true); }
public bool PostLedger(FiscalYear tr, bool SaveImmediately = true) { if (tr.PostStatus == LedgerPostStatus.Posted) { return(false); } var trLedger = new LedgerGroup() { Id = tr.Id, TransactionDate = tr.EndDate, TransactionName = tr.Name, TransactionType = transactionType }; tr.PeriodAccountBalances .Where(b => b.Account.Type == AccountTypes.Income || b.Account.Type == AccountTypes.Expense) .ToList().ForEach(b => { trLedger.AddDebit(b.Account, b.TotalCredit); trLedger.AddCredit(tr.ClosingAccount, b.TotalCredit); trLedger.AddCredit(b.Account, b.TotalDebit); trLedger.AddDebit(tr.ClosingAccount, b.TotalDebit); }); if (trLedger.FinalValidate()) { erpNodeDBContext.LedgerGroups.Add(trLedger); tr.PostStatus = LedgerPostStatus.Posted; } else { return(false); } if (SaveImmediately) { erpNodeDBContext.SaveChanges(); } return(true); }