Exemple #1
0
        public IResult <string> SetSalesQuote(ISalesQuoteParameters parameters, bool updateExisting)
        {
            var parsedParameters = parameters.ToParsedParameters(updateExisting);

            if (!parsedParameters.Success)
            {
                return(parsedParameters.ConvertTo <string>());
            }

            var result = new SetSalesQuoteConductor(_inventoryShipmentOrderUnitOfWork).Execute(_timeStamper.CurrentTimeStamp, parsedParameters.ResultingObject);

            if (!result.Success)
            {
                return(result.ConvertTo <string>());
            }

            _inventoryShipmentOrderUnitOfWork.Commit();

            var salesQuoteKey = result.ResultingObject.ToSalesQuoteKey();

            return(SyncParameters.Using(new SuccessResult <string>(salesQuoteKey), new SyncSalesQuoteParameters
            {
                SalesQuoteKey = salesQuoteKey,
                New = !updateExisting
            }));
        }
 public IResult <string> SetSalesQuote(ISalesQuoteParameters parameters, bool updateExisting = false)
 {
     try
     {
         return(_salesServiceProvider.SetSalesQuote(parameters, updateExisting));
     }
     catch (Exception ex)
     {
         ex = ex.GetBaseException();
         _exceptionLogger.LogException(ex);
         return(new FailureResult <string>(null, ex.Message));
     }
 }
        internal static IResult <SalesQuoteParameters> ToParsedParameters(this ISalesQuoteParameters parameters, bool updateExisting)
        {
            if (updateExisting && parameters.SalesQuoteNumber == null)
            {
                return(new InvalidResult <SalesQuoteParameters>(null, UserMessages.SalesQuoteNumberRequired));
            }

            FacilityKey sourceFacilityKey = null;

            if (!string.IsNullOrWhiteSpace(parameters.SourceFacilityKey))
            {
                var sourceFacilityKeyResult = KeyParserHelper.ParseResult <IFacilityKey>(parameters.SourceFacilityKey);
                if (!sourceFacilityKeyResult.Success)
                {
                    return(sourceFacilityKeyResult.ConvertTo <SalesQuoteParameters>());
                }
                sourceFacilityKey = sourceFacilityKeyResult.ResultingObject.ToFacilityKey();
            }

            CustomerKey customerKey = null;

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

            CompanyKey brokerKey = null;

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

            var itemParameters = new List <SalesQuoteItemParameters>();

            foreach (var item in parameters.Items ?? new ISalesQuoteItemParameters[0])
            {
                SalesQuoteItemKey itemKey = null;
                if (updateExisting && !string.IsNullOrWhiteSpace(item.SalesQuoteItemKey))
                {
                    var itemKeyResult = KeyParserHelper.ParseResult <ISalesQuoteItemKey>(item.SalesQuoteItemKey);
                    if (!itemKeyResult.Success)
                    {
                        return(itemKeyResult.ConvertTo <SalesQuoteParameters>());
                    }
                    itemKey = itemKeyResult.ResultingObject.ToSalesQuoteItemKey();
                }

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

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

                var treatmentKeyResult = KeyParserHelper.ParseResult <IInventoryTreatmentKey>(item.TreatmentKey);
                if (!treatmentKeyResult.Success)
                {
                    return(treatmentKeyResult.ConvertTo <SalesQuoteParameters>());
                }

                itemParameters.Add(new SalesQuoteItemParameters
                {
                    Parameters            = item,
                    SalesQuoteItemKey     = itemKey,
                    ProductKey            = productKeyResult.ResultingObject.ToProductKey(),
                    PackagingProductKey   = packagingKeyResult.ResultingObject.ToPackagingProductKey(),
                    InventoryTreatmentKey = treatmentKeyResult.ResultingObject.ToInventoryTreatmentKey()
                });
            }

            return(new SuccessResult <SalesQuoteParameters>(new SalesQuoteParameters
            {
                Parameters = parameters,
                SalesQuoteNumber = updateExisting ? parameters.SalesQuoteNumber : null,
                SourceFacilityKey = sourceFacilityKey,
                CustomerKey = customerKey,
                BrokerKey = brokerKey,
                Items = itemParameters
            }));
        }
        internal static void AssertEqual(this ISalesQuoteParameters expected, SalesQuote result)
        {
            if (expected.SalesQuoteNumber != null)
            {
                Assert.AreEqual(expected.SalesQuoteNumber, result.QuoteNum);
            }

            Assert.AreEqual(expected.QuoteDate, result.QuoteDate);
            Assert.AreEqual(expected.DateReceived, result.DateReceived);
            Assert.AreEqual(expected.CalledBy, result.CalledBy);
            Assert.AreEqual(expected.TakenBy, result.TakenBy);
            Assert.AreEqual(expected.UserToken, result.Employee.UserName);

            if (!string.IsNullOrWhiteSpace(expected.SourceFacilityKey))
            {
                Assert.AreEqual(expected.SourceFacilityKey, result.SourceFacility.ToFacilityKey().KeyValue);
            }
            else
            {
                Assert.IsNull(result.SourceFacility);
            }

            if (!string.IsNullOrWhiteSpace(expected.CustomerKey))
            {
                Assert.AreEqual(expected.CustomerKey, result.Customer.ToCustomerKey().KeyValue);
            }
            else
            {
                Assert.IsNull(result.Customer);
            }

            if (!string.IsNullOrWhiteSpace(expected.BrokerKey))
            {
                Assert.AreEqual(expected.BrokerKey, result.Broker.ToCompanyKey().KeyValue);
            }
            else
            {
                Assert.IsNull(result.Broker);
            }

            expected.ShipmentInformation.AssertEqual(result.ShipmentInformation, result.SoldTo);

            var resultItems = result.Items.ToList();

            (expected.Items ?? new ISalesQuoteItemParameters[0]).All(e =>
            {
                var match = resultItems.FirstOrDefault(r =>
                                                       (e.SalesQuoteItemKey == null || (e.SalesQuoteItemKey == r.ToSalesQuoteItemKey().KeyValue)) &&
                                                       e.ProductKey == r.Product.ToProductKey().KeyValue&&
                                                       e.PackagingKey == r.PackagingProduct.ToPackagingProductKey().KeyValue&&
                                                       e.TreatmentKey == r.Treatment.ToInventoryTreatmentKey().KeyValue&&
                                                       e.Quantity == r.Quantity &&
                                                       e.PriceBase == r.PriceBase &&
                                                       e.PriceFreight == r.PriceFreight &&
                                                       e.PriceTreatment == r.PriceTreatment &&
                                                       e.PriceWarehouse == r.PriceWarehouse &&
                                                       e.PriceRebate == r.PriceRebate);
                Assert.IsNotNull(match);
                resultItems.Remove(match);
                return(true);
            });
        }