public double GetScrapWeight(int plantID, int lineID, int shiftID, DateTime productionDate) { double returnValue = 0; Plant plant = _repository.Repository <Plant>().GetById(plantID); UnitOfMeasure defaultUom = plant.UnitOfMeasureDefaults.First(m => m.UnitOfMeasureType.Code == "W").UnitOfMeasure; ProdLine line = _repository.Repository <ProdLine>().GetById(lineID); ProdLineType lineType = _repository.Repository <ProdLineType>().GetById(line.LineTypeID); Application.UoMConversionService convert = new Application.UoMConversionService(); double result = 100; /* * var result = _repository.Repository<TPOLineScrap>().GetAllBy( * p => p.PlantID == plantID && * p.ShiftID == shiftID && * p.WorkOrder.LineID == lineID && * p.ProductionDate == productionDate).Sum( * p => convert.ConvertUoM(p.WeightUoMID, (decimal)p.Weight, defaultUom.ID) * ); * * returnValue = (double)Math.Round(result, 0); */ returnValue = result; return(returnValue); }
public double GetCompletionPercentage(int plantID, int lineID, int workOrderID) { double returnValue = 0.0; WorkOrder workOrder = _repository.Repository <WorkOrder>().GetById(workOrderID); ProdLine line = _repository.Repository <ProdLine>().GetById(lineID); ProdLineType lineType = _repository.Repository <ProdLineType>().GetById(line.LineTypeID); double ran = 0; if (lineType.ProdLineTypeCode == "IM") { ran = 0; /* * _repository.Repository<IMProd>().GetAllBy( * p => p.ProdLineID == lineID && * p.WorkOrderID == workOrder.ID && * p.IMProductID == workOrder.IMProductID && * p.PlantID == plantID).Sum(p => p.PartsCarton); */ } else { ran = 0; /* * ran = _repository.Repository<TPOCProductRoll>().GetAllBy( * p => p.LineID == lineID && * p.WorkOrderID == workOrder.ID && * p.ProductID == workOrder.TPOProductID && * p.PlantID == plantID).Sum( * p => (p.Length * p.TPOProduct.Width) == null ? 0 : (p.Length * p.TPOProduct.Width) * ); */ } if (workOrder.RunArea > 0) { returnValue = (ran / workOrder.RunArea); } return(returnValue); }
public int Add(ProductionLinesDto dto) { var entity = Mapper.Map <ProductionLinesDto, ProdLine>(dto); //TODO: Set fields on ProdLinesPerform based on values in ProdLine //ProdLinesPerform plp = new ProdLinesPerform(); //plp.LocID = entity.LocID; //TODO: Handle setting current work order to Line based on its type (see usp_WO_UpdateRCRWWorkOrders in old DB for reference) #region Line Type Checks //Get the type of production line ProdLineType type = _repository.Repository <ProdLineType>().GetById(entity.LineTypeID); if (type != null) { //If type is not reclaim or rework, make sure a WOLineUse record is present if (type.ProdLineTypeCode != "RW" && type.ProdLineTypeCode != "RC") { //TODO: Once WOLineUse table has been created, create a new instance of that Entity here and assign to newly created ProdLine } if (type.ProdLineTypeCode == "TPO" || type.ProdLineTypeCode == "RW" || type.ProdLineTypeCode == "WI" || type.ProdLineTypeCode == "CO") { //Create TPOCurrentScrim record if (type.ProdLineTypeCode == "TPO" || type.ProdLineTypeCode == "CO") { TPOCurrentScrim currScrim = new TPOCurrentScrim(); entity.TPOCurrentScrims.Add(currScrim); currScrim.PlantID = entity.PlantID; currScrim.DateEntered = entity.DateEntered; currScrim.EnteredBy = entity.EnteredBy; currScrim.LastModified = entity.LastModified; currScrim.ModifiedBy = entity.ModifiedBy; currScrim.ScrimPos = "NA"; if (type.ProdLineTypeCode == "TPO") { //TODO: Create TPOFormLineProd for this line for all products for the //current plant in TPOProducts where IsRepel is false //See usp_SA_LineProdFormCheck in old database } //TODO: Once TPOCurrentBatch table has been created, create a new instance of that Entity here } } } #endregion //Create ProductionShiftUse records for each available shift var prodShifts = _repository.Repository <ProductionShiftDto>().GetAllBy(s => s.PlantID == entity.PlantID).ToList(); for (int i = 0; i < prodShifts.Count; i++) { var minutes = 0; if (prodShifts[i].StartTime > prodShifts[i].EndTime) { minutes = prodShifts[i].StartTime.Subtract(prodShifts[i].EndTime).Minutes + 1440; } else { minutes = minutes = prodShifts[i].StartTime.Subtract(prodShifts[i].EndTime).Minutes; } ProductionShiftUse use = new ProductionShiftUse() { ShiftID = prodShifts[i].ID, PlantID = entity.PlantID, Day1Minutes = minutes, Day2Minutes = minutes, Day3Minutes = minutes, Day4Minutes = minutes, Day5Minutes = minutes, Day6Minutes = minutes, Day7Minutes = minutes, DateEntered = entity.DateEntered, EnteredBy = entity.EnteredBy, LastModified = entity.LastModified, ModifiedBy = entity.ModifiedBy }; entity.ProductionShiftUses.Add(use); //Need to create config line now since FK is non-nullable ProdLineRollConfig config = new ProdLineRollConfig() { RollName = type.ProdLineTypeCode, TypeID = type.ID, Order = 0 }; entity.ProdLineRollConfig = config; } //TODO: Create new ProdDteChng record ProdDateChange change = new ProdDateChange() { DateChange = DateTime.Now, RotationStart = DateTime.Now, PlantID = entity.PlantID, DateEntered = entity.DateEntered, EnteredBy = entity.EnteredBy, LastModified = entity.LastModified, ModifiedBy = entity.ModifiedBy }; entity.ProdDateChanges.Add(change); try { _repository.Repository <ProdLine>().Insert(entity); _repository.Save(); } catch (DbEntityValidationException valEx) { var sb = new StringBuilder(); foreach (var failure in valEx.EntityValidationErrors) { sb.AppendFormat("{0} failed validation\n", failure.Entry.Entity.GetType()); foreach (var error in failure.ValidationErrors) { sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage); sb.AppendLine(); } } throw new DbEntityValidationException( "Entity Validation Failed - errors follow:\n" + sb.ToString(), valEx ); // Add the original exception as the innerException } catch (Exception ex) { LogException(ex); throw; } return(entity.ID); }
public double GetScrapPercent(int plantID, int lineID, int shiftID, DateTime productionDate) { double returnValue = 0; Plant plant = _repository.Repository <Plant>().GetById(plantID); UnitOfMeasure defaultUom = plant.UnitOfMeasureDefaults.First(m => m.UnitOfMeasureType.Code == "W").UnitOfMeasure; ProdLine line = _repository.Repository <ProdLine>().GetById(lineID); ProdLineType lineType = _repository.Repository <ProdLineType>().GetById(line.LineTypeID); ProductionShift shift = _repository.Repository <ProductionShift>().GetById(shiftID); Application.UoMConversionService convert = new Application.UoMConversionService(); var scrap = 0; /* * var scrap = _repository.Repository<TPOLineScrap>().GetAllBy( * p => p.PlantID == plantID && * p.ShiftID == shiftID && * p.WorkOrder.LineID == lineID && * p.ProductionDate == productionDate).Sum( * p => convert.ConvertUoM(p.WeightUoMID, (decimal)p.Weight, defaultUom.ID) * ); */ if (lineType.ProdLineTypeCode == "IM") { var prod = 0; /* * var prod = _repository.Repository<IMProd>().GetAllBy( * p => p.ProdLineID == lineID && * p.ProdShift == shift.Code && * p.PlantID == plantID && * p.ProdDate == productionDate).Sum( * p => convert.ConvertUoM(p.WeightUOM, (decimal)p.CartonWeight, defaultUom.ID) * ); */ if (prod > 0) { returnValue = (double)(scrap / prod); } } else { var prod = 0; /* * var prod = _repository.Repository<TPOCProductRoll>().GetAllBy( * p => p.LineID == lineID && * p.ShiftID == shiftID && * p.PlantID == plantID && * p.ProductionDate == productionDate).Sum( * p => convert.ConvertUoM(p.WeightUoMID, (decimal)p.Weight, defaultUom.ID) * ); */ if (prod > 0) { returnValue = (double)(scrap / prod); } } return(returnValue); }