Browse Source

implement human resource integration

pull/3/head
Muhammad Sulaiman Yusuf 2 years ago
parent
commit
c831a1a619
  1. 77
      app/Console/Commands/syncHumanResourceIntegration.php
  2. 5
      app/Console/Kernel.php

77
app/Console/Commands/syncHumanResourceIntegration.php

@ -0,0 +1,77 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Helpers\MasterFunctionsHelper;
use App\Models\HumanResource;
class syncHumanResourceIntegration extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'sync:integration-human-resources';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Sync data HR from ADW';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$url = config('api.adw').'/employees?page=1';
echo "Requesting to " . $url;
$response = MasterFunctionsHelper::curlReq($url);
if(!$response)
return;
if($response->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));
}
}
}

5
app/Console/Kernel.php

@ -13,6 +13,7 @@ class Kernel extends ConsoleKernel
* @var array * @var array
*/ */
protected $commands = [ protected $commands = [
Commands\syncHumanResourceIntegration::class
]; ];
/** /**
@ -23,5 +24,7 @@ class Kernel extends ConsoleKernel
*/ */
protected function schedule(Schedule $schedule) protected function schedule(Schedule $schedule)
{ {
} $schedule->command('sync:integration-human-resources')->twiceDaily();
}
} }

Loading…
Cancel
Save