|
|
@ -41,7 +41,7 @@ class HumanResourceController extends Controller |
|
|
|
->where('company_id', $request->company_id) |
|
|
|
->where('company_id', $request->company_id) |
|
|
|
->first(); |
|
|
|
->first(); |
|
|
|
if($transaction->where([['type_paket','Basic'],['amount','!=',null]])->exists()) { |
|
|
|
if($transaction->where([['type_paket','Basic'],['amount','!=',null]])->exists()) { |
|
|
|
if($projectResult['total_hr'] < 10) { |
|
|
|
if($projectResult['total_hr'] < 50) { |
|
|
|
$countCreate = true; |
|
|
|
$countCreate = true; |
|
|
|
} |
|
|
|
} |
|
|
|
} elseif ($cloneQueryTransaction->where([['type_paket','Free'],['amount',0]])->exists()) { |
|
|
|
} elseif ($cloneQueryTransaction->where([['type_paket','Free'],['amount',0]])->exists()) { |
|
|
@ -74,7 +74,7 @@ class HumanResourceController extends Controller |
|
|
|
'employee_type' => 'required', |
|
|
|
'employee_type' => 'required', |
|
|
|
'company_id' => 'required', |
|
|
|
'company_id' => 'required', |
|
|
|
'username' => 'required', |
|
|
|
'username' => 'required', |
|
|
|
'email' => 'required' |
|
|
|
'email' => 'required|unique:m_users,email|email' |
|
|
|
]); |
|
|
|
]); |
|
|
|
|
|
|
|
|
|
|
|
$data = $request->all(); |
|
|
|
$data = $request->all(); |
|
|
@ -113,10 +113,38 @@ class HumanResourceController extends Controller |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
if (!$id || (int) $id < 0 || $id == "") { |
|
|
|
if (!$id || (int) $id < 0 || $id == "") { |
|
|
|
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); |
|
|
|
return response()->json(['status' => 'failed', 'message' => 'Id is required!', 'code' => 400], 400); |
|
|
|
} |
|
|
|
} |
|
|
|
$humanresource = HumanResource::find($id); |
|
|
|
$humanresource = HumanResource::find($id); |
|
|
|
|
|
|
|
if(empty($humanresource)) { |
|
|
|
|
|
|
|
return response()->json(['status' => 'failed', 'message' => 'Data Human Resource not found!', 'code' => 400], 400); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
$transaction = ProductTransaction::query() |
|
|
|
|
|
|
|
->where('company_id', $request->company_id); |
|
|
|
|
|
|
|
$cloneQueryTransaction = clone $transaction; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if($request->company_id && isset($request->password) && isset($request->username)) : |
|
|
|
|
|
|
|
$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; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
endif; |
|
|
|
$request->ktp_number !== $humanresource['ktp_number'] ? $this->validate($request,['ktp_number'=>'unique:m_users,ktp_number|string']) : ''; |
|
|
|
$request->ktp_number !== $humanresource['ktp_number'] ? $this->validate($request,['ktp_number'=>'unique:m_users,ktp_number|string']) : ''; |
|
|
|
$request->email !== $humanresource['email'] ? $this->validate($request,['email'=>'unique:m_users,email|email']) : ''; |
|
|
|
$request->email !== $humanresource['email'] ? $this->validate($request,['email'=>'unique:m_users,email|email']) : ''; |
|
|
|
$request->password ? $this->validate($request,['password'=>'required|min:8']) : ''; |
|
|
|
$request->password ? $this->validate($request,['password'=>'required|min:8']) : ''; |
|
|
@ -131,11 +159,10 @@ class HumanResourceController extends Controller |
|
|
|
return response()->json(['status' => 'failed', 'message' => 'Username already exists!', 'code' => 400], 400); |
|
|
|
return response()->json(['status' => 'failed', 'message' => 'Username already exists!', 'code' => 400], 400); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ($humanresource) { |
|
|
|
if ($countCreate) { |
|
|
|
$result = $humanresource->update($data); |
|
|
|
$result = $humanresource->update($data); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
return response()->json(['status' => 'failed', 'message' => 'data Human Resource Pool not found!', 'code' => 400], 400); |
|
|
|
return response()->json(['status' => 'failed', 'message' => 'Limited to create human resource!', 'code' => 500], 500); |
|
|
|
die(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ($result) { |
|
|
|
if ($result) { |
|
|
@ -153,7 +180,6 @@ class HumanResourceController extends Controller |
|
|
|
$delete = $data->delete(); |
|
|
|
$delete = $data->delete(); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
return response()->json(['status' => 'failed', 'message' => 'data Human Resource Pool not found!', 'code' => 400], 400); |
|
|
|
return response()->json(['status' => 'failed', 'message' => 'data Human Resource Pool not found!', 'code' => 400], 400); |
|
|
|
die(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|