public void Creates_tblProductionSchedule_record_as_expected()
            {
                //Arrange
                var productionLineLocation = RVCUnitOfWork.LocationRepository.FindBy(l => l.LocationType == LocationType.ProductionLine);

                if (productionLineLocation == null)
                {
                    Assert.Inconclusive("No ProductionLine location found.");
                }

                var productionDate = RVCUnitOfWork.ProductionScheduleRepository.SourceQuery.Select(p => p.ProductionDate).DefaultIfEmpty(DateTime.Now.Date).Max().AddDays(1);

                //Act
                var result = Service.CreateProductionSchedule(new CreateProductionScheduleParameters
                {
                    UserToken                 = TestUser.UserName,
                    ProductionDate            = productionDate,
                    ProductionLineLocationKey = productionLineLocation.ToLocationKey()
                });

                //Assert
                result.AssertSuccess();
                MockKillSwitch.Verify(k => k.Engage(), Times.Never());

                string street;
                int    row;

                LocationDescriptionHelper.GetStreetRow(productionLineLocation.Description, out street, out row);
                using (var oldContext = new RioAccessSQLEntities())
                {
                    var productionSchedule = oldContext.tblProductionSchedules.FirstOrDefault(p => p.ProductionDate == productionDate && (int)p.LineNumber == row);
                    Assert.AreEqual(TestUser.EmployeeId, productionSchedule.CreatedBy);
                }
            }
        private static string GetLineNumber(string locationDescription)
        {
            string street;
            int    row;

            return(LocationDescriptionHelper.GetStreetRow(locationDescription, out street, out row) ? row.ToString() : locationDescription);
        }
Exemplo n.º 3
0
        public Location GetProductionLocation(ILocation location)
        {
            Location productionLocation;

            LocationsByDescription.TryGetValue(LocationDescriptionHelper.GetDescription(location.Street, location.Row ?? 0), out productionLocation);
            return(productionLocation);
        }
            public void Deletes_tblProductionSchedule_and_associated_records()
            {
                //Arrange
                var productionSchedule = RVCUnitOfWork.ProductionScheduleRepository.Filter(p => p.ScheduledItems.Any(),
                                                                                           p => p.ProductionLineLocation)
                                         .OrderByDescending(p => p.ProductionDate)
                                         .FirstOrDefault();

                if (productionSchedule == null)
                {
                    Assert.Inconclusive("No suitable ProductionSchedule to test.");
                }

                //Act
                var result = Service.DeleteProductionSchedule(productionSchedule.ToProductionScheduleKey());

                //Assert
                result.AssertSuccess();
                using (var oldContext = new RioAccessSQLEntities())
                {
                    string street;
                    int    row;
                    LocationDescriptionHelper.GetStreetRow(productionSchedule.ProductionLineLocation.Description, out street, out row);
                    Assert.IsEmpty(oldContext.tblProductionScheduleItems.Where(i => i.ProductionDate == productionSchedule.ProductionDate && (int)i.LineNumber == row));
                    Assert.IsEmpty(oldContext.tblProductionScheduleGroups.Where(i => i.ProductionDate == productionSchedule.ProductionDate && (int)i.LineNumber == row));
                    Assert.IsEmpty(oldContext.tblProductionSchedules.Where(i => i.ProductionDate == productionSchedule.ProductionDate && (int)i.LineNumber == row));
                }
            }
Exemplo n.º 5
0
        public override void Synchronize(Func <ProductionScheduleKey> getInput)
        {
            var productionScheduleKey = getInput();

            var productionSchedule = UnitOfWork.ProductionScheduleRepository.FindByKey(productionScheduleKey,
                                                                                       p => p.ScheduledItems.Select(i => i.PackSchedule.ProductionBatches));

            var    location = UnitOfWork.LocationRepository.FindByKey(productionScheduleKey.ToLocationKey());
            string street;
            int    row;

            LocationDescriptionHelper.GetStreetRow(location.Description, out street, out row);

            var oldProductionSchedule = OldContext.tblProductionSchedules
                                        .Include(p => p.tblProductionScheduleGroups.Select(g => g.tblProductionScheduleItems))
                                        .FirstOrDefault(p => p.ProductionDate == productionScheduleKey.ProductionScheduleKey_ProductionDate && (int)p.LineNumber == row);

            if (productionSchedule == null)
            {
                if (oldProductionSchedule != null)
                {
                    DeleteSchedule(oldProductionSchedule);
                }
            }
            else
            {
                SetSchedule(oldProductionSchedule, productionSchedule, row);
            }

            OldContext.SaveChanges();

            Console.WriteLine(ConsoleOutput.SyncProductionSchedule, productionScheduleKey.ProductionScheduleKey_ProductionDate.ToString("yyyyMMdd"), row);
        }
 private static Location CreateProductionLine(int line, int facilityId)
 {
     return(new Location
     {
         LocationType = LocationType.ProductionLine,
         Description = LocationDescriptionHelper.GetDescription("Line", line),
         Active = true,
         Locked = false,
         FacilityId = facilityId
     });
 }
Exemplo n.º 7
0
        public bool IsGroup(string groupName)
        {
            string street;
            int    row;

            if (LocationDescriptionHelper.GetStreetRow(Location, out street, out row))
            {
                return(street == groupName);
            }
            return(Location == groupName);
        }
Exemplo n.º 8
0
        public Location GetProductionLine(int?productionLine)
        {
            if (productionLine == null)
            {
                return(null);
            }

            Location productionLocation;

            LocationsByDescription.TryGetValue(LocationDescriptionHelper.GetDescription("Line", productionLine.Value), out productionLocation);
            return(productionLocation);
        }
Exemplo n.º 9
0
        public PackSchedulePickSheetReportModel Initialize()
        {
            if (LocationDescriptionHelper.GetStreetRow(WarehouseLocation, out _street, out _row))
            {
                WarehouseLocation = LocationDescriptionHelper.ToDisplayString(_street, _row);
            }
            else
            {
                _street = null;
                _row    = 0;
            }

            return(this);
        }
Exemplo n.º 10
0
            public void Creates_new_tblLocation_record_as_expected()
            {
                //Arrange
                var facility = RVCUnitOfWork.FacilityRepository.Filter(f => f.WHID != null).FirstOrDefault();

                if (facility == null)
                {
                    Assert.Inconclusive("No suitable Facility found.");
                }

                var locations = RVCUnitOfWork.LocationRepository.Filter(l => l.Description.StartsWith("A")).ToList();
                var row       = 1;

                if (locations.Any())
                {
                    locations.ForEach(l =>
                    {
                        string street;
                        int otherRow;
                        LocationDescriptionHelper.GetStreetRow(l.Description, out street, out otherRow);
                        row = Math.Max(row, otherRow);
                    });
                }
                row += 1;

                //Act
                var result = Service.CreateLocation(new CreateLocationParameters
                {
                    UserToken    = TestUser.UserName,
                    FacilityKey  = new FacilityKey(facility),
                    LocationType = LocationType.ProductionLine,
                    Description  = string.Format("A~{0}", row),
                    Active       = true,
                    Locked       = true,
                });
                var resultString = GetKeyFromConsoleString(ConsoleOutput.SyncLocation);

                //Assert
                result.AssertSuccess();
                MockKillSwitch.Verify(k => k.Engage(), Times.Never());

                var locId    = int.Parse(resultString);
                var location = new RioAccessSQLEntities().tblLocations.FirstOrDefault(l => l.LocID == locId);

                Assert.AreEqual("A", location.Street);
                Assert.AreEqual(row, location.Row);
                Assert.AreEqual(facility.WHID.Value, location.WHID);
            }
Exemplo n.º 11
0
        private static tblLocation Update(IEmployeeKey employeeKey, Location location, tblLocation tblLocation)
        {
            string street;
            int    row;

            LocationDescriptionHelper.GetStreetRow(location.Description, out street, out row);

            tblLocation.EmployeeID = employeeKey == null ? tblLocation.EmployeeID : employeeKey.EmployeeKey_Id;
            tblLocation.EntryDate  = tblLocation.EntryDate ?? DateTime.UtcNow.ConvertUTCToLocal();
            tblLocation.Street     = street;
            tblLocation.Row        = row;
            tblLocation.WHID       = location.Facility.WHID.Value;
            tblLocation.InActive   = !location.Active;
            tblLocation.FreezeRow  = location.Locked ? "Yes" : null;

            return(tblLocation);
        }
        public void Initialize()
        {
            string street;
            int    row;

            if (LocationDescriptionHelper.GetStreetRow(Description, out street, out row))
            {
                LocationDescription = string.Format("{0}{1}", street, row);
                Street = street;
                Row    = row;
            }
            else
            {
                LocationDescription = Description;
                Street = Description;
                Row    = 0;
            }
        }
            public void Updates_existing_tblProductionSchedule_record_as_expected()
            {
                //Arrange
                var productionSchedule = RVCUnitOfWork.ProductionScheduleRepository.Filter(p => p.ScheduledItems.Any(),
                                                                                           p => p.ProductionLineLocation,
                                                                                           p => p.ScheduledItems.Select(i => i.PackSchedule))
                                         .OrderByDescending(p => p.ProductionDate)
                                         .FirstOrDefault();

                if (productionSchedule == null)
                {
                    Assert.Inconclusive("No suitable ProductionSchedule to test.");
                }

                //Act
                var result = Service.UpdateProductionSchedule(new UpdateProductionScheduleParameters
                {
                    UserToken             = TestUser.UserName,
                    ProductionScheduleKey = productionSchedule.ToProductionScheduleKey(),
                    ScheduledItems        = productionSchedule.ScheduledItems.Select((i, n) => new SetProductionScheduleItemParameters
                    {
                        Index = n,
                        FlushBeforeInstructions = "testing old context sync",
                        PackScheduleKey         = i.ToPackScheduleKey()
                    }).ToList()
                });

                //Assert
                result.AssertSuccess();
                using (var oldContext = new RioAccessSQLEntities())
                {
                    string street;
                    int    row;
                    LocationDescriptionHelper.GetStreetRow(productionSchedule.ProductionLineLocation.Description, out street, out row);
                    var oldProductionSchedule = oldContext.tblProductionSchedules
                                                .Include(p => p.tblProductionScheduleGroups)
                                                .FirstOrDefault(p => p.ProductionDate == productionSchedule.ProductionDate && p.LineNumber == row);
                    foreach (var item in productionSchedule.ScheduledItems)
                    {
                        var oldItem = oldProductionSchedule.tblProductionScheduleGroups.FirstOrDefault(g => g.PSNum == item.PackSchedule.PSNum);
                        Assert.AreEqual("testing old context sync", oldItem.FlushBeforeInstructions);
                    }
                }
            }
        public ProductionRecap_Lot(ProductionRecapLot lot)
        {
            Name = lot.ChileProduct.ProductName;
            Lot  = lot.LotKey.LotKey;

            string street;
            int    row;

            Line = LocationDescriptionHelper.GetStreetRow(lot.ProductionLocation.Description, out street, out row) ? row.ToString() : lot.ProductionLocation.Description;

            Shift = lot.Shift;
            PSNum = lot.ProductionBatch != null && lot.ProductionBatch.PSNum != null?lot.ProductionBatch.PSNum.ToString() : "";

            BatchType      = lot.WorkType;
            LotStat        = lot.TestResult.ToString();
            TargetWeight   = (int)lot.TotalInputWeight;
            ProducedWeight = (int)lot.TotalOutputWeight;
            ProductionTime = lot.ProductionTime;
        }
Exemplo n.º 15
0
 public void Initialize()
 {
     ReportDateTime = DateTime.Now;
     Locations      = LocationsSelect
                      .Where(l => l.IsGroup(GroupName))
                      .Select(l =>
     {
         string street;
         int row;
         LocationDescriptionHelper.GetStreetRow(l.Location, out street, out row);
         return(new
         {
             Street = street,
             Row = row,
             Select = l
         });
     })
                      .OrderBy(l => l.Street).ThenBy(l => l.Row)
                      .Select(l => new InventoryCycleCountLocationReturn
     {
         Location  = LocationDescriptionHelper.FormatLocationDescription(l.Select.Location),
         Inventory = l.Select.InventorySelect.GroupBy(i => new
         {
             lotKey       = i.LotKeyReturn.ToLotKey(),
             productKey   = i.ProductSelect.ToProductKey(),
             packagingKey = i.PackagingSelect.ProductKeyReturn.ToProductKey(),
             treatmentKey = i.TreatmentSelect.InventoryTreatmentKeyReturn.ToInventoryTreatmentKey()
         }).Select(g => new InventoryCycleCountInventoryReturn
         {
             LotKey         = g.Key.lotKey,
             ProductionDate = g.First().ProductionDate,
             ProductCode    = g.First().ProductSelect.ProductCode,
             ProductName    = g.First().ProductSelect.ProductName,
             Packaging      = g.First().PackagingSelect.ProductName,
             Treatment      = g.First().TreatmentSelect.TreatmentNameShort,
             Quantity       = g.Sum(i => i.Quantity),
             Weight         = g.Sum(i => i.Weight)
         })
                     .OrderBy(i => i.LotKey)
                     .ToList()
     })
                      .ToList();
 }
        public void Works_as_expected()
        {
            Assert.AreEqual("Line~23", LocationDescriptionHelper.GetDescription("Line", 23));
            Assert.AreEqual("A~1", LocationDescriptionHelper.GetDescription("A", 1));

            string street;
            int    row;

            Assert.IsTrue(LocationDescriptionHelper.GetStreetRow("Line", out street, out row));
            Assert.AreEqual("Line", street);
            Assert.AreEqual(0, row);

            Assert.IsTrue(LocationDescriptionHelper.GetStreetRow("Line~23", out street, out row));
            Assert.AreEqual("Line", street);
            Assert.AreEqual(23, row);

            Assert.IsTrue(LocationDescriptionHelper.GetStreetRow("Line~Thing~23", out street, out row));
            Assert.AreEqual("Line~Thing", street);
            Assert.AreEqual(23, row);
        }
Exemplo n.º 17
0
 public static void ResolveWithWarehouseLocationFormatting <T>(this IMemberConfigurationExpression <T> scope, Func <T, string> resolver)
 {
     scope.ResolveUsing(m => LocationDescriptionHelper.FormatLocationDescription(resolver.Invoke(m)));
 }
        protected override IEnumerable <Facility> BirthRecords()
        {
            _loadCount.Reset();

            var facilityId = _newContext.NextIdentity <Facility>(w => w.Id);
            var locationId = _newContext.NextIdentity <Location>(l => l.Id);

            foreach (var warehouse in SelectRecordsToLoad())
            {
                _loadCount.AddRead(EntityTypes.Facility);

                if (WarehouseExcluded(warehouse))
                {
                    Log(new CallbackParameters(CallbackReason.FacilityExcluded)
                    {
                        WarehouseAbbreviation = warehouse.WhouseAbbr
                    });
                    continue;
                }

                var warehouseLocations = new List <Location>();
                if (warehouse.WHID == 0)
                {
                    warehouseLocations.AddRange(new []
                    {
                        CreateProductionLine(1, facilityId),
                        CreateProductionLine(2, facilityId),
                        CreateProductionLine(3, facilityId),
                        CreateProductionLine(4, facilityId),
                        CreateProductionLine(5, facilityId),
                        CreateProductionLine(6, facilityId)
                    });
                }
                foreach (var location in warehouse.tblLocations)
                {
                    _loadCount.AddRead(EntityTypes.Location);

                    var locationType = GetLocationType(location.Street);
                    warehouseLocations.Add(new Location
                    {
                        LocID      = location.LocID,
                        FacilityId = facilityId,

                        LocationType = locationType,
                        Active       = location.InActive == false,
                        Locked       = !string.IsNullOrEmpty(location.FreezeRow),
                        Description  = LocationDescriptionHelper.GetDescription(location.Street, location.Row ?? 0),
                    });
                    _loadCount.AddLoaded(EntityTypes.Location);
                    locationId += 1;
                }

                _loadCount.AddLoaded(EntityTypes.Facility);

                yield return(new Facility
                {
                    WHID = warehouse.WHID,
                    Id = facilityId,
                    Active = warehouse.InActive == false,
                    Name = warehouse.WhouseAbbr,
                    PhoneNumber = warehouse.Phone,
                    EMailAddress = warehouse.Email,
                    ShippingLabelName = warehouse.Company,
                    FacilityType = GetFacilityType(warehouse),

                    Address = new Address
                    {
                        AddressLine1 = warehouse.Address1,
                        AddressLine2 = warehouse.Address2,
                        AddressLine3 = warehouse.Address3,
                        City = warehouse.City,
                        State = warehouse.State,
                        PostalCode = warehouse.Zip,
                        Country = warehouse.Country
                    },

                    Locations = warehouseLocations
                });

                facilityId += 1;
            }

            _loadCount.LogResults(l => Log(new CallbackParameters(l)));
        }
        public static void Configure()
        {
            #region common mappings

            // convert AttributeNamesByType to a string key.
            Mapper.CreateMap <IEnumerable <KeyValuePair <ProductTypeEnum, IEnumerable <KeyValuePair <string, string> > > >, IEnumerable <KeyValuePair <string, IEnumerable <KeyValuePair <string, string> > > > >()
            .ConvertUsing(dto => dto.Select(attr => new KeyValuePair <string, IEnumerable <KeyValuePair <string, string> > >(attr.Key.ToString(), attr.Value)));

            Mapper.CreateMap <IEnumerable <KeyValuePair <ProductTypeEnum, IEnumerable <KeyValuePair <string, string> > > >, IDictionary <string, IEnumerable <KeyValuePair <string, string> > > >()
            .ConvertUsing(dto => dto.ToDictionary(kvp => kvp.Key.ToString(), kvp => kvp.Value));

            Mapper.CreateMap <LotProductionStatus, string>()
            .ConvertUsing(status =>
            {
                switch (status)
                {
                case LotProductionStatus.Batched: return("Batched");

                case LotProductionStatus.Produced: return("Produced");

                default: return("Unknown");
                }
            });
            Mapper.CreateMap <IInventoryTreatmentReturn, InventoryTreatmentResponse>();

            Mapper.CreateMap <CreateCompanyRequest, CreateCompanyParameters>()
            .ForMember(m => m.BrokerKey, opt => opt.MapFrom(m => m.BrokerCompanyKey))
            .Ignoring(m => m.UserToken);
            Mapper.CreateMap <UpdateCompanyRequest, UpdateCompanyParameters>()
            .ForMember(m => m.BrokerKey, opt => opt.MapFrom(m => m.BrokerCompanyKey))
            .Ignoring(m => m.UserToken);

            Mapper.CreateMap <ContactAddressResponse, ContactAddressParameters>();
            Mapper.CreateMap <CreateContactRequest, CreateContactParameters>()
            .Ignoring(m => m.UserToken);
            Mapper.CreateMap <UpdateContractRequest, UpdateContactParameters>()
            .Ignoring(m => m.ContactKey, m => m.UserToken);
            Mapper.CreateMap <IContactAddressReturn, ContactAddressResponse>();
            Mapper.CreateMap <IContactSummaryReturn, ContactSummaryResponse>();

            Mapper.CreateMap <ICompanyHeaderReturn, CompanyResponse>();
            Mapper.CreateMap <ICompanySummaryReturn, CompanySummaryResponse>();
            Mapper.CreateMap <ICompanyDetailReturn, CompanyDetailResponse>()
            .ForMember(m => m.CustomerResponse, opt => opt.MapFrom(m => m.Customer));
            Mapper.CreateMap <ICustomerCompanyReturn, CustomerCompanyResponse>();
            Mapper.CreateMap <ICustomerCompanyNoteReturn, CustomerCompanyNoteResponse>();

            Mapper.CreateMap <SetCustomerNoteRequest, CreateCustomerNoteParameters>()
            .Ignoring(m => m.UserToken, m => m.CustomerKey);
            Mapper.CreateMap <SetCustomerNoteRequest, UpdateCustomerNoteParameters>()
            .Ignoring(m => m.UserToken, m => m.CustomerNoteKey);

            Mapper.CreateMap <INotebookReturn, Notebook>();
            Mapper.CreateMap <INoteReturn, Note>();
            Mapper.CreateMap <IAdditiveTypeReturn, Ingredient>()
            .ForMember(m => m.Key, opt => opt.MapFrom(dto => dto.AdditiveTypeKey))
            .ForMember(m => m.Description, opt => opt.MapFrom(dto => dto.AdditiveTypeDescription));

            Mapper.CreateMap <IShippingLabelReturn, ShippingLabel>()
            .ForMember(m => m.Address, opt => opt.ResolveUsing(m => new Address
            {
                AddressLine1 = m.AddressLine1,
                AddressLine2 = m.AddressLine2,
                AddressLine3 = m.AddressLine3,
                City         = m.City,
                State        = m.State,
                PostalCode   = m.PostalCode,
                Country      = m.Country
            }));

            Mapper.CreateMap <IUserSummaryReturn, UserSummaryResponse>();

            #endregion

            #region Production models

            Mapper.CreateMap <CreateProductionScheduleRequest, CreateProductionScheduleParameters>()
            .Ignoring(m => m.UserToken);
            Mapper.CreateMap <UpdateProductionScheduleRequest, UpdateProductionScheduleParameters>()
            .Ignoring(m => m.UserToken, m => m.ProductionScheduleKey);
            Mapper.CreateMap <SetProductionScheduleItemRequest, SetProductionScheduleItemParameters>();

            Mapper.CreateMap <IProductionScheduleSummaryReturn, ProductionScheduleSummaryResponse>();
            Mapper.CreateMap <IProductionScheduleDetailReturn, ProductionScheduleDetailResponse>()
            .Ignoring(m => m.Links);
            Mapper.CreateMap <IProductionScheduleItemReturn, ProductionScheduleItemResponse>();
            Mapper.CreateMap <IScheduledPackScheduleReturn, ScheduledPackScheduleResponse>();

            Mapper.CreateMap <IWorkTypeReturn, WorkType>();
            Mapper.CreateMap <IChileProductAdditiveIngredientSummaryReturn, ChileProductAdditiveIngredientSummary>();
            Mapper.CreateMap <IProductionBatchMaterialsSummaryReturn, ProductionBatchMaterialsSummary>()
            .ForMember(m => m.InventoryType, opt => opt.MapFrom(dto => dto.ProductType));
            Mapper.CreateMap <IProductionBatchSummaryReturn, ProductionBatchSummary>();
            Mapper.CreateMap <IProductionBatchDetailReturn, ProductionBatchDetails>()
            .ForMember(m => m.IsLocked, opt => opt.ResolveUsing(m => m.HasProductionBeenCompleted))
            .AfterMap((batchIn, batchOut) =>
            {
                var picked = batchOut.PickedInventoryItems.ToList();
                picked.ForEach(i => i.ValidForPicking = !batchOut.IsLocked);
                batchOut.PickedInventoryItems         = picked;
            });
            Mapper.CreateMap <IProductionBatchPackagingMaterialSummaryReturn, ProductionBatchPackagingMaterialSummary>();
            Mapper.CreateMap <CreateProductionBatchDto, CreateProductionBatchParameters>()
            .ForMember(m => m.LotDateCreated, opt => opt.ResolveUsing(m =>
                                                                      m.LotDateCreated == null
                        ? (DateTime?)null
                        : DateTime.SpecifyKind(m.LotDateCreated.Value, DateTimeKind.Local)
                                                                      ))
            .ForMember(m => m.UserToken, opt => opt.Ignore());

            Mapper.CreateMap <IMillAndWetdownSummaryReturn, MillAndWetdownSummary>()
            .ForMember(m => m.ProductionLineDescription, opt => opt.ResolveWithWarehouseLocationFormatting(m => m.ProductionLineDescription));
            Mapper.CreateMap <IMillAndWetdownDetailReturn, MillAndWetdownDetail>()
            .ForMember(m => m.ProductionLineDescription, opt => opt.ResolveWithWarehouseLocationFormatting(m => m.ProductionLineDescription));
            Mapper.CreateMap <IMillAndWetdownResultItemReturn, MillAndWetdownResultItem>();
            Mapper.CreateMap <IMillAndWetdownPickedItemReturn, MillAndWetdownPickedItem>()
            .ForMember(m => m.Product, opt => opt.MapFrom(m => m.LotProduct));

            #region Pack Schedule models

            Mapper.CreateMap <IPackScheduleSummaryReturn, PackScheduleSummary>()
            .ForMember(m => m.ProductionLineDescription, opt => opt.ResolveWithWarehouseLocationFormatting(m => m.ProductionLineDescription));

            Mapper.CreateMap <IPackScheduleDetailReturn, PackScheduleDetails>()
            .ForMember(m => m.ProductionLineDescription,
                       opt => opt.ResolveWithWarehouseLocationFormatting(m => m.ProductionLineDescription));

            Mapper.CreateMap <IProductionBatchTargetParameters, ProductionBatchTargets>();

            Mapper.CreateMap <CreatePackSchedule, CreatePackScheduleParameters>()
            .ForMember(m => m.UserToken, opt => opt.Ignore());

            Mapper.CreateMap <UpdatePackSchedule, UpdatePackScheduleParameters>()
            .ForMember(m => m.UserToken, opt => opt.Ignore());

            #endregion

            #region Production Results

            Mapper.CreateMap <ProductionResultItemDto, BatchProductionResultInventoryItemSummary>();
            Mapper.CreateMap <CreateProductionBatchResultsDto, CreateProductionBatchResultsParameters>()
            .ForMember(m => m.UserToken, opt => opt.Ignore());
            Mapper.CreateMap <UpdateProductionBatchResultsDto, UpdateProductionBatchResultsParameters>()
            .ForMember(m => m.UserToken, opt => opt.Ignore())
            .ForMember(m => m.ProductionResultKey, opt => opt.Ignore());

            Mapper.CreateMap <IProductionResultDetailReturn, ProductionResultDetail>()
            .ForMember(m => m.ProductionLine, opt => opt.MapFrom(m => m.ProductionLocation));
            Mapper.CreateMap <IProductionResultItemReturn, ProductionResultDetail.ProductionResultItem>()
            .ForMember(m => m.WarehouseLocation, opt => opt.MapFrom(m => m.Location));

            #endregion

            #endregion

            #region Inventory models

            Mapper.CreateMap <IProductReturn, InventoryProductResponse>()
            .ForMember(m => m.ProductType, opt => opt.Ignore())
            .ForMember(m => m.ProductSubType, opt => opt.Ignore());
            Mapper.CreateMap <IInventoryProductReturn, InventoryProductResponse>();
            Mapper.CreateMap <IChileProductReturn, ChileProductResponse>()
            .ForMember(m => m.ProductType, opt => opt.UseValue(ProductTypeEnum.Chile))
            .ForMember(m => m.ProductSubType, opt => opt.MapFrom(m => m.ChileStateName));

            Mapper.CreateMap <PickedInventoryDto, SetPickedInventoryParameters>();
            Mapper.CreateMap <PickedInventoryItemDto, SetPickedInventoryItemParameters>()
            .ForMember(m => m.Quantity, opt => opt.MapFrom(dto => dto.QuantityPicked));
            Mapper.CreateMap <PickedInventoryItemWithDestinationDto, IntraWarehouseOrderPickedItemParameters>()
            .ForMember(m => m.Quantity, opt => opt.MapFrom(dto => dto.QuantityPicked));

            MapInventorySummaryType <IInventorySummaryReturn, InventoryItem>();
            MapInventorySummaryType <IPickableInventorySummaryReturn, PickableInventoryItem>();

            Mapper.CreateMap <IPickedInventoryItemReturn, PickedInventoryItem>()
            .ForMember(m => m.LotStatus, opt => opt.MapFrom(dto => dto.QualityStatus))
            .ForMember(m => m.LotProductionStatus, opt => opt.MapFrom(dto => dto.ProductionStatus))
            .ForMember(m => m.Product, opt => opt.MapFrom(dto => dto.LotProduct))
            .ForMember(m => m.ReceivedPackagingName, opt => opt.MapFrom(dto => dto.PackagingReceived.ProductName))
            .ForMember(m => m.CustomerKey, opt => opt.MapFrom(dto => dto.Customer.CompanyKey))
            .ForMember(m => m.CustomerName, opt => opt.MapFrom(dto => dto.Customer.Name))
            .ForMember(m => m.ValidForPicking, opt => opt.UseValue(true));

            Mapper.CreateMap <IPickedInventoryItemReturn, PickedInventoryItemWithDestination>()
            .ForMember(m => m.LotStatus, opt => opt.MapFrom(dto => dto.QualityStatus))
            .ForMember(m => m.LotProductionStatus, opt => opt.MapFrom(dto => dto.ProductionStatus))
            .ForMember(m => m.Product, opt => opt.MapFrom(dto => dto.LotProduct))
            .ForMember(m => m.ReceivedPackagingName, opt => opt.MapFrom(dto => dto.PackagingReceived.ProductName))
            .ForMember(m => m.CustomerKey, opt => opt.MapFrom(dto => dto.Customer.CompanyKey))
            .ForMember(m => m.CustomerName, opt => opt.MapFrom(dto => dto.Customer.Name))
#warning DestinationLocation is mapped to CurrentLocation - VK
            //...But what the hell is it supposed to be doing instead? Is there some reason this decision was made? Is it a valid mapping? - VK 2015-8-5
            .ForMember(m => m.DestinationLocation, opt => opt.MapFrom(m => m.CurrentLocation))
            .ForMember(m => m.ValidForPicking, opt => opt.UseValue(true));

            Mapper.CreateMap <ReceiveInventoryDto, ReceiveInventoryParameters>()
            .ForMember(m => m.UserToken, opt => opt.Ignore());

            Mapper.CreateMap <ReceiveInventoryDto.ReceiveInventoryItemDto, ReceiveInventoryItemParameters>();

            Mapper.CreateMap <IInventoryPickOrderSummaryReturn, InventoryPickOrderSummary>()
            .ForMember(m => m.PoundsOnOrder, opt => opt.MapFrom(m => m.TotalWeight));

            Mapper.CreateMap <IPickedInventorySummaryReturn, PickedInventorySummary>()
            .ForMember(m => m.PoundsPicked, opt => opt.MapFrom(m => m.TotalWeightPicked));

            Mapper.CreateMap <IPickOrderDetailReturn <IPickOrderItemReturn>, InventoryPickOrderDetail>();

            Mapper.CreateMap <IPickOrderItemReturn, InventoryPickOrderItemResponse>();

            Mapper.CreateMap <SetInventoryPickOrderItemRequest, SetInventoryPickOrderItemParameters>();

            Mapper.CreateMap <IPickedInventoryDetailReturn, PickedInventory>();
            Mapper.CreateMap <IPickedInventoryDetailReturn, PickedInventoryWithDestination>();

            #region Chile Materials Recieved

            Mapper.CreateMap <CreateChileMaterialsReceivedRequest, CreateChileMaterialsReceivedParameters>()
            .Ignoring(m => m.UserToken);
            Mapper.CreateMap <UpdateChileMaterialsReceivedRequest, UpdateChileMaterialsReceivedParameters>()
            .Ignoring(m => m.UserToken, m => m.LotKey);
            Mapper.CreateMap <UpdateChileMaterialsReceivedItemRequest, UpdateChileMaterialsReceivedItemParameters>();
            Mapper.CreateMap <CreateChileMaterialsReceivedItemRequest, CreateChileMaterialsReceivedItemParameters>();

            Mapper.CreateMap <IChileMaterialsReceivedSummaryReturn, ChileMaterialsReceivedSummaryResponse>();
            Mapper.CreateMap <IChileMaterialsReceivedDetailReturn, ChileMaterialsReceivedDetailResponse>()
            .Ignoring(m => m.Links)
            .ForMember(m => m.IsEditingEnabled, opt => opt.UseValue(true));
            Mapper.CreateMap <IChileMaterialsReceivedItemReturn, ChileMaterialsReceivedItemResponse>();

            #endregion

            #region Mill & Wetdown

            Mapper.CreateMap <CreateMillAndWetdownRequest, CreateMillAndWetdownParameters>();
            Mapper.CreateMap <UpdateMillAndWetdownRequest, UpdateMillAndWetdownParameters>();
            Mapper.CreateMap <MillAndWetdownPickedItemRequest, MillAndWetdownPickedItemParameters>();
            Mapper.CreateMap <MillAndWetdownResultItemRequest, MillAndWetdownResultItemParameters>();

            #endregion

            #region IntraWarehouseOrder mappings

            Mapper.CreateMap <IIntraWarehouseOrderDetailReturn, IntraWarehouseOrderDetails>()
            .Map(m => m.PickedInventoryDetail, m => m.PickedInventory)
            .Map(m => m.OrderKey, m => m.MovementKey);

            Mapper.CreateMap <IIntraWarehouseOrderSummaryReturn, IntraWarehouseOrderSummary>()
            .Map(m => m.OrderKey, m => m.MovementKey);

            Mapper.CreateMap <CreateIntraWarehouseOrder, CreateIntraWarehouseOrderParameters>()
            .Map(m => m.PickedItems, m => m.PickedInventoryItems);

            Mapper.CreateMap <UpdateIntraWarehouseOrder, UpdateIntraWarehouseOrderParameters>();

            #endregion

            #region InterWarehouse Movements

            Mapper.CreateMap <SetPickedInventoryItemCodesRequestParameter, SetPickedInventoryItemCodesParameters>();

            Mapper.CreateMap <IInventoryShipmentOrderDetailReturn <IPickOrderDetailReturn <IPickOrderItemReturn>, IPickOrderItemReturn>, InterWarehouseOrderDetails>()
            .ForMember(m => m.ShipmentDate, opt => opt.MapFrom(m => m.Shipment.ShippingInstructions.ShipmentDate))
            .ForMember(m => m.IsLocked, opt => opt.ResolveUsing(m => m.OrderStatus == OrderStatus.Fulfilled))
            .MapLinkedResource()
            .AfterMap((mIn, mOut) =>
            {
                var picked = mOut.PickedInventory.PickedInventoryItems.ToList();
                picked.ForEach(i => i.ValidForPicking     = !mOut.IsLocked);
                mOut.PickedInventory.PickedInventoryItems = picked;
            });

            Mapper.CreateMap <IInventoryShipmentOrderSummaryReturn, InterWarehouseOrderSummary>();

            Mapper.CreateMap <SetInventoryShipmentOrderParameters, UpdateInterWarehouseOrderParameters>()
            .ForMember(m => m.SourceFacilityKey, opt => opt.MapFrom(m => m.OriginFacilityKey))
            .ForMember(m => m.InventoryShipmentOrderKey, opt => opt.Ignore())
            .ForMember(m => m.UserToken, opt => opt.Ignore())
            .ForMember(m => m.HeaderParameters, opt => opt.ResolveUsing(m => new SetOrderHeaderParameters
            {
                CustomerPurchaseOrderNumber = m.PurchaseOrderNumber,
                DateOrderReceived           = m.DateOrderReceived,
                OrderRequestedBy            = m.OrderRequestedBy,
                OrderTakenBy = m.OrderTakenBy,
            }))
            .ForMember(m => m.SetShipmentInformation, opt => opt.MapFrom(m => m.Shipment))
            .AfterMap((s, d) => d.SetShipmentInformation.ShippingInstructions.ShipmentDate = s.ShipmentDate);

            Mapper.CreateMap <SetOrderHeaderRequestParameter, SetOrderHeaderParameters>();

            Mapper.CreateMap <SetInventoryShipmentOrderParameters, SetOrderParameters>()
            .ForMember(m => m.HeaderParameters, opt => opt.ResolveUsing(m => new SetOrderHeaderRequestParameter
            {
                CustomerPurchaseOrderNumber = m.PurchaseOrderNumber,
                DateOrderReceived           = m.DateOrderReceived,
                OrderRequestedBy            = m.OrderRequestedBy,
                OrderTakenBy = m.OrderTakenBy,
                ShipmentDate = m.ShipmentDate,
            }))
            .ForMember(m => m.SetShipmentInformation, opt => opt.MapFrom(m => m.Shipment))
            .ForMember(m => m.SourceFacilityKey, opt => opt.MapFrom(m => m.OriginFacilityKey))
            .ForMember(m => m.UserToken, opt => opt.Ignore())
            .AfterMap((s, d) => d.SetShipmentInformation.ShippingInstructions.ShipmentDate = s.ShipmentDate);

            #endregion

            #region Inventory Adjustment mappings

            Mapper.CreateMap <IInventoryAdjustmentReturn, InventoryAdjustment>();
            Mapper.CreateMap <IInventoryAdjustmentItemReturn, InventoryAdjustmentItem>();

            #endregion

            #endregion

            #region Quality Control

            Mapper.CreateMap <IEnumerable <ILotDefectReturn>, IEnumerable <LotDefect> >()
            .ConvertUsing(
                (input) => input.AsEnumerable().Select(defect =>
                                                       defect.DefectType != DefectTypeEnum.InHouseContamination
                            ? Mapper.Map <LotAttributeDefect>(defect)
                            : Mapper.Map <LotDefect>(defect)));

            Mapper.CreateMap <ILotDefectReturn, LotAttributeDefect>()
            .ForMember(m => m.AttributeShortName, opt => opt.MapFrom(dto => dto.AttributeDefect.AttributeShortName))
            .ForMember(m => m.OriginalMaxLimit, opt => opt.MapFrom(dto => dto.AttributeDefect.OriginalMaxLimit))
            .ForMember(m => m.OriginalMinLimit, opt => opt.MapFrom(dto => dto.AttributeDefect.OriginalMinLimit))
            .ForMember(m => m.OriginalValue, opt => opt.MapFrom(dto => dto.AttributeDefect.OriginalValue));

            Mapper.CreateMap <ILotDefectReturn, LotDefect>();
            Mapper.CreateMap <ILotAttributeDefectReturn, AttributeDefect>();

            Mapper.CreateMap <ILotDefectResolutionReturn, LotDefectResolutionReturn>();

            #endregion

            #region Lot models

            Mapper.CreateMap <ILotCustomerAllowanceReturn, LotCustomerAllowanceResponse>();
            Mapper.CreateMap <ILotCustomerOrderAllowanceReturn, LotCustomerOrderAllowanceResponse>();
            Mapper.CreateMap <ILotContractAllowanceReturn, LotContractAllowanceResponse>();

            Mapper.CreateMap <ILotQualitySummaryReturn, LotQualitySummaryResponse>()
            .ForMember(m => m.LotDate, opt => opt.MapFrom(dto => dto.LotDateCreated))
            .ForMember(m => m.Product, opt => opt.MapFrom(dto => dto.LotProduct))
            .ForMember(m => m.CustomerName, opt => opt.MapFrom(dto => dto.Customer.Name))
            .ForMember(m => m.CustomerKey, opt => opt.MapFrom(dto => dto.Customer.CompanyKey))
            .ForMember(m => m.OldContextLotStat, opt => opt.Ignore());

            Mapper.CreateMap <ILotQualitySingleSummaryReturn, LotDetailsResponse>();

            Mapper.CreateMap <ILotAttributeReturn, LotAttribute>()
            .ForMember(m => m.AttributeDate, opt => opt.ResolveUsing(dto => dto.AttributeDate.ToShortDateString()));

            Mapper.CreateMap <ILotStatInfoReturn, LotStatInfoResponse>();
            Mapper.CreateMap <ICreateLotDefectReturn, CreateLotDefectResponse>();

            Mapper.CreateMap <LotAttributeRequest, AttributeValueParameters>();
            Mapper.CreateMap <DefectResolutionRequest, DefectResolutionParameters>();
            Mapper.CreateMap <LotAttributeInfoRequest, AttributeInfoParameters>();

            Mapper.CreateMap <UpdateLotRequest, SetLotAttributeParameters>()
            .Ignoring(m => m.UserToken)
            .ForMember(m => m.Attributes, opt => opt.ResolveUsing(m => m.Attributes.ToDictionary(a => a.AttributeKey, a => a.Map().To <AttributeValueParameters>())));

            Mapper.CreateMap <AddLotAttributesRequest, AddLotAttributesParameters>()
            .Ignoring(m => m.UserToken)
            .ForMember(m => m.Attributes, opt => opt.ResolveUsing(m => m.Attributes.ToDictionary(a => a.AttributeKey, a => a.Map().To <AttributeValueParameters>())));

            Mapper.CreateMap <ILotHistoryReturn, LotHistoryResponse>();
            Mapper.CreateMap <ILotHistoryAttributeReturn, LotHistoryAttributeResponse>();
            Mapper.CreateMap <ILotHistoryRecordReturn, LotHistoryRecordResponse>();
            Mapper.CreateMap <ILotOutputTraceReturn, LotOutputTraceResponse>();
            Mapper.CreateMap <ILotOutputTraceInputReturn, LotOutputTraceInputResponse>();
            Mapper.CreateMap <ILotOutputTraceOrdersReturn, LotOutputTraceOrdersResponse>();

            Mapper.CreateMap <ILotInputTraceReturn, LotInputTraceResponse>();

            #endregion

            #region Product models

            Mapper.CreateMap <SetChileProductIngredientRequest, SetChileProductIngredientParameters>();
            Mapper.CreateMap <SetChileProductIngredientsRequest, SetChileProductIngredientsParameters>()
            .Ignoring(m => m.UserToken, m => m.ChileProductKey);

            Mapper.CreateMap <AttributeRangeRequest, SetAttributeRangeParameters>();
            Mapper.CreateMap <SetChileProductAttributeRangesRequest, SetChileProductAttributeRangesParameters>()
            .Ignoring(m => m.UserToken, m => m.ChileProductKey);

            Mapper.CreateMap <IPackagingProductReturn, PackagingProductResponse>();
            Mapper.CreateMap <IProductAttributeRangeReturn, ProductAttributeRangeReturnViewModel>();
            Mapper.CreateMap <IProductIngredientReturn, ProductIngredientViewModel>();

            #endregion

            #region customer models

            Mapper.CreateMap <SalesOrderItem, SalesOrderItemParameters>();
            Mapper.CreateMap <CreateSalesOrderRequest, CreateSalesOrderParameters>()
            .ForMember(m => m.FreightCharge, opt => opt.ResolveUsing(m => m.FreightCharge.Value))
            .Ignoring(m => m.UserToken)
            .AfterMap((s, d) => d.SetShipmentInformation.ShippingInstructions.ShipmentDate = s.HeaderParameters.ShipmentDate);
            Mapper.CreateMap <UpdateSalesOrderRequest, UpdateSalesOrderParameters>()
            .Ignoring(m => m.UserToken)
            .AfterMap((s, d) => d.SetShipmentInformation.ShippingInstructions.ShipmentDate = s.HeaderParameters.ShipmentDate);

            Mapper.CreateMap <CustomerProductRangeRequest, SetCustomerProductAttributeRangeParameters>();
            Mapper.CreateMap <SetCustomerProductRangesRequest, SetCustomerProductAttributeRangesParameters>()
            .Ignoring(m => m.UserToken);

            Mapper.CreateMap <ICustomerChileProductAttributeRangeReturn, CustomerChileProductAttributeRangeReturn>();
            Mapper.CreateMap <ICustomerChileProductAttributeRangesReturn, CustomerChileProductAttributeRangesReturn>();

            Mapper.CreateMap <ICustomerContractSummaryReturn, CustomerContractSummaryResponse>()
            .ForMember(m => m.TermBegin, opt => opt.ResolveUsing(m => m.TermBegin.HasValue ? m.TermBegin.Value.ToShortDateString() : ""))
            .ForMember(m => m.TermEnd, opt => opt.ResolveUsing(m => m.TermEnd.HasValue ? m.TermEnd.Value.ToShortDateString() : ""))
            .ForMember(m => m.ContractDate, opt => opt.ResolveUsing(m => m.ContractDate.ToShortDateString()))
            .ForMember(m => m.CustomerKey, opt => opt.MapFrom(m => m.Customer.CompanyKey))
            .ForMember(m => m.CustomerName, opt => opt.MapFrom(m => m.Customer.Name))
            .ForMember(m => m.BrokerCompanyKey, opt => opt.MapFrom(m => m.Broker.CompanyKey))
            .ForMember(m => m.BrokerCompanyName, opt => opt.MapFrom(m => m.Broker.Name))
            .ForMember(m => m.ContactName, opt => opt.MapFrom(m => m.ContactName))
            .ForMember(m => m.DistributionWarehouseKey, opt => opt.MapFrom(m => m.DefaultPickFromFacility.FacilityKey))
            .ForMember(m => m.DistributionWarehouseName, opt => opt.MapFrom(m => m.DefaultPickFromFacility.FacilityName));

            Mapper.CreateMap <ICustomerContractDetailReturn, CustomerContractResponse>()
            .ForMember(m => m.ContractDate, opt => opt.MapFrom(m => m.ContractDate))
            .ForMember(m => m.CustomerKey, opt => opt.MapFrom(m => m.Customer.CompanyKey))
            .ForMember(m => m.CustomerName, opt => opt.MapFrom(m => m.Customer.Name))
            .ForMember(m => m.BrokerCompanyKey, opt => opt.MapFrom(m => m.Broker.CompanyKey))
            .ForMember(m => m.BrokerCompanyName, opt => opt.MapFrom(m => m.Broker.Name))
            .ForMember(m => m.DistributionWarehouseKey, opt => opt.MapFrom(m => m.DefaultPickFromFacility.FacilityKey))
            .ForMember(m => m.DistributionWarehouseName, opt => opt.MapFrom(m => m.DefaultPickFromFacility.FacilityName))
            .ForMember(m => m.CommentsNotebookKey, opt => opt.MapFrom(m => m.Comments.NotebookKey))
            .MapLinkedResource();

            Mapper.CreateMap <IContractItemReturn, CustomerContractResponse.ContractItem>()
            .ForMember(m => m.ChileProductClassificationKey, opt => opt.MapFrom(m => m.ChileProduct.ChileTypeKey))
            .ForMember(m => m.ChileProductKey, opt => opt.MapFrom(m => m.ChileProduct.ProductKey))
            .ForMember(m => m.ChileProductName, opt => opt.MapFrom(m => m.ChileProduct.ProductName))
            .ForMember(m => m.ChileProductCode, opt => opt.MapFrom(m => m.ChileProduct.ProductCode))
            .ForMember(m => m.PackagingProductKey, opt => opt.MapFrom(m => m.PackagingProduct.ProductKey))
            .ForMember(m => m.PackagingProductName, opt => opt.MapFrom(m => m.PackagingProduct.ProductName))
            .ForMember(m => m.TreatmentKey, opt => opt.MapFrom(m => m.Treatment.TreatmentKey));

            Mapper.CreateMap <CreateCustomerContractRequest, CreateCustomerContractParameters>()
            .ForMember(m => m.DefaultPickFromFacilityKey, opt => opt.MapFrom(m => m.DistributionWarehouseKey));
            Mapper.CreateMap <CreateCustomerContractRequest.ContractItem, CreateCustomerContractParameters.ContractItem>()
            .ForMember(m => m.CustomerCodeOverride, opt => opt.MapFrom(m => m.CustomerProductCode));

            Mapper.CreateMap <UpdateCustomerContractRequest, UpdateCustomerContractParameters>()
            .ForMember(m => m.ContractKey, opt => opt.Ignore())
            .ForMember(m => m.DefaultPickFromWarehouseKey, opt => opt.MapFrom(m => m.DistributionWarehouseKey));
            Mapper.CreateMap <UpdateCustomerContractRequest.ContractItem, UpdateCustomerContractParameters.ContractItem>()
            .ForMember(m => m.CustomerCodeOverride, opt => opt.MapFrom(m => m.CustomerProductCode));

            Mapper.CreateMap <SetContractsStatusRequest, SetContractsStatusParameters>();

            Mapper.CreateMap <IContractShipmentSummaryReturn, IEnumerable <ContractShipmentSummaryItem> >()
            .ConvertUsing(c => c.Items.Select(i => new ContractShipmentSummaryItem
            {
                ContractKey    = c.ContractKey,
                ContractNumber = c.ContractNumber.HasValue ? c.ContractNumber.ToString() : string.Empty,
                ContractStatus = c.ContractStatus.ToString(),

                ProductName         = i.ChileProduct.ProductCodeAndName,
                CustomerProductCode = i.CustomerProductCode,
                PackagingName       = i.PackagingProduct.ProductName,
                Treatment           = i.Treatment.TreatmentNameShort,

                ContractBeginDate = c.TermBegin.HasValue ? c.TermBegin.Value.ToShortDateString() : null,
                ContractEndDate   = c.TermEnd.HasValue ? c.TermEnd.Value.ToShortDateString() : null,

                BasePrice          = i.BasePrice,
                ContractItemValue  = i.TotalValue,
                ContractItemPounds = i.TotalWeight,

                TotalPoundsShippedForContractItem   = i.TotalWeightShipped,
                TotalPoundsPendingForContractItem   = i.TotalWeightPending,
                TotalPoundsRemainingForContractItem = i.TotalWeightRemaining,
            }));

            Mapper.CreateMap <ISalesOrderItemReturn, SalesOrderPickOrderItemResponse>();

            Mapper.CreateMap <IPickOrderDetailReturn <ISalesOrderItemReturn>, SalesOrderPickOrderDetail>();

            Mapper.CreateMap <ISalesOrderSummaryReturn, SalesOrderSummaryResponse>()
            .ForMember(m => m.ShipmentStatus, opt => opt.MapFrom(m => m.Shipment.Status))
            .ForMember(m => m.OrderStatus, opt => opt.MapFrom(m => m.SalesOrderStatus))
            .ForMember(m => m.OrderNum, opt => opt.MapFrom(m => m.MoveNum));

            Mapper.CreateMap <ISalesOrderDetailReturn, SalesOrderDetailsResponse>()
            .ForMember(m => m.ShipmentDate, opt => opt.MapFrom(m => m.Shipment.ShippingInstructions.ShipmentDate))
            .ForMember(m => m.OrderNum, opt => opt.MapFrom(m => m.MoveNum))
            .ForMember(m => m.IsLocked, opt => opt.ResolveUsing(m => m.OrderStatus == OrderStatus.Fulfilled))
            .AfterMap((s, d) => d.Shipment.ShippingInstructions.ShipFromOrSoldTo = s.ShipFromReplace)
            .MapLinkedResource();

            #endregion

            #region Inventory Treatment Orders

            Mapper.CreateMap <ITreatmentOrderDetailReturn, TreatmentOrderDetail>()
            .ForMember(m => m.ShipmentDate, opt => opt.MapFrom(m => m.Shipment.ShippingInstructions.ShipmentDate))
            .ForMember(m => m.PickOrder, opt => opt.MapFrom(m => m.PickOrder))
            .ForMember(m => m.PickedInventory, opt => opt.MapFrom(m => m.PickedInventory))
            .ForMember(m => m.Shipment, opt => opt.MapFrom(m => m.Shipment))
            .ForMember(m => m.OriginFacility, opt => opt.MapFrom(m => m.OriginFacility))
            .ForMember(m => m.IsLocked, opt => opt.ResolveUsing(m => m.OrderStatus == OrderStatus.Fulfilled))
            .ForMember(m => m.EnableReturnFromTreatment, opt => opt.ResolveUsing(m => m.OrderStatus == OrderStatus.Scheduled && m.Shipment.Status == ShipmentStatus.Shipped))
            .MapLinkedResource()
            .AfterMap((mIn, mOut) =>
            {
                var picked = mOut.PickedInventory.PickedInventoryItems.ToList();
                picked.ForEach(i => i.ValidForPicking     = !mOut.IsLocked);
                mOut.PickedInventory.PickedInventoryItems = picked;
            });

            Mapper.CreateMap <ITreatmentOrderSummaryReturn, TreatmentOrderSummary>()
            .ForMember(m => m.Shipment, opt => opt.MapFrom(m => m.Shipment))
            .ForMember(m => m.PickedInventory, opt => opt.MapFrom(m => m.PickedInventory))
            .ForMember(m => m.PickOrder, opt => opt.MapFrom(m => m.PickOrder))
            .ForMember(m => m.OriginFacility, opt => opt.MapFrom(m => m.OriginFacility))
            .ForMember(m => m.EnableReturnFromTreatment, opt => opt.ResolveUsing(m => m.OrderStatus == OrderStatus.Scheduled && m.Shipment.Status == ShipmentStatus.Shipped));

            Mapper.CreateMap <CreateTreatmentOrderRequestParameter, CreateTreatmentOrderParameters>()
            .ForMember(m => m.UserToken, opt => opt.Ignore())
            .AfterMap((s, d) => d.SetShipmentInformation.ShippingInstructions.ShipmentDate = s.HeaderParameters.ShipmentDate);

            Mapper.CreateMap <UpdateTreatmentOrderRequestParameter, UpdateTreatmentOrderParameters>()
            .ForMember(m => m.UserToken, opt => opt.Ignore())
            .AfterMap((s, d) => d.SetShipmentInformation.ShippingInstructions.ShipmentDate = s.HeaderParameters.ShipmentDate);

            Mapper.CreateMap <ReceiveTreatmentOrderRequestParameter, ReceiveTreatmentOrderParameters>()
            .ForMember(m => m.UserToken, opt => opt.Ignore());

            #endregion

            #region Shipments

            Mapper.CreateMap <SetShipmentInformationRequestParameter, SetInventoryShipmentInformationParameters>()
            .ForMember(m => m.InventoryShipmentOrderKey, opt => opt.Ignore())
            .ForMember(m => m.TransitInformation, opt => opt.MapFrom(m => m.Transit));
            Mapper.CreateMap <SetShippingInstructionsRequestParameter, SetShippingInstructionsParameters>()
            .Ignoring(m => m.ShipmentDate)
            .ForMember(m => m.FreightBillTo, opt => opt.MapFrom(m => m.FreightBill));
            Mapper.CreateMap <SetTransitInformationRequestParameter, SetTransitInformationParameter>();

            Mapper.CreateMap <IShipmentSummaryReturn, ShipmentSummary>().
            ForMember(m => m.ScheduledShipDate, opt => opt.ResolveUsing(m => m.ShipmentDate));

            Mapper.CreateMap <IShipmentDetailReturn, ShipmentDetails>()
            .ForMember(m => m.Transit, opt => opt.MapFrom(m => m.TransitInformation));

            Mapper.CreateMap <IShippingInstructions, ShippingInstructions>()
            .ForMember(m => m.ScheduledShipDateTime, opt => opt.MapFrom(m => m.ShipmentDate))
            .ForMember(m => m.ShipFromOrSoldTo, opt => opt.MapFrom(m => m.ShipFromOrSoldToShippingLabel))
            .ForMember(m => m.FreightBill, opt => opt.MapFrom(m => m.FreightBillToShippingLabel))
            .ForMember(m => m.ShipTo, opt => opt.MapFrom(m => m.ShipToShippingLabel));

            Mapper.CreateMap <ITransitInformation, TransitInformation>();
            Mapper.CreateMap <ITransitInformation, TransitViewModel>()
            .ConstructUsing(TransitViewModel.Create);

            Mapper.CreateMap <PostItemDestinationsRequestParameter, PostItemParameters>();
            Mapper.CreateMap <PostAndCloseShipmentOrderRequestParameter, PostParameters>()
            .ForMember(m => m.UserToken, opt => opt.Ignore())
            .ForMember(m => m.OrderKey, opt => opt.Ignore());

            #endregion

            #region Warehouses / Warehouse Locations

            Mapper.CreateMap <IFacilitySummaryReturn, FacilityResponse>()
            .ForMember(m => m.ShippingLabel, opt => opt.Ignore());

            Mapper.CreateMap <IFacilityDetailReturn, FacilityResponse>();

            Mapper.CreateMap <IFacilityDetailReturn, FacilityDetailsResponse>();

            Mapper.CreateMap <SaveFacilityParameter, CreateFacilityParameters>()
            .ForMember(m => m.Name, opt => opt.MapFrom(m => m.FacilityName));

            Mapper.CreateMap <SaveFacilityParameter, UpdateFacilityParameters>()
            .ForMember(m => m.Name, opt => opt.MapFrom(m => m.FacilityName))
            .ForMember(m => m.FacilityKey, opt => opt.Ignore());

            Mapper.CreateMap <ILocationReturn, WarehouseLocationResponse>()
            .ForMember(m => m.WarehouseKey, opt => opt.MapFrom(m => m.FacilityKey))
            .ForMember(m => m.WarehouseName, opt => opt.MapFrom(m => m.FacilityName))
            .ForMember(m => m.WarehouseLocationKey, opt => opt.MapFrom(m => m.LocationKey))
            .ForMember(m => m.LocationName, opt => opt.MapFrom(m => m.Description));

            Mapper.CreateMap <ILocationReturn, FacilityLocationResponse>()
            .ForMember(m => m.GroupName, opt => opt.Ignore())
            .ForMember(m => m.Row, opt => opt.Ignore());

            Mapper.CreateMap <UpdateLocationParameter, UpdateLocationParameters>()
            .ForMember(m => m.Description, opt => opt.ResolveUsing(m => LocationDescriptionHelper.GetDescription(m.GroupName, m.Row)))
            .ForMember(m => m.Active, opt => opt.ResolveUsing(m => m.Status != LocationStatus.InActive))
            .ForMember(m => m.Locked, opt => opt.ResolveUsing(m => m.Status == LocationStatus.Locked));

            Mapper.CreateMap <CreateLocationParameter, CreateLocationParameters>()
            .ForMember(m => m.Description, opt => opt.ResolveUsing(m => LocationDescriptionHelper.GetDescription(m.GroupName, m.Row)))
            .ForMember(m => m.Active, opt => opt.ResolveUsing(m => m.Status != LocationStatus.InActive))
            .ForMember(m => m.Locked, opt => opt.ResolveUsing(m => m.Status == LocationStatus.Locked));

            #endregion

            Mapper.CreateMap <IInventoryTransactionReturn, LotInventoryTransactionResponse>()
            .ForMember(m => m.TransactionDate, opt => opt.ResolveUsing(m => m.TimeStamp))
            .ForMember(m => m.FacilityName, opt => opt.ResolveUsing(m => m.Location.FacilityName))
            .ForMember(m => m.ProductName, opt => opt.ResolveUsing(m => m.Product.ProductName))
            .ForMember(m => m.Treatment, opt => opt.MapFrom(m => m.Treatment.TreatmentNameShort))
            .ForMember(m => m.TransactionSourceReferenceKey, opt => opt.ResolveUsing(m => m.SourceReference));

            Mapper.CreateMap <IInventoryTransactionsByLotReturn, LotInputResponse>()
            .ForMember(m => m.InputItems, opt => opt.ResolveUsing(ToLotInputResponse));

            Mapper.CreateMap <ICustomerProductCodeReturn, CustomerProductCodeResponse>();

            #region Sample Requests

            Mapper.CreateMap <ISampleOrderSummaryReturn, SampleRequestSummaryResponse>();

            Mapper.CreateMap <ISampleOrderItemMatchReturn, SampleRequestItemLabResultsResponse>();
            Mapper.CreateMap <ISampleOrderItemSpecReturn, SampleRequestItemSpecResponse>();
            Mapper.CreateMap <ISampleOrderItemReturn, SampleRequestItemResponse>()
            .Ignoring(m => m.Links);
            Mapper.CreateMap <ISampleOrderJournalEntryReturn, SampleRequestJournalEntryResponse>();
            Mapper.CreateMap <ISampleOrderDetailReturn, SampleRequestDetailResponse>()
            .Ignoring(m => m.Links);

            Mapper.CreateMap <CreateSampleOrderRequest, SetSampleOrderParameters>()
            .ForMember(m => m.ShipmentMethod, opt => opt.MapFrom(m => m.ShipVia))
            .Ignoring(m => m.UserToken, m => m.SampleOrderKey);
            Mapper.CreateMap <CreateSampleItemRequest, SampleOrderItemParameters>()
            .Ignoring(m => m.SampleOrderItemKey);

            Mapper.CreateMap <SetSampleOrderRequest, SetSampleOrderParameters>()
            .ForMember(m => m.ShipmentMethod, opt => opt.MapFrom(m => m.ShipVia))
            .Ignoring(m => m.UserToken, m => m.SampleOrderKey);
            Mapper.CreateMap <UpdateSampleItemRequest, SampleOrderItemParameters>();

            Mapper.CreateMap <SetSampleSpecsRequest, SetSampleSpecsParameters>()
            .Ignoring(m => m.SampleOrderItemKey);
            Mapper.CreateMap <SetSampleMatchRequest, SetSampleMatchParameters>()
            .Ignoring(m => m.SampleOrderItemKey);
            Mapper.CreateMap <SetJournalEntryRequest, SetSampleOrderJournalEntryParameters>()
            .Ignoring(m => m.UserToken, m => m.SampleOrderKey, m => m.JournalEntryKey);

            #endregion

            #region Sales Quotes

            Mapper.CreateMap <ISalesQuoteSummaryReturn, SalesQuoteSummaryResponse>()
            .ForMember(m => m.ScheduledShipDate, opt => opt.ResolveUsing(m => m.ShipmentDate));
            Mapper.CreateMap <ISalesQuoteDetailReturn, SalesQuoteDetailResponse>()
            .MapLinkedResource()
            .AfterMap((s, d) =>
            {
                d.Shipment.ShippingInstructions.ShipFromOrSoldTo = s.ShipFromReplace;
                d.Links = new ResourceLinkCollection();
            });
            Mapper.CreateMap <ISalesQuoteItemReturn, SalesQuoteItemResponse>();

            Mapper.CreateMap <CreateSalesQuoteRequest, SalesQuoteParameters>()
            .Ignoring(m => m.UserToken, m => m.SalesQuoteNumber)
            .AfterMap((s, d) =>
            {
                if (d.ShipmentInformation != null && d.ShipmentInformation.ShippingInstructions != null)
                {
                    if (s.ShipmentInformation != null && s.ShipmentInformation.ShippingInstructions != null)
                    {
                        d.ShipmentInformation.ShippingInstructions.ShipmentDate = s.ShipmentInformation.ShippingInstructions.ScheduledShipDateTime;
                    }
                }
            });
            Mapper.CreateMap <CreateSalesQuoteItemRequest, SalesQuoteItemParameters>()
            .Ignoring(m => m.SalesQuoteItemKey);

            Mapper.CreateMap <UpdateSalesQuoteRequest, SalesQuoteParameters>()
            .Ignoring(m => m.UserToken, m => m.SalesQuoteNumber)
            .AfterMap((s, d) =>
            {
                if (d.ShipmentInformation != null && d.ShipmentInformation.ShippingInstructions != null)
                {
                    if (s.ShipmentInformation != null && s.ShipmentInformation.ShippingInstructions != null)
                    {
                        d.ShipmentInformation.ShippingInstructions.ShipmentDate = s.ShipmentInformation.ShippingInstructions.ScheduledShipDateTime;
                    }
                }
            });
            Mapper.CreateMap <UpdateSalesQuoteItemRequest, SalesQuoteItemParameters>();

            #endregion


            Mapper.AssertConfigurationIsValid();
        }
        private static void SetupProductionBatchPacketReport()
        {
            Mapper.CreateMap <IProductionPacketReturn, IEnumerable <ProductionBatchPacketReportModel> >()
            .ConstructUsing(ps => ps.Batches.Select(b => new ProductionBatchPacketReportModel
            {
                Header = new ProductionBatchPacketReportModel.ProductionBatchPacketReportHeader
                {
                    BatchType          = ps.WorkType.Description,
                    LotNumber          = b.LotKey,
                    PSNum              = ps.PSNum ?? 0,
                    PackScheduleKey    = ps.PackScheduleKey,
                    PackScheduleDate   = ps.DateCreated,
                    ProductNameDisplay = ps.ChileProduct.ProductCodeAndName,
                    Description        = ps.SummaryOfWork,
                    TargetWeight       = b.TargetParameters.BatchTargetWeight,
                    TargetAsta         = b.TargetParameters.BatchTargetAsta,
                    TargetScan         = b.TargetParameters.BatchTargetScan,
                    TargetScoville     = b.TargetParameters.BatchTargetScoville,
                    CalculatedAsta     = b.CalculatedParameters.BatchTargetAsta,
                    CalculatedScan     = b.CalculatedParameters.BatchTargetScan,
                    CalculatedScoville = b.CalculatedParameters.BatchTargetScoville,
                    BatchNotes         = b.Notes,
                },
                PickedChileInventoryItemsByChileType = b.PickedItems
                                                       .Where(p => p.LotProduct.ProductType.HasValue && p.LotProduct.ProductType.Value == ProductTypeEnum.Chile)
                                                       .GroupBy(
                    item => item.LotKey.Substring(0, 2),
                    item => new ProductionBatchPacketReportModel.PickedChileInventoryItem
                {
                    LotNumber     = item.LotKey,
                    LotStatus     = item.QualityStatus.ToString(),
                    PackagingName = item.PackagingProduct.ProductName,
                    PickedFromWarehouseLocationName = LocationDescriptionHelper.FormatLocationDescription(item.Location.Description),
                    ProductNameDisplay = item.LotProduct.ProductName,
                    Quantity           = item.QuantityPicked,
                    WeightPicked       = item.QuantityPicked * item.PackagingProduct.Weight,
                    Treatment          = item.InventoryTreatment.TreatmentNameShort,
                },
                    (g, items) => new KeyValuePair <string, IEnumerable <ProductionBatchPacketReportModel.PickedChileInventoryItem> >(ConvertLotType(g),
                                                                                                                                      items.OrderBy(i => i.PickedFromWarehouseLocationName))),

                PickedAdditiveInventoryItemsByAdditiveType = b.PickedItems
                                                             .Where(p => p.LotProduct.ProductType.HasValue && p.LotProduct.ProductType.Value == ProductTypeEnum.Additive)
                                                             .GroupBy(
                    item => item.LotKey.Substring(0, 2),
                    item => new ProductionBatchPacketReportModel.PickedAdditiveInventoryItem
                {
                    LotNumber     = item.LotKey,
                    PackagingName = item.PackagingReceived.ProductName,            // ?? item.PackagingProduct.ProductName,
                    PickedFromWarehouseLocationName = LocationDescriptionHelper.FormatLocationDescription(item.Location.Description),
                    ProductNameDisplay = item.LotProduct.ProductName,
                    Quantity           = item.QuantityPicked,
                    WeightPicked       = item.QuantityPicked * item.PackagingProduct.Weight,
                },
                    (g, items) => new KeyValuePair <string, IEnumerable <ProductionBatchPacketReportModel.PickedAdditiveInventoryItem> >(ConvertLotType(g),
                                                                                                                                         items.OrderBy(i => i.PickedFromWarehouseLocationName))),

                PickedPackagingInventoryItems = b.PickedItems
                                                .Where(p => p.LotProduct.ProductType.HasValue && p.LotProduct.ProductType.Value == ProductTypeEnum.Packaging)
                                                .Select(item => new ProductionBatchPacketReportModel.PickedPackagingInventoryItem
                {
                    LotNumber = item.LotKey,
                    PickedFromWarehouseLocationName = LocationDescriptionHelper.FormatLocationDescription(item.Location.Description),
                    ProductNameDisplay = item.LotProduct.ProductName,
                    Quantity           = item.QuantityPicked,
                })
                                                .OrderBy(i => i.PickedFromWarehouseLocationName),

                BatchInstructions = b.Instructions.Notes.Select(n => new KeyValuePair <int, string>(0, n.Text)).Distinct(),    // fix indexer
                ExpectedOutputs   = b.PickedItems
                                    .Where(i => i.LotProduct.ProductType.HasValue && i.LotProduct.ProductType.Value == ProductTypeEnum.Packaging)
                                    .Select(p => p.LotProduct.ProductName)
                                    .Concat(new[] { "", "" })
                                    .Select(s => new ProductionBatchPacketReportModel.ExpectedOutput
                {
                    PackagingName = s
                }),
            }));
        }