public static IEnumerable <DTOCommand> TakeNeighbour(this IEnumerable <DTOCommand> commands) { using (var dc = new WMSContext()) { var commandsList = commands.ToList(); List <string> sourceList = commandsList .Select(prop => prop.Source.Substring(0, 10) + ":1") .ToList(); var Places = (from place in dc.Places where sourceList.Any(prop => prop == place.PlaceID) select place).ToList(); for (int i = 0; i < commandsList.Count(); i++) { yield return new DTOCommand { Order_ID = commandsList[i].Order_ID, Source = commandsList[i].Source.Substring(0, 10) + ":1", TU_ID = Places[i].TU_ID, Target = null, LastChange = DateTime.Now } } ; } }
/// <summary> /// DTOOrder is connected only to one DTOCommand /// Order can be connected to many DTOCommands /// Order /// </summary> /// <param name="o"></param> /// <returns></returns> public static IEnumerable <DTOOrder> OrderToDTOOrders(this IEnumerable <Order> orders) { using (var dc = new WMSContext()) { string destination = ""; int counter = 0; IEnumerable <string> targets = null; foreach (Order o in orders) { if (o.Destination != destination) { targets = dc.PlaceIds .Where(prop => prop.ID.StartsWith(o.Destination) && prop.DimensionClass != -1) .Select(prop => prop.ID) .ToList(); destination = o.Destination; if (dc.Parameters.Find($"Counter[{o.Destination}]") == null) { dc.Parameters.Add(new Parameter { Name = $"Counter[{o.Destination}]", Value = Convert.ToString(0) }); dc.SaveChanges(); } counter = Convert.ToInt16(dc.Parameters.Find($"Counter[{o.Destination}]").Value); } _counterLast = counter; _destinationLast = destination; double defQty = dc.SKU_IDs.Find(o.SKU_ID).DefaultQty; int fullTUs = (int)(o.SKU_Qty / defQty); double partialQty = o.SKU_Qty - fullTUs * defQty; for (int i = 0; i < fullTUs; i++) { DTOOrder dtoOrder = new DTOOrder(o); dtoOrder.Destination = targets.ElementAt(counter % targets.Count()); // alternatively // dtoOrder.Destination = targets.ElementAt((counter / 12) % targets.Count()); dtoOrder.SKU_Qty = defQty; counter++; yield return(dtoOrder); } if (partialQty > 0) { DTOOrder dtoOrder = new DTOOrder(o); dtoOrder.Destination = targets.ElementAt(counter % targets.Count()); dtoOrder.SKU_Qty = partialQty; counter++; yield return(dtoOrder); } o.Status = Order.OrderStatus.Active; dc.Parameters.Find($"Counter[{o.Destination}]").Value = Convert.ToString(counter); } dc.SaveChanges(); } }
public override string BuildXml() { XElement el0 = null; LoadSchema(); XDocument XDocument = new XDocument(new XDeclaration("1.0", "UTF-8", "yes"), el0 = new XElement("Belgeler")); XNamespace ns = XDocument.Root.Name.Namespace; // belgeler el0.Add(new XElement("Baslik")); el0.Add(new XElement("Detaylar")); // baslik el0.Element(ns + "Baslik").Add(new XElement("BelgeKodu", XmlConvert.ToString(DocumentID))); el0.Element(ns + "Baslik").Add(new XElement("Tesis", "Aksaray")); using (var dc = new WMSContext()) { foreach (var cmd in Commands) { if (cmd.Order_ID.HasValue) { Order order = dc.Orders.Find(cmd.Order_ID.Value); SKU_ID skuid = dc.SKU_IDs.Find(order.SKU_ID); TU tu = dc.TUs.FirstOrDefault(prop => prop.TU_ID == cmd.TU_ID); // Detay el0.Element(ns + "Detaylar").Add(new XElement("Detay")); (el0.Element(ns + "Detaylar").LastNode as XElement).Add(new XElement("BelgeKodu", XmlConvert.ToString(order.ERP_ID.HasValue ? order.SubOrderERPID: 0))); // (el0.Element(ns + "Detaylar").LastNode as XElement).Add(new XElement("RefBelgeDetayNo")); (el0.Element(ns + "Detaylar").LastNode as XElement).Add(new XElement("UrunKod", tu.SKU_ID)); (el0.Element(ns + "Detaylar").LastNode as XElement).Add(new XElement("Miktar", XmlConvert.ToString(tu.Qty))); (el0.Element(ns + "Detaylar").LastNode as XElement).Add(new XElement("Birim", skuid.Unit)); // (el0.Element(ns + "Detaylar").LastNode as XElement).Add(new XElement("NetAgirLik")); // (el0.Element(ns + "Detaylar").LastNode as XElement).Add(new XElement("AgirlikBirimi")); (el0.Element(ns + "Detaylar").LastNode as XElement).Add(new XElement("KaynakBatchNo", tu.Batch)); // (el0.Element(ns + "Detaylar").LastNode as XElement).Add(new XElement("HedefBatchNo"), tu.Batch); // (el0.Element(ns + "Detaylar").LastNode as XElement).Add(new XElement("SeriNo")); // (el0.Element(ns + "Detaylar").LastNode as XElement).Add(new XElement("KaynakLokasyon")); (el0.Element(ns + "Detaylar").LastNode as XElement).Add(new XElement("HedefLokasyon", order.Destination)); // (el0.Element(ns + "Detaylar").LastNode as XElement).Add(new XElement("KaynakStatus")); // (el0.Element(ns + "Detaylar").LastNode as XElement).Add(new XElement("HedefStatu")); (el0.Element(ns + "Detaylar").LastNode as XElement).Add(new XElement("PaletNo", $"{cmd.TU_ID:d9}")); // (el0.Element(ns + "Detaylar").LastNode as XElement).Add(new XElement("Po")); // (el0.Element(ns + "Detaylar").LastNode as XElement).Add(new XElement("PoLine")); // (el0.Element(ns + "Detaylar").LastNode as XElement).Add(new XElement("SKT")); // (el0.Element(ns + "Detaylar").LastNode as XElement).Add(new XElement("URT")); } } } return(XDocument.ToString()); }
/// <summary> /// Find identical TU (skuid,batch,qty) with nearest prod date on level 2 with free level 1 /// </summary> /// <param name="cmd"></param> /// <returns></returns> public static string FindBrotherOnDepth2(this DTOCommand cmd) { List <string> reck = new List <string> { "W:11", "W:12", "W:21", "W:22" }; using (var dc = new WMSContext()) { TU tu = dc.TUs.FirstOrDefault(prop => prop.TU_ID == cmd.TU_ID); string brother = dc.Places .Where(prop => reck.Any(p => prop.PlaceID.StartsWith(p)) && prop.PlaceID.EndsWith("2")) .Where(prop => prop.FK_PlaceID.Status == 0) .Where(prop => !dc.Places.Any(p => p.PlaceID == prop.PlaceID.Substring(0, 10) + ":1")) .Where(prop => !dc.Commands.Any(p => (p.Source == prop.PlaceID && p.Status < Command.CommandStatus.Canceled) || (p.Target == prop.PlaceID.Substring(0, 10) + ":1" && p.Status < Command.CommandStatus.Canceled))) .Select(prop => new { Place = prop.PlaceID, TU = prop.FK_TU_ID.FK_TU.FirstOrDefault() }) .Where(prop => prop.TU.Batch == tu.Batch && prop.TU.SKU_ID == tu.SKU_ID && prop.TU.Qty == tu.Qty) .Union( dc.Commands .Where(prop => reck.Any(p => prop.Target.StartsWith(p)) && prop.Target.EndsWith("2") && prop.Status < Command.CommandStatus.Canceled) .Where(prop => !dc.Commands.Any(p => p.Target == prop.Target.Substring(0, 10) + ":1" && p.Status < Command.CommandStatus.Canceled)) .Where(prop => !dc.Places.Any(p => p.PlaceID == prop.Target.Substring(0, 10) + ":1")) .Where(prop => dc.PlaceIds.Any(p => p.ID == prop.Target.Substring(0, 10) + ":1" && p.Status == 0)) .Select(prop => new { Place = prop.Target, TU = prop.FK_TU_ID.FK_TU.FirstOrDefault() }) .Where(prop => prop.TU.Batch == tu.Batch && prop.TU.SKU_ID == tu.SKU_ID && prop.TU.Qty == tu.Qty) ) .Where(prop => prop.Place.EndsWith("2")) .OrderBy(prop => DbFunctions.DiffHours(prop.TU.ExpDate, tu.ExpDate)) // add order by production date .Select(prop => prop.Place) .FirstOrDefault(); return(brother); } }