Пример #1
0
        /// <summary>
        /// Performs the task of applying taxes to the invoice.
        /// </summary>
        /// <param name="value">
        /// The <see cref="IInvoice"/>
        /// </param>
        /// <returns>
        /// The <see cref="Attempt"/>.
        /// </returns>
        public override Attempt<IInvoice> PerformTask(IInvoice value)
        {
            // if taxes are not to be applied, skip this step
            if (this.SalePreparation.ApplyTaxesToInvoice)
            {
                try
                {
                    // clear any current tax lines
                    var removers = value.Items.Where(x => x.LineItemType == LineItemType.Tax);
                    foreach (var remove in removers)
                    {
                        value.Items.Remove(remove);
                    }

                    IAddress taxAddress = null;
                    var shippingItems = value.ShippingLineItems().ToArray();
                    if (shippingItems.Any())
                    {
                        var shipment = shippingItems.First().ExtendedData.GetShipment<OrderLineItem>();
                        taxAddress = shipment.GetDestinationAddress();
                    }

                    taxAddress = taxAddress ?? value.GetBillingAddress();

                    this.SetTaxableSetting(value);
                    var taxes = value.CalculateTaxes(this.SalePreparation.MerchelloContext, taxAddress);
                    this.SetTaxableSetting(value, true);                    

                    var taxLineItem = taxes.AsLineItemOf<InvoiceLineItem>();

                    var currencyCode =
                        this.SalePreparation.MerchelloContext.Services.StoreSettingService.GetByKey(
                            Core.Constants.StoreSettingKeys.CurrencyCodeKey).Value;

                    taxLineItem.ExtendedData.SetValue(Core.Constants.ExtendedDataKeys.CurrencyCode, currencyCode);

                    value.Items.Add(taxLineItem);

                    return Attempt<IInvoice>.Succeed(value);
                }
                catch (Exception ex)
                {
                    return Attempt<IInvoice>.Fail(ex);
                }
            }

            return Attempt<IInvoice>.Succeed(value);
        }
Пример #2
0
        /// <summary>
        /// Performs the task of applying taxes to the invoice.
        /// </summary>
        /// <param name="value">
        /// The <see cref="IInvoice"/>
        /// </param>
        /// <returns>
        /// The <see cref="Attempt"/>.
        /// </returns>
        public override Attempt <IInvoice> PerformTask(IInvoice value)
        {
            // if taxes are not to be applied, skip this step
            if (this.SalePreparation.ApplyTaxesToInvoice)
            {
                try
                {
                    // clear any current tax lines
                    var removers = value.Items.Where(x => x.LineItemType == LineItemType.Tax);
                    foreach (var remove in removers)
                    {
                        value.Items.Remove(remove);
                    }

                    IAddress taxAddress    = null;
                    var      shippingItems = value.ShippingLineItems().ToArray();
                    if (shippingItems.Any())
                    {
                        var shipment = shippingItems.First().ExtendedData.GetShipment <OrderLineItem>();
                        taxAddress = shipment.GetDestinationAddress();
                    }

                    taxAddress = taxAddress ?? value.GetBillingAddress();

                    this.SetTaxableSetting(value);
                    var taxes = value.CalculateTaxes(this.SalePreparation.MerchelloContext, taxAddress);
                    this.SetTaxableSetting(value, true);

                    var taxLineItem = taxes.AsLineItemOf <InvoiceLineItem>();

                    var currencyCode =
                        this.SalePreparation.MerchelloContext.Services.StoreSettingService.GetByKey(
                            Core.Constants.StoreSetting.CurrencyCodeKey).Value;

                    taxLineItem.ExtendedData.SetValue(Core.Constants.ExtendedDataKeys.CurrencyCode, currencyCode);

                    value.Items.Add(taxLineItem);

                    return(Attempt <IInvoice> .Succeed(value));
                }
                catch (Exception ex)
                {
                    return(Attempt <IInvoice> .Fail(ex));
                }
            }

            return(Attempt <IInvoice> .Succeed(value));
        }
        public override Attempt <IInvoice> PerformTask(IInvoice value)
        {
            // if taxes are not to be applied, skip this step
            if (SalePreparation.ApplyTaxesToInvoice)
            {
                try
                {
                    // clear any current tax lines
                    var removers = value.Items.Where(x => x.LineItemType == LineItemType.Tax);
                    foreach (var remove in removers)
                    {
                        value.Items.Remove(remove);
                    }

                    var taxes = value.CalculateTaxes(SalePreparation.MerchelloContext, value.GetBillingAddress());

                    var taxLineItem = taxes.AsLineItemOf <InvoiceLineItem>();

                    var currencyCode =
                        SalePreparation.MerchelloContext.Services.StoreSettingService.GetByKey(
                            Constants.StoreSettingKeys.CurrencyCodeKey).Value;

                    taxLineItem.ExtendedData.SetValue(Constants.ExtendedDataKeys.CurrencyCode, currencyCode);

                    value.Items.Add(taxLineItem);

                    return(Attempt <IInvoice> .Succeed(value));
                }
                catch (Exception ex)
                {
                    return(Attempt <IInvoice> .Fail(ex));
                }
            }

            return(Attempt <IInvoice> .Succeed(value));
        }
Пример #4
0
 /// <summary>
 /// Calculates taxes for the invoice
 /// </summary>
 /// <param name="invoice">The <see cref="IInvoice"/></param>
 /// <param name="taxAddress">The address (generally country code and region) to be used to determine the taxation rates</param>
 /// <param name="quoteOnly">A value indicating whether or not the taxes should be calculated as a quote</param>
 /// <returns>The <see cref="ITaxCalculationResult"/> from the calculation</returns>
 public static ITaxCalculationResult CalculateTaxes(this IInvoice invoice, IAddress taxAddress, bool quoteOnly = true)
 {
     return(invoice.CalculateTaxes(MerchelloContext.Current, taxAddress, quoteOnly));
 }
Пример #5
0
 /// <summary>
 /// Calculates taxes for the invoice
 /// </summary>
 /// <param name="invoice">
 /// The <see cref="IInvoice"/>
 /// </param>
 /// <param name="quoteOnly">
 /// A value indicating whether or not the taxes should be calculated as a quote
 /// </param>
 /// <returns>
 /// The <see cref="ITaxCalculationResult"/> from the calculation
 /// </returns>
 public static ITaxCalculationResult CalculateTaxes(this IInvoice invoice, bool quoteOnly = true)
 {
     return(invoice.CalculateTaxes(invoice.GetBillingAddress(), quoteOnly));
 }
Пример #6
0
 /// <summary>
 /// Calculates taxes for the invoice
 /// </summary>
 /// <param name="invoice">The <see cref="IInvoice"/></param>
 /// <param name="taxAddress">The address (generally country code and region) to be used to determine the taxation rates</param>
 /// <returns>The <see cref="ITaxCalculationResult"/> from the calculation</returns>
 public static ITaxCalculationResult CalculateTaxes(this IInvoice invoice, IAddress taxAddress)
 {
     return(invoice.CalculateTaxes(MerchelloContext.Current, taxAddress));
 }
Пример #7
0
 /// <summary>
 /// Calculates taxes for the invoice
 /// </summary>
 /// <param name="invoice">The <see cref="IInvoice"/></param>
 /// <returns>The <see cref="ITaxCalculationResult"/> from the calculation</returns>
 public static ITaxCalculationResult CalculateTaxes(this IInvoice invoice)
 {
     return(invoice.CalculateTaxes(invoice.GetBillingAddress()));
 }