private ProductionDetail IniEdit(ProductionDetail model)
        {
            model.MainMenu    = _mainMenu;
            model.CurrentMenu = PageInfo;

            var company = GlobalFunctions.GetCompanyList(_companyBll);

            if (CurrentUser.UserRole != Enums.UserRole.Administrator)
            {
                var userPlantCompany = _userPlantMapBll.GetCompanyByUserId(CurrentUser.USER_ID);
                var poaMapCompany    = _poaMapBll.GetCompanyByPoaId(CurrentUser.USER_ID);
                var distinctCompany  = company.Where(x => userPlantCompany.Contains(x.Value));
                if (CurrentUser.UserRole == Enums.UserRole.POA)
                {
                    distinctCompany = company.Where(x => poaMapCompany.Contains(x.Value));
                }
                var getCompany = new SelectList(distinctCompany, "Value", "Text");
                company = getCompany;
            }

            model.CompanyCodeList = company;
            model.PlantWerkList   = GlobalFunctions.GetPlantByCompanyId("");
            model.FacodeList      = GlobalFunctions.GetFaCodeByPlant("");
            model.UomList         = GlobalFunctions.GetUomStickGram(_uomBll);

            return(model);
        }
        //
        // GET: /Production/Edit
        public ActionResult Edit(string companyCode, string plantWerk, string faCode, DateTime productionDate)
        {
            if (CurrentUser.UserRole == Enums.UserRole.Viewer || CurrentUser.UserRole == Enums.UserRole.Controller)
            {
                return(RedirectToAction("Edit", "Production", new
                {
                    companyCode = companyCode,
                    plantWerk = plantWerk,
                    faCode = faCode,
                    productionDate = productionDate
                }));
            }

            var model = new ProductionDetail();

            var dbProduction = _productionBll.GetById(companyCode, plantWerk, faCode, productionDate);

            model = Mapper.Map <ProductionDetail>(dbProduction);
            model = IniEdit(model);
            model.CompanyCodeX    = model.CompanyCode;
            model.PlantWerksX     = model.PlantWerks;
            model.ProductionDateX = model.ProductionDate;
            model.FaCodeX         = model.FaCode;


            return(View(model));
        }
Exemple #3
0
        public async Task <ProductionDetail> getProductDetailsByProductDetailsIdAsync(string path)
        {
            ProductionDetail    productDetails = null;
            HttpResponseMessage response       = await client.GetAsync(path);

            if (response.IsSuccessStatusCode)
            {
                productDetails = await response.Content.ReadAsAsync <ProductionDetail>();
            }
            return(productDetails);
        }
        public JsonResult GetBrandCeByPlant(string plantWerk)
        {
            var listBrandCe = GlobalFunctions.GetFaCodeByPlant(plantWerk);

            var model = new ProductionDetail()
            {
                FacodeList = listBrandCe
            };

            return(Json(model));
        }
        private ProductionDetail InitDetail(ProductionDetail model)
        {
            model.MainMenu        = _mainMenu;
            model.CurrentMenu     = PageInfo;
            model.CompanyCodeList = GlobalFunctions.GetCompanyList(_companyBll);
            model.PlantWerkList   = GlobalFunctions.GetPlantAll();
            model.FacodeList      = GlobalFunctions.GetBrandList();
            model.UomList         = GlobalFunctions.GetUomStickGram(_uomBll);

            return(model);
        }
        public ActionResult ProductDetail(int id)
        {
            DBModelContainer db = new DBModelContainer();
            ProductionDetail pr = new ProductionDetail();

            pr.ProductId = id;

            var names = (from p in db.Products
                         join c in db.Categories on p.CategoryId equals c.CategoryId
                         where p.ProductId == id
                         select new { ProductName = p.Name,
                                      CategoryName = c.Name }).FirstOrDefault();

            pr.Title = names.CategoryName + " > " + names.ProductName;

            pr.listdata = (from p in db.ProductDetails
                           join production in db.Products on p.ProductId equals production.ProductId
                           where p.ProductId == id
                           select new ProductionDetail()
            {
                Color = p.Color,
                Description = production.Description,
                Price = p.Price,
                Size = p.Size,
                Amount = p.Amount,
                Picture = p.Picture,
                ProductDetailsId = p.ProductDetailsId,
                ProductId = p.ProductId,
                ProductionName = production.Name
            }).ToList();

            // return View(productionDetail.FirstOrDefault());
            pr.reviewListData = (from r in db.Reviews
                                 join p in db.Products on r.ProductId equals p.ProductId
                                 join u in db.Users on r.UserId equals u.UserId
                                 where p.ProductId == id
                                 select new ReviewProduction()
            {
                ProductId = r.ProductId,

                Title = r.Title,
                Content = r.Content,
                OverallRating = r.OverallRating,

                ReviewId = r.ReviewId,
                UserId = r.UserId,
                UserName = u.UserName,
                ReviewDate = r.ReviewDate
            }).ToList();

            return(View(pr));
        }
        //
        // GET: /Production/Create
        public ActionResult Create()
        {
            if (CurrentUser.UserRole == Enums.UserRole.Viewer || CurrentUser.UserRole == Enums.UserRole.Administrator || CurrentUser.UserRole == Enums.UserRole.Controller)
            {
                AddMessageInfo("Operation not allow", Enums.MessageInfoType.Error);
                return(RedirectToAction("Index"));
            }

            var model = new ProductionDetail();

            model = InitCreate(model);
            model.ProductionDate = DateTime.Today.ToString("dd MMM yyyy");

            return(View(model));
        }
        //
        // GET: /Production/Detail
        public ActionResult Detail(string companyCode, string plantWerk, string faCode, DateTime productionDate)
        {
            var model = new ProductionDetail();

            var dbProduction = _productionBll.GetById(companyCode, plantWerk, faCode, productionDate);

            model = Mapper.Map <ProductionDetail>(dbProduction);

            model.ChangesHistoryList =
                Mapper.Map <List <ChangesHistoryItemModel> >(_changeHistoryBll.GetByFormTypeAndFormId(Enums.MenuList.CK4C,
                                                                                                      "Daily_" + companyCode + "_" + plantWerk + "_" + faCode + "_" + productionDate.ToString("ddMMMyyyy")));

            model = InitDetail(model);

            return(View(model));
        }
        public async Task <ActionResult> ProductDetail(int id)
        {
            DBModelContainer db = new DBModelContainer();
            ProductionDetail pr = new ProductionDetail();

            pr.ProductId = id;

            // get product title equal to CategoryName + " > " + names.ProductName;
            ProductionService service = new ProductionService();

            pr.Title = (await service.getProductTitleByProductId(id)).Title;

            /*{
             *  Color,
             *  Description,
             *  Price,
             *  Size,
             *  Amount,
             *  Picture,
             *  ProductDetailsId,
             *  ProductId,
             *  ProductionName
             * }*/
            // get all productDetails by a given product
            pr.listdata = await service.getProductDetailsByProductId(id);

            /*{
             *  ProductId,
             *
             *  Title,
             *  Content,
             *  OverallRating,
             *
             *  ReviewId,
             *  UserId,
             *  UserName,
             *  ReviewDate
             * }*/
            // get all reviews about a given product
            pr.reviewListData = await service.getReviewsByProductId(id);

            return(View(pr));
        }
        public JsonResult CompanyListPartialProduction(string companyId)
        {
            var listPlant = GlobalFunctions.GetPlantByCompanyId(companyId);

            var filterPlant = listPlant;

            var newListPlant = new SelectList(filterPlant, "Value", "Text");

            if (CurrentUser.UserRole != Enums.UserRole.Administrator)
            {
                var newFilterPlant = listPlant.Where(x => CurrentUser.ListUserPlants.Contains(x.Value));

                newListPlant = new SelectList(newFilterPlant, "Value", "Text");
            }

            var model = new ProductionDetail()
            {
                PlantWerkList = newListPlant
            };

            return(Json(model));
        }
Exemple #11
0
        // Get
        public async Task <ActionResult> Index()
        {
            ShoppingService   service        = new ShoppingService();
            ProductionService productService = new ProductionService();
            ShoppingCart      shoppingCart   = new ShoppingCart();

            if (FormsAuth.UserManager.User != null)
            {
                /*{
                 *  Amount,
                 *  CartId,
                 *  Type,
                 *  CartDetailsId,
                 *  ExtendedPrice,
                 *  ProductDetailsId,
                 *  Price,
                 *  Picture,
                 *  ProductName,
                 *  ProductID,
                 *  Color,
                 *  UserId,
                 *  TotalAmountProduction
                 * }*/
                // get all shopping cart items of current user
                shoppingCart.listItemCart = await service.getCartItemsByUserId(UserManager.User.Id);
            }
            else  // get from Cookie
            {
                HttpCookie reqCookies;
                HttpCookie reqIDListCookies = Request.Cookies["ProductDetailIDlist"];
                if (reqIDListCookies != null)
                {
                    string dataAsString = reqIDListCookies.Value;
                    if (!dataAsString.Equals(string.Empty))
                    {
                        List <int>      listdata     = new List <int>();
                        List <CartItem> listCartItem = new List <CartItem>();

                        listdata = dataAsString.Split(',').Select(x => Convert.ToInt32(x)).ToList();
                        for (int i = 0; i < listdata.Count(); i++)
                        {
                            CartItem item = new CartItem();
                            item.ProductDetailsId = listdata[i];

                            reqCookies = Request.Cookies["CartItems[" + item.ProductDetailsId.ToString() + "]"];
                            if (reqCookies != null)
                            {
                                CartItem cookiesItem = new JavaScriptSerializer().Deserialize <CartItem>(reqCookies.Value);

                                item.Amount = cookiesItem.Amount;
                                item.Price  = cookiesItem.Price;

                                listCartItem.Add(item);
                            }
                        }

                        //
                        if (listCartItem.Count() > 0)
                        {
                            List <CartDetailItem> cartDetailItemList = new List <CartDetailItem>();

                            // for each cookies item
                            foreach (CartItem cookiesItem in listCartItem)
                            {
                                CartDetailItem cartDetailItem = new CartDetailItem();

                                // get more information from product & productDetails tables in Database
                                ProductionDetail productDetail = await productService.getProductDetailByProductDetailsIds(cookiesItem.ProductDetailsId);

                                Production product = await productService.getProductionByProductDetailsId(cookiesItem.ProductDetailsId);

                                cartDetailItem.ProductDetailsId      = cookiesItem.ProductDetailsId;
                                cartDetailItem.Price                 = productDetail.Price;
                                cartDetailItem.Picture               = productDetail.Picture;
                                cartDetailItem.Color                 = productDetail.Color;
                                cartDetailItem.TotalAmountProduction = productDetail.Amount;
                                cartDetailItem.Amount                = cookiesItem.Amount;
                                cartDetailItem.ExtendedPrice         = cookiesItem.Price;
                                cartDetailItem.CartId                = 0;
                                cartDetailItem.Type          = 0;
                                cartDetailItem.CartDetailsId = 0;
                                cartDetailItem.ProductID     = product.ProductId;
                                cartDetailItem.ProductName   = product.ProductionName;
                                cartDetailItem.UserId        = 0;

                                cartDetailItemList.Add(cartDetailItem);
                            }

                            shoppingCart.listItemCart = cartDetailItemList;
                        }
                    }
                }
            }

            return(View(shoppingCart));
        }
Exemple #12
0
 /// <summary>
 /// 取得庫存
 /// </summary>
 /// <returns></returns>
 public List <Item> GetStorage(BrandEnum brand, FlavorEnum flavor, PackageEnum package, ProductionType productionType, ProductionDetail productionDetailType)
 {
     return(_stockService.GetStorage(brand, flavor, package, productionType, productionDetailType));
 }
Exemple #13
0
 public List <Item> GetItems(BrandEnum brand, FlavorEnum flavor, ProductionType type, ProductionDetail detail)
 {
     throw new NotImplementedException();
 }
        private void Extract(Guid srcPackID, string productCode, int productionID, bool isAllowPos)
        {
            if (productionID <= 0)
                throw new Exception("Production null");

            PackBLL bll = new PackBLL();

            Pack pack = bll.Get4Extract(srcPackID, isAllowPos);

            var newP = PackBLL.Add(pack.DIN, productCode, pack);

            if (pack.Status != Pack.StatusX.Produced)
                PackBLL.ChangeStatus(pack.ID, Pack.StatusX.Produced, PackTransaction.TypeX.Out_Product);

            var pDetail = new ProductionDetail()
            {
                ProductionID = productionID,
                FromPackID = pack.ID,
                ToPackID = newP.ID,
            };
            Add(pDetail);
        }
        private void Divide(Guid srcPackID, string division, int volume, int productionID)
        {
            PackBLL bll = new PackBLL();

            Pack pack = bll.Get4Extract(srcPackID);

            string newProductCode = pack.ProductCode.Substring(0, pack.ProductCode.Length - 2) + division;

            var newP = PackBLL.Add(pack.DIN, newProductCode, volume, orgPack: pack);

            if (pack.Status != Pack.StatusX.Produced)
                PackBLL.ChangeStatus(pack.ID, Pack.StatusX.Produced, PackTransaction.TypeX.Out_Product);

            var pDetail = new ProductionDetail()
            {
                ProductionID = productionID,
                FromPackID = pack.ID,
                ToPackID = newP.ID,
            };
            Add(pDetail);
        }
        public ActionResult Edit(ProductionDetail model)
        {
            var dbProduction = _productionBll.GetById(model.CompanyCodeX, model.PlantWerksX, model.FaCodeX,
                                                      Convert.ToDateTime(model.ProductionDateX));

            try
            {
                if (dbProduction == null)
                {
                    ModelState.AddModelError("Production", "Data is not Found");
                    model = IniEdit(model);

                    return(View("Edit", model));
                }

                var param = new MonthClosingGetByParam();
                param.ClosingDate = Convert.ToDateTime(model.ProductionDate);
                param.PlantId     = model.PlantWerks;
                param.DisplayDate = null;

                var monthClosingdata = _monthClosingBll.GetDataByParam(param);
                if (monthClosingdata != null)
                {
                    AddMessageInfo("Please check closing date.", Enums.MessageInfoType.Warning);
                    model                = IniEdit(model);
                    model.CompanyCode    = model.CompanyCode;
                    model.PlantWerks     = model.PlantWerks;
                    model.FaCode         = model.FaCode;
                    model.ProductionDate = model.ProductionDate;
                    return(View("Edit", model));
                }

                if (model.CompanyCode != model.CompanyCodeX || model.PlantWerks != model.PlantWerksX ||
                    model.FaCode != model.FaCodeX || Convert.ToDateTime(model.ProductionDate) != Convert.ToDateTime(model.ProductionDateX))
                {
                    var existingData = _productionBll.GetExistDto(model.CompanyCode, model.PlantWerks, model.FaCode,
                                                                  Convert.ToDateTime(model.ProductionDate));
                    if (existingData != null)
                    {
                        AddMessageInfo("Data Already Exist", Enums.MessageInfoType.Warning);
                        return(RedirectToAction("Edit", "Production", new
                        {
                            companyCode = model.CompanyCode,
                            plantWerk = model.PlantWerks,
                            faCode = model.FaCode,
                            productionDate = model.ProductionDate
                        }));
                    }
                    else
                    {
                        model.QtyPacked       = 0;
                        model.ProdQtyStick    = 0;
                        model.QtyPackedStr    = "0";
                        model.ProdQtyStickStr = "0";
                        model.Zb                = 0;
                        model.ZbStr             = "0";
                        model.PackedAdjusted    = 0;
                        model.PackedAdjustedStr = "0";
                    }
                }

                //if (model.PackedAdjustedStr != "" && model.PackedAdjustedStr != null && model.QtyPackedStr != "" && model.QtyPackedStr != null)
                //{
                //    if (decimal.Parse(model.PackedAdjustedStr) > decimal.Parse(model.QtyPackedStr))
                //    {
                //        AddMessageInfo("Packed-Adjusted value can't be greater than Qty Packed", Enums.MessageInfoType.Warning);
                //        return RedirectToAction("Edit", "Production", new
                //        {
                //            companyCode = model.CompanyCode,
                //            plantWerk = model.PlantWerks,
                //            faCode = model.FaCode,
                //            productionDate = model.ProductionDate
                //        });
                //    }
                //}

                var dbPrductionNew = Mapper.Map <ProductionDto>(model);

                if (!ModelState.IsValid)
                {
                    var error = ModelState.Values.Where(c => c.Errors.Count > 0).ToList();
                    if (error.Count > 0)
                    {
                        //
                    }
                }

                var output  = _productionBll.Save(dbPrductionNew, CurrentUser.USER_ID);
                var message = Constans.SubmitMessage.Updated;

                if (output.isNewData)
                {
                    message = Constans.SubmitMessage.Saved;
                }

                if (!output.isFromSap)
                {
                    if (model.CompanyCode != model.CompanyCodeX || model.PlantWerks != model.PlantWerksX || model.FaCode != model.FaCodeX ||
                        Convert.ToDateTime(model.ProductionDate) != Convert.ToDateTime(model.ProductionDateX))
                    {
                        MoveOldChangeLogHistory(dbPrductionNew);
                        _productionBll.DeleteOldData(model.CompanyCodeX, model.PlantWerksX, model.FaCodeX, Convert.ToDateTime(model.ProductionDateX));
                    }
                }

                AddMessageInfo(message, Enums.MessageInfoType.Success);

                return(RedirectToAction("Index"));
            }
            catch (Exception exception)
            {
                AddMessageInfo(exception.Message, Enums.MessageInfoType.Error);
            }

            model = IniEdit(model);

            return(View("Edit", model));
        }
        public ActionResult Create(ProductionDetail model)
        {
            if (ModelState.IsValid)
            {
                var param = new MonthClosingGetByParam();
                param.ClosingDate = Convert.ToDateTime(model.ProductionDate);
                param.PlantId     = model.PlantWerks;
                param.DisplayDate = null;

                var monthClosingdata = _monthClosingBll.GetDataByParam(param);
                if (monthClosingdata != null)
                {
                    AddMessageInfo("Please check closing date.", Enums.MessageInfoType.Warning);
                    model                = InitCreate(model);
                    model.CompanyCode    = model.CompanyCode;
                    model.PlantWerks     = model.PlantWerks;
                    model.FaCode         = model.FaCode;
                    model.ProductionDate = model.ProductionDate;
                    return(View(model));
                }

                var existingData = _productionBll.GetExistDto(model.CompanyCode, model.PlantWerks, model.FaCode,
                                                              Convert.ToDateTime(model.ProductionDate));
                if (existingData != null)
                {
                    AddMessageInfo("Data Already Exist", Enums.MessageInfoType.Warning);
                    return(RedirectToAction("Edit", "Production", new
                    {
                        companyCode = model.CompanyCode,
                        plantWerk = model.PlantWerks,
                        faCode = model.FaCode,
                        productionDate = model.ProductionDate
                    }));
                }

                //if(model.PackedAdjusted > model.QtyPacked){
                //    AddMessageInfo("Packed-Adjusted value can't be greater than Qty Packed", Enums.MessageInfoType.Warning);
                //    return RedirectToAction("Edit", "Production", new
                //    {
                //        companyCode = model.CompanyCode,
                //        plantWerk = model.PlantWerks,
                //        faCode = model.FaCode,
                //        productionDate = model.ProductionDate
                //    });
                //}

                var data = Mapper.Map <ProductionDto>(model);

                try
                {
                    _productionBll.Save(data, CurrentUser.USER_ID);

                    AddMessageInfo(Constans.SubmitMessage.Saved, Enums.MessageInfoType.Success
                                   );
                    return(RedirectToAction("Index"));
                }
                catch (Exception exception)
                {
                    AddMessageInfo(exception.Message, Enums.MessageInfoType.Error
                                   );
                }
            }
            else
            {
                var errorlist = ModelState.Values.Select(x => x.Errors).ToList();

                var errMsg = "";

                foreach (var error in errorlist)
                {
                    foreach (var err in error)
                    {
                        errMsg = err.ErrorMessage + "\n";
                    }
                }
                AddMessageInfo(errMsg, Enums.MessageInfoType.Error);
            }
            model = InitCreate(model);
            return(View(model));
        }
        public Expression <Func <ItemEntity, bool> > GetItemExp(BrandEnum brand, FlavorEnum flavor, PackageEnum package, ProductionType productionType, ProductionDetail productionDetailType)
        {
            Expression <Func <ItemEntity, bool> > itemWhere = c => true;

            if (brand != BrandEnum.Null)
            {
                var prefix = itemWhere.Compile();
                itemWhere = c => prefix(c) && c.Brand == (int)brand;
            }
            if (flavor != FlavorEnum.Null)
            {
                var prefix = itemWhere.Compile();
                itemWhere = c => prefix(c) && c.Flavor == (int)flavor;
            }
            if (package != PackageEnum.Null)
            {
                var prefix = itemWhere.Compile();
                itemWhere = c => prefix(c) && c.Package == (int)package;
            }
            if (productionType != ProductionType.Null)
            {
                var prefix = itemWhere.Compile();
                itemWhere = c => prefix(c) && c.ProductionType == (int)productionType;
            }
            if (productionDetailType != ProductionDetail.Null)
            {
                var prefix = itemWhere.Compile();
                itemWhere = c => prefix(c) && c.ProductionDetailType == (int)productionDetailType;
            }

            return(itemWhere);
        }
 private ProductionDetail Add(ProductionDetail detail)
 {
     RedBloodDataContext db = new RedBloodDataContext();
     db.ProductionDetails.InsertOnSubmit(detail);
     db.SubmitChanges();
     return detail;
 }