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;
                }
            }
        }
Exemplo n.º 2
0
        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 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)));
        }