private static void UpdateOldLot(tblLot oldLot, Lot newLot, Customer customer, bool completedOverride, bool updateSerializationOnly) { if (!updateSerializationOnly) { if (customer != null) { oldLot.Company_IA = customer.Company.Name; } oldLot.Notes = newLot.Notes; oldLot.PurchOrder = newLot.PurchaseOrderNumber; oldLot.ShipperNum = newLot.ShipperNumber; if (string.IsNullOrWhiteSpace(oldLot.Company_IA) || newLot.Vendor != null) { oldLot.Company_IA = newLot.Vendor == null ? null : newLot.Vendor.Name; } LotSyncHelper.SetLotAttributes(oldLot, newLot.Attributes.ToList()); LotSyncHelper.SetTestData(oldLot, newLot); LotSyncHelper.SetLotStat(oldLot, newLot, completedOverride, newLot.ChileLot == null ? null : newLot.ChileLot.ChileProduct.ProductAttributeRanges.ToList()); } oldLot.Serialized = SerializableLot.Serialize(newLot); }
public ChileLot CreateChileLot(LotDTO oldLot, Lot newLot, SerializableLot deserialized, ChileProduct chileProduct, IEnumerable <AttributeName> attributeNames, out List <LotAttributeDefect> lotAttributeDefects) { if (SerializableLot.UpdateLot(newLot, deserialized, oldLot.TestDate != null, out lotAttributeDefects)) { return(_serializedChileLotHelper.CreateSerializedChileLot(oldLot, newLot, chileProduct, attributeNames, ref lotAttributeDefects)); } return(_unserializedChileLotHelper.CreateUnserializedChileLot(oldLot, newLot, chileProduct, attributeNames, out lotAttributeDefects)); }
private static void SetIdentifiable(Lot newLot, LotDTO oldLot) { var deserialized = SerializableLot.Deserialize(oldLot.Serialized); if (deserialized != null) { if (deserialized.LotIdentifiable != null) { newLot.EmployeeId = deserialized.LotIdentifiable.EmployeeKey.EmployeeKeyId; newLot.TimeStamp = deserialized.LotIdentifiable.TimeStamp; } } }
private LotResults GetChileLotResults(LotDTO oldLot, Lot newLot, SerializableLot deserializedLot) { _loadCount.AddRead(EntityTypes.ChileLot); var product = _newContextHelper.GetProduct(oldLot.tblProduct.ProdID); if (product == null) { Log(new CallbackParameters(oldLot, CallbackReason.ChileProductNotLoaded)); return(null); } if (product.ChileProduct == null) { if (product.AdditiveProduct != null) { Log(new CallbackParameters(oldLot, CallbackReason.ExpectedChileProductButFoundAdditive) { Product = product }); } else if (product.PackagingProduct != null) { Log(new CallbackParameters(oldLot, CallbackReason.ExpectedChileProductButFoundPackaging) { Product = product }); } return(null); } var chileProduct = _newContextHelper.GetChileProduct(oldLot.tblProduct.ProdID); if (chileProduct == null) { throw new Exception("Could not find ChileProduct with AttributeRanges."); } List <LotAttributeDefect> lotAttributeDefects; var newChileLot = _createChileLotHelper.CreateChileLot(oldLot, newLot, deserializedLot, chileProduct, _newContextHelper.AttributesNames.Values, out lotAttributeDefects); if (newChileLot == null) { return(null); } return(new LotResults { ChileLot = newChileLot, LotAttributeDefects = lotAttributeDefects }); }
protected override IEnumerable <Results> BirthRecords() { _loadCount.Reset(); foreach (var lot in SelectLotsToLoad(OldContext)) { var serialized = SerializableLot.Deserialize(lot.Serialized); var results = LoadAllowances(lot.Lot, serialized); _loadCount.AddLoaded(EntityTypes.LotCustomerAllowance, (uint)(results.CustomerAllowances.Count)); _loadCount.AddLoaded(EntityTypes.LotContractAllowance, (uint)(results.ContractAllowances.Count)); _loadCount.AddLoaded(EntityTypes.LotCustomerOrderAllowance, (uint)(results.CustomerOrderAllowances.Count)); yield return(results); } }
protected LotEntityObjectMother.LotDTO CreateTblLot(Lot serializedLot, IEnumerable <LotAttributeDefect> attributeDefects = null, Attributes attributes = null) { var tblLot = new LotEntityObjectMother.LotDTO { EntryDate = DateTime.UtcNow.ConvertUTCToLocal(), Serialized = SerializableLot.Serialize(serializedLot, attributeDefects ?? new LotAttributeDefect[0]) }; foreach (var attribute in attributes ?? new Attributes()) { var set = tblLot.AttributeSet(attribute.NameKey); if (set != null) { set((decimal?)attribute.Value); } } return(tblLot); }
private IPackagingProductKey GetPackagingReceived(LotDTO lot, SerializableLot deserializedLot) { if (deserializedLot != null && !string.IsNullOrWhiteSpace(deserializedLot.ReceivedPkgID)) { var packagingProduct = _newContextHelper.GetPackagingProduct(deserializedLot.ReceivedPkgID); if (packagingProduct == null) { Log(new CallbackParameters(lot, CallbackReason.SerializedReceivedPackagingNotLoaded) { ReceivedPkgID = deserializedLot.ReceivedPkgID }); return(null); } return(packagingProduct); } var packagingIds = lot.tblIncomings.Select(i => i.PkgID).Distinct().ToList(); switch (packagingIds.Count) { case 0: return(_newContextHelper.NoPackagingProduct); case 1: return(_newContextHelper.GetPackagingProduct(packagingIds.Single())); default: { var packagingInputs = lot.tblIncomings.GroupBy(dto => dto.PkgID, dto => new { Qty = dto.Quantity }) .Select(group => new { PkgId = group.Key, Qty = group.Sum(g => g.Qty ?? 0), PackagingProduct = _newContextHelper.GetPackagingProduct(group.Key) }); var pkg = packagingInputs.Select(p => new { TotalWeight = p.PackagingProduct.Weight * (double)p.Qty, Packaging = p.PackagingProduct }).OrderByDescending(p => p.TotalWeight).FirstOrDefault(); return(pkg == null ? _newContextHelper.NoPackagingProduct : pkg.Packaging); } } }
private Results LoadAllowances(int lotNumber, SerializableLot deserializedLot) { var results = new Results(); var lotKey = LotNumberParser.ParseLotNumber(lotNumber); foreach (var customer in deserializedLot.CustomerAllowances ?? new List <SerializableLot.CustomerAllowance>()) { var company = _newContextHelper.GetCompany(customer.CompanyName, CompanyType.Customer); if (company == null) { Log(new CallbackParameters(lotNumber, CallbackReason.CustomerNotLoaded) { CustomerAllowance = customer }); } else { results.CustomerAllowances.Add(new LotCustomerAllowance { LotDateCreated = lotKey.LotKey_DateCreated, LotDateSequence = lotKey.LotKey_DateSequence, LotTypeId = lotKey.LotKey_LotTypeId, CustomerId = company.Id }); } } foreach (var contract in deserializedLot.ContractAllowances ?? new List <SerializableLot.ContractAllowance>()) { var contractKey = _newContextHelper.GetContractKey(contract.ContractId); if (contractKey == null) { Log(new CallbackParameters(lotNumber, CallbackReason.ContractNotLoaded) { ContractAllowance = contract }); } else { results.ContractAllowances.Add(new LotContractAllowance { LotDateCreated = lotKey.LotKey_DateCreated, LotDateSequence = lotKey.LotKey_DateSequence, LotTypeId = lotKey.LotKey_LotTypeId, ContractYear = contractKey.ContractKey_Year, ContractSequence = contractKey.ContractKey_Sequence }); } } foreach (var customerOrder in deserializedLot.CustomerOrderAllowances ?? new List <SerializableLot.CustomerOrderAllowance>()) { var order = _newContextHelper.GetInventoryShipmentOrder(customerOrder.OrderNum, InventoryShipmentOrderTypeEnum.SalesOrder); if (order == null) { Log(new CallbackParameters(lotNumber, CallbackReason.SalesOrderNotLoaded) { CustomerOrderAllowance = customerOrder }); } else { results.CustomerOrderAllowances.Add(new LotSalesOrderAllowance { LotDateCreated = lotKey.LotKey_DateCreated, LotDateSequence = lotKey.LotKey_DateSequence, LotTypeId = lotKey.LotKey_LotTypeId, SalesOrderDateCreated = order.DateCreated, SalesOrderSequence = order.Sequence }); } } return(results); }
protected override IEnumerable <LotResults> BirthRecords() { _loadCount.Reset(); var lotKeys = new Dictionary <LotKey, int>(); foreach (var lot in SelectLotsToLoad(OldContext)) { _loadCount.AddRead(EntityTypes.Lot); LotKey lotKey; if (!LotNumberParser.ParseLotNumber(lot.Lot, out lotKey)) { Log(new CallbackParameters(lot, CallbackReason.InvalidLotNumber)); continue; } if (_newContextHelper.LotLoaded(lotKey)) { continue; } if (lotKeys.ContainsKey(lotKey)) { Log(new CallbackParameters(lot, CallbackReason.DuplicateLotNumber) { ExistingLotNumber = lotKeys[lotKey] }); continue; } lotKeys.Add(lotKey, lot.Lot); if (lot.EntryDate == null) { Log(new CallbackParameters(lot, CallbackReason.EntryDateNull)); continue; } if (lot.tblProduct == null) { Log(new CallbackParameters(lot, CallbackReason.NullProductReference)); continue; } var lotType = lotKey.LotKey_LotTypeId.ToLotType(); if (lotType == null) { Log(new CallbackParameters(lot, CallbackReason.InvalidLotType) { LotKey = lotKey }); continue; } var deserialized = SerializableLot.Deserialize(lot.Serialized); var packagingReceived = GetPackagingReceived(lot, deserialized); if (packagingReceived == null) { continue; } Models.Company vendor = null; if (!string.IsNullOrWhiteSpace(lot.Company_IA)) { vendor = _newContextHelper.GetCompany(lot.Company_IA); if (vendor == null) { Log(new CallbackParameters(lot, CallbackReason.CompanyNotLoaded)); } } var newLot = new Lot { LotDateCreated = lotKey.LotKey_DateCreated, LotDateSequence = lotKey.LotKey_DateSequence, LotTypeId = lotKey.LotKey_LotTypeId, EmployeeId = lot.DeterminedEmployeeId != null ? lot.DeterminedEmployeeId.Value : _newContextHelper.DefaultEmployee.EmployeeId, TimeStamp = lot.DeterminedTimestamp.ConvertLocalToUTC() ?? lotKey.LotKey_DateCreated, ReceivedPackagingProductId = packagingReceived.PackagingProductKey_ProductId, VendorId = vendor == null ? (int?)null : vendor.Id, PurchaseOrderNumber = lot.PurchOrder, ShipperNumber = lot.ShipperNum, Notes = lot.Notes }; LotResults results = null; switch (lotType.Value.ToProductType()) { case ProductTypeEnum.Additive: results = GetAdditiveLotResults(lot, newLot); break; case ProductTypeEnum.Chile: results = GetChileLotResults(lot, newLot, deserialized); break; case ProductTypeEnum.Packaging: results = GetPackagingLotResults(lot, newLot); break; } if (results != null) { _loadCount.AddLoaded(EntityTypes.Lot); if (results.ChileLot != null) { _loadCount.AddLoaded(EntityTypes.ChileLot); _loadCount.AddLoaded(EntityTypes.LotAttribute, (uint)results.ChileLot.Lot.Attributes.Count); _loadCount.AddLoaded(EntityTypes.LotDefect, (uint)(results.ChileLot.Lot.LotDefects == null ? 0 : results.ChileLot.Lot.LotDefects.Count)); _loadCount.AddLoaded(EntityTypes.LotDefectResolution, (uint)(results.ChileLot.Lot.LotDefects == null ? 0 : results.ChileLot.Lot.LotDefects.Count(d => d.Resolution != null))); _loadCount.AddLoaded(EntityTypes.LotAttributeDefect, (uint)(results.LotAttributeDefects == null ? 0 : results.LotAttributeDefects.Count)); } if (results.AdditiveLot != null) { _loadCount.AddLoaded(EntityTypes.AdditiveLot); _loadCount.AddLoaded(EntityTypes.LotAttribute, (uint)results.AdditiveLot.Lot.Attributes.Count); } _loadCount.AddLoaded(EntityTypes.PackagingLot, (uint)(results.PackagingLot != null ? 1 : 0)); yield return(results); } } _loadCount.LogResults(l => Log(new CallbackParameters(l))); }