我正在尝试发送使用 Intuit .NET SDK v3 创建的 PurchaseOrder。我找到了一个合适的 Invoice 示例:如何添加发票或销售收据 quickbooks rest api v3.0
但我无法弄清楚我需要做什么才能使其适用于采购订单。无论我设置什么属性,我都会收到 BadRequest。
DataService commonService = new DataService(context);
QueryService<Vendor> accountQueryService = new QueryService<Vendor>(context);
Vendor customer = accountQueryService.Where(x => x.Id == "9").FirstOrDefault<Vendor>();
QueryService<Item> itemQueryService = new QueryService<Item>(context);
Item item = itemQueryService.Where(x => x.Id == "1").FirstOrDefault<Item>();
PurchaseOrder invoice = new PurchaseOrder();
invoice.VendorRef = new ReferenceType()
{
name = customer.DisplayName,
Value = customer.Id
};
/*invoice.APAccountRef = new ReferenceType()
{
type = Enum.GetName(typeof(objectNameEnumType), objectNameEnumType.Account),
name = "Account Receivable",
Value = "QB:37"
};*/
List<Line> lineList = new List<Line>();
Line line = new Line();
line.Description = "Description";
line.Amount = new Decimal(100.00);
line.AmountSpecified = true;
//line.DetailType = LineDetailTypeEnum.DescriptionOnly;
//line.DetailTypeSpecified = true;
line.DetailType = LineDetailTypeEnum.PurchaseOrderItemLineDetail;
line.DetailTypeSpecified = true;
PurchaseOrderItemLineDetail det = new PurchaseOrderItemLineDetail();
det.Qty = 10;
det.QtySpecified = true;
det.ItemRef = new ReferenceType()
{
name = item.Name,
Value = item.Id
};
line.AnyIntuitObject = det;
lineList.Add(line);
invoice.Line = lineList.ToArray();
我尝试设置帐户并仅在该行中使用描述,但没有成功。如果我添加使用上述代码创建的 PurchaseOrder,我会收到 BadRequest 错误,其中包含 Validation 异常。
可以请有人在这里指出我正确的方向。我可能缺少一些 PurchaseOrder 属性。
我正在使用使用 NuGet 加载的 August V3 SDK。
更新
这是下面 Manas Mukherjee 建议的 XML 的 c# 翻译
DataService commonService = new DataService(context);
QueryService<Vendor> accountQueryService = new QueryService<Vendor>(context);
Vendor customer = accountQueryService.Where(x => x.Id == "9").FirstOrDefault<Vendor>();
QueryService<Item> itemQueryService = new QueryService<Item>(context);
Item item = itemQueryService.Where(x => x.Id == "1").FirstOrDefault<Item>();
PurchaseOrder invoice = new PurchaseOrder();
invoice.TxnDate = DateTime.Now;
invoice.TxnDateSpecified = true;
invoice.Memo = "For Internal usage";
invoice.GlobalTaxCalculation = GlobalTaxCalculationEnum.TaxInclusive;
invoice.GlobalTaxCalculationSpecified = true;
invoice.ReplyEmail = new EmailAddress();
invoice.ReplyEmail.Address = "testing@testing.com";
invoice.ReplyEmail.Default = false;
invoice.ReplyEmail.DefaultSpecified = true;
invoice.ReplyEmail.Tag = "Home";
invoice.ShipAddr = new PhysicalAddress();
invoice.ShipAddr.Line1 = "shippingToAddr1Sat Oct 19 09:48:52 IST 2013";
invoice.ShipAddr.Line2 = "shippingToAddr2Sat Oct 19 09:48:52 IST 2013";
invoice.ShipAddr.Line3 = "shippingToAddr3Sat Oct 19 09:48:52 IST 2013";
invoice.ShipAddr.City = "Bangalore";
invoice.ShipAddr.Country = "India";
invoice.ShipAddr.CountrySubDivisionCode = "KA";
invoice.ShipAddr.PostalCode = "560045";
invoice.POEmail = new EmailAddress();
invoice.POEmail.Address = "testing@testing.com";
invoice.POEmail.Default = true;
invoice.POEmail.DefaultSpecified = true;
invoice.POEmail.Tag = "Business";
invoice.VendorRef = new ReferenceType()
{
name = customer.DisplayName,
Value = customer.Id
};
invoice.TotalAmt = new Decimal(100.00);
invoice.TotalAmtSpecified = true;
invoice.APAccountRef = new ReferenceType()
{
//type = Enum.GetName(typeof(objectNameEnumType), objectNameEnumType.Account),
name = "Accounts Payable (A/P)",
Value = "32"
};
List<Line> lineList = new List<Line>();
Line line = new Line();
line.Amount = new Decimal(100.00);
line.AmountSpecified = true;
line.DetailType = LineDetailTypeEnum.AccountBasedExpenseLineDetail;
line.DetailTypeSpecified = true;
AccountBasedExpenseLineDetail det = new AccountBasedExpenseLineDetail();
det.AccountRef = new ReferenceType()
{
name = "Accounts Payable (A/P)",
Value = "32"
};
line.AnyIntuitObject = det;
/*PurchaseOrderItemLineDetail det = new PurchaseOrderItemLineDetail();
det.Qty = 10;
det.QtySpecified = true;
det.ItemRef = new ReferenceType()
{
name = item.Name,
Value = item.Id
};
line.AnyIntuitObject = det;*/
lineList.Add(line);
invoice.Line = lineList.ToArray();
return invoice;
不幸的是,我仍然收到 BadRequest 错误。
更新 2
经过更多测试后,我发现它由于 APAccountRef 属性而出错。不设置这个属性也没关系。
当我尝试在行中使用 PurchaseOrderItemLineDetail 时,出现了另一个问题。不确定这种类型是否正确(基于它看起来像一个的名称),但使用这种详细信息类型会导致 BadRequest 错误。使用 ItemBasedExpenseLineDetail 是一种解决方法。
我会将 Manas 的答案设置为正确,因为它给了我进一步调查的方向。但非常感谢 Nimisha Shrivastava 对伐木的帮助。