You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用.NET 8 SDK创建QuickBooks Desktop发票时传递预估金额参数

在QBFC16Lib中为QuickBooks发票添加“Estimate Amount”参数的方法

QuickBooks中的“Estimate Amount”字段依赖于关联的估算单(Estimate),无法直接手动赋值,需要通过关联估算单让QB自动同步该金额,具体实现如下:

现有代码回顾

IMsgSetRequest requestMsgSet = qbSession.CreateMsgSetRequest("US", 16, 0);
requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue;

IInvoiceAdd invoiceAddRq = requestMsgSet.AppendInvoiceAddRq();
invoiceAddRq.CustomerRef.FullName.SetValue(customerRefFullName);
invoiceAddRq.TxnDate.SetValue(invoice.CreatedDate);
invoiceAddRq.DueDate.SetValue(invoice.DueDate);
invoiceAddRq.TemplateRef.FullName.SetValue("My Progress Invoice");

foreach (var scheduled in invoice.Scheduled)
{
    IORInvoiceLineAdd orderLine = invoiceAddRq.ORInvoiceLineAddList.Append();
    orderLine.InvoiceLineAdd.ItemRef.FullName.SetValue(itemName);
    orderLine.InvoiceLineAdd.Amount.SetValue((double)scheduled.WorkThisPeriod);
    orderLine.InvoiceLineAdd.Desc.SetValue(scheduled.Description);
}

实现步骤

1. 发票级别关联估算单(整体进度发票)

如果是基于整个估算单生成进度发票,在InvoiceAdd对象中添加估算单关联,并指定要应用的金额或百分比:

// 关联目标估算单(替换为实际估算单的FullName或ListID)
invoiceAddRq.EstimateRef.FullName.SetValue("客户A-2024Q1项目估算");
// 方式1:指定要应用的金额
invoiceAddRq.AmountToApply.SetValue(1500.00);
// 方式2:指定完成百分比(QB自动计算对应金额)
// invoiceAddRq.PercentComplete.SetValue(30.00);

2. 发票行级别关联估算单行(明细进度发票)

如果需要按估算单行生成对应发票行,在循环中为每个InvoiceLineAdd关联对应的估算单行:

foreach (var scheduled in invoice.Scheduled)
{
    IORInvoiceLineAdd orderLine = invoiceAddRq.ORInvoiceLineAddList.Append();
    orderLine.InvoiceLineAdd.ItemRef.FullName.SetValue(itemName);
    orderLine.InvoiceLineAdd.Amount.SetValue((double)scheduled.WorkThisPeriod);
    orderLine.InvoiceLineAdd.Desc.SetValue(scheduled.Description);
    
    // 关联对应估算单行(替换为实际估算单行的ListID)
    orderLine.InvoiceLineAdd.EstimateLineRef.ListID.SetValue("估算单行的唯一ID");
}

注意事项

  • 关联的估算单必须属于当前发票的客户,否则QB会返回错误
  • 未关联估算单时,“Estimate Amount”字段不会有值,该字段仅同步关联估算单的对应数据
  • 可参考QBFC官方文档,查看IInvoiceAdd和IInvoiceLineAdd的属性定义

内容的提问来源于stack exchange,提问作者Raman Shuliak

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 06:23:20