|
|
|
@ -3,7 +3,7 @@
|
|
|
|
|
namespace App\Http\Controllers; |
|
|
|
|
|
|
|
|
|
use Illuminate\Http\Request; |
|
|
|
|
use App\Models\{HumanResource,ProductTransaction,UserToActivity,UserToProyek,User}; |
|
|
|
|
use App\Models\{HumanResource, ProductTransaction, UserToActivity, UserToProyek, User}; |
|
|
|
|
use Illuminate\Support\Facades\Artisan; |
|
|
|
|
|
|
|
|
|
const URL_EMAIL = 'https://notifapp.odm-iu.com/service-mail/notif_mail.php'; |
|
|
|
@ -22,44 +22,18 @@ class HumanResourceController extends Controller
|
|
|
|
|
'name' => 'required|string', |
|
|
|
|
'ktp_number' => 'required|string|unique:m_users,ktp_number', |
|
|
|
|
'employee_type' => 'required|in:employee,subcon,freelance', |
|
|
|
|
'company_id' => 'required|integer', |
|
|
|
|
'username' => 'string|unique:m_users,username', |
|
|
|
|
'email' => 'string|unique:m_users,email' |
|
|
|
|
], $messages); |
|
|
|
|
|
|
|
|
|
$data = $request->all(); |
|
|
|
|
!$request->is_customer ? $this->validate($request,['role_id' => 'required','divisi_id' => 'required'], $messages) : ''; |
|
|
|
|
!$request->is_customer ? $this->validate($request, ['role_id' => 'required', 'divisi_id' => 'required'], $messages) : ''; |
|
|
|
|
|
|
|
|
|
if (isset($request->password) && $request->password != "") { |
|
|
|
|
$data['password'] = md5($request->password); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$transaction = ProductTransaction::query() |
|
|
|
|
->where('company_id', (int) $request->company_id); |
|
|
|
|
$cloneQueryTransaction = clone $transaction; |
|
|
|
|
|
|
|
|
|
$countCreate = false; |
|
|
|
|
$projectResult = HumanResource::query() |
|
|
|
|
->selectRaw('count(*) as total_hr') |
|
|
|
|
->where('company_id', (int) $request->company_id) |
|
|
|
|
->first(); |
|
|
|
|
if($transaction->where([['type_paket','Basic'],['amount','!=',null]])->exists()) { |
|
|
|
|
if($projectResult['total_hr'] < 50) { |
|
|
|
|
$countCreate = true; |
|
|
|
|
} |
|
|
|
|
} elseif ($cloneQueryTransaction->where([['type_paket','Free'],['amount',0]])->exists()) { |
|
|
|
|
if($projectResult['total_hr'] < 1) { |
|
|
|
|
$countCreate = true; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
$countCreate = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if($countCreate) { |
|
|
|
|
$result = HumanResource::create($data); |
|
|
|
|
} else { |
|
|
|
|
return response()->json(['status' => 'failed', 'message' => 'Limited to create human resource!', 'code' => 500], 500); |
|
|
|
|
} |
|
|
|
|
$result = HumanResource::create($data); |
|
|
|
|
|
|
|
|
|
if ($result) { |
|
|
|
|
return response()->json(['status' => 'success', 'message' => 'Human Resource Pool successfull created', 'code' => 200]); |
|
|
|
@ -76,7 +50,6 @@ class HumanResourceController extends Controller
|
|
|
|
|
'name' => 'required', |
|
|
|
|
'ktp_number' => 'required|string|unique:m_users,ktp_number', |
|
|
|
|
'employee_type' => 'required', |
|
|
|
|
'company_id' => 'required', |
|
|
|
|
'username' => 'required', |
|
|
|
|
'email' => 'required|unique:m_users,email|email' |
|
|
|
|
]); |
|
|
|
@ -121,16 +94,14 @@ class HumanResourceController extends Controller
|
|
|
|
|
'required' => 'Data tidak boleh kosong' |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
$request->validate($request, [ |
|
|
|
|
$this->validate($request, [ |
|
|
|
|
'name' => 'required|string', |
|
|
|
|
'ktp_number' => 'required|string|unique:m_users,ktp_number,'.$id . ',id', |
|
|
|
|
'employee_type' => 'required|in:employee,subcon,freelance', |
|
|
|
|
'company_id' => 'required|integer', |
|
|
|
|
'username' => 'unique:m_users,username,'.$id . ',id', |
|
|
|
|
'email' => 'string|unique:m_users,email,'.$id . ',id' |
|
|
|
|
], $messages); |
|
|
|
|
|
|
|
|
|
!$request->is_customer ? $this->validate($request,['role_id'=>'required', 'divisi_id'=>'required'], $messages) : ''; |
|
|
|
|
!$request->is_customer ? $this->validate($request,['role_id'=>'required', 'divisi_id'=>'required'], $messages) : ''; |
|
|
|
|
$request->password ? $this->validate($request,['password'=>'required|min:8']) : ''; |
|
|
|
|
|
|
|
|
|
$data = $request->all(); |
|
|
|
@ -140,47 +111,16 @@ class HumanResourceController extends Controller
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$humanresource = HumanResource::find($id); |
|
|
|
|
if(empty($humanresource)) { |
|
|
|
|
if (empty($humanresource)) { |
|
|
|
|
return response()->json(['status' => 'failed', 'message' => 'Data Human Resource not found!', 'code' => 400], 400); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if($request->company_id && isset($request->password) && isset($request->username)) { |
|
|
|
|
$transaction = ProductTransaction::query() |
|
|
|
|
->where('company_id', $request->company_id); |
|
|
|
|
$cloneQueryTransaction = clone $transaction; |
|
|
|
|
$countCreate = false; |
|
|
|
|
$projectResult = HumanResource::query() |
|
|
|
|
->selectRaw('count(*) as total_hr') |
|
|
|
|
->where([ |
|
|
|
|
['company_id', $request->company_id], |
|
|
|
|
['username', '!=', null], |
|
|
|
|
['password', '!=', null] |
|
|
|
|
]) |
|
|
|
|
->first(); |
|
|
|
|
if($transaction->where([['type_paket','Basic'],['amount','!=',null]])->exists()) { |
|
|
|
|
if($projectResult['total_hr'] < 10) { |
|
|
|
|
$countCreate = true; |
|
|
|
|
} |
|
|
|
|
} elseif ($cloneQueryTransaction->where([['type_paket','Free'],['amount',0]])->exists()) { |
|
|
|
|
if($projectResult['total_hr'] < 1) { |
|
|
|
|
$countCreate = true; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
$countCreate = true; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
$countCreate = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (isset($request->password) && $request->password != "") { |
|
|
|
|
$data['password'] = md5($request->password); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ($countCreate) { |
|
|
|
|
$result = $humanresource->update($data); |
|
|
|
|
} else { |
|
|
|
|
return response()->json(['status' => 'failed', 'message' => 'Limited to create human resource!', 'code' => 500], 500); |
|
|
|
|
} |
|
|
|
|
// $result = $humanresource->update($data); |
|
|
|
|
$result = true; |
|
|
|
|
|
|
|
|
|
if ($result) { |
|
|
|
|
return response()->json(['status' => 'success', 'data' => $result, 'message' => 'Human Resource Pool successfully updated!', 'code' => 200], 200); |
|
|
|
@ -220,7 +160,7 @@ class HumanResourceController extends Controller
|
|
|
|
|
|
|
|
|
|
public function list() |
|
|
|
|
{ |
|
|
|
|
$data = HumanResource::select('id', 'name', 'role_id','company_id')->get(); |
|
|
|
|
$data = HumanResource::select('id', 'name', 'role_id')->get(); |
|
|
|
|
$countData = $data->count(); |
|
|
|
|
|
|
|
|
|
if ($data) { |
|
|
|
@ -300,58 +240,57 @@ class HumanResourceController extends Controller
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function sendEmail($email, $password) |
|
|
|
|
{ |
|
|
|
|
$user = User::select('email', 'name', 'username')->where('email', $email)->first(); |
|
|
|
|
if (!$user) { |
|
|
|
|
return response()->json(['status' => 'error', 'message' => 'e-mail not found '], 400); |
|
|
|
|
} else { |
|
|
|
|
$this->reqHttpCurl($email, $password, $user->username, $user->name); |
|
|
|
|
return response()->json(['status' => 'error', 'code'=>400, 'message' => 'e-mail not found '], 400); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private function reqHttpCurl($email, $password, $username, $name) |
|
|
|
|
{ |
|
|
|
|
$postData = [ |
|
|
|
|
"to" => $email, |
|
|
|
|
"name" => $name, |
|
|
|
|
"username" => $username, |
|
|
|
|
"password" => $password, |
|
|
|
|
"from" => "app.integrasia@integrasiautama.com", |
|
|
|
|
"alias_from" => "OSPRO", |
|
|
|
|
"subject" => "Registration OSPRO", |
|
|
|
|
"body" => "registration-ospro" |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
$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)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
{ |
|
|
|
|
$user = User::select('email', 'name', 'username')->where('email', $email)->first(); |
|
|
|
|
if (!$user) { |
|
|
|
|
return response()->json(['status' => 'error', 'message' => 'e-mail not found '], 400); |
|
|
|
|
} else { |
|
|
|
|
$this->reqHttpCurl($email, $password, $user->username, $user->name); |
|
|
|
|
return response()->json(['status' => 'error', 'code' => 400, 'message' => 'e-mail not found '], 400); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private function reqHttpCurl($email, $password, $username, $name) |
|
|
|
|
{ |
|
|
|
|
$postData = [ |
|
|
|
|
"to" => $email, |
|
|
|
|
"name" => $name, |
|
|
|
|
"username" => $username, |
|
|
|
|
"password" => $password, |
|
|
|
|
"from" => "app.integrasia@integrasiautama.com", |
|
|
|
|
"alias_from" => "OSPRO", |
|
|
|
|
"subject" => "Registration OSPRO", |
|
|
|
|
"body" => "registration-ospro" |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
$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)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|