Exemplo n.º 1
0
        /// <summary>
        /// Builds a <see cref="SalePreparationSummary"/>
        /// </summary>
        /// <param name="manager">
        /// The preparation.
        /// </param>
        /// <returns>
        /// The <see cref="SalePreparationSummary"/>.
        /// </returns>
        public SalePreparationSummary Build(ICheckoutManagerBase manager)
        {
            if (manager.Payment.IsReadyToInvoice())
            {
                var invoice = manager.Payment.PrepareInvoice();
                return(new SalePreparationSummary()
                {
                    TotalLabel = "Total",
                    Currency = _currency,
                    Items = invoice.Items.Where(x => x.LineItemType == LineItemType.Product).Select(x => _basketLineItemFactory.Build(x)),
                    ItemTotal = ModelExtensions.FormatPrice(invoice.TotalItemPrice(), _currency),
                    ShippingTotal = ModelExtensions.FormatPrice(invoice.TotalShipping(), _currency),
                    TaxTotal = ModelExtensions.FormatPrice(invoice.TotalTax(), _currency),
                    DiscountsTotal = ModelExtensions.FormatPrice(invoice.TotalDiscounts(), _currency),
                    InvoiceTotal = ModelExtensions.FormatPrice(invoice.Total, _currency),
                });
            }

            return(new SalePreparationSummary()
            {
                TotalLabel = "Sub Total",
                Currency = _currency,
                Items = manager.Context.ItemCache.Items.Select(x => _basketLineItemFactory.Build(x)),
                ItemTotal = ModelExtensions.FormatPrice(manager.Context.ItemCache.Items.Where(x => x.LineItemType == LineItemType.Product).Sum(x => x.TotalPrice), _currency),
                ShippingTotal = ModelExtensions.FormatPrice(manager.Context.ItemCache.Items.Where(x => x.LineItemType == LineItemType.Shipping).Sum(x => x.TotalPrice), _currency),
                TaxTotal = ModelExtensions.FormatPrice(manager.Context.ItemCache.Items.Where(x => x.LineItemType == LineItemType.Tax).Sum(x => x.TotalPrice), _currency),
                DiscountsTotal = ModelExtensions.FormatPrice(manager.Context.ItemCache.Items.Where(x => x.LineItemType == LineItemType.Discount).Sum(x => x.TotalPrice), _currency),
                InvoiceTotal = ModelExtensions.FormatPrice(manager.Context.ItemCache.Items.Where(x => x.LineItemType != LineItemType.Discount).Sum(x => x.TotalPrice) - manager.Context.ItemCache.Items.Where(x => x.LineItemType == LineItemType.Discount).Sum(x => x.TotalPrice), _currency),
            });
        }
        /// <summary>
        /// Builds a <see cref="SalePreparationSummary"/>
        /// </summary>
        /// <param name="preparation">
        /// The preparation.
        /// </param>
        /// <returns>
        /// The <see cref="SalePreparationSummary"/>.
        /// </returns>
        public SalePreparationSummary Build(SalePreparationBase preparation)
        {
            if (preparation.IsReadyToInvoice())
            {
                var invoice = preparation.PrepareInvoice();
                return(new SalePreparationSummary()
                {
                    TotalLabel = "Total",
                    CurrencySymbol = _currency.Symbol,
                    Items = invoice.Items.Where(x => x.LineItemType == LineItemType.Product).Select(x => _basketLineItemFactory.Build(x)),
                    ItemTotal = ModelExtensions.FormatPrice(invoice.TotalItemPrice(), _currency.Symbol),
                    ShippingTotal = ModelExtensions.FormatPrice(invoice.TotalShipping(), _currency.Symbol),
                    TaxTotal = ModelExtensions.FormatPrice(invoice.TotalTax(), _currency.Symbol),
                    DiscountsTotal = ModelExtensions.FormatPrice(invoice.TotalDiscounts(), _currency.Symbol),
                    InvoiceTotal = ModelExtensions.FormatPrice(invoice.Total, _currency.Symbol)
                });
            }

            return(new SalePreparationSummary()
            {
                TotalLabel = "Sub Total",
                CurrencySymbol = _currency.Symbol,
                Items = preparation.ItemCache.Items.Select(x => _basketLineItemFactory.Build(x)),
                ItemTotal = ModelExtensions.FormatPrice(preparation.ItemCache.Items.Where(x => x.LineItemType == LineItemType.Product).Sum(x => x.TotalPrice), _currency.Symbol),
                ShippingTotal = ModelExtensions.FormatPrice(preparation.ItemCache.Items.Where(x => x.LineItemType == LineItemType.Shipping).Sum(x => x.TotalPrice), _currency.Symbol),
                TaxTotal = ModelExtensions.FormatPrice(preparation.ItemCache.Items.Where(x => x.LineItemType == LineItemType.Tax).Sum(x => x.TotalPrice), _currency.Symbol),
                DiscountsTotal = ModelExtensions.FormatPrice(preparation.ItemCache.Items.Where(x => x.LineItemType == LineItemType.Discount).Sum(x => x.TotalPrice), _currency.Symbol),
                InvoiceTotal = ModelExtensions.FormatPrice(preparation.ItemCache.Items.Where(x => x.LineItemType != LineItemType.Discount).Sum(x => x.TotalPrice) - preparation.ItemCache.Items.Where(x => x.LineItemType == LineItemType.Discount).Sum(x => x.TotalPrice), _currency.Symbol)
            });
        }