I'm successfully creating invoices using the Xero API using slightly modified code from: https://xeroapi.github.io/xero-php-oauth2/docs/v2/accounting/index.html#api-Accounting-createInvoices
The issue is the created invoice is missing the Account Code which is defined as:
$lineItem1->setAccountCode('200');
The complete code is:
$lineItemTracking = new XeroAPI\XeroPHP\Models\Accounting\LineItemTracking;
$lineItemTracking->setTrackingCategoryID($trackingCategoryID);
$lineItemTracking->setOption($projectNo);
$lineItemTrackings = [];
array_push($lineItemTrackings, $lineItemTracking);
// For CIS we create 2 line items for Materials Account Code: 200 and Labour Account Code: 210
$lineItem1 = new XeroAPI\XeroPHP\Models\Accounting\LineItem;
$lineItem1->setDescription('CIS Labour');
$lineItem1->setQuantity(1);
$lineItem1->setUnitAmount(0);
$lineItem1->setAccountCode('210');
$lineItem1->setTracking($lineItemTrackings);
$lineItem2 = new XeroAPI\XeroPHP\Models\Accounting\LineItem;
$lineItem2->setDescription('Materials');
$lineItem2->setQuantity(1);
$lineItem2->setUnitAmount(0);
$lineItem2->setAccountCode('200');
$lineItem2->setTracking($lineItemTrackings);
$lineItems = [];
array_push($lineItems, $lineItem1, $lineItem2 );
$invoice = new XeroAPI\XeroPHP\Models\Accounting\Invoice;
$invoice->setType(XeroAPI\XeroPHP\Models\Accounting\Invoice::TYPE_ACCREC);
$invoice->setContact($contact);
$invoice->setLineItems($lineItems);
$invoice->setReference($projectNo);
$invoice->setStatus(XeroAPI\XeroPHP\Models\Accounting\Invoice::STATUS_DRAFT);
$invoices = new XeroAPI\XeroPHP\Models\Accounting\Invoices;
$arr_invoices = [];
array_push($arr_invoices, $invoice);
$invoices->setInvoices($arr_invoices);
The invoice is created correctly with both line items, but the Account field is empty when I'm expecting to see 210 and 200.
Can you suggest anything I'm missing?
What amounts are you sending as the line item? In Xero, line items that are 0.00 will have the account codes removed as this is the behaviour for approved invoices in the front end of Xero.