public IResult Execute(IChileProductKey product, ICustomerKey customer, out IDictionary <AttributeNameKey, ChileProductAttributeRange> productSpec, out IDictionary <AttributeNameKey, CustomerProductAttributeRange> customerSpec)
        {
            productSpec  = null;
            customerSpec = null;

            var customerPredicate = customer == null ? c => false : customer.ToCustomerKey().FindByPredicate;
            var chileProduct      = _lotUnitOfWork.ChileProductRepository.Filter(product.ToChileProductKey().FindByPredicate)
                                    .AsExpandable()
                                    .Select(c => new
            {
                attributeRanges = c.ProductAttributeRanges,
                customerRanges  = c.CustomerProductAttributeRanges.Where(r => customerPredicate.Invoke(r.Customer) && r.Active)
            })
                                    .FirstOrDefault();

            if (chileProduct == null)
            {
                return(new InvalidResult <IDictionary <IAttributeNameKey, IAttributeRange> >(null, string.Format(UserMessages.ChileProductNotFound, product.ToChileProductKey())));
            }

            productSpec  = chileProduct.attributeRanges.ToDictionary(r => r.ToAttributeNameKey(), r => r);
            customerSpec = chileProduct.customerRanges.ToDictionary(r => r.ToAttributeNameKey(), r => r);

            return(new SuccessResult());
        }
Esempio n. 2
0
        internal static IResult <CreateSalesOrderConductorParameters> ToParsedParameters(this ICreateSalesOrderParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            ICustomerKey customerKey = null;

            if (!string.IsNullOrWhiteSpace(parameters.CustomerKey))
            {
                var customerKeyResult = KeyParserHelper.ParseResult <ICustomerKey>(parameters.CustomerKey);
                if (!customerKeyResult.Success)
                {
                    return(customerKeyResult.ConvertTo <CreateSalesOrderConductorParameters>());
                }
                customerKey = customerKeyResult.ResultingObject;
            }

            ICompanyKey brokerKey = null;

            if (!string.IsNullOrWhiteSpace(parameters.BrokerKey))
            {
                var brokerKeyResult = KeyParserHelper.ParseResult <ICompanyKey>(parameters.BrokerKey);
                if (!brokerKeyResult.Success)
                {
                    return(brokerKeyResult.ConvertTo <CreateSalesOrderConductorParameters>());
                }
                brokerKey = brokerKeyResult.ResultingObject;
            }

            var facilityKeyResult = KeyParserHelper.ParseResult <IFacilityKey>(parameters.FacilitySourceKey);

            if (!facilityKeyResult.Success)
            {
                return(facilityKeyResult.ConvertTo <CreateSalesOrderConductorParameters>());
            }

            var orderItemsResult = parameters.PickOrderItems == null ? null : parameters.PickOrderItems.ToParsedParametersList();

            if (orderItemsResult != null && !orderItemsResult.Success)
            {
                return(orderItemsResult.ConvertTo <CreateSalesOrderConductorParameters>());
            }

            return(new SuccessResult().ConvertTo(new CreateSalesOrderConductorParameters
            {
                CreateParameters = parameters,
                CustomerKey = customerKey == null ? null : customerKey.ToCustomerKey(),
                BrokerKey = brokerKey == null ? null : brokerKey.ToCompanyKey(),
                ShipFromFacilityKey = facilityKeyResult.ResultingObject.ToFacilityKey(),
                OrderItems = orderItemsResult == null ? null : orderItemsResult.ResultingObject
            }));
        }
        internal IResult <CustomerNote> Create(ICustomerKey customerKey, DateTime timestamp, ISetCustomerNoteParameters parameters)
        {
            var noteId = new EFUnitOfWorkHelper(_companyUnitOfWork).GetNextSequence <CustomerNote>(c => c.CustomerId == customerKey.CustomerKey_Id, c => c.NoteId);
            var note   = _companyUnitOfWork.CustomerNoteRepository.Add(new CustomerNote
            {
                CustomerId = customerKey.CustomerKey_Id,
                NoteId     = noteId
            });

            return(SetCustomerNote(note, timestamp, parameters));
        }
        internal static PackSchedule SetCustomerKey(this PackSchedule packSchedule, ICustomerKey customerKey)
        {
            if (packSchedule == null)
            {
                throw new ArgumentNullException("packSchedule");
            }

            packSchedule.Customer   = null;
            packSchedule.CustomerId = customerKey == null ? (int?)null : customerKey.CustomerKey_Id;

            return(packSchedule);
        }
        internal static IResult <List <InventoryPickOrderItemParameter> > ToParsedItems(this IEnumerable <ISetInventoryPickOrderItemParameters> parameters)
        {
            var pickedItems = new List <InventoryPickOrderItemParameter>();

            foreach (var item in parameters)
            {
                if (item.Quantity <= 0)
                {
                    return(new InvalidResult <List <InventoryPickOrderItemParameter> >(null, "Quantity cannot be less than or equal to 0."));
                }

                var productKeyResult = KeyParserHelper.ParseResult <IProductKey>(item.ProductKey);
                if (!productKeyResult.Success)
                {
                    return(productKeyResult.ConvertTo <List <InventoryPickOrderItemParameter> >());
                }

                var packagingProductKeyResult = KeyParserHelper.ParseResult <IPackagingProductKey>(item.PackagingKey);
                if (!packagingProductKeyResult.Success)
                {
                    return(packagingProductKeyResult.ConvertTo <List <InventoryPickOrderItemParameter> >());
                }

                IInventoryTreatmentKey treatmentKey = StaticInventoryTreatments.NoTreatment;
                if (!string.IsNullOrEmpty(item.TreatmentKey))
                {
                    var treatmentKeyResult = KeyParserHelper.ParseResult <IInventoryTreatmentKey>(item.TreatmentKey);
                    if (!treatmentKeyResult.Success)
                    {
                        return(treatmentKeyResult.ConvertTo <List <InventoryPickOrderItemParameter> >());
                    }
                    treatmentKey = treatmentKeyResult.ResultingObject;
                }

                ICustomerKey customer = null;
                if (!string.IsNullOrWhiteSpace(item.CustomerKey))
                {
                    var customerKeyResult = KeyParserHelper.ParseResult <ICustomerKey>(item.CustomerKey);
                    if (!customerKeyResult.Success)
                    {
                        return(customerKeyResult.ConvertTo <List <InventoryPickOrderItemParameter> >());
                    }
                    customer = customerKeyResult.ResultingObject;
                }

                pickedItems.Add(new InventoryPickOrderItemParameter(productKeyResult.ResultingObject, packagingProductKeyResult.ResultingObject, treatmentKey, item.Quantity, customer, item.CustomerProductCode, item.CustomerLotCode));
            }

            return(new SuccessResult <List <InventoryPickOrderItemParameter> >(pickedItems));
        }
Esempio n. 6
0
        internal static Lot AddCustomerAllowance(this Lot lot, ICustomerKey customer)
        {
            if (lot.CustomerAllowances == null)
            {
                lot.CustomerAllowances = new List <LotCustomerAllowance>();
            }

            lot.CustomerAllowances.Add(new LotCustomerAllowance
            {
                LotTypeId       = lot.LotTypeId,
                LotDateCreated  = lot.LotDateCreated,
                LotDateSequence = lot.LotDateSequence,
                CustomerId      = customer.CustomerKey_Id
            });

            return(lot);
        }
Esempio n. 7
0
        internal static Contract ConstrainByKeys(this Contract contract, ICustomerKey customerKey, ICompanyKey brokerKey = null)
        {
            if (contract == null)
            {
                throw new ArgumentNullException("contract");
            }

            if (customerKey != null)
            {
                contract.Customer   = null;
                contract.CustomerId = customerKey.CustomerKey_Id;
            }

            if (brokerKey != null)
            {
                contract.Broker   = null;
                contract.BrokerId = brokerKey.CompanyKey_Id;
            }

            return(contract);
        }
Esempio n. 8
0
        internal static SalesOrder ConstrainByKeys(this SalesOrder order, ICustomerKey customerKey, ICompanyKey brokerKey = null)
        {
            if (order == null)
            {
                throw new ArgumentNullException("order");
            }

            if (customerKey != null)
            {
                order.Customer   = null;
                order.CustomerId = customerKey.CustomerKey_Id;
            }

            if (brokerKey != null)
            {
                order.Broker   = null;
                order.BrokerId = brokerKey.CompanyKey_Id;
            }

            return(order);
        }
        internal static Expression <Func <Inventory, bool> > ByAllowance(ICustomerKey customer, ISalesOrderKey salesOrder, IContractKey contract)
        {
            var predicate = PredicateBuilder.False <Inventory>();

            if (contract != null)
            {
                var contractPredicate = LotContractAllowancePredicates.ByContractKey(contract);
                predicate = predicate.Or(i => i.Lot.ContractAllowances.Any(a => contractPredicate.Invoke(a)));
            }

            if (salesOrder != null)
            {
                var customerOrderPredicate = LotCustomerOrderAllowancePredicates.ByCustomerOrderKey(salesOrder);
                predicate = predicate.Or(i => i.Lot.SalesOrderAllowances.Any(a => customerOrderPredicate.Invoke(a)));
            }

            if (customer != null)
            {
                var customerPredicate = LotCustomerAllowancePredicates.ByCustomerKey(customer);
                predicate = predicate.Or(i => i.Lot.CustomerAllowances.Any(a => customerPredicate.Invoke(a)));
            }

            return(predicate);
        }
        public IResult Execute(ICustomerKey customerKey, IChileProductKey chileProductKey, out int?prodId, out string companyIA)
        {
            prodId    = null;
            companyIA = null;

            var predicate = CustomerProductAttributeRangePredicates.ByCustomerProduct(customerKey, chileProductKey);

            foreach (var attributeRange in _salesUnitOfWork.CustomerProductAttributeRangeRepository.Filter(predicate,
                                                                                                           r => r.Customer.Company,
                                                                                                           r => r.ChileProduct.Product).ToList())
            {
                int parsed;
                if (int.TryParse(attributeRange.ChileProduct.Product.ProductCode, out parsed))
                {
                    prodId = parsed;
                }

                companyIA = !string.IsNullOrWhiteSpace(attributeRange.Customer.Company.Name) ? attributeRange.Customer.Company.Name : companyIA;

                _salesUnitOfWork.CustomerProductAttributeRangeRepository.Remove(attributeRange);
            }

            return(new SuccessResult());
        }
Esempio n. 11
0
        public PickingValidatorContext(IDictionary <AttributeNameKey, ChileProductAttributeRange> productSpec,
                                       IDictionary <AttributeNameKey, CustomerProductAttributeRange> customerSpec,
                                       IContractKey contractKey, ISalesOrderKey salesOrderKey, ICustomerKey customerKey)
        {
            if (contractKey != null)
            {
                ContractKey = contractKey.ToContractKey();
            }

            if (salesOrderKey != null)
            {
                CustomerOrderKey = salesOrderKey.ToSalesOrderKey();
            }

            if (customerKey != null)
            {
                CustomerKey = customerKey.ToCustomerKey();
            }

            var productSpecRanges  = productSpec == null ? new Dictionary <string, IAttributeRange>() : productSpec.To().Dictionary <string, IAttributeRange>(p => p.Key, p => p.Value);
            var customerSpecRanges = customerSpec == null ? new Dictionary <string, IAttributeRange>() : customerSpec.To().Dictionary <string, IAttributeRange>(p => p.Key, p => p.Value);

            foreach (var prodSpec in productSpecRanges)
            {
                IAttributeRange custRange;
                if (customerSpecRanges.TryGetValue(prodSpec.Key, out custRange))
                {
                    customerSpecRanges.Remove(prodSpec.Key);
                }

                AttributeSpecs.Add(prodSpec.Key, new PickingValidatorAttributeSpec(prodSpec.Value, custRange));
            }

            foreach (var custSpec in customerSpecRanges)
            {
                AttributeSpecs.Add(custSpec.Key, new PickingValidatorAttributeSpec(null, custSpec.Value));
            }
        }
 internal static Expression <Func <LotCustomerAllowance, bool> > ByCustomerKey(ICustomerKey key)
 {
     return(a => a.CustomerId == key.CustomerKey_Id);
 }
Esempio n. 13
0
 public CustomerProductAttributeRangeKey(ICustomerKey customerKey, IChileProductKey chileProductKey, IAttributeNameKey attributeNameKey) : base(customerKey.CustomerKey_Id, chileProductKey.ChileProductKey_ProductId, attributeNameKey.AttributeNameKey_ShortName)
 {
 }
 internal static SalesQuote SetCustomer(this SalesQuote salesQuote, ICustomerKey customer)
 {
     salesQuote.Customer   = null;
     salesQuote.CustomerId = customer == null ? (int?)null : customer.CustomerKey_Id;
     return(salesQuote);
 }
Esempio n. 15
0
 public static CustomerKey ToCustomerKey(this ICustomerKey k)
 {
     return(new CustomerKey(k));
 }
 public CustomerProductCodeKey(ICustomerKey customerKey, IChileProductKey chileProductKey) : base(customerKey.CustomerKey_Id, chileProductKey.ChileProductKey_ProductId)
 {
 }
Esempio n. 17
0
 public InventoryPickOrderItemParameter(IProductKey productKey, IPackagingProductKey packagingProductKey, IInventoryTreatmentKey treatmentKey, int quantity, ICustomerKey customer, string customerProductCode, string customerLotCode)
 {
     ProductId           = productKey.ProductKey_ProductId;
     PackagingProductId  = packagingProductKey.PackagingProductKey_ProductId;
     TreatmentId         = treatmentKey == null ? (int?)null : treatmentKey.InventoryTreatmentKey_Id;
     Quantity            = quantity;
     CustomerKey         = customer != null ? new CustomerKey(customer) : null;
     CustomerProductCode = customerProductCode;
     CustomerLotCode     = customerLotCode;
 }
Esempio n. 18
0
 internal static Expression <Func <CustomerProductAttributeRange, bool> > ByCustomerProduct(ICustomerKey customerKey, IChileProductKey chileProductKey)
 {
     return(r => r.CustomerId == customerKey.CustomerKey_Id && r.ChileProductId == chileProductKey.ChileProductKey_ProductId);
 }
Esempio n. 19
0
        internal static CustomerProductAttributeRange SetValues(this CustomerProductAttributeRange range, ICustomerKey customer = null, IAttributeNameKey attribute = null, double?min = null, double?max = null,
                                                                IChileProductKey chileProduct = null, bool active = true)
        {
            if (range == null)
            {
                throw new ArgumentNullException("range");
            }

            if (customer != null)
            {
                range.Customer   = null;
                range.CustomerId = customer.CustomerKey_Id;
            }

            if (attribute != null)
            {
                range.AttributeName      = null;
                range.AttributeShortName = attribute.AttributeNameKey_ShortName;
            }

            if (min != null)
            {
                range.RangeMin = min.Value;
            }

            if (max != null)
            {
                range.RangeMax = max.Value;
            }

            if (chileProduct != null)
            {
                range.ChileProduct   = null;
                range.ChileProductId = chileProduct.ChileProductKey_ProductId;
            }

            range.Active = active;

            return(range);
        }
Esempio n. 20
0
 internal static SampleOrder SetRequestCustomer(this SampleOrder sampleOrder, ICustomerKey customer)
 {
     sampleOrder.RequestCustomer   = null;
     sampleOrder.RequestCustomerId = customer == null ? (int?)null : customer.CustomerKey_Id;
     return(sampleOrder);
 }
Esempio n. 21
0
        internal static CustomerProductAttributeRange ConstrainByKeys(this CustomerProductAttributeRange range, ICustomerKey customerKey, IChileProductKey chileProductKey = null)
        {
            if (range == null)
            {
                throw new ArgumentNullException("range");
            }

            if (customerKey != null)
            {
                range.Customer   = null;
                range.CustomerId = customerKey.CustomerKey_Id;
            }

            if (chileProductKey != null)
            {
                range.ChileProduct   = null;
                range.ChileProductId = chileProductKey.ChileProductKey_ProductId;
            }

            return(range);
        }
Esempio n. 22
0
        internal static Expression <Func <SalesQuote, bool> > ByCustomerKey(ICustomerKey customerKey)
        {
            var customerPredicate = customerKey.ToCustomerKey().FindByPredicate;

            return(q => new[] { q.Customer }.Where(c => c != null).Any(c => customerPredicate.Invoke(c)));
        }
        internal static InventoryPickOrderItem SetCustomer(this InventoryPickOrderItem item, ICustomerKey customer)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            if (customer != null)
            {
                item.Customer   = null;
                item.CustomerId = customer == null ? (int?)null : customer.CustomerKey_Id;
            }

            return(item);
        }
Esempio n. 24
0
        internal static CustomerProductCode ConstrainByKeys(this CustomerProductCode productCode, ICustomerKey customerKey, IChileProductKey chileProductKey = null)
        {
            if (productCode == null)
            {
                throw new ArgumentNullException("productCode");
            }

            if (customerKey != null)
            {
                productCode.Customer   = null;
                productCode.CustomerId = customerKey.CustomerKey_Id;
            }

            if (chileProductKey != null)
            {
                productCode.ChileProduct   = null;
                productCode.ChileProductId = chileProductKey.ChileProductKey_ProductId;
            }

            return(productCode);
        }
Esempio n. 25
0
        internal static Expression <Func <Contract, bool> > ByCustomerKey(ICustomerKey customerKey)
        {
            var customerPredicate = customerKey.ToCustomerKey().FindByPredicate;

            return(c => customerPredicate.Invoke(c.Customer));
        }