Search code examples
c#asp.netquickbooksnsoftware

Automatically closing an open balance on a new SalesOrder record in Quickbooks


I'm attempting to create a sale record in quickbooks using the nsoftware sdk. The following code creates the sale item in Quickbooks as desired except it shows an "Open Balance" and a status of "Open".

enter image description here

    var total = "999";

    var connectionString = config.ToString(); 

    var report = new nsoftware.InQB.Salesorder
    {
        QBConnectionString = config.ToString(),
        CustomerName = "Internal Application Test", 
    }; 

    var salesOrderItem = new SalesOrderItem(); 
    salesOrderItem.ItemName = "Daily Cash Sales Test";
    salesOrderItem.Amount = total;

    //salesOrderItem.ManuallyClosed = ManuallyCloseds.mcManuallyClosed;

    report.LineItems.Add(salesOrderItem);

    await report.OpenQBConnectionAsync().ConfigureAwait(false);

    bool isSuccess = true;

    try
    {
        await report.AddAsync().ConfigureAwait(false);   
    }
    catch (Exception x)
    {
        System.Diagnostics.Debug.WriteLine(x);
        isSuccess = false;
    }
    finally
    {
        await report.CloseQBConnectionAsync().ConfigureAwait(false);
    }

I've attempted to close the sale by including a call to manually closed:

salesOrderItem.ManuallyClosed = ManuallyCloseds.mcManuallyClosed;

Which doesn't seem to have any affect at all.

My Question

Is there a way to zero out the open balance and close the sale programmatically?


Solution

  • As far as I can tell, you can't simply zero out the balance and close a sales order. You have to jump through a few hoops.

    In order to mark the Sales order as paid with a zero balance, you'll need to create an invoice for the customer of your Sales order. Then, you need to apply a payment (ReceivePayment) to the invoice. This will cause your sales order to be marked as paid with a zero balance.

    You can use this official Intuit resource to build the necessary queries:

    https://developer-static.intuit.com/qbSDK-current/Common/newOSR/index.html

    The Consolibyte website also contains a bunch of useful examples here:

    http://www.consolibyte.com/docs/index.php/Example_qbXML_Requests

    Of course, if anyone has a better solution, feel free to post it and I will reconsider the selected answer.