public async Task <IActionResult> Edit(int id, [Bind("inventoryin_id,purchase_id,product_id,inventoryin_qty,manufacturer_date")] InventoryIn inventoryIn) { if (id != inventoryIn.inventoryin_id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(inventoryIn); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!InventoryInExists(inventoryIn.inventoryin_id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["product_id"] = new SelectList(_context.ProductInfos, "product_id", "product_name", inventoryIn.product_id); ViewData["purchase_id"] = new SelectList(_context.PurchaseOrders, "purchase_id", "purchase_id", inventoryIn.purchase_id); return(View(inventoryIn)); }
public IHttpActionResult GetInventoryIn(int id) { InventoryIn inventoryIn = db.InventoryIns.Find(id); if (inventoryIn == null) { return(NotFound()); } return(Ok(inventoryIn)); }
/// <summary> /// Call this method when adding product to inventory. /// Add product info into the InventoryIn table and then ++ then quantity in the Inventory Table By product Extension class.. /// Modify Account Balance for product bought. /// Verify account balance info. /// Add account balance to db. /// Create InventoryIn /// Create Product /// Add those to database. /// Just not save. Save it when all successful. /// </summary> /// <param name="db">Pass the dbContext</param> /// <param name="accountBalance"></param> /// <returns></returns> public bool InventoryAdd(JustFoodDBEntities db, AccountBalance accountBalance) { bool result = true; accountBalance.Dated = DateTime.Now; accountBalance.AddBy = userinfo.GetUserSession().UserID; accountBalance.IsBoughtProduct = true; accountBalance.IsAddedMoney = false; accountBalance.IsExpense = true; if (accountBalance.Amount < 0 || accountBalance.AddedQuantity < 1) { Statics.ErrorCollection.Add("Amount", "Amount or Quantity can't be negative."); result = false; } //checking if quantity type is valid. if (accountBalance.QtyType == null || db.QuantityTypes.Find(accountBalance.QtyType) == null) { Statics.ErrorCollection.Add("QtyType", "Quantity type is not valid , please select a valid quantity type."); result = false; } var quantity = accountBalance.AddedQuantity; var unitprice = (accountBalance.Amount / (double)quantity); var qtyExtension = new QuantityTypeExtension(); unitprice = Math.Round(unitprice, 2); int userid = userinfo.GetUserID(); // check if quantity mismatch. decimal multiplier = 0; var mismatch = qtyExtension.Mismatch((int)accountBalance.CategoryProduct, (byte)accountBalance.QtyType, out multiplier); if (!mismatch) { var invtIn = new InventoryIn { CategoryID = (int)accountBalance.CategoryProduct, Quantity = (decimal)quantity, UnitPrice = unitprice, AddedBy = userid, QtyType = (byte)accountBalance.QtyType, Dated = DateTime.Now }; var productExt = new ProductExtension(); //add inventory product in. db.InventoryIns.Add(invtIn); accountBalance.AddedQuantity = accountBalance.AddedQuantity * multiplier; accountBalance.Amount = accountBalance.Amount * -1; //expense db.AccountBalances.Add(accountBalance); productExt.AddProduct(accountBalance, db); } return(result); }
//update one item into Inventory table public static List <InventoryIn> UpdateInventory(InventoryIn e) { var item = (from inventory in db.InventoryIns where inventory.Seq == e.Seq select inventory).SingleOrDefault(); if (item != null) { item.SN = e.SN; item.Date = e.Date; item.Location = e.Location; item.ModelNo = e.ModelNo; } db.SaveChanges(); return(GetAllInventory()); }
private async void ItemName_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter && ItemName.TextLength > 0) { inventoryItemBindingSource.DataSource = await InventoryManager.GetItemStockAsync(ItemName.Text); bindingSource1.DataSource = await InventoryManager.GetItemCheckInsAsync(ItemName.Text); bindingSource2.DataSource = await InventoryManager.GetItemCheckOutsAsync(ItemName.Text); Current.ClearSelection(); InventoryIn.ClearSelection(); InventoryOut.ClearSelection(); IsTime = true; } }
private async void Current_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Delete && e.Shift && Login.Role != "Operator") { DataGridViewRow row = Current.CurrentRow; if (row != null) { InventoryItem item = inventoryItemBindingSource.List[row.Index] as InventoryItem; InventoryManager.DeleteInventoryItem(item); MessageBox.Show($"{item.ItemName} was successfully deleted.", ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); inventoryItemBindingSource.DataSource = await InventoryManager.GetItemStockAsync(ItemName.Text); bindingSource1.DataSource = await InventoryManager.GetItemCheckInsAsync(ItemName.Text); bindingSource2.DataSource = await InventoryManager.GetItemCheckOutsAsync(ItemName.Text); Current.ClearSelection(); InventoryIn.ClearSelection(); InventoryOut.ClearSelection(); } } }
public async Task <IActionResult> Create(InventoryInView inventoryInView) { //return Json(inventoryInView); //กรณีที่เป็น Complete //if (inventoryInView.purchase_type_id == 3) if (ModelState.IsValid) { //return Content("yes"); if (inventoryInView.purchase_type_id == 3) { var obj = new InventoryIn { purchase_id = inventoryInView.purchase_id, product_id = inventoryInView.product_id, inventoryin_qty = inventoryInView.inventoryin_qty, manufacturer_week = inventoryInView.manufacturer_week, manufacturer_year = inventoryInView.manufacturer_year, purchaseItem_id = inventoryInView.purchaseItem_id, CompleteDate = DateTime.Now }; _context.InventoryIn.Add(obj); //return Json(obj); var row = new PActivity { purchase_type_id = inventoryInView.purchase_type_id, purchaseItem_id = inventoryInView.purchaseItem_id, activity_date = DateTime.Now }; _context.PActivities.Add(row); //update purchase_type_id into purchase_items table var found = await _context.PurchaseItems.FirstOrDefaultAsync(x => x.purchaseItem_id == inventoryInView.purchaseItem_id); found.purchase_type_id = 3; _context.PurchaseItems.Update(found); var pproduct = await _context.ProductInfos.Where(x => x.product_id == inventoryInView.product_id).FirstOrDefaultAsync(); var found2 = await _context.Inventories .FirstOrDefaultAsync(x => x.product_name == pproduct.product_name); found2.invento_qty += inventoryInView.inventoryin_qty; _context.Inventories.Update(found2); var po = _context.PurchaseOrders .Where(x => x.purchase_id == inventoryInView.purchase_id) .FirstOrDefault(); DateTime today = DateTime.Now; TimeSpan timeDiff = today - po.purchase_date; double num_day = timeDiff.TotalDays; int i_num_day = (int)Math.Round(num_day); int kpi = 0; if (i_num_day > 5) { kpi = 1; } //use kip to update performance table var new_kpi = new SupplierPerformance { leadTime = kpi, deliver_date = today, supplier_id = inventoryInView.supplier_id, purchaseItem_id = inventoryInView.purchaseItem_id, backOrder = 0 }; _context.SupplierPerformances.Add(new_kpi); var p = await _context.SupplierInfos.Where(x => x.supplier_id == inventoryInView.supplier_id).FirstOrDefaultAsync(); p.leadtime += kpi; _context.SupplierInfos.Update(p); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } //กรณีที่เป็น BackOrder if (inventoryInView.purchase_type_id == 2) { var bo = new SupplierPerformance { supplier_id = inventoryInView.supplier_id, purchaseItem_id = inventoryInView.purchaseItem_id, deliver_date = DateTime.Now, leadTime = 0, backOrder = 1 }; _context.SupplierPerformances.Add(bo); var p = await _context.SupplierInfos.Where(x => x.supplier_id == inventoryInView.supplier_id).FirstOrDefaultAsync(); p.backorder += 1; _context.SupplierInfos.Update(p); var bol = new BackOrder { purchaseItem_id = inventoryInView.purchaseItem_id }; _context.BackOrders.Add(bol); var found = await _context.PurchaseItems.FirstOrDefaultAsync(x => x.purchaseItem_id == inventoryInView.purchaseItem_id); found.purchase_type_id = 2; _context.PurchaseItems.Update(found); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } ViewData["product_id"] = new SelectList(_context.ProductInfos, "product_id", "product_name", inventoryInView.product_id); ViewData["purchase_id"] = new SelectList(_context.PurchaseOrders, "purchase_id", "purchase_id", inventoryInView.purchase_id); ViewData["purchase_type_id"] = new SelectList(_context.PurchaseOrderTypes, "Purchase_type_id", "Purchase_type_name"); return(View()); }
//Insert one item into Inventory table public static List <InventoryIn> InsertInventory(InventoryIn e) { db.InventoryIns.Add(e); db.SaveChanges(); return(GetAllInventory()); }