private void initializeProducedStock(Company company, IProductRepository productRepository) { ProductTypeEnum producedProduct = (ProductTypeEnum)company.ProductID; var producedProductEntity = company.Entity.GetEquipmentItem(producedProduct, company.Quality, productRepository); Stock = new ProductStockViewModel(company, producedProductEntity); }
public IActionResult ProductStockViewModel([FromQuery] string name = "") { List <ProductStockViewModel> lstData = new List <ProductStockViewModel>(); using (var command = _context.Database.GetDbConnection().CreateCommand()) { if (name == "") { command.CommandText = "SELECT p.ProductID as ProductID, p.ProductName as ProductName, ps.Quantity from ProductModel p inner join StockModel ps on p.ProductID=ps.ProductId"; } else { command.CommandText = "SELECT p.ProductID as ProductID, p.ProductName as ProductName, ps.Quantity from ProductModel p inner join StockModel ps on p.ProductID=ps.ProductId where p.ProductName LIKE '%" + name + "%'"; } _context.Database.OpenConnection(); using (var result = command.ExecuteReader()) { ProductStockViewModel data; while (result.Read()) { data = new ProductStockViewModel(); data.ProductID = result.GetInt32(0); data.ProductName = result.GetString(1); data.Quantity = result.GetInt32(2); lstData.Add(data); } } return(View(lstData.OrderBy(x => x.ProductName))); } }
public async Task <IActionResult> AddEditProductStock(int id, ProductStockViewModel model) { if (!ModelState.IsValid) { ModelState.AddModelError("", "Opps something wrong"); return(View(model)); } if (id > 0) { ProductStock productStock = await _unitOfWork.Repository <ProductStock>().GetByIdAsync(id); productStock.InQuantity = model.InQuantity; productStock.OutQuantity = model.OutQuantity; productStock.ModifiedDate = DateTime.Now; productStock.ProductId = model.ProductId; productStock.Remarks = model.Remarks; await _unitOfWork.Repository <ProductStock>().UpdateAsync(productStock); } else { ProductStock productStock = new ProductStock { InQuantity = model.InQuantity, OutQuantity = model.OutQuantity, AddedDate = DateTime.Now, ModifiedDate = DateTime.Now, ProductId = model.ProductId, Remarks = model.Remarks }; await _unitOfWork.Repository <ProductStock>().InsertAsync(productStock); } return(RedirectToAction(nameof(AddEditProductStock))); }
public IActionResult StockListReport([FromQuery] string SelectedProduct = "") { List <ProductStockViewModel> lstData = new List <ProductStockViewModel>(); using (var command = _context.Database.GetDbConnection().CreateCommand()) { if (SelectedProduct == "") { command.CommandText = "SELECT p.Id as ProductId,p.ProductName as ProductName,ps.Quantity from Product p inner join ProductStock ps on p.Id=ps.ProductId"; } else { command.CommandText = "SELECT p.Id as ProductId,p.ProductName as ProductName,ps.Quantity from Product p inner join ProductStock ps on p.Id=ps.ProductId WHERE p.Id=" + SelectedProduct; } _context.Database.OpenConnection(); using (var result = command.ExecuteReader()) { ProductStockViewModel data; while (result.Read()) { data = new ProductStockViewModel(); data.ProductId = result.GetInt32(0); data.ProductName = result.GetString(1); data.Quantity = result.GetInt32(2); lstData.Add(data); } } } return(View(lstData)); }
// GET: CenterProducts public ActionResult Details(int id) { CenterProductStockViewModel stockvm = new CenterProductStockViewModel(); stockvm.ProductStockViewModels = new List <ProductStockViewModel>(); stockvm.CenterId = id; Usuario usuario = db.Usuarios.Find(SessionHelper.GetUser()); ViewBag.Title = "Stock del Centro " + usuario.Center?.Descripcion; ViewBag.isAdmin = usuario.Rol.IsAdmin; List <Product> products = db.Products.Where(p => p.Enable).ToList(); List <CenterProduct> centerProducts = db.CenterProducts.Where(x => x.CenterId == id).ToList(); foreach (var item in products) { ProductStockViewModel productStockViewModel = new ProductStockViewModel(); CenterProduct centerProduct = centerProducts.Where(x => x.ProductId == item.Id).FirstOrDefault(); if (centerProducts.Any(x => x.ProductId == item.Id)) { productStockViewModel.Stock = centerProduct.Stock; } else { productStockViewModel.Stock = 0; } productStockViewModel.ProductId = item.Id; productStockViewModel.Product = item; stockvm.ProductStockViewModels.Add(productStockViewModel); } return(View(stockvm)); }
public async Task <IActionResult> AddEditProductStock(int id) { try { ProductStockViewModel model = new ProductStockViewModel(); ViewBag.Colors = _unitOfWork.Repository <Colors>().GetAll(); ViewBag.Sizes = _unitOfWork.Repository <ProductSize>().GetAll(); if (id > 0) { ProductStock productStock = await _unitOfWork.Repository <ProductStock>().GetSingleIncludeAsync(x => x.Id == id); model.Id = productStock.Id; model.InQuantity = productStock.InQuantity; model.MinQuantity = productStock.MinQuantity; model.ProductId = productStock.ProductId; model.SizeId = productStock.SizeId; model.ColorId = productStock.ColorId; model.IsActive = productStock.IsActive; model.HaveStock = productStock.HaveStock; } return(PartialView("~/Views/ProductStock/AddEditProductStock.cshtml", model)); } catch (Exception ex) { throw; } }
public List <ProductStockViewModel> GetProductsStock() { try { List <ProductStockViewModel> productList = new List <ProductStockViewModel>(); _unitOfWork.Repository <ProductStock>().GetAllInclude(p => p.Product, c => c.Colors, s => s.ProductSize).ToList().ForEach(x => { ProductStockViewModel product = new ProductStockViewModel { Id = x.Id, ModifiedDate = x.ModifiedDate, AddedDate = x.AddedDate, InQuantity = x.InQuantity, ProductName = x.Product.Name, Size = x.ProductSize.Size, MinQuantity = x.MinQuantity, Color = x.Colors.Color, IsActive = x.IsActive, HaveStock = x.HaveStock, IamgeProduct = x.Product.ImagePath, }; productList.Add(product); }); return(productList); } catch (Exception ex) { throw; } }
/* * Question No. 5 Solution */ public IActionResult StockListSearchReport(String SearchBy) { List <String> ProductNames = new List <string>(); List <ProductStockViewModel> lstData = new List <ProductStockViewModel>(); using (var command = _context.Database.GetDbConnection().CreateCommand()) { command.CommandText = "SELECT p.ProdId, p.ProdName, ps.Quantity FROM Product p INNER JOIN Stock ps ON p.ProdId = ps.ProdId"; _context.Database.OpenConnection(); using (var result = command.ExecuteReader()) { ProductStockViewModel data; while (result.Read()) { data = new ProductStockViewModel(); data.ProdId = result.GetInt32(0); data.ProdName = result.GetString(1); data.Quantity = result.GetInt32(2); lstData.Add(data); ProductNames.Add(data.ProdName.ToString()); } } } ViewData["ProductNames"] = ProductNames; return(View(lstData.Where(x => SearchBy != null && x.ProdName.ToLower().Contains(SearchBy.ToLower())))); }
public ActionResult Edit(ProductStockViewModel form) { ProductStock ps = _productstockRepository.GetById(form.StockID); ps.StockQTY = ps.StockQTY + form.AddQTY; _productstockRepository.Update(ps); return(RedirectToAction("Index", "ProductStock", new { area = "SK_AREA", page = TempData["page7"] })); }
public async Task <IActionResult> AddEditProductStock(int id) { ProductStockViewModel model = new ProductStockViewModel(); if (id > 0) { ProductStock productStock = await _unitOfWork.Repository <ProductStock>().GetSingleIncludeAsync(x => x.Id == id, p => p.Product); model.Id = productStock.Id; model.InQuantity = productStock.InQuantity; model.OutQuantity = productStock.OutQuantity; model.ProductId = productStock.ProductId; model.Remarks = productStock.Remarks; model.ProductName = productStock.Product.Name; } return(View(model)); }
public IActionResult StockListReport([FromQuery] string productname) { List <ProductStockViewModel> lstData = new List <ProductStockViewModel>(); if (string.IsNullOrEmpty(productname)) { using (var command = _context.Database.GetDbConnection().CreateCommand()) { command.CommandText = "SELECT p.ProductId as ProductId,Name as ProductName,Quantity from Product p inner join Stock ps on ps.StockId=p.ProductId"; _context.Database.OpenConnection(); using (var result = command.ExecuteReader()) { ProductStockViewModel data; while (result.Read()) { data = new ProductStockViewModel(); data.ProductId = result.GetInt32(0); data.ProductName = result.GetString(1); data.Quantity = result.GetInt32(2); lstData.Add(data); } } } } else { using (var command = _context.Database.GetDbConnection().CreateCommand()) { command.CommandText = "SELECT p.ProductId as ProductId,Name as ProductName,Quantity from Product p inner join Stock ps on ps.StockId=p.ProductId where Name='" + productname + "'"; _context.Database.OpenConnection(); using (var result = command.ExecuteReader()) { ProductStockViewModel data; while (result.Read()) { data = new ProductStockViewModel(); data.ProductId = result.GetInt32(0); data.ProductName = result.GetString(1); data.Quantity = result.GetInt32(2); lstData.Add(data); } } } } return(View(lstData)); }
public ActionResult Stock(int id) { var locationsList = db.Locations .Include(l => l.Stocks) .ToList(); var locations = new List <StockLocation>(); foreach (var location in locationsList) { var stock = location .Stocks .FirstOrDefault(s => s.LocationId == location.Id && s.ProductId == id); var sl = new StockLocation() { Location = location, Stock = stock == null ? 0 : stock.StockQuantity }; locations.Add(sl); } var model = new ProductStockViewModel() { Product = db.Products.FirstOrDefault(p => p.Id == id), Location = db.Locations.FirstOrDefault(), Locations = locations, Stock = 0 }; if (db.Stocks.Any(s => s.ProductId == model.Product.Id && s.LocationId == model.Location.Id)) { model.Stock = db.Stocks .FirstOrDefault(s => s.ProductId == model.Product.Id && s.LocationId == model.Location.Id) .StockQuantity; } return(View(model)); }
public ActionResult Stock(int?prodId, int?storeId) { if (prodId == null || storeId == null) { return(RedirectToAction("Index", controllerName: "Store")); } TempData["prodId"] = prodId; TempData["storeId"] = storeId; var oldStock = db.Stocks.FirstOrDefault(m => m.ProductId == prodId && m.StoreId == storeId); var prod = db.Products.FirstOrDefault(m => m.Id == prodId); var store = db.Stores.FirstOrDefault(m => m.Id == storeId); var model = new ProductStockViewModel { Product = prod, MaxPerUser = 10, GST = prod.DefaultGST, CurrencyType = store.DefaultCurrencyType }; if (oldStock != null) { model.Price = oldStock.Price; model.Stock = oldStock.CurrentStock; model.MaxPerUser = oldStock.MaxAmtPerUser; model.GST = oldStock.GST; model.CurrencyType = oldStock.CurrencyType ?? store.DefaultCurrencyType; } if (model.Product == null) { return(RedirectToAction("Index", controllerName: "Store")); } return(View(model)); }
/* * Question No. 6 Solution */ public IActionResult StockListItemReport(String SearchBy) { List <ProductStockViewModel> lstData = new List <ProductStockViewModel>(); using (var command = _context.Database.GetDbConnection().CreateCommand()) { command.CommandText = "SELECT p.ProdId, p.ProdName, ps.Quantity FROM Product p INNER JOIN Stock ps ON p.ProdId = ps.ProdId"; _context.Database.OpenConnection(); using (var result = command.ExecuteReader()) { ProductStockViewModel data; while (result.Read()) { data = new ProductStockViewModel(); data.ProdId = result.GetInt32(0); data.ProdName = result.GetString(1); data.Quantity = result.GetInt32(2); lstData.Add(data); } } } return(View(lstData.Where(x => x.ProdName == SearchBy))); }
public ActionResult Edit(int id = 0) { ProductStockViewModel _PSVM = new ProductStockViewModel(); var getidstockqty = _productstockRepository.GetById(id); //ProductID _PSVM.ProductID = getidstockqty.ProductID; //ProductName var pn = _productRepository.GetById(getidstockqty.ProductID); var pn2 = pn.ProductName; _PSVM.ProductName = pn2; //ColorName var tempcolor = db.ProductColors.Join(db.Colors, PC => PC.ColorID, C => C.ColorID, (PC, C) => new { ColorName = C.ColorName, ColorID = C.ColorID, ProductID = PC.ProductID, ProductColorID = PC.ProductColorID, }); var tempcolor2 = tempcolor.Where(PC => PC.ProductColorID == getidstockqty.ProductColorID).Select(C => C.ColorName); _PSVM.ColorName = tempcolor2.First(); Debug.WriteLine("_PSVM.ColorName =" + _PSVM.ColorName); //SizeName var tempsize = db.ProductSizes.Join(db.Sizes, PS => PS.SizeID, S => S.SizeID, (PS, S) => new { SizeName = S.SizeName, SizeID = S.SizeID, ProductID = PS.ProductID, ProductSizeID = PS.ProductSizeID, }); var tempsize2 = tempsize.Where(S => S.ProductSizeID == getidstockqty.ProductSizeID).Select(S => S.SizeName); _PSVM.SizeName = tempsize2.First(); Debug.WriteLine("_PSVM.SizeName =" + _PSVM.SizeName); //StockID _PSVM.StockID = getidstockqty.StockID; //StockQTY _PSVM.StockQTY = getidstockqty.StockQTY; //MinStock _PSVM.MinStock = getidstockqty.MinStock; //SuppilerName var ts = _productRepository.GetById(getidstockqty.ProductID); var ts2 = ts.SupplierID; var ts3 = _supplierRepository.GetById(ts2).SupplierName; _PSVM.SupplierName = ts3; Debug.WriteLine("_PSVM.SupplierName =" + _PSVM.SupplierName); //訂購數量欄位 _PSVM.OrderQTY = db.OrderDetails .Where(x => x.ProductID == getidstockqty.ProductID && x.ProductColorID == getidstockqty.ProductColorID && x.ProductSizeID == getidstockqty.ProductSizeID && x.OrderHeader.OrderStatusID == 1).Select(x => x.OrderQTY).Count(); //購物車訂購數量 _PSVM.CartQTY = db.Carts.Where(x => x.ProductID == getidstockqty.ProductID && x.ProductColorID == getidstockqty.ProductColorID && x.ProductSizeID == getidstockqty.ProductSizeID).Select(x => x.Quantity).Count(); //需補貨數量 _PSVM.AddQTY = _PSVM.CartQTY + _PSVM.OrderQTY + _PSVM.MinStock - _PSVM.StockQTY; return(View(_PSVM)); }
public JsonResult AddEditProductStock(int id, ProductStockViewModel model) { try { if (!ModelState.IsValid) { ModelState.AddModelError("", "Opps something wrong"); var result = new { Result = "Erro", Error = true, Id = 0 }; return(Json(result)); } if (id > 0) { ProductStock productStock = _unitOfWork.Repository <ProductStock>().GetById(id); productStock.InQuantity = model.InQuantity; productStock.MinQuantity = model.MinQuantity; productStock.ProductId = model.ProductId; productStock.SizeId = model.SizeId; productStock.ColorId = model.ColorId; productStock.IsActive = model.IsActive; if (model.InQuantity > model.MinQuantity) { productStock.HaveStock = true; } else { productStock.HaveStock = false; } _unitOfWork.Repository <ProductStock>().Update(productStock); var result = new { Result = "Stock Atualizado com sucesso", Error = false, Id = productStock.Id }; return(Json(result)); } else { if (_unitOfWork.Repository <ProductStock>().FindAll(x => x.ProductId == model.ProductId && x.ColorId == model.ColorId && x.SizeId == model.SizeId).Count() == 0) { ProductStock productStock = new ProductStock { InQuantity = model.InQuantity, MinQuantity = model.MinQuantity, ProductId = model.ProductId, SizeId = model.SizeId, ColorId = model.ColorId, IsActive = true, }; if (model.InQuantity > model.MinQuantity) { productStock.HaveStock = true; } else { productStock.HaveStock = false; } _unitOfWork.Repository <ProductStock>().Insert(productStock); var result = new { Result = "Stock Atualizado com sucesso", Error = false, Id = productStock.Id }; return(Json(result)); } else { var result = new { Result = "Erro: Já existe um Produto para a cor e tamanho selecionado", Error = true, Id = 0 }; return(Json(result)); } } } catch (Exception ex) { throw; } }
public ActionResult Stock(ProductStockViewModel model) { int?prodId = TempData["prodId"] as int?; int?storeId = TempData["storeId"] as int?; if (prodId == null || storeId == null) { return(RedirectToAction("Index", controllerName: "Store")); } var oldStock = db.Stocks .FirstOrDefault(m => m.ProductId == prodId && m.StoreId == storeId); if (model.Price <= 0 || Convert.ToString(model.Price) == string.Empty) { ModelState.AddModelError("Price", "Price can't be empty or less than 0"); } if (ModelState.IsValid) { if (model.Stock <= 0) { model.Status = StockStatus.OutOfStock; } else { model.Status = StockStatus.InStock; } if (oldStock is null) { var stock = db.Stocks.Add( new Stock { CurrentStock = model.Stock, Price = model.Price, ProductId = (int)prodId, StoreId = (int)storeId, StockingDate = DateTime.Now, Status = model.Status, MaxAmtPerUser = model.MaxPerUser, GST = model.GST } ); } else { oldStock.CurrentStock = model.Stock; oldStock.Price = model.Price; oldStock.Status = model.Status; oldStock.MaxAmtPerUser = model.MaxPerUser; oldStock.GST = model.GST; db.Entry(oldStock).State = EntityState.Modified; } db.SaveChanges(); return(RedirectToAction("Index", controllerName: "Store")); } TempData["prodId"] = prodId; TempData["storeId"] = storeId; var stock_2 = db.Stocks .Include(m => m.Product) .Include(m => m.Store) .FirstOrDefault(m => m.Id == model.Stock); model = new ProductStockViewModel { Stock = stock_2.Id, Price = stock_2.Price, MaxPerUser = stock_2.MaxAmtPerUser, Product = stock_2.Product, CurrencyType = stock_2.Store.DefaultCurrencyType }; return(View(model)); }
// GET: SK_AREA/ProductStock public ActionResult Index(int?page) { if (HttpContext.Request.Cookies["IsLogin"].Value == "Admin") { TempData["page7"] = page ?? 1; var productstockModel = _productstockRepository.GetAll(); List <ProductStockViewModel> _ListPSVM = new List <ProductStockViewModel>(); foreach (var beta in productstockModel) { ProductStockViewModel _PSVM = new ProductStockViewModel(); //ProductID _PSVM.ProductID = beta.ProductID; //ProductName var pn = _productRepository.GetById(beta.ProductID); var pn2 = pn.ProductName; _PSVM.ProductName = pn2; //ColorName var tempcolor = db.ProductColors.Join(db.Colors, PC => PC.ColorID, C => C.ColorID, (PC, C) => new { ColorName = C.ColorName, ColorID = C.ColorID, ProductID = PC.ProductID, ProductColorID = PC.ProductColorID, }); var tempcolor2 = tempcolor.Where(PC => PC.ProductColorID == beta.ProductColorID).Select(C => C.ColorName); _PSVM.ColorName = tempcolor2.First(); Debug.WriteLine("_PSVM.ColorName =" + _PSVM.ColorName); //SizeName var tempsize = db.ProductSizes.Join(db.Sizes, PS => PS.SizeID, S => S.SizeID, (PS, S) => new { SizeName = S.SizeName, SizeID = S.SizeID, ProductID = PS.ProductID, ProductSizeID = PS.ProductSizeID, }); var tempsize2 = tempsize.Where(S => S.ProductSizeID == beta.ProductSizeID).Select(S => S.SizeName); _PSVM.SizeName = tempsize2.First(); Debug.WriteLine("_PSVM.SizeName =" + _PSVM.SizeName); //StockID _PSVM.StockID = beta.StockID; //StockQTY _PSVM.StockQTY = beta.StockQTY; //MinStock _PSVM.MinStock = beta.MinStock; //SuppilerName var ts = _productRepository.GetById(beta.ProductID); var ts2 = ts.SupplierID; var ts3 = _supplierRepository.GetById(ts2).SupplierName; _PSVM.SupplierName = ts3; Debug.WriteLine("_PSVM.SupplierName =" + _PSVM.SupplierName); //訂購數量欄位 _PSVM.OrderQTY = db.OrderDetails .Where(x => x.ProductID == beta.ProductID && x.ProductColorID == beta.ProductColorID && x.ProductSizeID == beta.ProductSizeID && x.OrderHeader.OrderStatusID == 1).Select(x => x.OrderQTY).Count(); //購物車訂購數量 _PSVM.CartQTY = db.Carts.Where(x => x.ProductID == beta.ProductID && x.ProductColorID == beta.ProductColorID && x.ProductSizeID == beta.ProductSizeID).Select(x => x.Quantity).Count(); //需補貨數量 _PSVM.AddQTY = _PSVM.CartQTY + _PSVM.OrderQTY + _PSVM.MinStock - _PSVM.StockQTY; //讀圖片 var tempphoto = db.ProductColors.Find(beta.ProductColorID); var tempphoto2 = db.Colors.Find(tempphoto.ColorID).ColorName; _PSVM.PhotoID = Convert.ToInt32(tempphoto.PhotoID); _PSVM.readimg_to_getimagebyte = tempphoto.ColorID; //寫入集合 List<ProductStockViewModel> _ListPSVM if (_PSVM.AddQTY > 0) { _ListPSVM.Add(_PSVM); } } return(View(_ListPSVM.ToList().ToPagedList(page ?? 1, 5))); } else { RedirectToAction("PermissionError", "ProductMaintain"); } return(View()); }