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();
            }
        }
예제 #2
0
        public ProductGroupQuality GetProductGroupQuality(int ProductGroupId)
        {
            ProductGroupQuality p = (from fp in db.FinishedProduct
                                     join pg in db.ProductGroups on fp.ProductGroupId equals pg.ProductGroupId into ProductGroupTable
                                     from ProductGroupTab in ProductGroupTable.DefaultIfEmpty()
                                     join pq in db.ProductQuality on fp.ProductQualityId equals pq.ProductQualityId into ProductQualityTable
                                     from ProductQualityTab in ProductQualityTable.DefaultIfEmpty()
                                     where fp.ProductGroupId == ProductGroupId
                                     select new ProductGroupQuality
            {
                ProductGroupName = ProductGroupTab.ProductGroupName,
                ProductQualityName = ProductQualityTab.ProductQualityName,
                GrossWeight = fp.GrossWeight
            }).FirstOrDefault();

            return(p);
        }
        public IEnumerable <ProductTypeAttributeViewModel> GetAttributeForProduct(int id)
        {
            //int Typeid = new ProductTypeService(_unitOfWork).GetProductTypeByName(ProductTypeConstants.Rug).ProductTypeId;
            int Typeid = (from P in db.Product
                          join Pg in db.ProductGroups on P.ProductGroupId equals Pg.ProductGroupId into ProductGroupTable
                          from ProductGroupTab in ProductGroupTable.DefaultIfEmpty()
                          where P.ProductId == id
                          select new
            {
                ProductTypeId = ProductGroupTab.ProductTypeId
            }).FirstOrDefault().ProductTypeId;

            //var frn= from p in db.ProductTypeAttribute
            //      join t in db.ProductAttributes on p.ProductTypeAttributeId equals t.ProductTypeAttributeId into table
            //      from tab in table.DefaultIfEmpty()
            //      where (tab.ProductId == id || ((int?)tab.ProductId ?? 0) == 0) && (p.ProductType_ProductTypeId == Typeid)
            //      select new ProductTypeAttributeViewModel
            //      {
            //          ListItem=p.ListItem,
            //          DataType=p.DataType,
            //          DefaultValue = tab.ProductAttributeValue,
            //          Name = p.Name,
            //          ProductTypeAttributeId = p.ProductTypeAttributeId,
            //          ProductAttributeId = (int?)tab.ProductAttributeId ?? 0
            //      };


            var temp = from p in db.ProductTypeAttribute
                       join t in db.ProductAttributes on p.ProductTypeAttributeId equals t.ProductTypeAttributeId into table
                       from tab in table.Where(m => m.ProductId == id).DefaultIfEmpty()
                       where (p.ProductType_ProductTypeId == Typeid)
                       select new ProductTypeAttributeViewModel
            {
                ListItem               = p.ListItem,
                DataType               = p.DataType,
                DefaultValue           = tab.ProductAttributeValue,
                Name                   = p.Name,
                ProductTypeAttributeId = p.ProductTypeAttributeId,
                ProductAttributeId     = (int?)tab.ProductAttributeId ?? 0
            };

            return(temp);
        }
        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));
        }