本文整理汇总了C#中IInvoice.CalculateTaxes方法的典型用法代码示例。如果您正苦于以下问题:C# IInvoice.CalculateTaxes方法的具体用法?C# IInvoice.CalculateTaxes怎么用?C# IInvoice.CalculateTaxes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IInvoice
的用法示例。
在下文中一共展示了IInvoice.CalculateTaxes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PerformTask
/// <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);
}