|
|
|
<?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 = null;
|
|
|
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|