Emmmanuel FIADUFE

Emmmanuel FIADUFE

  • 693
  • 1.1k
  • 55.5k

I want product qty and amount to sum up by date

Oct 24 2023 6:11 PM

Hello Team,

Please I want to sum up product quantity and amount by same date. Thank you

 public ActionResult GetAllPrintSalesRecord(string sDate = null, string eDate = null, string OrderNo = null)
        {
            ASPNETMASTERPOSTEntities db = new ASPNETMASTERPOSTEntities();

            var dataList = db.tblSales.Join(
                db.tblSalesDetails,
                sales => sales.SalesId,
                detail => detail.SalesId,
                (sales, detail) => new { Sales = sales, detail = detail });

            var modifiedData = dataList.GroupBy(a => new { a.detail.ProductId, a.Sales.OrderDate }).Select(x => new

            {
                SalesDetailId = x.FirstOrDefault().detail.SalesDetailId,
                Quantity = x.Sum(c => c.detail.Quantity),
                ProductId = x.Key.ProductId,
                ProductName = x.FirstOrDefault().detail.tblProduct.ProductName,
                SalesId = x.FirstOrDefault().Sales.SalesId,
                OrderDate = x.FirstOrDefault().Sales.OrderDate,
                SubTotal = x.FirstOrDefault().Sales.SubTotal,
                DiscountPercent = x.FirstOrDefault().Sales.DiscountPercent,
                VatPercent = x.FirstOrDefault().Sales.VatPercent,
                TotalAmount = x.Sum(c => c.Sales.TotalAmount)
            }).ToList();
  return Json(new { modifiedData = modifiedData, total = total, discount = discount, tax = tax }, JsonRequestBehavior.AllowGet);
        }
 


Answers (2)