calcinai / xero-php

A php library for the Xero API, with a cleaner OAuth interface and ORM-like abstraction.
MIT License
357 stars 256 forks source link

How to retrieve LEAVES for employee? #896

Open pdolinaj opened 11 months ago

pdolinaj commented 11 months ago

I am retrieving list of all employees:

$data = $xero->load(\XeroPHP\Models\Accounting\Employee::class)->execute();

How can I retrieve all leaves for this employee?

vendor/calcinai/xero-php/src/XeroPHP/Models/PayrollUK/Employee/Leave.php

Is there a way to retrieve more data about employee, e.g. email address? I can only access the user ID + First Name + Last Name.

calcinai commented 11 months ago

Hi @pdolinaj, it looks like this might need to be added to the model. Have a look at the Employee/Employment model as a guide (it uses the same api structure) and feel free to make a PR.

Sing out if you have any issues.

pdolinaj commented 11 months ago

Thanks, I'll have a look at it.

On another note, I was trying to create a Leave for employee but I'm facing 2 issues:

           $xero = new \XeroPHP\Application($access_token, $tenant_id);
            $employee_id = 'e752b13c-a157-4bc1-92aa-493c588a5365';
            $leave = new \XeroPHP\Models\PayrollUK\Employee\Leave($xero);
            $leave->setStartDate(new \DateTime('2023-07-01'));
            $leave->setEndDate(new \DateTime('2023-07-07'));
            $leave->setDescription('Holiday Test');
            $leave->save();
  1. It complains that it's missing the LeaveTypeId

XeroPHP\Remote\Exception XeroPHP\Models\PayrollUK\Employee\Leave::$LeaveTypeID is mandatory and is either missing or empty.

  1. There's no way to set the EmployeeId when creating the leave.

Any ideas please?

Healyhatman commented 2 months ago

This one would need an update to make it work I reckon since you actually need to send to a different URL, and I'm not sure how the codebase handles this.

POST https://api.xero.com/payroll.xro/2.0/employees/35cdd697-c9fc-4931-b579-a18cb8b6fe14/leave

So it might need a change to getAPIStem() to add the employee ID to the URL if one exists?