public void MapPPStepSequencesOnActivites(Dictionary <string, ProcessPlan> processPlans) { if (processPlans.ContainsKey(ProductType)) { ProcessPlan = processPlans[ProductType]; foreach (LotActivityRaw activity in LotActivitiesRaw) { List <SingleStep> steps = ProcessPlan.Steps.Where(x => activity.Stepname == x.Stepname && activity.Techstage == x.Techstage && activity.Subplan == x.Subplan).ToList(); // One step of process plans matches the activity if (steps.Count() == 1) { SingleStep step = steps.First(); activity.PPStepSequence = step.StepSequence; } // No step of process plan matches the acitivy, so PPStepSequence is set to -1 else if (!steps.Any()) { activity.PPStepSequence = -1; } // Multiple steps of process plan match the activity, so exception is thrown else if (steps.Count() > 1) { throw new Exception($"Multiple steps found in process plan {steps.First().Productname} with same Stepname {activity.Stepname}, " + $"Techstage {activity.Techstage} and Subplan {activity.Subplan} as activity {activity.LotId}"); } } } }
private Dictionary <string, ProcessPlan> getProcessPlans() { Dictionary <string, ProcessPlan> ProcessPlans = new Dictionary <string, ProcessPlan>(); foreach (string product in getProductTypes()) { ProcessPlan plan = new ProcessPlan(product, lotStepsRaw.Where(x => x.Productname == product).OrderBy(x => x.StepSequence).ToList()); ProcessPlans.Add(product, plan); } return(ProcessPlans); }
public async Task <ApiResult <bool> > SplitProcess(long id) { var process = await _context.ProcessPlans .Include(x => x.ProcessingDetails) .Where(x => x.Id == id).FirstOrDefaultAsync(); var listProcessingDetails = new List <ProcessingDetail>(); foreach (var item in process.ProcessingDetails) { var amount = item.Amount - item.EnterAmount; if (amount > 0) { var processingDetails = new ProcessingDetail() { Amount = amount, IdRecipe = item.IdRecipe, IdProcessPlan = item.IdProcessPlan, Unit = item.Unit }; listProcessingDetails.Add(processingDetails); } } var stt = 1; Location: string code = process.Code + "-" + stt.ToString(); var checkCode = await _context.ProcessPlans.AnyAsync(x => x.Code == code); if (checkCode) { stt++; goto Location; } var processPlan = new ProcessPlan() { Code = code, IdAuthority = process.IdAuthority, IdCreator = process.IdCreator, IdResponsible = process.IdResponsible, Censorship = false, CreatedDate = DateTime.Now, ExpectedDate = DateTime.Now, Name = process.Name + " (Tách)", Note = process.Note, Status = StatusProcessPlan.Processing, ProcessingDetails = listProcessingDetails }; _context.ProcessPlans.Add(processPlan); await _context.SaveChangesAsync(); process.Status = StatusProcessPlan.Processed; var note = process.Note + " (Đã từng tách kế hoạch)"; process.Note = note; _context.ProcessPlans.Update(process); await _context.SaveChangesAsync(); return(new ApiSuccessResult <bool>()); }
public async Task <ApiResult <bool> > Create(CreatePlan bundle) { var processingDetails = new List <ProcessingDetail>(); if (bundle.Pack.Length > 0) { var i = 0; foreach (var item in bundle.Pack) { processingDetails.Add(new ProcessingDetail() { Amount = bundle.Amount[i], IdRecipe = bundle.IdMaterials[i], Unit = item }); i++; } } // lưu code var user = await _userManager.FindByNameAsync(bundle.NameCreator); var code = await _context.ManageCodes.FirstOrDefaultAsync(x => x.Name == bundle.Code); var stt = 1; Location: var location = code.Location + stt; var str = code.Name + location; var checkCode = await _context.OrderPlans.AnyAsync(x => x.Code == str); if (checkCode) { stt++; goto Location; } code.Location = location; _context.ManageCodes.Update(code); await _context.SaveChangesAsync(); // kế hoạch var process = new ProcessPlan() { Code = str, CreatedDate = DateTime.Now, ExpectedDate = bundle.ExpectedDate, Note = bundle.Note, IdCreator = user.Id, IdResponsible = bundle.IdResponsible, ProcessingDetails = processingDetails, Name = bundle.Name }; _context.ProcessPlans.Add(process); await _context.SaveChangesAsync(); return(new ApiSuccessResult <bool>()); }