From 8f6b5421c9f10d6c61e6a74ab0c56e6dd9339ae5 Mon Sep 17 00:00:00 2001 From: JL Date: Tue, 2 Feb 2021 15:45:11 -0800 Subject: [PATCH] adding payroll batch employee functions --- src/PrismApi.php | 12 ++++++++++ src/Services/PayrollService.php | 41 +++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/src/PrismApi.php b/src/PrismApi.php index 88bce2f..e0c61b4 100644 --- a/src/PrismApi.php +++ b/src/PrismApi.php @@ -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 diff --git a/src/Services/PayrollService.php b/src/Services/PayrollService.php index 90d3d06..7b276bb 100644 --- a/src/Services/PayrollService.php +++ b/src/Services/PayrollService.php @@ -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)) { @@ -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 + ] + ]); + } } \ No newline at end of file