Beispiel #1
0
        public void MarkRollAsUsed(int scrimRollID, int lineID, string userName)
        {
            //Get scrim roll and prod line
            var entity   = _repository.Repository <ScrimRoll>().GetById(scrimRollID);
            var prodLine = _repository.Repository <ProdLine>().GetById(lineID);

            //Get current production date
            TPO.Services.Production.ProdDateChangeService dateSvc = new Production.ProdDateChangeService();
            var dateChange = dateSvc.GetCurrentProductionDate(lineID);

            //Get current production shift
            TPO.Services.Production.ProductionShiftService shiftSvc = new Production.ProductionShiftService();
            var prodShift = shiftSvc.GetCurrentProductionShift(lineID);

            //Get appropriate action type
            var actionType = _repository.Repository <ScrimActionType>().GetAllBy(at => at.Code == "PR").FirstOrDefault();

            //Get appropriate user
            TPO.Services.Application.SecurityService secSvc = new Application.SecurityService();
            var user = secSvc.GetByUserName(userName);

            //Create ScrimActionDto
            ScrimActionDto actionDto = new ScrimActionDto();

            actionDto.ScrimRollID      = scrimRollID;
            actionDto.TypeID           = actionType.ID;
            actionDto.ActionLength     = (entity.Length - entity.LengthUsed) * -1;
            actionDto.ActionWeight     = (entity.Weight - entity.WeightUsed) * -1;
            actionDto.StartLength      = entity.Length - entity.LengthUsed;
            actionDto.StartWeight      = entity.Weight - entity.WeightUsed;
            actionDto.EndLength        = entity.Length - actionDto.StartLength;
            actionDto.EndWeight        = entity.Weight - actionDto.StartWeight;
            actionDto.ActionReasonText = "Production Used Roll";
            actionDto.UserID           = user.Id;
            actionDto.ActionDate       = dateChange.CurrentProductionDate;
            actionDto.ShiftID          = prodShift != null ? prodShift.ID : (int?)null;
            actionDto.LineID           = lineID;
            actionDto.WorkOrderID      = prodLine.CurrentWorkOrderID;
            actionDto.PlantID          = prodLine.PlantID;
            actionDto.FleeceProd       = false;
            actionDto.DateEntered      = DateTime.Now;
            actionDto.EnteredBy        = userName;
            actionDto.LastModified     = actionDto.DateEntered;
            actionDto.ModifiedBy       = actionDto.EnteredBy;

            ScrimActionService actionSvc = new ScrimActionService();

            actionSvc.Add(actionDto);
        }
Beispiel #2
0
        public void Update(ScrimRollDto scrimRollDto, ScrimActionDto scrimActionDto)
        {
            try
            {
                var scrimRoll = new ScrimRoll();
                Mapper.Map(scrimRollDto, scrimRoll);
                _repository.Repository <ScrimRoll>().Update(scrimRoll);
                //CommitUnitOfWork();

                var scrimAction = new ScrimAction();
                Mapper.Map(scrimActionDto, scrimAction);
                if (scrimAction.ID > 0)
                {
                    _repository.Repository <ScrimAction>().Update(scrimAction);
                }
                else
                {
                    _repository.Repository <ScrimAction>().Insert(scrimAction);
                }
                CommitUnitOfWork();
            }
            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;
            }
        }
        public JsonResult SaveAdjustment(int scrimRollId, int actionTypeId, double adjustment, int uomId, string adjustmentReason)
        {
            TPO.Web.Core.ResponseMessage responseMessage;

            try
            {
                var model = new ScrimActionModel();
                {
                    model.ActionDate  = DateTime.Now;
                    model.PlantId     = CurrentPlantId;
                    model.ScrimRollID = scrimRollId;
                    var uomModel             = GetUomModel(uomId);
                    var uomTypeModel         = GetUomTypeModel(uomModel.TypeID);
                    var scrimActionTypeModel = GetScrimActionTypeModel(actionTypeId);
                    var scrimRollModel       = GetScrimRollModel(scrimRollId);
                    scrimRollModel.IsLoaded = true;
                    model.StartLength       = (double)scrimRollModel.Length;
                    model.StartWeight       = (double)scrimRollModel.Weight;
                    var    uoMConversionService = new UoMConversionService();
                    string adjustmentReasonText;
                    if (uomTypeModel.Code == "L")
                    {
                        model.ActionLength = adjustment;
                        decimal adjustmentLength = uoMConversionService.ConvertUoM(uomId, (decimal)adjustment,
                                                                                   scrimRollModel.LengthUoMID);
                        if (scrimActionTypeModel.Code == "SA")
                        {
                            scrimRollModel.LengthUsed -= adjustmentLength;
                            scrimRollModel.Length     += adjustmentLength;
                            adjustmentReasonText       = "(Adjusted length by " + adjustment + " " + uomModel.Code + ")";
                        }
                        else
                        {
                            scrimRollModel.Length     = adjustmentLength;
                            scrimRollModel.LengthUsed = scrimRollModel.ReceivedLength - scrimRollModel.Length;
                            adjustmentReasonText      = "(Set length to " + adjustment + " " + uomModel.Code + ")";
                        }
                    }
                    else
                    {
                        model.ActionWeight = adjustment;
                        decimal adjustmentWeight = uoMConversionService.ConvertUoM(uomId, (decimal)adjustment,
                                                                                   scrimRollModel.WeightUoMID);
                        if (scrimActionTypeModel.Code == "SA")
                        {
                            scrimRollModel.WeightUsed -= adjustmentWeight;
                            scrimRollModel.Weight     += adjustmentWeight;
                            adjustmentReasonText       = "(Adjusted weight by " + adjustment + " " + uomModel.Code + ")";
                        }
                        else
                        {
                            scrimRollModel.Weight     = adjustmentWeight;
                            scrimRollModel.WeightUsed = scrimRollModel.ReceivedWeight - scrimRollModel.Weight;
                            adjustmentReasonText      = "(Set weight to " + adjustment + " " + uomModel.Code + ")";
                        }
                    }
                    if (adjustmentReason == null)
                    {
                        adjustmentReason = string.Empty;
                    }
                    else
                    {
                        adjustmentReason += " ";
                    }
                    model.DateEntered      = DateTime.Now;
                    model.EndLength        = (double)scrimRollModel.Length;
                    model.EndWeight        = (double)scrimRollModel.Weight;
                    model.EnteredBy        = CurrentUser;
                    model.LastModified     = DateTime.Now;
                    model.ModifiedBy       = CurrentUser;
                    model.RollID           = null;
                    model.TypeID           = actionTypeId;
                    model.UserID           = GetUserModel(CurrentUser).Id;
                    model.ActionReasonText = adjustmentReason + adjustmentReasonText;
                    using (var scrimRollService = new ScrimRollService())
                    {
                        var scrimActionDto = new ScrimActionDto();
                        Mapper.Map(model, scrimActionDto);
                        var scrimRollDto = new ScrimRollDto();
                        Mapper.Map(scrimRollModel, scrimRollDto);
                        scrimRollService.Update(scrimRollDto, scrimActionDto);
                        SetResponseMesssage(ActionTypeMessage.SuccessfulSave);
                    }
                }

                responseMessage = SetResponseMesssage(ActionTypeMessage.SuccessfulSave);
            }
            catch (Exception exc)
            {
                responseMessage = SetResponseMesssage(ActionTypeMessage.FailedSave, exc.Message);
            }

            return(Json(responseMessage, JsonRequestBehavior.AllowGet));
        }