public VehicleDeliveryRestriction CheckRestriction(VehicleDeliveryRestriction model) { if (appConfigRepository.AppConfig.TransactionOption.VehicleDeliveryRestriction == false) { return(null); } return(dbContext.VehicleDeliveryRestrictions.Where(a => a.VehicleNum == model.VehicleNum && a.CommodityId == model.CommodityId && a.DTRestriction > model.DateTimeIn).AsNoTracking().FirstOrDefault()); }
public bool Delete(VehicleDeliveryRestriction model) { var vehicleDeliveryRestriction = CheckRestriction(model); if (vehicleDeliveryRestriction != null) { dbContext.VehicleDeliveryRestrictions.Remove(vehicleDeliveryRestriction); dbContext.SaveChanges(); } return(true); }
public VehicleDeliveryRestriction Create(VehicleDeliveryRestriction model) { if (appConfigRepository.AppConfig.TransactionOption.VehicleDeliveryRestriction == false) { return(null); } dbContext.Database.ExecuteSqlRaw($"DELETE FROM VehicleDeliveryRestrictions WHERE VehicleNum = '{model.VehicleNum}'"); model.DTRestriction = model.DateTimeIn.AddMinutes(appConfigRepository.AppConfig.TransactionOption.VehicleDeliveryRestrictionPeriod); dbContext.VehicleDeliveryRestrictions.Add(model); dbContext.SaveChanges(); return(model); }
public VehicleDeliveryRestriction Update(VehicleDeliveryRestriction oldModel, VehicleDeliveryRestriction newModel) { if (appConfigRepository.AppConfig.TransactionOption.VehicleDeliveryRestriction == false) { return(null); } var entity = dbContext.VehicleDeliveryRestrictions.Where(a => a.VehicleNum == oldModel.VehicleNum && a.CommodityId == oldModel.CommodityId).AsNoTracking().FirstOrDefault(); if (entity == null) { return(null); } entity.VehicleNum = newModel.VehicleNum; entity.CommodityId = newModel.CommodityId; dbContext.VehicleDeliveryRestrictions.Update(entity); dbContext.SaveChanges(); return(entity); }
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); }
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); }
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); }