Browse Source

updating models & controller method ke 1

master
wahyuun 1 year ago
parent
commit
e18e3c0f46
  1. 23
      app/Http/Controllers/API/ActivityDokumenController.php
  2. 112
      app/Http/Controllers/API/ConfigAlertController.php
  3. 97
      app/Http/Controllers/API/ConfigAlertUserController.php
  4. 88
      app/Http/Controllers/API/DashboardBoDController.php
  5. 121
      app/Http/Controllers/API/DivisiController.php
  6. 210
      app/Http/Controllers/API/HumanResourceController.php
  7. 45
      app/Http/Controllers/API/MaterialProjectController.php
  8. 132
      app/Http/Controllers/API/MaterialResourceController.php
  9. 16
      app/Http/Controllers/API/MenuController.php
  10. 84
      app/Http/Controllers/API/ProjectCharterController.php
  11. 232
      app/Http/Controllers/API/ProjectController.php
  12. 17
      app/Http/Controllers/API/ProjectDokumenController.php
  13. 107
      app/Http/Controllers/API/ProjectPhaseController.php
  14. 122
      app/Http/Controllers/API/ProjectRoleController.php
  15. 113
      app/Http/Controllers/API/ProjectTypeController.php
  16. 261
      app/Http/Controllers/API/RequestMaterialController.php
  17. 13
      app/Http/Controllers/API/RoleController.php
  18. 19
      app/Http/Controllers/API/RoleMenuController.php
  19. 45
      app/Http/Controllers/API/ToolsProjectController.php
  20. 161
      app/Http/Controllers/API/ToolsRequestController.php
  21. 131
      app/Http/Controllers/API/ToolsResourceController.php
  22. 45
      app/Http/Controllers/API/UserProyekController.php
  23. 6
      app/Models/ActivityDokumen.php
  24. 11
      app/Models/CommentActivity.php
  25. 9
      app/Models/ConfigAlert.php
  26. 12
      app/Models/ConfigAlertUser.php
  27. 47
      app/Models/Divisi.php
  28. 6
      app/Models/DokumenProject.php
  29. 6
      app/Models/Holiday.php
  30. 33
      app/Models/HumanResource.php
  31. 6
      app/Models/Image.php
  32. 7
      app/Models/Link.php
  33. 11
      app/Models/MaterialProject.php
  34. 11
      app/Models/MaterialResource.php
  35. 9
      app/Models/OfficeHours.php
  36. 13
      app/Models/ProjectApproval.php
  37. 25
      app/Models/ProjectCharter.php
  38. 13
      app/Models/ProjectMileStone.php
  39. 12
      app/Models/ProjectParticipants.php
  40. 10
      app/Models/ProjectPhase.php
  41. 10
      app/Models/ProjectRole.php
  42. 10
      app/Models/ProjectType.php
  43. 16
      app/Models/ReportActivity.php
  44. 116
      app/Models/ReportActivityMaterial.php
  45. 84
      app/Models/RequestMaterial.php
  46. 13
      app/Models/ShowHideColumn.php
  47. 11
      app/Models/ToolsProject.php
  48. 26
      app/Models/ToolsRequest.php
  49. 11
      app/Models/ToolsResource.php
  50. 10
      app/Models/UserProject.php
  51. 8
      app/Models/UserToProyek.php
  52. 92
      app/Models/VersionGantt.php
  53. 2
      routes/api.php

23
app/Http/Controllers/API/ActivityDokumenController.php

@ -11,7 +11,7 @@ class ActivityDokumenController extends Controller
public function dokumenByActivityId($id) 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); 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) 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); return response()->json(['status' => 'failed', 'message' => 'Id is required!', 'code' => 400], 400);
} }
@ -44,8 +44,12 @@ class ActivityDokumenController extends Controller
if (!$request->hasFile('dokumen')) { if (!$request->hasFile('dokumen')) {
return response()->json(['status' => 'failed', 'message' => 'file is required!', 'code' => 400], 400); 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'); $document = $request->file('dokumen');
$name = $document->getClientOriginalName(); $name = $document->getClientOriginalName();
@ -55,13 +59,12 @@ class ActivityDokumenController extends Controller
return response()->json(['status' => 'failed', 'message' => 'Upload failed!', 'code' => 500], 500); 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) { if (!$result) {
unlink($this->pathActivityDocument . $name); unlink($this->pathActivityDocument . $name);
@ -86,7 +89,7 @@ class ActivityDokumenController extends Controller
public function downloadDokumen($id) 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); return response()->json(['status' => 'failed', 'message' => 'Id is required!', 'code' => 400], 400);
} }

112
app/Http/Controllers/API/ConfigAlertController.php

@ -4,8 +4,118 @@ namespace App\Http\Controllers\API;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\ConfigAlert;
use Illuminate\Support\Facades\Validator;
class ConfigAlertController extends Controller 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);
}
}
} }

97
app/Http/Controllers/API/ConfigAlertUserController.php

@ -4,8 +4,103 @@ namespace App\Http\Controllers\API;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\ConfigAlertUser;
use Illuminate\Support\Facades\Validator;
class ConfigAlertUserController extends Controller 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);
}
}
} }

88
app/Http/Controllers/API/DashboardBoDController.php

@ -88,11 +88,11 @@ class DashboardBoDController extends Controller
$return = []; $return = [];
foreach ($projects as $project) { foreach ($projects as $project) {
$resp = null; $resp = null;
if ($project->kode_sortname != "") { if ($project['kode_sortname'] != "") {
$resp = $this->getInvoiceIntegration($project->kode_sortname); $resp = $this->getInvoiceIntegration($project['kode_sortname']);
array_push($return, [ array_push($return, [
'project' => $project->nama, 'project' => $project['nama'],
'project_code' => $project->kode_sortname, 'project_code' => $project['kode_sortname'],
'invoiced' => $resp->data->total_invoice_amount ?? 0, 'invoiced' => $resp->data->total_invoice_amount ?? 0,
'paid' => $resp->data->total_invoice_paid_amount ?? 0, 'paid' => $resp->data->total_invoice_paid_amount ?? 0,
'response' => $resp, 'response' => $resp,
@ -117,11 +117,11 @@ class DashboardBoDController extends Controller
$projects = Project::where('mulai_proyek', 'LIKE', '%' . $year . '%')->get(); $projects = Project::where('mulai_proyek', 'LIKE', '%' . $year . '%')->get();
foreach ($projects as $project) { foreach ($projects as $project) {
$project->scurve = MasterFunctionsHelper::getSCurve($project->id); $project['scurve'] = MasterFunctionsHelper::getSCurve($project['id']);
$selisihProgress = 0; $selisihProgress = 0;
if ($project->scurve && $project->scurve[0]) { if ($project['scurve'] && $project['scurve'][0]) {
$planningArray = $project->scurve[0]['data']['percentagePlan']; $planningArray = $project['scurve'][0]['data']['percentagePlan'];
$actualArray = $project->scurve[0]['data']['percentageReal']; $actualArray = $project['scurve'][0]['data']['percentageReal'];
$planningProgress = !empty($planningArray) ? $planningArray[count($planningArray) - 1] : 0; $planningProgress = !empty($planningArray) ? $planningArray[count($planningArray) - 1] : 0;
$actualProgress = !empty($actualArray) ? $actualArray[count($actualArray) - 1] : 0; $actualProgress = !empty($actualArray) ? $actualArray[count($actualArray) - 1] : 0;
} }
@ -151,14 +151,14 @@ class DashboardBoDController extends Controller
$scheduleData = new Collection(); $scheduleData = new Collection();
$behindSchedule = $warning = $onSchedule = 0; $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) { foreach ($projects as $project) {
$project->scurve = MasterFunctionsHelper::getSCurve($project->id); $project['scurve'] = MasterFunctionsHelper::getSCurve($project['id']);
if (@$project->scurve['difference'] > 0 && @$project->scurve['difference'] <= 5) if ($project['scurve']['difference'] > 0 && $project['scurve']['difference'] <= 5)
$warning++; $warning++;
elseif (@$project->scurve['difference'] > 5 && @$project->scurve['difference'] <= 100) elseif ($project['scurve']['difference'] > 5 && $project['scurve']['difference'] <= 100)
$behindSchedule++; $behindSchedule++;
elseif (@$project->scurve['difference'] == 0) elseif ($project['scurve']['difference'] == 0)
$onSchedule++; $onSchedule++;
} }
@ -179,9 +179,21 @@ class DashboardBoDController extends Controller
$year = $this->interpolateYear($year); $year = $this->interpolateYear($year);
return response()->json([ return response()->json([
'data' => [ 'data' => [
'overrun' => Project::where([['mulai_proyek', 'LIKE', '%' . $year . '%'], ['budget_health', 'overrun']])->count(), 'overrun' => Project::query()
'warning' => Project::where([['mulai_proyek', 'LIKE', '%' . $year . '%'], ['budget_health', 'warning']])->count(), ->where([
'on-budget' => Project::where([['mulai_proyek', 'LIKE', '%' . $year . '%'], ['budget_health', 'on-budget']])->count(), ['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); ], 200);
} }
@ -193,16 +205,15 @@ class DashboardBoDController extends Controller
['divisi_id', $divisi], ['divisi_id', $divisi],
['mulai_proyek', 'LIKE', '%' . $year . '%'], ['mulai_proyek', 'LIKE', '%' . $year . '%'],
['budget_health', $health] ['budget_health', $health]
]) ])->count();
->count();
} }
public function getTotalProjectBudgetHealthPerDivision($year = '%') public function getTotalProjectBudgetHealthPerDivision($year = '%')
{ {
$year = $this->interpolateYear($year); $year = $this->interpolateYear($year);
$divisions = Divisi::select('id', 'name') $divisions = Divisi::query()
->with('children') ->select('id', 'name')
->whereNull('parent') ->whereNull('parent')
->get(); ->get();
// to do : count in more than 1 level child // to do : count in more than 1 level child
@ -231,14 +242,15 @@ class DashboardBoDController extends Controller
public function getTotalProjectPerPhase($year = '%') public function getTotalProjectPerPhase($year = '%')
{ {
$year = $this->interpolateYear($year); $year = $this->interpolateYear($year);
$projectPhases = ProjectPhase::orderBy('order')->get(); $projectPhases = ProjectPhase::query()
->orderBy('order')
->get();
foreach ($projectPhases as $phase) { foreach ($projectPhases as $phase) {
$phase->totalProject = Project::query() $phase->totalProject = Project::query()
->where([ ->where([
['phase_id', $phase->id], ['phase_id', $phase->id],
['mulai_proyek', 'like', '%' . $year . '%'] ['mulai_proyek', 'like', '%' . $year . '%']
]) ])->count();
->count();
} }
return response()->json([ return response()->json([
'data' => [ 'data' => [
@ -252,7 +264,7 @@ class DashboardBoDController extends Controller
return Project::query() return Project::query()
->where([ ->where([
['divisi_id', $id], ['divisi_id', $id],
['mulai_proyek', 'like', '%' . $year . '%'] ['mulai_proyek', 'LIKE', '%' . $year . '%']
]) ])
->count(); ->count();
} }
@ -261,8 +273,8 @@ class DashboardBoDController extends Controller
{ {
$year = $this->interpolateYear($year); $year = $this->interpolateYear($year);
$divisions = Divisi::select('id', 'name') $divisions = Divisi::query()
->with('children') ->select('id', 'name')
->whereNull('parent') ->whereNull('parent')
->get(); ->get();
@ -282,9 +294,10 @@ class DashboardBoDController extends Controller
private function countTotalProjectValueInDivision($id, $year) 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([ ->where([
['mulai_proyek', 'like', '%' . $year . '%'], ['mulai_proyek', 'LIKE', '%' . $year . '%'],
['divisi_id', $id] ['divisi_id', $id]
]) ])
->pluck('sum') ->pluck('sum')
@ -295,8 +308,8 @@ class DashboardBoDController extends Controller
{ {
$year = $this->interpolateYear($year); $year = $this->interpolateYear($year);
$divisions = Divisi::select('id', 'name') $divisions = Divisi::query()
->with('children') ->select('id', 'name')
->whereNull('parent') ->whereNull('parent')
->get(); ->get();
@ -318,28 +331,29 @@ class DashboardBoDController extends Controller
public function getDetailExpenditure($year = '%') public function getDetailExpenditure($year = '%')
{ {
$year = $this->interpolateYear($year); $year = $this->interpolateYear($year);
$projects = Project::where('mulai_proyek', 'like', '%' . $year . '%') $projects = Project::query()
->where('mulai_proyek', 'LIKE', '%' . $year . '%')
->orderByDesc('id') ->orderByDesc('id')
->get(); ->get();
foreach ($projects as $project) { foreach ($projects as $project) {
$lastGantt = MasterFunctionsHelper::getLatestGantt($project->id); $lastGantt = MasterFunctionsHelper::getLatestGantt($project['id']);
if ($project->kode_sortname != "") { if (!empty($project['kode_sortname'])) {
$resp = $this->getInvoiceIntegration($project->kode_sortname); $resp = $this->getInvoiceIntegration($project['kode_sortname']);
$project->invoice = [ $project->invoice = [
'invoiced' => $resp->data->total_invoice_amount ?? 0, 'invoiced' => $resp->data->total_invoice_amount ?? 0,
'paid' => $resp->data->total_invoice_paid_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'])) { if (!isset($lastGantt['last_gantt_id'])) {
$project->manPowers = 0; $project->manPowers = 0;
} else { } else {
$project->manPowers = UserToVersionGantt::where('version_gantt_id', $lastGantt['last_gantt_id'])->count(); $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([ return response()->json([

121
app/Http/Controllers/API/DivisiController.php

@ -4,8 +4,127 @@ namespace App\Http\Controllers\API;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\Divisi;
use Illuminate\Support\Facades\Validator;
class DivisiController extends Controller 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);
}
}
} }

210
app/Http/Controllers/API/HumanResourceController.php

@ -4,8 +4,216 @@ namespace App\Http\Controllers\API;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use App\Models\{HumanResource, UserToActivity, UserToProyek};
use Illuminate\Support\Facades\Artisan;
class HumanResourceController extends Controller 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');
}
} }

45
app/Http/Controllers/API/MaterialProjectController.php

@ -4,8 +4,51 @@ namespace App\Http\Controllers\API;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\MaterialProject;
class MaterialProjectController extends Controller 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]);
}
}
} }

132
app/Http/Controllers/API/MaterialResourceController.php

@ -4,8 +4,138 @@ namespace App\Http\Controllers\API;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\{MaterialResource, RequestMaterial};
use Illuminate\Support\Facades\Validator;
class MaterialResourceController extends Controller 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);
}
} }

16
app/Http/Controllers/API/MenuController.php

@ -12,11 +12,14 @@ class MenuController extends Controller
public function add(Request $request) public function add(Request $request)
{ {
$validator = Validator::make($request->all(), [ $validator = Validator::make($request->all(), [
'parent_id' => 'nullable',
'icon' => 'required', 'icon' => 'required',
'name' => 'required|string', 'name' => 'required|string',
'alias_name' => 'nullable',
'url' => 'required', 'url' => 'required',
'sequence' => 'required', 'sequence' => 'required',
'created_by' => '' 'created_by' => 'nullable|string|max:80',
'updated_by' => 'nullable|string|max:80',
]); ]);
if ($validator->fails()) { if ($validator->fails()) {
return response()->json(['status' => 'failed', 'message' => 'add data menu failed!', 'code' => 400], 400); 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) 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); return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
die();
} }
$result = Menu::find($id); $result = Menu::find($id);
@ -48,16 +50,20 @@ class MenuController extends Controller
public function update(Request $request, $id) 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); return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
} }
$data = Menu::find($id); $data = Menu::find($id);
$validator = Validator::make($request->all(), [ $validator = Validator::make($request->all(), [
'parent_id' => '',
'icon' => 'required', 'icon' => 'required',
'name' => 'required|string', 'name' => 'required|string',
'alias_name' => '',
'url' => 'required', 'url' => 'required',
'sequence' => 'required' 'sequence' => 'required',
'created_by' => '',
'updated_by' => '',
]); ]);
if ($validator->fails()) { if ($validator->fails()) {
return response()->json(['status' => 'failed', 'message' => 'data menu failed updated!', 'code' => 400], 400); return response()->json(['status' => 'failed', 'message' => 'data menu failed updated!', 'code' => 400], 400);

84
app/Http/Controllers/API/ProjectCharterController.php

@ -4,8 +4,90 @@ namespace App\Http\Controllers\API;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\ProjectCharter;
use Illuminate\Support\Facades\Validator;
class ProjectCharterController extends Controller 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);
}
} }

232
app/Http/Controllers/API/ProjectController.php

@ -28,11 +28,11 @@ use App\Models\{
ActivityDokumen, ActivityDokumen,
Holiday, Holiday,
ReportActivity, ReportActivity,
OfficeHours OfficeHours,
ReportActivityMaterial
}; };
use Illuminate\Support\Facades\{DB, Artisan, Validator}; use Illuminate\Support\Facades\{DB, Artisan, Validator};
use App\Helpers\MasterFunctionsHelper; use App\Helpers\MasterFunctionsHelper;
use App\Models\ReportActivityMaterial;
const API_GEOLOCATION = "https://nominatim.oslogdev.com/search/ADDR?format=json&addressdetails=1&limit=1"; 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) public function add(Request $request)
{ {
$validator = Validator::make($request->all(), [ $validator = Validator::make($request->all(), [
'nama' => 'required', 'kode_sortname' => 'string|nullable',
'mulai_proyek' => 'required', 'jumlah_stakeholder' => 'integer|nullable',
'akhir_proyek' => 'required', 'nama' => 'required|string',
'rencana_biaya' => 'required', 'mulai_proyek' => 'required|date',
'type_proyek_id' => 'required', 'akhir_proyek' => 'nullable|date',
'created_by' => '', 'area_kerja' => 'nullable|string|max:200',
'phase_id' => '' '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()) { if ($validator->fails()) {
@ -69,41 +93,85 @@ class ProjectController extends Controller
} }
$this->createOfficeHours($result->id); $this->createOfficeHours($result->id);
$dataResultInsert = Project::where([ $dataResultInsert = Project::query()
['nama', $validated['nama']], ->where([
['mulai_proyek', $validated['mulai_proyek']] ['nama', $validated['nama']],
])->first(); ['mulai_proyek', $validated['mulai_proyek']]
])->first();
return response()->json(['status' => 'success', 'message' => 'Data added!', 'data_result' => $dataResultInsert, 'code' => 200], 200); return response()->json(['status' => 'success', 'message' => 'Data added!', 'data_result' => $dataResultInsert, 'code' => 200], 200);
} }
public function edit($id) 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); return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
$result = Project::find($id); $result = Project::find($id);
if (!$result) if (!$result) {
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404); return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
}
return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200);
} }
public function update(Request $request, $id) 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); 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); $data = Project::find($id);
if (!$data) if (!$data) {
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404); 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' => 'failed', 'message' => 'Failed to update!', 'code' => 500], 500);
}
return response()->json(['status' => 'success', 'message' => 'Data updated!', 'code' => 200], 200); return response()->json(['status' => 'success', 'message' => 'Data updated!', 'code' => 200], 200);
} }
@ -153,15 +221,17 @@ class ProjectController extends Controller
private function deleteRelative($project_id) private function deleteRelative($project_id)
{ {
UserToProyek::where('proyek_id', $project_id)->delete(); $id_proyek = $project_id;
UserToActivity::where('proyek_id', $project_id)->delete();
AssignMaterial::where('proyek_id', $project_id)->delete(); UserToProyek::where('proyek_id', $id_proyek)->delete();
ProjectCharter::where('proyek_id', $project_id)->delete(); UserToActivity::where('proyek_id', $id_proyek)->delete();
ProjectApproval::where('proyek_id', $project_id)->delete(); AssignMaterial::where('proyek_id', $id_proyek)->delete();
ProjectMileStone::where('proyek_id', $project_id)->delete(); ProjectCharter::where('proyek_id', $id_proyek)->delete();
ProjectParticipants::where('proyek_id', $project_id)->delete(); ProjectApproval::where('proyek_id', $id_proyek)->delete();
$this->deleteVersionGantt($project_id); ProjectMileStone::where('proyek_id', $id_proyek)->delete();
$this->deleteDokumenProject($project_id); ProjectParticipants::where('proyek_id', $id_proyek)->delete();
$this->deleteVersionGantt($id_proyek);
$this->deleteDokumenProject($id_proyek);
} }
private function deleteVersionGantt($project_id) private function deleteVersionGantt($project_id)
@ -172,13 +242,18 @@ class ProjectController extends Controller
$activityIds = $activity->all(); $activityIds = $activity->all();
$dataRa = ReportActivity::whereIn("activity_id", $activityIds)->get(); $dataRa = ReportActivity::whereIn("activity_id", $activityIds)->get();
foreach ($dataRa as $ra) { 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) { foreach ($images as $image) {
if (file_exists($this->pathImage . $image->image)) { if (file_exists($this->pathImage . $image->image)) {
unlink($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(); $dataAd = ActivityDokumen::whereIn("activity_id", $activityIds)->get();
foreach ($dataAd as $ad) { foreach ($dataAd as $ad) {
@ -208,10 +283,11 @@ class ProjectController extends Controller
unlink($this->pathDocument . $dokumen->file); unlink($this->pathDocument . $dokumen->file);
} }
} }
DokumenProject::where([ DokumenProject::query()
["type_dokumen", "project-document-out-folder"], ->where([
['ref_id', $project_id] ["type_dokumen", "project-document-out-folder"],
])->delete(); ['ref_id', $project_id]
])->delete();
$dataFolder = FolderDocumentProyek::where('proyek_id', $project_id)->pluck("id"); $dataFolder = FolderDocumentProyek::where('proyek_id', $project_id)->pluck("id");
$ref_ids = $dataFolder->all(); $ref_ids = $dataFolder->all();
@ -253,14 +329,14 @@ class ProjectController extends Controller
$progress = $costVariance = $actualCost = 0; $progress = $costVariance = $actualCost = 0;
$lastActivity = null; $lastActivity = null;
$scheduleHealth = "on-track"; $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) { 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; $actualCost = $rootActivity->biaya_actual ?? 0;
$progress = $rootActivity->persentase_progress ?? 0; $progress = $rootActivity->persentase_progress ?? 0;
$timeleft = strtotime($d->mulai_proyek) - strtotime($rootActivity->end_date); $timeleft = strtotime($d['mulai_proyek']) - strtotime($rootActivity->end_date);
$date1 = new \DateTime(date("Y-m-d", strtotime($d->mulai_proyek))); $date1 = new \DateTime(date("Y-m-d", strtotime($d['mulai_proyek'])));
$date2 = new \DateTime(date("Y-m-d", strtotime($rootActivity->end_date))); $date2 = new \DateTime(date("Y-m-d", strtotime($rootActivity->end_date)));
$daysRemaining = $date2->diff($date1); $daysRemaining = $date2->diff($date1);
$daysRemaining = $daysRemaining->d; $daysRemaining = $daysRemaining->d;
@ -272,26 +348,26 @@ class ProjectController extends Controller
} }
$lastActivity = date("d/m/Y", strtotime($rootActivity->end_date)); $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['plannedInterval'] = date("d/m/Y", strtotime($d['mulai_proyek'])) . " - " . date("d/m/Y", strtotime($d['akhir_proyek']));
$d->plannedCost = $d->rencana_biaya; $d['plannedCost'] = $d['rencana_biaya'];
$d->actualCost = $actualCost; $d['actualCost'] = $actualCost;
$d->lastActivity = $lastActivity ?? "-"; $d['lastActivity'] = $lastActivity ?? "-";
$d->costVariance = $costVariance; $d['costVariance'] = $costVariance;
$d->costHealth = $d->budget_health; $d['costHealth'] = $d['budget_health'];
$d->scheduleHealth = $scheduleHealth; $d['scheduleHealth'] = $scheduleHealth;
$d->progress = $progress; $d['progress'] = $progress;
$d->lastGanttId = VersionGantt::where("proyek_id", $d->id)->orderByDesc('id')->first()->id ?? null; $d['lastGanttId'] = VersionGantt::where("proyek_id", $d['id'])->orderByDesc('id')->first()->id ?? null;
$d->manpower = UserToProyek::where("proyek_id", $d->id)->count() ?? 0; $d['manpower'] = UserToProyek::where("proyek_id", $d['id'])->count() ?? 0;
$d->projectManager = Project::query() $d['projectManager'] = Project::query()
->join('m_users', 'm_users.id', '=', 'm_proyek.pm_id') ->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') ->pluck('m_users.name')
->first(); ->first();
if ($d->area_kerja != '') { if ($d['area_kerja'] != '') {
$d->geolocation = $this->httpReq($d->area_kerja); $d['geolocation'] = $this->httpReq($d['area_kerja']);
$d->geolocation = []; $d['geolocation'] = [];
} else { } else {
$d->geolocation = []; $d['geolocation'] = [];
} }
} }
@ -386,7 +462,7 @@ class ProjectController extends Controller
$reports = []; $reports = [];
foreach ($activities as $activity) { foreach ($activities as $activity) {
$activity_id = $activity->id; $activity_id = $activity['id'];
$countReports = ReportActivityMaterial::where('activity_id', $activity_id)->count(); $countReports = ReportActivityMaterial::where('activity_id', $activity_id)->count();
if ($countReports === 1) { if ($countReports === 1) {
$dataReports = ReportActivityMaterial::where('activity_id', $activity_id)->orderBy('report_date')->get(); $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++) { for ($i = 0; $i < count($reports); $i++) {
$activity = Activity::find($reports[$i]['activity_id']); $activity = Activity::find($reports[$i]['activity_id']);
$activity->start_date = $reports[$i]['min_date']; $activity['start_date'] = $reports[$i]['min_date'];
$activity->end_date = $reports[$i]['max_date']; $activity['end_date'] = $reports[$i]['max_date'];
$activity->save(); $activity->save();
} }
@ -426,8 +502,8 @@ class ProjectController extends Controller
foreach ($activities as $activity) { foreach ($activities as $activity) {
$activity->update([ $activity->update([
"planned_start" => $activity->start_date, "planned_start" => $activity['start_date'],
"planned_end" => $activity->end_date, "planned_end" => $activity['end_date'],
]); ]);
} }
@ -436,20 +512,14 @@ class ProjectController extends Controller
public function getInvoiceIntegration(Request $request) 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; $response = null;
// return response()->json(['status'=>'success', 'data'=> $response, 'code'=>200], 200);
return response()->json(['status' => 'success', 'data' => '', 'code' => 200], 200); return response()->json(['status' => 'success', 'data' => '', 'code' => 200], 200);
} }
public function detail($id) 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); 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) public function getOverdueActivities(Request $request)
{ {
$payload = $request->all(); $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); return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
} }
@ -493,11 +563,11 @@ class ProjectController extends Controller
{ {
$payload = $request->all(); $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); 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( ->select(
'u.name', 'u.name',
'a.name as activity_name', 'a.name as activity_name',
@ -510,10 +580,10 @@ class ProjectController extends Controller
'ram.description as report_notes', 'ram.description as report_notes',
'ram.report_date' 'ram.report_date'
) )
->join('report_activity_material as ram', 'ram.assign_material_id', '=', 'ama.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_req_material AS rm', 'rm.id', '=', 'ama.material_id')
->join('m_activity as a', 'a.id', '=', 'ama.activity_id') ->join('m_activity AS a', 'a.id', '=', 'ama.activity_id')
->join('m_users as u', 'u.id', '=', 'ram.user_id') ->join('m_users AS u', 'u.id', '=', 'ram.user_id')
->where('ama.proyek_id', '=', $payload['project_id']) ->where('ama.proyek_id', '=', $payload['project_id'])
->whereNotNull('ram.lat') ->whereNotNull('ram.lat')
->whereBetween('ram.report_date', [$payload['start_date'], $payload['end_date']]); ->whereBetween('ram.report_date', [$payload['start_date'], $payload['end_date']]);
@ -550,7 +620,7 @@ class ProjectController extends Controller
'mu.name as pm', 'mu.name as pm',
'mp.budget_health' '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) ->where('mp.id', $id)
->first(); ->first();
@ -561,18 +631,18 @@ class ProjectController extends Controller
$manpowers = UserToProyek::where('proyek_id', $id)->count(); $manpowers = UserToProyek::where('proyek_id', $id)->count();
$rootActivity = Activity::whereNull('parent_id')->where('proyek_id', $id)->orderByDesc('version_gantt_id')->first(); $rootActivity = Activity::whereNull('parent_id')->where('proyek_id', $id)->orderByDesc('version_gantt_id')->first();
$actualCost = $rootActivity->biaya_actual ?? 0; $actualCost = $rootActivity['biaya_actual'] ?? 0;
$progress = $rootActivity->persentase_progress ?? 0; $progress = $rootActivity['persentase_progress'] ?? 0;
$commentActivity = DB::table('m_comment_activity as mca') $commentActivity = DB::table('m_comment_activity as mca')
->select( ->select(
'mca.activity_id', 'mca.activity_id',
'mca.comment as comment', 'mca.comment AS comment',
'mca.created_by as comment_by', 'mca.created_by AS comment_by',
'mca.created_at as comment_created', 'mca.created_at AS comment_created',
'ma.name as activity' '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) ->where('ma.proyek_id', $id)
->orderBy('comment_by') ->orderBy('comment_by')
->take(2) ->take(2)

17
app/Http/Controllers/API/ProjectDokumenController.php

@ -10,7 +10,7 @@ class ProjectDokumenController extends Controller
{ {
public function dokumenByProyekId($id) 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); 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) 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); 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) public function uploadProjectDokumen(Request $request)
{ {
if ($request->hasFile('dokumen')) { if ($request->hasFile('dokumen')) {
$request->validate([ $validated = $request->validate([
'dokumen' => 'mimes:png,jpg,pdf,jpeg,gif' 'dokumen' => 'required|image|mimes:png,jpg,pdf,jpeg,gif',
'ref_id' => 'required|integer',
'file' => 'required',
'type_dokumen' => 'required'
]); ]);
$document = $request->file('dokumen'); $document = $request->file('dokumen');
$ref_id = $request->ref_id; $ref_id = $validated['ref_id'];
$name = $document->getClientOriginalName(); $name = $document->getClientOriginalName();
$result = $document->move($this->pathDocument, $name); $result = $document->move($this->pathDocument, $name);
@ -59,7 +62,7 @@ class ProjectDokumenController extends Controller
$data = [ $data = [
'ref_id' => (int)$ref_id, 'ref_id' => (int)$ref_id,
'file' => $name, '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); $result = DokumenProject::create($data);
@ -90,7 +93,7 @@ class ProjectDokumenController extends Controller
public function downloadDokumen($id) 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); return response()->json(['status' => 'failed', 'message' => 'Id is required!', 'code' => 400], 400);
} }

107
app/Http/Controllers/API/ProjectPhaseController.php

@ -4,8 +4,113 @@ namespace App\Http\Controllers\API;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\ProjectPhase;
use Illuminate\Support\Facades\Validator;
class ProjectPhaseController extends Controller 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);
}
}
} }

122
app/Http/Controllers/API/ProjectRoleController.php

@ -4,8 +4,128 @@ namespace App\Http\Controllers\API;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\ProjectRole;
use Illuminate\Support\Facades\Validator;
class ProjectRoleController extends Controller 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);
}
} }

113
app/Http/Controllers/API/ProjectTypeController.php

@ -4,8 +4,119 @@ namespace App\Http\Controllers\API;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\ProjectType;
use Illuminate\Support\Facades\Validator;
class ProjectTypeController extends Controller 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);
}
}
} }

261
app/Http/Controllers/API/RequestMaterialController.php

@ -4,8 +4,267 @@ namespace App\Http\Controllers\API;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\{RequestMaterial, MaterialResource};
use Illuminate\Support\Facades\{DB, Validator};
class RequestMaterialController extends Controller 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);
}
} }

13
app/Http/Controllers/API/RoleController.php

@ -15,7 +15,8 @@ class RoleController extends Controller
$validator = Validator::make($request->all(), [ $validator = Validator::make($request->all(), [
'name' => 'required', 'name' => 'required',
'description' => 'required', 'description' => 'required',
'created_by' => '' 'created_by' => '',
'updated_by' => ''
]); ]);
if ($validator->fails()) { if ($validator->fails()) {
@ -31,7 +32,7 @@ class RoleController extends Controller
public function edit($id) 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); 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) 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); return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
} }
$data = Role::find($id); $data = Role::find($id);
$validated = $request->validate([ $validated = $request->validate([
'name' => 'required', 'name' => 'required',
'description' => 'required' 'description' => 'required',
'created_by' => '',
'updated_by' => ''
]); ]);
if (!$data) { if (!$data) {
@ -71,7 +74,7 @@ class RoleController extends Controller
public function delete($id) 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); return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
} }

19
app/Http/Controllers/API/RoleMenuController.php

@ -14,7 +14,8 @@ class RoleMenuController extends Controller
$validator = Validator::make($request->all(), [ $validator = Validator::make($request->all(), [
'role_id' => 'required', 'role_id' => 'required',
'menu_id' => 'required', 'menu_id' => 'required',
'created_by' => '' 'created_by' => '',
'updated_by' => ''
]); ]);
if ($validator->fails()) { if ($validator->fails()) {
@ -30,14 +31,26 @@ class RoleMenuController extends Controller
public function update(Request $request, $id) 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); 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); $data = RoleMenu::find($id);
if ($data) { if ($data) {
$result = $data->update($request->all()); $result = $data->update($validated);
if ($result) : if ($result) :
return response()->json(['status' => 'success', 'message' => 'data role menu successfully updated!', 'code' => 200], 200); return response()->json(['status' => 'success', 'message' => 'data role menu successfully updated!', 'code' => 200], 200);
else : else :

45
app/Http/Controllers/API/ToolsProjectController.php

@ -4,8 +4,51 @@ namespace App\Http\Controllers\API;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\ToolsProject;
class ToolsProjectController extends Controller 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]);
}
}
} }

161
app/Http/Controllers/API/ToolsRequestController.php

@ -4,8 +4,167 @@ namespace App\Http\Controllers\API;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\{ToolsResource, ToolsRequest};
use Illuminate\Support\Facades\Validator;
class ToolsRequestController extends Controller 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);
}
}
} }

131
app/Http/Controllers/API/ToolsResourceController.php

@ -4,8 +4,137 @@ namespace App\Http\Controllers\API;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\ToolsResource;
use Illuminate\Support\Facades\Validator;
class ToolsResourceController extends Controller 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);
}
} }

45
app/Http/Controllers/API/UserProyekController.php

@ -4,8 +4,51 @@ namespace App\Http\Controllers\API;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\UserProject;
class UserProyekController extends Controller 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);
}
}
} }

6
app/Models/ActivityDokumen.php

@ -6,12 +6,8 @@ use Illuminate\Database\Eloquent\Model;
class ActivityDokumen extends Model class ActivityDokumen extends Model
{ {
protected $table = 'm_document_activity'; protected $table = 'm_document_activity', $guarded = ['id'];
const CREATED_AT = 'created_at'; const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at'; const UPDATED_AT = 'updated_at';
protected $fillable = [
'file', 'description', 'activity_id', 'created_at', 'created_by', 'updated_at', 'updated_by'
];
} }

11
app/Models/CommentActivity.php

@ -6,17 +6,8 @@ use Illuminate\Database\Eloquent\Model;
class CommentActivity extends Model class CommentActivity extends Model
{ {
protected $table = 'm_comment_activity'; protected $table = 'm_comment_activity', $guarded = ['id'];
const CREATED_AT = 'created_at'; const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at'; const UPDATED_AT = 'updated_at';
protected $fillable = [
'activity_id',
'comment',
'created_at',
'created_by',
'updated_at',
'updated_by'
];
} }

9
app/Models/ConfigAlert.php

@ -6,12 +6,11 @@ use Illuminate\Database\Eloquent\Model;
class ConfigAlert extends 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 CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at'; const UPDATED_AT = 'updated_at';
protected $fillable = [
'nama', 'keterangan', 'created_at', 'created_by', 'updated_at', 'updated_by'
];
} }

12
app/Models/ConfigAlertUser.php

@ -6,12 +6,12 @@ use Illuminate\Database\Eloquent\Model;
class ConfigAlertUser extends 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 CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at'; const UPDATED_AT = 'updated_at';
protected $fillable = [
'user_id', 'config_alert_id', 'created_at', 'created_by', 'updated_at', 'updated_by'
];
} }

47
app/Models/Divisi.php

@ -6,36 +6,31 @@ use Illuminate\Database\Eloquent\Model;
class Divisi extends 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 CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at'; const UPDATED_AT = 'updated_at';
protected $fillable = [ public static function boot()
'name', {
'parent', parent::boot();
'description',
'created_at',
'created_by',
'updated_at',
'updated_by'
];
public static function boot() {
parent::boot();
static::deleting(function($data) { static::deleting(function ($data) {
$data->children()->delete(); $data->children()->delete();
}); });
} }
public function parent() public function parent()
{ {
return $this->belongsTo('App\Models\Divisi','parent')->where('parent', null)->with('parent'); return $this->belongsTo(self::class, 'parent')->where('parent', null);
} }
public function children() public function children()
{ {
return $this->hasMany('App\Models\Divisi','parent')->with('children'); return $this->hasMany(self::class, 'parent');
} }
} }

6
app/Models/DokumenProject.php

@ -6,12 +6,8 @@ use Illuminate\Database\Eloquent\Model;
class DokumenProject extends Model class DokumenProject extends Model
{ {
protected $table = 'document_project'; protected $table = 'document_project', $guarded = ['id'];
const CREATED_AT = 'created_at'; const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at'; const UPDATED_AT = 'updated_at';
protected $fillable = [
'file', 'type_dokumen', 'ref_id', 'created_at', 'created_by', 'updated_at', 'updated_by'
];
} }

6
app/Models/Holiday.php

@ -6,12 +6,8 @@ use Illuminate\Database\Eloquent\Model;
class Holiday extends Model class Holiday extends Model
{ {
protected $table = 'm_holidays'; protected $table = 'm_holidays', $guarded = ['id'];
const CREATED_AT = 'created_at'; const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at'; const UPDATED_AT = 'updated_at';
protected $fillable = [
'proyek_id', 'duration', 'version_gantt_id', 'date', 'description', 'created_at', 'created_by', 'updated_at', 'updated_by'
];
} }

33
app/Models/HumanResource.php

@ -6,33 +6,12 @@ use Illuminate\Database\Eloquent\Model;
class HumanResource extends 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 CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_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'
];
} }

6
app/Models/Image.php

@ -6,12 +6,8 @@ use Illuminate\Database\Eloquent\Model;
class Image extends Model class Image extends Model
{ {
protected $table = 'm_image'; protected $table = 'm_image', $guarded = ['id'];
const CREATED_AT = 'created_at'; const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at'; const UPDATED_AT = 'updated_at';
protected $fillable = [
'image', 'ref_id', 'category', 'created_at', 'created_by', 'updated_at', 'updated_by'
];
} }

7
app/Models/Link.php

@ -6,13 +6,8 @@ use Illuminate\Database\Eloquent\Model;
class Link extends Model class Link extends Model
{ {
protected $table = 'm_activity_link'; protected $table = 'm_activity_link', $guarded = ['id'];
const CREATED_AT = 'created_at'; const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_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'
];
} }

11
app/Models/MaterialProject.php

@ -6,12 +6,11 @@ use Illuminate\Database\Eloquent\Model;
class MaterialProject extends 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 CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at'; const UPDATED_AT = 'updated_at';
protected $fillable = [
'material_resource_id', 'proyek_id', 'subproyek_id', 'created_at', 'created_by', 'updated_at', 'updated_by'
];
} }

11
app/Models/MaterialResource.php

@ -6,12 +6,13 @@ use Illuminate\Database\Eloquent\Model;
class MaterialResource extends 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 CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at'; const UPDATED_AT = 'updated_at';
protected $fillable = [
'name', 'uom', 'unit_price', 'description', 'status', 'qty', 'created_at', 'created_by', 'updated_at', 'updated_by'
];
} }

9
app/Models/OfficeHours.php

@ -6,15 +6,8 @@ use Illuminate\Database\Eloquent\Model;
class OfficeHours extends Model class OfficeHours extends Model
{ {
protected $table = 'm_office_hours'; protected $table = 'm_office_hours', $guarded = ['id'];
const CREATED_AT = 'created_at'; const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_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'
];
} }

13
app/Models/ProjectApproval.php

@ -6,19 +6,8 @@ use Illuminate\Database\Eloquent\Model;
class ProjectApproval extends Model class ProjectApproval extends Model
{ {
protected $table = 'project_approval'; protected $table = 'project_approval', $guarded = ['id'];
const CREATED_AT = 'created_at'; const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at'; const UPDATED_AT = 'updated_at';
protected $fillable = [
'proyek_id',
'tittle',
'name',
'date_approval',
'created_at',
'created_by',
'updated_at',
'updated_by'
];
} }

25
app/Models/ProjectCharter.php

@ -6,26 +6,13 @@ use Illuminate\Database\Eloquent\Model;
class ProjectCharter extends Model class ProjectCharter extends Model
{ {
protected $table = 'project_charter'; protected $table = 'project_charter', $guarded = ['id'];
const CREATED_AT = 'created_at'; protected $casts = [
const UPDATED_AT = 'updated_at'; 'id' => 'integer',
'proyek_id' => 'integer'
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'
]; ];
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
} }

13
app/Models/ProjectMileStone.php

@ -6,19 +6,8 @@ use Illuminate\Database\Eloquent\Model;
class ProjectMileStone extends Model class ProjectMileStone extends Model
{ {
protected $table = 'project_milestone'; protected $table = 'project_milestone', $guarded = ['id'];
const CREATED_AT = 'created_at'; const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at'; const UPDATED_AT = 'updated_at';
protected $fillable = [
'proyek_id',
'status',
'due_date',
'deadline',
'created_at',
'created_by',
'updated_at',
'updated_by'
];
} }

12
app/Models/ProjectParticipants.php

@ -6,18 +6,8 @@ use Illuminate\Database\Eloquent\Model;
class ProjectParticipants extends Model class ProjectParticipants extends Model
{ {
protected $table = 'project_participants'; protected $table = 'project_participants', $guarded = ['id'];
const CREATED_AT = 'created_at'; const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at'; const UPDATED_AT = 'updated_at';
protected $fillable = [
'proyek_id',
'tittle',
'name',
'created_at',
'created_by',
'updated_at',
'updated_by'
];
} }

10
app/Models/ProjectPhase.php

@ -6,12 +6,12 @@ use Illuminate\Database\Eloquent\Model;
class ProjectPhase extends 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 CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at'; const UPDATED_AT = 'updated_at';
protected $fillable = [
'name', 'color', 'order', 'created_at', 'created_by', 'updated_at', 'updated_by'
];
} }

10
app/Models/ProjectRole.php

@ -6,12 +6,10 @@ use Illuminate\Database\Eloquent\Model;
class ProjectRole extends 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 CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at'; const UPDATED_AT = 'updated_at';
protected $fillable = [
'name', 'description', 'created_at', 'created_by', 'updated_at', 'updated_by'
];
} }

10
app/Models/ProjectType.php

@ -6,12 +6,12 @@ use Illuminate\Database\Eloquent\Model;
class ProjectType extends 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 CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at'; const UPDATED_AT = 'updated_at';
protected $fillable = [
'name', 'description', 'created_at', 'created_by', 'updated_at', 'updated_by'
];
} }

16
app/Models/ReportActivity.php

@ -6,22 +6,8 @@ use Illuminate\Database\Eloquent\Model;
class ReportActivity extends Model class ReportActivity extends Model
{ {
protected $table = 'report_activity'; protected $table = 'report_activity', $guarded = ['id'];
const CREATED_AT = 'created_at'; const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_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'
];
} }

116
app/Models/ReportActivityMaterial.php

@ -9,65 +9,59 @@ use Carbon\Carbon;
class ReportActivityMaterial extends Model class ReportActivityMaterial extends Model
{ {
protected $table = 'report_activity_material'; protected $table = 'report_activity_material', $guarded = ['id'];
const CREATED_AT = 'created_at'; const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at'; const UPDATED_AT = 'updated_at';
protected $fillable = [ public function getReportDateAttribute($value)
'activity_id', 'user_id', 'qty', 'lat', 'lon','assign_material_id', {
'report_date', 'description', 'created_at', 'created_by', 'updated_at', 'updated_by' return Carbon::createFromTimestamp(strtotime($value))
]; ->timezone(env('APP_TIMEZONE'))
->toDateTimeString();
public function getReportDateAttribute($value) }
{
return Carbon::createFromTimestamp(strtotime($value)) public static function boot()
->timezone(env('APP_TIMEZONE')) {
->toDateTimeString(); parent::boot();
}
static::created(function ($data) {
public static function boot() { $activity = Activity::find($data->activity_id);
parent::boot(); $assignedMaterial = AssignMaterial::find($data->assign_material_id);
static::created(function($data) { $biayaActual = $activity->biaya_actual + floatval($assignedMaterial->budget) * floatval($data->qty);
$activity = Activity::find($data->activity_id);
$assignedMaterial = AssignMaterial::find($data->assign_material_id); $dataPlan = AssignMaterial::where('activity_id', $activity->id)->get();
if ($dataPlan[0]->status_activity == 'done') {
$biayaActual = $activity->biaya_actual + floatval($assignedMaterial->budget) * floatval($data->qty); $percentage = 100;
} else {
$dataPlan = AssignMaterial::where('activity_id', $activity->id)->get(); $totalPlan = $dataPlan->sum('qty_planning');
if($dataPlan[0]->status_activity == 'done'){ $totalVolumeActual = ReportActivityMaterial::where('activity_id', '=', $activity->id)->sum("qty");
$percentage = 100; $percentage = ($totalVolumeActual * 100) / $totalPlan;
} else { $percentage = $percentage >= config('app.max_percentage_not_done') ? config('app.max_percentage_not_done') : $percentage;
$totalPlan = $dataPlan->sum('qty_planning'); }
$totalVolumeActual = ReportActivityMaterial::where('activity_id', '=', $activity->id)->sum("qty");
$percentage = ($totalVolumeActual * 100) / $totalPlan; $activity->update([
$percentage = $percentage >= config('app.max_percentage_not_done') ? config('app.max_percentage_not_done') : $percentage; "persentase_progress" => $percentage,
} "biaya_actual" => $biayaActual,
]);
$activity->update([
"persentase_progress" => $percentage, $activity->save();
"biaya_actual" => $biayaActual, });
]);
static::deleted(function ($data) {
$activity->save();
}); $activity = Activity::find($data->activity_id);
$assignedMaterial = AssignMaterial::find($data->assign_material_id);
static::deleted(function($data) {
$activity->biaya_actual -= floatval($assignedMaterial->budget) * floatval($data->qty);
$activity = Activity::find($data->activity_id);
$assignedMaterial = AssignMaterial::find($data->assign_material_id); $dataPlan = AssignMaterial::where('activity_id', $activity->id)->get();
$totalPlan = $dataPlan->sum('qty_planning');
$activity->biaya_actual -= floatval($assignedMaterial->budget) * floatval($data->qty); $totalVolumeActual = ReportActivityMaterial::where('activity_id', '=', $activity->id)->sum("qty");
$percentage = ($totalVolumeActual * 100) / $totalPlan;
$dataPlan = AssignMaterial::where('activity_id', $activity->id)->get(); $activity->persentase_progress = $percentage >= config('app.max_percentage_not_done') ? config('app.max_percentage_not_done') : $percentage;
$totalPlan = $dataPlan->sum('qty_planning'); $activity->save();
$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();
});
}
} }

84
app/Models/RequestMaterial.php

@ -7,62 +7,44 @@ use Carbon\Carbon;
class RequestMaterial extends Model class RequestMaterial extends Model
{ {
protected $table = 'm_req_material'; protected $table = 'm_req_material', $guarded = ['id'];
const CREATED_AT = 'created_at'; const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at'; const UPDATED_AT = 'updated_at';
protected $casts = [ protected $casts = [
'id' => 'integer', 'id' => 'integer',
'price' => 'string', 'proyek_id' => 'integer',
'price' => 'float',
'qty' => 'float',
'qty_received' => 'float'
]; ];
protected $fillable = [ public function getRequiredDateAttribute($value)
'description', {
'required_date', return Carbon::createFromTimestamp(strtotime($value))
'qty', ->timezone(env('APP_TIMEZONE'))
'uom', ->toDateTimeString();
'qty_received', }
'fom_date',
'pr_date', public function getFomDateAttribute($value)
'po_date', {
'received_date', return Carbon::createFromTimestamp(strtotime($value))
'delivery_date', ->timezone(env('APP_TIMEZONE'))
'status', ->toDateTimeString();
'proyek_id', }
'created_at',
'created_by', public function getPrDateAttribute($value)
'updated_at', {
'updated_by', return Carbon::createFromTimestamp(strtotime($value))
'price' ->timezone(env('APP_TIMEZONE'))
]; ->toDateTimeString();
}
public function getRequiredDateAttribute($value)
{ public function getPoDateAttribute($value)
return Carbon::createFromTimestamp(strtotime($value)) {
->timezone(env('APP_TIMEZONE')) return Carbon::createFromTimestamp(strtotime($value))
->toDateTimeString(); ->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();
}
} }

13
app/Models/ShowHideColumn.php

@ -6,19 +6,8 @@ use Illuminate\Database\Eloquent\Model;
class ShowHideColumn extends 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 CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at'; const UPDATED_AT = 'updated_at';
protected $fillable = [
'user_id',
'version_gantt_id',
'column_name',
'show',
'created_at',
'created_by',
'updated_at',
'updated_by'
];
} }

11
app/Models/ToolsProject.php

@ -6,12 +6,11 @@ use Illuminate\Database\Eloquent\Model;
class ToolsProject extends 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 CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at'; const UPDATED_AT = 'updated_at';
protected $fillable = [
'tools_id', 'proyek_id', 'subproyek_id', 'created_at', 'created_by', 'updated_at', 'updated_by'
];
} }

26
app/Models/ToolsRequest.php

@ -6,26 +6,12 @@ use Illuminate\Database\Eloquent\Model;
class ToolsRequest extends 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 CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_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'
];
} }

11
app/Models/ToolsResource.php

@ -6,12 +6,11 @@ use Illuminate\Database\Eloquent\Model;
class ToolsResource extends 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 CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at'; const UPDATED_AT = 'updated_at';
protected $fillable = [
'name', 'description', 'qty', 'asset_type', 'uom', 'created_at', 'created_by', 'updated_at', 'updated_by'
];
} }

10
app/Models/UserProject.php

@ -6,12 +6,12 @@ use Illuminate\Database\Eloquent\Model;
class UserProject extends 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 CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at'; const UPDATED_AT = 'updated_at';
protected $fillable = [
'user_id', 'proyek_id', 'subproyek_id', 'created_at', 'created_by', 'updated_at', 'updated_by'
];
} }

8
app/Models/UserToProyek.php

@ -6,14 +6,8 @@ use Illuminate\Database\Eloquent\Model;
class UserToProyek extends 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 CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_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'
];
} }

92
app/Models/VersionGantt.php

@ -9,69 +9,53 @@ use DateTime;
class VersionGantt extends Model class VersionGantt extends Model
{ {
protected $table = 'm_version_gantt'; protected $table = 'm_version_gantt', $guarded = ['id'];
const CREATED_AT = 'created_at'; const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_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) { public static function boot()
$data->updateActDuration(); {
}); parent::boot();
}
public function updateActDuration(){ static::updated(function ($data) {
$daysOff = explode(',', $this->config_dayoff); $data->updateActDuration();
if (in_array('0', $daysOff)) { });
$key = array_search('0', $daysOff, false); }
$daysOff[$key] = '7';
} public function updateActDuration()
$activities = Activity::where('version_gantt_id', $this->id)->get(); {
foreach ($activities as $value) { $daysOff = explode(',', $this->config_dayoff);
$exist = Link::where('t_activity_id', $value->id)->exists(); if (in_array('0', $daysOff)) {
$startDate = new DateTime($value->start_date); $key = array_search('0', $daysOff, false);
$endDate = new DateTime($value->end_date); $daysOff[$key] = '7';
$duration = $endDate->diff($startDate)->days + 1;
if ($exist) {
$duration--;
} }
$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 // Iterate through each day and subtract the days off
for ($i = 0; $i < $duration; $i++) { for ($i = 0; $i < $duration; $i++) {
$currentDate = clone $startDate; $currentDate = clone $startDate;
$currentDate->modify("+$i day"); $currentDate->modify("+$i day");
$currentDayOfWeek = $currentDate->format('N'); // Get the day of the week (1 - Monday, 7 - Sunday) $currentDayOfWeek = $currentDate->format('N'); // Get the day of the week (1 - Monday, 7 - Sunday)
if (in_array($currentDayOfWeek, $daysOff)) { if (in_array($currentDayOfWeek, $daysOff)) {
$duration--; // Subtract one day from the duration for each day off $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();
}
} }
} }

2
routes/api.php

@ -219,7 +219,7 @@ Route::middleware('cors')->group(function () {
Route::get('/list', 'list'); Route::get('/list', 'list');
}); });
// user-to-project Route // user-to-project Route
Route::post('/user-to-project/assign', [UserProyekController::class, 'assignUserProyek']); Route::post('/user-to-project/assign', UserProyekController::class);
// request-material Route // request-material Route
Route::group(['prefix' => 'request-material', 'controller' => RequestMaterialController::class], function () { Route::group(['prefix' => 'request-material', 'controller' => RequestMaterialController::class], function () {
Route::post('/add', 'add'); Route::post('/add', 'add');

Loading…
Cancel
Save