From c831a1a6193e066c537a14a2e61d4a53648a3fee Mon Sep 17 00:00:00 2001 From: Muhammad Sulaiman Yusuf Date: Fri, 11 Nov 2022 02:38:33 +0700 Subject: [PATCH] implement human resource integration --- .../Commands/syncHumanResourceIntegration.php | 77 +++++++++++++++++++ app/Console/Kernel.php | 5 +- 2 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 app/Console/Commands/syncHumanResourceIntegration.php diff --git a/app/Console/Commands/syncHumanResourceIntegration.php b/app/Console/Commands/syncHumanResourceIntegration.php new file mode 100644 index 0000000..0f3b72d --- /dev/null +++ b/app/Console/Commands/syncHumanResourceIntegration.php @@ -0,0 +1,77 @@ +message != 'success') + return; + + if(!is_int($response->total) || $response->total == 0) + return; + + $totalPage = $response->last_page; + echo "\nTotal Page = " . $totalPage; + $currentResponse = $response; + for($i = 1; $i <= $totalPage; $i++){ + echo "\nCurrent Page = " . $i; + $employeesPageData = $currentResponse->data; + foreach($employeesPageData as $employee){ + HumanResource::firstOrCreate( + ['ktp_number' => $employee->emp_id], + [ + 'name' => $employee->name, + 'employee_type' => 'employee', + 'status_resource' => 'active', + 'role_id' => 24, + 'created_by' => 'integration' + ], + ); + } + echo "\n------------------------------------------\n"; + $currentResponse = MasterFunctionsHelper::curlReq(str_replace('1', $i, $url)); + } + } +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index cdba880..a379d80 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -13,6 +13,7 @@ class Kernel extends ConsoleKernel * @var array */ protected $commands = [ + Commands\syncHumanResourceIntegration::class ]; /** @@ -23,5 +24,7 @@ class Kernel extends ConsoleKernel */ protected function schedule(Schedule $schedule) { - } + $schedule->command('sync:integration-human-resources')->twiceDaily(); + } + }