You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
1.7 KiB
77 lines
1.7 KiB
<?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)); |
|
} |
|
} |
|
}
|
|
|