Beispiel #1
0
        public Dictionary <string, string> Validate(ReturnedVehicle model)
        {
            var modelStateErrors = new Dictionary <string, string>();
            var saleTransaction  = dbContext.SaleTransactions.Where(a => a.SaleId == model.SaleId).Include(a => a.ReturnedVehicle).AsNoTracking().ToList().FirstOrDefault();

            //if (saleTransaction?.ReturnedVehicle != null)
            //{
            //    modelStateErrors.Add(nameof(model.ReturnedVehicleId), "Selected Vehicle already returned to truck");
            //    return modelStateErrors;
            //}

            if ((saleTransaction.NetWt - model.PlantNetWt) <= -500)
            {
                if (model.Remarks.IsNull())
                {
                    modelStateErrors.Add(nameof(model.Remarks), "Remarks is required for weight validation report");
                }
            }

            var reqTimeVariance = appconfigRepo.AppConfig.TransactionOption.ReturnedVehicleVarianceTime;

            if (model.DiffTime > reqTimeVariance)
            {
                if (model.TimeVarianceRemarks.IsNull())
                {
                    modelStateErrors.Add(nameof(model.Remarks), $"Time variance Remarks is required if arrival takes longer than {reqTimeVariance} hours");
                }
            }


            return(modelStateErrors);
        }
        private bool validateEntity(ReturnedVehicle model)
        {
            var modelErrors = repository.Validate(model);

            foreach (var err in modelErrors)
            {
                ModelState.AddModelError(err.Key, err.Value);
            }
            return(ModelState.ErrorCount == 0);
        }
Beispiel #3
0
        public decimal GetPMAdjustedWt(ReturnedVehicle model)
        {
            var result = model.PlantNetWt;

            if (model.PM >= 0.05m)
            {
                result = model.PlantNetWt - Math.Round((model.PM - 0.05m) * model.PlantNetWt) / 100;
            }
            return(result);
        }
Beispiel #4
0
        public decimal GetOTAdjustedWt(ReturnedVehicle model)
        {
            var result = model.PlantNetWt;

            if (model.OT >= 5)
            {
                result = model.PlantNetWt - Math.Round((model.OT - 5) * model.PlantNetWt) / 100;
            }
            return(result);
        }
Beispiel #5
0
        public SaleTransaction Create(long SaleId, ReturnedVehicle model)
        {
            var saleTransaction = saleTransactionRepository.GetById(SaleId);

            var correctedMC = mcRepo.GetCorrectedMC(model.MC, model.PlantNetWt);

            //model.MCStatus = correctedMC.MCStatus;
            model.Corrected10 = correctedMC.Corrected10;
            model.Corrected12 = correctedMC.Corrected12;
            model.Corrected14 = correctedMC.Corrected14;
            //model.Corrected15 = correctedMC.Corrected15;

            saleTransaction.ReturnedVehicle = model;
            dbContext.Update(saleTransaction);
            dbContext.SaveChanges();

            return(saleTransaction);
        }
 public IActionResult Put([FromBody] ReturnedVehicle model)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             return(InvalidModelStateResult());
         }
         if (!validateEntity(model))
         {
             return(InvalidModelStateResult());
         }
         return(Accepted(repository.Update(model)));
     }
     catch (Exception ex)
     {
         logger.LogError(ex.GetExceptionMessages());
         return(StatusCode(StatusCodes.Status500InternalServerError, Constants.ErrorMessages.CreateError));
     }
 }
Beispiel #7
0
        public ReturnedVehicle Update(ReturnedVehicle model)
        {
            var entity = GetById(model.ReturnedVehicleId);

            entity.MC                  = model.MC;
            entity.BaleCount           = model.BaleCount;
            entity.PMAdjustedWt        = model.PMAdjustedWt;
            entity.OTAdjustedWt        = model.OTAdjustedWt;
            entity.DiffDay             = model.DiffDay;
            entity.DiffTime            = model.DiffTime;
            entity.DiffCorrected10     = model.DiffCorrected10;
            entity.DiffCorrected12     = model.DiffCorrected12;
            entity.DiffNet             = model.DiffNet;
            entity.DTArrival           = model.DTArrival;
            entity.DTGuardIn           = model.DTGuardIn;
            entity.DTGuardOut          = model.DTGuardOut;
            entity.DTOutToPlant        = model.DTOutToPlant;
            entity.Corrected10         = model.Corrected10;
            entity.Corrected12         = model.Corrected12;
            entity.PlantNetWt          = model.PlantNetWt;
            entity.Remarks             = model.Remarks;
            entity.TimeVarianceRemarks = model.TimeVarianceRemarks;
            entity.VehicleOrigin       = model.VehicleOrigin;

            var correctedMC = mcRepo.GetCorrectedMC(model.MC, model.PlantNetWt);

            //model.MCStatus = correctedMC.MCStatus;
            entity.Corrected10 = correctedMC.Corrected10;
            entity.Corrected12 = correctedMC.Corrected12;
            entity.Corrected14 = correctedMC.Corrected14;
            //model.Corrected15 = correctedMC.Corrected15;

            dbContext.ReturnedVehicles.Update(entity);
            dbContext.SaveChanges();
            return(entity);
        }