protected override IEnumerable <SalesOrderLoad> BirthRecords()
        {
            LoadCount.Reset();

            foreach (var oldOrder in SelectOrdersToLoad())
            {
                var order = CreateCustomerOrder(oldOrder);
                if (order != null)
                {
                    if (IsOldAndEmpty(order))
                    {
                        Log(new CallbackParameters(CallbackReason.OldAndEmpty)
                        {
                            Order = oldOrder
                        });
                        continue;
                    }

                    LoadCount.AddLoaded(EntityType.SalesOrder);
                    if (order.SalesOrderItems != null)
                    {
                        LoadCount.AddLoaded(EntityType.SalesOrderItem, (uint)order.SalesOrderItems.Count);
                    }
                    if (order.SalesOrderPickedItems != null)
                    {
                        LoadCount.AddLoaded(EntityType.SalesOrderPickedItem, (uint)order.SalesOrderPickedItems.Count);
                    }

                    yield return(order);
                }
            }
        }
Example #2
0
        private void LoadItemMatch(tblSampleRVCMatchDTO tblSampleRVCMatch, SampleOrderItem orderItem)
        {
            if (tblSampleRVCMatch == null)
            {
                return;
            }

            LoadCount.AddRead(EntityType.SampleOrderItemMatch);

            orderItem.Match = new SampleOrderItemMatch
            {
                SampleOrderYear     = orderItem.SampleOrderYear,
                SampleOrderSequence = orderItem.SampleOrderSequence,
                ItemSequence        = orderItem.ItemSequence,

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

                Notes = tblSampleRVCMatch.Notes,

                RVCMatchID = tblSampleRVCMatch.RVCMatchID
            };
        }
Example #3
0
        protected override IEnumerable <SampleOrder> BirthRecords()
        {
            foreach (var tblSample in SelectRecordsToLoad())
            {
                var sampleOrder = LoadSampleOrder(tblSample);
                if (sampleOrder != null)
                {
                    LoadCount.AddLoaded(EntityType.SampleOrder);
                    LoadCount.AddLoaded(EntityType.SampleOrderJournalEntry, (uint)sampleOrder.JournalEntries.Count);
                    LoadCount.AddLoaded(EntityType.SampleOrderItem, (uint)sampleOrder.Items.Count);
                    LoadCount.AddLoaded(EntityType.SampleOrderItemSpec, (uint)sampleOrder.Items.Count(i => i.Spec != null));
                    LoadCount.AddLoaded(EntityType.SampleOrderItemMatch, (uint)sampleOrder.Items.Count(i => i.Match != null));

                    yield return(sampleOrder);
                }
            }
        }
Example #4
0
        private void LoadItemSpec(tblSampleCustSpecDTO tblSampleCustSpec, SampleOrderItem orderItem)
        {
            if (tblSampleCustSpec == null)
            {
                return;
            }

            LoadCount.AddRead(EntityType.SampleOrderItemSpec);

            orderItem.Spec = new SampleOrderItemSpec
            {
                SampleOrderYear     = orderItem.SampleOrderYear,
                SampleOrderSequence = orderItem.SampleOrderSequence,
                ItemSequence        = orderItem.ItemSequence,

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

                Notes = tblSampleCustSpec.Notes,

                CustSpecID = tblSampleCustSpec.CustSpecID
            };
        }
Example #5
0
        private void LoadNotes(SampleOrder sampleOrder, tblSampleDTO tblSample)
        {
            var journalEntries = new List <SampleOrderJournalEntry>();
            var noteSequence   = 1;

            foreach (var tblSampleNote in tblSample.tblSampleNotes)
            {
                LoadCount.AddRead(EntityType.SampleOrderJournalEntry);

                var employeeId = _newContextHelper.DefaultEmployee.EmployeeId;
                if (tblSampleNote.EmployeeID != null)
                {
                    employeeId = tblSampleNote.EmployeeID.Value;
                }
                else
                {
                    Log(new CallbackParameters(CallbackReason.tblSampleNote_EmployeeID_Null)
                    {
                        tblSampleNote = tblSampleNote
                    });
                }

                journalEntries.Add(new SampleOrderJournalEntry
                {
                    SampleOrderYear     = sampleOrder.Year,
                    SampleOrderSequence = sampleOrder.Sequence,
                    EntrySequence       = noteSequence++,

                    EmployeeId = employeeId,
                    Date       = tblSampleNote.SampleJnlDate,
                    Text       = tblSampleNote.SampleNote,

                    SamNoteID = tblSampleNote.SamNoteID
                });
            }

            sampleOrder.JournalEntries = journalEntries;
        }
Example #6
0
        private void LoadDetails(SampleOrder sampleOrder, tblSampleDTO tblSample)
        {
            var items        = new List <SampleOrderItem>();
            var itemSequence = 1;

            foreach (var tblSampleDetail in tblSample.tblSampleDetails)
            {
                LoadCount.AddRead(EntityType.SampleOrderItem);

                var product = _newContextHelper.GetProduct(tblSampleDetail.ProdID);
                if (product == null && tblSampleDetail.ProdID != null)
                {
                    Log(new CallbackParameters(CallbackReason.tblSampleDetail_MissingProduct)
                    {
                        tblSampleDetail = tblSampleDetail
                    });
                    continue;
                }

                LotKey lotKey = null;
                if (tblSampleDetail.Lot != null)
                {
                    lotKey = LotNumberParser.ParseLotNumber(tblSampleDetail.Lot.Value);
                    if (lotKey == null)
                    {
                        Log(new CallbackParameters(CallbackReason.tblSampleDetail_InvalidLotNumber)
                        {
                            tblSampleDetail = tblSampleDetail
                        });
                        continue;
                    }

                    if (!_newContextHelper.LotLoaded(lotKey))
                    {
                        Log(new CallbackParameters(CallbackReason.tblSampleDetail_MissingLot)
                        {
                            tblSampleDetail = tblSampleDetail
                        });
                        continue;
                    }
                }

                var sampleOrderItem = new SampleOrderItem
                {
                    SampleOrderYear     = sampleOrder.Year,
                    SampleOrderSequence = sampleOrder.Sequence,
                    ItemSequence        = itemSequence++,

                    ProductId = product == null ? (int?)null : product.ProductKey.ProductKey_ProductId,

                    LotDateCreated  = lotKey == null ? (DateTime?)null : lotKey.LotKey_DateCreated,
                    LotDateSequence = lotKey == null ? (int?)null : lotKey.LotKey_DateSequence,
                    LotTypeId       = lotKey == null ? (int?)null : lotKey.LotKey_LotTypeId,

                    Quantity            = (int)(tblSampleDetail.Qty ?? 0),
                    Description         = tblSampleDetail.Desc,
                    CustomerProductName = tblSampleDetail.SampleMatch,

                    SampleDetailID = tblSampleDetail.SampleDetailID,
                };

                LoadItemSpec(tblSampleDetail.tblSampleCustSpec, sampleOrderItem);
                LoadItemMatch(tblSampleDetail.tblSampleRVCMatch, sampleOrderItem);

                items.Add(sampleOrderItem);
            }

            sampleOrder.Items = items;
        }
Example #7
0
        private SampleOrder LoadSampleOrder(tblSampleDTO tblSample)
        {
            LoadCount.AddRead(EntityType.SampleOrder);

            var employeeId = _newContextHelper.DefaultEmployee.EmployeeId;

            if (tblSample.EmployeeID != null)
            {
                employeeId = tblSample.EmployeeID.Value;
            }
            else
            {
                Log(new CallbackParameters(CallbackReason.tblSample_EmployeeID_Null)
                {
                    tblSample = tblSample
                });
            }

            var requestCustomer = _newContextHelper.GetCompany(tblSample.Company_IA, CompanyType.Customer);

            if (requestCustomer == null && !string.IsNullOrWhiteSpace(tblSample.Company_IA))
            {
                Log(new CallbackParameters(CallbackReason.tblSample_MissingCompanyIA)
                {
                    tblSample = tblSample
                });
                return(null);
            }

            var broker = _newContextHelper.GetCompany(tblSample.Broker, CompanyType.Broker);

            if (broker == null && !string.IsNullOrWhiteSpace(tblSample.Broker))
            {
                Log(new CallbackParameters(CallbackReason.tblSample_MissingBroker)
                {
                    tblSample = tblSample
                });
                return(null);
            }

            var status = ParseStatus(tblSample.Status);

            if (status == null)
            {
                Log(new CallbackParameters(CallbackReason.tblSample_InvalidStatus)
                {
                    tblSample = tblSample
                });
                return(null);
            }

            var dateDue       = tblSample.SampleDate ?? tblSample.EntryDate.GetDate().Value;
            var dateReceived  = tblSample.DateRecd ?? tblSample.EntryDate.GetDate().Value;
            var dateCompleted = tblSample.DateCompleted;

            if (tblSample.Completed && dateCompleted == null)
            {
                dateCompleted = tblSample.SampleDate ?? tblSample.EntryDate.Value;
            }

            var sampleOrderKey = ParseSampleOrderKey(tblSample.SampleID);
            var sampleOrder    = new SampleOrder
            {
                Year       = sampleOrderKey.SampleOrderKey_Year,
                Sequence   = sampleOrderKey.SampleOrderKey_Sequence,
                EmployeeId = employeeId,
                TimeStamp  = tblSample.EntryDate.Value.ConvertLocalToUTC(),

                Comments       = tblSample.Comments,
                PrintNotes     = tblSample.Notes2Print,
                Volume         = (double)(tblSample.Volume ?? 0),
                DateDue        = dateDue,
                DateReceived   = dateReceived,
                DateCompleted  = dateCompleted,
                ShipmentMethod = tblSample.Priority,
                FOB            = tblSample.FOB,
                Status         = status.Value,
                Active         = tblSample.Active,

                RequestCustomerId = requestCustomer == null ? (int?)null : requestCustomer.Id,
                BrokerId          = broker == null ? (int?)null : broker.Id,

                Request = new ShippingLabel
                {
                    Name    = tblSample.Contact_IA,
                    Address = new Address
                    {
                        AddressLine1 = tblSample.Address1_IA,
                        AddressLine2 = tblSample.Address2_IA,
                        AddressLine3 = tblSample.Address3_IA,
                        City         = tblSample.City_IA,
                        State        = tblSample.State_IA,
                        PostalCode   = tblSample.Zip_IA,
                        Country      = tblSample.Country_IA,
                    }
                },

                ShipToCompany = tblSample.SCompany,
                ShipTo        = new ShippingLabel
                {
                    Name    = tblSample.SContact,
                    Phone   = tblSample.SPhone,
                    Address = new Address
                    {
                        AddressLine1 = tblSample.SAddress1,
                        AddressLine2 = tblSample.SAddress2,
                        AddressLine3 = tblSample.SAddress3,
                        City         = tblSample.SCity,
                        State        = tblSample.SState,
                        PostalCode   = tblSample.SZip,
                        Country      = tblSample.SCountry
                    }
                },

                SampleID = tblSample.SampleID
            };

            LoadNotes(sampleOrder, tblSample);
            LoadDetails(sampleOrder, tblSample);

            return(sampleOrder);
        }
Example #8
0
        protected override IEnumerable <SalesQuote> BirthRecords()
        {
            var dateSequences = new Dictionary <DateTime, int>();

            foreach (var oldQuote in SelectRecordsToLoad())
            {
                LoadCount.AddRead(EntityType.SalesQuote);

                var sourceFacility = _newContextHelper.GetFacility(oldQuote.WHID);
                if (oldQuote.WHID != null && sourceFacility == null)
                {
                    Log(new CallbackParameters(CallbackReason.FacilityNotFound)
                    {
                        tblQuote = oldQuote
                    });
                    continue;
                }

                var customer = _newContextHelper.GetCompany(oldQuote.Company_IA, CompanyType.Customer);
                if (oldQuote.Company_IA != null && customer == null)
                {
                    Log(new CallbackParameters(CallbackReason.CompanyNotFound)
                    {
                        tblQuote = oldQuote
                    });
                    continue;
                }

                var broker = _newContextHelper.GetCompany(oldQuote.Broker, CompanyType.Broker);
                if (oldQuote.Broker != null && broker == null)
                {
                    Log(new CallbackParameters(CallbackReason.BrokerNotFound)
                    {
                        tblQuote = oldQuote
                    });
                    continue;
                }

                var dateCreated = oldQuote.EntryDate.Value.Date;

                var shipmentInformation = new ShipmentInformation
                {
                    DateCreated = dateCreated,
                    Sequence    = _newContextHelper.ShipmentInformationKeys.GetNextSequence(dateCreated),

                    Status               = ShipmentStatus.Scheduled,
                    PalletWeight         = (double?)oldQuote.PalletOR,
                    PalletQuantity       = (int)(oldQuote.PalletQty ?? 0),
                    FreightBillType      = oldQuote.FreightBillType,
                    ShipmentMethod       = oldQuote.ShipVia,
                    DriverName           = oldQuote.Driver,
                    CarrierName          = oldQuote.Carrier,
                    TrailerLicenseNumber = oldQuote.TrlNbr,
                    ContainerSeal        = oldQuote.ContSeal,

                    RequiredDeliveryDate = oldQuote.DelDueDate,
                    ShipmentDate         = oldQuote.Date ?? oldQuote.SchShipDate,
                    InternalNotes        = oldQuote.InternalNotes,
                    ExternalNotes        = oldQuote.ExternalNotes,
                    SpecialInstructions  = oldQuote.SpclInstr,

                    ShipTo      = oldQuote.ShipTo,
                    FreightBill = oldQuote.BillTo
                };

                int sequence;
                if (!dateSequences.TryGetValue(dateCreated, out sequence))
                {
                    sequence = 0;
                }

                var employeeId = _newContextHelper.DefaultEmployee.EmployeeId;
                if (oldQuote.EmployeeID == null)
                {
                    Log(new CallbackParameters(CallbackReason.DefaultEmployee)
                    {
                        tblQuote = oldQuote
                    });
                }
                else
                {
                    employeeId = oldQuote.EmployeeID.Value;
                }

                var salesQuote = new SalesQuote
                {
                    TimeStamp  = oldQuote.EntryDate.Value.ConvertLocalToUTC(),
                    EmployeeId = employeeId,

                    DateCreated = dateCreated,
                    Sequence    = sequence,

                    QuoteNum     = oldQuote.QuoteNum,
                    QuoteDate    = oldQuote.Date.Value,
                    DateReceived = oldQuote.DateRecd,
                    CalledBy     = oldQuote.From,
                    TakenBy      = oldQuote.TakenBy,
                    PaymentTerms = oldQuote.PayTerms,

                    SourceFacilityId = sourceFacility == null ? (int?)null : sourceFacility.Id,
                    CustomerId       = customer == null ? (int?)null : customer.Id,
                    BrokerId         = broker == null ? (int?)null : broker.Id,

                    ShipmentInfoDateCreated = shipmentInformation.DateCreated,
                    ShipmentInfoSequence    = shipmentInformation.Sequence,
                    ShipmentInformation     = shipmentInformation,

                    SoldTo = oldQuote.SoldTo,

                    Items = new List <SalesQuoteItem>()
                };

                var itemSequence = 0;
                foreach (var detail in oldQuote.Details)
                {
                    LoadCount.AddRead(EntityType.SalesQuoteItem);

                    var product = _newContextHelper.GetProduct(detail.ProdID);
                    if (product == null)
                    {
                        Log(new CallbackParameters(CallbackReason.ProductNotFound)
                        {
                            tblQuoteDetail = detail
                        });
                        continue;
                    }

                    var packaging = _newContextHelper.GetPackagingProduct(detail.PkgID);
                    if (packaging == null)
                    {
                        Log(new CallbackParameters(CallbackReason.PackagingNotFound)
                        {
                            tblQuoteDetail = detail
                        });
                        continue;
                    }

                    var treatment = _newContextHelper.GetInventoryTreatment(detail.TrtmtID ?? 0);
                    if (treatment == null)
                    {
                        Log(new CallbackParameters(CallbackReason.TreatmentNotFound)
                        {
                            tblQuoteDetail = detail
                        });
                        continue;
                    }

                    salesQuote.Items.Add(new SalesQuoteItem
                    {
                        DateCreated  = salesQuote.DateCreated,
                        Sequence     = salesQuote.Sequence,
                        ItemSequence = itemSequence++,

                        QDetailID = detail.QDetail,

                        ProductId          = product.ProductKey.ProductKey_ProductId,
                        PackagingProductId = packaging.Id,
                        TreatmentId        = treatment.Id,

                        Quantity            = (int)(detail.Quantity ?? 0),
                        PriceBase           = (double)(detail.Price ?? 0),
                        PriceFreight        = (double)(detail.FreightP ?? 0),
                        PriceTreatment      = (double)(detail.TrtnmntP ?? 0),
                        PriceWarehouse      = (double)(detail.WHCostP ?? 0),
                        PriceRebate         = (double)(detail.Rebate ?? 0),
                        CustomerProductCode = detail.CustProductCode,
                    });
                }

                LoadCount.AddLoaded(EntityType.SalesQuote);
                LoadCount.AddLoaded(EntityType.SalesQuoteItem, (uint)salesQuote.Items.Count);

                yield return(salesQuote);

                if (!dateSequences.ContainsKey(dateCreated))
                {
                    dateSequences.Add(dateCreated, sequence);
                }
                dateSequences[dateCreated] += 1;
            }
        }
        protected override IEnumerable <TreatmentOrder> BirthRecords()
        {
            foreach (var order in SelectMovementOrdersToLoad())
            {
                var entityType = GetEntityType(order.TTypeID);
                LoadCount.AddRead(entityType);

                if (order.EntryDate == null)
                {
                    Log(new CallbackParameters(CallbackReason.NullEntryDate)
                    {
                        MovementOrder = order
                    });
                    continue;
                }
                var dateCreated = order.EntryDate.Value.ConvertLocalToUTC().Date;

                var sourceFacility = NewContextHelper.GetFacility(order.FromWHID);
                if (sourceFacility == null)
                {
                    Log(new CallbackParameters(CallbackReason.SourceWarehouseNotLoaded)
                    {
                        MovementOrder = order
                    });
                    continue;
                }

                var destinationFacility = NewContextHelper.GetFacility(order.ToWHID);
                if (destinationFacility == null)
                {
                    Log(new CallbackParameters(CallbackReason.TreatmentFaciltyNotLoaded)
                    {
                        MovementOrder = order
                    });
                    continue;
                }
                destinationFacility.FacilityType = FacilityType.Treatment;

                var deserialized = SerializableMove.Deserialize(order.Serialized);

                var treatment = DeterminedOrderTreatment(order, deserialized);
                if (treatment == null)
                {
                    Log(new CallbackParameters(CallbackReason.TreatmentNotDetermined)
                    {
                        MovementOrder = order
                    });
                    continue;
                }

                var shipmentDate = order.Date.GetDate() ?? order.EntryDate.GetDate();
                if (shipmentDate == null)
                {
                    Log(new CallbackParameters(CallbackReason.UndeterminedShipmentDate)
                    {
                        MovementOrder = order
                    });
                    continue;
                }

                var sequence      = PickedInventoryKeyHelper.Singleton.GetNextSequence(dateCreated);
                var shipmentOrder = SetOrderProperties(new InventoryShipmentOrder
                {
                    DateCreated             = dateCreated,
                    Sequence                = sequence,
                    ShipmentInfoDateCreated = dateCreated,
                    ShipmentInfoSequence    = NewContextHelper.ShipmentInformationKeys.GetNextSequence(dateCreated),
                    DestinationFacilityId   = destinationFacility.Id,
                    SourceFacilityId        = sourceFacility.Id
                }, order);
                if (shipmentOrder == null)
                {
                    continue;
                }

                var treatmentOrder = new TreatmentOrder
                {
                    DateCreated = dateCreated,
                    Sequence    = sequence,

                    InventoryTreatmentId   = treatment.InventoryTreatmentKey_Id,
                    InventoryShipmentOrder = shipmentOrder,
                    Returned = order.Returned.ConvertLocalToUTC()
                };
                treatmentOrder.InventoryShipmentOrder.ShipmentInformation = CreateShipmentInformation(treatmentOrder.InventoryShipmentOrder, order);
                treatmentOrder.InventoryShipmentOrder.InventoryPickOrder  = CreateInventoryPickOrder(treatmentOrder.InventoryShipmentOrder, order);
                treatmentOrder.InventoryShipmentOrder.PickedInventory     = CreatePickedInventory(treatmentOrder.InventoryShipmentOrder, order, treatmentOrder.InventoryShipmentOrder.ShipmentInformation.Status);
                if (treatmentOrder.InventoryShipmentOrder.PickedInventory == null)
                {
                    continue;
                }
                treatmentOrder.InventoryShipmentOrder.PickedInventory.Items.ForEach(i => i.TreatmentId = NewContextHelper.NoTreatment.Id);

                if (deserialized != null)
                {
                    deserialized.SetOrder(treatmentOrder);
                }

                LoadCount.AddLoaded(entityType);
                LoadCount.AddLoaded(EntityTypes.InventoryShipmentOrder);
                LoadCount.AddLoaded(EntityTypes.PickOrder);
                LoadCount.AddLoaded(EntityTypes.PickOrderItem, (uint)treatmentOrder.InventoryShipmentOrder.InventoryPickOrder.Items.Count);
                LoadCount.AddLoaded(EntityTypes.PickedInventory);
                LoadCount.AddLoaded(EntityTypes.PickedInventoryItem, (uint)treatmentOrder.InventoryShipmentOrder.PickedInventory.Items.Count);
                LoadCount.AddLoaded(EntityTypes.ShipmentInformation);

                yield return(treatmentOrder);
            }

            LoadCount.LogResults(l => Log(new CallbackParameters(l)));
        }
        private SalesOrderLoad CreateCustomerOrder(tblOrderDTO oldOrder)
        {
            LoadCount.AddRead(EntityType.SalesOrder);

            if (oldOrder.EntryDate == null)
            {
                Log(new CallbackParameters(CallbackReason.EntryDateNull)
                {
                    Order = oldOrder
                });
                return(null);
            }

            var employeeId = _newContextHelper.DefaultEmployee.EmployeeId;

            if (oldOrder.EmployeeID != null)
            {
                employeeId = oldOrder.EmployeeID.Value;
            }
            else
            {
                Log(new CallbackParameters(CallbackReason.EmployeeIDNull)
                {
                    Order = oldOrder
                });
            }

            Models.Company customer = null;
            if (!string.IsNullOrWhiteSpace(oldOrder.Company_IA))
            {
                customer = _newContextHelper.GetCompany(oldOrder.Company_IA, CompanyType.Customer);
                if (customer == null)
                {
                    Log(new CallbackParameters(CallbackReason.CustomerNotFound)
                    {
                        Order = oldOrder
                    });
                    return(null);
                }
            }

            Models.Company broker = null;
            if (!string.IsNullOrWhiteSpace(oldOrder.Broker))
            {
                broker = _newContextHelper.GetCompany(oldOrder.Broker, CompanyType.Broker);
                if (broker == null)
                {
                    Log(new CallbackParameters(CallbackReason.BrokerNotFound)
                    {
                        Order = oldOrder
                    });
                    return(null);
                }
            }

            var warehouse = _newContextHelper.GetFacility(oldOrder.WHID);

            if (warehouse == null)
            {
                Log(new CallbackParameters(CallbackReason.WarehouseNotFound)
                {
                    Order = oldOrder
                });
                return(null);
            }

            var dateReceived = oldOrder.EntryDate.Value.Date;

            if (oldOrder.DateRecd != null)
            {
                dateReceived = oldOrder.DateRecd.Value.Date;
            }
            else
            {
                Log(new CallbackParameters(CallbackReason.DateRecdNull)
                {
                    Order = oldOrder
                });
            }

            if (oldOrder.Status.ToTblOrderStatus() == null)
            {
                Log(new CallbackParameters(CallbackReason.InvalidStatus)
                {
                    Order = oldOrder
                });
                return(null);
            }

            var shipmentInformation = CreateShipmentInformation(oldOrder);

            if (shipmentInformation == null)
            {
                return(null);
            }

            var timestamp = oldOrder.EntryDate.Value.ConvertLocalToUTC();
            var order     = SetItems(new SalesOrderLoad
            {
                CustomerId   = customer == null ? (int?)null : customer.Id,
                BrokerId     = broker == null ? (int?)null : broker.Id,
                PaymentTerms = oldOrder.PayTerms,
                PreShipmentSampleRequired = oldOrder.PreSample,
                OrderStatus   = ((tblOrderStatus)oldOrder.Status).ToCustomerOrderStatus(),
                InvoiceDate   = oldOrder.InvoiceDate,
                InvoiceNotes  = oldOrder.InvoiceNotes,
                CreditMemo    = oldOrder.CreditMemo,
                FreightCharge = (float)(oldOrder.FreightCharge ?? 0.0m),

                SoldTo = oldOrder.SoldTo,
                InventoryShipmentOrder = new InventoryShipmentOrder
                {
                    MoveNum    = oldOrder.OrderNum,
                    EmployeeId = employeeId,
                    TimeStamp  = timestamp,
                    OrderType  = oldOrder.TTypeID.ToOrderType(),
                    ShipmentInfoDateCreated = shipmentInformation.DateCreated,
                    ShipmentInfoSequence    = shipmentInformation.Sequence,
                    ShipmentInformation     = shipmentInformation,
                    DestinationFacilityId   = null,
                    SourceFacilityId        = warehouse.Id,
                    OrderStatus             = oldOrder.Status.ToTblOrderStatus().ToOrderStatus(),

                    PurchaseOrderNumber = oldOrder.PONbr,
                    DateReceived        = dateReceived,
                    RequestedBy         = oldOrder.From,
                    TakenBy             = oldOrder.TakenBy,

                    PickedInventory = new PickedInventory
                    {
                        EmployeeId   = employeeId,
                        TimeStamp    = timestamp,
                        PickedReason = PickedReason.SalesOrder,
                        Archived     = oldOrder.Status > (int)tblOrderStatus.Staged,
                    },
                    InventoryPickOrder = new InventoryPickOrder()
                }
            }, oldOrder);

            var            dateCreated = oldOrder.EntryDate.Value.Date;
            int            sequence;
            ISalesOrderKey key;

            if (_salesOrderKey.TryParse(oldOrder.SerializedKey, out key))
            {
                dateCreated = key.SalesOrderKey_DateCreated;
                sequence    = key.SalesOrderKey_Sequence;
            }
            else
            {
                sequence = PickedInventoryKeyHelper.Singleton.GetNextSequence(dateCreated);
                order.RequiresKeySync = true;
            }
            SetPickedInventoryKey(order, dateCreated, sequence);

            return(order);
        }
        private SalesOrderLoad SetItems(SalesOrderLoad order, tblOrderDTO oldOrder)
        {
            var orderItemSequence  = 0;
            var pickedItemSequence = 0;

            order.SalesOrderItems       = new List <SalesOrderItem>();
            order.SalesOrderPickedItems = new List <SalesOrderPickedItem>();

            var latestStaged = oldOrder.tblOrderDetails.SelectMany(d => d.tblStagedFGs)
                               .OrderByDescending(s => s.EntryDate)
                               .FirstOrDefault();

            if (latestStaged != null)
            {
                order.InventoryShipmentOrder.PickedInventory.TimeStamp = latestStaged.EntryDate.ConvertLocalToUTC();
                if (latestStaged.EmployeeID != null)
                {
                    order.InventoryShipmentOrder.PickedInventory.EmployeeId = latestStaged.EmployeeID.Value;
                }
            }

            foreach (var detail in oldOrder.tblOrderDetails)
            {
                LoadCount.AddRead(EntityType.SalesOrderItem);

                var product = _newContextHelper.GetProduct(detail.ProdID);
                if (product == null)
                {
                    Log(new CallbackParameters(CallbackReason.DetailProductNotFound)
                    {
                        Order  = oldOrder,
                        Detail = detail
                    });
                    continue;
                }

                var packaging = _newContextHelper.GetPackagingProduct(detail.PkgID);
                if (packaging == null)
                {
                    Log(new CallbackParameters(CallbackReason.DetailPackagingNotFound)
                    {
                        Order  = oldOrder,
                        Detail = detail
                    });
                    continue;
                }

                var treatment = _newContextHelper.NoTreatment;
                if (detail.TrtmtID != null)
                {
                    treatment = _newContextHelper.GetInventoryTreatment(detail.TrtmtID.Value);
                    if (treatment == null)
                    {
                        Log(new CallbackParameters(CallbackReason.DetailTreatmentNotFound)
                        {
                            Order  = oldOrder,
                            Detail = detail
                        });
                        continue;
                    }
                }

                IContractItemKey contractItemKey = null;
                if (detail.KDetailID != null)
                {
                    contractItemKey = _newContextHelper.GetContractItemKey(detail.KDetailID);
                    if (contractItemKey == null)
                    {
                        Log(new CallbackParameters(CallbackReason.ContractItemNotFound)
                        {
                            Order  = oldOrder,
                            Detail = detail
                        });
                        continue;
                    }
                }

                order.SalesOrderItems.Add(new SalesOrderItem
                {
                    ItemSequence         = orderItemSequence,
                    ContractYear         = contractItemKey == null ? (int?)null : contractItemKey.ContractKey_Year,
                    ContractSequence     = contractItemKey == null ? (int?)null : contractItemKey.ContractKey_Sequence,
                    ContractItemSequence = contractItemKey == null ? (int?)null : contractItemKey.ContractItemKey_Sequence,
                    PriceBase            = (double)(detail.Price ?? 0),
                    PriceFreight         = (double)(detail.FreightP ?? 0),
                    PriceTreatment       = (double)(detail.TrtnmntP ?? 0),
                    PriceWarehouse       = (double)(detail.WHCostP ?? 0),
                    PriceRebate          = (double)(detail.Rebate ?? 0),
                    ODetail = detail.ODetail,

                    InventoryPickOrderItem = new InventoryPickOrderItem
                    {
                        ItemSequence        = orderItemSequence,
                        ProductId           = product.ProductKey.ProductKey_ProductId,
                        PackagingProductId  = packaging.Id,
                        TreatmentId         = treatment.Id,
                        Quantity            = (int)(detail.Quantity ?? 0),
                        CustomerLotCode     = detail.CustLot,
                        CustomerProductCode = detail.CustProductCode,
                    }
                });

                foreach (var staged in detail.tblStagedFGs)
                {
                    LoadCount.AddRead(EntityType.SalesOrderPickedItem);

                    LotKey lotKey;
                    if (!LotNumberParser.ParseLotNumber(staged.Lot, out lotKey))
                    {
                        Log(new CallbackParameters(CallbackReason.StagedInvalidLotNumber)
                        {
                            Order  = oldOrder,
                            Staged = staged
                        });
                        continue;
                    }

                    packaging = _newContextHelper.GetPackagingProduct(staged.PkgID);
                    if (packaging == null)
                    {
                        Log(new CallbackParameters(CallbackReason.StagedPackagingNotFound)
                        {
                            Order  = oldOrder,
                            Staged = staged
                        });
                        continue;
                    }

                    var currentLocation = _newContextHelper.GetLocation(staged.LocID);
                    if (currentLocation == null)
                    {
                        Log(new CallbackParameters(CallbackReason.StagedLocationNotFound)
                        {
                            Order  = oldOrder,
                            Staged = staged
                        });
                        continue;
                    }

                    var fromLocation = detail.tblOutgoing.Any() ? DeterminePickedFromLocation(detail, staged) : currentLocation;
                    if (fromLocation == null)
                    {
                        Log(new CallbackParameters(CallbackReason.UndeterminedPickedFromLocation)
                        {
                            Order  = oldOrder,
                            Staged = staged
                        });
                        continue;
                    }

                    treatment = _newContextHelper.GetInventoryTreatment(staged.TrtmtID);
                    if (treatment == null)
                    {
                        Log(new CallbackParameters(CallbackReason.StagedTreatmentNotFound)
                        {
                            Order  = oldOrder,
                            Staged = staged
                        });
                        continue;
                    }

                    order.SalesOrderPickedItems.Add(new SalesOrderPickedItem
                    {
                        ItemSequence      = pickedItemSequence,
                        OrderItemSequence = orderItemSequence,

                        PickedInventoryItem = new PickedInventoryItem
                        {
                            DetailID        = staged.EntryDate,
                            ItemSequence    = pickedItemSequence,
                            LotDateCreated  = lotKey.LotKey_DateCreated,
                            LotDateSequence = lotKey.LotKey_DateSequence,
                            LotTypeId       = lotKey.LotKey_LotTypeId,

                            Quantity           = (int)(staged.Quantity ?? 0),
                            PackagingProductId = packaging.Id,
                            FromLocationId     = fromLocation.Id,
                            CurrentLocationId  = currentLocation.Id,
                            TreatmentId        = treatment.Id,
                            ToteKey            = "",

                            CustomerLotCode     = staged.CustLot,
                            CustomerProductCode = staged.CustProductCode
                        }
                    });
                    pickedItemSequence++;
                }
                orderItemSequence++;
            }

            return(order);
        }
Example #12
0
        public bool IsInteresting(EntitiesConfiguration configuration = null)
        {
            if (configuration == null)
            {
                return(true);
            }

            if (!configuration.Enabled)
            {
                return(false);
            }

            if (!configuration.IgnoreNulls)
            {
                return(true);
            }

            var monitoredStatistics = configuration.MonitoredStatistics;
            var filterStats         = (monitoredStatistics?.Count).GetValueOrDefault(0) > 0;


            if ((filterStats && !monitoredStatistics.Contains("LoadCount")) || (configuration.IgnoreNulls && LoadCount.GetValueOrDefault(0) == 0))
            {
                LoadCount = null;
            }

            if ((filterStats && !monitoredStatistics.Contains("UpdateCount")) || (configuration.IgnoreNulls && UpdateCount.GetValueOrDefault(0) == 0))
            {
                UpdateCount = null;
            }

            if ((filterStats && !monitoredStatistics.Contains("DeleteCount")) || (configuration.IgnoreNulls && DeleteCount.GetValueOrDefault(0) == 0))
            {
                DeleteCount = null;
            }

            if ((filterStats && !monitoredStatistics.Contains("FetchCount")) || (configuration.IgnoreNulls && FetchCount.GetValueOrDefault(0) == 0))
            {
                FetchCount = null;
            }

            if ((EntityType != "Entity") || (filterStats && !monitoredStatistics.Contains("InsertCount")) || (configuration.IgnoreNulls && InsertCount.GetValueOrDefault(0) == 0))
            {
                InsertCount = null;
            }

            if ((EntityType != "Entity") || (filterStats && !monitoredStatistics.Contains("OptimisticFailureCount")) || (configuration.IgnoreNulls && OptimisticFailureCount.GetValueOrDefault(0) == 0))
            {
                OptimisticFailureCount = null;
            }

            if ((EntityType != "Collection") || (filterStats && !monitoredStatistics.Contains("RecreateCount")) || (configuration.IgnoreNulls && RecreateCount.GetValueOrDefault(0) == 0))
            {
                RecreateCount = null;
            }

            var isInteresting = (
                (
                    LoadCount.HasValue ||
                    UpdateCount.HasValue ||
                    InsertCount.HasValue ||
                    DeleteCount.HasValue ||
                    FetchCount.HasValue ||
                    OptimisticFailureCount.HasValue ||
                    RecreateCount.HasValue
                )
                );

            if (!isInteresting)
            {
                EntityName = null;
                EntityType = null;
            }

            return(isInteresting);
        }//end IsInteresting()
        protected override IEnumerable <InventoryShipmentOrder> BirthRecords()
        {
            LoadCount.Reset();

            foreach (var order in SelectMovementOrdersToLoad())
            {
                var entityType = GetEntityType(order.TTypeID);
                LoadCount.AddRead(entityType);

                if (order.EntryDate == null)
                {
                    Log(new CallbackParameters(CallbackReason.NullEntryDate)
                    {
                        MovementOrder = order
                    });
                    continue;
                }
                var dateCreated = order.EntryDate.Value.ConvertLocalToUTC().Date;
                var sequence    = PickedInventoryKeyHelper.Singleton.GetNextSequence(dateCreated);

                var sourceWarehouse = NewContextHelper.GetFacility(order.FromWHID);
                if (sourceWarehouse == null)
                {
                    Log(new CallbackParameters(CallbackReason.SourceWarehouseNotLoaded)
                    {
                        MovementOrder = order
                    });
                    continue;
                }

                var destinationWarehouse = NewContextHelper.GetFacility(order.ToWHID);
                if (destinationWarehouse == null)
                {
                    Log(new CallbackParameters(CallbackReason.DestinationWarehouseNotLoaded)
                    {
                        MovementOrder = order
                    });
                    continue;
                }

                var shipmentInformationSequence = NewContextHelper.ShipmentInformationKeys.GetNextSequence(dateCreated);

                var shipmentOrder = SetOrderProperties(new InventoryShipmentOrder
                {
                    DateCreated             = dateCreated,
                    Sequence                = sequence,
                    ShipmentInfoDateCreated = dateCreated,
                    ShipmentInfoSequence    = shipmentInformationSequence,
                    DestinationFacilityId   = destinationWarehouse.Id,
                    SourceFacilityId        = sourceWarehouse.Id
                }, order);
                if (shipmentOrder == null)
                {
                    continue;
                }

                shipmentOrder.ShipmentInformation = CreateShipmentInformation(shipmentOrder, order);
                shipmentOrder.InventoryPickOrder  = CreateInventoryPickOrder(shipmentOrder, order);
                shipmentOrder.PickedInventory     = CreatePickedInventory(shipmentOrder, order, shipmentOrder.ShipmentInformation.Status);
                if (shipmentOrder.PickedInventory == null)
                {
                    continue;
                }

                var deserialized = SerializableMove.Deserialize(order.Serialized);
                if (deserialized != null)
                {
                    deserialized.SetOrder(shipmentOrder);
                }

                LoadCount.AddLoaded(entityType);
                LoadCount.AddLoaded(EntityTypes.InventoryShipmentOrder);
                LoadCount.AddLoaded(EntityTypes.PickOrder);
                LoadCount.AddLoaded(EntityTypes.PickOrderItem, (uint)shipmentOrder.InventoryPickOrder.Items.Count);
                LoadCount.AddLoaded(EntityTypes.PickedInventory);
                LoadCount.AddLoaded(EntityTypes.PickedInventoryItem, (uint)shipmentOrder.PickedInventory.Items.Count);
                LoadCount.AddLoaded(EntityTypes.ShipmentInformation);

                yield return(shipmentOrder);
            }

            LoadCount.LogResults(l => Log(new CallbackParameters(l)));
        }