0

How do we set a division (tracking category option) using Laravel 5 wrapper for Xero's PHP API?

According to the Xero API the object that gets send should look something like this:

<Tracking>
    <TrackingCategory>
      <Name>Activity/Workstream</Name>
      <Option>Onsite consultancy</Option>
    </TrackingCategory>
</Tracking>

I tried the followings code but it didn't work.

$line[$i]->setTrackingCategory('Divisions');
$line[$i]->setTrackingOption('Cruises');

I got an error:

Call to undefined method XeroPHP/Models/Accounting/Invoice/LineItem::setTrackingCategory()

My divisions are already set in Xero as shown below.

enter image description here

Johnny
  • 386
  • 1
  • 3
  • 11

2 Answers2

2

The underlying SDK that's being used is this one: https://github.com/calcinai/xero-php

Looking at the source code for that SDK, it looks like this is the method that you should be using to put tracking details on invoice line items: https://github.com/calcinai/xero-php/blob/master/src/XeroPHP/Models/Accounting/Invoice/LineItem.php#L356:#L364

Cheers, Matt

MJMortimer
  • 865
  • 5
  • 10
0

I too had a similar issue and its down to the format of the data.

Here is my solution:

            $trackingCategory = new \XeroPHP\Models\Accounting\TrackingCategory();
            $trackingCategory->setTrackingCategoryID('9d8ad8f6-0d0f-41e0-8851-ef47e8b54ae6');
            $trackingCategory->setName('Income');
            $trackingCategory->setTrackingOptionID('dba3d4da-f9ed-4eee-8e0b-452d11fdb1fa');
            $trackingCategory->setOption('Main');


            $lineItem->addTracking($trackingCategory);

We initially make an empty model for tracking category, set the main category id and name. Once set, we need the tracking option id and the name but name of the option should be with setoption()

Once complete, add to the line item it refers to using addtracking()

Adsy2010
  • 525
  • 6
  • 23