@ -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)