public ActionResult SetPicked(long PickID, int ActualpickQty, string OutboundPlanNo) { OBpicking picking = new OBpicking(); picking = (from c in db.OBpickings where c.ID == PickID select c).FirstOrDefault(); picking.ActualQty = ActualpickQty; db.Entry(picking).State = EntityState.Modified; db.SaveChanges(); OBoutboundPlan outboundplan = new OBoutboundPlan(); outboundplan = (from u in db.OBoutboundPlans.ToList() where u.OutboundPlanNo == OutboundPlanNo select u).FirstOrDefault(); //outbound Item List <OBoutboundItem> outbound_itemlist = (from ob in db.OBoutboundItems where ob.OutBoundPlanCode == outboundplan.OutboundPlanNo select ob).ToList(); foreach (OBoutboundItem item in outbound_itemlist) { List <STstockInventoryDetail> stockdetail_list = (from std in db.STstockInventoryDetails join al in db.OBallocations on new { X1 = std.StockCode, X2 = std.StockDetailCode } equals new { X1 = al.StockCode, X2 = al.StockDetailCode } where std.ItemCode == item.ItemCode && al.OutboundPlanNo == item.OutBoundPlanCode orderby std.Update_Date ascending select std).ToList(); foreach (STstockInventoryDetail inv in stockdetail_list) //Reset Picked Qty { inv.PickedQty = 0; //db.Entry(inv).State = EntityState.Modified; //db.SaveChanges(); } decimal?outboundItemSUM = ActualpickQty; foreach (STstockInventoryDetail inv in stockdetail_list) { if (outboundItemSUM != 0) { if (inv.ActualStockQty - outboundItemSUM > 0) { inv.PickedQty = outboundItemSUM; outboundItemSUM = 0; } else { inv.PickedQty = inv.AllocatedQty; outboundItemSUM = outboundItemSUM - inv.AllocatedQty; } db.Entry(inv).State = EntityState.Modified; db.SaveChanges(); } } } outboundplan.Update_Date = DateTime.Now; outboundplan.Update_User = user.UserID; db.Entry(outboundplan).State = EntityState.Modified; db.SaveChanges(); return(Json(new { result = "success" }, JsonRequestBehavior.AllowGet)); }
public ActionResult Allocate_Outbound(string OutboundPlanNo) { string DateID = DateTime.Now.ToString("yyyyMMdd"); string gencode = string.Empty; string lastgencode = (from u in db.OBpickings.ToList() orderby u.OutboundBatchNo descending select u.OutboundBatchNo).FirstOrDefault(); if (lastgencode == null) { gencode = DateID + "BTC0000001"; } else { gencode = lastgencode.Substring(11); int upId = Convert.ToInt32(gencode.TrimStart(new char[] { '0' })) + 1; gencode = DateID + string.Format("BTC{0}", upId.ToString().PadLeft(7, '0')); } OBoutboundPlan outboundplan = new OBoutboundPlan(); outboundplan = (from u in db.OBoutboundPlans.ToList() where u.OutboundPlanNo == OutboundPlanNo select u).FirstOrDefault(); //outbound Item List <OBoutboundItem> outbound_itemlist = (from ob in db.OBoutboundItems where ob.OutBoundPlanCode == outboundplan.OutboundPlanNo select ob).ToList(); foreach (OBoutboundItem item in outbound_itemlist) { List <STstockInventoryDetail> stockdetail_list = (from std in db.STstockInventoryDetails where std.ItemCode == item.ItemCode orderby std.Update_Date ascending select std).ToList(); decimal? Case = (item.QtyPerCase == null) ? 0 : item.QtyPerCase; decimal? InnerCase = (item.QtyPerInnerCase == null) ? 0 : item.QtyPerInnerCase; decimal? Unit = (item.QtyPerUnit == null) ? 0 : item.QtyPerUnit; decimal? outboundItemSUM = Case + InnerCase + Unit; OBpicking picking = new OBpicking(); #region for Picking picking.OutboundBatchNo = gencode; picking.OutboundPlanNo = item.OutBoundPlanCode; picking.OutboundDetailNo = item.OutboundItemCode; picking.ItemQty = outboundItemSUM; picking.ActualQty = 0; picking.Is_Deleted = false; picking.Create_Date = DateTime.Now; picking.Create_User = user.UserID; picking.Update_Date = DateTime.Now; picking.Update_User = user.UserID; db.OBpickings.Add(picking); db.SaveChanges(); #endregion #region ALLOCATION COMPUTE //foreach (STstockInventoryDetail inv in stockdetail_list) //{ // OBallocation allocation = new OBallocation(); // STstockInventoryDetail stockdetails = new STstockInventoryDetail(); // stockdetails = (from c in db.STstockInventoryDetails // where c.ActualStockQty > c.AllocatedQty // select c).FirstOrDefault(); // if (outboundItemSUM != 0) // { // #region for Allocation // allocation.OutboundPlanNo = item.OutBoundPlanCode; // allocation.OutboundDetailNo = item.OutboundItemCode; // allocation.StockCode = inv.StockCode; // allocation.StockDetailCode = inv.StockDetailCode; // allocation.QtyCase = inv.CaseQty; // allocation.QtyInnerCase = inv.InnerCaseQty; // allocation.QtyUnit = inv.UnitQty; // if (inv.ActualStockQty - outboundItemSUM > 0) // { // allocation.ItemQty = outboundItemSUM; // stockdetails.AllocatedQty = stockdetails.AllocatedQty + outboundItemSUM; // outboundItemSUM = 0; // } // else // { // allocation.ItemQty = inv.ActualStockQty; // stockdetails.AllocatedQty = inv.ActualStockQty; // outboundItemSUM = outboundItemSUM - inv.ActualStockQty; // } // allocation.Is_Deleted = false; // allocation.Create_Date = DateTime.Now; // allocation.Create_User = user.UserID; // allocation.Update_Date = DateTime.Now; // allocation.Update_User = user.UserID; // db.OBallocations.Add(allocation); // db.SaveChanges(); // #endregion // stockdetails.Update_User = user.UserID; // stockdetails.Update_Date = DateTime.Now; // db.Entry(stockdetails).State = EntityState.Modified; // db.SaveChanges(); // } //} #endregion } outboundplan.Update_Date = DateTime.Now; outboundplan.Update_User = user.UserID; outboundplan.OutboundStatus = "Allocated"; db.Entry(outboundplan).State = EntityState.Modified; db.SaveChanges(); return(Json(new { result = "success" }, JsonRequestBehavior.AllowGet)); }