protected override IEnumerable <PackagingProduct> BirthRecords()
        {
            _loadCount.Reset();

            var productId = _newContext.NextIdentity <Product>(p => p.Id);

            foreach (var package in OldContext.CreateObjectSet <tblPackaging>().ToList())
            {
                _loadCount.AddRead(EntityTypes.PackagingProduct);
                _loadCount.AddRead(EntityTypes.Product);
                _loadCount.AddLoaded(EntityTypes.PackagingProduct);
                _loadCount.AddLoaded(EntityTypes.Product);

                yield return(new PackagingProduct
                {
                    Id = productId,
                    Product = new Product
                    {
                        Id = productId,
                        ProductType = ProductTypeEnum.Packaging,
                        IsActive = package.InActive == false,
                        Name = package.Packaging,
                        ProductCode = package.PkgID.ToString(CultureInfo.InvariantCulture),
                    },
                    Weight = (double)(package.NetWgt ?? 0),
                    PackagingWeight = (double)(package.PkgWgt ?? 0),
                    PalletWeight = (double)(package.PalletWgt ?? 0)
                });

                productId += 1;
            }

            _loadCount.LogResults(l => Log(new CallbackParameters(l)));
        }
        private IEnumerable <TransactionDTO> GetOutgoing()
        {
            return(OldContext.CreateObjectSet <tblOutgoing>()
                   .OrderByDescending(o => o.EntryDate)
                   .Where(o => CutoffDate == null || o.EntryDate > CutoffDate)
                   .Select(o => new TransactionDTO
            {
                EmployeeID = o.EmployeeID,
                EntryDate = o.EntryDate,
                TTypeID = o.TTypeID,

                Lot = o.Lot,
                PkgID = o.PkgID,
                LocID = o.LocID,
                TrtmtID = o.TrtmtID,
                Tote = o.Tote,
                Quantity = -o.Quantity,
                NewLot = o.NewLot,

                OutgoingID = o.ID,
                RinconID = o.RinconID,
                MoveNum = o.MoveNum,
                OrderNum = o.OrderNum,
                AdjustID = o.AdjustID,
                PackSchId = o.PackSchID
            }));
        }
Beispiel #3
0
        protected override IEnumerable <AdditiveProduct> BirthRecords()
        {
            _loadCount.Reset();

            var productId = _newContext.NextIdentity <Product>(p => p.Id);

            foreach (var additiveProduct in OldContext.CreateObjectSet <tblProduct>().ToList().Where(p => p.PTypeID == (int)LotTypeEnum.Additive && p.ProdGrpID != 11 && p.ProdGrpID != 7))
            {
                _loadCount.AddRead(EntityTypes.AdditiveProduct);
                _loadCount.AddRead(EntityTypes.Product);
                _loadCount.AddLoaded(EntityTypes.AdditiveProduct);
                _loadCount.AddLoaded(EntityTypes.Product);

                yield return(new AdditiveProduct
                {
                    Id = productId,
                    Product = new Product
                    {
                        Id = productId,
                        ProductType = ProductTypeEnum.Additive,
                        IsActive = additiveProduct.InActive == false,
                        Name = additiveProduct.Product,
                        ProductCode = additiveProduct.ProdID.ToString(CultureInfo.InvariantCulture)
                    },
                    AdditiveTypeId = additiveProduct.IngrID ?? AdditiveTypeMother.Unknown.Id
                });

                productId += 1;
            }

            _loadCount.LogResults(l => Log(new CallbackParameters(l)));
        }
        private List <tblRinconDTO> SelectRinconRecordsToLoad()
        {
            return(OldContext.CreateObjectSet <tblRincon>()
                   .Where(r => r.Updated != null)
                   .Select(r => new tblRinconDTO
            {
                EmployeeID = r.EmployeeID,
                RinconID = r.RinconID,
                MoveDate = r.MoveDate,
                SheetNum = r.SheetNum,
                PrepBy = r.PrepBy,

                tblRinconDetails = r.tblRinconDetails.Select(d => new tblRinconDetailDTO
                {
                    RDetailID = d.RDetailID,
                    EmployeeID = d.EmployeeID,
                    RinconID = d.RinconID,
                    Lot = d.Lot,
                    PTypeID = d.tblLot.PTypeID,
                    PkgID = d.PkgID,
                    TrtmtID = d.TrtmtID,
                    Quantity = d.Quantity,
                    CurrLocID = d.CurrLocID,
                    DestLocID = d.DestLocID
                })
            })
                   .ToList());
        }
        private List <IGrouping <int, ViewInventoryLoadSelected> > SelectLotsToLoad()
        {
            var minDate = DateTime.UtcNow.Month > 7 ? new DateTime(DateTime.UtcNow.Year, 8, 1) : new DateTime(DateTime.UtcNow.Year - 1, 8, 1);

            return(OldContext.CreateObjectSet <ViewInventoryLoadSelected>()
                   .Where(l =>
                          l.tblLot.PTypeID == (int)LotType &&
                          l.Quantity >= 1 &&
                          !l.tblLot.tblIncomings.Any(i => i.Tote != null && i.Tote != string.Empty && l.tblLot.EntryDate <= minDate))
                   .GroupBy(i => i.Lot).ToList());
        }
 private List <tblProduct> SelectChileProductsToLoad()
 {
     return(OldContext.CreateObjectSet <tblProduct>()
            .Include(p => p.tblProductGrp)
            .Where(p =>
                   p.ProdGrpID != null &&
                   p.ProdGrpID != 7 &&
                   (
                       p.PTypeID == (int)LotTypeEnum.Raw ||
                       p.PTypeID == (int)LotTypeEnum.DeHydrated ||
                       p.PTypeID == (int)LotTypeEnum.WIP ||
                       p.PTypeID == (int)LotTypeEnum.FinishedGood ||
                       p.ProdGrpID == 11 ||
                       p.ProdGrpID == 12
                   ))
            .ToList());
 }
Beispiel #7
0
        protected override IEnumerable <InventoryTreatment> BirthRecords()
        {
            _loadCount.Reset();

            foreach (var treatment in OldContext.CreateObjectSet <tblTreatment>().ToList())
            {
                _loadCount.AddRead(EntityType.InventoryTreatment);
                _loadCount.AddLoaded(EntityType.InventoryTreatment);
                yield return(new InventoryTreatment
                {
                    Id = treatment.TrtmtID,
                    LongName = treatment.TrtmtDesc,
                    ShortName = treatment.Trtmt,
                    Active = treatment.InActive == false,
                });
            }

            _loadCount.LogResults(l => Log(new CallbackParameters(l)));
        }
Beispiel #8
0
 private IEnumerable <tblOrderDTO> GetCodes()
 {
     return(OldContext.CreateObjectSet <tblOrderDetail>()
            .Where(d => d.CustProductCode != null && d.CustProductCode != "")
            .GroupBy(d => d.tblOrder.Company_IA)
            .Select(byCompany => new tblOrderDTO
     {
         Company_IA = byCompany.Key,
         Products = byCompany.GroupBy(d => d.ProdID)
                    .Select(byProduct => new tblProductDTO
         {
             ProdID = byProduct.Key,
             CustProductCodes = byProduct.Select(d => new tblOrderDetailDTO
             {
                 ODetail = d.ODetail,
                 CustProductCode = d.CustProductCode
             })
         })
     }));
 }
        private IEnumerable <TransactionDTO> GetIncoming()
        {
            return(OldContext.CreateObjectSet <tblIncoming>()
                   .OrderByDescending(i => i.EntryDate)
                   .Where(i => CutoffDate == null || i.EntryDate > CutoffDate)
                   .Select(i => new TransactionDTO
            {
                EmployeeID = i.EmployeeID,
                EntryDate = i.EntryDate,
                TTypeID = i.TTypeID,

                Lot = i.Lot,
                PkgID = i.PkgID,
                LocID = i.LocID,
                TrtmtID = i.TrtmtID,
                Tote = i.Tote,
                Quantity = i.Quantity,

                IncomingID = i.ID,
            }));
        }
Beispiel #10
0
        protected override IEnumerable <CustomerProductAttributeRange> BirthRecords()
        {
            _loadCount.Reset();

            foreach (var oldContextSpec in OldContext.CreateObjectSet <SerializedCustomerProdSpecs>().ToList())
            {
                var chileProduct = _newContextHelper.GetChileProduct(oldContextSpec.ProdID);
                if (chileProduct == null)
                {
                    Log(new CallbackParameters(CallbackReason.ChileProductNotLoaded)
                    {
                        Spec = oldContextSpec
                    });
                    continue;
                }

                var customer = _newContextHelper.GetCompany(oldContextSpec.Company_IA, CompanyType.Customer);
                if (customer == null)
                {
                    Log(new CallbackParameters(CallbackReason.CustomerNotLoaded)
                    {
                        Spec = oldContextSpec
                    });
                    continue;
                }

                var dataModels = SerializableCustomerSpec.Deserialize(oldContextSpec.Serialized).ToDataModels(chileProduct, customer);
                foreach (var dataModel in dataModels)
                {
                    _loadCount.AddRead(EntityTypes.CustomerProductAttributeRange);
                    _loadCount.AddLoaded(EntityTypes.CustomerProductAttributeRange);
                    yield return(dataModel);
                }
            }

            _loadCount.LogResults(l => Log(new CallbackParameters(l)));
        }
        protected override IEnumerable <Employee> BirthRecords()
        {
            _loadCount.Reset();

            foreach (var employee in OldContext.CreateObjectSet <tblEmployee>().ToList())
            {
                _loadCount.AddRead(EntityTypes.Employee);

                var newEmployee = new Employee
                {
                    EmployeeId   = employee.EmployeeID,
                    UserName     = employee.Employee,
                    DisplayName  = employee.EName,
                    EmailAddress = "",
                    IsActive     = false // users are activated when their web account is created - vk 12/16/2013
                };

                var existingEmployee = PreservedData.Employees.FirstOrDefault(e => e.UserName == newEmployee.UserName);
                if (existingEmployee != null)
                {
                    newEmployee.EmailAddress = existingEmployee.EmailAddress;
                    newEmployee.IsActive     = existingEmployee.IsActive;
                    newEmployee.Claims       = existingEmployee.Claims;

                    Log(new CallbackParameters(CallbackReason.EmployeeDataPreserved)
                    {
                        Employee = newEmployee
                    });
                }

                _loadCount.AddLoaded(EntityTypes.Employee);
                yield return(newEmployee);
            }

            _loadCount.LogResults(l => Log(new CallbackParameters(l)));
        }
 private List <tblWarehouse> SelectRecordsToLoad()
 {
     return(OldContext.CreateObjectSet <tblWarehouse>()
            .Include("tblLocations")
            .ToList());
 }
        protected List<MovementOrderDTO> SelectMovementOrdersToLoad()
        {
            var transTypes = TransTypeIDs;

            return OldContext.CreateObjectSet<tblMove>()
                .Where(m => transTypes.Contains(m.TTypeID))
                .Select(m => new MovementOrderDTO
                    {
                        Serialized = m.Serialized,
                        
                        TTypeID = m.TTypeID,
                        MoveNum = m.MoveNum,
                        EmployeeID = m.EmployeeID,
                        EntryDate = m.EntryDate,
                        FromWHID = m.WHID,
                        ToWHID = m.C2WHID,
                        PONbr = m.PONbr,
                        Date = m.Date,
                        DateRecd = m.DateRecd,
                        From = m.From,
                        TakenBy = m.TakenBy,
                        Returned = m.Returned,

                        Status = m.Status,
                        PalletOR = m.PalletOR,
                        PalletQty = m.PalletQty,
                        FreightBillType = m.FreightBillType,
                        ShipVia = m.ShipVia,
                        Driver = m.Driver,
                        Carrier = m.Carrier,
                        TrlNbr = m.TrlNbr,
                        ContSeal = m.ContSeal,

                        CCompany = m.CCompany,
                        CAddress1 = m.CAddress1,
                        CAddress2 = m.CAddress2,
                        CAddress3 = m.CAddress3,
                        CCity = m.CCity,
                        CState = m.CState,
                        CZip = m.CZip,
                        CCountry = m.CCountry,

                        SCompany = m.SCompany,
                        SAddress1 = m.SAddress1,
                        SAddress2 = m.SAddress2,
                        SAddress3 = m.SAddress3,
                        SCity = m.SCity,
                        SState = m.SState,
                        SZip = m.SZip,
                        SCountry = m.SCountry,
                        SPhone = m.SPhone,

                        Company = m.Company,
                        Address1 = m.Address1,
                        Address2 = m.Address2,
                        Address3 = m.Address3,
                        City = m.City,
                        State = m.State,
                        Zip = m.Zip,
                        Country = m.Country,
                        Email = m.Email,
                        Phone = m.Phone,
                        Fax = m.Fax,

                        SchdShipDate = m.SchdShipDate,
                        DelDueDate = m.DelDueDate,
                        InternalNotes = m.InternalNotes,
                        ExternalNotes = m.ExternalNotes,
                        SpecialInstructions = m.SpclInstr,

                        tblMoveOrderDetails = m.tblMoveOrderDetails.Select(o => new tblMoveOrderDetail
                            {
                                MOrderDetail = o.MOrderDetail,
                                MoveNum = o.MoveNum,
                                ProdID = o.ProdID,
                                PkgID = o.PkgID,
                                TrtmtID = o.TrtmtID,
                                Quantity = o.Quantity,
                                CustomerID = o.CustomerID,
                                CustLot = o.CustLot,
                                CustProductCode = o.CustProductCode,
                            }),
                        tblMoveDetails = m.tblMoveDetails.Select(d => new tblMoveDetail
                            {
                                EmployeeID = d.EmployeeID,
                                MDetail = d.MDetail,
                                MoveNum = d.MoveNum,
                                Lot = d.Lot,
                                PkgID = d.PkgID,
                                Quantity = d.Quantity,
                                LocID = d.LocID,
                                Move2 = d.Move2,
                                TrtmtID = d.TrtmtID,
                                PType = d.tblLot.PTypeID,
                                CustLot = d.CustLot,
                                CustProductCode = d.CustProductCode
                            }),
                        tblOutgoings = m.tblOutgoings.Select(o => new tblOutgoing
                            {
                                EntryDate = o.EntryDate,
                                EmployeeID = o.EmployeeID,
                                ID = o.ID,
                                Lot = o.Lot,
                                PkgID = o.PkgID,
                                LocID = o.LocID,
                                TrtmtID = o.TrtmtID,
                                Tote = o.Tote,
                                Quantity = o.Quantity,
                                TTypeID = o.TTypeID
                            })
                    }).ToList();
        }
Beispiel #14
0
        private IEnumerable <tblQuoteDTO> SelectRecordsToLoad()
        {
            return(OldContext.CreateObjectSet <tblQuote>()
                   .AsNoTracking()
                   .Select(q => new tblQuoteDTO
            {
                QuoteNum = q.QuoteNum,
                Date = q.Date,
                DateRecd = q.DateRecd,
                From = q.From,
                TakenBy = q.TakenBy,

                EmployeeID = q.EmployeeID,
                EntryDate = q.EntryDate,
                WHID = q.WHID,
                Company_IA = q.Company_IA,
                Broker = q.Broker,

                Status = q.Status,
                PalletOR = q.PalletOR,
                PalletQty = q.PalletQty,
                FreightBillType = q.FreightBillType,
                ShipVia = q.ShipVia,
                Driver = q.Driver,
                Carrier = q.Carrier,
                TrlNbr = q.TrlNbr,
                ContSeal = q.ContSeal,
                DelDueDate = q.DelDueDate,
                SchShipDate = q.SchdShipDate,
                PayTerms = q.PayTerms,
                SpclInstr = q.SpclInstr,
                InternalNotes = q.InternalNotes,
                ExternalNotes = q.ExternalNotes,

                SoldTo = new SoldToLabel
                {
                    Name = q.CCompany,
                    Address = new Address
                    {
                        AddressLine1 = q.CAddress1,
                        AddressLine2 = q.CAddress2,
                        AddressLine3 = q.CAddress3,
                        City = q.CCity,
                        State = q.CState,
                        PostalCode = q.CZip,
                        Country = q.CCountry
                    }
                },
                ShipTo = new ShipToLabel
                {
                    Name = q.SCompany,
                    Phone = q.SPhone,
                    Address = new Address
                    {
                        AddressLine1 = q.SAddress1,
                        AddressLine2 = q.SAddress2,
                        AddressLine3 = q.SAddress3,
                        City = q.SCity,
                        State = q.SState,
                        PostalCode = q.SZip,
                        Country = q.SCountry
                    }
                },
                BillTo = new BillToLabel
                {
                    Name = q.Company,
                    Phone = q.Phone,
                    EMail = q.Email,
                    Fax = q.Fax,
                    Address = new Address
                    {
                        AddressLine1 = q.Address1,
                        AddressLine2 = q.Address2,
                        AddressLine3 = q.Address3,
                        City = q.City,
                        State = q.State,
                        PostalCode = q.Zip,
                        Country = q.Country
                    }
                },

                Details = q.tblQuoteDetails.Select(d => new tblQuoteItemDTO
                {
                    QDetail = d.QDetail,
                    ProdID = d.ProdID,
                    PkgID = d.PkgID,
                    TrtmtID = d.TrtmtID,
                    Quantity = d.Quantity,
                    Price = d.Price,
                    FreightP = d.FreightP,
                    TrtnmntP = d.TrtnmntP,
                    WHCostP = d.WHCostP,
                    Rebate = d.Rebate,
                    CustProductCode = d.CustProductCode
                })
            }));
        }
Beispiel #15
0
        private IEnumerable <tblSampleDTO> SelectRecordsToLoad()
        {
            return(OldContext.CreateObjectSet <tblSample>()
                   .AsNoTracking()
                   .Select(s => new tblSampleDTO
            {
                SampleID = s.SampleID,
                EmployeeID = s.EmployeeID,
                EntryDate = s.EntryDate,

                Comments = s.Comments,
                Notes2Print = s.Notes2Print,

                Contact_IA = s.Contact_IA,
                Company_IA = s.Company_IA,
                Address1_IA = s.Address1_IA,
                Address2_IA = s.Address2_IA,
                Address3_IA = s.Address3_IA,
                City_IA = s.City_IA,
                State_IA = s.State_IA,
                Zip_IA = s.Zip_IA,
                Country_IA = s.Country_IA,

                SContact = s.SContact,
                SCompany = s.SCompany,
                SAddress1 = s.SAddress1,
                SAddress2 = s.SAddress2,
                SAddress3 = s.SAddress3,
                SCity = s.SCity,
                SState = s.SState,
                SZip = s.SZip,
                SCountry = s.SCountry,
                SPhone = s.SPhone,

                Broker = s.Broker,
                Volume = s.Volume,
                SampleDate = s.SampleDate,
                DateRecd = s.DateRecd,
                DateCompleted = s.DateCompleted,
                Priority = s.Priority,
                FOB = s.FOB,
                Status = s.Status,
                Completed = s.Completed,
                Active = s.Active,

                tblSampleNotes = s.tblSampleNotes.Select(n => new tblSampleNoteDTO
                {
                    SamNoteID = n.SamNoteID,
                    SampleJnlDate = n.SampleJnlDate,
                    SampleNote = n.SampleNote,
                    EmployeeID = n.EmployeeID
                }),

                tblSampleDetails = s.tblSampleDetails.Select(d => new tblSampleDetailDTO
                {
                    SampleDetailID = d.SampleDetailID,
                    ProdID = d.ProdID,
                    Lot = d.Lot,
                    Qty = d.Qty,
                    Desc = d.Desc,
                    SampleMatch = d.SampleMatch,

                    tblSampleCustSpec = d.tblSampleCustSpecs.OrderByDescending(c => c.CustSpecID)
                                        .Select(c => new tblSampleCustSpecDTO
                    {
                        CustSpecID = c.CustSpecID,

                        AstaMin = c.AstaMin,
                        AstaMax = c.AstaMax,
                        MoistureMin = c.MoistureMin,
                        MoistureMax = c.MoistureMax,
                        WaterActivityMin = c.WaterActivityMin,
                        WaterActivityMax = c.WaterActivityMax,
                        Mesh = c.Mesh,
                        AoverB = c.AoverB,
                        ScovMin = c.ScovMin,
                        ScovMax = c.ScovMax,
                        ScanMin = c.ScanMin,
                        ScanMax = c.ScanMax,
                        TPCMin = c.TPCMin,
                        TPCMax = c.TPCMax,
                        YeastMin = c.YeastMin,
                        YeastMax = c.YeastMax,
                        MoldMin = c.MoldMin,
                        MoldMax = c.MoldMax,
                        ColiformsMin = c.ColiformsMin,
                        ColiformsMax = c.ColiformsMax,
                        EColiMin = c.EColiMin,
                        EColiMax = c.EColiMax,
                        SalMin = c.SalMin,
                        SalMax = c.SalMax,

                        Notes = c.Notes
                    })
                                        .FirstOrDefault(),
                    tblSampleRVCMatch = d.tblSampleRVCMatches.OrderByDescending(m => m.RVCMatchID)
                                        .Select(m => new tblSampleRVCMatchDTO
                    {
                        RVCMatchID = m.RVCMatchID,

                        Gran = m.Gran,
                        AvgAsta = m.AvgAsta,
                        AoverB = m.AoverB,
                        AvgScov = m.AvgScov,
                        H2O = m.H2O,
                        Scan = m.Scan,
                        Yeast = m.Yeast,
                        Mold = m.Mold,
                        Coli = m.Coli,
                        TPC = m.TPC,
                        EColi = m.EColi,
                        Sal = m.Sal,
                        InsPrts = m.InsPrts,
                        RodHrs = m.RodHrs,

                        Notes = m.Notes
                    })
                                        .FirstOrDefault()
                }),
            }));
        }
        protected override IEnumerable <ChileMaterialsReceived> BirthRecords()
        {
            _loadCount.Reset();

            var dataSource = OldContext.CreateObjectSet <tblIncoming>()
                             .Include(i => i.tblLot, i => i.tblPackaging, i => i.tblVariety)
                             .Where(i => i.TTypeID == (int?)TransType.DeHy || i.TTypeID == (int?)TransType.Other)
                             .GroupBy(i => i.Lot).ToList();

            foreach (var tblIncomings in dataSource)
            {
                _loadCount.AddRead(EntityTypes.ChileMaterialsReceived);

                var oldLot    = tblIncomings.First().tblLot;
                var transType = tblIncomings.Select(i => i.TTypeID).Distinct().Single().ToTransType();

                LotKey lotKey;
                if (!LotNumberParser.ParseLotNumber(tblIncomings.Key, out lotKey))
                {
                    Log(new CallbackParameters(CallbackReason.InvalidLotNumber)
                    {
                        Lot = oldLot
                    });
                    continue;
                }

                var employeeId = oldLot.EmployeeID ?? _newContextHelper.DefaultEmployee.EmployeeId;
                if (oldLot.EmployeeID == null)
                {
                    Log(new CallbackParameters(CallbackReason.DefaultEmployee)
                    {
                        Lot        = oldLot,
                        EmployeeId = employeeId
                    });
                }

                if (oldLot.EntryDate == null)
                {
                    Log(new CallbackParameters(CallbackReason.NullEntryDate)
                    {
                        Lot = oldLot
                    });
                    continue;
                }
                var entryDate = oldLot.EntryDate.Value.ConvertLocalToUTC();

                var supplierNames = tblIncomings.Select(i => i.Company_IA).Distinct().ToList();
                if (supplierNames.Count != 1)
                {
                    Log(new CallbackParameters(CallbackReason.NoSingleSupplierName)
                    {
                        Lot = oldLot
                    });
                    continue;
                }
                var supplierName = (supplierNames.Single() ?? "").Trim();
                if (string.IsNullOrEmpty(supplierName))
                {
                    var locales = tblIncomings.Select(l => l.DehyLocale).Where(l => !string.IsNullOrEmpty(l)).Distinct().ToList();
                    if (locales.Count == 1)
                    {
                        supplierName = locales.Single();
                        Log(new CallbackParameters(CallbackReason.UsedDehyLocaleAsDehydrator)
                        {
                            Lot        = oldLot,
                            DehyLocale = supplierName
                        });
                    }
                }

                var supplier = _newContextHelper.GetCompany(supplierName, CompanyType.Dehydrator, CompanyType.Supplier);
                if (supplier == null)
                {
                    Log(new CallbackParameters(CallbackReason.SupplierNotLoaded)
                    {
                        Lot            = oldLot,
                        DehydratorName = supplierName
                    });
                    continue;
                }

                var chileLot = _newContextHelper.GetChileLotWithProduct(lotKey);
                if (chileLot == null)
                {
                    Log(new CallbackParameters(CallbackReason.ChileLotNotLoaded)
                    {
                        Lot = oldLot
                    });
                    continue;
                }

                var treatmentIds = tblIncomings.Select(i => i.TrtmtID).Distinct().ToList();
                if (treatmentIds.Count != 1)
                {
                    Log(new CallbackParameters(CallbackReason.NoSingleTrmtID)
                    {
                        Lot = oldLot,
                    });
                    continue;
                }
                var treatmentId = treatmentIds.Single();

                var treatment = _newContextHelper.GetInventoryTreatment(treatmentId);
                if (treatment == null)
                {
                    Log(new CallbackParameters(CallbackReason.TreatmentNotLoaded)
                    {
                        Lot    = oldLot,
                        TrmtID = treatmentId
                    });
                }

                var newItems     = new List <ChileMaterialsReceivedItem>();
                var itemSequence = 1;

                var oldItemGroups = tblIncomings.GroupBy(i => new ChileMaterialsItemReceivedKeys(i), new ChileMaterialsItemReceivedKeysEqualityComparer());
                foreach (var oldItems in oldItemGroups)
                {
                    var newItem = CreateItemReceived(oldItems, lotKey, itemSequence);
                    if (newItem != null)
                    {
                        newItems.Add(newItem);
                        ++itemSequence;
                    }
                }

                _loadCount.AddLoaded(EntityTypes.ChileMaterialsReceived);
                _loadCount.AddLoaded(EntityTypes.ChileMaterialsReceivedItem, (uint)newItems.Count);

                yield return(new ChileMaterialsReceived
                {
                    ChileMaterialsReceivedType = transType == TransType.DeHy ? ChileMaterialsReceivedType.Dehydrated : ChileMaterialsReceivedType.Other,
                    EmployeeId = employeeId,
                    TimeStamp = entryDate,

                    LotDateCreated = chileLot.LotDateCreated,
                    LotDateSequence = chileLot.LotDateSequence,
                    LotTypeId = chileLot.LotTypeId,

                    LoadNumber = oldLot.LoadNum,
                    DateReceived = chileLot.LotDateCreated,

                    ChileProductId = chileLot.ChileProductId,
                    SupplierId = supplier.Id,
                    TreatmentId = treatment.Id,

                    Items = newItems
                });
            }

            _loadCount.LogResults(l => Log(new CallbackParameters(l)));
        }
        protected override IEnumerable <PackScheduleResult> BirthRecords()
        {
            _loadCount.Reset();
            _keyReservation = new PackScheduleKeyReservationHelper();

            _batchItemPackSchIds = OldContext.CreateObjectSet <tblBatchItem>()
                                   .Where(i => i.BatchLot != null)
                                   .Select(i => new
            {
                BatchLot = i.BatchLot.Value,
                i.PackSchID
            })
                                   .GroupBy(i => i.BatchLot)
                                   .ToDictionary(i => i.Key, i => i.Select(g => g.PackSchID).ToList());
            var oldPackSchedules = SelectPackSchedulesToLoad(OldContext);

            foreach (var oldPackSchedule in oldPackSchedules)
            {
                var key             = _keyReservation.ParseAndRegisterKey(oldPackSchedule.SerializedKey);
                var requiresKeySync = key == null;
                _loadCount.AddRead(EntityTypes.PackSchedule);

                if (oldPackSchedule.ProdID == null)
                {
                    Log(new CallbackParameters(CallbackReason.NullProduct)
                    {
                        PackSchedule = oldPackSchedule
                    });
                    continue;
                }

                if (oldPackSchedule.Product.PTypeID == null)
                {
                    Log(new CallbackParameters(CallbackReason.NullProductType)
                    {
                        PackSchedule = oldPackSchedule
                    });
                    continue;
                }

                if (oldPackSchedule.PackSchDate == null)
                {
                    Log(new CallbackParameters(CallbackReason.NullPackSchDate)
                    {
                        PackSchedule = oldPackSchedule
                    });
                    continue;
                }

                if (oldPackSchedule.BatchTypeID == null)
                {
                    Log(new CallbackParameters(CallbackReason.NullBatchTypeID)
                    {
                        PackSchedule = oldPackSchedule
                    });
                    continue;
                }

                var chileProduct = _newContextHelper.GetChileProduct(oldPackSchedule.ProdID);
                if (chileProduct == null)
                {
                    Log(new CallbackParameters(CallbackReason.ChileProductNotLoaded)
                    {
                        PackSchedule = oldPackSchedule
                    });
                    continue;
                }

                int?line;
                var lineResult = PackScheduleProductionLineHelper.DetermineProductionLine(oldPackSchedule, out line);
                if (lineResult != PackScheduleProductionLineHelper.ProductionLineResult.FromPackSchedule)
                {
                    Log(new CallbackParameters(lineResult.ToCallbackReason())
                    {
                        PackSchedule = oldPackSchedule
                    });
                }
                if (line == null)
                {
                    continue;
                }

                var productionLine = _newContextHelper.GetProductionLine(line);
                if (productionLine == null)
                {
                    Log(new CallbackParameters(CallbackReason.ProductionLineNotLoaded)
                    {
                        PackSchedule = oldPackSchedule,
                        Line         = line
                    });
                    continue;
                }

                Models.Company customer = null;
                if (!string.IsNullOrWhiteSpace(oldPackSchedule.Company_IA))
                {
                    customer = _newContextHelper.GetCompany(oldPackSchedule.Company_IA, CompanyType.Customer);
                    if (customer == null)
                    {
                        Log(new CallbackParameters(CallbackReason.CustomerNotLoaded)
                        {
                            PackSchedule = oldPackSchedule
                        });
                        continue;
                    }
                }

                key = key ?? _keyReservation.GetNextAndRegisterKey(new PackScheduleKeyReservationHelper.Key
                {
                    PackScheduleKey_DateCreated  = oldPackSchedule.PackSchID.Date,
                    PackScheduleKey_DateSequence = 0
                });
                var packSchedule = new PackScheduleResult
                {
                    RequiresKeySync  = requiresKeySync,
                    PackSchID        = oldPackSchedule.PackSchID,
                    PSNum            = oldPackSchedule.PSNum,
                    DateCreated      = key.PackScheduleKey_DateCreated,
                    SequentialNumber = key.PackScheduleKey_DateSequence,

                    EmployeeId = oldPackSchedule.EmployeeID ?? _newContextHelper.DefaultEmployee.EmployeeId,
                    TimeStamp  = oldPackSchedule.PackSchID.ConvertLocalToUTC(),

                    ChileProductId = chileProduct.Id,

                    ProductionLineLocationId = productionLine.Id,
                    ProductionDeadline       = oldPackSchedule.ProductionDeadline.GetDate(),
                    ScheduledProductionDate  = oldPackSchedule.PackSchDate.Value.Date,

                    DefaultBatchTargetParameters = new ProductionBatchTargetParameters(oldPackSchedule),
                    SummaryOfWork = oldPackSchedule.PackSchDesc,

                    CustomerId  = customer == null ? (int?)null : customer.Id,
                    OrderNumber = oldPackSchedule.OrderNumber
                };

                bool isSerialized;
                if (!ProcessSerializedPackSchedule(packSchedule, oldPackSchedule, out isSerialized))
                {
                    if (isSerialized)
                    {
                        continue;
                    }
                    if (!ProcessUnserializedPackSchedule(packSchedule, oldPackSchedule))
                    {
                        continue;
                    }
                }

                if (packSchedule.EmployeeId == _newContextHelper.DefaultEmployee.EmployeeId)
                {
                    Log(new CallbackParameters(CallbackReason.DefaultEmployee)
                    {
                        PackSchedule      = oldPackSchedule,
                        DefaultEmployeeId = packSchedule.EmployeeId
                    });
                }

                _loadCount.AddLoaded(EntityTypes.PackSchedule);
                packSchedule.ProductionBatches.ForEach(b =>
                {
                    _loadCount.AddLoaded(EntityTypes.ProductionBatch);
                    _loadCount.AddLoaded(EntityTypes.Notebook);
                    _loadCount.AddLoaded(EntityTypes.PickedInventory);
                    _loadCount.AddLoaded(EntityTypes.ChileLot);
                    _loadCount.AddLoaded(EntityTypes.Lot);
                });

                yield return(packSchedule);
            }

            _loadCount.LogResults(l => Log(new CallbackParameters(l)));
        }
Beispiel #18
0
 private List <tblProduct> SelectProductsToLoad()
 {
     return(OldContext.CreateObjectSet <tblProduct>().Where(p => p.ProdGrpID == 7).ToList());
 }
        protected override IEnumerable <Models.Contact> BirthRecords()
        {
            var oldContactsByCompany = OldContext.CreateObjectSet <Contact>().GroupBy(c => c.Company_IA).ToList();

            foreach (var oldCompanyContacts in oldContactsByCompany)
            {
                var oldContactAddressesGroup = oldCompanyContacts.GroupBy(c => new ContactKey(c), ContactKey.ContactKeyEqualityComparer);
                var contactId = 0;
                foreach (var oldContactAddresses in oldContactAddressesGroup)
                {
                    if (oldCompanyContacts.Key == null)
                    {
                        foreach (var contact in oldCompanyContacts)
                        {
                            Log(new CallbackParameters(CallbackReason.NullCompany)
                            {
                                Contact = contact
                            });
                        }
                        continue;
                    }

                    var companies = _newContext.Set <Models.Company>().Where(c => c.Name == oldCompanyContacts.Key).ToList();
                    if (companies.Count != 1)
                    {
                        foreach (var contact in oldCompanyContacts)
                        {
                            Log(new CallbackParameters(CallbackReason.MultipleCompanies)
                            {
                                Contact = contact
                            });
                        }
                        continue;
                    }
                    var company = companies.Single();

                    var addressId = 0;
                    contactId += 1;

                    var contactAddresses = new List <ContactAddress>();
                    foreach (var oldContactAddress in oldContactAddresses.Select(AddressHelper.ToAddress).Distinct(AddressHelper.AddressEqualityComparer))
                    {
                        addressId += 1;
                        contactAddresses.Add(new ContactAddress
                        {
                            CompanyId = company.Id,
                            ContactId = contactId,
                            AddressId = addressId,

                            Address = oldContactAddress
                        });
                    }

                    var name = oldContactAddresses.Key.Name;
                    if (name != null && name.Length > Constants.StringLengths.ContactName)
                    {
                        name = string.Concat(name.Take(Constants.StringLengths.ContactName));
                    }

                    var phoneNumber = oldContactAddresses.Key.PhoneNumber;
                    if (phoneNumber != null && phoneNumber.Length > Constants.StringLengths.PhoneNumber)
                    {
                        phoneNumber = string.Concat(phoneNumber.Take(Constants.StringLengths.PhoneNumber));
                    }

                    var email = oldContactAddresses.Key.EMailAddress;
                    if (email != null && email.Length > Constants.StringLengths.Email)
                    {
                        email = string.Concat(email.Take(Constants.StringLengths.Email));
                    }

                    yield return(new Models.Contact
                    {
                        CompanyId = company.Id,
                        ContactId = contactId,

                        Name = name,
                        PhoneNumber = phoneNumber,
                        EMailAddress = email,

                        Addresses = contactAddresses
                    });
                }
            }
        }
        private IEnumerable <tblOrderDTO> SelectOrdersToLoad()
        {
            return(OldContext.CreateObjectSet <tblOrder>()
                   .AsNoTracking()
                   .Where(o => o.TTypeID == (decimal)TransType.Sale || o.TTypeID == (decimal)TransType.MiscInvoice)
                   .OrderByDescending(o => o.SerializedKey != null)
                   .Select(o => new tblOrderDTO
            {
                SerializedKey = o.SerializedKey,
                OrderNum = o.OrderNum,
                EntryDate = o.EntryDate,
                EmployeeID = o.EmployeeID,
                TTypeID = (TransType)o.TTypeID,

                Status = o.Status,
                Company_IA = o.Company_IA,
                Broker = o.Broker,
                WHID = o.WHID,
                From = o.From,
                TakenBy = o.TakenBy,
                DateRecd = o.DateRecd,
                PayTerms = o.PayTerms,
                PreSample = o.PreSample,
                PONbr = o.PONbr,
                Date = o.Date,
                InvoiceDate = o.InvoiceDate,
                InvoiceNotes = o.InvoiceNotes,
                CreditMemo = o.CreditMemo,
                FreightCharge = o.FCharge,

                PalletOR = o.PalletOR,
                PalletQty = o.PalletQty,
                FreightBillType = o.FreightBillType,
                ShipVia = o.ShipVia,
                Driver = o.Driver,
                Carrier = o.Carrier,
                TrlNbr = o.TrlNbr,
                ContSeal = o.ContSeal,

                DelDueDate = o.DelDueDate,
                SchShipDate = o.SchdShipDate,

                SoldTo = new SoldToLabel
                {
                    Name = o.CCompany,
                    Address = new Address
                    {
                        AddressLine1 = o.CAddress1,
                        AddressLine2 = o.CAddress2,
                        AddressLine3 = o.CAddress3,
                        City = o.CCity,
                        State = o.CState,
                        PostalCode = o.CZip,
                        Country = o.CCountry
                    }
                },
                ShipTo = new ShipToLabel
                {
                    Name = o.SCompany,
                    Phone = o.SPhone,
                    Address = new Address
                    {
                        AddressLine1 = o.SAddress1,
                        AddressLine2 = o.SAddress2,
                        AddressLine3 = o.SAddress3,
                        City = o.SCity,
                        State = o.SState,
                        PostalCode = o.SZip,
                        Country = o.SCountry
                    }
                },
                BillTo = new BillToLabel
                {
                    Name = o.Company,
                    Phone = o.Phone,
                    EMail = o.Email,
                    Fax = o.Fax,
                    Address = new Address
                    {
                        AddressLine1 = o.Address1,
                        AddressLine2 = o.Address2,
                        AddressLine3 = o.Address3,
                        City = o.City,
                        State = o.State,
                        PostalCode = o.Zip,
                        Country = o.Country
                    }
                },

                tblOrderDetails = o.tblOrderDetails.Select(d => new tblOrderDetailDTO
                {
                    ODetail = d.ODetail,
                    ProdID = d.ProdID,
                    PkgID = d.PkgID,
                    Quantity = d.Quantity,
                    TrtmtID = d.TrtmtID,
                    Price = d.Price,
                    FreightP = d.FreightP,
                    TrtnmntP = d.TrtnmntP,
                    WHCostP = d.WHCostP,
                    Rebate = d.Rebate,
                    KDetailID = d.KDetailID,
                    CustProductCode = d.CustProductCode,
                    CustLot = d.CustLot,

                    tblStagedFGs = d.tblStagedFGs.Select(s => new tblStagedFGDTO
                    {
                        EntryDate = s.EntryDate,
                        Lot = s.Lot,
                        TTypeID = s.TTypeID,
                        PkgID = s.PkgID,
                        Quantity = s.Quantity,
                        LocID = s.LocID,
                        TrtmtID = s.TrtmtID,
                        EmployeeID = s.EmployeeID,
                        CustLot = s.CustLot,
                        CustProductCode = s.CustProductCode,
                    }),

                    tblOutgoing = d.tblOutgoing.Select(n => new tblOutgoingDTO
                    {
                        EntryDate = n.EntryDate,
                        Quantity = n.Quantity,
                        Lot = n.Lot,
                        PkgID = n.PkgID,
                        LocID = n.LocID,
                        TrtmtID = n.TrtmtID
                    })
                })
            }));
        }