Search code examples
c#.netquickbooksqbfc

How do I get fields such as "cost" from an estimate query using Quickbooks SDK (QBFC)?


I'm running an estimate query through QBFC on Quickbooks Desktop Edition, and while I'm able to pull some fields that I see on the Estimate screen in Quickbooks, there are other fields that I am not able to pull/find. Furthermore, some attributes I'm pulling don't match the values I'm expecting.

My code is here:

...
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
        }
    }
}

I'd get an example output of:

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
...

You'll notice above that I log lineRet.Amount's value, but if you look at this picture I've attached, amount is actually giving me the red circle on the far right column as opposed to the green circle (under the 'Amount' column).

When I log subtotal and total, I expect to see both the green and red circles near the bottom, but instead I'm getting the value of the red circle twice (subtotal is not coming out correctly).

Finally, I am unable to get the "Cost / Unit" column (which was originally named 'Cost' I believe).

Any ideas on how to access these fields, or why some fields seem to be pulling the wrong values?

Thank you in advance for your time.

Examples of what I'm getting and what I want to get


Solution

  • According to the documentation:

    Subtotal

    The total of all the estimate lines before taxes are applied. (By contrast, a subtotal item (an ItemSubtotal object) gives only the total of the amounts in the lines that appear above it.)

    Thus, it looks like the "Subtotal" in the SDK has a different meaning from the "Subtotal" in the UI. In the SDK, the subtotal means the pre-tax total. In the UI, it means the pre-markup total.

    I think the only way to get the pre-markup total using the SDK is to iterate over each line and total it yourself.

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

    Note that the line's Amount property seems to represent the total amount (rate * quantity * markup). Thus, to find the pre-markup total for each line, we can just multiple the line's rate by its quantity instead.

    With regards to the Cost / Unit, this seems to be the rate for each line. This can be retrieved using:

    lineRet.ORRate.Rate.GetValue()