Browse Source

Merge pull request 'dev-wahyun' (#81) from dev-wahyun into staging

Reviewed-on: ibnu/generic-ospro-backend#81
pull/1/head
farhantock 7 months ago
parent
commit
349549a586
  1. 59
      app/Http/Controllers/HumanResourceController.php

59
app/Http/Controllers/HumanResourceController.php

@ -2,12 +2,8 @@
namespace App\Http\Controllers;
use App\Models\User;
use App\Models\UserToProyek;
use Illuminate\Http\Request;
use App\Models\HumanResource;
use App\Models\UserToActivity;
use App\Models\ProductTransaction;
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';
@ -16,29 +12,36 @@ class HumanResourceController extends Controller
{
public function add(Request $request)
{
$messages = [
'ktp_number.unique' => 'Nomor KTP/ID Card tidak boleh sama',
'username.unique' => 'Username tidak boleh sama',
'required' => 'Data tidak boleh kosong'
];
$this->validate($request, [
'name' => 'required',
'name' => 'required|string',
'ktp_number' => 'required|string|unique:m_users,ktp_number',
'employee_type' => 'required',
'company_id' => 'required',
'username' => 'unique:m_users,username',
]);
'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']) : '';
!$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', $request->company_id);
->where('company_id', (int) $request->company_id);
$cloneQueryTransaction = clone $transaction;
$countCreate = false;
$projectResult = HumanResource::query()
->selectRaw('count(*) as total_hr')
->where('company_id', $request->company_id)
->where('company_id', (int) $request->company_id)
->first();
if($transaction->where([['type_paket','Basic'],['amount','!=',null]])->exists()) {
if($projectResult['total_hr'] < 50) {
@ -67,6 +70,7 @@ class HumanResourceController extends Controller
public function add_user(Request $request)
{
$this->validate($request, [
'role_id' => 'required',
'name' => 'required',
@ -111,12 +115,30 @@ class HumanResourceController extends Controller
public function update(Request $request, $id)
{
$messages = [
'ktp_number.unique' => 'Nomor KTP/ID Card tidak boleh sama',
'username.unique' => 'Username tidak boleh sama',
'required' => 'Data tidak boleh kosong'
];
!$request->is_customer ? $this->validate($request,['role_id'=>'required','divisi_id'=>'required']) : '';
$request->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->password ? $this->validate($request,['password'=>'required|min:8']) : '';
$data = $request->all();
if (!$id || (int) $id < 0 || $id == "") {
return response()->json(['status' => 'failed', 'message' => 'Id is required!', 'code' => 400], 400);
}
$humanresource = HumanResource::find($id);
if(empty($humanresource)) {
return response()->json(['status' => 'failed', 'message' => 'Data Human Resource not found!', 'code' => 400], 400);
@ -149,20 +171,11 @@ class HumanResourceController extends Controller
} else {
$countCreate = true;
}
$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->password ? $this->validate($request,['password'=>'required|min:8']) : '';
$data = $request->all();
if (isset($request->password) && $request->password != "") {
$data['password'] = md5($request->password);
}
if (isset($data['username']) && HumanResource::where('username', $data['username'])->where('id', '<>', $id)->exists()) {
return response()->json(['status' => 'failed', 'message' => 'Username already exists!', 'code' => 400], 400);
}
if ($countCreate) {
$result = $humanresource->update($data);
} else {

Loading…
Cancel
Save