private void PrepareViewBag(DesignConsumptionLineViewModel svm) { var ProductFaceContentGroups = from p in db.Product join pg in db.ProductGroups on p.ReferenceDocId equals pg.ProductGroupId into ProductGroupTable from ProductGroupTab in ProductGroupTable.DefaultIfEmpty() join fp in db.FinishedProduct on ProductGroupTab.ProductGroupId equals fp.ProductGroupId into FinishedProductTable from FinishedProductTab in FinishedProductTable.DefaultIfEmpty() join pcl in db.ProductContentLine on FinishedProductTab.FaceContentId equals pcl.ProductContentHeaderId into ProductContentLineTable from ProductContentLineTab in ProductContentLineTable.DefaultIfEmpty() where p.ProductId == svm.BaseProductId && ((int?)ProductContentLineTab.ProductGroupId ?? 0) != 0 group new { ProductContentLineTab } by new { ProductContentLineTab.ProductGroupId } into Result select new { ProductGroupId = Result.Key.ProductGroupId }; var TotalMainContents = (from L in db.BomDetail join P in db.Product on L.ProductId equals P.ProductId into ProductTable from ProductTab in ProductTable.DefaultIfEmpty() join pcon in ProductFaceContentGroups on ProductTab.ProductGroupId equals pcon.ProductGroupId into ProductFaceContentTable from ProductFaceContentTab in ProductFaceContentTable.DefaultIfEmpty() where L.BaseProductId == svm.BaseProductId && ((int?)ProductFaceContentTab.ProductGroupId ?? 0) != 0 group new { L } by new { L.BaseProductId } into Result select new { TotalQty = Result.Sum(i => i.L.Qty) }).FirstOrDefault(); var TotalOtherContents = (from L in db.BomDetail join P in db.Product on L.ProductId equals P.ProductId into ProductTable from ProductTab in ProductTable.DefaultIfEmpty() join pcon in ProductFaceContentGroups on ProductTab.ProductGroupId equals pcon.ProductGroupId into ProductFaceContentTable from ProductFaceContentTab in ProductFaceContentTable.DefaultIfEmpty() where L.BaseProductId == svm.BaseProductId && ((int?)ProductFaceContentTab.ProductGroupId ?? 0) == 0 group new { L } by new { L.BaseProductId } into Result select new { TotalQty = Result.Sum(i => i.L.Qty) }).FirstOrDefault(); if (TotalMainContents != null && svm.Weight != 0) { Decimal TotalMainContentPercentage = Math.Round(TotalMainContents.TotalQty * 100 / svm.Weight, 2); ViewBag.LastTransaction = TotalMainContentPercentage + "% Main Contents filled, " + (100 - TotalMainContentPercentage) + " remaining."; } if (TotalOtherContents != null && svm.Weight != 0) { Decimal TotalOtherContentPercentage = Math.Round(TotalOtherContents.TotalQty * 100 / svm.Weight, 2); ViewBag.LastTransaction = ViewBag.LastTransaction + (TotalOtherContentPercentage + "% Other Contents filled.").ToString(); } }
public JsonResult IsProductContent(int BaseProductId, int ProductId) { bool IsContent = true; var ProductFaceContentGroups = from p in db.Product join pg in db.ProductGroups on p.ReferenceDocId equals pg.ProductGroupId into ProductGroupTable from ProductGroupTab in ProductGroupTable.DefaultIfEmpty() join fp in db.FinishedProduct on ProductGroupTab.ProductGroupId equals fp.ProductGroupId into FinishedProductTable from FinishedProductTab in FinishedProductTable.DefaultIfEmpty() join pcl in db.ProductContentLine on FinishedProductTab.FaceContentId equals pcl.ProductContentHeaderId into ProductContentLineTable from ProductContentLineTab in ProductContentLineTable.DefaultIfEmpty() where p.ProductId == BaseProductId && ((int?)ProductContentLineTab.ProductGroupId ?? 0) != 0 group new { ProductContentLineTab } by new { ProductContentLineTab.ProductGroupId } into Result select new { ProductGroupId = Result.Key.ProductGroupId }; var temp = (from p in db.Product join pcon in ProductFaceContentGroups on p.ProductGroupId equals pcon.ProductGroupId into ProductFaceContentTable from ProductFaceContentTab in ProductFaceContentTable.DefaultIfEmpty() where p.ProductId == ProductId && ((int?)ProductFaceContentTab.ProductGroupId ?? 0) != 0 select new { ProductId = p.ProductId }).FirstOrDefault(); if (temp != null) { IsContent = true; } else { IsContent = false; } return(Json(IsContent)); }
public JsonResult GetConsumptionTotalQty(int BaseProductId, Decimal TotalWeight, Decimal BomQty, int BomDetailId, int BaseProcessId) { var ProductFaceContentGroups = from p in db.Product join pg in db.ProductGroups on p.ReferenceDocId equals pg.ProductGroupId into ProductGroupTable from ProductGroupTab in ProductGroupTable.DefaultIfEmpty() join fp in db.FinishedProduct on ProductGroupTab.ProductGroupId equals fp.ProductGroupId into FinishedProductTable from FinishedProductTab in FinishedProductTable.DefaultIfEmpty() join pcl in db.ProductContentLine on FinishedProductTab.FaceContentId equals pcl.ProductContentHeaderId into ProductContentLineTable from ProductContentLineTab in ProductContentLineTable.DefaultIfEmpty() where p.ProductId == BaseProductId && ((int?)ProductContentLineTab.ProductGroupId ?? 0) != 0 group new { ProductContentLineTab } by new { ProductContentLineTab.ProductGroupId } into Result select new { ProductGroupId = Result.Key.ProductGroupId }; Decimal TotalFillQty = 0; var temp = (from L in db.BomDetail join p in db.Product on L.ProductId equals p.ProductId into ProductTable from ProductTab in ProductTable.DefaultIfEmpty() join pcon in ProductFaceContentGroups on ProductTab.ProductGroupId equals pcon.ProductGroupId into ProductFaceContentTable from ProductFaceContentTab in ProductFaceContentTable.DefaultIfEmpty() where L.BaseProductId == BaseProductId && L.BomDetailId != BomDetailId && L.BaseProcessId == BaseProcessId && ((int?)ProductFaceContentTab.ProductGroupId ?? 0) != 0 group(L) by(L.BaseProductId) into Result select new { TotalQty = Result.Sum(i => i.Qty) }).FirstOrDefault(); if (temp != null) { TotalFillQty = temp.TotalQty; } return(Json(TotalFillQty)); }