Example #1
0
        public static decimal LineTotalForItem(LineItemDTO li)
        {
            decimal result = li.BasePricePerItem * li.Quantity;

            result += SumUpDiscounts(li);
            return(result);
        }
Example #2
0
        public static void SplitTaxesAcrossItems(decimal taxTotal, decimal subTotal, List <LineItemDTO> items)
        {
            // Total Tax for all items on this schedule is calculated
            // Now, we assign the tax parts to each line item based on their
            // linetotal value. The last item should get the remainder of the tax
            decimal RoundedTotal = Math.Round(taxTotal, 2);

            decimal TotalApplied = 0M;

            for (int i = 0; i < items.Count(); i++)
            {
                LineItemDTO li = items[i];

                li.TaxPortion = 0m;
                if (i == items.Count() - 1)
                {
                    // last item
                    li.TaxPortion = (RoundedTotal - TotalApplied);
                }
                else
                {
                    decimal percentOfTotal = 0;
                    if (LineTotalForItem(li) != 0)
                    {
                        percentOfTotal = LineTotalForItem(li) / subTotal;
                    }
                    decimal part = Math.Round(percentOfTotal * subTotal, 2);
                    li.TaxPortion = part;
                    TotalApplied += part;
                }
            }
        }
Example #3
0
 private static decimal SumUpDiscounts(LineItemDTO li)
 {
     if (li.DiscountDetails != null)
     {
         return((li.DiscountDetails).Sum(y => y.Amount));
     }
     return(0);
 }
        /// <summary>
        ///     Allows you to convert the current line object to the DTO equivalent for use with the REST API
        /// </summary>
        /// <returns>A new instance of LineItemDTO</returns>
        public LineItemDTO ToDto()
        {
            var dto = new LineItemDTO();

            dto.Id               = Id;
            dto.StoreId          = StoreId;
            dto.LastUpdatedUtc   = LastUpdatedUtc;
            dto.BasePricePerItem = BasePricePerItem;

            dto.PromotionIds         = PromotionIds;
            dto.FreeQuantity         = FreeQuantity;
            dto.LineTotal            = LineTotal;
            dto.AdjustedPricePerItem = AdjustedPricePerItem;
            dto.IsUserSuppliedPrice  = IsUserSuppliedPrice;
            dto.IsBundle             = IsBundle;
            dto.IsGiftCard           = IsGiftCard;

            foreach (var detail in DiscountDetails)
            {
                dto.DiscountDetails.Add(detail.ToDto());
            }
            dto.OrderBvin               = OrderBvin ?? string.Empty;
            dto.ProductId               = ProductId ?? string.Empty;
            dto.VariantId               = VariantId ?? string.Empty;
            dto.ProductName             = ProductName ?? string.Empty;
            dto.ProductSku              = ProductSku ?? string.Empty;
            dto.ProductShortDescription = ProductShortDescription ?? string.Empty;
            dto.Quantity         = Quantity;
            dto.QuantityReturned = QuantityReturned;
            dto.QuantityShipped  = QuantityShipped;
            dto.ShippingPortion  = ShippingPortion;
            dto.StatusCode       = StatusCode ?? string.Empty;
            dto.StatusName       = StatusName ?? string.Empty;
            dto.TaxRate          = TaxRate;
            dto.TaxPortion       = TaxPortion;
            foreach (var op in SelectionData.OptionSelectionList)
            {
                dto.SelectionData.Add(op.ToDto());
            }
            dto.IsNonShipping         = IsNonShipping;
            dto.TaxSchedule           = TaxSchedule;
            dto.ProductShippingHeight = ProductShippingHeight;
            dto.ProductShippingLength = ProductShippingLength;
            dto.ProductShippingWeight = ProductShippingWeight;
            dto.ProductShippingWidth  = ProductShippingWidth;
            foreach (var cp in CustomProperties)
            {
                dto.CustomProperties.Add(cp.ToDto());
            }
            dto.ShipFromAddress        = ShipFromAddress.ToDto();
            dto.ShipFromMode           = (ShippingModeDTO)(int)ShipFromMode;
            dto.ShipFromNotificationId = ShipFromNotificationId ?? string.Empty;
            dto.ShipSeparately         = ShipSeparately;
            dto.ExtraShipCharge        = ExtraShipCharge;
            dto.ShippingCharge         = (ShippingChargeTypeDTO)(int)ShippingCharge;

            return(dto);
        }
Example #5
0
        //DTO
        public LineItemDTO ToDto()
        {
            LineItemDTO dto = new LineItemDTO();

            dto.Id               = this.Id;
            dto.StoreId          = this.StoreId;
            dto.LastUpdatedUtc   = this.LastUpdatedUtc;
            dto.BasePricePerItem = this.BasePricePerItem;
            foreach (DiscountDetail detail in this.DiscountDetails)
            {
                dto.DiscountDetails.Add(detail.ToDto());
            }
            dto.OrderBvin               = this.OrderBvin ?? string.Empty;
            dto.ProductId               = this.ProductId ?? string.Empty;
            dto.VariantId               = this.VariantId ?? string.Empty;
            dto.ProductName             = this.ProductName ?? string.Empty;
            dto.ProductSku              = this.ProductSku ?? string.Empty;
            dto.ProductShortDescription = this.ProductShortDescription ?? string.Empty;
            dto.Quantity         = this.Quantity;
            dto.QuantityReturned = this.QuantityReturned;
            dto.QuantityShipped  = this.QuantityShipped;
            dto.ShippingPortion  = this.ShippingPortion;
            dto.StatusCode       = this.StatusCode ?? string.Empty;
            dto.StatusName       = this.StatusName ?? string.Empty;
            dto.TaxPortion       = this.TaxPortion;
            foreach (Catalog.OptionSelection op in this.SelectionData)
            {
                dto.SelectionData.Add(op.ToDto());
            }
            dto.ShippingSchedule      = this.ShippingSchedule;
            dto.TaxSchedule           = this.TaxSchedule;
            dto.ProductShippingHeight = this.ProductShippingHeight;
            dto.ProductShippingLength = this.ProductShippingLength;
            dto.ProductShippingWeight = this.ProductShippingWeight;
            dto.ProductShippingWidth  = this.ProductShippingWidth;
            foreach (CustomProperty cp in this.CustomProperties)
            {
                dto.CustomProperties.Add(cp.ToDto());
            }
            dto.ShipFromAddress        = this.ShipFromAddress.ToDto();
            dto.ShipFromMode           = (ShippingModeDTO)((int)this.ShipFromMode);
            dto.ShipFromNotificationId = this.ShipFromNotificationId ?? string.Empty;
            dto.ShipSeparately         = this.ShipSeparately;
            dto.ExtraShipCharge        = this.ExtraShipCharge;

            return(dto);
        }
Example #6
0
        public void FromDto(LineItemDTO dto)
        {
            if (dto == null)
            {
                return;
            }

            this.Id               = dto.Id;
            this.StoreId          = dto.StoreId;
            this.LastUpdatedUtc   = dto.LastUpdatedUtc;
            this.BasePricePerItem = dto.BasePricePerItem;
            this.DiscountDetails.Clear();
            if (dto.DiscountDetails != null)
            {
                foreach (DiscountDetailDTO detail in dto.DiscountDetails)
                {
                    DiscountDetail d = new DiscountDetail();
                    d.FromDto(detail);
                    this.DiscountDetails.Add(d);
                }
            }
            this.OrderBvin               = dto.OrderBvin ?? string.Empty;
            this.ProductId               = dto.ProductId ?? string.Empty;
            this.VariantId               = dto.VariantId ?? string.Empty;
            this.ProductName             = dto.ProductName ?? string.Empty;
            this.ProductSku              = dto.ProductSku ?? string.Empty;
            this.ProductShortDescription = dto.ProductShortDescription ?? string.Empty;
            this.Quantity         = dto.Quantity;
            this.QuantityReturned = dto.QuantityReturned;
            this.QuantityShipped  = dto.QuantityShipped;
            this.ShippingPortion  = dto.ShippingPortion;
            this.StatusCode       = dto.StatusCode ?? string.Empty;
            this.StatusName       = dto.StatusName ?? string.Empty;
            this.TaxPortion       = dto.TaxPortion;
            this.SelectionData.Clear();
            if (dto.SelectionData != null)
            {
                foreach (OptionSelectionDTO op in dto.SelectionData)
                {
                    Catalog.OptionSelection o = new Catalog.OptionSelection();
                    o.FromDto(op);
                    this.SelectionData.Add(o);
                }
            }
            this.ShippingSchedule      = dto.ShippingSchedule;
            this.TaxSchedule           = dto.TaxSchedule;
            this.ProductShippingHeight = dto.ProductShippingHeight;
            this.ProductShippingLength = dto.ProductShippingLength;
            this.ProductShippingWeight = dto.ProductShippingWeight;
            this.ProductShippingWidth  = dto.ProductShippingWidth;
            this.CustomProperties.Clear();
            if (dto.CustomProperties != null)
            {
                foreach (CustomPropertyDTO cpd in dto.CustomProperties)
                {
                    CustomProperty prop = new CustomProperty();
                    prop.FromDto(cpd);
                    this.CustomProperties.Add(prop);
                }
            }
            this.ShipFromAddress.FromDto(dto.ShipFromAddress);
            this.ShipFromMode           = (Shipping.ShippingMode)((int)dto.ShipFromMode);
            this.ShipFromNotificationId = dto.ShipFromNotificationId ?? string.Empty;
            this.ShipSeparately         = dto.ShipSeparately;
            this.ExtraShipCharge        = dto.ExtraShipCharge;
        }
        /// <summary>
        ///     Allows you to populate the current line item object using a LineItemDTO instance
        /// </summary>
        /// <param name="dto">An instance of the line item from the REST API</param>
        public void FromDto(LineItemDTO dto)
        {
            if (dto == null)
            {
                return;
            }

            Id                   = dto.Id;
            StoreId              = dto.StoreId;
            LastUpdatedUtc       = dto.LastUpdatedUtc;
            BasePricePerItem     = dto.BasePricePerItem;
            LineTotal            = dto.LineTotal;
            AdjustedPricePerItem = dto.AdjustedPricePerItem;
            IsUserSuppliedPrice  = dto.IsUserSuppliedPrice;
            IsBundle             = dto.IsBundle;
            IsGiftCard           = dto.IsGiftCard;
            PromotionIds         = dto.PromotionIds;
            FreeQuantity         = dto.FreeQuantity;

            DiscountDetails.Clear();
            if (dto.DiscountDetails != null)
            {
                foreach (var detail in dto.DiscountDetails)
                {
                    var d = new DiscountDetail();
                    d.FromDto(detail);
                    DiscountDetails.Add(d);
                }
            }
            OrderBvin               = dto.OrderBvin ?? string.Empty;
            ProductId               = dto.ProductId ?? string.Empty;
            VariantId               = dto.VariantId ?? string.Empty;
            ProductName             = dto.ProductName ?? string.Empty;
            ProductSku              = dto.ProductSku ?? string.Empty;
            ProductShortDescription = dto.ProductShortDescription ?? string.Empty;
            Quantity         = dto.Quantity;
            QuantityReturned = dto.QuantityReturned;
            QuantityShipped  = dto.QuantityShipped;
            ShippingPortion  = dto.ShippingPortion;
            TaxRate          = dto.TaxRate;
            TaxPortion       = dto.TaxPortion;
            StatusCode       = dto.StatusCode ?? string.Empty;
            StatusName       = dto.StatusName ?? string.Empty;
            SelectionData.Clear();
            if (dto.SelectionData != null)
            {
                foreach (var op in dto.SelectionData)
                {
                    var o = new OptionSelection();
                    o.FromDto(op);
                    SelectionData.OptionSelectionList.Add(o);
                }
            }
            IsNonShipping         = dto.IsNonShipping;
            TaxSchedule           = dto.TaxSchedule;
            ProductShippingHeight = dto.ProductShippingHeight;
            ProductShippingLength = dto.ProductShippingLength;
            ProductShippingWeight = dto.ProductShippingWeight;
            ProductShippingWidth  = dto.ProductShippingWidth;
            CustomProperties.Clear();
            if (dto.CustomProperties != null)
            {
                foreach (var cpd in dto.CustomProperties)
                {
                    var prop = new CustomProperty();
                    prop.FromDto(cpd);
                    CustomProperties.Add(prop);
                }
            }
            ShipFromAddress.FromDto(dto.ShipFromAddress);
            ShipFromMode           = (ShippingMode)(int)dto.ShipFromMode;
            ShipFromNotificationId = dto.ShipFromNotificationId ?? string.Empty;
            ShipSeparately         = dto.ShipSeparately;
            ExtraShipCharge        = dto.ExtraShipCharge;
            ShippingCharge         = (ShippingChargeType)(int)dto.ShippingCharge;
        }