public bool PostLedger(Sale sale, bool saveChange = true) { if (sale.PostStatus == LedgerPostStatus.Posted) { throw new Exception("Post fail, Transaction aleardy posted"); } if (sale.Total == 0) { return(false); } Console.WriteLine(sale.Profile.Name); var trLedger = new Models.Accounting.LedgerGroup() { Id = sale.Id, TransactionDate = sale.TransactionDate, TransactionName = sale.Name, ProfileName = sale.Profile.Name, TransactionNo = sale.No, TransactionType = transactionType, Reference = sale.Reference, }; this.PostLedger_Items(trLedger, sale); this.PostLedger_Tax(trLedger, sale); trLedger.AddDebit(organization.SystemAccounts.AccountReceivable, sale.Total); if (trLedger.FinalValidate()) { sale.PostStatus = LedgerPostStatus.Posted; erpNodeDBContext.LedgerGroups.Add(trLedger); } else { trLedger.RemoveAllLedgerLines(); organization.EventLogs.NewEventLog(EventLogLevel.Error, "1011", "Error Posting", trLedger.TransactionName, ""); return(false); } if (saveChange) { erpNodeDBContext.SaveChanges(); } return(true); }
public bool PostLedger(Purchase tr, bool SaveImmediately = true) { if (tr.PostStatus == LedgerPostStatus.Posted) { throw new Exception("Post fail, Transaaction aleardy posted"); } if (tr.Total == 0) { return(false); } var trLedger = new Models.Accounting.LedgerGroup() { Id = tr.Id, TransactionDate = tr.TransactionDate, TransactionName = tr.Name, TransactionNo = tr.No, TransactionType = transactionType, Reference = tr.Reference, ProfileName = tr.Profile?.Name, }; this.PostLedger_Items(trLedger, tr); this.PostLedger_Tax(trLedger, tr); trLedger.AddCredit(organization.SystemAccounts.AccountPayable, tr.Total); if (trLedger.FinalValidate()) { tr.PostStatus = LedgerPostStatus.Posted; erpNodeDBContext.LedgerGroups.Add(trLedger); } else { trLedger.RemoveAllLedgerLines(); organization.EventLogs.NewEventLog(EventLogLevel.Error, "1011", "Error Posting", trLedger.TransactionName, ""); return(false); } if (SaveImmediately) { erpNodeDBContext.SaveChanges(); } return(true); }