当前位置: 首页>>代码示例>>C#>>正文


C# IInvoice.AsTaxRequest方法代码示例

本文整理汇总了C#中IInvoice.AsTaxRequest方法的典型用法代码示例。如果您正苦于以下问题:C# IInvoice.AsTaxRequest方法的具体用法?C# IInvoice.AsTaxRequest怎么用?C# IInvoice.AsTaxRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IInvoice的用法示例。


在下文中一共展示了IInvoice.AsTaxRequest方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CalculateTaxForInvoice

        /// <summary>
        /// The calculate tax for invoice.
        /// </summary>
        /// <param name="invoice">
        /// The invoice.
        /// </param>
        /// <param name="taxAddress">
        /// The tax address.
        /// </param>
        /// <param name="quoteOnly">
        /// A value indicating whether or not this is a tax quote or a formal tax submission
        /// </param>
        /// <returns>
        /// The <see cref="ITaxCalculationResult"/>.
        /// </returns>
        public ITaxCalculationResult CalculateTaxForInvoice(IInvoice invoice, IAddress taxAddress, bool quoteOnly)
        {
            var defaultStoreAddress = _settings.DefaultStoreAddress;

            string prefix = invoice.InvoiceNumberPrefix;

            if (quoteOnly)
            {                
                invoice.InvoiceNumberPrefix = string.Format("Quote-{0}", Guid.NewGuid());
            }

            var request = invoice.AsTaxRequest(defaultStoreAddress, quoteOnly);
            if (quoteOnly) invoice.InvoiceNumberPrefix = prefix;

            request.CompanyCode = _settings.CompanyCode;

            var avaTaxResult = _avaTaxService.GetTax(request);

            if (avaTaxResult.ResultCode == SeverityLevel.Success)
            {
                var extendedData = new ExtendedDataCollection();

                extendedData.SetValue(Core.Constants.ExtendedDataKeys.TaxTransactionResults, JsonConvert.SerializeObject(avaTaxResult));

                return new TaxCalculationResult(TaxMethod.Name, -1, avaTaxResult.TotalTax, extendedData);
            }

            IEnumerable<ApiResponseMessage> messages;
            try
            {
                messages = avaTaxResult.Messages;
            }
            catch (Exception)
            {                    
                messages = Enumerable.Empty<ApiResponseMessage>();
            }
        
            var exception = new AvaTaxApiException(string.Format("AvaTax returned result code: {0}.  {1}", avaTaxResult.ResultCode, string.Join(Environment.NewLine, messages.Select(x => x.Details))));

            LogHelper.Error<AvaTaxTaxationGatewayMethod>("AvaTax API returned an exception", exception);

            throw exception;
        }
开发者ID:drpeck,项目名称:Merchello,代码行数:58,代码来源:AvaTaxTaxationGatewayMethod.cs


注:本文中的IInvoice.AsTaxRequest方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。