Beispiel #1
0
 public void AppendShipment(Shipment shipment)
 {
     if (Shipments == null)
     {
         Shipments = new List <Shipment>();
     }
     Shipments.Add(shipment);
 }
Beispiel #2
0
        private async void Initialize(IRepositoryFactory <IFulfillmentCenterRepository> fulfillmentCenterRepositoryFactory)
        {
            IsInitializing = true;

            AvailableFulfillments = await Task.Run(() =>
            {
                using (var fulfillmentCenterRepository = fulfillmentCenterRepositoryFactory.GetRepositoryInstance())
                {
                    var l = new List <FulfillmentCenter>();
                    if (fulfillmentCenterRepository.FulfillmentCenters != null)
                    {
                        l = fulfillmentCenterRepository.FulfillmentCenters.OrderBy(x => x.Name).ToList();
                    }
                    return(l);
                }
            });

            var res = await Task.Run(() =>
            {
                using (var orderRepository = _orderRepositoryFactory.GetRepositoryInstance())
                {
                    var l = new List <Foundation.Orders.Model.Shipment>();
                    if (orderRepository.Shipments != null)
                    {
                        l = orderRepository.Shipments.Expand(
                            "OrderForm/OrderGroup/OrderAddresses,ShipmentItems/LineItem")
                            .Where(ship =>
                                   ship.PicklistId == null &&
                                   (ship.Status == null ||
                                    ship.OrderForm.OrderGroup.Status ==
                                    Foundation.Orders.Model.OrderStatus.InProgress.ToString()) &&
                                   ship.Status ==
                                   Foundation.Orders.Model.ShipmentStatus.Released.ToString()).OrderByDescending(item => item.LastModified).ToList();
                    }
                    return(l);
                }
            });

            SelectedFulfillmentCenter = AvailableFulfillments.Any() ? AvailableFulfillments.First() : null;

            res.ForEach(shipment => Shipments.Add(new Shipment(shipment)));
            OnSpecifiedPropertyChanged("Shipments");
            OnIsValidChanged();
            IsInitializing = false;
        }
Beispiel #3
0
        /// <summary>
        /// Populates collections within table. The tables used will be removed from
        /// the table collection.
        /// Override this method to populate your custom collection objects.
        /// </summary>
        /// <param name="tables">The tables.</param>
        /// <param name="filter">The filter.</param>
        protected override void PopulateCollections(DataTableCollection tables, string filter)
        {
            filter = String.Format("OrderFormId = '{0}'", this.OrderFormId.ToString());

            base.PopulateCollections(tables, filter);

            // Populate object collections
            DataView view = DataHelper.CreateDataView(tables["Shipment"], filter);

            // Read until we are done, since this is a collection
            foreach (DataRowView row in view)
            {
                Shipment orderShipment = (Shipment)OrderContext.Current.ShipmentClassInfo.CreateInstance();
                orderShipment.Load(row);
                orderShipment.PopulateCollectionsInternal(tables, filter);
                Shipments.Add(orderShipment);
            }

            view = DataHelper.CreateDataView(tables["LineItem"], filter);

            // Read until we are done, since this is a collection
            foreach (DataRowView row in view)
            {
                LineItem lineItem = (LineItem)OrderContext.Current.LineItemClassInfo.CreateInstance();
                lineItem.Load(row);
                lineItem.PopulateCollectionsInternal(tables, filter);
                LineItems.Add(lineItem);
            }

            // Populate object collections
            // Populates payments collection
            LoadPayments(tables, filter);

            // Load discounts
            view = DataHelper.CreateDataView(tables["OrderFormDiscount"], filter);

            // Read until we are done, since this is a collection
            foreach (DataRowView row in view)
            {
                OrderFormDiscount discount = new OrderFormDiscount();
                discount.Load(row);
                Discounts.Add(discount);
            }
        }
        Shipments BuildShipments(RealTimeRateCalculationContext context)
        {
            var useDistributors = context.CartItems.HasDistributorComponents() && AppLogic.AppConfigBool("RTShipping.MultiDistributorCalculation");
            var freeShippingAllowsRateSelection = AppLogic.AppConfigBool("FreeShippingAllowsRateSelection");

            var shipments = new Shipments
            {
                HasDistributorItems = useDistributors,
            };

            // Get ship separately cart items
            var packageId = 1;

            foreach (var cartItem in context.CartItems.Where(ci => ci.IsShipSeparately))
            {
                // Only calculate rates for products that require shipping
                if (cartItem.IsDownload ||
                    cartItem.IsSystem ||
                    !cartItem.Shippable ||
                    GiftCard.ProductIsEmailGiftCard(cartItem.ProductID) ||
                    (cartItem.FreeShipping && !freeShippingAllowsRateSelection))
                {
                    continue;
                }

                var packages = new Packages();
                ApplyDestinationForAddress(packages, context.ShipmentAddress);

                if (useDistributors && cartItem.DistributorID > 0)
                {
                    ApplyOriginForDistributor(packages, cartItem.DistributorID);
                }

                packages.AddPackage(new Package(cartItem)
                {
                    PackageId = packageId++,
                });

                shipments.Add(packages);
            }

            // Now get all itmes that do not ship separately, but group them into shipments by distributor.
            // Note that distributor ID 0 will be all of the items without a distributor.
            var maxDistributorId = useDistributors
                                ? DB.GetSqlN("select max(DistributorID) N from ProductDistributor")
                                : 0;

            for (int distributorId = 0; distributorId <= maxDistributorId; distributorId++)
            {
                var remainingItemsWeight         = 0m;
                var remainingItemsInsuranceValue = 0m;
                foreach (var cartItem in context.CartItems.Where(ci => !ci.IsShipSeparately))
                {
                    // Only calculate rates for products that require shipping
                    if (cartItem.IsDownload ||
                        cartItem.IsSystem ||
                        !cartItem.Shippable ||
                        GiftCard.ProductIsEmailGiftCard(cartItem.ProductID) ||
                        (cartItem.FreeShipping && !freeShippingAllowsRateSelection))
                    {
                        continue;
                    }

                    if (useDistributors && cartItem.DistributorID != distributorId)
                    {
                        continue;
                    }

                    var weight = cartItem.Weight;
                    if (weight == 0m)
                    {
                        weight = AppLogic.AppConfigUSDecimal("RTShipping.DefaultItemWeight");
                    }

                    if (weight == 0m)
                    {
                        weight = 0.5m;                         // must have SOMETHING to use!
                    }
                    remainingItemsWeight         += (weight * cartItem.Quantity);
                    remainingItemsInsuranceValue += (cartItem.Price * cartItem.Quantity);
                }

                if (remainingItemsWeight == 0m)
                {
                    continue;
                }

                var package = new Package
                {
                    PackageId    = packageId++,
                    Weight       = remainingItemsWeight + AppLogic.AppConfigUSDecimal("RTShipping.PackageExtraWeight"),
                    Insured      = AppLogic.AppConfigBool("RTShipping.Insured"),
                    InsuredValue = remainingItemsInsuranceValue,
                };

                var packages = new Packages();
                ApplyDestinationForAddress(packages, context.ShipmentAddress);

                if (useDistributors && distributorId != 0)
                {
                    ApplyOriginForDistributor(packages, distributorId);
                }

                packages.AddPackage(package);
                shipments.Add(packages);
            }

            return(shipments);
        }