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);
}
Vishal JoshiPosted Oct 24, 2023, 8:02 PM
Hello Emmanuel,
You can use Group by to sum the quantity and total amount of sales records. you can add key columns as orderDate and ProductId into the group by.
Please check the code below to get it to work.
Thanks
Vishal Joshi
Emmmanuel FIADUFEPosted Oct 24, 2023, 10:10 PM
Thank you Mr Vishal, it is working as per your correction