public IEnumerable <LedgerJournalVm> GetLedgerReport(int LedgerAccountId = 1) { var ledger = Ledgergenerals.Where(a => a.LedgerAccountId == LedgerAccountId).FirstOrDefault(); if (ledger == null) { LedgerName = "No Ledger Found"; return(null); } else { LedgerName = Ledgergenerals.Where(a => a.LedgerAccountId == LedgerAccountId).FirstOrDefault().LedgerAccount.AccountName + " Ledger"; } var data = Ledgergenerals.Where(a => a.LedgerAccountId == LedgerAccountId) .Where(a => a.JournalEntryDate.Date >= FromDate && a.JournalEntryDate.Date <= ToDate) .OrderBy(a => a.JournalEntryDate.Date) .Select(a => new LedgerJournalVm { TransactionId = a.LedgerTransactionId, Date = a.JournalEntryDate.Date, LedgerAccount = a.LedgerAccount.AccountName, DebitString = a.Debit > 0 ? ResolveOpp(a.LedgerTransactionId, a.LedgerAccountId) : "", CreditString = a.Credit > 0 ? ResolveOpp(a.LedgerTransactionId, a.LedgerAccountId) : "", Particulars = LedgerTransactions.Where(b => b.LedgerTransactionId == a.LedgerTransactionId).Select(b => b.Description).FirstOrDefault(), // OtherLedgerAccount = ResolveOpp(a.LedgerTransactionId, a.LedgerAccountId), Debit = a.Debit, Credit = a.Credit, StartDate = FromDate, EndDate = ToDate, // Balance=ResolveBalance("10/11/2017", "21/12/2017", a.LedgerTransactionId, a.LedgerAccountId) Balance = GetBalance(a) }).ToList(); data.Insert(0, new LedgerJournalVm { Balance = ResolveBalanceBroughtDown(LedgerAccountId) }); // data.Insert(0, new LedgerJournalVm { Balance = ResolveBalanceBroughtDown(LedgerAccountId) }); JournalVms = new ObservableCollection <LedgerJournalVm>(data); CalculateTotals(); return(JournalVms); }
public IEnumerable <LedgerJournalVm> GetLedgerReport(int LedgerAccountId = 1) { CultureInfo info = new CultureInfo("ne-NP"); info.NumberFormat.CurrencySymbol = "Rs"; info.DateTimeFormat = new DateTimeFormatInfo(); info.DateTimeFormat.Calendar = new GregorianCalendar(GregorianCalendarTypes.Localized); info.DateTimeFormat.AMDesignator = "AM"; info.DateTimeFormat.PMDesignator = "PM"; System.Threading.Thread.CurrentThread.CurrentCulture = info; Thread.CurrentThread.CurrentUICulture = info; var data = Ledgergenerals.Where(a => a.LedgerAccountId == LedgerAccountId) .Where(a => a.JournalEntryDate.Date >= FromDate.Date && a.JournalEntryDate.Date <= ToDate.Date) .OrderBy(a => a.JournalEntryDate.Date) .Select(a => new LedgerJournalVm { TransactionId = a.LedgerTransactionId, Date = a.JournalEntryDate.Date, LedgerAccount = a.LedgerAccount.AccountName, Debit = a.Debit, //== 0 ? "" : a.Debit.ToString(), Credit = a.Credit, // == 0 ? "" : a.Credit.ToString(), Particulars = LedgerTransactions.Where(b => b.LedgerTransactionId == a.LedgerTransactionId).Select(b => b.Description).FirstOrDefault(), OtherLedgerAccount = ResolveOpp(a.LedgerTransactionId, a.LedgerAccountId), StartDate = FromDate.Date, EndDate = ToDate.Date, Balance = GetBalance(a), }).ToList(); data.Insert(0, new LedgerJournalVm { Date = DateTime.Parse("01/01/2001"), StartDate = FromDate, EndDate = ToDate, LedgerAccount = SelectedLedgerAccount.AccountName, Balance = ResolveBalanceBroughtDown(LedgerAccountId) }); JournalVms = new ObservableCollection <LedgerJournalVm>(data); JournalVms.Add(new Rms.Reports.LedgerJournalVm { Date = ToDate, BalanceCarriedDown = ResolveBalanceCarriedDown() }); return(JournalVms); }
public IEnumerable <LedgerJournalVm> GetLedgerReport(int LedgerAccountId) { ResolveBalance("ds", "sds", 1, 1); return(Ledgergenerals.Where(a => a.LedgerAccountId == LedgerAccountId) .Where(a => a.JournalEntryDate >= DateTime.Parse("10/11/2017", DateTimeFormatInfo.InvariantInfo) && a.JournalEntryDate <= DateTime.Parse("12/20/2018", DateTimeFormatInfo.InvariantInfo)) .OrderBy(a => a.JournalEntryDate) .Select(a => new LedgerJournalVm { TransactionId = a.LedgerTransactionId, Date = a.JournalEntryDate.Date, LedgerAccount = a.LedgerAccount.AccountName, Debit = a.Debit, //== 0 ? "" : a.Debit.ToString(), Credit = a.Credit, // == 0 ? "" : a.Credit.ToString(), Particulars = LedgerTransactions.Where(b => b.LedgerTransactionId == a.LedgerTransactionId).Select(b => b.Description).FirstOrDefault(), OtherLedgerAccount = ResolveOpp(a.LedgerTransactionId, a.LedgerAccountId), StartDate = DateTime.Parse("10/11/2017", DateTimeFormatInfo.InvariantInfo), EndDate = DateTime.Parse("12/21/2018", DateTimeFormatInfo.InvariantInfo), // Balance=ResolveBalance("10/11/2017", "21/12/2017", a.LedgerTransactionId, a.LedgerAccountId) }).ToList()); }
//private string ResolveBalance(string StartDate, string EndDate, int transactionId, int ledgerAccountId) //{ // var v = Ledgergenerals // .Where(a => a.JournalEntryDate >= DateTime.Parse("10/11/2017") && a.JournalEntryDate <= DateTime.Parse("10/12/2017")) // .Where(a => a.LedgerAccountId == 1); // List<Ledgergeneral> ldd = new List<Ledgergeneral>(); // List<OppAccount> oppacounts = new List<ViewModels.OppAccount>(); // foreach (var item in v) // { // ldd.Add(item); // } // decimal creditsum = ldd.Sum(a => a.Credit); // decimal debitsum = ldd.Sum(a => a.Debit); // string balance = ""; // if (creditsum > debitsum) // { // balance = "cBalance b/d" + (creditsum - debitsum).ToString(); // } // if (debitsum > creditsum) // { // balance = "cBalance b/d" + (debitsum - creditsum).ToString(); // } // return balance; //} public string ResolveOpp(int transactionId, int ledgerAccountId) { StringBuilder sb = new StringBuilder(); LedgerGeneral thisledger = new LedgerGeneral(); var v = LedgerTransactions.Where(a => a.LedgerTransactionId == transactionId); List <LedgerGeneral> ld = new List <LedgerGeneral>(); List <LedgerGeneral> ldd = new List <LedgerGeneral>(); //List<OppAccount> oppacounts = new List<ViewModels.OppAccount>(); foreach (var item in v) { foreach (var i in item.LedgerGenerals) { ldd.Add(i); if (i.LedgerAccountId == ledgerAccountId) { thisledger = i; continue; } ld.Add(i); } } if (ldd.Count() > 2) { LedgerGeneral maxdebit = new LedgerGeneral(); LedgerGeneral maxcredit = new LedgerGeneral(); maxdebit = ldd.Where(a => a.Debit == ldd.Max(b => b.Debit)).FirstOrDefault(); maxcredit = ldd.Where(a => a.Credit == ldd.Max(b => b.Credit)).FirstOrDefault(); bool debitbigger = false; if (maxdebit.Debit > maxcredit.Credit) { debitbigger = true; } else if (maxcredit.Credit > maxdebit.Debit) { debitbigger = false; } if (thisledger.Credit > 0) { if (thisledger == maxcredit) { if (debitbigger == false) { foreach (var item in ld) { if (item.Credit > 0) { var name = item.LedgerAccount.AccountName; if (name.Length > 8) { name = name.Substring(0, 8); } sb.Append(name + " "); sb.AppendLine(item.Credit.ToString()); } if (item.Debit > 0) { var name = item.LedgerAccount.AccountName; if (name.Length > 8) { name = name.Substring(0, 8); } sb.Append(name + " "); sb.AppendLine(item.Debit.ToString()); } } } else { sb.Append(maxdebit.LedgerAccount.AccountName + " "); sb.AppendLine(thisledger.Credit.ToString()); return(sb.ToString()); } } else { sb.Append(maxdebit.LedgerAccount.AccountName + " "); sb.AppendLine(thisledger.Credit.ToString()); return(sb.ToString()); } } else if (thisledger.Debit > 0) { if (thisledger == maxdebit) { if (debitbigger == true) { foreach (var item in ld) { if (item.Credit > 0) { var name = item.LedgerAccount.AccountName; if (name.Length > 8) { name = name.Substring(0, 8); } sb.Append(name + " "); sb.AppendLine(item.Credit.ToString()); } if (item.Debit > 0) { var name = item.LedgerAccount.AccountName; if (name.Length > 8) { name = name.Substring(0, 8); } sb.Append(name + " "); sb.AppendLine(item.Debit.ToString()); } } } else { sb.Append(maxcredit.LedgerAccount.AccountName + " "); sb.AppendLine(thisledger.Debit.ToString()); return(sb.ToString()); } } else { sb.Append(maxcredit.LedgerAccount.AccountName + " "); sb.AppendLine(thisledger.Debit.ToString()); return(sb.ToString()); } } } else { LedgerGeneral oppositeaccount = new LedgerGeneral(); foreach (var item in ldd) { if (item.LedgerAccountId != ledgerAccountId) { oppositeaccount = item; break; } } sb.Append(oppositeaccount.LedgerAccount.AccountName + " "); if (thisledger.Debit > 0) { sb.AppendLine(thisledger.Debit.ToString()); } if (thisledger.Credit > 0) { sb.AppendLine(thisledger.Credit.ToString()); } } return(sb.ToString().Trim()); }
//private string ResolveBalance(string StartDate, string EndDate, int transactionId, int ledgerAccountId) //{ // var v = Ledgergenerals // .Where(a => a.JournalEntryDate >= DateTime.Parse("10/11/2017") && a.JournalEntryDate <= DateTime.Parse("10/12/2017")) // .Where(a => a.LedgerAccountId == 1); // List<Ledgergeneral> ldd = new List<Ledgergeneral>(); // List<OppAccount> oppacounts = new List<ViewModels.OppAccount>(); // foreach (var item in v) // { // ldd.Add(item); // } // decimal creditsum = ldd.Sum(a => a.Credit); // decimal debitsum = ldd.Sum(a => a.Debit); // string balance = ""; // if (creditsum > debitsum) // { // balance = "cBalance b/d" + (creditsum - debitsum).ToString(); // } // if (debitsum > creditsum) // { // balance = "cBalance b/d" + (debitsum - creditsum).ToString(); // } // return balance; //} public string ResolveOpp(int transactionId, int ledgerAccountId) { var v = LedgerTransactions.Where(a => a.LedgerTransactionId == transactionId); List <LedgerGeneral> ld = new List <LedgerGeneral>(); List <LedgerGeneral> ldd = new List <LedgerGeneral>(); LedgerGeneral thisledger = new LedgerGeneral(); //List<OppAccount> oppacounts = new List<ViewModels.OppAccount>(); foreach (var item in v) { foreach (var i in item.LedgerGenerals) { ldd.Add(i); if (i.LedgerAccountId == ledgerAccountId) { thisledger = i; continue; } ld.Add(i); } } StringBuilder sb = new StringBuilder(); LedgerGeneral maxdebit = new LedgerGeneral(); LedgerGeneral maxcredit = new LedgerGeneral(); maxdebit = ldd.Where(a => a.Debit == ldd.Max(b => b.Debit)).FirstOrDefault(); maxcredit = ldd.Where(a => a.Credit == ldd.Max(b => b.Credit)).FirstOrDefault(); bool debitbigger = false; if (maxdebit.Debit > maxcredit.Credit) { debitbigger = true; } else if (maxcredit.Credit > maxdebit.Debit) { debitbigger = false; } if (thisledger.Credit > 0) { if (thisledger == maxcredit) { if (debitbigger == false) { foreach (var item in ld) { if (item.Credit > 0) { sb.AppendLine(item.Credit.ToString()); } if (item.Debit > 0) { sb.AppendLine(item.Debit.ToString()); } } } else { sb.AppendLine(thisledger.Credit.ToString()); return(sb.ToString()); } } else { sb.AppendLine(thisledger.Credit.ToString()); return(sb.ToString()); } } else if (thisledger.Debit > 0) { if (thisledger == maxdebit) { if (debitbigger == true) { foreach (var item in ld) { if (item.Credit > 0) { sb.AppendLine(item.Credit.ToString()); } if (item.Debit > 0) { sb.AppendLine(item.Debit.ToString()); } } } else { sb.AppendLine(thisledger.Debit.ToString()); return(sb.ToString()); } } else { sb.AppendLine(thisledger.Debit.ToString()); return(sb.ToString()); } } return(sb.ToString()); }