|
|
|
@ -2,12 +2,16 @@
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers; |
|
|
|
|
|
|
|
|
|
use App\Models\User; |
|
|
|
|
use Illuminate\Support\Str; |
|
|
|
|
use App\Models\UserToProyek; |
|
|
|
|
use Illuminate\Http\Request; |
|
|
|
|
use App\Models\HumanResource; |
|
|
|
|
use App\Models\UserToActivity; |
|
|
|
|
use App\Models\UserToProyek; |
|
|
|
|
use Illuminate\Support\Facades\Artisan; |
|
|
|
|
|
|
|
|
|
const URL_EMAIL = 'https://notifapp.odm-iu.com/service-mail/notif_mail.php'; |
|
|
|
|
|
|
|
|
|
class HumanResourceController extends Controller |
|
|
|
|
{ |
|
|
|
|
public function add(Request $request) |
|
|
|
@ -35,6 +39,34 @@ class HumanResourceController extends Controller
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function add_user(Request $request) |
|
|
|
|
{ |
|
|
|
|
$this->validate($request, [ |
|
|
|
|
'role_id' => 'required', |
|
|
|
|
'name' => 'required', |
|
|
|
|
'ktp_number' => 'required|numeric|unique:m_users,ktp_number', |
|
|
|
|
'employee_type' => 'required', |
|
|
|
|
'company_id' => 'required', |
|
|
|
|
'username' => 'required', |
|
|
|
|
'email' => 'required' |
|
|
|
|
]); |
|
|
|
|
|
|
|
|
|
$data = $request->all(); |
|
|
|
|
|
|
|
|
|
if (isset($request->password) && $request->password != "") { |
|
|
|
|
$data['password'] = md5($request->password); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$result = HumanResource::create($data); |
|
|
|
|
|
|
|
|
|
if ($result) { |
|
|
|
|
$this->sendEmail($request->email, $data['password']); |
|
|
|
|
return response()->json(['status' => 'success', 'message' => 'Human Resource Pool successfull created', 'code' => 200]); |
|
|
|
|
} else { |
|
|
|
|
return response()->json(['status' => 'failed', 'message' => 'Human Resource Pool failed created', 'code' => 400]); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function edit($id) |
|
|
|
|
{ |
|
|
|
|
if (!$id || (int) $id < 0 || $id == "") { |
|
|
|
@ -197,4 +229,64 @@ class HumanResourceController extends Controller
|
|
|
|
|
{ |
|
|
|
|
Artisan::call('sync:integration-human-resources'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function sendEmail($email, $hashPassword) |
|
|
|
|
{ |
|
|
|
|
$hashed = $hashPassword; |
|
|
|
|
$user = User::select('email', 'name')->where('email', $email)->first(); |
|
|
|
|
|
|
|
|
|
if (!$user) { |
|
|
|
|
return response()->json(['status' => 'error', 'message' => 'e-mail not found '], 400); |
|
|
|
|
} else { |
|
|
|
|
$this->reqHttpCurl($email, $hashed, $user->name); |
|
|
|
|
// if (User::where('email', $email)->update(['password'=> md5($hashed)])) |
|
|
|
|
// return response()->json(['status' => 'success', 'code'=>200, 'message' => 'Password already sent to mail'], 200); |
|
|
|
|
|
|
|
|
|
return response()->json(['status' => 'error', 'code'=>400, 'message' => 'e-mail not found '], 400); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private function reqHttpCurl($email, $password, $username) |
|
|
|
|
{ |
|
|
|
|
$postData = [ |
|
|
|
|
"to" => $email, |
|
|
|
|
"password"=> $password, |
|
|
|
|
"name" => $username, |
|
|
|
|
"from" => "app.integrasia@integrasiautama.com", |
|
|
|
|
"alias_from" => "ADW", |
|
|
|
|
"subject" => "Informasi Akun", |
|
|
|
|
"body" => "informasi-akun-adw" |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
$curl = curl_init(); |
|
|
|
|
|
|
|
|
|
curl_setopt_array($curl, array( |
|
|
|
|
CURLOPT_URL => URL_EMAIL, |
|
|
|
|
CURLOPT_RETURNTRANSFER => true, |
|
|
|
|
CURLOPT_ENCODING => "", |
|
|
|
|
CURLOPT_MAXREDIRS => 10, |
|
|
|
|
CURLOPT_TIMEOUT => 30000, |
|
|
|
|
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
|
|
|
|
CURLOPT_CUSTOMREQUEST => "POST", |
|
|
|
|
CURLOPT_POSTFIELDS => json_encode($postData), |
|
|
|
|
CURLOPT_HTTPHEADER => array( |
|
|
|
|
// Set here requred headers |
|
|
|
|
"accept: */*", |
|
|
|
|
"accept-language: en-US,en;q=0.8", |
|
|
|
|
"content-type: application/json", |
|
|
|
|
), |
|
|
|
|
)); |
|
|
|
|
|
|
|
|
|
$response = curl_exec($curl); |
|
|
|
|
$err = curl_error($curl); |
|
|
|
|
|
|
|
|
|
curl_close($curl); |
|
|
|
|
|
|
|
|
|
if ($err) { |
|
|
|
|
echo "cURL Error #:" . $err; |
|
|
|
|
} else { |
|
|
|
|
print_r(json_decode($response)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|