public ActionResult StockTakeUpdate(StockTakeList[] arr, string[] arr1) { try { int count = 0; string transType = "Stock Take"; List <StockTakeList> list = new List <StockTakeList>(); for (int i = 0; i < arr.Length; i++) { list.Add(arr[i]); } using (SSISdbEntities m = new SSISdbEntities()) { int itemTransCount = m.StockTakeHeaders.Count() + 1; string itemTransactionId = CommonLogic.SerialNo(itemTransCount, "ST"); // Update StockTakeHeader Table StockTakeHeader stockTakeHeader = new StockTakeHeader(); stockTakeHeader.StockTakeID = itemTransactionId; stockTakeHeader.Date = DateTime.Now; stockTakeHeader.TransactionType = transType; m.StockTakeHeaders.Add(stockTakeHeader); m.SaveChanges(); foreach (StockTakeList l in list) { Item item = m.Items.Where(x => x.ItemCode == l.ItemCode).FirstOrDefault(); int itemQty = Convert.ToInt32(arr1[count]); float avgCost = item.AvgUnitCost; int qtyOnHand = item.Quantity; int qtyAdjusted = itemQty - qtyOnHand; float totalAmt = avgCost * (float)qtyAdjusted; string itemcode = l.ItemCode; if (qtyAdjusted != 0) { // Update Item Table item.Quantity = itemQty; // Update ItemTransaction Table ItemTransaction itemTransaction = new ItemTransaction(); itemTransaction.TransDateTime = DateTime.Now; itemTransaction.DocumentRefNo = itemTransactionId; itemTransaction.ItemCode = itemcode; itemTransaction.TransactionType = transType; itemTransaction.Quantity = qtyAdjusted; itemTransaction.UnitCost = avgCost; itemTransaction.Amount = totalAmt; m.ItemTransactions.Add(itemTransaction); m.SaveChanges(); } // Update StockTakeDetails Table StockTakeDetail stockTakeDetail = new StockTakeDetail(); stockTakeDetail.StockTakeID = itemTransactionId; stockTakeDetail.ItemCode = itemcode; stockTakeDetail.QuantityOnHand = qtyOnHand; stockTakeDetail.QuantityCounted = itemQty; stockTakeDetail.QuantityAdjusted = qtyAdjusted; m.StockTakeDetails.Add(stockTakeDetail); m.SaveChanges(); count++; } } } catch (FormatException fe) { Debug.WriteLine(fe.Message); }catch (Exception e) { Debug.WriteLine(e.Message); } return(View()); }
public void DeleteStockTakeDetail(string stockTakeId, string itemCode) { StockTakeDetail stockTakeDetail = context.StockTakeDetails.Where(x => x.StockTakeID == stockTakeId && x.ItemCode == itemCode).First(); context.StockTakeDetails.Remove(stockTakeDetail); }
public void UpdateStockTakeDetail(StockTakeDetail stockTakeDetail) { context.Entry(stockTakeDetail).State = EntityState.Modified; }
public void InsertStockTakeDetail(StockTakeDetail stockTakeDetail) { context.StockTakeDetails.Add(stockTakeDetail); }