要解决"Acumatica和Avalara无法获取税收"的问题,你需要确保正确配置和使用这两个软件,并使用适当的代码示例来获取税收信息。下面是一个基本的解决方案:
确保已正确配置和连接Acumatica和Avalara。
使用Acumatica的API来获取税收信息的代码示例:
using PX.Data;
using PX.Objects.TX;
public class MyTaxCalculationClass
{
public decimal GetTaxAmount(int inventoryID, decimal unitPrice, string customerTaxZone)
{
decimal taxAmount = 0;
// 获取税收地点
TaxZone taxZone = PXSelect>>>.Select(Base, customerTaxZone);
// 获取税收计算器
TaxCalc taxCalc = new TaxCalc();
// 计算税收
taxAmount = taxCalc.CalculateTax(Base, inventoryID, taxZone.TaxZoneID, unitPrice);
return taxAmount;
}
}
using AvaTaxCalcREST;
using AvaTaxCalcREST.Batching;
using AvaTaxCalcREST.Tax;
public class MyTaxCalculationClass
{
public decimal GetTaxAmount(int inventoryID, decimal unitPrice, string customerTaxZone)
{
decimal taxAmount = 0;
// 创建Avalara客户端
AvaTaxClient client = new AvaTaxClient("MyAccount", "MyLicenseKey", "MyMachineName", AvaTaxEnvironment.Production);
// 创建税收请求
GetTaxRequest taxRequest = new GetTaxRequest();
// 设置请求参数
taxRequest.CustomerCode = customerTaxZone;
taxRequest.DetailLevel = DetailLevel.Tax;
taxRequest.DocCode = "MyDocCode";
taxRequest.CompanyCode = "MyCompanyCode";
taxRequest.DocType = DocumentType.SalesInvoice;
// 添加行项目
Line line = new Line();
line.No = "1";
line.Amount = unitPrice;
line.ItemCode = inventoryID.ToString();
taxRequest.Lines.Add(line);
// 发送请求并获取税收结果
GetTaxResult taxResult = client.GetTax(taxRequest);
// 提取税收金额
foreach (TaxLine taxLine in taxResult.TaxLines)
{
taxAmount += taxLine.Tax;
}
return taxAmount;
}
}
请注意,上述代码示例仅作为参考,实际情况可能需要根据你的特定需求进行调整和修改。另外,确保你已正确引用和配置Acumatica和Avalara的相关程序集和API密钥。