Skip to content

Commit

Permalink
adding payroll batch employee functions
Browse files Browse the repository at this point in the history
  • Loading branch information
WalrusSoup committed Feb 2, 2021
1 parent 0194196 commit 8f6b542
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/PrismApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,18 @@ public function getEmployees($id, string $clientId)
return $employeeService->getEmployees($id, $clientId);
}

/**
* Returns all employees in a given payroll batch (by their prism id)
*
* @param string $batchId
* @param string $clientId
*/
public function getEmployeesInPayrollBatch(string $batchId, string $clientId)
{
$payrollService = new PayrollService($this->client);
return $payrollService->getEmployeesForBatch($batchId, $clientId);
}


/**
* Returns a list of employees this user account can access
Expand Down
41 changes: 41 additions & 0 deletions src/Services/PayrollService.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,29 @@ public function getBatchListByDate(\DateTimeInterface $date, string $clientId)
}
}

public function getEmployeesForBatch(string $batchId, string $clientId)
{
if(empty($clientId)) {
throw new \InvalidArgumentException('Client ID cannot be empty');
}
if(empty($batchId)) {
throw new \InvalidArgumentException('Client ID cannot be empty');
}
try {
return $this->decodeRestResponse($this->executeGetEmployeeListByBatch($batchId, $clientId))['employeeIdList']['employeeId'];
} catch (ClientException $exception) {
$response = $exception->getResponse();
$status = $response->getStatusCode();
// If none exist, just return an empty array instead of a 404 error
if($status === 404) {
return [];
}
throw new ApiException(
"Received $status: '{$response->getBody()}' when authenticating with API."
);
}
}

public function getPayrollBatch(string $batchId, string $clientId)
{
if(empty($clientId)) {
Expand Down Expand Up @@ -221,4 +244,22 @@ public function executeGetBatchListByDate(string $startDate, string $endDate, st
]
]);
}

/**
* Gets a list of employees by batch date
*
* @param string $batchId
* @param string $clientId
* @return \Psr\Http\Message\ResponseInterface
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function executeGetEmployeeListByBatch(string $batchId, string $clientId)
{
return $this->client->request('GET', 'payroll/getEmployeeForBatch', [
'query' => [
'batchId' => $batchId,
'clientId' => $clientId
]
]);
}
}

0 comments on commit 8f6b542

Please sign in to comment.