diff --git a/app/Http/Controllers/API/ActivityDokumenController.php b/app/Http/Controllers/API/ActivityDokumenController.php index 2086364..5869583 100644 --- a/app/Http/Controllers/API/ActivityDokumenController.php +++ b/app/Http/Controllers/API/ActivityDokumenController.php @@ -11,7 +11,7 @@ class ActivityDokumenController extends Controller public function dokumenByActivityId($id) { - if (empty($id) || !is_int((int)$id)) { + if (empty($id)) { return response()->json(['status' => 'failed', 'message' => 'activity id is required!', 'code' => 400], 400); } @@ -21,7 +21,7 @@ class ActivityDokumenController extends Controller public function delete($id) { - if (empty($id) || !is_int((int)$id)) { + if (empty($id)) { return response()->json(['status' => 'failed', 'message' => 'Id is required!', 'code' => 400], 400); } @@ -44,8 +44,12 @@ class ActivityDokumenController extends Controller if (!$request->hasFile('dokumen')) { return response()->json(['status' => 'failed', 'message' => 'file is required!', 'code' => 400], 400); } + $validated = $request->validate([ + 'activity_id' => 'required|integer', + 'file' => 'required', + 'description' => '' + ]); - $activity_id = $request->activity_id; $document = $request->file('dokumen'); $name = $document->getClientOriginalName(); @@ -55,13 +59,12 @@ class ActivityDokumenController extends Controller return response()->json(['status' => 'failed', 'message' => 'Upload failed!', 'code' => 500], 500); } - $data = [ - 'activity_id' => (int)$activity_id, - 'file' => $name, - 'description' => $request->description - ]; - $result = ActivityDokumen::create($data); + $result = ActivityDokumen::create([ + 'activity_id' => $validated['activity_id'], + 'file' => $name, + 'description' => $validated['description'] + ]); if (!$result) { unlink($this->pathActivityDocument . $name); @@ -86,7 +89,7 @@ class ActivityDokumenController extends Controller public function downloadDokumen($id) { - if (empty($id) || !is_int((int)$id)) { + if (empty($id)) { return response()->json(['status' => 'failed', 'message' => 'Id is required!', 'code' => 400], 400); } diff --git a/app/Http/Controllers/API/ConfigAlertController.php b/app/Http/Controllers/API/ConfigAlertController.php index 4fd9f19..c252236 100644 --- a/app/Http/Controllers/API/ConfigAlertController.php +++ b/app/Http/Controllers/API/ConfigAlertController.php @@ -4,8 +4,118 @@ namespace App\Http\Controllers\API; use App\Http\Controllers\Controller; use Illuminate\Http\Request; +use App\Models\ConfigAlert; +use Illuminate\Support\Facades\Validator; class ConfigAlertController extends Controller { - // + public function add(Request $request) + { + $validator = Validator::make($request->all(), [ + 'name' => 'required|string', + 'keterangan' => 'nullable', + 'created_by' => 'nullable|string|max:80', + 'updated_by' => 'nullable|string|max:80' + ]); + + if ($validator->fails()) { + return response()->json(['status' => 'failed', 'message' => 'add data config alert failed!', 'code' => 400], 400); + } + $validated = $validator->validated(); + + $validated['created_by'] = $this->currentName; + + $result = ConfigAlert::create($validated); + + if ($result) { + return response()->json(['status' => 'success', 'message' => 'add data config alert successfully!', 'code' => 200], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'add data config alert failed!', 'code' => 400], 400); + } + } + + public function edit($id) + { + if (empty($id)) { + return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); + } + + $result = ConfigAlert::find($id); + + if ($result) { + return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'failed get data config alert, please try again later!', 'code' => 400], 400); + } + } + + public function update(Request $request, $id) + { + if (empty($id)) { + return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); + } + $data = ConfigAlert::find($id); + + $validator = Validator::make($request->all(), [ + 'name' => 'required|string', + 'keterangan' => 'nullable', + 'created_by' => 'nullable|string|max:80', + 'updated_by' => 'nullable|string|max:80' + ]); + + if ($validator->fails()) { + return response()->json(['status' => 'failed', 'message' => 'data config alert failed updated!', 'code' => 400], 400); + } + $validated = $validator->validated(); + + if ($data) { + $result = $data->update($validated); + if ($result) { + return response()->json(['status' => 'success', 'message' => 'data config alert successfully updated!', 'code' => 200], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'data config alert failed updated!', 'code' => 400], 400); + } + } else { + return response()->json(['status' => 'failed', 'message' => 'data config alert not found!', 'code' => 400], 400); + } + } + + public function delete($id) + { + $data = ConfigAlert::find($id); + + if ($data) { + $delete = $data->delete(); + if ($delete) { + return response()->json(['status' => 'success', 'message' => 'data config alert successfully deleted!', 'code' => 200], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'data config alert failed deleted!', 'code' => 400], 400); + } + } else { + return response()->json(['status' => 'failed', 'message' => 'data config alert not found!', 'code' => 400], 400); + } + } + + public function search(Request $request) + { + $payload = $request->all(); + $dataBuilder = $this->setUpPayload($payload, 'config_alert'); + $builder = $dataBuilder['builder']; + $countBuilder = $dataBuilder['count']; + $dataGet = $builder->get(); + $totalRecord = $countBuilder->count(); + return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => $totalRecord], 200); + } + + public function list() + { + $data = ConfigAlert::all(); + $countData = $data->count(); + + if ($data) { + return response()->json(['status' => 'success', 'code' => 200, 'data' => $data, 'totalRecord' => $countData], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'failed get list config alert, please try again later!', 'code' => 400], 400); + } + } } diff --git a/app/Http/Controllers/API/ConfigAlertUserController.php b/app/Http/Controllers/API/ConfigAlertUserController.php index c4b9d03..9f88fb2 100644 --- a/app/Http/Controllers/API/ConfigAlertUserController.php +++ b/app/Http/Controllers/API/ConfigAlertUserController.php @@ -4,8 +4,103 @@ namespace App\Http\Controllers\API; use App\Http\Controllers\Controller; use Illuminate\Http\Request; +use App\Models\ConfigAlertUser; +use Illuminate\Support\Facades\Validator; class ConfigAlertUserController extends Controller { - // + public function add(Request $request) + { + $validator = Validator::make($request->all(), [ + 'user_id' => 'required|integer', + 'config_alert_id' => 'required|integer', + 'created_by' => 'nullable|string|max:80', + 'updated_by' => 'nullable|string|max:80' + ]); + + if ($validator->fails()) { + return response()->json(['status' => 'failed', 'message' => 'add data config alert user failed!', 'code' => 400], 400); + } + $validated = $validator->validated(); + + $validated['created_by'] = $this->currentName; + + $result = ConfigAlertUser::create($validated); + + if ($result) { + return response()->json(['status' => 'success', 'message' => 'add data config alert user successfully!', 'code' => 200], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'add data config alert user failed!', 'code' => 400], 400); + } + } + + public function update(Request $request, $id) + { + if (empty($id)) { + return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); + } + + $data = ConfigAlertUser::find($id); + + $validator = Validator::make($request->all(), [ + 'user_id' => 'required|integer', + 'config_alert_id' => 'required|integer', + 'created_by' => 'nullable|string|max:80', + 'updated_by' => 'nullable|string|max:80' + ]); + + if ($validator->fails()) { + return response()->json(['status' => 'failed', 'message' => 'data config alert user failed updated!', 'code' => 400], 400); + } + $validated = $validator->validated(); + + if ($data) { + $result = $data->update($validated); + if ($result) { + return response()->json(['status' => 'success', 'message' => 'data config alert user successfully updated!', 'code' => 200], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'data config alert user failed updated!', 'code' => 400], 400); + } + } else { + return response()->json(['status' => 'failed', 'message' => 'data config alert user not found!', 'code' => 400], 400); + } + } + + public function delete($id) + { + $data = ConfigAlertUser::find($id); + + if ($data) { + $delete = $data->delete(); + if ($delete) { + return response()->json(['status' => 'success', 'message' => 'data config alert user successfully deleted!', 'code' => 200], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'data config alert user failed deleted!', 'code' => 400], 400); + } + } else { + return response()->json(['status' => 'failed', 'message' => 'data config alert user not found!', 'code' => 400], 400); + } + } + + public function search(Request $request) + { + $payload = $request->all(); + $dataBuilder = $this->setUpPayload($payload, 'config_alert_to_user'); + $builder = $dataBuilder['builder']; + $countBuilder = $dataBuilder['count']; + $dataGet = $builder->get(); + $totalRecord = $countBuilder->count(); + return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => $totalRecord], 200); + } + + public function getConfigUser($id) + { + $getData = ConfigAlertUser::where('user_id', $id)->get(); + + if ($getData) { + return response()->json(['status' => 'success', 'code' => 200, 'data' => $getData], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'config alert for this user not found!', 'code' => 400], 400); + } + } } diff --git a/app/Http/Controllers/API/DashboardBoDController.php b/app/Http/Controllers/API/DashboardBoDController.php index b4cfff4..2bb963d 100644 --- a/app/Http/Controllers/API/DashboardBoDController.php +++ b/app/Http/Controllers/API/DashboardBoDController.php @@ -88,11 +88,11 @@ class DashboardBoDController extends Controller $return = []; foreach ($projects as $project) { $resp = null; - if ($project->kode_sortname != "") { - $resp = $this->getInvoiceIntegration($project->kode_sortname); + if ($project['kode_sortname'] != "") { + $resp = $this->getInvoiceIntegration($project['kode_sortname']); array_push($return, [ - 'project' => $project->nama, - 'project_code' => $project->kode_sortname, + 'project' => $project['nama'], + 'project_code' => $project['kode_sortname'], 'invoiced' => $resp->data->total_invoice_amount ?? 0, 'paid' => $resp->data->total_invoice_paid_amount ?? 0, 'response' => $resp, @@ -117,11 +117,11 @@ class DashboardBoDController extends Controller $projects = Project::where('mulai_proyek', 'LIKE', '%' . $year . '%')->get(); foreach ($projects as $project) { - $project->scurve = MasterFunctionsHelper::getSCurve($project->id); + $project['scurve'] = MasterFunctionsHelper::getSCurve($project['id']); $selisihProgress = 0; - if ($project->scurve && $project->scurve[0]) { - $planningArray = $project->scurve[0]['data']['percentagePlan']; - $actualArray = $project->scurve[0]['data']['percentageReal']; + if ($project['scurve'] && $project['scurve'][0]) { + $planningArray = $project['scurve'][0]['data']['percentagePlan']; + $actualArray = $project['scurve'][0]['data']['percentageReal']; $planningProgress = !empty($planningArray) ? $planningArray[count($planningArray) - 1] : 0; $actualProgress = !empty($actualArray) ? $actualArray[count($actualArray) - 1] : 0; } @@ -151,14 +151,14 @@ class DashboardBoDController extends Controller $scheduleData = new Collection(); $behindSchedule = $warning = $onSchedule = 0; - $projects = Project::where('mulai_proyek', 'LIKE', '%' . $year . '%')->where('divisi_id', $division->id)->get(); + $projects = Project::where('mulai_proyek', 'LIKE', '%' . $year . '%')->where('divisi_id', $division['id'])->get(); foreach ($projects as $project) { - $project->scurve = MasterFunctionsHelper::getSCurve($project->id); - if (@$project->scurve['difference'] > 0 && @$project->scurve['difference'] <= 5) + $project['scurve'] = MasterFunctionsHelper::getSCurve($project['id']); + if ($project['scurve']['difference'] > 0 && $project['scurve']['difference'] <= 5) $warning++; - elseif (@$project->scurve['difference'] > 5 && @$project->scurve['difference'] <= 100) + elseif ($project['scurve']['difference'] > 5 && $project['scurve']['difference'] <= 100) $behindSchedule++; - elseif (@$project->scurve['difference'] == 0) + elseif ($project['scurve']['difference'] == 0) $onSchedule++; } @@ -179,9 +179,21 @@ class DashboardBoDController extends Controller $year = $this->interpolateYear($year); return response()->json([ 'data' => [ - 'overrun' => Project::where([['mulai_proyek', 'LIKE', '%' . $year . '%'], ['budget_health', 'overrun']])->count(), - 'warning' => Project::where([['mulai_proyek', 'LIKE', '%' . $year . '%'], ['budget_health', 'warning']])->count(), - 'on-budget' => Project::where([['mulai_proyek', 'LIKE', '%' . $year . '%'], ['budget_health', 'on-budget']])->count(), + 'overrun' => Project::query() + ->where([ + ['mulai_proyek', 'LIKE', '%' . $year . '%'], + ['budget_health', 'overrun'] + ])->count(), + 'warning' => Project::query() + ->where([ + ['mulai_proyek', 'LIKE', '%' . $year . '%'], + ['budget_health', 'warning'] + ])->count(), + 'on-budget' => Project::query() + ->where([ + ['mulai_proyek', 'LIKE', '%' . $year . '%'], + ['budget_health', 'on-budget'] + ])->count(), ] ], 200); } @@ -193,16 +205,15 @@ class DashboardBoDController extends Controller ['divisi_id', $divisi], ['mulai_proyek', 'LIKE', '%' . $year . '%'], ['budget_health', $health] - ]) - ->count(); + ])->count(); } public function getTotalProjectBudgetHealthPerDivision($year = '%') { $year = $this->interpolateYear($year); - $divisions = Divisi::select('id', 'name') - ->with('children') + $divisions = Divisi::query() + ->select('id', 'name') ->whereNull('parent') ->get(); // to do : count in more than 1 level child @@ -231,14 +242,15 @@ class DashboardBoDController extends Controller public function getTotalProjectPerPhase($year = '%') { $year = $this->interpolateYear($year); - $projectPhases = ProjectPhase::orderBy('order')->get(); + $projectPhases = ProjectPhase::query() + ->orderBy('order') + ->get(); foreach ($projectPhases as $phase) { $phase->totalProject = Project::query() ->where([ ['phase_id', $phase->id], ['mulai_proyek', 'like', '%' . $year . '%'] - ]) - ->count(); + ])->count(); } return response()->json([ 'data' => [ @@ -252,7 +264,7 @@ class DashboardBoDController extends Controller return Project::query() ->where([ ['divisi_id', $id], - ['mulai_proyek', 'like', '%' . $year . '%'] + ['mulai_proyek', 'LIKE', '%' . $year . '%'] ]) ->count(); } @@ -261,8 +273,8 @@ class DashboardBoDController extends Controller { $year = $this->interpolateYear($year); - $divisions = Divisi::select('id', 'name') - ->with('children') + $divisions = Divisi::query() + ->select('id', 'name') ->whereNull('parent') ->get(); @@ -282,9 +294,10 @@ class DashboardBoDController extends Controller private function countTotalProjectValueInDivision($id, $year) { - return Project::selectRaw('SUM(CAST("rencana_biaya" AS DOUBLE PRECISION))') + return Project::query() + ->selectRaw('SUM(CAST("rencana_biaya" AS DOUBLE PRECISION))') ->where([ - ['mulai_proyek', 'like', '%' . $year . '%'], + ['mulai_proyek', 'LIKE', '%' . $year . '%'], ['divisi_id', $id] ]) ->pluck('sum') @@ -295,8 +308,8 @@ class DashboardBoDController extends Controller { $year = $this->interpolateYear($year); - $divisions = Divisi::select('id', 'name') - ->with('children') + $divisions = Divisi::query() + ->select('id', 'name') ->whereNull('parent') ->get(); @@ -318,28 +331,29 @@ class DashboardBoDController extends Controller public function getDetailExpenditure($year = '%') { $year = $this->interpolateYear($year); - $projects = Project::where('mulai_proyek', 'like', '%' . $year . '%') + $projects = Project::query() + ->where('mulai_proyek', 'LIKE', '%' . $year . '%') ->orderByDesc('id') ->get(); foreach ($projects as $project) { - $lastGantt = MasterFunctionsHelper::getLatestGantt($project->id); + $lastGantt = MasterFunctionsHelper::getLatestGantt($project['id']); - if ($project->kode_sortname != "") { - $resp = $this->getInvoiceIntegration($project->kode_sortname); + if (!empty($project['kode_sortname'])) { + $resp = $this->getInvoiceIntegration($project['kode_sortname']); $project->invoice = [ 'invoiced' => $resp->data->total_invoice_amount ?? 0, 'paid' => $resp->data->total_invoice_paid_amount ?? 0, ]; } - $project->pm = User::find($project->pm_id); + $project->pm = User::findOrFail($project['pm_id']); if (!isset($lastGantt['last_gantt_id'])) { $project->manPowers = 0; } else { $project->manPowers = UserToVersionGantt::where('version_gantt_id', $lastGantt['last_gantt_id'])->count(); - $project->scurve = MasterFunctionsHelper::getSCurve($project->id); + $project['scurve'] = MasterFunctionsHelper::getSCurve($project['id']); } - $project->lastGanttId = MasterFunctionsHelper::getLatestGantt($project->id); + $project->lastGanttId = MasterFunctionsHelper::getLatestGantt($project['id']); } return response()->json([ diff --git a/app/Http/Controllers/API/DivisiController.php b/app/Http/Controllers/API/DivisiController.php index 7cdb3a6..125589b 100644 --- a/app/Http/Controllers/API/DivisiController.php +++ b/app/Http/Controllers/API/DivisiController.php @@ -4,8 +4,127 @@ namespace App\Http\Controllers\API; use App\Http\Controllers\Controller; use Illuminate\Http\Request; +use App\Models\Divisi; +use Illuminate\Support\Facades\Validator; class DivisiController extends Controller { - // + + private function getAllChildren($divisi, $depth = 0, $array = []) + { + $divisi->depth = $depth; + array_push($array, $divisi); + foreach ($divisi->children as $child) { + $array = $this->getAllChildren($child, $depth + 1, $array); + } + return $array; + } + + public function add(Request $request) + { + $validator = Validator::make($request->all(), [ + 'name' => 'required|string|max:200', + 'description' => 'nullable', + 'parent' => 'nullable|integer', + 'created_by' => 'nullable|string|max:80', + 'updated_by' => 'nullable|string|max:80' + ]); + + if ($validator->fails()) { + return response()->json(['status' => 'failed', 'message' => 'Failed to add data', 'code' => 500]); + } + $validated = $validator->validated(); + + $validated['created_by'] = $this->currentName; + + $result = Divisi::create($validated); + + if (!$result) { + return response()->json(['status' => 'failed', 'message' => 'Failed to add data', 'code' => 500]); + } else { + return response()->json(['status' => 'success', 'message' => 'Data created!', 'code' => 200]); + } + } + + public function update(Request $request, $id) + { + if (empty($id)) { + return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); + } + $data = Divisi::find($id); + + $validator = Validator::make($request->all(), [ + 'name' => 'required|string|max:200', + 'description' => 'nullable', + 'parent' => 'nullable|integer', + 'created_by' => 'nullable|string|max:80', + 'updated_by' => 'nullable|string|max:80' + ]); + + if ($validator->fails()) { + return response()->json(['status' => 'failed', 'message' => 'Update failed!', 'code' => 500], 500); + } + $validated = $validator->validated(); + + if (!$data) { + return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404); + } + + $result = $data->update($validated); + + if (!$result) { + return response()->json(['status' => 'failed', 'message' => 'Update failed!', 'code' => 500], 500); + } + + return response()->json(['status' => 'success', 'message' => 'Data added!', 'code' => 200], 200); + } + + public function delete($id) + { + if (empty($id)) { + return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); + } + + $data = Divisi::find($id); + + if (!$data) { + return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404); + } + + $delete = $data->delete(); + + if (!$delete) { + return response()->json(['status' => 'failed', 'message' => 'Delete failed!', 'code' => 500], 500); + } else { + return response()->json(['status' => 'success', 'message' => 'Data deleted!', 'code' => 200], 200); + } + } + + public function search() + { + return $this->list(); + // cant use builder for this case + } + + public function list() + { + $parentMenus = Divisi::whereNull('parent')->with('children')->get(); + $divisions = []; + foreach ($parentMenus as $menu) { + $childs = $this->getAllChildren($menu); + foreach ($childs as $d) { + $d->displayName = ' ' . $d->name; + for ($i = 0; $i < $d->depth; $i++) { + $d->displayName = '--' . $d->displayName; + } + array_push($divisions, $d); + } + } + $countData = count($divisions); + if (empty($countData)) { + return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404); + } else { + return response()->json(['status' => 'success', 'code' => 200, 'data' => $divisions, 'totalRecord' => $countData], 200); + } + } } diff --git a/app/Http/Controllers/API/HumanResourceController.php b/app/Http/Controllers/API/HumanResourceController.php index 95bf506..e567f1f 100644 --- a/app/Http/Controllers/API/HumanResourceController.php +++ b/app/Http/Controllers/API/HumanResourceController.php @@ -4,8 +4,216 @@ namespace App\Http\Controllers\API; use App\Http\Controllers\Controller; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Validator; +use App\Models\{HumanResource, UserToActivity, UserToProyek}; +use Illuminate\Support\Facades\Artisan; class HumanResourceController extends Controller { - // + public function add(Request $request) + { + $validator = Validator::make($request->all(), [ + 'role_id' => 'required|integer', + 'divisi_id' => 'nullable|integer', + 'username' => 'nullable|string|max:80', + 'password' => 'nullable|string|max:100', + 'session_login' => 'nullable|string', + 'name' => 'required|string', + 'phone_number' => 'required|string|max:15', + 'email' => 'email|nullable', + 'address' => 'nullable', + 'fcm_token' => 'nullable', + 'gender' => 'nullable|string|max:50', + 'birth_place' => 'nullable|string|max:150', + 'birth_date' => 'nullable|date', + 'blood_type' => 'nullable|string|max:2', + 'ktp_number' => 'required|max:20|string', + 'employee_type' => 'required|string', + 'status_resource' => 'nullable|string|max:50', + 'status_boundary' => 'nullable|boolean', + 'created_by' => 'nullable|string|max:80', + 'updated_by' => 'nullable|string|max:80' + ]); + if ($validator->fails()) { + return response()->json(['status' => 'failed', 'message' => 'Human Resource Pool failed created', 'code' => 400]); + } + $validated = $validator->validated(); + + if (isset($validated['password']) && $validated['password'] != "") { + $validated['password'] = bcrypt($validated['password']); + } + + $result = HumanResource::create($validated); + + if ($result) { + 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 (empty($id)) { + return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); + } + + $result = HumanResource::find($id); + + if ($result) { + return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'failed get data human resource, please try again later!', 'code' => 400], 400); + } + } + + public function update(Request $request, $id) + { + + if (empty($id)) { + return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); + } + + $humanresource = HumanResource::find($id); + + $validator = Validator::make($request->all(), [ + 'role_id' => 'required|integer', + 'divisi_id' => 'nullable|integer', + 'username' => 'nullable|string|max:80', + 'password' => 'nullable|string|max:100', + 'session_login' => 'nullable|string', + 'name' => 'required|string', + 'phone_number' => 'required|string|max:15', + 'email' => 'email|nullable', + 'address' => 'nullable', + 'fcm_token' => 'nullable', + 'gender' => 'nullable|string|max:50', + 'birth_place' => 'nullable|string|max:150', + 'birth_date' => 'nullable|date', + 'blood_type' => 'nullable|string|max:2', + 'ktp_number' => 'required|max:20|string', + 'employee_type' => 'required|string', + 'status_resource' => 'nullable|string|max:50', + 'status_boundary' => 'nullable|boolean', + 'created_by' => 'nullable|string|max:80', + 'updated_by' => 'nullable|string|max:80' + ]); + if ($validator->fails()) { + return response()->json(['status' => 'failed', 'message' => 'Human Resource Pool failed created', 'code' => 400]); + } + $validated = $validator->validated(); + + if (isset($request->password) && $request->password != "") { + $validated['password'] = bcrypt($request->password); + } + // Get data in models + $getHumanResource = HumanResource::where('username', $validated['username'])->whereId($id)->exists(); + if (isset($validated['username']) && $getHumanResource) { + return response()->json(['status' => 'failed', 'message' => 'Username already exists!', 'code' => 400], 400); + } + + if ($humanresource) { + $result = $humanresource->update($validated); + if ($result) { + return response()->json(['status' => 'success', 'message' => 'Human Resource Pool successfully updated!', 'code' => 200], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'Human Resource Pool failed updated!', 'code' => 400], 400); + } + } else { + return response()->json(['status' => 'failed', 'message' => 'data Human Resource Pool not found!', 'code' => 400], 400); + } + } + + public function delete($id) + { + $data = HumanResource::find($id); + + if ($data) { + $delete = $data->delete(); + if ($delete) { + return response()->json(['status' => 'success', 'message' => 'Human Resource Pool successfully deleted!', 'code' => 200], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'Human Resource Pool failed deleted!', 'code' => 400], 400); + } + } else { + return response()->json(['status' => 'failed', 'message' => 'data Human Resource Pool not found!', 'code' => 400], 400); + } + } + + public function search(Request $request) + { + $payload = $request->all(); + $dataBuilder = $this->setUpPayload($payload, 'm_users'); + $builder = $dataBuilder['builder']; + $countBuilder = $dataBuilder['count']; + $dataGet = $builder->get(); + $totalRecord = $countBuilder->count(); + return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => $totalRecord], 200); + } + + public function list() + { + $data = HumanResource::all(); + $countData = $data->count(); + + if ($data) { + return response()->json(['status' => 'success', 'code' => 200, 'data' => $data, 'totalRecord' => $countData], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'failed get list human resource, please try again later!', 'code' => 400], 400); + } + } + + public function select(Request $request) + { + + $search = $request->query('search'); + + $idActivity = (int)$request->query('idact'); + $idProyek = (int)$request->query('idProyek'); + + $forbidden = []; + + if ($idActivity && $idActivity > 0) { + $dataF = UserToActivity::select("user_id")->where("activity_id", $idActivity)->get(); + foreach ($dataF as $val) { + $forbidden[] = $val->user_id; + } + } + + if ($search && !empty($search)) { + $data = UserToProyek::select("m_users.id as id", "m_users.name as name", "assign_hr_to_proyek.project_role as proyek_role")->join('m_users', 'm_users.id', '=', 'assign_hr_to_proyek.user_id') + ->where("assign_hr_to_proyek.proyek_id", $idProyek)->where("m_users.name", 'like', '%' . $search . '%')->whereNotIn("m_users.id", $forbidden)->get(); + } else { + $data = UserToProyek::select("m_users.id as id", "m_users.name as name", "assign_hr_to_proyek.project_role as proyek_role")->where("assign_hr_to_proyek.proyek_id", $idProyek)->join('m_users', 'm_users.id', '=', 'assign_hr_to_proyek.user_id')->whereNotIn("m_users.id", $forbidden)->get(); + } + + return response()->json($data); + } + + public function checkOldPassword(Request $request, $id) + { + if (empty($id)) { + return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); + die(); + } + + $data = $request->all(); + + if (isset($request->old_password) && $request->old_password != "") { + $result = HumanResource::find($id); + $data['old_password'] = bcrypt($request->old_password); + if ($data['old_password'] !== $result->password) { + return response()->json(['status' => 'failed', 'message' => "old password seems doesn't match in records. please try again.", 'code' => 400], 400); + } elseif ($data['old_password'] === $result->password) { + return response()->json(['status' => 'success', 'message' => "old password match", 'data' => $result, 'code' => 200], 200); + } + } else { + return response()->json(['status' => 'failed', 'message' => 'old_password is required!', 'code' => 400], 400); + } + } + + public function sync() + { + Artisan::call('sync:integration-human-resources'); + } } diff --git a/app/Http/Controllers/API/MaterialProjectController.php b/app/Http/Controllers/API/MaterialProjectController.php index ba270dc..3694c4d 100644 --- a/app/Http/Controllers/API/MaterialProjectController.php +++ b/app/Http/Controllers/API/MaterialProjectController.php @@ -4,8 +4,51 @@ namespace App\Http\Controllers\API; use App\Http\Controllers\Controller; use Illuminate\Http\Request; +use App\Models\MaterialProject; class MaterialProjectController extends Controller { - // + public function __invoke(Request $request) + { + $projectId = $request->project_id; + $subproyekId = $request->subproyek_id; + $listMaterialId = $request->material_id; + + if (!$projectId && !$subproyekId) { + return response()->json(['status' => 'failed', 'message' => 'Required proyek_id or subproyek id', 'code' => 400]); + } + + if (is_array($listMaterialId) && count($listMaterialId) > 0) { + $result = 0; + MaterialProject::where('proyek_id', $projectId)->delete(); + MaterialProject::where('proyek_id', $subproyekId)->delete(); + foreach ($listMaterialId as $material_id) { + $data = [ + 'material_resource_id' => (int)$material_id + ]; + + if ($projectId && $projectId != "" && (int)$projectId > 0) { + $data['proyek_id'] = $projectId; + } else if ($subproyekId && $subproyekId != "" && (int)$subproyekId > 0) { + $data['subproyek_id'] = $subproyekId; + } + + $insert = MaterialProject::create($data); + if ($insert) { + $result++; + } else { + $result--; + } + } + if ($result > 0) { + return response()->json(['status' => 'success', 'message' => 'Material Project successfull updated', 'code' => 200]); + } else { + return response()->json(['status' => 'failed', 'message' => 'Material Project failed updated', 'code' => 400]); + } + } else { + MaterialProject::where('proyek_id', $projectId)->delete(); + MaterialProject::where('proyek_id', $subproyekId)->delete(); + return response()->json(['status' => 'success', 'message' => 'Material Project Successfull updated', 'code' => 200]); + } + } } diff --git a/app/Http/Controllers/API/MaterialResourceController.php b/app/Http/Controllers/API/MaterialResourceController.php index aabe04b..685022e 100644 --- a/app/Http/Controllers/API/MaterialResourceController.php +++ b/app/Http/Controllers/API/MaterialResourceController.php @@ -4,8 +4,138 @@ namespace App\Http\Controllers\API; use App\Http\Controllers\Controller; use Illuminate\Http\Request; +use App\Models\{MaterialResource, RequestMaterial}; +use Illuminate\Support\Facades\Validator; class MaterialResourceController extends Controller { - // + public function add(Request $request) + { + $validator = Validator::make($request->all(), [ + 'name' => 'required|string', + 'uom' => 'required|string', + 'unit_price' => 'required|integer', + 'description' => 'required', + 'status' => 'nullable|string|max:80', + 'qty' => 'nullable', + 'created_by' => 'nullable|string|max:80', + 'updated_by' => 'nullable|string|max:80', + ]); + if ($validator->fails()) { + return response()->json(['status' => 'failed', 'message' => 'add data material resource failed!', 'code' => 400], 400); + } + $validated = $validator->validated(); + + $validated['description'] = trim($validated['description']); + $validated['created_by'] = $this->currentName; + + $result = MaterialResource::create($validated); + + if ($result) { + return response()->json(['status' => 'success', 'message' => 'add data material resource successfully!', 'code' => 200], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'add data material resource failed!', 'code' => 400], 400); + } + } + + public function edit($id) + { + if (empty($id)) { + return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); + } + $result = MaterialResource::find($id); + + if ($result) { + return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'failed get data material resource, please try again later!', 'code' => 400], 400); + } + } + + public function update(Request $request, $id) + { + if (empty($id)) { + return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); + } + + $data = MaterialResource::find($id); + + if ($data) { + $validator = Validator::make($request->all(), [ + 'name' => 'required|string', + 'uom' => 'required|string', + 'unit_price' => 'required|integer', + 'description' => 'required', + 'status' => 'nullable|string|max:80', + 'qty' => 'nullable', + 'created_by' => 'nullable|string|max:80', + 'updated_by' => 'nullable|string|max:80', + ]); + if ($validator->fails()) { + return response()->json(['status' => 'failed', 'message' => 'data material resource failed updated!', 'code' => 400], 400); + } + $validated = $validator->validated(); + + $result = $data->update($validated); + if ($result) { + return response()->json(['status' => 'success', 'message' => 'data material resource successfully updated!', 'code' => 200], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'data material resource failed updated!', 'code' => 400], 400); + } + } else { + return response()->json(['status' => 'failed', 'message' => 'data material resource not found!', 'code' => 400], 400); + } + } + + public function delete($id) + { + $data = MaterialResource::find($id); + + if ($data) { + $delete = $data->delete(); + if ($delete) { + return response()->json(['status' => 'success', 'message' => 'data material resource successfully deleted!', 'code' => 200], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'data material resource failed deleted!', 'code' => 400], 400); + } + } else { + return response()->json(['status' => 'failed', 'message' => 'data material resource not found!', 'code' => 400], 400); + } + } + + public function search(Request $request) + { + $payload = $request->all(); + $dataBuilder = $this->setUpPayload($payload, 'm_material_resource'); + $builder = $dataBuilder['builder']; + $countBuilder = $dataBuilder['count']; + $dataGet = $builder->get(); + $totalRecord = $countBuilder->count(); + return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => $totalRecord], 200); + } + + public function list() + { + $data = MaterialResource::all(); + $countData = $data->count(); + + if ($data && $countData) { + return response()->json(['status' => 'success', 'code' => 200, 'data' => $data, 'totalRecord' => $countData], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'failed get list material resource, please try again later!', 'code' => 400], 400); + } + } + + public function select(Request $request) + { + $search = $request->query('search'); + $projectId = $request->idProyek; + + if ($search && !empty($search)) { + $data = RequestMaterial::where("description", 'ILIKE', '%' . $search . '%')->get(); + } else { + $data = RequestMaterial::where("proyek_id", $projectId)->get(); + } + return response()->json($data); + } } diff --git a/app/Http/Controllers/API/MenuController.php b/app/Http/Controllers/API/MenuController.php index fb58188..87a7822 100644 --- a/app/Http/Controllers/API/MenuController.php +++ b/app/Http/Controllers/API/MenuController.php @@ -12,11 +12,14 @@ class MenuController extends Controller public function add(Request $request) { $validator = Validator::make($request->all(), [ + 'parent_id' => 'nullable', 'icon' => 'required', 'name' => 'required|string', + 'alias_name' => 'nullable', 'url' => 'required', 'sequence' => 'required', - 'created_by' => '' + 'created_by' => 'nullable|string|max:80', + 'updated_by' => 'nullable|string|max:80', ]); if ($validator->fails()) { return response()->json(['status' => 'failed', 'message' => 'add data menu failed!', 'code' => 400], 400); @@ -32,9 +35,8 @@ class MenuController extends Controller public function edit($id) { - if (!$id || (int) $id < 0 || empty($id)) { + if (empty($id)) { return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); - die(); } $result = Menu::find($id); @@ -48,16 +50,20 @@ class MenuController extends Controller public function update(Request $request, $id) { - if (!$id || (int) $id < 0 || empty($id)) { + if (empty($id)) { return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); } $data = Menu::find($id); $validator = Validator::make($request->all(), [ + 'parent_id' => '', 'icon' => 'required', 'name' => 'required|string', + 'alias_name' => '', 'url' => 'required', - 'sequence' => 'required' + 'sequence' => 'required', + 'created_by' => '', + 'updated_by' => '', ]); if ($validator->fails()) { return response()->json(['status' => 'failed', 'message' => 'data menu failed updated!', 'code' => 400], 400); diff --git a/app/Http/Controllers/API/ProjectCharterController.php b/app/Http/Controllers/API/ProjectCharterController.php index 5c3533d..90980bc 100644 --- a/app/Http/Controllers/API/ProjectCharterController.php +++ b/app/Http/Controllers/API/ProjectCharterController.php @@ -4,8 +4,90 @@ namespace App\Http\Controllers\API; use App\Http\Controllers\Controller; use Illuminate\Http\Request; +use App\Models\ProjectCharter; +use Illuminate\Support\Facades\Validator; class ProjectCharterController extends Controller { - // + public function add(Request $request) + { + $validator = Validator::make($request->all(), [ + 'proyek_id' => 'required|integer', + 'description' => 'nullable', + 'objectives' => 'nullable', + 'project_is_considered_successful' => 'nullable', + 'participants' => 'nullable', + 'available_resources' => 'nullable', + 'milestones' => 'nullable', + 'potential_risks' => 'nullable', + 'approval' => 'nullable', + 'created_by' => 'nullable|string|max:80', + 'updated_by' => 'nullable|string|max:80', + ]); + + if ($validator->fails()) { + return response()->json(['status' => 'failed', 'message' => 'add data project charter failed!', 'code' => 400], 400); + } + $validated = $validator->validated(); + + $validated['created_by'] = $this->currentName; + + $result = ProjectCharter::create($validated); + + if ($result) { + return response()->json(['status' => 'success', 'message' => 'add data project charter successfully!', 'code' => 200], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'add data project charter failed!', 'code' => 400], 400); + } + } + + public function update(Request $request, $id) + { + if (empty($id)) { + return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); + } + + $data = ProjectCharter::find($id); + + $validator = Validator::make($request->all(), [ + 'proyek_id' => 'required|integer', + 'description' => 'nullable', + 'objectives' => 'nullable', + 'project_is_considered_successful' => 'nullable', + 'participants' => 'nullable', + 'available_resources' => 'nullable', + 'milestones' => 'nullable', + 'potential_risks' => 'nullable', + 'approval' => 'nullable', + 'created_by' => 'nullable|string|max:80', + 'updated_by' => 'nullable|string|max:80', + ]); + + if ($validator->fails()) { + return response()->json(['status' => 'failed', 'message' => 'data project failed updated!', 'code' => 400], 400); + } + $validated = $validator->validated(); + + if ($data) { + $result = $data->update($validated); + if ($result) { + return response()->json(['status' => 'success', 'message' => 'data project successfully updated!', 'code' => 200], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'data project failed updated!', 'code' => 400], 400); + } + } else { + return response()->json(['status' => 'failed', 'message' => 'data project not found!', 'code' => 400], 400); + } + } + + public function search(Request $request) + { + $payload = $request->all(); + $dataBuilder = $this->setUpPayload($payload, 'project_charter'); + $builder = $dataBuilder['builder']; + $countBuilder = $dataBuilder['count']; + $dataGet = $builder->get(); + $totalRecord = $countBuilder->count(); + return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => $totalRecord], 200); + } } diff --git a/app/Http/Controllers/API/ProjectController.php b/app/Http/Controllers/API/ProjectController.php index 7ed779c..6ab2804 100644 --- a/app/Http/Controllers/API/ProjectController.php +++ b/app/Http/Controllers/API/ProjectController.php @@ -28,11 +28,11 @@ use App\Models\{ ActivityDokumen, Holiday, ReportActivity, - OfficeHours + OfficeHours, + ReportActivityMaterial }; use Illuminate\Support\Facades\{DB, Artisan, Validator}; use App\Helpers\MasterFunctionsHelper; -use App\Models\ReportActivityMaterial; const API_GEOLOCATION = "https://nominatim.oslogdev.com/search/ADDR?format=json&addressdetails=1&limit=1"; @@ -42,13 +42,37 @@ class ProjectController extends Controller public function add(Request $request) { $validator = Validator::make($request->all(), [ - 'nama' => 'required', - 'mulai_proyek' => 'required', - 'akhir_proyek' => 'required', - 'rencana_biaya' => 'required', - 'type_proyek_id' => 'required', - 'created_by' => '', - 'phase_id' => '' + 'kode_sortname' => 'string|nullable', + 'jumlah_stakeholder' => 'integer|nullable', + 'nama' => 'required|string', + 'mulai_proyek' => 'required|date', + 'akhir_proyek' => 'nullable|date', + 'area_kerja' => 'nullable|string|max:200', + 'lokasi_kantor' => 'nullable', + 'rencana_biaya' => 'nullable|string', + 'biaya_actual' => 'nullable|string', + 'company' => 'nullable|string', + 'pm_id' => 'nullable|integer', + 'type_proyek_id' => 'nullable|integer', + 'persentase_progress' => 'nullable|numeric', + 'keterangan' => 'nullable', + 'durasi_proyek' => 'nullable|integer', + 'created_by' => 'nullable|string|max:80', + 'updated_by' => 'nullable|string|max:80', + 'progress_by_worklog' => 'nullable|boolean', + 'status' => 'nullable|string|max:50', + 'project_objectives' => 'nullable', + 'considered_success_when' => 'nullable', + 'potential_risk' => 'nullable', + 'testing_environment' => 'nullable', + 'currency_symbol' => 'nullable|string|max:100', + 'currency_code' => 'nullable|string|max:100', + 'currency_name' => 'nullable|string|max:100', + 'phase_id' => 'nullable|integer', + 'budget_health' => 'nullable|string|max:10', + 'divisi_id' => 'nullable|integer', + 'calculaiton_status' => 'nullable|boolean', + 'scurve' => 'nullable|json', ]); if ($validator->fails()) { @@ -69,41 +93,85 @@ class ProjectController extends Controller } $this->createOfficeHours($result->id); - $dataResultInsert = Project::where([ - ['nama', $validated['nama']], - ['mulai_proyek', $validated['mulai_proyek']] - ])->first(); + $dataResultInsert = Project::query() + ->where([ + ['nama', $validated['nama']], + ['mulai_proyek', $validated['mulai_proyek']] + ])->first(); return response()->json(['status' => 'success', 'message' => 'Data added!', 'data_result' => $dataResultInsert, 'code' => 200], 200); } public function edit($id) { - if (empty($id) || !is_int((int)$id)) + if (empty($id)) return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); $result = Project::find($id); - if (!$result) + if (!$result) { return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404); + } return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200); } public function update(Request $request, $id) { - if (empty($id) || !is_int((int)$id)) + if (empty($id)) { return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); + } + $validator = Validator::make($request->all(), [ + 'kode_sortname' => 'string|nullable', + 'jumlah_stakeholder' => 'integer|nullable', + 'nama' => 'required|string', + 'mulai_proyek' => 'required|date', + 'akhir_proyek' => 'nullable|date', + 'area_kerja' => 'nullable|string|max:200', + 'lokasi_kantor' => 'nullable', + 'rencana_biaya' => 'nullable|string', + 'biaya_actual' => 'nullable|string', + 'company' => 'nullable|string', + 'pm_id' => 'nullable|integer', + 'type_proyek_id' => 'nullable|integer', + 'persentase_progress' => 'nullable|numeric', + 'keterangan' => 'nullable', + 'durasi_proyek' => 'nullable|integer', + 'created_by' => 'nullable|string|max:80', + 'updated_by' => 'nullable|string|max:80', + 'progress_by_worklog' => 'nullable|boolean', + 'status' => 'nullable|string|max:50', + 'project_objectives' => 'nullable', + 'considered_success_when' => 'nullable', + 'potential_risk' => 'nullable', + 'testing_environment' => 'nullable', + 'currency_symbol' => 'nullable|string|max:100', + 'currency_code' => 'nullable|string|max:100', + 'currency_name' => 'nullable|string|max:100', + 'phase_id' => 'nullable|integer', + 'budget_health' => 'nullable|string|max:10', + 'divisi_id' => 'nullable|integer', + 'calculaiton_status' => 'nullable|boolean', + 'scurve' => 'nullable|json', + ]); + + if ($validator->fails()) { + return response()->json(['status' => 'failed', 'message' => 'Failed to update!', 'code' => 500], 500); + } + + $validated = $validator->validated(); $data = Project::find($id); - if (!$data) + if (!$data) { return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404); + } - $result = $data->update($request->all()); + $result = $data->update($validated); - if (!$result) + if (!$result) { return response()->json(['status' => 'failed', 'message' => 'Failed to update!', 'code' => 500], 500); + } return response()->json(['status' => 'success', 'message' => 'Data updated!', 'code' => 200], 200); } @@ -153,15 +221,17 @@ class ProjectController extends Controller private function deleteRelative($project_id) { - UserToProyek::where('proyek_id', $project_id)->delete(); - UserToActivity::where('proyek_id', $project_id)->delete(); - AssignMaterial::where('proyek_id', $project_id)->delete(); - ProjectCharter::where('proyek_id', $project_id)->delete(); - ProjectApproval::where('proyek_id', $project_id)->delete(); - ProjectMileStone::where('proyek_id', $project_id)->delete(); - ProjectParticipants::where('proyek_id', $project_id)->delete(); - $this->deleteVersionGantt($project_id); - $this->deleteDokumenProject($project_id); + $id_proyek = $project_id; + + UserToProyek::where('proyek_id', $id_proyek)->delete(); + UserToActivity::where('proyek_id', $id_proyek)->delete(); + AssignMaterial::where('proyek_id', $id_proyek)->delete(); + ProjectCharter::where('proyek_id', $id_proyek)->delete(); + ProjectApproval::where('proyek_id', $id_proyek)->delete(); + ProjectMileStone::where('proyek_id', $id_proyek)->delete(); + ProjectParticipants::where('proyek_id', $id_proyek)->delete(); + $this->deleteVersionGantt($id_proyek); + $this->deleteDokumenProject($id_proyek); } private function deleteVersionGantt($project_id) @@ -172,13 +242,18 @@ class ProjectController extends Controller $activityIds = $activity->all(); $dataRa = ReportActivity::whereIn("activity_id", $activityIds)->get(); foreach ($dataRa as $ra) { - $images = Image::where("ref_id", $ra->id)->where("category", "report_activity")->get(); + $images = Image::where("ref_id", $ra['id'])->where("category", "report_activity")->get(); foreach ($images as $image) { if (file_exists($this->pathImage . $image->image)) { unlink($this->pathImage . $image->image); } } - Image::where("ref_id", $ra->id)->where("category", "report_activity")->delete(); + Image::query() + ->where([ + ["ref_id", $ra['id']], + ["category", "report_activity"] + ]) + ->delete(); } $dataAd = ActivityDokumen::whereIn("activity_id", $activityIds)->get(); foreach ($dataAd as $ad) { @@ -208,10 +283,11 @@ class ProjectController extends Controller unlink($this->pathDocument . $dokumen->file); } } - DokumenProject::where([ - ["type_dokumen", "project-document-out-folder"], - ['ref_id', $project_id] - ])->delete(); + DokumenProject::query() + ->where([ + ["type_dokumen", "project-document-out-folder"], + ['ref_id', $project_id] + ])->delete(); $dataFolder = FolderDocumentProyek::where('proyek_id', $project_id)->pluck("id"); $ref_ids = $dataFolder->all(); @@ -253,14 +329,14 @@ class ProjectController extends Controller $progress = $costVariance = $actualCost = 0; $lastActivity = null; $scheduleHealth = "on-track"; - $rootActivity = Activity::whereNull('parent_id')->where('proyek_id', $d->id)->orderByDesc('version_gantt_id')->first(); + $rootActivity = Activity::whereNull('parent_id')->where('proyek_id', $d['id'])->orderByDesc('version_gantt_id')->first(); if ($rootActivity) { - $costVariance = (int)$d->rencana_biaya - (int)$rootActivity->biaya_actual; + $costVariance = (int)$d['rencana_biaya'] - (int)$rootActivity->biaya_actual; $actualCost = $rootActivity->biaya_actual ?? 0; $progress = $rootActivity->persentase_progress ?? 0; - $timeleft = strtotime($d->mulai_proyek) - strtotime($rootActivity->end_date); - $date1 = new \DateTime(date("Y-m-d", strtotime($d->mulai_proyek))); + $timeleft = strtotime($d['mulai_proyek']) - strtotime($rootActivity->end_date); + $date1 = new \DateTime(date("Y-m-d", strtotime($d['mulai_proyek']))); $date2 = new \DateTime(date("Y-m-d", strtotime($rootActivity->end_date))); $daysRemaining = $date2->diff($date1); $daysRemaining = $daysRemaining->d; @@ -272,26 +348,26 @@ class ProjectController extends Controller } $lastActivity = date("d/m/Y", strtotime($rootActivity->end_date)); } - $d->plannedInterval = date("d/m/Y", strtotime($d->mulai_proyek)) . " - " . date("d/m/Y", strtotime($d->akhir_proyek)); - $d->plannedCost = $d->rencana_biaya; - $d->actualCost = $actualCost; - $d->lastActivity = $lastActivity ?? "-"; - $d->costVariance = $costVariance; - $d->costHealth = $d->budget_health; - $d->scheduleHealth = $scheduleHealth; - $d->progress = $progress; - $d->lastGanttId = VersionGantt::where("proyek_id", $d->id)->orderByDesc('id')->first()->id ?? null; - $d->manpower = UserToProyek::where("proyek_id", $d->id)->count() ?? 0; - $d->projectManager = Project::query() + $d['plannedInterval'] = date("d/m/Y", strtotime($d['mulai_proyek'])) . " - " . date("d/m/Y", strtotime($d['akhir_proyek'])); + $d['plannedCost'] = $d['rencana_biaya']; + $d['actualCost'] = $actualCost; + $d['lastActivity'] = $lastActivity ?? "-"; + $d['costVariance'] = $costVariance; + $d['costHealth'] = $d['budget_health']; + $d['scheduleHealth'] = $scheduleHealth; + $d['progress'] = $progress; + $d['lastGanttId'] = VersionGantt::where("proyek_id", $d['id'])->orderByDesc('id')->first()->id ?? null; + $d['manpower'] = UserToProyek::where("proyek_id", $d['id'])->count() ?? 0; + $d['projectManager'] = Project::query() ->join('m_users', 'm_users.id', '=', 'm_proyek.pm_id') - ->where('m_proyek.id', $d->id) + ->where('m_proyek.id', $d['id']) ->pluck('m_users.name') ->first(); - if ($d->area_kerja != '') { - $d->geolocation = $this->httpReq($d->area_kerja); - $d->geolocation = []; + if ($d['area_kerja'] != '') { + $d['geolocation'] = $this->httpReq($d['area_kerja']); + $d['geolocation'] = []; } else { - $d->geolocation = []; + $d['geolocation'] = []; } } @@ -386,7 +462,7 @@ class ProjectController extends Controller $reports = []; foreach ($activities as $activity) { - $activity_id = $activity->id; + $activity_id = $activity['id']; $countReports = ReportActivityMaterial::where('activity_id', $activity_id)->count(); if ($countReports === 1) { $dataReports = ReportActivityMaterial::where('activity_id', $activity_id)->orderBy('report_date')->get(); @@ -412,8 +488,8 @@ class ProjectController extends Controller for ($i = 0; $i < count($reports); $i++) { $activity = Activity::find($reports[$i]['activity_id']); - $activity->start_date = $reports[$i]['min_date']; - $activity->end_date = $reports[$i]['max_date']; + $activity['start_date'] = $reports[$i]['min_date']; + $activity['end_date'] = $reports[$i]['max_date']; $activity->save(); } @@ -426,8 +502,8 @@ class ProjectController extends Controller foreach ($activities as $activity) { $activity->update([ - "planned_start" => $activity->start_date, - "planned_end" => $activity->end_date, + "planned_start" => $activity['start_date'], + "planned_end" => $activity['end_date'], ]); } @@ -436,20 +512,14 @@ class ProjectController extends Controller public function getInvoiceIntegration(Request $request) { - // $search = urlencode($request->search); - // if(empty($search)) - // return response()->json(['status'=>'error', 'message'=>'Empty query string!'], 400); - // $url = str_replace("SEARCH", $search, config('api.adw').'/project_cost?project_no=SEARCH'); - $response = null; - // return response()->json(['status'=>'success', 'data'=> $response, 'code'=>200], 200); return response()->json(['status' => 'success', 'data' => '', 'code' => 200], 200); } public function detail($id) { - if (empty($id) || !is_int((int)$id)) { + if (empty($id)) { return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); } @@ -468,7 +538,7 @@ class ProjectController extends Controller public function getOverdueActivities(Request $request) { $payload = $request->all(); - if (empty($payload['id']) || !is_int((int)$payload['id'])) { + if (empty($payload['id'])) { return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); } @@ -493,11 +563,11 @@ class ProjectController extends Controller { $payload = $request->all(); - if (empty($payload['project_id']) || !is_int((int)$payload['project_id'])) { + if (empty($payload['project_id'])) { return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); } - $reports = DB::table('assign_material_to_activity as ama') + $reports = DB::table('assign_material_to_activity AS ama') ->select( 'u.name', 'a.name as activity_name', @@ -510,10 +580,10 @@ class ProjectController extends Controller 'ram.description as report_notes', 'ram.report_date' ) - ->join('report_activity_material as ram', 'ram.assign_material_id', '=', 'ama.id') - ->join('m_req_material as rm', 'rm.id', '=', 'ama.material_id') - ->join('m_activity as a', 'a.id', '=', 'ama.activity_id') - ->join('m_users as u', 'u.id', '=', 'ram.user_id') + ->join('report_activity_material AS ram', 'ram.assign_material_id', '=', 'ama.id') + ->join('m_req_material AS rm', 'rm.id', '=', 'ama.material_id') + ->join('m_activity AS a', 'a.id', '=', 'ama.activity_id') + ->join('m_users AS u', 'u.id', '=', 'ram.user_id') ->where('ama.proyek_id', '=', $payload['project_id']) ->whereNotNull('ram.lat') ->whereBetween('ram.report_date', [$payload['start_date'], $payload['end_date']]); @@ -550,7 +620,7 @@ class ProjectController extends Controller 'mu.name as pm', 'mp.budget_health' ) - ->join('m_users as mu', 'mu.id', '=', 'mp.pm_id') + ->join('m_users AS mu', 'mu.id', '=', 'mp.pm_id') ->where('mp.id', $id) ->first(); @@ -561,18 +631,18 @@ class ProjectController extends Controller $manpowers = UserToProyek::where('proyek_id', $id)->count(); $rootActivity = Activity::whereNull('parent_id')->where('proyek_id', $id)->orderByDesc('version_gantt_id')->first(); - $actualCost = $rootActivity->biaya_actual ?? 0; - $progress = $rootActivity->persentase_progress ?? 0; + $actualCost = $rootActivity['biaya_actual'] ?? 0; + $progress = $rootActivity['persentase_progress'] ?? 0; $commentActivity = DB::table('m_comment_activity as mca') ->select( 'mca.activity_id', - 'mca.comment as comment', - 'mca.created_by as comment_by', - 'mca.created_at as comment_created', - 'ma.name as activity' + 'mca.comment AS comment', + 'mca.created_by AS comment_by', + 'mca.created_at AS comment_created', + 'ma.name AS activity' ) - ->join('m_activity as ma', 'ma.id', '=', 'mca.activity_id') + ->join('m_activity AS ma', 'ma.id', '=', 'mca.activity_id') ->where('ma.proyek_id', $id) ->orderBy('comment_by') ->take(2) diff --git a/app/Http/Controllers/API/ProjectDokumenController.php b/app/Http/Controllers/API/ProjectDokumenController.php index b61fd92..a12b83b 100644 --- a/app/Http/Controllers/API/ProjectDokumenController.php +++ b/app/Http/Controllers/API/ProjectDokumenController.php @@ -10,7 +10,7 @@ class ProjectDokumenController extends Controller { public function dokumenByProyekId($id) { - if (empty($id) || !is_int((int)$id)) { + if (empty($id)) { return response()->json(['status' => 'failed', 'message' => 'project id is required!', 'code' => 400], 400); } @@ -25,7 +25,7 @@ class ProjectDokumenController extends Controller public function delete($id) { - if (empty($id) || !is_int((int)$id)) { + if (empty($id)) { return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); } @@ -46,12 +46,15 @@ class ProjectDokumenController extends Controller public function uploadProjectDokumen(Request $request) { if ($request->hasFile('dokumen')) { - $request->validate([ - 'dokumen' => 'mimes:png,jpg,pdf,jpeg,gif' + $validated = $request->validate([ + 'dokumen' => 'required|image|mimes:png,jpg,pdf,jpeg,gif', + 'ref_id' => 'required|integer', + 'file' => 'required', + 'type_dokumen' => 'required' ]); $document = $request->file('dokumen'); - $ref_id = $request->ref_id; + $ref_id = $validated['ref_id']; $name = $document->getClientOriginalName(); $result = $document->move($this->pathDocument, $name); @@ -59,7 +62,7 @@ class ProjectDokumenController extends Controller $data = [ 'ref_id' => (int)$ref_id, 'file' => $name, - 'type_dokumen' => isset($request->type_dokumen) ? $request->type_dokumen : 'project-document' + 'type_dokumen' => isset($validated['type_dokumen']) ? $validated['type_dokumen'] : 'project-document' ]; $result = DokumenProject::create($data); @@ -90,7 +93,7 @@ class ProjectDokumenController extends Controller public function downloadDokumen($id) { - if (empty($id) || !is_int((int)$id)) { + if (empty($id)) { return response()->json(['status' => 'failed', 'message' => 'Id is required!', 'code' => 400], 400); } diff --git a/app/Http/Controllers/API/ProjectPhaseController.php b/app/Http/Controllers/API/ProjectPhaseController.php index 9469a83..b37f716 100644 --- a/app/Http/Controllers/API/ProjectPhaseController.php +++ b/app/Http/Controllers/API/ProjectPhaseController.php @@ -4,8 +4,113 @@ namespace App\Http\Controllers\API; use App\Http\Controllers\Controller; use Illuminate\Http\Request; +use App\Models\ProjectPhase; +use Illuminate\Support\Facades\Validator; class ProjectPhaseController extends Controller { - // + public function add(Request $request) + { + $validator = Validator::make($request->all(), [ + 'name' => 'required|string|max:100', + 'color' => 'nullable|string|max:10', + 'order' => 'nullable|integer', + 'created_by' => 'nullable|string|max:80', + 'updated_by' => 'nullable|string|max:80', + ]); + if ($validator->fails()) { + return response()->json(['status' => 'failed', 'message' => 'add data menu failed!', 'code' => 400], 400); + } + $validated = $validator->validated(); + $validated['created_by'] = $this->currentName; + + $result = ProjectPhase::create($validated); + if ($result) { + return response()->json(['status' => 'success', 'message' => 'data added!', 'code' => 200], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'Failed to add data', 'code' => 500], 500); + } + } + + public function edit($id) + { + if (empty($id)) { + return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); + } + $result = ProjectPhase::find($id); + if ($result) { + return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'Failed to get data!', 'code' => 404], 404); + } + } + + public function update(Request $request, $id) + { + if (empty($id)) { + return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); + } + $result = ProjectPhase::find($id); + + $validator = Validator::make($request->all(), [ + 'name' => 'required|string|max:100', + 'color' => 'nullable|string|max:10', + 'order' => 'nullable|integer', + 'created_by' => 'nullable|string|max:80', + 'updated_by' => 'nullable|string|max:80', + ]); + if ($validator->fails()) { + return response()->json(['status' => 'failed', 'message' => 'data project type failed updated!', 'code' => 400], 400); + } + $validated = $validator->validated(); + + if (!$result) { + return response()->json(['status' => 'failed', 'message' => 'data role not found!', 'code' => 400], 400); + } + + $updatedResult = $result->update($validated); + + if (!$updatedResult) { + return response()->json(['status' => 'success', 'message' => 'Data berhasil disimpan!', 'code' => 200], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'data project type failed updated!', 'code' => 400], 400); + } + } + + public function delete($id) + { + $result = ProjectPhase::find($id); + if (!$result) { + return response()->json(['status' => 'failed', 'message' => 'data project phase not found!', 'code' => 400], 400); + } + $deleted = $result->delete(); + if ($deleted) { + return response()->json(['status' => 'success', 'message' => 'Data berhasil dihapus!', 'code' => 200], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'Data gagal dihapus!', 'code' => 500], 500); + } + } + + public function search(Request $request) + { + $payload = $request->all(); + $dataBuilder = $this->setUpPayload($payload, 'm_proyek_phase'); + $builder = $dataBuilder['builder']; + $countBuilder = $dataBuilder['count']; + $dataGet = $builder->get(); + $totalRecord = $countBuilder->count(); + return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => $totalRecord], 200); + } + + public function list() + { + $data = ProjectPhase::all(); + $countData = $data->count(); + + if ($data) { + return response()->json(['status' => 'success', 'code' => 200, 'data' => $data, 'totalRecord' => $countData], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'failed get list project type, please try again later!', 'code' => 400], 400); + } + } } diff --git a/app/Http/Controllers/API/ProjectRoleController.php b/app/Http/Controllers/API/ProjectRoleController.php index 4382b06..228f060 100644 --- a/app/Http/Controllers/API/ProjectRoleController.php +++ b/app/Http/Controllers/API/ProjectRoleController.php @@ -4,8 +4,128 @@ namespace App\Http\Controllers\API; use App\Http\Controllers\Controller; use Illuminate\Http\Request; +use App\Models\ProjectRole; +use Illuminate\Support\Facades\Validator; class ProjectRoleController extends Controller { - // + public function add(Request $request) + { + $validator = Validator::make($request->all(), [ + 'name' => 'required|string|max:150', + 'description' => 'required|string', + 'created_by' => 'nullable|string|max:80', + 'updated_by' => 'nullable|string|max:80' + ]); + if ($validator->fails()) { + return response()->json(['status' => 'failed', 'message' => 'add data project role failed!', 'code' => 400], 400); + } + $validated = $validator->validated(); + + $validated['created_by'] = $this->currentName; + + $result = ProjectRole::create($validated); + + if ($result) { + return response()->json(['status' => 'success', 'message' => 'add data project role successfully!', 'code' => 200], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'add data project role failed!', 'code' => 400], 400); + } + } + + public function edit($id) + { + if (empty($id)) { + return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); + } + $result = ProjectRole::find($id); + + if ($result) { + return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'failed get data project role, please try again later!', 'code' => 400], 400); + } + } + + public function update(Request $request, $id) + { + if (empty($id)) { + return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); + } + + $data = ProjectRole::find($id); + + $validator = Validator::make($request->all(), [ + 'name' => 'required|string|max:150', + 'description' => 'required|string', + 'created_by' => 'nullable|string|max:80', + 'updated_by' => 'nullable|string|max:80' + ]); + if ($validator->fails()) { + return response()->json(['status' => 'failed', 'message' => 'data project role failed updated!', 'code' => 400], 400); + } + $validated = $validator->validated(); + + if ($data) { + $result = $data->update($validated); + if ($result) { + return response()->json(['status' => 'success', 'message' => 'data project role successfully updated!', 'code' => 200], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'data project role failed updated!', 'code' => 400], 400); + } + } else { + return response()->json(['status' => 'failed', 'message' => 'data project role not found!', 'code' => 400], 400); + } + } + + public function delete($id) + { + $data = ProjectRole::find($id); + + if ($data) { + $delete = $data->delete(); + if ($delete) { + return response()->json(['status' => 'success', 'message' => 'data project role successfully deleted!', 'code' => 200], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'data project role failed deleted!', 'code' => 400], 400); + } + } else { + return response()->json(['status' => 'failed', 'message' => 'data project role not found!', 'code' => 400], 400); + } + } + + public function search(Request $request) + { + $payload = $request->all(); + $dataBuilder = $this->setUpPayload($payload, 'm_role_proyek'); + $builder = $dataBuilder['builder']; + $countBuilder = $dataBuilder['count']; + $dataGet = $builder->get(); + $totalRecord = $countBuilder->count(); + return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => $totalRecord], 200); + } + + public function list() + { + $data = ProjectRole::all(); + $countData = $data->count(); + + if ($data) { + return response()->json(['status' => 'success', 'code' => 200, 'data' => $data, 'totalRecord' => $countData], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'failed get list project role, please try again later!', 'code' => 400], 400); + } + } + + public function select(Request $request) + { + $search = $request->query('search'); + if ($search && !empty($search)) { + $data = ProjectRole::where("name", 'like', '%' . $search . '%')->get(); + } else { + $data = ProjectRole::all(); + } + + return response()->json($data); + } } diff --git a/app/Http/Controllers/API/ProjectTypeController.php b/app/Http/Controllers/API/ProjectTypeController.php index 23c67bc..7786a5b 100644 --- a/app/Http/Controllers/API/ProjectTypeController.php +++ b/app/Http/Controllers/API/ProjectTypeController.php @@ -4,8 +4,119 @@ namespace App\Http\Controllers\API; use App\Http\Controllers\Controller; use Illuminate\Http\Request; +use App\Models\ProjectType; +use Illuminate\Support\Facades\Validator; class ProjectTypeController extends Controller { - // + public function add(Request $request) + { + $validator = Validator::make($request->all(), [ + 'name' => 'required|string|max:150', + 'description' => 'required|string', + 'company_id' => 'nullable|integer', + 'created_by' => 'nullable|string|max:80', + 'updated_by' => 'nullable|string|max:80' + ]); + if ($validator->fails()) { + return response()->json(['status' => 'failed', 'message' => 'add data project role failed!', 'code' => 400], 400); + } + $validated = $validator->validated(); + + $validated['created_by'] = $this->currentName; + + $result = ProjectType::create($validated); + + if ($result) { + return response()->json(['status' => 'success', 'message' => 'add data project type successfully!', 'code' => 200], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'add data project type failed!', 'code' => 400], 400); + } + } + + public function edit($id) + { + if (empty($id)) { + return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); + } + + $result = ProjectType::find($id); + + if ($result) { + return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'failed get data project type, please try again later!', 'code' => 400], 400); + } + } + + public function update(Request $request, $id) + { + if (empty($id)) { + return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); + } + + $data = ProjectType::find($id); + + $validator = Validator::make($request->all(), [ + 'name' => 'required|string|max:150', + 'description' => 'required|string', + 'company_id' => 'nullable|integer', + 'created_by' => 'nullable|string|max:80', + 'updated_by' => 'nullable|string|max:80' + ]); + if ($validator->fails()) { + return response()->json(['status' => 'failed', 'message' => 'data project type failed updated!', 'code' => 400], 400); + } + $validated = $validator->validated(); + + if ($data) { + $result = $data->update($validated); + if ($result) { + return response()->json(['status' => 'success', 'message' => 'data project type successfully updated!', 'code' => 200], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'data project type failed updated!', 'code' => 400], 400); + } + } else { + return response()->json(['status' => 'failed', 'message' => 'data role not found!', 'code' => 400], 400); + } + } + + public function delete($id) + { + $data = ProjectType::find($id); + + if ($data) { + $delete = $data->delete(); + if ($delete) { + return response()->json(['status' => 'success', 'message' => 'data project type successfully deleted!', 'code' => 200], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'data project type failed deleted!', 'code' => 400], 400); + } + } else { + return response()->json(['status' => 'failed', 'message' => 'data project type not found!', 'code' => 400], 400); + } + } + + public function search(Request $request) + { + $payload = $request->all(); + $dataBuilder = $this->setUpPayload($payload, 'm_type_proyek'); + $builder = $dataBuilder['builder']; + $countBuilder = $dataBuilder['count']; + $dataGet = $builder->get(); + $totalRecord = $countBuilder->count(); + return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => $totalRecord], 200); + } + + public function list() + { + $data = ProjectType::all(); + $countData = $data->count(); + + if ($data) { + return response()->json(['status' => 'success', 'code' => 200, 'data' => $data, 'totalRecord' => $countData], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'failed get list project type, please try again later!', 'code' => 400], 400); + } + } } diff --git a/app/Http/Controllers/API/RequestMaterialController.php b/app/Http/Controllers/API/RequestMaterialController.php index e1acb59..98bcdb1 100644 --- a/app/Http/Controllers/API/RequestMaterialController.php +++ b/app/Http/Controllers/API/RequestMaterialController.php @@ -4,8 +4,267 @@ namespace App\Http\Controllers\API; use App\Http\Controllers\Controller; use Illuminate\Http\Request; +use App\Models\{RequestMaterial, MaterialResource}; +use Illuminate\Support\Facades\{DB, Validator}; class RequestMaterialController extends Controller { - // + private function sanitizeDecimal($number) + { + $number = str_replace(".", "", $number); + $number = str_replace(",", ".", $number); + return $number; + } + + public function add(Request $request) + { + $validator = Validator::make($request->all(), [ + 'description' => 'required', + 'required_date' => 'required', + 'qty' => 'required', + 'uom' => 'required|string', + 'qty_received' => 'nullable', + 'fom_date' => 'required', + 'pr_date' => 'nullable', + 'po_date' => 'nullable', + 'received_date' => 'nullable', + 'delivery_date' => 'nullable', + 'status' => 'nullable|string', + 'proyek_id' => 'required|integer', + 'price' => 'nullable', + 'created_by' => 'nullable|string|max:80', + 'updated_by' => 'nullable|string|max:80', + ]); + if ($validator->fails()) { + return response()->json(['status' => 'failed', 'message' => 'add data menu failed!', 'code' => 400], 400); + } + $validated = $validator->validated(); + + $validated['price'] = $this->sanitizeDecimal($validated['price']); + $validated['qty'] = $this->sanitizeDecimal($validated['qty']); + $validated['status'] = "fom"; + $validated['created_by'] = $this->currentName; + + $result = RequestMaterial::create($validated); + + if ($result) { + return response()->json(['status' => 'success', 'message' => 'Data added!', 'data' => $result, 'code' => 200], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'Failed to add!', 'code' => 500], 500); + } + } + + public function edit($id) + { + if (empty($id)) { + return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); + } + + $result = RequestMaterial::find($id); + + if ($result) { + return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404); + } + } + + public function delete($id) + { + $data = RequestMaterial::find($id); + + if ($data) { + $delete = $data->delete(); + if ($delete) { + return response()->json(['status' => 'success', 'message' => 'Data deleted!', 'code' => 200], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'Failed to delete!', 'code' => 500], 500); + } + } else { + return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404); + } + } + + public function search(Request $request) + { + $payload = $request->all(); + $dataBuilder = $this->setUpPayload($payload, 'm_req_material'); + $builder = $dataBuilder['builder']; + $countBuilder = $dataBuilder['count']; + $dataGet = $builder->get(); + $totalRecord = $countBuilder->count(); + return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => $totalRecord], 200); + } + + public function list() + { + $data = RequestMaterial::all(); + $countData = $data->count(); + + if ($data) { + return response()->json(['status' => 'success', 'code' => 200, 'data' => $data, 'totalRecord' => $countData], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'failed get list request material, please try again later!', 'code' => 400], 400); + } + } + + public function update(Request $request, $id) + { + if (empty($id)) { + return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); + die; + } + + $reqMaterial = RequestMaterial::find($id); + $validator = Validator::make($request->all(), [ + 'description' => 'required', + 'required_date' => 'required', + 'qty' => 'required', + 'uom' => 'required|string', + 'qty_received' => 'nullable', + 'fom_date' => 'required', + 'pr_date' => 'nullable', + 'po_date' => 'nullable', + 'received_date' => 'nullable', + 'delivery_date' => 'nullable', + 'status' => 'nullable|string', + 'proyek_id' => 'required|integer', + 'price' => 'nullable', + 'created_by' => 'nullable|string|max:80', + 'updated_by' => 'nullable|string|max:80', + ]); + if ($validator->fails()) { + return response()->json(['status' => 'failed', 'message' => 'add data menu failed!', 'code' => 400], 400); + } + $validated = $validator->validated(); + try { + DB::beginTransaction(); + if (!$reqMaterial) { + return response()->json(['status' => 'failed', 'message' => 'data request material not found!', 'code' => 400], 400); + } + + if (!isset($validated['status'])) : + if (!$reqMaterial->update($validated)) { + return response()->json(['status' => 'failed', 'message' => 'request material failed updated!', 'code' => 400], 400); + } else { + return response()->json(['status' => 'success', 'message' => 'request material successfully updated!', 'code' => 200], 200); + } + endif; + + if ($validated['status'] === "receipt to warehouse") : + $materialResource = MaterialResource::where('name', 'ILIKE', $reqMaterial['description'])->first(); + if ($materialResource) { + $reqMaterial->update($validated); + $payloadMQty = $materialResource['qty'] + $reqMaterial['qty_received']; + MaterialResource::whereId($materialResource['id'])->update(['qty' => $payloadMQty]); + return response()->json(['status' => 'success', 'code' => 200], 200); + } + + $reqMaterial->update($validated); + + $resultMaterial = MaterialResource::create([ + "name" => $validated['description'], + "uom" => $validated['uom'], + "unit_price" => 0, + "description" => $validated['description'], + "qty" => $reqMaterial['qty_received'], + "status" => "Barang tersedia", + "created_by" => $this->currentName + ]); + + if ($resultMaterial) { + return response()->json(['status' => 'success', 'message' => 'add data material resource successfully!', 'code' => 200], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'add data material resource failed!', 'code' => 400], 400); + } + elseif ($validated['status'] === "receipt to site") : + $reqMaterial->update($validated); + + $materialResource = MaterialResource::where('name', 'ILIKE', $reqMaterial['description'])->first(); + if (!$materialResource) { + return response()->json(['status' => 'failed', 'message' => 'update status receipt to site request material resource failed, because material is not exist in warehouse!', 'code' => 400], 400); + die; + } + + $reqMaterial->update($validated); + $payloadMQty = $materialResource['qty'] - $reqMaterial['qty_received']; + + if ($payloadMQty < 0) { + return response()->json(['status' => 'failed', 'message' => 'update status receipt to site request material resource failed, because material is not exist in warehouse!', 'code' => 400], 400); + die; + } + + $materialResourceScnd = MaterialResource::query() + ->whereId($materialResource['id']) + ->update([ + 'qty' => $payloadMQty + ]); + if ($materialResourceScnd) { + return response()->json(['status' => 'success', 'message' => 'request material status receipt to site successfully updated!', 'code' => 200], 200); + } + endif; + + if (!$reqMaterial->update($validated)) { + return response()->json(['status' => 'failed', 'message' => 'request material failed updated!', 'code' => 400], 400); + } else { + return response()->json(['status' => 'success', 'message' => 'request material successfully updated!', 'code' => 200], 200); + } + DB::commit(); + } catch (\Throwable $th) { + DB::rollBack(); + return response()->json(['status' => 'failed', 'message' => 'request material failed updated!', 'code' => 400], 400); + } + } + + private function curlReq($url, $token) + { + $ch = curl_init(); + $headers = [ + 'Authorization: ' . $token + ]; + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + + $response = curl_exec($ch); + if ($response === false) { + $response = curl_error($ch); + } + curl_close($ch); + + return json_decode($response); + } + + public function getMaterialIntegration() + { + $search = null; + if (empty($search)) { + return response()->json(['status' => 'error', 'message' => 'Empty query string!'], 400); + } + $url = str_replace("SEARCH", $search, config('api.adw') . '/stock_master?name=SEARCH'); + $token = config('api.adw_token'); + $firstResponse = $this->curlReq($url, $token); + + if ($firstResponse->total == 0) { + return response()->json(['status' => 'error', 'message' => 'Data not found!', 'code' => 404], 404); + } + + $data = $firstResponse->data; + $currentPage = 1; + + if ($firstResponse->last_page > 0) { + do { + $currentPage++; + $response = $this->curlReq($url . '&page=' . $currentPage, $token); + foreach ($response->data as $d) { + array_push($data, $d); + } + } while ($currentPage < 5); + // let the user narrow down the search by themself + // a searching action with 'cable' keyword could take minutes + // because there are >1k items associated with that keyword + } + + return response()->json(['status' => 'success', 'data' => $data, 'total' => count($data), 'code' => 200], 200); + } } diff --git a/app/Http/Controllers/API/RoleController.php b/app/Http/Controllers/API/RoleController.php index fa077ae..6aa197e 100644 --- a/app/Http/Controllers/API/RoleController.php +++ b/app/Http/Controllers/API/RoleController.php @@ -15,7 +15,8 @@ class RoleController extends Controller $validator = Validator::make($request->all(), [ 'name' => 'required', 'description' => 'required', - 'created_by' => '' + 'created_by' => '', + 'updated_by' => '' ]); if ($validator->fails()) { @@ -31,7 +32,7 @@ class RoleController extends Controller public function edit($id) { - if (empty($id) || !is_int((int)$id)) { + if (empty($id)) { return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); } @@ -46,14 +47,16 @@ class RoleController extends Controller public function update(Request $request, $id) { - if (empty($id) || !is_int((int)$id)) { + if (empty($id)) { return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); } $data = Role::find($id); $validated = $request->validate([ 'name' => 'required', - 'description' => 'required' + 'description' => 'required', + 'created_by' => '', + 'updated_by' => '' ]); if (!$data) { @@ -71,7 +74,7 @@ class RoleController extends Controller public function delete($id) { - if (empty($id) || !is_int((int)$id)) { + if (empty($id)) { return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); } diff --git a/app/Http/Controllers/API/RoleMenuController.php b/app/Http/Controllers/API/RoleMenuController.php index a2173b1..cc6622d 100644 --- a/app/Http/Controllers/API/RoleMenuController.php +++ b/app/Http/Controllers/API/RoleMenuController.php @@ -14,7 +14,8 @@ class RoleMenuController extends Controller $validator = Validator::make($request->all(), [ 'role_id' => 'required', 'menu_id' => 'required', - 'created_by' => '' + 'created_by' => '', + 'updated_by' => '' ]); if ($validator->fails()) { @@ -30,14 +31,26 @@ class RoleMenuController extends Controller public function update(Request $request, $id) { - if (!$id || (int) $id < 0 || empty($id)) { + if (empty($id)) { return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); } + $validator = Validator::make($request->all(), [ + 'role_id' => 'required', + 'menu_id' => 'required', + 'created_by' => '', + 'updated_by' => '' + ]); + + if ($validator->fails()) { + return response()->json(['status' => 'failed', 'message' => 'data role menu failed updated!', 'code' => 400], 400); + } + + $validated = $validator->validated(); $data = RoleMenu::find($id); if ($data) { - $result = $data->update($request->all()); + $result = $data->update($validated); if ($result) : return response()->json(['status' => 'success', 'message' => 'data role menu successfully updated!', 'code' => 200], 200); else : diff --git a/app/Http/Controllers/API/ToolsProjectController.php b/app/Http/Controllers/API/ToolsProjectController.php index 76b8ddc..de35556 100644 --- a/app/Http/Controllers/API/ToolsProjectController.php +++ b/app/Http/Controllers/API/ToolsProjectController.php @@ -4,8 +4,51 @@ namespace App\Http\Controllers\API; use App\Http\Controllers\Controller; use Illuminate\Http\Request; +use App\Models\ToolsProject; class ToolsProjectController extends Controller { - // + public function assignTools(Request $request) + { + $projectId = $request->project_id; + $subproyekId = $request->subproyek_id; + $listToolsId = $request->tools_id; + + if (!$projectId && !$subproyekId) { + return response()->json(['status' => 'failed', 'message' => 'Required proyek_id or subproyek id', 'code' => 400]); + } + + if (is_array($listToolsId) && count($listToolsId) > 0) { + $result = 0; + ToolsProject::where('proyek_id', $projectId)->delete(); + ToolsProject::where('proyek_id', $subproyekId)->delete(); + foreach ($listToolsId as $tool_id) { + $data = [ + 'tools_id' => (int)$tool_id + ]; + + if ($projectId && $projectId != "" && (int)$projectId > 0) { + $data['proyek_id'] = $projectId; + } else if ($subproyekId && $subproyekId != "" && (int)$subproyekId > 0) { + $data['subproyek_id'] = $subproyekId; + } + + $insert = ToolsProject::create($data); + if ($insert) { + $result++; + } else { + $result--; + } + } + if ($result > 0) { + return response()->json(['status' => 'success', 'message' => 'Tools Project successfull updated', 'code' => 200]); + } else { + return response()->json(['status' => 'failed', 'message' => 'Tools Project failed updated', 'code' => 400]); + } + } else { + ToolsProject::where('proyek_id', $projectId)->delete(); + ToolsProject::where('proyek_id', $subproyekId)->delete(); + return response()->json(['status' => 'success', 'message' => 'Tools Project Successfull updated', 'code' => 200]); + } + } } diff --git a/app/Http/Controllers/API/ToolsRequestController.php b/app/Http/Controllers/API/ToolsRequestController.php index 512919d..ad11224 100644 --- a/app/Http/Controllers/API/ToolsRequestController.php +++ b/app/Http/Controllers/API/ToolsRequestController.php @@ -4,8 +4,167 @@ namespace App\Http\Controllers\API; use App\Http\Controllers\Controller; use Illuminate\Http\Request; +use App\Models\{ToolsResource, ToolsRequest}; +use Illuminate\Support\Facades\Validator; class ToolsRequestController extends Controller { - // + public function add(Request $request) + { + $validator = Validator::make($request->all(), [ + 'asset_type' => 'required|string', + 'asset_name' => 'required|string', + 'required_date' => 'required', + 'qty' => 'required', + 'uom' => 'required|string', + 'qty_received' => 'nullable|string', + 'description' => 'required', + 'status' => 'nullable|string', + 'proyek_id' => 'nullable|integer', + 'ownership_status' => 'nullable|string|max:100', + 'ownership_name' => 'nullable|string', + 'created_by' => 'nullable|string|max:80', + 'updated_by' => 'nullable|string|max:80', + ]); + if ($validator->fails()) { + return response()->json(['status' => 'failed', 'message' => 'Tools Request Project failed created', 'code' => 400]); + } + $validated = $validator->validated(); + + $validated['status'] = "fot"; + $validated['created_by'] = $this->currentName; + + $result = ToolsRequest::create($validated); + if ($result) { + return response()->json(['status' => 'success', 'message' => 'Tools Request Project successfull created', 'code' => 200]); + } else { + return response()->json(['status' => 'failed', 'message' => 'Tools Request Project failed created', 'code' => 400]); + } + } + + public function update(Request $request, $id) + { + + $validator = Validator::make($request->all(), [ + 'asset_type' => 'required|string', + 'asset_name' => 'required|string', + 'required_date' => 'required', + 'qty' => 'required', + 'uom' => 'required|string', + 'qty_received' => 'nullable|string', + 'description' => 'required', + 'status' => 'nullable|string', + 'proyek_id' => 'nullable|integer', + 'ownership_status' => 'nullable|string|max:100', + 'ownership_name' => 'nullable|string', + 'created_by' => 'nullable|string|max:80', + 'updated_by' => 'nullable|string|max:80', + ]); + if ($validator->fails()) { + return response()->json(['status' => 'failed', 'message' => 'add data material resource failed!', 'code' => 400], 400); + } + $validated = $validator->validated(); + if (empty($id)) { + return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); + die(); + } + if (!isset($validated['status'])) { + return response()->json(['status' => 'failed', 'message' => 'status is required!', 'code' => 400], 400); + die(); + } + $data = ToolsRequest::find($id); + + if ($data) : + if ($validated['status'] === "receipt to warehouse") { + + $dataT = ToolsResource::where('name', $data['asset_name'])->first(); + if ($dataT) { + $result = $data->update($validated); + $payloadMQty = $dataT['qty'] + $data['qty_received']; + $resultUpdateM = ToolsResource::where('id', $dataT['id'])->update(['qty' => $payloadMQty]); + return response()->json(['status' => 'success', 'message' => 'request material successfully updated!', 'code' => 200], 200); + } else { + $result = $data->update($validated); + $dataPayloadM = array( + "name" => $validated['asset_name'], + "uom" => $validated['uom'], + "unit_price" => 0, + "description" => $validated['description'], + "qty" => $data->qty_received, + "asset_type" => $validated['asset_type'], + "created_by" => $this->currentName + ); + $result = ToolsResource::create($dataPayloadM); + if ($result) { + return response()->json(['status' => 'success', 'message' => 'add data material resource successfully!', 'code' => 200], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'add data material resource failed!', 'code' => 400], 400); + } + } + } elseif ($validated['status'] === "receipt to site") { + + $dataT = ToolsResource::where('name', $data['asset_name'])->first(); + if ($dataT) { + $result = $data->update($validated); + $payloadMQty = $dataT['qty'] - $data['qty_received']; + if ($payloadMQty < 0) { + return response()->json(['status' => 'failed', 'message' => 'update status receipt to site request material resource failed, because material is not exist in warehouse!', 'code' => 400], 400); + die(); + } + $resultUpdateM = ToolsResource::where('id', $dataT['id'])->update(['qty' => $payloadMQty]); + return response()->json(['status' => 'success', 'message' => 'request material status receipt to site successfully updated!', 'code' => 200], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'update status receipt to site request material resource failed, because tools is not exist in warehouse!', 'code' => 400], 400); + } + } else { + $resultUpdate = $data->update($validated); + if ($resultUpdate) { + return response()->json(['status' => 'success', 'message' => 'request material successfully updated!', 'code' => 200], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'request material failed updated!', 'code' => 400], 400); + } + } + else : + return response()->json(['status' => 'failed', 'message' => 'data request material not found!', 'code' => 400], 400); + endif; + } + + public function delete($id) + { + $data = ToolsRequest::find($id); + + if ($data) { + $delete = $data->delete(); + if ($delete) { + return response()->json(['status' => 'success', 'message' => 'Tools Request Project successfully deleted!', 'code' => 200], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'Tools Request Project failed deleted!', 'code' => 400], 400); + } + } else { + return response()->json(['status' => 'failed', 'message' => 'data Tools Request Project not found!', 'code' => 400], 400); + } + } + + public function search(Request $request) + { + $payload = $request->all(); + $dataBuilder = $this->setUpPayload($payload, 'm_req_tools'); + $builder = $dataBuilder['builder']; + $countBuilder = $dataBuilder['count']; + $dataGet = $builder->get(); + $totalRecord = $countBuilder->count(); + return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => $totalRecord], 200); + } + + public function list() + { + $data = ToolsRequest::all(); + $countData = $data->count(); + + if ($data) { + return response()->json(['status' => 'success', 'code' => 200, 'data' => $data, 'totalRecord' => $countData], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'failed get list tools request, please try again later!', 'code' => 400], 400); + } + } } diff --git a/app/Http/Controllers/API/ToolsResourceController.php b/app/Http/Controllers/API/ToolsResourceController.php index c1808e6..dcb2db1 100644 --- a/app/Http/Controllers/API/ToolsResourceController.php +++ b/app/Http/Controllers/API/ToolsResourceController.php @@ -4,8 +4,137 @@ namespace App\Http\Controllers\API; use App\Http\Controllers\Controller; use Illuminate\Http\Request; +use App\Models\ToolsResource; +use Illuminate\Support\Facades\Validator; class ToolsResourceController extends Controller { - // + public function add(Request $request) + { + + $validator = Validator::make($request->all(), [ + 'name' => 'required|string|max:50', + 'description' => 'nullable', + 'qty' => 'required', + 'asset_type' => 'nullable|string', + 'asset_type' => 'required|string', + 'uom' => 'required|string|max:200', + 'created_by' => 'nullable|string|max:80', + 'updated_by' => 'nullable|string|max:80', + ]); + if ($validator->fails()) { + return response()->json(['status' => 'failed', 'message' => 'add data tools resource failed!', 'code' => 400], 400); + } + $validated = $validator->validated(); + + $validated['created_by'] = $this->currentName; + + $result = ToolsResource::create($validated); + + if ($result) { + return response()->json(['status' => 'success', 'message' => 'add data tools resource successfully!', 'code' => 200], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'add data tools resource failed!', 'code' => 400], 400); + } + } + + public function edit($id) + { + if (empty($id)) { + return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); + } + + $result = ToolsResource::find($id); + + if ($result) { + return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'failed get data tools resource, please try again later!', 'code' => 400], 400); + } + } + + public function update(Request $request, $id) + { + if (empty($id)) { + return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); + } + + $data = ToolsResource::find($id); + $validator = Validator::make($request->all(), [ + 'name' => 'required|string|max:50', + 'description' => 'nullable', + 'qty' => 'required', + 'asset_type' => 'nullable|string', + 'asset_type' => 'required|string', + 'uom' => 'required|string|max:200', + 'created_by' => 'nullable|string|max:80', + 'updated_by' => 'nullable|string|max:80', + ]); + if ($validator->fails()) { + return response()->json(['status' => 'failed', 'message' => 'add data tools resource failed!', 'code' => 400], 400); + } + $validated = $validator->validated(); + + if ($data) { + $result = $data->update($validated); + if ($result) { + return response()->json(['status' => 'success', 'message' => 'data tools resource successfully updated!', 'code' => 200], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'data tools resource failed updated!', 'code' => 400], 400); + } + } else { + return response()->json(['status' => 'failed', 'message' => 'data tools resource not found!', 'code' => 400], 400); + } + } + + public function delete($id) + { + $data = ToolsResource::find($id); + + if ($data) { + $delete = $data->delete(); + if ($delete) { + return response()->json(['status' => 'success', 'message' => 'data tools resource successfully deleted!', 'code' => 200], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'data tools resource failed deleted!', 'code' => 400], 400); + } + } else { + return response()->json(['status' => 'failed', 'message' => 'data tools resource not found!', 'code' => 400], 400); + } + } + + public function search(Request $request) + { + $payload = $request->all(); + $dataBuilder = $this->setUpPayload($payload, 'm_tools_resource'); + $builder = $dataBuilder['builder']; + $countBuilder = $dataBuilder['count']; + $dataGet = $builder->get(); + $totalRecord = $countBuilder->count(); + return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => $totalRecord], 200); + } + + public function list() + { + $data = ToolsResource::all(); + $countData = $data->count(); + + if ($data) { + return response()->json(['status' => 'success', 'code' => 200, 'data' => $data, 'totalRecord' => $countData], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'failed get list material resource, please try again later!', 'code' => 400], 400); + } + } + + public function select(Request $request) + { + $search = $request->query('search'); + + if ($search && !empty($search)) { + $data = ToolsResource::where("name", 'like', '%' . $search . '%')->get(); + } else { + $data = ToolsResource::all(); + } + return response()->json($data); + } } diff --git a/app/Http/Controllers/API/UserProyekController.php b/app/Http/Controllers/API/UserProyekController.php index 1115662..b1d26c4 100644 --- a/app/Http/Controllers/API/UserProyekController.php +++ b/app/Http/Controllers/API/UserProyekController.php @@ -4,8 +4,51 @@ namespace App\Http\Controllers\API; use App\Http\Controllers\Controller; use Illuminate\Http\Request; +use App\Models\UserProject; class UserProyekController extends Controller { - // + public function __invoke(Request $request) + { + $projectId = $request->project_id; + $subproyekId = $request->subproyek_id; + $listUser = $request->user_id; + + if (!$projectId && !$subproyekId) { + return response()->json(['status' => 'failed', 'message' => 'Required proyek_id or subproyek id', 'code' => 400], 400); + } + + if (is_array($listUser) && count($listUser) > 0) { + $result = 0; + UserProject::where('proyek_id', $projectId)->delete(); + UserProject::where('proyek_id', $subproyekId)->delete(); + foreach ($listUser as $id) { + $data = [ + 'user_id' => (int)$id + ]; + + if ($projectId && $projectId != "" && (int)$projectId > 0) { + $data['proyek_id'] = $projectId; + } else if ($subproyekId && $subproyekId != "" && (int)$subproyekId > 0) { + $data['subproyek_id'] = $subproyekId; + } + + $insert = UserProject::create($data); + if ($insert) { + $result++; + } else { + $result--; + } + } + if ($result > 0) { + return response()->json(['status' => 'success', 'message' => 'User Project successfull updated', 'code' => 200], 200); + } else { + return response()->json(['status' => 'failed', 'message' => 'User Project failed updated', 'code' => 400], 400); + } + } else { + UserProject::where('proyek_id', $projectId)->delete(); + UserProject::where('proyek_id', $subproyekId)->delete(); + return response()->json(['status' => 'success', 'message' => 'User Project Successfull updated', 'code' => 200], 200); + } + } } diff --git a/app/Models/ActivityDokumen.php b/app/Models/ActivityDokumen.php index 86eb579..16b8403 100644 --- a/app/Models/ActivityDokumen.php +++ b/app/Models/ActivityDokumen.php @@ -6,12 +6,8 @@ use Illuminate\Database\Eloquent\Model; class ActivityDokumen extends Model { - protected $table = 'm_document_activity'; + protected $table = 'm_document_activity', $guarded = ['id']; const CREATED_AT = 'created_at'; const UPDATED_AT = 'updated_at'; - - protected $fillable = [ - 'file', 'description', 'activity_id', 'created_at', 'created_by', 'updated_at', 'updated_by' - ]; } diff --git a/app/Models/CommentActivity.php b/app/Models/CommentActivity.php index 36ad674..bfef283 100644 --- a/app/Models/CommentActivity.php +++ b/app/Models/CommentActivity.php @@ -6,17 +6,8 @@ use Illuminate\Database\Eloquent\Model; class CommentActivity extends Model { - protected $table = 'm_comment_activity'; + protected $table = 'm_comment_activity', $guarded = ['id']; const CREATED_AT = 'created_at'; const UPDATED_AT = 'updated_at'; - - protected $fillable = [ - 'activity_id', - 'comment', - 'created_at', - 'created_by', - 'updated_at', - 'updated_by' - ]; } diff --git a/app/Models/ConfigAlert.php b/app/Models/ConfigAlert.php index 0a2980e..010d6f9 100644 --- a/app/Models/ConfigAlert.php +++ b/app/Models/ConfigAlert.php @@ -6,12 +6,11 @@ use Illuminate\Database\Eloquent\Model; class ConfigAlert extends Model { - protected $table = 'config_alert'; + protected $table = 'config_alert', $guarded = ['id']; + protected $casts = [ + 'id' => 'integer' + ]; const CREATED_AT = 'created_at'; const UPDATED_AT = 'updated_at'; - - protected $fillable = [ - 'nama', 'keterangan', 'created_at', 'created_by', 'updated_at', 'updated_by' - ]; } diff --git a/app/Models/ConfigAlertUser.php b/app/Models/ConfigAlertUser.php index b791716..def67ba 100644 --- a/app/Models/ConfigAlertUser.php +++ b/app/Models/ConfigAlertUser.php @@ -6,12 +6,12 @@ use Illuminate\Database\Eloquent\Model; class ConfigAlertUser extends Model { - protected $table = 'config_alert_to_user'; - + protected $table = 'config_alert_to_user', $guarded = ['id']; + protected $casts = [ + 'id' => 'integer', + 'user_id' => 'integer', + 'config_alert_id' => 'integer' + ]; const CREATED_AT = 'created_at'; const UPDATED_AT = 'updated_at'; - - protected $fillable = [ - 'user_id', 'config_alert_id', 'created_at', 'created_by', 'updated_at', 'updated_by' - ]; } diff --git a/app/Models/Divisi.php b/app/Models/Divisi.php index 52012ae..9ec2081 100644 --- a/app/Models/Divisi.php +++ b/app/Models/Divisi.php @@ -6,36 +6,31 @@ use Illuminate\Database\Eloquent\Model; class Divisi extends Model { - protected $table = 'm_divisi'; - + protected $table = 'm_divisi', $guarded = ['id']; + protected $with = ['parent', 'children']; + protected $casts = [ + 'id' => 'integer', + 'parent' => 'integer' + ]; const CREATED_AT = 'created_at'; const UPDATED_AT = 'updated_at'; - protected $fillable = [ - 'name', - 'parent', - 'description', - 'created_at', - 'created_by', - 'updated_at', - 'updated_by' - ]; - - public static function boot() { - parent::boot(); + public static function boot() + { + parent::boot(); - static::deleting(function($data) { - $data->children()->delete(); - }); - } + static::deleting(function ($data) { + $data->children()->delete(); + }); + } - public function parent() - { - return $this->belongsTo('App\Models\Divisi','parent')->where('parent', null)->with('parent'); - } + public function parent() + { + return $this->belongsTo(self::class, 'parent')->where('parent', null); + } - public function children() - { - return $this->hasMany('App\Models\Divisi','parent')->with('children'); - } + public function children() + { + return $this->hasMany(self::class, 'parent'); + } } diff --git a/app/Models/DokumenProject.php b/app/Models/DokumenProject.php index 174c103..ad68133 100644 --- a/app/Models/DokumenProject.php +++ b/app/Models/DokumenProject.php @@ -6,12 +6,8 @@ use Illuminate\Database\Eloquent\Model; class DokumenProject extends Model { - protected $table = 'document_project'; + protected $table = 'document_project', $guarded = ['id']; const CREATED_AT = 'created_at'; const UPDATED_AT = 'updated_at'; - - protected $fillable = [ - 'file', 'type_dokumen', 'ref_id', 'created_at', 'created_by', 'updated_at', 'updated_by' - ]; } diff --git a/app/Models/Holiday.php b/app/Models/Holiday.php index 0df7577..46b7ba9 100644 --- a/app/Models/Holiday.php +++ b/app/Models/Holiday.php @@ -6,12 +6,8 @@ use Illuminate\Database\Eloquent\Model; class Holiday extends Model { - protected $table = 'm_holidays'; + protected $table = 'm_holidays', $guarded = ['id']; const CREATED_AT = 'created_at'; const UPDATED_AT = 'updated_at'; - - protected $fillable = [ - 'proyek_id', 'duration', 'version_gantt_id', 'date', 'description', 'created_at', 'created_by', 'updated_at', 'updated_by' - ]; } diff --git a/app/Models/HumanResource.php b/app/Models/HumanResource.php index 18adae0..8ff4761 100644 --- a/app/Models/HumanResource.php +++ b/app/Models/HumanResource.php @@ -6,33 +6,12 @@ use Illuminate\Database\Eloquent\Model; class HumanResource extends Model { - protected $table = 'm_users'; - + protected $table = 'm_users', $guarded = ['id']; + protected $casts = [ + 'id' => 'integer', + 'role_id' => 'integer', + 'divisi_id' => 'integer' + ]; const CREATED_AT = 'created_at'; const UPDATED_AT = 'updated_at'; - - protected $fillable = [ - 'role_id', - 'username', - 'password', - 'session_login', - 'name', - 'phone_number', - 'email', - 'address', - 'fcm_token', - 'gender', - 'birth_place', - 'birth_date', - 'blood_type', - 'ktp_number', - 'employee_type', - 'status_resource', - 'created_at', - 'created_by', - 'updated_at', - 'updated_by', - 'divisi_id', - 'status_boundary' - ]; } diff --git a/app/Models/Image.php b/app/Models/Image.php index e48e009..10b2a07 100644 --- a/app/Models/Image.php +++ b/app/Models/Image.php @@ -6,12 +6,8 @@ use Illuminate\Database\Eloquent\Model; class Image extends Model { - protected $table = 'm_image'; + protected $table = 'm_image', $guarded = ['id']; const CREATED_AT = 'created_at'; const UPDATED_AT = 'updated_at'; - - protected $fillable = [ - 'image', 'ref_id', 'category', 'created_at', 'created_by', 'updated_at', 'updated_by' - ]; } diff --git a/app/Models/Link.php b/app/Models/Link.php index e9a8ba5..24e9a32 100644 --- a/app/Models/Link.php +++ b/app/Models/Link.php @@ -6,13 +6,8 @@ use Illuminate\Database\Eloquent\Model; class Link extends Model { - protected $table = 'm_activity_link'; + protected $table = 'm_activity_link', $guarded = ['id']; const CREATED_AT = 'created_at'; const UPDATED_AT = 'updated_at'; - - protected $fillable = [ - 's_activity_id', 't_activity_id', 'type_link', 'code_link', 'version_gantt_id', 'lag', - 'created_at', 'created_by', 'updated_at', 'updated_by' - ]; } diff --git a/app/Models/MaterialProject.php b/app/Models/MaterialProject.php index cd31481..3a8e909 100644 --- a/app/Models/MaterialProject.php +++ b/app/Models/MaterialProject.php @@ -6,12 +6,11 @@ use Illuminate\Database\Eloquent\Model; class MaterialProject extends Model { - protected $table = 'material_to_proyek'; - + protected $table = 'material_to_proyek', $guarded = ['id']; + protected $casts = [ + 'id' => 'integer', + 'proyek_id' => 'integer' + ]; const CREATED_AT = 'created_at'; const UPDATED_AT = 'updated_at'; - - protected $fillable = [ - 'material_resource_id', 'proyek_id', 'subproyek_id', 'created_at', 'created_by', 'updated_at', 'updated_by' - ]; } diff --git a/app/Models/MaterialResource.php b/app/Models/MaterialResource.php index 7a8f3ae..030e535 100644 --- a/app/Models/MaterialResource.php +++ b/app/Models/MaterialResource.php @@ -6,12 +6,13 @@ use Illuminate\Database\Eloquent\Model; class MaterialResource extends Model { - protected $table = 'm_material_resource'; + protected $table = 'm_material_resource', $guarded = ['id']; + protected $casts = [ + 'id' => 'integer', + 'unit_price' => 'integer', + 'qty' => 'float' + ]; const CREATED_AT = 'created_at'; const UPDATED_AT = 'updated_at'; - - protected $fillable = [ - 'name', 'uom', 'unit_price', 'description', 'status', 'qty', 'created_at', 'created_by', 'updated_at', 'updated_by' - ]; } diff --git a/app/Models/OfficeHours.php b/app/Models/OfficeHours.php index bb7e12b..22e2544 100644 --- a/app/Models/OfficeHours.php +++ b/app/Models/OfficeHours.php @@ -6,15 +6,8 @@ use Illuminate\Database\Eloquent\Model; class OfficeHours extends Model { - protected $table = 'm_office_hours'; + protected $table = 'm_office_hours', $guarded = ['id']; const CREATED_AT = 'created_at'; const UPDATED_AT = 'updated_at'; - - protected $fillable = [ - 'proyek_id', 'monday_start', 'monday_end', 'tuesday_start', 'tuesday_end', - 'wednesday_start', 'wednesday_end', 'thursday_start', 'thursday_end', - 'friday_start', 'friday_end', 'saturday_start', 'saturday_end', 'sunday_start', 'sunday_end', - 'created_at', 'created_by', 'updated_at', 'updated_by' - ]; } diff --git a/app/Models/ProjectApproval.php b/app/Models/ProjectApproval.php index ec306d6..5d1b994 100644 --- a/app/Models/ProjectApproval.php +++ b/app/Models/ProjectApproval.php @@ -6,19 +6,8 @@ use Illuminate\Database\Eloquent\Model; class ProjectApproval extends Model { - protected $table = 'project_approval'; + protected $table = 'project_approval', $guarded = ['id']; const CREATED_AT = 'created_at'; const UPDATED_AT = 'updated_at'; - - protected $fillable = [ - 'proyek_id', - 'tittle', - 'name', - 'date_approval', - 'created_at', - 'created_by', - 'updated_at', - 'updated_by' - ]; } diff --git a/app/Models/ProjectCharter.php b/app/Models/ProjectCharter.php index d999f85..ea2d968 100644 --- a/app/Models/ProjectCharter.php +++ b/app/Models/ProjectCharter.php @@ -6,26 +6,13 @@ use Illuminate\Database\Eloquent\Model; class ProjectCharter extends Model { - protected $table = 'project_charter'; + protected $table = 'project_charter', $guarded = ['id']; - const CREATED_AT = 'created_at'; - const UPDATED_AT = 'updated_at'; - - protected $fillable = [ - 'proyek_id', - 'description', - 'objectives', - 'project_is_considered_successful', - 'participants', - 'available_resources', - 'milestones', - 'potential_risks', - 'approval', - 'created_at', - 'created_by', - 'updated_at', - 'updated_by' + protected $casts = [ + 'id' => 'integer', + 'proyek_id' => 'integer' ]; - + const CREATED_AT = 'created_at'; + const UPDATED_AT = 'updated_at'; } diff --git a/app/Models/ProjectMileStone.php b/app/Models/ProjectMileStone.php index aedf47c..6d5adbf 100644 --- a/app/Models/ProjectMileStone.php +++ b/app/Models/ProjectMileStone.php @@ -6,19 +6,8 @@ use Illuminate\Database\Eloquent\Model; class ProjectMileStone extends Model { - protected $table = 'project_milestone'; + protected $table = 'project_milestone', $guarded = ['id']; const CREATED_AT = 'created_at'; const UPDATED_AT = 'updated_at'; - - protected $fillable = [ - 'proyek_id', - 'status', - 'due_date', - 'deadline', - 'created_at', - 'created_by', - 'updated_at', - 'updated_by' - ]; } diff --git a/app/Models/ProjectParticipants.php b/app/Models/ProjectParticipants.php index 00d9f16..c79c51f 100644 --- a/app/Models/ProjectParticipants.php +++ b/app/Models/ProjectParticipants.php @@ -6,18 +6,8 @@ use Illuminate\Database\Eloquent\Model; class ProjectParticipants extends Model { - protected $table = 'project_participants'; + protected $table = 'project_participants', $guarded = ['id']; const CREATED_AT = 'created_at'; const UPDATED_AT = 'updated_at'; - - protected $fillable = [ - 'proyek_id', - 'tittle', - 'name', - 'created_at', - 'created_by', - 'updated_at', - 'updated_by' - ]; } diff --git a/app/Models/ProjectPhase.php b/app/Models/ProjectPhase.php index 1a82a81..4385743 100644 --- a/app/Models/ProjectPhase.php +++ b/app/Models/ProjectPhase.php @@ -6,12 +6,12 @@ use Illuminate\Database\Eloquent\Model; class ProjectPhase extends Model { - protected $table = 'm_proyek_phase'; + protected $table = 'm_proyek_phase', $guarded = ['id']; + protected $casts = [ + 'id' => 'integer', + 'order' => 'integer' + ]; const CREATED_AT = 'created_at'; const UPDATED_AT = 'updated_at'; - - protected $fillable = [ - 'name', 'color', 'order', 'created_at', 'created_by', 'updated_at', 'updated_by' - ]; } diff --git a/app/Models/ProjectRole.php b/app/Models/ProjectRole.php index 2d3eb92..dbc8740 100644 --- a/app/Models/ProjectRole.php +++ b/app/Models/ProjectRole.php @@ -6,12 +6,10 @@ use Illuminate\Database\Eloquent\Model; class ProjectRole extends Model { - protected $table = 'm_role_proyek'; - + protected $table = 'm_role_proyek', $guarded = ['id']; + protected $casts = [ + 'id' => 'integer' + ]; const CREATED_AT = 'created_at'; const UPDATED_AT = 'updated_at'; - - protected $fillable = [ - 'name', 'description', 'created_at', 'created_by', 'updated_at', 'updated_by' - ]; } diff --git a/app/Models/ProjectType.php b/app/Models/ProjectType.php index a3cf118..10e87a9 100644 --- a/app/Models/ProjectType.php +++ b/app/Models/ProjectType.php @@ -6,12 +6,12 @@ use Illuminate\Database\Eloquent\Model; class ProjectType extends Model { - protected $table = 'm_type_proyek'; + protected $table = 'm_type_proyek', $guarded = ['id']; + protected $casts = [ + 'id' => 'integer', + 'company_id' => 'integer' + ]; const CREATED_AT = 'created_at'; const UPDATED_AT = 'updated_at'; - - protected $fillable = [ - 'name', 'description', 'created_at', 'created_by', 'updated_at', 'updated_by' - ]; } diff --git a/app/Models/ReportActivity.php b/app/Models/ReportActivity.php index c899c00..c263680 100644 --- a/app/Models/ReportActivity.php +++ b/app/Models/ReportActivity.php @@ -6,22 +6,8 @@ use Illuminate\Database\Eloquent\Model; class ReportActivity extends Model { - protected $table = 'report_activity'; + protected $table = 'report_activity', $guarded = ['id']; const CREATED_AT = 'created_at'; const UPDATED_AT = 'updated_at'; - - protected $fillable = [ - 'activity_id', - 'user_id', - 'report_date', - 'job_count_report', - 'description', - 'lat', - 'lon', - 'created_at', - 'created_by', - 'updated_at', - 'updated_by' - ]; } diff --git a/app/Models/ReportActivityMaterial.php b/app/Models/ReportActivityMaterial.php index 39849d5..4958cd4 100644 --- a/app/Models/ReportActivityMaterial.php +++ b/app/Models/ReportActivityMaterial.php @@ -9,65 +9,59 @@ use Carbon\Carbon; class ReportActivityMaterial extends Model { - protected $table = 'report_activity_material'; - - const CREATED_AT = 'created_at'; - const UPDATED_AT = 'updated_at'; - - protected $fillable = [ - 'activity_id', 'user_id', 'qty', 'lat', 'lon','assign_material_id', - 'report_date', 'description', 'created_at', 'created_by', 'updated_at', 'updated_by' - ]; - - public function getReportDateAttribute($value) - { - return Carbon::createFromTimestamp(strtotime($value)) - ->timezone(env('APP_TIMEZONE')) - ->toDateTimeString(); - } - - public static function boot() { - parent::boot(); - - static::created(function($data) { - $activity = Activity::find($data->activity_id); - $assignedMaterial = AssignMaterial::find($data->assign_material_id); - - $biayaActual = $activity->biaya_actual + floatval($assignedMaterial->budget) * floatval($data->qty); - - $dataPlan = AssignMaterial::where('activity_id', $activity->id)->get(); - if($dataPlan[0]->status_activity == 'done'){ - $percentage = 100; - } else { - $totalPlan = $dataPlan->sum('qty_planning'); - $totalVolumeActual = ReportActivityMaterial::where('activity_id', '=', $activity->id)->sum("qty"); - $percentage = ($totalVolumeActual * 100) / $totalPlan; - $percentage = $percentage >= config('app.max_percentage_not_done') ? config('app.max_percentage_not_done') : $percentage; - } - - $activity->update([ - "persentase_progress" => $percentage, - "biaya_actual" => $biayaActual, - ]); - - $activity->save(); - }); - - static::deleted(function($data) { - - $activity = Activity::find($data->activity_id); - $assignedMaterial = AssignMaterial::find($data->assign_material_id); - - $activity->biaya_actual -= floatval($assignedMaterial->budget) * floatval($data->qty); - - $dataPlan = AssignMaterial::where('activity_id', $activity->id)->get(); - $totalPlan = $dataPlan->sum('qty_planning'); - $totalVolumeActual = ReportActivityMaterial::where('activity_id', '=', $activity->id)->sum("qty"); - $percentage = ($totalVolumeActual * 100) / $totalPlan; - $activity->persentase_progress = $percentage >= config('app.max_percentage_not_done') ? config('app.max_percentage_not_done') : $percentage; - $activity->save(); - - }); - - } + protected $table = 'report_activity_material', $guarded = ['id']; + + const CREATED_AT = 'created_at'; + const UPDATED_AT = 'updated_at'; + + public function getReportDateAttribute($value) + { + return Carbon::createFromTimestamp(strtotime($value)) + ->timezone(env('APP_TIMEZONE')) + ->toDateTimeString(); + } + + public static function boot() + { + parent::boot(); + + static::created(function ($data) { + $activity = Activity::find($data->activity_id); + $assignedMaterial = AssignMaterial::find($data->assign_material_id); + + $biayaActual = $activity->biaya_actual + floatval($assignedMaterial->budget) * floatval($data->qty); + + $dataPlan = AssignMaterial::where('activity_id', $activity->id)->get(); + if ($dataPlan[0]->status_activity == 'done') { + $percentage = 100; + } else { + $totalPlan = $dataPlan->sum('qty_planning'); + $totalVolumeActual = ReportActivityMaterial::where('activity_id', '=', $activity->id)->sum("qty"); + $percentage = ($totalVolumeActual * 100) / $totalPlan; + $percentage = $percentage >= config('app.max_percentage_not_done') ? config('app.max_percentage_not_done') : $percentage; + } + + $activity->update([ + "persentase_progress" => $percentage, + "biaya_actual" => $biayaActual, + ]); + + $activity->save(); + }); + + static::deleted(function ($data) { + + $activity = Activity::find($data->activity_id); + $assignedMaterial = AssignMaterial::find($data->assign_material_id); + + $activity->biaya_actual -= floatval($assignedMaterial->budget) * floatval($data->qty); + + $dataPlan = AssignMaterial::where('activity_id', $activity->id)->get(); + $totalPlan = $dataPlan->sum('qty_planning'); + $totalVolumeActual = ReportActivityMaterial::where('activity_id', '=', $activity->id)->sum("qty"); + $percentage = ($totalVolumeActual * 100) / $totalPlan; + $activity->persentase_progress = $percentage >= config('app.max_percentage_not_done') ? config('app.max_percentage_not_done') : $percentage; + $activity->save(); + }); + } } diff --git a/app/Models/RequestMaterial.php b/app/Models/RequestMaterial.php index 9154eb7..a5120fe 100644 --- a/app/Models/RequestMaterial.php +++ b/app/Models/RequestMaterial.php @@ -7,62 +7,44 @@ use Carbon\Carbon; class RequestMaterial extends Model { - protected $table = 'm_req_material'; + protected $table = 'm_req_material', $guarded = ['id']; const CREATED_AT = 'created_at'; const UPDATED_AT = 'updated_at'; - protected $casts = [ + protected $casts = [ 'id' => 'integer', - 'price' => 'string', + 'proyek_id' => 'integer', + 'price' => 'float', + 'qty' => 'float', + 'qty_received' => 'float' ]; - protected $fillable = [ - 'description', - 'required_date', - 'qty', - 'uom', - 'qty_received', - 'fom_date', - 'pr_date', - 'po_date', - 'received_date', - 'delivery_date', - 'status', - 'proyek_id', - 'created_at', - 'created_by', - 'updated_at', - 'updated_by', - 'price' - ]; - - public function getRequiredDateAttribute($value) - { - return Carbon::createFromTimestamp(strtotime($value)) - ->timezone(env('APP_TIMEZONE')) - ->toDateTimeString(); - } - - public function getFomDateAttribute($value) - { - return Carbon::createFromTimestamp(strtotime($value)) - ->timezone(env('APP_TIMEZONE')) - ->toDateTimeString(); - } - - public function getPrDateAttribute($value) - { - return Carbon::createFromTimestamp(strtotime($value)) - ->timezone(env('APP_TIMEZONE')) - ->toDateTimeString(); - } - - public function getPoDateAttribute($value) - { - return Carbon::createFromTimestamp(strtotime($value)) - ->timezone(env('APP_TIMEZONE')) - ->toDateTimeString(); - } - + public function getRequiredDateAttribute($value) + { + return Carbon::createFromTimestamp(strtotime($value)) + ->timezone(env('APP_TIMEZONE')) + ->toDateTimeString(); + } + + public function getFomDateAttribute($value) + { + return Carbon::createFromTimestamp(strtotime($value)) + ->timezone(env('APP_TIMEZONE')) + ->toDateTimeString(); + } + + public function getPrDateAttribute($value) + { + return Carbon::createFromTimestamp(strtotime($value)) + ->timezone(env('APP_TIMEZONE')) + ->toDateTimeString(); + } + + public function getPoDateAttribute($value) + { + return Carbon::createFromTimestamp(strtotime($value)) + ->timezone(env('APP_TIMEZONE')) + ->toDateTimeString(); + } } diff --git a/app/Models/ShowHideColumn.php b/app/Models/ShowHideColumn.php index 4553bc7..5cfc40d 100644 --- a/app/Models/ShowHideColumn.php +++ b/app/Models/ShowHideColumn.php @@ -6,19 +6,8 @@ use Illuminate\Database\Eloquent\Model; class ShowHideColumn extends Model { - protected $table = 'm_gantt_show_hide'; + protected $table = 'm_gantt_show_hide', $guarded = ['id']; const CREATED_AT = 'created_at'; const UPDATED_AT = 'updated_at'; - - protected $fillable = [ - 'user_id', - 'version_gantt_id', - 'column_name', - 'show', - 'created_at', - 'created_by', - 'updated_at', - 'updated_by' - ]; } diff --git a/app/Models/ToolsProject.php b/app/Models/ToolsProject.php index 392cd94..81d2b3d 100644 --- a/app/Models/ToolsProject.php +++ b/app/Models/ToolsProject.php @@ -6,12 +6,11 @@ use Illuminate\Database\Eloquent\Model; class ToolsProject extends Model { - protected $table = 'tools_to_proyek'; - + protected $table = 'tools_to_proyek', $guarded = ['id']; + protected $casts = [ + 'id' => 'integer', + 'proyek_id' => 'integer' + ]; const CREATED_AT = 'created_at'; const UPDATED_AT = 'updated_at'; - - protected $fillable = [ - 'tools_id', 'proyek_id', 'subproyek_id', 'created_at', 'created_by', 'updated_at', 'updated_by' - ]; } diff --git a/app/Models/ToolsRequest.php b/app/Models/ToolsRequest.php index 0b0a2c9..e9c04b7 100644 --- a/app/Models/ToolsRequest.php +++ b/app/Models/ToolsRequest.php @@ -6,26 +6,12 @@ use Illuminate\Database\Eloquent\Model; class ToolsRequest extends Model { - protected $table = 'm_req_tools'; - + protected $table = 'm_req_tools', $guarded = ['id']; + protected $casts = [ + 'id' => 'integer', + 'proyek_id' => 'integer', + 'qty_received' => 'float', + ]; const CREATED_AT = 'created_at'; const UPDATED_AT = 'updated_at'; - - protected $fillable = [ - 'asset_type', - 'asset_name', - 'required_date', - 'qty', - 'uom', - 'qty_received', - 'description', - 'status', - 'proyek_id', - "ownership_status", - "ownership_name", - 'created_at', - 'created_by', - 'updated_at', - 'updated_by' - ]; } diff --git a/app/Models/ToolsResource.php b/app/Models/ToolsResource.php index 43ffe69..f52f036 100644 --- a/app/Models/ToolsResource.php +++ b/app/Models/ToolsResource.php @@ -6,12 +6,11 @@ use Illuminate\Database\Eloquent\Model; class ToolsResource extends Model { - protected $table = 'm_tools_resource'; - + protected $table = 'm_tools_resource', $guarded = ['id']; + protected $casts = [ + 'id' => 'integer', + 'qty' => 'float' + ]; const CREATED_AT = 'created_at'; const UPDATED_AT = 'updated_at'; - - protected $fillable = [ - 'name', 'description', 'qty', 'asset_type', 'uom', 'created_at', 'created_by', 'updated_at', 'updated_by' - ]; } diff --git a/app/Models/UserProject.php b/app/Models/UserProject.php index 6314a2c..ea0bb89 100644 --- a/app/Models/UserProject.php +++ b/app/Models/UserProject.php @@ -6,12 +6,12 @@ use Illuminate\Database\Eloquent\Model; class UserProject extends Model { - protected $table = 'user_to_proyek'; + protected $table = 'user_to_proyek', $guarded = ['id']; + protected $casts = [ + 'id' => 'integer', + 'proyek_id' => 'integer' + ]; const CREATED_AT = 'created_at'; const UPDATED_AT = 'updated_at'; - - protected $fillable = [ - 'user_id', 'proyek_id', 'subproyek_id', 'created_at', 'created_by', 'updated_at', 'updated_by' - ]; } diff --git a/app/Models/UserToProyek.php b/app/Models/UserToProyek.php index 613f620..5394eb2 100644 --- a/app/Models/UserToProyek.php +++ b/app/Models/UserToProyek.php @@ -6,14 +6,8 @@ use Illuminate\Database\Eloquent\Model; class UserToProyek extends Model { - protected $table = 'assign_hr_to_proyek'; + protected $table = 'assign_hr_to_proyek', $guarded = ['id']; const CREATED_AT = 'created_at'; const UPDATED_AT = 'updated_at'; - - protected $fillable = [ - 'user_id', 'proyek_id', 'rbs', 'project_role', 'group_r', 'max_used', 'standart_rate', - 'uom_standart_rate', 'overtime_rate', 'uom_overtime_rate', 'cost_per_used', 'accrue_at', - 'base_calender', 'created_at', 'created_by', 'updated_at', 'updated_by' - ]; } diff --git a/app/Models/VersionGantt.php b/app/Models/VersionGantt.php index b6e9254..eb4f51b 100644 --- a/app/Models/VersionGantt.php +++ b/app/Models/VersionGantt.php @@ -9,69 +9,53 @@ use DateTime; class VersionGantt extends Model { - protected $table = 'm_version_gantt'; + protected $table = 'm_version_gantt', $guarded = ['id']; const CREATED_AT = 'created_at'; const UPDATED_AT = 'updated_at'; - protected $fillable = [ - 'name_version', - 'description', - 'date_base_line', - 'proyek_id', - 'config_dayoff', - 'auto_schedule', - 'calculation_type', - 'committed_cost', - 'cost_to_complete', - 'progress', - 'bobot', - 'hierarchy_ftth_id', - 'created_at', - 'created_by', - 'updated_at', - 'updated_by' - ]; - - public static function boot() { - parent::boot(); - static::updated(function($data) { - $data->updateActDuration(); - }); - } + public static function boot() + { + parent::boot(); - public function updateActDuration(){ - $daysOff = explode(',', $this->config_dayoff); - if (in_array('0', $daysOff)) { - $key = array_search('0', $daysOff, false); - $daysOff[$key] = '7'; - } - $activities = Activity::where('version_gantt_id', $this->id)->get(); - foreach ($activities as $value) { - $exist = Link::where('t_activity_id', $value->id)->exists(); - $startDate = new DateTime($value->start_date); - $endDate = new DateTime($value->end_date); - $duration = $endDate->diff($startDate)->days + 1; - if ($exist) { - $duration--; + static::updated(function ($data) { + $data->updateActDuration(); + }); + } + + public function updateActDuration() + { + $daysOff = explode(',', $this->config_dayoff); + if (in_array('0', $daysOff)) { + $key = array_search('0', $daysOff, false); + $daysOff[$key] = '7'; } + $activities = Activity::where('version_gantt_id', $this->id)->get(); + foreach ($activities as $value) { + $exist = Link::where('t_activity_id', $value->id)->exists(); + $startDate = new DateTime($value->start_date); + $endDate = new DateTime($value->end_date); + $duration = $endDate->diff($startDate)->days + 1; + if ($exist) { + $duration--; + } - // Iterate through each day and subtract the days off - for ($i = 0; $i < $duration; $i++) { - $currentDate = clone $startDate; - $currentDate->modify("+$i day"); - - $currentDayOfWeek = $currentDate->format('N'); // Get the day of the week (1 - Monday, 7 - Sunday) - - if (in_array($currentDayOfWeek, $daysOff)) { - $duration--; // Subtract one day from the duration for each day off + // Iterate through each day and subtract the days off + for ($i = 0; $i < $duration; $i++) { + $currentDate = clone $startDate; + $currentDate->modify("+$i day"); + + $currentDayOfWeek = $currentDate->format('N'); // Get the day of the week (1 - Monday, 7 - Sunday) + + if (in_array($currentDayOfWeek, $daysOff)) { + $duration--; // Subtract one day from the duration for each day off + } } + + // Update the activity duration + $value->duration = $duration; + $value->save(); } - - // Update the activity duration - $value->duration = $duration; - $value->save(); - } } } diff --git a/routes/api.php b/routes/api.php index cf96819..0764372 100644 --- a/routes/api.php +++ b/routes/api.php @@ -219,7 +219,7 @@ Route::middleware('cors')->group(function () { Route::get('/list', 'list'); }); // user-to-project Route - Route::post('/user-to-project/assign', [UserProyekController::class, 'assignUserProyek']); + Route::post('/user-to-project/assign', UserProyekController::class); // request-material Route Route::group(['prefix' => 'request-material', 'controller' => RequestMaterialController::class], function () { Route::post('/add', 'add');