consolibyte / quickbooks-php

QuickBooks Integration for PHP
Eclipse Public License 1.0
458 stars 338 forks source link

Modifying Sales Receipt Line #293

Open shabananavas opened 3 years ago

shabananavas commented 3 years ago

I'm trying to modify an already synced Sales Receipt to Quickbooks again. Changing the values in the billing address works just fine. However, I can't seem to figure out how to update the line items in the Sales Receipt. I'm not getting any errors, but the items are not updating. The data I'm sending looks like this for the SalesReceiptLineMod call:

{
  "TxnID": "A-1606904011",
  "EditSequence": "1606911025",
  "CustomerRef ListID": "80000013-2223223",
  "RefNumber": "16",
  "TxnDate": "2007-11-16",
  "": "Some Name",
  "CustomerRef FullName": "Some Name",
  "BillAddress Addr1": "PO Box",
  "BillAddress Addr2": "",
  "BillAddress Addr3": "",
  "BillAddress Addr4": "",
  "BillAddress Addr5": null,
  "BillAddress City": "City",
  "BillAddress State": "OR",
  "BillAddress Province": "",
  "BillAddress PostalCode": "89899",
  "BillAddress Country": "US",
  "BillAddress Note": "",
  "PaymentMethodRef FullName": "Manual",
  "SalesReceiptLineMod": "[]"
}

And the SalesReceiptLines look like this:

Item 1:

{
  "TxnLineID": -1,
  "ItemRef FullName": "My Edited Product",
  "Desc": null,
  "Quantity": 2,
  "Amount": "5000.00"
}

Item 2:

{
  "TxnLineID": -1,
  "ItemRef FullName": "My Edited Shipping rate",
  "Quantity": 10,
  "Amount": "30.00"
}

It appears that this is the only thing that is being included in the XML when it is sent to Quickbooks:

{ "TxnID": "A-1606904011", "EditSequence": "1606913062", "CustomerRef ListID": "80000013-1606898215", "CustomerRef FullName": "Sharon Holt-DeLapp", "TxnDate": "2007-11-16", "RefNumber": "16", "BillAddress Addr1": "PO Box 582", "BillAddress Addr2": "", "BillAddress Addr3": "", "BillAddress Addr4": "", "BillAddress Addr5": null, "BillAddress City": "Hillsboro", "BillAddress State": "OR", "BillAddress PostalCode": "97123", "BillAddress Country": "US", "BillAddress Note": "", "PaymentMethodRef FullName": "Manual" }

So, the line items seem to be removed. I've tried to do what has been mentioned here by passing a -1 for the TxnLineID. However, it's still not updating the items.

Any help would be appreciated. Thanks.

shabananavas commented 3 years ago

This is the gist of how the SalesReceipt is being built:

  $invoice = new \QuickBooks_QBXML_Object_SalesReceipt();

  // Build customer details here.
  //....

  /** @var \Drupal\commerce_order\Entity\OrderItem $item */
  foreach ($order->getItems() as $item) {
    $line->setItemName('My Edited Product');
    $line->setDescription('Some description');
    $line->setItemListID('80000006-1606821864');

    $is_update ? $invoice->addListItem('SalesReceiptLineMod', $line) : $invoice->addListItem('SalesReceiptLineAdd', $line);
  }

  if ($is_update) {
    return $invoice->asQBXML(\QUICKBOOKS_MOD_SALESRECEIPT, \QuickBooks_XML::XML_DROP, '');
  }
  return $invoice->asQBXML(\QUICKBOOKS_ADD_SALESRECEIPT, \QuickBooks_XML::XML_DROP, '');