Example #1
0
        private tblLot GetOrCreateLot(Lot lot)
        {
            var oldLot = _oldContext.GetLot(lot, false);

            if (oldLot == null)
            {
                var        lotNumber = LotNumberBuilder.BuildLotNumber(lot);
                tblProduct product   = null;
                switch (lot.LotTypeEnum.ToProductType())
                {
                case ProductTypeEnum.Additive:
                    var additiveProduct = _unitOfWork.AdditiveProductRepository.FindByKey(lot.AdditiveLot.ToAdditiveProductKey(), p => p.Product);
                    product = _oldContextHelper.GetProduct(additiveProduct.Product.ProductCode);
                    break;

                case ProductTypeEnum.Chile:
                    var chileProduct = _unitOfWork.ChileProductRepository.FindByKey(lot.ChileLot.ToChileProductKey(), p => p.Product);
                    product = _oldContextHelper.GetProduct(chileProduct.Product.ProductCode);
                    break;

                case ProductTypeEnum.Packaging:
                    var packagingProduct = _unitOfWork.PackagingProductRepository.FindByKey(lot.PackagingLot.ToPackagingProductKey(), p => p.Product);
                    product = GetOrCreatePackagingProduct(packagingProduct, lot, lot.TimeStamp);
                    break;
                }

                oldLot = new tblLot
                {
                    Lot        = lotNumber,
                    EmployeeID = lot.EmployeeId,
                    EntryDate  = DateTime.UtcNow.ConvertUTCToLocal().RoundMillisecondsForSQL(),

                    PTypeID   = lot.LotTypeId,
                    ProdID    = product.ProdID,
                    Julian    = lotNumber.Julian,
                    TargetWgt = 0,
                    Notes     = "Old Context Synchronization"
                };

                _oldContext.tblLots.AddObject(oldLot);
            }

            return(oldLot);
        }
Example #2
0
        private tblLot GetOrCreateLot(ChileLotProduction production, out bool newLot)
        {
            newLot = false;
            var lotNumber = LotNumberBuilder.BuildLotNumber(production);
            var tblLot    = OldContext.tblLots
                            .Include(l => l.tblIncomings, l => l.tblOutgoings)
                            .FirstOrDefault(l => l.Lot == lotNumber);

            if (tblLot == null)
            {
                tblLot = new tblLot
                {
                    Lot        = lotNumber,
                    EmployeeID = production.ResultingChileLot.Lot.EmployeeId,
                    EntryDate  = production.ResultingChileLot.Lot.TimeStamp.ConvertUTCToLocal().RoundMillisecondsForSQL(),

                    PTypeID  = production.LotTypeId,
                    Julian   = lotNumber.Julian,
                    BatchNum = production.LotDateSequence,

                    Shift             = production.Results.ShiftKey,
                    Notes             = "Old Context Synchronization",
                    BatchProdctnOrder = 0,
                    SetTrtmtID        = 0,
                    BatchStatID       = (int?)BatchStatID.Produced,
                    TargetWgt         = 0, //looks like default value set in old context - RI 2014/2/17,
                    tblOutgoings      = new EntityCollection <tblOutgoing>(),
                    tblIncomings      = new EntityCollection <tblIncoming>()
                };
                OldContext.tblLots.AddObject(tblLot);
                newLot = true;
            }

            var product        = OldContextHelper.GetProduct(production.ResultingChileLot.ChileProduct);
            var productionLine = OldContextHelper.GetProductionLine(production.Results.ProductionLineLocation).Value;
            var productionDate = production.LotDateCreated.Date;
            var batchBegTime   = production.Results.ProductionBegin.ConvertUTCToLocal().RoundMillisecondsForSQL();
            var batchEndTime   = production.Results.ProductionEnd.ConvertUTCToLocal().RoundMillisecondsForSQL();

            tblLot.ProdID         = product.ProdID;
            tblLot.ProductionLine = productionLine;
            tblLot.BatchBegTime   = batchBegTime;
            tblLot.BatchEndTime   = batchEndTime;
            tblLot.ProductionDate = productionDate;
            tblLot.Produced       = productionDate;

            return(tblLot);
        }
Example #3
0
        private void SetPickOrder(InventoryShipmentOrder newOrder, tblMove oldOrder)
        {
            var MOrderDetail       = OldContext.tblMoveOrderDetails.Any() ? OldContext.tblMoveOrderDetails.Max(m => m.MOrderDetail).AddSeconds(1) : DateTime.UtcNow.ConvertUTCToLocal();
            var oldDetailsToRemove = oldOrder.tblMoveOrderDetails.ToList();

            foreach (var newItem in newOrder.InventoryPickOrder.Items)
            {
                var oldItem = oldDetailsToRemove.FirstOrDefault();
                if (oldItem == null)
                {
                    oldItem = new tblMoveOrderDetail
                    {
                        MOrderDetail = MOrderDetail
                    };
                    OldContext.tblMoveOrderDetails.AddObject(oldItem);
                    MOrderDetail = MOrderDetail.AddSeconds(1);
                }
                else
                {
                    oldDetailsToRemove.Remove(oldItem);
                }

                oldItem.MoveNum  = newOrder.MoveNum.Value;
                oldItem.Quantity = newItem.Quantity;
                oldItem.ProdID   = OldContextHelper.GetProduct(newItem.Product.ProductCode).ProdID;
                oldItem.PkgID    = OldContextHelper.GetPackaging(newItem.PackagingProduct).PkgID;
                oldItem.NetWgt   = (decimal?)newItem.PackagingProduct.Weight;
                oldItem.TtlWgt   = (decimal?)(newItem.PackagingProduct.Weight * newItem.Quantity);
                oldItem.TrtmtID  = OldContextHelper.GetTreatment(newItem).TrtmtID;

                oldItem.EmployeeID      = null;
                oldItem.CustProductCode = newItem.CustomerProductCode;
                oldItem.CustLot         = newItem.CustomerLotCode;
                oldItem.CustomerID      = newItem.Customer != null ? newItem.Customer.Company.Name : null;
            }

            foreach (var o in oldDetailsToRemove)
            {
                OldContext.tblMoveOrderDetails.DeleteObject(o);
            }
        }
        private tblLot CreateNewLot(LotNumberResult lotNumber, ProductionBatch productionBatch)
        {
            var chileProduct   = OldContextHelper.GetProduct(productionBatch.PackSchedule.ChileProduct);
            var productionLine = OldContextHelper.GetProductionLine(productionBatch.PackSchedule.ProductionLineLocation);
            var batchTypeId    = BatchTypeIDHelper.GetBatchTypeID(productionBatch.PackSchedule.WorkType.Description);

            return(new tblLot
            {
                Lot = lotNumber,
                EmployeeID = productionBatch.Production.ResultingChileLot.Lot.EmployeeId,
                EntryDate = productionBatch.Production.ResultingChileLot.Lot.TimeStamp.ConvertUTCToLocal().RoundMillisecondsForSQL(),

                Notes = productionBatch.Production.ResultingChileLot.Lot.Notes,

                PTypeID = productionBatch.LotTypeId,
                Julian = lotNumber.Julian,
                BatchNum = productionBatch.LotDateSequence,
                ProdID = chileProduct.ProdID,

                PackSchID = productionBatch.PackSchedule.PackSchID,
                BatchTypeID = (int?)batchTypeId,
                Company_IA = productionBatch.PackSchedule.Customer == null ? null : productionBatch.PackSchedule.Customer.Company.Name,

                ProductionDate = productionBatch.PackSchedule.ScheduledProductionDate,
                ProductionLine = productionLine,
                BatchProdctnOrder = 0,     //Seems constant in old context - RI 2014/4/16

                SetTrtmtID = 0,
                LotStat = 0,
                BatchStatID = (int?)BatchStatID.Scheduled,
                TargetWgt = (decimal?)productionBatch.TargetParameters.BatchTargetWeight,
                TgtAsta = (decimal?)productionBatch.TargetParameters.BatchTargetAsta,
                TgtScan = (decimal?)productionBatch.TargetParameters.BatchTargetScan,
                TgtScov = (decimal?)productionBatch.TargetParameters.BatchTargetScoville,
            });
        }
Example #5
0
        private tblLot SyncDehydratedReceived(ChileMaterialsReceived received)
        {
            var lotNumber = LotNumberBuilder.BuildLotNumber(received);
            var product   = OldContextHelper.GetProduct(received.ChileProduct);

            var oldLot = OldContextHelper.OldContext.tblLots
                         .Include(l => l.tblIncomings)
                         .FirstOrDefault(l => l.Lot == lotNumber.LotNumber)
                         ?? AddNewLot(received, lotNumber);

            oldLot.ProdID         = product.ProdID;
            oldLot.LoadNum        = received.LoadNumber;
            oldLot.Company_IA     = received.Supplier.Name;
            oldLot.PurchOrder     = received.ChileLot.Lot.PurchaseOrderNumber;
            oldLot.ShipperNum     = received.ChileLot.Lot.ShipperNumber;
            oldLot.ProductionDate = received.DateReceived;
            oldLot.Produced       = received.DateReceived;
            oldLot.Pellets        = received.ChileMaterialsReceivedType == ChileMaterialsReceivedType.Other;

            var varieties = OldContextHelper.OldContext.tblVarieties.ToList();

            SyncIncomingRecords(received, oldLot, varieties);
            return(oldLot);
        }
Example #6
0
        public override void Synchronize(Func <SyncSalesQuoteParameters> getInput)
        {
            var parameters = getInput();
            var key        = parameters.SalesQuoteKey;
            var salesQuote = UnitOfWork.SalesQuoteRepository.FindByKey(key,
                                                                       q => q.SourceFacility,
                                                                       q => q.Customer.Company,
                                                                       q => q.Broker,
                                                                       q => q.ShipmentInformation,
                                                                       q => q.Items.Select(i => i.Product),
                                                                       q => q.Items.Select(i => i.PackagingProduct.Product),
                                                                       q => q.Items.Select(i => i.Treatment));

            if (salesQuote == null)
            {
                throw new Exception(string.Format("Could not find SalesQuote[{0}].", key));
            }

            var      commitNewContext = false;
            tblQuote tblQuote;

            if (salesQuote.QuoteNum == null || parameters.New)
            {
                var quoteNum = (salesQuote.TimeStamp.Year * 100) - 1;
                quoteNum = OldContext.tblQuotes.Select(q => q.QuoteNum)
                           .Where(q => q > quoteNum)
                           .DefaultIfEmpty(quoteNum)
                           .Max() + 1;
                tblQuote = new tblQuote
                {
                    QuoteNum   = quoteNum,
                    TTypeID    = 19,
                    Status     = 1,
                    PreSample  = false,
                    s_GUID     = Guid.NewGuid(),
                    EmployeeID = salesQuote.EmployeeId,
                    EntryDate  = salesQuote.TimeStamp.ConvertUTCToLocal().RoundMillisecondsForSQL()
                };
                OldContext.tblQuotes.AddObject(tblQuote);

                salesQuote.QuoteNum = quoteNum;
                commitNewContext    = true;
            }
            else
            {
                tblQuote = OldContext.tblQuotes
                           .Include(q => q.tblQuoteDetails)
                           .FirstOrDefault(q => q.QuoteNum == salesQuote.QuoteNum);
                if (tblQuote == null)
                {
                    throw new Exception(string.Format("Could not find tblQuote[{0}]", salesQuote.QuoteNum));
                }
            }

            tblQuote.Date       = salesQuote.QuoteDate;
            tblQuote.DateRecd   = salesQuote.DateReceived;
            tblQuote.From       = salesQuote.CalledBy;
            tblQuote.TakenBy    = salesQuote.TakenBy;
            tblQuote.WHID       = salesQuote.SourceFacility == null ? null : salesQuote.SourceFacility.WHID;
            tblQuote.Company_IA = salesQuote.Customer == null ? null : salesQuote.Customer.Company.Name;
            tblQuote.Broker     = salesQuote.Broker == null ? null : salesQuote.Broker.Name;

            tblQuote.PalletOR        = (decimal?)salesQuote.ShipmentInformation.PalletWeight;
            tblQuote.PalletQty       = salesQuote.ShipmentInformation.PalletQuantity;
            tblQuote.FreightBillType = salesQuote.ShipmentInformation.FreightBillType;
            tblQuote.ShipVia         = salesQuote.ShipmentInformation.ShipmentMethod;
            tblQuote.Driver          = salesQuote.ShipmentInformation.DriverName;
            tblQuote.Carrier         = salesQuote.ShipmentInformation.CarrierName;
            tblQuote.TrlNbr          = salesQuote.ShipmentInformation.TrailerLicenseNumber;
            tblQuote.ContSeal        = salesQuote.ShipmentInformation.ContainerSeal;
            tblQuote.DelDueDate      = salesQuote.ShipmentInformation.RequiredDeliveryDate.ConvertUTCToLocal().RoundMillisecondsForSQL();
            tblQuote.SchdShipDate    = salesQuote.ShipmentInformation.ShipmentDate.ConvertUTCToLocal().RoundMillisecondsForSQL();

            tblQuote.CCompany  = salesQuote.SoldTo.Name;
            tblQuote.CAddress1 = salesQuote.SoldTo.Address.AddressLine1;
            tblQuote.CAddress2 = salesQuote.SoldTo.Address.AddressLine2;
            tblQuote.CAddress3 = salesQuote.SoldTo.Address.AddressLine3;
            tblQuote.CCity     = salesQuote.SoldTo.Address.City;
            tblQuote.CState    = salesQuote.SoldTo.Address.State;
            tblQuote.CZip      = salesQuote.SoldTo.Address.PostalCode;
            tblQuote.CCountry  = salesQuote.SoldTo.Address.Country;

            tblQuote.SCompany  = salesQuote.ShipmentInformation.ShipTo.Name;
            tblQuote.SPhone    = salesQuote.ShipmentInformation.ShipTo.Phone;
            tblQuote.SAddress1 = salesQuote.ShipmentInformation.ShipTo.Address.AddressLine1;
            tblQuote.SAddress2 = salesQuote.ShipmentInformation.ShipTo.Address.AddressLine2;
            tblQuote.SAddress3 = salesQuote.ShipmentInformation.ShipTo.Address.AddressLine3;
            tblQuote.SCity     = salesQuote.ShipmentInformation.ShipTo.Address.City;
            tblQuote.SState    = salesQuote.ShipmentInformation.ShipTo.Address.State;
            tblQuote.SZip      = salesQuote.ShipmentInformation.ShipTo.Address.PostalCode;
            tblQuote.SCountry  = salesQuote.ShipmentInformation.ShipTo.Address.Country;

            tblQuote.Company  = salesQuote.ShipmentInformation.FreightBill.Name;
            tblQuote.Phone    = salesQuote.ShipmentInformation.FreightBill.Phone;
            tblQuote.Email    = salesQuote.ShipmentInformation.FreightBill.EMail;
            tblQuote.Address1 = salesQuote.ShipmentInformation.FreightBill.Address.AddressLine1;
            tblQuote.Address2 = salesQuote.ShipmentInformation.FreightBill.Address.AddressLine2;
            tblQuote.Address3 = salesQuote.ShipmentInformation.FreightBill.Address.AddressLine3;
            tblQuote.City     = salesQuote.ShipmentInformation.FreightBill.Address.City;
            tblQuote.State    = salesQuote.ShipmentInformation.FreightBill.Address.State;
            tblQuote.Zip      = salesQuote.ShipmentInformation.FreightBill.Address.PostalCode;
            tblQuote.Country  = salesQuote.ShipmentInformation.FreightBill.Address.Country;

            var QDetail         = OldContext.tblQuoteDetails.Select(d => d.QDetail).DefaultIfEmpty(DateTime.Now).Max();
            var detailsToRemove = tblQuote.tblQuoteDetails.ToDictionary(d => d.QDetail);

            foreach (var item in salesQuote.Items)
            {
                tblQuoteDetail detail;
                if (item.QDetailID != null)
                {
                    if (detailsToRemove.TryGetValue(item.QDetailID.Value, out detail))
                    {
                        detailsToRemove.Remove(item.QDetailID.Value);
                    }
                    else
                    {
                        throw new Exception(string.Format("Could not find tblQuoteDetail[{0}]", item.QDetailID));
                    }
                }
                else
                {
                    QDetail = QDetail.AddSeconds(1).RoundMillisecondsForSQL();
                    detail  = new tblQuoteDetail
                    {
                        QDetail  = QDetail,
                        QuoteNum = tblQuote.QuoteNum,
                        s_GUID   = Guid.NewGuid()
                    };
                    OldContext.tblQuoteDetails.AddObject(detail);

                    item.QDetailID   = detail.QDetail;
                    commitNewContext = true;
                }

                var product   = OldContextHelper.GetProduct(item.Product.ProductCode);
                var packaging = OldContextHelper.GetPackaging(item.PackagingProduct);
                var treatment = OldContextHelper.GetTreatment(item.Treatment);

                detail.ProdID  = product.ProdID;
                detail.PkgID   = packaging.PkgID;
                detail.TrtmtID = treatment.TrtmtID;

                detail.Quantity        = item.Quantity;
                detail.Price           = (decimal?)item.PriceBase;
                detail.FreightP        = (decimal?)item.PriceFreight;
                detail.TrtnmntP        = (decimal?)item.PriceTreatment;
                detail.WHCostP         = (decimal?)item.PriceWarehouse;
                detail.Rebate          = (decimal?)item.PriceRebate;
                detail.CustProductCode = item.CustomerProductCode;
            }

            foreach (var detail in detailsToRemove.Values)
            {
                OldContext.tblQuoteDetails.DeleteObject(detail);
            }

            OldContext.SaveChanges();
            if (commitNewContext)
            {
                UnitOfWork.Commit();
            }

            Console.WriteLine(ConsoleOutput.SyncTblQuote, tblQuote.QuoteNum);
        }
Example #7
0
        private void SynchronizeOldContract(Contract contract, tblContract oldContract)
        {
            var warehouse = OldContextHelper.GetWarehouse(contract.DefaultPickFromFacility.Name);

            if (warehouse == null)
            {
                throw new Exception(string.Format("Could not find tblWarehouse with WhouseAbbr[{0}].", contract.DefaultPickFromFacility.Name));
            }

            oldContract.EmployeeID = contract.EmployeeId;
            oldContract.KDate      = contract.ContractDate;
            oldContract.BegDate    = contract.TermBegin;
            oldContract.EndDate    = contract.TermEnd;

            oldContract.Contact_IA  = contract.ContactName;
            oldContract.Company_IA  = contract.Customer.Company.Name;
            oldContract.Address1_IA = contract.ContactAddress.AddressLine1;
            oldContract.Address2_IA = contract.ContactAddress.AddressLine2;
            oldContract.Address3_IA = contract.ContactAddress.AddressLine3;
            oldContract.City_IA     = contract.ContactAddress.City;
            oldContract.State_IA    = contract.ContactAddress.State;
            oldContract.Zip_IA      = contract.ContactAddress.PostalCode;
            oldContract.Country_IA  = contract.ContactAddress.Country;
            oldContract.Broker      = contract.Broker.Name;
            oldContract.PmtTerms    = contract.PaymentTerms;
            oldContract.PONum       = contract.CustomerPurchaseOrder;
            oldContract.KType       = contract.ContractType.ToString();
            oldContract.KStatus     = contract.ContractStatus.ToString();
            oldContract.FOB         = contract.FOB;
            oldContract.Comments    = contract.Comments.Notes.AggregateNotes();
            oldContract.Notes2Print = contract.NotesToPrint;
            oldContract.WHID        = warehouse.WHID;

            oldContract.Serialized = SerializableContract.Serialize(contract);

            var existingDetails = oldContract.tblContractDetails != null?oldContract.tblContractDetails.ToList() : new List <tblContractDetail>();

            var kDetailId = OldContext.tblContractDetails.Any() ? OldContext.tblContractDetails.Max(d => d.KDetailID) : DateTime.UtcNow.ConvertUTCToLocal();

            foreach (var item in contract.ContractItems)
            {
                var detail = item.KDetailID == null ? null : existingDetails.FirstOrDefault(d => d.KDetailID == item.KDetailID.Value);
                if (detail == null)
                {
                    kDetailId = kDetailId.AddSeconds(1);
                    detail    = new tblContractDetail
                    {
                        KDetailID  = kDetailId,
                        ContractID = oldContract.ContractID
                    };
                    OldContext.tblContractDetails.AddObject(detail);
                    item.KDetailID    = kDetailId;
                    _commitNewContext = true;
                }
                else
                {
                    existingDetails.Remove(detail);
                }

                detail.ProdID          = OldContextHelper.GetProduct(item.ChileProduct).ProdID;
                detail.PkgID           = OldContextHelper.GetPackaging(item.PackagingProduct).PkgID;
                detail.Quantity        = item.Quantity;
                detail.TrtmtID         = OldContextHelper.GetTreatment(item).TrtmtID;
                detail.Price           = (decimal?)item.PriceBase;
                detail.FreightP        = (decimal?)item.PriceFreight;
                detail.TrtnmntP        = (decimal?)item.PriceTreatment;
                detail.WHCostP         = (decimal?)item.PriceWarehouse;
                detail.Rebate          = (decimal?)item.PriceRebate;
                detail.CustProductCode = item.CustomerProductCode;
                detail.Spec            = item.UseCustomerSpec ? "Cust" : "RVC";
                detail.TtlWgt          = (decimal?)(item.Quantity * item.PackagingProduct.Weight);
            }

            foreach (var detail in existingDetails)
            {
                OldContext.tblContractDetails.DeleteObject(detail);
            }
        }
Example #8
0
        private void SyncOrderItems(SalesOrder salesOrder, tblOrder tblOrder)
        {
            var detailsToDelete = tblOrder.tblOrderDetails.ToList();

            var nowODetail = DateTime.UtcNow.ConvertUTCToLocal().RoundMillisecondsForSQL();
            var oDetail    = OldContext.tblOrderDetails.Any() ? OldContext.tblOrderDetails.Max(o => o.ODetail) : nowODetail;

            if (oDetail < nowODetail)
            {
                oDetail = nowODetail;
            }

            var nowEntryDate  = DateTime.UtcNow.ConvertUTCToLocal().RoundMillisecondsForSQL();
            var lastEntryDate = OldContext.tblStagedFGs.Select(f => f.EntryDate).DefaultIfEmpty(nowEntryDate).Max();

            if (lastEntryDate < nowEntryDate)
            {
                lastEntryDate = nowEntryDate;
            }

            foreach (var orderItem in salesOrder.SalesOrderItems)
            {
                var detail = detailsToDelete.FirstOrDefault(d => d.ODetail == orderItem.ODetail);
                if (detail != null)
                {
                    detailsToDelete.Remove(detail);
                }
                else
                {
                    oDetail = oDetail.AddSeconds(1);
                    detail  = new tblOrderDetail
                    {
                        ODetail      = oDetail,
                        s_GUID       = Guid.NewGuid(),
                        tblStagedFGs = new EntityCollection <tblStagedFG>()
                    };
                    tblOrder.tblOrderDetails.Add(detail);
                    orderItem.ODetail = detail.ODetail;
                    _commitNewContext = true;
                }

                var product   = OldContextHelper.GetProduct(orderItem.InventoryPickOrderItem.Product.ProductCode);
                var packaging = OldContextHelper.GetPackaging(orderItem.InventoryPickOrderItem.PackagingProduct);
                var treatment = OldContextHelper.GetTreatment(orderItem.InventoryPickOrderItem);

                detail.OrderNum        = orderItem.Order.InventoryShipmentOrder.MoveNum.Value;
                detail.ProdID          = product.ProdID;
                detail.PkgID           = packaging.PkgID;
                detail.Quantity        = orderItem.InventoryPickOrderItem.Quantity;
                detail.TrtmtID         = treatment.TrtmtID;
                detail.Price           = (decimal?)orderItem.PriceBase;
                detail.FreightP        = (decimal?)orderItem.PriceFreight;
                detail.TrtnmntP        = (decimal?)orderItem.PriceTreatment;
                detail.WHCostP         = (decimal?)orderItem.PriceWarehouse;
                detail.Rebate          = (decimal?)orderItem.PriceRebate;
                detail.KDetailID       = orderItem.ContractItem == null ? null : orderItem.ContractItem.KDetailID;
                detail.CustProductCode = orderItem.InventoryPickOrderItem.CustomerProductCode;
                detail.CustLot         = orderItem.InventoryPickOrderItem.CustomerLotCode;

                SyncPickedItems(tblOrder, orderItem, ref lastEntryDate, detail);
            }

            foreach (var detail in detailsToDelete)
            {
                foreach (var staged in detail.tblStagedFGs)
                {
                    OldContext.tblStagedFGs.DeleteObject(staged);
                }
                OldContext.tblOrderDetails.DeleteObject(detail);
            }
        }