Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to PayrollUK model #886

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
63 changes: 63 additions & 0 deletions src/XeroPHP/Models/PayrollUK/Employee.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace XeroPHP\Models\PayrollUK;

use XeroPHP\Exception;
use XeroPHP\Models\PayrollUK\Employee\Address;
use XeroPHP\Models\PayrollUK\Employee\Employment;
use XeroPHP\Remote;
Expand Down Expand Up @@ -370,4 +371,66 @@ public function getIsOffPayrollWorker()
{
return $this->_data[ 'isOffPayrollWorker' ];
}

/**
* @return Employee\Leave[]
*/
public function getLeaves()
{
/**
* @var \XeroPHP\Remote\Model
*/
if ($this->hasGUID() === false) {
throw new Exception(
'Employee Leaves are only available to objects that exist remotely.'
);
}

$uri = sprintf('%s/%s/leave', $this->getResourceURI(), $this->getGUID());
$api = $this->getAPIStem();

$url = new Remote\URL($this->_application, $uri, $api);
$request = new Remote\Request($this->_application, $url, Remote\Request::METHOD_GET);
$request->send();

$leavePeriods = [];
foreach ($request->getResponse()->getElements() as $element) {
$leave = new Employee\Leave($this->_application);
$leave->fromStringArray($element);
$leavePeriods[] = $leave;
}

return $leavePeriods;
}

/**
* @return Employee\StatutoryLeave[]
*/
public function getStatutoryLeavesSummary()
{
/**
* @var \XeroPHP\Remote\Model
*/
if ($this->hasGUID() === false) {
throw new Exception(
'Employee Leaves are only available to objects that exist remotely.'
);
}

$uri = sprintf('StatutoryLeaves/Summary/%s', $this->getGUID());
$api = $this->getAPIStem();

$url = new Remote\URL($this->_application, $uri, $api);
$request = new Remote\Request($this->_application, $url, Remote\Request::METHOD_GET);
$request->send();

$leavePeriods = [];
foreach ($request->getResponse()->getElements() as $element) {
$leave = new Employee\StatutoryLeave($this->_application);
$leave->fromStringArray($element);
$leavePeriods[] = $leave;
}

return $leavePeriods;
}
}
59 changes: 31 additions & 28 deletions src/XeroPHP/Models/PayrollUK/Employee/Leave.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@

use XeroPHP\Models\PayrollUK\Employee\Leave\Period;
use XeroPHP\Remote;
use XeroPHP\Traits\TitleCaseKeysBeforeSave;

class Leave extends Remote\Model
{
use TitleCaseKeysBeforeSave;

/**
* Xero identifier.
*
Expand Down Expand Up @@ -53,7 +56,7 @@ class Leave extends Remote\Model
*/
public static function getResourceURI()
{
return 'Leave';
return 'Employees/{EmployeeID}/Leave';
}

/**
Expand Down Expand Up @@ -112,12 +115,12 @@ public static function getSupportedMethods()
public static function getProperties()
{
return [
'LeaveID' => [false, self::PROPERTY_TYPE_STRING, null, false, false],
'LeaveTypeID' => [true, self::PROPERTY_TYPE_STRING, null, false, false],
'Description' => [false, self::PROPERTY_TYPE_STRING, null, false, false],
'StartDate' => [true, self::PROPERTY_TYPE_DATE, '\\DateTimeInterface', false, false],
'EndDate' => [true, self::PROPERTY_TYPE_DATE, '\\DateTimeInterface', false, false],
'Periods' => [false, self::PROPERTY_TYPE_OBJECT, 'PayrollUK\\Leave\\Period', true, false],
'leaveID' => [false, self::PROPERTY_TYPE_STRING, null, false, false],
'leaveTypeID' => [true, self::PROPERTY_TYPE_STRING, null, false, false],
'description' => [false, self::PROPERTY_TYPE_STRING, null, false, false],
'startDate' => [true, self::PROPERTY_TYPE_DATE, '\\DateTimeInterface', false, false],
'endDate' => [true, self::PROPERTY_TYPE_DATE, '\\DateTimeInterface', false, false],
'periods' => [false, self::PROPERTY_TYPE_OBJECT, 'PayrollUK\\Employee\\Leave\\Period', true, false],
];
}

Expand All @@ -131,7 +134,7 @@ public static function isPageable()
*/
public function getLeaveID()
{
return $this->_data['LeaveID'];
return $this->_data['leaveID'];
}

/**
Expand All @@ -141,8 +144,8 @@ public function getLeaveID()
*/
public function setLeaveID($value)
{
$this->propertyUpdated('LeaveID', $value);
$this->_data['LeaveID'] = $value;
$this->propertyUpdated('leaveID', $value);
$this->_data['leaveID'] = $value;

return $this;
}
Expand All @@ -152,7 +155,7 @@ public function setLeaveID($value)
*/
public function getLeaveTypeID()
{
return $this->_data['LeaveTypeID'];
return $this->_data['leaveTypeID'];
}

/**
Expand All @@ -162,8 +165,8 @@ public function getLeaveTypeID()
*/
public function setLeaveTypeID($value)
{
$this->propertyUpdated('LeaveTypeID', $value);
$this->_data['LeaveTypeID'] = $value;
$this->propertyUpdated('leaveTypeID', $value);
$this->_data['leaveTypeID'] = $value;

return $this;
}
Expand All @@ -173,7 +176,7 @@ public function setLeaveTypeID($value)
*/
public function getStartDate()
{
return $this->_data['StartDate'];
return $this->_data['startDate'];
}

/**
Expand All @@ -183,8 +186,8 @@ public function getStartDate()
*/
public function setStartDate(\DateTimeInterface $value)
{
$this->propertyUpdated('StartDate', $value);
$this->_data['StartDate'] = $value;
$this->propertyUpdated('startDate', $value);
$this->_data['startDate'] = $value;

return $this;
}
Expand All @@ -194,7 +197,7 @@ public function setStartDate(\DateTimeInterface $value)
*/
public function getEndDate()
{
return $this->_data['EndDate'];
return $this->_data['endDate'];
}

/**
Expand All @@ -204,8 +207,8 @@ public function getEndDate()
*/
public function setEndDate(\DateTimeInterface $value)
{
$this->propertyUpdated('EndDate', $value);
$this->_data['EndDate'] = $value;
$this->propertyUpdated('endDate', $value);
$this->_data['endDate'] = $value;

return $this;
}
Expand All @@ -215,7 +218,7 @@ public function setEndDate(\DateTimeInterface $value)
*/
public function getDescription()
{
return $this->_data['Description'];
return $this->_data['description'];
}

/**
Expand All @@ -225,8 +228,8 @@ public function getDescription()
*/
public function setDescription($value)
{
$this->propertyUpdated('Description', $value);
$this->_data['Description'] = $value;
$this->propertyUpdated('description', $value);
$this->_data['description'] = $value;

return $this;
}
Expand All @@ -236,7 +239,7 @@ public function setDescription($value)
*/
public function getPeriods()
{
return $this->_data['Periods'];
return $this->_data['periods'];
}

/**
Expand All @@ -246,12 +249,12 @@ public function getPeriods()
*/
public function addPeriod(Period $value)
{
$this->propertyUpdated('Periods', $value);
if (! isset($this->_data['Periods'])) {
$this->_data['Periods'] = new Remote\Collection();
$this->propertyUpdated('periods', $value);
if (! isset($this->_data['periods'])) {
$this->_data['periods'] = new Remote\Collection();
}
$this->_data['Periods'][] = $value;
$this->_data['periods'][] = $value;

return $this;
}
}
}
Loading