Пример #1
0
        public IActionResult WeighIn([FromBody] Inyard model)
        {
            try
            {
                //NOTE: VALIDATION CALLED SEPERATELY BEFORE CHECKING WEIGHT STABILITY
                model.DateTimeIn = model.IsOfflineIn ? model.DateTimeIn : DateTime.Now;

                if (!ModelState.IsValid)
                {
                    return(InvalidModelStateResult());
                }
                var modelStateDic = transValRepository.ValidateInyardWeighing(model);
                if (modelStateDic.Count > 0)
                {
                    ModelState.AddModelErrors(modelStateDic);
                    return(InvalidModelStateResult());
                }
                return(Accepted(repository.WeighIn(model)));
            }
            catch (Exception ex)
            {
                logger.LogError(ex.GetExceptionMessages());
                return(StatusCode(StatusCodes.Status500InternalServerError, Constants.ErrorMessages.CreateError));
            }
        }
Пример #2
0
 public IActionResult Validate([FromBody] Inyard model)
 {
     try
     {
         if (model.TransactionProcess == SysUtility.Enums.TransactionProcess.WEIGH_IN)
         {
             model.DateTimeIn = model.IsOfflineIn ? model.DateTimeIn : DateTime.Now;
         }
         else if (model.TransactionProcess == SysUtility.Enums.TransactionProcess.WEIGH_OUT)
         {
             model.DateTimeOut = model.IsOfflineOut ?? false ? model.DateTimeOut : DateTime.Now;
         }
         if (!ModelState.IsValid)
         {
             return(InvalidModelStateResult());
         }
         var modelStateDic = transValRepository.ValidateInyardWeighing(model);
         if (modelStateDic.Count > 0)
         {
             ModelState.AddModelErrors(modelStateDic);
             return(InvalidModelStateResult());
         }
         return(Accepted(model));
     }
     catch (Exception ex)
     {
         logger.LogError(ex.GetExceptionMessages());
         return(StatusCode(StatusCodes.Status500InternalServerError, Constants.ErrorMessages.CreateError));
     }
 }
Пример #3
0
        public IActionResult Update(long id, [FromBody] Inyard model)
        {
            try
            {
                if (repository.Get().Count(a => a.InyardId == model.InyardId) == 0)
                {
                    return(NotFound("Selected Inyard Not found found"));
                }
                if (!ModelState.IsValid)
                {
                    return(InvalidModelStateResult());
                }
                var modelStateDic = transValRepository.ValidateInyardWeighing(model);
                if (modelStateDic.Count > 0)
                {
                    ModelState.AddModelErrors(transValRepository.ValidateInyardWeighing(model));
                    return(InvalidModelStateResult());
                }

                return(Accepted(repository.Update(model)));
            }
            catch (Exception ex)
            {
                logger.LogError(ex.GetExceptionMessages());
                return(StatusCode(StatusCodes.Status500InternalServerError, Constants.ErrorMessages.CreateError));
            }
        }
Пример #4
0
        private string formatOfflineInEvent(Inyard model)
        {
            var str = new StringBuilder();

            str.Append($"Reference Number: {model.InyardNum};");
            return(str.ToString());
        }
Пример #5
0
        public SqlRawParameter GetSqlRawParameter(Inyard parameters)
        {
            if (parameters == null)
            {
                return(new SqlRawParameter());
            }
            var sqlQry = new StringBuilder();

            sqlQry.AppendLine("SELECT * FROM Inyards");
            var whereClauses = new List <string>();
            var sqlParams    = new List <SqlParameter>();

            if (!parameters.InyardNum.IsNull())
            {
                sqlParams.Add(new SqlParameter(nameof(parameters.InyardNum).Parametarize(), parameters.InyardNum));
                whereClauses.Add($"{nameof(parameters.InyardNum)} = {nameof(parameters.InyardNum).Parametarize()}");
            }
            if (!parameters.VehicleNum.IsNull())
            {
                sqlParams.Add(new SqlParameter(nameof(parameters.VehicleNum).Parametarize(), parameters.VehicleNum));
                whereClauses.Add($"{nameof(parameters.VehicleNum)} = {nameof(parameters.VehicleNum).Parametarize()}");
            }
            if (whereClauses.Count > 0)
            {
                sqlQry.AppendLine(" WHERE ");
                sqlQry.AppendLine(String.Join(" AND ", whereClauses.ToArray()));
            }

            return(new SqlRawParameter()
            {
                SqlParameters = sqlParams, SqlQuery = sqlQry.ToString()
            });
        }
Пример #6
0
        public bool ValidateMCFile(Inyard model)
        {
            if (model.IsOfflineOut ?? false)
            {
                return(true);
            }
            if (appConfigRepository.AppConfig.TransactionOption.MCInput != SysUtility.Config.Enums.MCInputOption.TESTER_FILE)
            {
                return(true);
            }
            if (appConfigRepository.AppConfig.TransactionOption.ValidateMCFileDate == false)
            {
                return(true);
            }

            if (model.MoistureReaderLogs?.Count > 0)
            {
                var dtLog = model.MoistureReaderLogs.FirstOrDefault().DTLog;
                if (dtLog < model.DateTimeIn ||
                    dtLog > model.DateTimeOut)
                {
                    return(false);
                }
            }

            return(true);
        }
Пример #7
0
        public bool Delete(Inyard model)
        {
            dbContext.Inyards.Remove(model);

            vehicleDeliveryRestrictionRepository.Delete(new VehicleDeliveryRestriction(model.VehicleNum, model.CommodityId)
            {
                DateTimeIn = model.DateTimeIn,
            });

            dbContext.SaveChanges();
            return(true);
        }
Пример #8
0
 public IActionResult Get([FromQuery] Inyard parameters = null)
 {
     try
     {
         var model     = repository.Get(parameters);
         var modelList = model.ToList();
         return(Ok(model));
     }
     catch (Exception ex)
     {
         logger.LogError(ex.GetExceptionMessages());
         return(StatusCode(StatusCodes.Status500InternalServerError, Constants.ErrorMessages.FetchError));
     }
 }
Пример #9
0
        public IActionResult ValidateCommodity([FromBody] Inyard model)
        {
            if (model == null)
            {
                return(NotFound());
            }
            var isValid = transValRepository.ValidateCommodity(model.CommodityId, model.TransactionTypeCode);

            if (General.IsDevelopment)
            {
                logger.LogDebug(ModelState.ToJson());
            }
            string propName = model.TransactionTypeCode == "I" ? "Raw Material" : "Commodity";

            if (isValid)
            {
                return(Accepted(true));
            }
            else
            {
                return(UnprocessableEntity(Constants.ErrorMessages.NotFoundProperty(propName)));
            }
        }
Пример #10
0
        public IActionResult WeighOut([FromBody] Inyard model)
        {
            try
            {
                if (repository.Get().Count(a => a.InyardId == model.InyardId) == 0)
                {
                    return(NotFound("Selected Inyard Not found found"));
                }

                model.DateTimeOut = (model.IsOfflineOut ?? false) ? model.DateTimeOut : DateTime.Now;

                if (!ModelState.IsValid)
                {
                    return(InvalidModelStateResult());
                }
                var modelStateDic = transValRepository.ValidateInyardWeighing(model);
                if (modelStateDic.Count > 0)
                {
                    ModelState.AddModelErrors(modelStateDic);
                    return(InvalidModelStateResult());
                }

                if (model.TransactionTypeCode == "I")
                {
                    return(Accepted(repository.WeighoutPurchase(model)));
                }
                else
                {
                    return(Accepted(repository.WeighoutSale(model)));
                }
            }
            catch (Exception ex)
            {
                logger.LogError(ex.GetExceptionMessages());
                return(StatusCode(StatusCodes.Status500InternalServerError, Constants.ErrorMessages.CreateError));
            }
        }
Пример #11
0
        public SaleTransaction WeighoutSale(Inyard model)
        {
            model.DateTimeOut = model.IsOfflineOut ?? false ? model.DateTimeIn : DateTime.Now;
            var refNum = dbContext.ReferenceNumbers.FirstOrDefault();

            model.MCStatus = 12;
            updateRelatedTableColumns(ref model);

            var weekDetail = new WeekDetail(model.DateTimeOut.Value);

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

            var saleTransaction = new SaleTransaction()
            {
                BaleCount         = model.BaleCount,
                BaleTypeDesc      = baleTypeRepository.Get().Where(a => a.BaleTypeId == model.BaleTypeId).Take(1).Select(a => a.BaleTypeDesc).FirstOrDefault(),
                BaleTypeId        = model.BaleTypeId,
                BalingStationCode = model.BalingStationCode,
                BalingStationName = model.BalingStationName,
                BalingStationNum  = model.BalingStationNum,
                CategoryDesc      = model.CategoryDesc,
                CategoryId        = model.CategoryId,
                Corrected10       = correctedMC.Corrected10,
                Corrected12       = correctedMC.Corrected12,
                Corrected14       = correctedMC.Corrected14,
                Corrected15       = correctedMC.Corrected15,
                CustomerId        = model.ClientId,
                CustomerName      = model.ClientName,
                DateTimeIn        = model.DateTimeIn,
                DateTimeOut       = model.IsOfflineOut ?? false ? model.DateTimeIn : DateTime.Now,
                DriverName        = model.DriverName ?? String.Empty.ToUpper(),
                FirstDay          = weekDetail.FirstDay,
                GrossWt           = model.GrossWt,
                HaulerId          = model.HaulerId ?? 0,
                HaulerName        = model.HaulerName,
                IsOfflineIn       = model.IsOfflineIn,
                IsOfflineOut      = model.IsOfflineOut ?? false,
                LastDay           = weekDetail.LastDay,
                MC       = model.MC,
                MCStatus = model.MCStatus,
                MoistureReaderProcess = model.MoistureReaderProcess,
                MoistureReaderDesc    = model.MoistureReaderDesc,
                MoistureReaderId      = model.MoistureReaderId,
                MoistureSettingsId    = 1,
                OT            = model.OT,
                NetWt         = model.NetWt,
                PM            = model.PM,
                PaperMillId   = model.PaperMillId,
                PaperMillCode = model.PaperMillCode,
                Price         = model.Price,
                PrintCount    = 0,
                ProductId     = model.CommodityId,
                ProductDesc   = model.CommodityDesc,
                ReceiptNum    = refNum.SaleReceiptNum,
                Remarks       = model.Remarks ?? String.Empty.ToUpper(),
                SealNum       = model.SealNum,
                SaleBales     = model.Bales.Select(a => new SaleBale()
                {
                    BaleId = a.BaleId
                }).ToList(),
                SignatoryId     = 1,
                TareWt          = model.TareWt,
                TimeZoneIn      = model.DateTimeIn.GetTimeZone(),
                TimeZoneOut     = model.DateTimeOut.GetTimeZone(),
                Trip            = model.Trip?.ToUpper(),
                VehicleNum      = model.VehicleNum?.ToUpper(),
                VehicleTypeCode = model.VehicleTypeCode,
                VehicleTypeId   = model.VehicleTypeId,
                WeekDay         = weekDetail.WeekDay,
                WeekNum         = weekDetail.WeekNum,
                WeigherInId     = model.WeigherInId,
                WeigherInName   = model.WeigherInName,
                WeigherOutId    = model.WeigherOutId,
                WeigherOutName  = model.WeigherOutName
            };

            using var transaction = dbContext.Database.BeginTransaction();

            dbContext.SaleTransactions.Add(saleTransaction);

            refNum.SaleReceiptNum = String.Format(StringFormats.REFNO_FORMAT, Convert.ToInt32(refNum.SaleReceiptNum) + 1);
            dbContext.ReferenceNumbers.Update(refNum);

            dbContext.Inyards.Remove(model);

            dbContext.SaveChanges();

            transaction.Commit();

            if (model.IsOfflineOut ?? false)
            {
                var auditLog = new AuditLog()
                {
                    AuditLogEventId = auditLogEventRepository.GetOfflineOutEventId(),
                    UserAccountId   = model.WeigherInId,
                    Notes           = formatSalefflineOutEvent(saleTransaction)
                };
                auditLogRepository.Create(auditLog);
            }


            baleRepository.CheckAndCreateBaleOverageReminder();
            balingStationRepository.CheckAndCreateStockStatusReminder();

            return(saleTransaction);
        }
Пример #12
0
        public Inyard updateRelatedTableColumns(ref Inyard outModifiedInyard)
        {
            var vehicleNum = outModifiedInyard.VehicleNum;
            var vehicle    = vehicleRepository.Get()
                             .Include(a => a.VehicleType).DefaultIfEmpty()
                             .Where(a => a.VehicleNum == vehicleNum)
                             .Select(a => new { a.VehicleNum, a.VehicleTypeId, VehicleTypeCode = a.VehicleType == null ? "" : a.VehicleType.VehicleTypeCode }).ToList().FirstOrDefault();

            outModifiedInyard.VehicleTypeId   = vehicle?.VehicleTypeId ?? 0;
            outModifiedInyard.VehicleTypeCode = vehicle?.VehicleTypeCode;

            if (outModifiedInyard.TransactionTypeCode == "I")
            {
                var clientId = outModifiedInyard.ClientId;
                outModifiedInyard.ClientName = supplierRepository.Get()
                                               .Where(a => a.SupplierId == clientId).Select(a => a.SupplierName).FirstOrDefault();

                var commodityId = outModifiedInyard.CommodityId;
                var material    = rawMaterialRepository.Get()
                                  .Where(a => a.RawMaterialId == commodityId)
                                  .Include(a => a.Category).DefaultIfEmpty()
                                  .Select(a => new { a.RawMaterialDesc, a.Price, a.CategoryId, CategoryDesc = a.Category == null ? null : a.Category.CategoryDesc })
                                  .FirstOrDefault();
                var poNum = outModifiedInyard.PONum;

                outModifiedInyard.CommodityDesc = material?.RawMaterialDesc;
                outModifiedInyard.CategoryId    = material?.CategoryId ?? 0;
                outModifiedInyard.CategoryDesc  = material?.CategoryDesc;
                outModifiedInyard.Price         = material?.Price ?? 0;

                var purchaseOrderId = outModifiedInyard.PurchaseOrderId;
                var poDetails       = purchaseOrderRepository.Get()
                                      .Where(a => a.PurchaseOrderId == purchaseOrderId).Select(a => new { a.PONum, a.Price, a.POType }).FirstOrDefault();

                outModifiedInyard.PONum  = poDetails?.PONum ?? String.Empty;
                outModifiedInyard.Price  = poDetails?.Price ?? 0;
                outModifiedInyard.POType = poDetails?.POType;

                var sourceId = outModifiedInyard.SourceId;
                var source   = sourceRepository.Get()
                               .Where(a => a.SourceId == sourceId)
                               .Include(a => a.SourceCategory).DefaultIfEmpty()
                               .Select(a => new { a.SourceDesc, a.SourceCategoryId, SourceCategoryDesc = a.SourceCategory == null ? null : a.SourceCategory.Description })
                               .FirstOrDefault();
                outModifiedInyard.SourceName         = source?.SourceDesc;
                outModifiedInyard.SourceCategoryId   = source?.SourceCategoryId ?? 0;
                outModifiedInyard.SourceCategoryDesc = source?.SourceCategoryDesc;
            }
            else
            {
                var clientId = outModifiedInyard.ClientId;
                outModifiedInyard.ClientName = customerRepository.Get()
                                               .Where(a => a.CustomerId == clientId).Select(a => a.CustomerName).FirstOrDefault();

                var haulerId = outModifiedInyard.HaulerId;
                outModifiedInyard.HaulerName = haulerRepository.Get()
                                               .Where(a => a.HaulerId == haulerId).Select(a => a.HaulerName).FirstOrDefault();

                var commodityId = outModifiedInyard.CommodityId;
                var product     = productRepository.Get()
                                  .Where(a => a.ProductId == commodityId)
                                  .Include(a => a.Category).DefaultIfEmpty()
                                  .Select(a => new { a.ProductDesc, a.CategoryId, CategoyDesc = a.Category == null ? null : a.Category.CategoryDesc })
                                  .FirstOrDefault();
                outModifiedInyard.CommodityDesc = product?.ProductDesc;
                outModifiedInyard.CategoryId    = product?.CategoryId ?? 0;
                outModifiedInyard.CategoryDesc  = product?.CategoyDesc;


                var pmId = outModifiedInyard.PaperMillId;
                outModifiedInyard.PaperMillCode = paperMillRepository.Get()
                                                  .Where(a => a.PaperMillId == pmId).Select(a => a.PaperMillCode).FirstOrDefault();
            }

            var msId = outModifiedInyard.MoistureReaderId;

            outModifiedInyard.MoistureReaderDesc = moistureReaderRepository.Get()
                                                   .Where(a => a.MoistureReaderId == msId).Select(a => a.Description).FirstOrDefault();

            var balingStation = balingStationRepository.Get().Where(a => a.Selected).Take(1).AsNoTracking()
                                .Select(a => new { a.BalingStationNum, a.BalingStationCode, a.BalingStationName }).FirstOrDefault();

            outModifiedInyard.BalingStationNum  = balingStation.BalingStationNum;
            outModifiedInyard.BalingStationCode = balingStation.BalingStationCode;
            outModifiedInyard.BalingStationName = balingStation.BalingStationName;

            var userAccountId = String.Empty;

            if (outModifiedInyard.TransactionProcess == SysUtility.Enums.TransactionProcess.WEIGH_IN ||
                outModifiedInyard.TransactionProcess == SysUtility.Enums.TransactionProcess.UPDATE_WEIGH_IN)
            {
                userAccountId = outModifiedInyard.WeigherInId;
                outModifiedInyard.WeigherInName = userAccountRepository.Get().Where(a => a.UserAccountId == userAccountId)
                                                  .Select(a => a.FullName).FirstOrDefault();
            }
            else if (outModifiedInyard.TransactionProcess == SysUtility.Enums.TransactionProcess.WEIGH_OUT ||
                     outModifiedInyard.TransactionProcess == SysUtility.Enums.TransactionProcess.UPDATE_WEIGH_OUT)
            {
                userAccountId = outModifiedInyard.WeigherOutId;
                outModifiedInyard.WeigherOutName = userAccountRepository.Get().Where(a => a.UserAccountId == userAccountId)
                                                   .Select(a => a.FullName).FirstOrDefault();
            }
            return(outModifiedInyard);
        }
Пример #13
0
        public Inyard Update(Inyard model)
        {
            var entity = dbContext.Inyards.Find(model.InyardId);

            if (entity == null)
            {
                throw new Exception("Selected Record does not exists.");
            }

            updateRelatedTableColumns(ref model);

            var oldVehicleNum  = entity.VehicleNum;
            var oldCommodityId = entity.CommodityId;

            entity.BaleCount        = model.BaleCount;
            entity.BaleTypeId       = model.BaleTypeId;
            entity.ClientId         = model.ClientId;
            entity.ClientName       = model.ClientName?.ToUpper();
            entity.CommodityId      = model.CommodityId;
            entity.CommodityDesc    = model.CommodityDesc;
            entity.DriverName       = model.DriverName?.ToUpper();
            entity.DRNum            = model.DRNum?.ToUpper();;
            entity.HaulerId         = model.HaulerId;
            entity.HaulerName       = model.HaulerName;
            entity.PaperMillId      = model.PaperMillId;
            entity.PaperMillCode    = model.PaperMillCode;
            entity.PONum            = model.PONum;
            entity.POType           = model.POType;
            entity.Price            = model.Price;
            entity.PurchaseOrderId  = model.PurchaseOrderId;
            entity.PlantTruckOrigin = model.PlantTruckOrigin?.ToUpper();
            entity.Remarks          = model.Remarks?.ToUpper();
            entity.SealNum          = model.SealNum?.ToUpper();
            entity.SubSupplierName  = model.SubSupplierName?.ToUpper();
            entity.TimeZoneIn       = model.TimeZoneIn?.ToUpper();
            entity.Trip             = model.Trip?.ToUpper();
            entity.VehicleNum       = model.VehicleNum?.ToUpper();
            entity.WeigherInId      = model.WeigherInId;
            entity.WeigherInName    = model.WeigherInName;

            dbContext.Inyards.Update(entity);
            dbContext.SaveChanges();
            dbContext.Entry <Inyard>(entity).State = EntityState.Detached;

            if (model.IsOfflineIn == false)
            {
                if (oldVehicleNum != model.VehicleNum || oldCommodityId != model.CommodityId)
                {
                    var oldVd = new VehicleDeliveryRestriction(oldVehicleNum, oldCommodityId);
                    var newVD = new VehicleDeliveryRestriction(model.VehicleNum, model.CommodityId);
                    vehicleDeliveryRestrictionRepository.Update(oldVd, newVD);
                }

                if (oldVehicleNum != model.VehicleNum)
                {
                    var oldpg = new PurchaseGrossWtRestriction(oldVehicleNum, model.InitialWt);
                    var newpg = new PurchaseGrossWtRestriction(model.VehicleNum, model.InitialWt);
                    purchaseGrossWtRestrictionRepository.Update(oldpg, newpg);
                }
            }

            return(entity);
        }
Пример #14
0
 public IQueryable <Inyard> Get(Inyard model)
 {
     return(dbContext.Inyards.AsNoTracking());
 }
Пример #15
0
        public Dictionary <string, string> ValidateInyardWeighing(Inyard model)
        {
            var modelStateDict = new Dictionary <string, string>();

            if (model.TransactionProcess == SysUtility.Enums.TransactionProcess.WEIGH_IN ||
                model.TransactionProcess == SysUtility.Enums.TransactionProcess.UPDATE_WEIGH_IN)
            {
                if (model.IsOfflineIn == false)
                {
                    if (model.VehicleNum != model.VehicleNumOld || model.VehicleNumOld == null)
                    {
                        var vehicleDeliverRestriction = new VehicleDeliveryRestriction(model.VehicleNum, model.CommodityId)
                        {
                            DateTimeIn = model.DateTimeIn
                        };
                        var vehicleDeliveryRestrictionResult = vehicleDeliveryRestrictionRepository.CheckRestriction(vehicleDeliverRestriction);
                        if (vehicleDeliveryRestrictionResult != null)
                        {
                            modelStateDict.Add(nameof(Inyard.VehicleNum), ValidationMessages.VehicleDeliveryInvalid(vehicleDeliveryRestrictionResult.DTRestriction));
                        }

                        var purchaseGrossRestrictionresult = new PurchaseGrossWtRestriction(model.VehicleNum, model.CommodityId)
                        {
                            DateTimeIn = model.DateTimeIn
                        };
                        var purchaseGrossRestrictionResult = purchaseGrossWtRestrictionRepository.CheckRestriction(purchaseGrossRestrictionresult);
                        if (purchaseGrossRestrictionResult != null)
                        {
                            modelStateDict.Add(nameof(Inyard.GrossWt), ValidationMessages.PurchaseGrossInvalid(purchaseGrossRestrictionResult.DTRestriction));
                        }
                    }
                }

                #region VALIDATE INSPECTOR/WEIGHER
                if (model.WeigherInId.IsNull())
                {
                    modelStateDict.Add(nameof(model.WeigherInId), ValidationMessages.Required("Inspector is required."));
                }
                else if (UserAccountExists(model.WeigherInId) == false)
                {
                    modelStateDict.Add(nameof(model.BaleTypeId), ValidationMessages.UserNotExists);
                }
                #endregion

                if (modelStateDict.Count > 0)
                {
                    return(modelStateDict);
                }
            }
            else
            {
                #region VALIDATE INSPECTOR/WEIGHER
                if (model.WeigherOutId.IsNull())
                {
                    modelStateDict.Add(nameof(model.WeigherOutId), ValidationMessages.Required("Inspector is required."));
                }
                else if (UserAccountExists(model.WeigherOutId) == false)
                {
                    modelStateDict.Add(nameof(model.WeigherOutId), ValidationMessages.UserNotExists);
                }
                #endregion
            }

            #region VALIDATE VEHICLE NUM
            if (model.VehicleNum.IsNull())
            {
                modelStateDict.Add(nameof(model.VehicleNum), ValidationMessages.Required("Vehicle Number"));
            }
            #endregion

            #region VALIDATE BALE TYPE
            if (model.BaleTypeId.IsNullOrZero())
            {
                modelStateDict.Add(nameof(model.BaleTypeId), ValidationMessages.Required("Bale Type"));
            }
            else if (BaleTypeExists(model.BaleTypeId) == false)
            {
                modelStateDict.Add(nameof(model.BaleTypeId), ValidationMessages.BaleTypeNotExists);
            }
            #endregion

            if (model.TransactionTypeCode == "I")
            {
                if (model.TransactionProcess == SysUtility.Enums.TransactionProcess.WEIGH_IN)
                {
                    if (model.GrossWt == 0)
                    {
                        modelStateDict.Add(nameof(model.GrossWt), ValidationMessages.InvalidWeight);
                    }
                }
                else if (model.TransactionProcess == SysUtility.Enums.TransactionProcess.WEIGH_OUT)
                {
                    if (model.MC == 0)
                    {
                        modelStateDict.Add(nameof(model.MC), ValidationMessages.Required("MC"));
                    }
                    if (model.TareWt == 0 || model.NetWt == 0)
                    {
                        modelStateDict.Add(nameof(model.TareWt), ValidationMessages.InvalidWeight);
                    }

                    var corrected10 = 0M;
                    if (model.MC != 0 & model.NetWt != 0)
                    {
                        var correctedMC = moistureSettingsRepository.GetCorrectedMC(model.MC, model.NetWt);
                        corrected10 = correctedMC.Corrected10;
                    }

                    #region VALIDATE RECEIPT NUM
                    //var receiptNum = refNumRepository.Get().FirstOrDefault().PurchaseReceiptNum;
                    if (dbContext.PurchaseTransactions.AsNoTracking().Count(a => a.ReceiptNum == model.InyardNum) > 0)
                    {
                        modelStateDict.Add(nameof(model.InyardNum), ValidationMessages.InvalidReceiptNum);
                    }
                    #endregion

                    #region VALIDATE MOISTURE READER
                    if (model.MoistureReaderId.IsNullOrZero())
                    {
                        modelStateDict.Add(nameof(model.MoistureReaderId), ValidationMessages.Required("Moisture Reader"));
                    }
                    else if (MoistureReaderExists(model.MoistureReaderId ?? 0) == false)
                    {
                        modelStateDict.Add(nameof(model.MoistureReaderId), ValidationMessages.MoistureReaderNotExists);
                    }
                    #endregion

                    #region VALIDATE MC FILE
                    if (ValidateMCFile(model) == false)
                    {
                        modelStateDict.Add(nameof(model.MC), ValidationMessages.MCFileInvalid);
                    }
                    #endregion
                }

                #region VALIDATE DR
                if (model.DRNum.IsNull())
                {
                    modelStateDict.Add(nameof(model.DRNum), ValidationMessages.Required("DR Number"));
                }
                #endregion
                #region VALIDATE SUPPLIER
                if (model.ClientId.IsNullOrZero())
                {
                    modelStateDict.Add(nameof(model.ClientId), ValidationMessages.Required("Supplier"));
                }
                else if (SupplierExists(model.ClientId) == false)
                {
                    modelStateDict.Add(nameof(model.ClientName), ValidationMessages.SupplierNotExists);
                }
                #endregion

                #region VALIDATE MATERIAL
                if (model.CommodityId.IsNullOrZero())
                {
                    modelStateDict.Add(nameof(model.CommodityId), ValidationMessages.Required("Material"));
                }
                else if (RawMaterialExists(model.CommodityId) == false)
                {
                    modelStateDict.Add(nameof(model.CommodityId), ValidationMessages.RawMaterialNotExists);
                }
                #endregion

                #region VALIDATE SOURCE
                if (model.SourceId.IsNullOrZero())
                {
                    modelStateDict.Add(nameof(model.SourceId), ValidationMessages.Required("Source"));
                }
                else if (SourceExists(model.SourceId) == false)
                {
                    modelStateDict.Add(nameof(model.SourceId), ValidationMessages.SourceNotExists);
                }
                #endregion

                #region VALIDATE PO

                var po = purchaseOrderRepository.ValidatePO(new PurchaseOrder()
                {
                    PurchaseOrderId = model.PurchaseOrderId ?? 0
                });
                if (po == null)
                {
                    modelStateDict.Add(nameof(model.PurchaseOrderId), ValidationMessages.POInvalid);
                }
                else if (po.BalanceRemainingKg < -5000)
                {
                    modelStateDict.Add(nameof(model.PurchaseOrderId), ValidationMessages.PORemainingBalanceInvalid);
                }

                #endregion
            }

            if (model.TransactionTypeCode == "O")
            {
                if (model.TransactionProcess == SysUtility.Enums.TransactionProcess.WEIGH_IN)
                {
                    if (model.TareWt == 0)
                    {
                        modelStateDict.Add(nameof(model.TareWt), ValidationMessages.InvalidWeight);
                    }
                }
                else if (model.TransactionProcess == SysUtility.Enums.TransactionProcess.WEIGH_OUT)
                {
                    if (model.MC == 0)
                    {
                        modelStateDict.Add(nameof(model.MC), ValidationMessages.Required("MC"));
                    }
                    if (model.TareWt == 0 || model.NetWt == 0)
                    {
                        modelStateDict.Add(nameof(model.TareWt), ValidationMessages.InvalidWeight);
                    }

                    var receiptNum = refNumRepository.Get().FirstOrDefault().PurchaseReceiptNum;
                    if (dbContext.SaleTransactions.AsNoTracking().Count(a => a.ReceiptNum == receiptNum) > 0)
                    {
                        modelStateDict.Add(nameof(model.InyardNum), ValidationMessages.InvalidReceiptNum);
                    }
                    if (model.BaleCount == 0)
                    {
                        modelStateDict.Add(nameof(model.BaleCount), ValidationMessages.Required("Bale Count"));
                    }

                    #region VALIDATE MOISTURE READER
                    if (model.MoistureReaderId.IsNullOrZero())
                    {
                        modelStateDict.Add(nameof(model.MoistureReaderId), ValidationMessages.Required("Moisture Reader"));
                    }
                    else if (MoistureReaderExists(model.MoistureReaderId ?? 0) == false)
                    {
                        modelStateDict.Add(nameof(model.MoistureReaderId), ValidationMessages.MoistureReaderNotExists);
                    }
                    #endregion
                }

                #region VALIDATE CUSTOMER / HAULER
                if (model.ClientId.IsNullOrZero() && model.HaulerId.IsNullOrZero())
                {
                    modelStateDict.Add(nameof(model.ClientId), ValidationMessages.Required("Customer/Hauler"));
                }
                if (model.ClientId.IsNullOrZero() == false)
                {
                    if (CustomerExists(model.ClientId) == false)
                    {
                        modelStateDict.Add(nameof(model.ClientId), ValidationMessages.CustomerNotExists);
                    }
                }
                if (model.HaulerId.IsNullOrZero() == false)
                {
                    if (HaulerExists(model.HaulerId ?? 0) == false)
                    {
                        modelStateDict.Add(nameof(model.HaulerId), ValidationMessages.HaulerNotExists);
                    }
                }
                #endregion

                #region VALIDATE PRODUCT
                if (model.CommodityId.IsNullOrZero())
                {
                    modelStateDict.Add(nameof(model.CommodityId), ValidationMessages.Required("Product"));
                }
                else if (ProductExists(model.CommodityId) == false)
                {
                    modelStateDict.Add(nameof(model.CommodityId), ValidationMessages.ProductNotExists);
                }
                #endregion

                #region VALIDATE BALES
                if (model.TransactionProcess == SysUtility.Enums.TransactionProcess.WEIGH_OUT)
                {
                    if (model.Bales.Count() > 0)
                    {
                        var unRelatedBalesCount = model.Bales.Count(a => a.ProductId != model.CommodityId);
                        if (unRelatedBalesCount > 0)
                        {
                            modelStateDict.Add(nameof(model.CommodityId), "Selected bales must match the product type.");
                        }
                        ;
                    }
                }
                #endregion

                #region VALIDATE PAPER MILL
                if (model.PaperMillId.IsNullOrZero())
                {
                    modelStateDict.Add(nameof(model.PaperMillId), ValidationMessages.Required("Paper Mill"));
                }
                else if (PaperMillExists(model.PaperMillId ?? 0) == false)
                {
                    modelStateDict.Add(nameof(model.PaperMillId), ValidationMessages.ProductNotExists);
                }
                #endregion
            }

            return(modelStateDict);
        }
Пример #16
0
        public Inyard WeighIn(Inyard model)
        {
            var refNum = refNumRepository.Get().FirstOrDefault();

            model.InyardNum = refNum?.InyardNum;

            updateRelatedTableColumns(ref model);

            var newInyard = new Inyard()
            {
                BaleCount         = model.BaleCount,
                BaleTypeDesc      = baleTypeRepository.Get().Where(a => a.BaleTypeId == model.BaleTypeId).Take(1).Select(a => a.BaleTypeDesc).FirstOrDefault(),
                BaleTypeId        = model.BaleTypeId,
                BalingStationNum  = model.BalingStationNum,
                BalingStationCode = model.BalingStationCode,
                BalingStationName = model.BalingStationName,
                CategoryDesc      = model.CategoryDesc,
                CategoryId        = model.CategoryId,
                ClientId          = model.ClientId,
                ClientName        = model.ClientName,
                CommodityDesc     = model.CommodityDesc,
                CommodityId       = model.CommodityId,
                DateTimeIn        = model.DateTimeIn,
                DateTimeOut       = null,
                DriverName        = model.DriverName?.ToUpper(),
                DRNum             = model.DRNum?.ToUpper(),
                GrossWt           = model.GrossWt,
                HaulerId          = model.HaulerId,
                HaulerName        = model.HaulerName,
                InyardNum         = model.InyardNum,
                IsOfflineIn       = model.IsOfflineIn,
                IsOfflineOut      = model.IsOfflineOut,
                MC       = model.MC,
                MCStatus = model.MCStatus,
                MoistureReaderProcess = model.MoistureReaderProcess,
                MoistureReaderDesc    = model.MoistureReaderDesc,
                MoistureReaderId      = model.MoistureReaderId,
                MoistureSettingsId    = 1,
                NetWt               = model.NetWt,
                OT                  = model.OT,
                PlantMC             = model.PlantMC,
                PlantNetWt          = model.PlantNetWt,
                PlantTruckOrigin    = model.PlantTruckOrigin?.ToUpper(),
                PM                  = model.PM,
                PaperMillId         = model.PaperMillId,
                PaperMillCode       = model.PaperMillCode,
                PurchaseOrderId     = model.PurchaseOrderId,
                PONum               = model.PONum,
                POType              = model.POType,
                Price               = model.Price,
                Remarks             = model.Remarks?.ToUpper(),
                SealNum             = model.SealNum?.ToUpper(),
                SignatoryId         = 1,
                SourceCategoryDesc  = model.SourceCategoryDesc,
                SourceCategoryId    = model.SourceCategoryId,
                SourceId            = model.SourceId,
                SourceName          = model.SourceName,
                SubSupplierName     = model.SubSupplierName?.ToUpper(),
                TareWt              = model.TareWt,
                TimeZoneIn          = model.DateTimeIn.GetTimeZone(),
                TimeZoneOut         = null,
                TransactionProcess  = model.TransactionProcess,
                TransactionTypeCode = model.TransactionTypeCode,
                Trip                = model.Trip?.ToUpper(),
                VehicleNum          = model.VehicleNum?.ToUpper(),
                VehicleTypeCode     = model.VehicleTypeCode,
                VehicleTypeId       = model.VehicleTypeId,
                WeigherInId         = model.WeigherInId,
                WeigherInName       = model.WeigherInName,
                WeigherOutId        = null,
                WeigherOutName      = null
            };

            dbContext.Inyards.Add(newInyard);

            refNum.InyardNum = String.Format(StringFormats.REFNO_FORMAT, Convert.ToInt32(refNum.InyardNum) + 1);
            dbContext.ReferenceNumbers.Update(refNum);
            dbContext.SaveChanges();

            if (model.TransactionTypeCode == "I" && model.IsOfflineIn == false)
            {
                var vd = new VehicleDeliveryRestriction()
                {
                    VehicleNum  = model.VehicleNum,
                    CommodityId = model.CommodityId,
                    DateTimeIn  = model.DateTimeIn
                };

                vehicleDeliveryRestrictionRepository.Create(vd);

                var pg = new PurchaseGrossWtRestriction()
                {
                    VehicleNum = model.VehicleNum,
                    Weight     = model.InitialWt,
                    DateTimeIn = model.DateTimeIn
                };

                purchaseGrossWtRestrictionRepository.Create(pg);
            }

            if (model.IsOfflineIn)
            {
                var auditLog = new AuditLog()
                {
                    AuditLogEventId   = auditLogEventRepository.GetOfflineInEventId(),
                    UserAccountId     = model.WeigherInId,
                    AuditLogEventDesc = String.Empty,
                    Notes             = formatOfflineInEvent(model)
                };
                auditLogRepository.Create(auditLog);
            }
            return(newInyard);
        }
Пример #17
0
        public PurchaseTransaction WeighoutPurchase(Inyard model)
        {
            var refNum = dbContext.ReferenceNumbers.FirstOrDefault();

            updateRelatedTableColumns(ref model);

            var weekDetail = new WeekDetail(model.DateTimeOut.Value);

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

            var newPurchase = new PurchaseTransaction()
            {
                BaleCount         = model.BaleCount,
                BaleTypeDesc      = baleTypeRepository.Get().Where(a => a.BaleTypeId == model.BaleTypeId).Take(1).Select(a => a.BaleTypeDesc).FirstOrDefault(),
                BaleTypeId        = model.BaleTypeId,
                BalingStationNum  = model.BalingStationNum,
                BalingStationCode = model.BalingStationCode,
                BalingStationName = model.BalingStationName,
                CategoryDesc      = model.CategoryDesc,
                CategoryId        = model.CategoryId,
                Corrected10       = correctedMC.Corrected10,
                Corrected12       = correctedMC.Corrected12,
                Corrected14       = correctedMC.Corrected14,
                Corrected15       = correctedMC.Corrected15,
                DateTimeIn        = model.DateTimeIn,
                DateTimeOut       = model.IsOfflineOut ?? false ? model.DateTimeIn : DateTime.Now,
                DriverName        = model.DriverName?.ToUpper(),
                DRNum             = model.DRNum?.ToUpper(),
                FirstDay          = weekDetail.FirstDay,
                FactoryWt         = model.PlantNetWt,
                GrossWt           = model.GrossWt,
                IsOfflineIn       = model.IsOfflineIn,
                IsOfflineOut      = model.IsOfflineOut ?? false,
                LastDay           = weekDetail.LastDay,
                MC       = model.MC,
                MCDate   = model.MoistureReaderLogs.FirstOrDefault()?.DTLog,
                MCStatus = model.MCStatus,
                MoistureReaderProcess = model.MoistureReaderProcess,
                MoistureReaderDesc    = model.MoistureReaderDesc,
                MoistureReaderId      = model.MoistureReaderId,
                MoistureReaderLogs    = model.MoistureReaderLogs,
                MoistureSettingsId    = 1,
                OT                 = model.OT,
                NetWt              = model.NetWt,
                PM                 = model.PM,
                PurchaseOrderId    = model.PurchaseOrderId,
                PONum              = model.PONum,
                POType             = model.POType,
                Price              = model.Price,
                PrintCount         = 0,
                RawMaterialDesc    = model.CommodityDesc,
                RawMaterialId      = model.CommodityId,
                ReceiptNum         = refNum.PurchaseReceiptNum,
                Remarks            = model.Remarks?.ToUpper(),
                SignatoryId        = 1,
                SourceCategoryDesc = model.SourceCategoryDesc,
                SourceCategoryId   = model.SourceCategoryId,
                SourceId           = model.SourceId,
                SourceName         = model.SourceName,
                SupplierId         = model.ClientId,
                SupplierName       = model.ClientName,
                SubSupplierName    = model.SubSupplierName?.ToUpper(),
                TareWt             = model.TareWt,
                TimeZoneIn         = model.DateTimeIn.GetTimeZone(),
                TimeZoneOut        = model.DateTimeOut.GetTimeZone(),
                Trip               = model.Trip?.ToUpper(),
                VehicleNum         = model.VehicleNum?.ToUpper(),
                VehicleTypeCode    = model.VehicleTypeCode,
                VehicleTypeId      = model.VehicleTypeId,
                WeekDay            = weekDetail.WeekDay,
                WeekNum            = weekDetail.WeekNum,
                WeigherInId        = model.WeigherInId,
                WeigherInName      = model.WeigherInName,
                WeigherOutId       = model.WeigherOutId,
                WeigherOutName     = model.WeigherOutName
            };

            dbContext.PurchaseTransactions.Add(newPurchase);

            if (subSupplierRepository.Get().Count(a => a.SubSupplierName == model.SubSupplierName) == 0)
            {
                dbContext.SubSuppliers.Add(new SubSupplier()
                {
                    SubSupplierName = model.SubSupplierName?.Trim(), IsActive = true
                });
            }

            refNum.PurchaseReceiptNum = String.Format(StringFormats.REFNO_FORMAT, Convert.ToInt32(refNum.PurchaseReceiptNum) + 1);
            dbContext.ReferenceNumbers.Update(refNum);

            dbContext.Inyards.Remove(model);

            dbContext.SaveChanges();

            if (model.IsOfflineOut ?? false)
            {
                var auditLog = new AuditLog()
                {
                    AuditLogEventId = auditLogEventRepository.GetOfflineOutEventId(),
                    UserAccountId   = model.WeigherInId,
                    Notes           = formatPurchaseOfflineOutEvent(newPurchase)
                };
                auditLogRepository.Create(auditLog);
            }

            balingStationRepository.CheckAndCreateStockStatusReminder();

            return(newPurchase);
        }