XeroAPI / xero-php-oauth2

Xero PHP SDK for oAuth 2 generated from Xero API OpenAPI Spec 3.0
MIT License
92 stars 66 forks source link

setLineItems missing #253

Closed irricheck closed 2 years ago

irricheck commented 3 years ago

When I create a new invoice, I get an error that setLineItems is not valid, yet all samples I can find online says its the way to add the line items to an invoice before creating it. Must be missing something

here is my code:


$jobdescription = 'test line item 1';
$quantity = 5;
$rateperhour = 150.10;
$accountcode = '1120';

$contact = new \XeroPHP\Models\Accounting\Contact;
$contact->setContactId($contactid);

$lineitem = new \XeroPHP\Models\Accounting\LineItem;
$lineitem->setDescription($jobdescription)
    ->setQuantity($quantity)
    ->setUnitAmount(number_format($rateperhour, 2))
    ->setAccountCode($accountcode);

$arr_lineitems=[]; 

array_push($arr_lineitems, $lineitem);

$invoice = new \XeroPHP\Models\Accounting\Invoice($xero);

$invoice->setContact($contact)  ;   
$invoice->setLineItems($lineitem);   //this fails with function is not defined. I can also not find this function in any of the code in the src folder
$invoice->save(); 
wobinb commented 2 years ago

The LineItems should be an array, and you are creating the array here: $arr_lineitems=[]; array_push($arr_lineitems, $lineitem);

However you are then only passing a single item in here: $invoice->setLineItems($lineitem);

Does it work any better if you change it to: $invoice->setLineItems($arr_lineitems); ?

RettBehrens commented 2 years ago

Hey @irricheck We've tested this locally and cannot replicate your function not defined issue. Additionally, confirmed the method is available on the Invoice model.

    /**
     * Sets line_items
     *
     * @param \XeroAPI\XeroPHP\Models\Accounting\LineItem[]|null $line_items See LineItems
     *
     * @return $this
     */
    public function setLineItems($line_items)
    {

        $this->container['line_items'] = $line_items;

        return $this;
    }

Please reopen the issue if your still experiencing the error