public static List <BO_CreditSales> GetUnPaidCreditSales(JQueryDataTableParamModel Param) { using (AprosysAccountingEntities db_aa = new AprosysAccountingEntities()) { List <BO_CreditSales> lst_CreditSales = new List <BO_CreditSales>(); //Param.Start_Date = BL_Common.GetDatetime().AddDays(-7); Param.End_Date = Param.End_Date.AddDays(1); var lst = db_aa.Credit_GetUnpaidCreditSales(Param.Start_Date, Param.End_Date).ToList(); var partiallyPaid = GetAllPartialPayments().GroupBy(x => x.InvoiceNum).ToDictionary(x => x.Key); BO_CreditSales obj; if (lst != null && lst.Count > 0) { foreach (var _sales in lst.ToList()) { obj = new BO_CreditSales(); obj.invoiceNo = _sales.InvoiceNo; obj.sellDate = _sales.SalesDate.Value; obj.customerName = _sales.CustomerName; obj.netAmount = _sales.Amount ?? 0; obj.customerID = _sales.CustId; if (partiallyPaid.ContainsKey(obj.invoiceNo)) { obj.netAmount = obj.netAmount - partiallyPaid[obj.invoiceNo].Sum(x => x.Amount); } if (obj.netAmount > 0) { lst_CreditSales.Add(obj); } } } return(lst_CreditSales.OrderByDescending(x => (Convert.ToInt32(x.invoiceNo.Remove(0, 4)))).ToList()); } // return lst_CreditSales; }