【问题标题】:How do I get fields such as "cost" from an estimate query using Quickbooks SDK (QBFC)?如何使用 Quickbooks SDK (QBFC) 从估算查询中获取“成本”等字段?
【发布时间】:2019-09-12 19:19:27
【问题描述】:

我正在 Quickbooks 桌面版上通过 QBFC 运行估算查询,虽然我能够提取在 Quickbooks 的估算屏幕上看到的一些字段,但还有其他字段我无法提取/查找.此外,我提取的某些属性与我期望的值不匹配。

我的代码在这里:

...
IEstimateQuery estimateQuery = msgSetReq.AppendEstimateQueryRq();
estimateQuery.OwnerIDList.Add("0");
estimateQuery.ORTxnQuery.TxnFilter.EntityFilter.OREntityFilter.FullNameList.Add("testcustomer");
estimateQuery.IncludeLineItems.SetValue(true);

IMsgSetResponse msgSetResp = sessionManager.DoRequests(msgSetReq);

IResponse resp = msgSetResp.ResponseList.GetAt(0); //a list of responses for each request - we only sent one request so get the first response

IEstimateRetList estimateList = (IEstimateRetList)resp.Detail;
for(int i=0; i < estimateList.Count; i++) {
    IEstimateRet estimate = estimateList.GetAt(i);
    Debug.WriteLine("est name: " + estimate.CustomerRef.FullName.GetValue());
    Debug.WriteLine("est subtotal: " + estimate.Subtotal.GetValue());
    Debug.WriteLine("est total: " + estimate.TotalAmount.GetValue());

    if(estimate.DataExtRetList != null) {
        for(int j=0; j<estimate.DataExtRetList.Count; j++) {
            string fieldName = estimate.DataExtRetList.GetAt(j).DataExtName.GetValue();
            string fieldValue = estimate.DataExtRetList.GetAt(j).DataExtValue.GetValue();
            Debug.WriteLine("--- " + fieldName + " : " + fieldValue);
        }
    }

    if(estimate.OREstimateLineRetList != null) {
        for (int j = 0; j < estimate.OREstimateLineRetList.Count; j++) {
            IEstimateLineRet lineRet = estimate.OREstimateLineRetList.GetAt(j).EstimateLineRet;

            if(lineRet.Amount != null) {
                Debug.WriteLine("total [" + j + "] " + lineRet.Amount.GetValue()); //for some reason amount is estimated par total
                if (lineRet.Desc != null) {
                    Debug.WriteLine("description row [" + j + "] " + lineRet.Desc.GetValue());
                }
            }

            //lineRet.DataExtRetList is null, I've checked
        }
    }
}

我会得到一个示例输出:

est name: testcustomer
est subtotal: 6996.07
est total: 6996.07
--- Net Income : 6530.24
--- Other : 8036
total [0] 4451.1
description row [0] Test item1
total [1] 1952.5
description row [1] Test item2
...

你会注意到我在上面记录了 lineRet.Amount 的值,但如果你看一下我附上的这张图片,金额实际上是在最右边的列上给了我红色圆圈,而不是绿色圆圈(在“金额”列)。

当我记录小计和总计时,我希望在底部附近同时看到绿色和红色圆圈,但我却两次获得了红色圆圈的值(小计未正确显示)。

最后,我无法获得“成本/单位”列(我相信最初命名为“成本”)。

关于如何访问这些字段的任何想法,或者为什么某些字段似乎提取了错误的值?

提前感谢您的宝贵时间。

【问题讨论】:

    标签: c# .net quickbooks qbfc


    【解决方案1】:

    根据documentation

    小计

    税前所有估算行的总和。 (相比之下,小计项目(ItemSubtotal 对象)仅给出 显示在其上方的行中的总金额。)

    因此,SDK 中的“小计”似乎与 UI 中的“小计”具有不同的含义。在 SDK 中,小计是指税前总计。在 UI 中,它表示预标记总计。

    我认为使用 SDK 获得预标记总数的唯一方法是遍历每一行并自行合计。

    // Somewhere outside your loop
    double premarkupSubtotal = 0;
    
    // ...
    // Within your loop
    premarkupSubtotal += (lineRet.ORRate.Rate.GetValue() * lineRet.Quantity.GetValue());
    

    请注意,该行的 Amount 属性似乎代表总金额(费率 * 数量 * 加价)。因此,要找到每条线路的预加价总额,我们可以将线路的费率乘以它的数量。

    关于成本/单位,这似乎是每条线的费率。可以使用以下方法检索:

    lineRet.ORRate.Rate.GetValue()
    

    【讨论】:

    • 感谢凯的帮助!关于使用 ItemQuery .. 我觉得在 Estimates 屏幕中,项目的价格要么是手动输入的,要么是当时从数据库中提取的.. 但在后者的情况下,如果我执行 ItemQuery 并且商品的价格发生了变化,这与估价中显示的价格会不会有所不同?或者,我认为我可以访问加价率,所以也许我可以从那开始向后工作。
    • @SuperXero,啊,是的,对不起,你是对的。执行 ItemQuery 可能不必返回估算中使用的相同费率。我进行了更多测试,看起来您的“成本/单位”代表单位费率,“金额”是指每行的预标记小计。所以在这种情况下,两者都可以从 lineRet 派生。 (成本/单位是 lineRet.ORRate.Rate 和 Amount = lineRet.ORRate.Rate.GetValue() * lineRet.Quantity.GetValue())我将更新我的答案以反映这一点。
    • 做了更多测试。我假设您的“成本/单位”是通过估算模板定制的“成本”列,以将“成本/单位”显示为标题。如果可用,QuickBooks 会使用项目的成本自动填充成本列。如果不可用,则使用销售率。然后根据销售和购买价格之间的差额(减去任何价格水平调整)自动填充加价百分比。因此,“成本”列应对应 SDK 中的 ORRate.Rate。
    • 感谢 Kei - 你是对的,lineRet.ORRate.Rate 绝对是我想要的成本。看起来你是正确的,除了迭代项目(这没问题)之外,小计不可访问。再次感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多