Browse Source

add Hierarchy

pull/1/head
farhantock 1 year ago
parent
commit
c313683113
  1. 29
      app/Http/Controllers/AuthController.php
  2. 2
      app/Http/Controllers/Controller.php
  3. 600
      app/Http/Controllers/ProjectController.php
  4. 2
      app/Models/Project.php

29
app/Http/Controllers/AuthController.php

@ -11,6 +11,7 @@ use App\Models\Role;
use Illuminate\Http\JsonResponse; use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Password; use Illuminate\Support\Facades\Password;
use Illuminate\Validation\ValidationException; use Illuminate\Validation\ValidationException;
class AuthController extends Controller class AuthController extends Controller
{ {
public function __construct() public function __construct()
@ -25,8 +26,8 @@ class AuthController extends Controller
$remember = $request->remember; $remember = $request->remember;
$is_mobile = $request->is_mobile; $is_mobile = $request->is_mobile;
if(empty($username) || empty($password)) if (empty($username) || empty($password))
return response()->json(['status'=>'error','message'=>'You must fill all the fields'], 400); return response()->json(['status' => 'error', 'message' => 'You must fill all the fields'], 400);
$usernameCheck = false; $usernameCheck = false;
$passwordCheck = false; $passwordCheck = false;
@ -37,34 +38,38 @@ class AuthController extends Controller
if (User::where('password', md5($password))->exists()) if (User::where('password', md5($password))->exists())
$passwordCheck = true; $passwordCheck = true;
if ($usernameCheck & $passwordCheck){ if ($usernameCheck & $passwordCheck) {
$user = User::where('username', $username)->where('password', md5($password))->first(); $user = User::where('username', $username)->where('password', md5($password))->first();
if($is_mobile){ if ($is_mobile) {
$fcm_token = $request->fcm_token; $fcm_token = $request->fcm_token;
if(!$fcm_token || $fcm_token=="") if (!$fcm_token || $fcm_token == "")
return response()->json(['status'=>'error','message'=>'FCM Token is required'], 400); return response()->json(['status' => 'error', 'message' => 'FCM Token is required'], 400);
$dataUpdateFcm = array( $dataUpdateFcm = array(
"fcm_token"=>$fcm_token "fcm_token" => $fcm_token
); );
$hr = User::find($user->id); $hr = User::find($user->id);
if($hr) if ($hr)
$hr->update($dataUpdateFcm); $hr->update($dataUpdateFcm);
} }
$dataRole = Role::find($user->role_id); $dataRole = Role::find($user->role_id);
$dataHierarchy = $this->getDataHierarchy($user->divisi_id, $user->id);
if($dataRole) if ($dataRole)
$user->role = $dataRole; $user->role = $dataRole;
if (! $token =Auth::login($user)) if ($dataHierarchy)
$user->hierarchy = $dataHierarchy;
if (!$token = Auth::login($user))
return response()->json(['error' => 'Unauthorized'], 401); return response()->json(['error' => 'Unauthorized'], 401);
$ttl = 60; $ttl = 60;
if($remember) if ($remember)
$ttl = 10080; $ttl = 10080;
// todo : change existing md5 hashed function to laravel's originally bcrypt // todo : change existing md5 hashed function to laravel's originally bcrypt
@ -80,7 +85,7 @@ class AuthController extends Controller
'expires_in' => auth()->factory()->getTTL() * $ttl, 'expires_in' => auth()->factory()->getTTL() * $ttl,
), ),
]); ]);
}else { } else {
if (!$usernameCheck && !$passwordCheck) if (!$usernameCheck && !$passwordCheck)
return response()->json(['code' => 201, 'message' => "username and password doesn't match"], 201); return response()->json(['code' => 201, 'message' => "username and password doesn't match"], 201);
if (!$passwordCheck) if (!$passwordCheck)

2
app/Http/Controllers/Controller.php

@ -7,8 +7,8 @@ use Illuminate\Support\Facades\Http;
use App\Models\UserToActivity; use App\Models\UserToActivity;
use App\Models\Activity; use App\Models\Activity;
use App\Models\AssignMaterial; use App\Models\AssignMaterial;
use App\Models\User;
use App\Models\Divisi; use App\Models\Divisi;
use App\Models\User;
use Laravel\Lumen\Routing\Controller as BaseController; use Laravel\Lumen\Routing\Controller as BaseController;
use App\Models\ReportK3Detail; use App\Models\ReportK3Detail;

600
app/Http/Controllers/ProjectController.php

@ -50,7 +50,7 @@ class ProjectController extends Controller
{ {
$this->validate($request, [ $this->validate($request, [
'nama' => 'required', 'nama' => 'required',
'mulai_proyek' => 'required', 'mulai_proyek' => 'required',
'akhir_proyek' => 'required', 'akhir_proyek' => 'required',
'rencana_biaya' => 'required', 'rencana_biaya' => 'required',
'type_proyek_id' => 'required' 'type_proyek_id' => 'required'
@ -59,81 +59,82 @@ class ProjectController extends Controller
$data = $request->all(); $data = $request->all();
$data['created_by'] = $this->currentName; $data['created_by'] = $this->currentName;
$data['created_by_id'] = $this->currentId;
if(empty($data['phase_id'])) if (empty($data['phase_id']))
$data['phase_id'] = 1; $data['phase_id'] = 1;
$result = Project::create($data); $result = Project::create($data);
if(!$result) if (!$result)
return response()->json(['status'=>'failed','message'=>'Failed to add data!','code'=> 500], 500); return response()->json(['status' => 'failed', 'message' => 'Failed to add data!', 'code' => 500], 500);
$this->createOfficeHours($result->id); $this->createOfficeHours($result->id);
$dataResultInsert = Project::where('nama', $data['nama'])->where('mulai_proyek', $data['mulai_proyek'])->first(); $dataResultInsert = Project::where('nama', $data['nama'])->where('mulai_proyek', $data['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) || !is_int((int)$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::query() $result = Project::query()
->from('m_proyek AS mp') ->from('m_proyek AS mp')
->where('mp.id', $id) ->where('mp.id', $id)
->selectRaw('value_proyek,scoupe_of_work,kode_sortname,jumlah_stakeholder,nama,mulai_proyek,akhir_proyek,area_kerja,rencana_biaya,biaya_actual,company,pm_id,type_proyek_id,divisi_id,persentase_progress,keterangan,durasi_proyek,progress_by_worklog,currency_symbol,late_consequence,assumtion,currency_code,currency_name,project_objectives,considered_success_when,potential_risk,testing_environment,budget_health,phase_id,calculation_status'); ->selectRaw('value_proyek,scoupe_of_work,kode_sortname,jumlah_stakeholder,nama,mulai_proyek,akhir_proyek,area_kerja,rencana_biaya,biaya_actual,company,pm_id,type_proyek_id,divisi_id,persentase_progress,keterangan,durasi_proyek,progress_by_worklog,currency_symbol,late_consequence,assumtion,currency_code,currency_name,project_objectives,considered_success_when,potential_risk,testing_environment,budget_health,phase_id,calculation_status');
if (!is_null($result->first()['divisi_id'])) { if (!is_null($result->first()['divisi_id'])) {
$result->leftJoin('m_divisi', 'mp.divisi_id', '=', 'm_divisi.id') $result->leftJoin('m_divisi', 'mp.divisi_id', '=', 'm_divisi.id')
->addSelect(DB::raw('m_divisi.name AS nama_divisi')); ->addSelect(DB::raw('m_divisi.name AS nama_divisi'));
} }
$result = $result->first(); $result = $result->first();
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) || !is_int((int)$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 = 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($request->all());
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);
} }
private function createOfficeHours($proyek_id) private function createOfficeHours($proyek_id)
{ {
$dataCreate = array( $dataCreate = array(
"proyek_id"=>$proyek_id, "proyek_id" => $proyek_id,
"monday_start"=> "08:00:00", "monday_start" => "08:00:00",
"monday_end"=> "16:00:00", "monday_end" => "16:00:00",
"tuesday_start"=> "08:00:00", "tuesday_start" => "08:00:00",
"tuesday_end"=> "16:00:00", "tuesday_end" => "16:00:00",
"wednesday_start"=> "08:00:00", "wednesday_start" => "08:00:00",
"wednesday_end"=> "16:00:00", "wednesday_end" => "16:00:00",
"thursday_start"=> "08:00:00", "thursday_start" => "08:00:00",
"thursday_end"=> "16:00:00", "thursday_end" => "16:00:00",
"friday_start"=> "08:00:00", "friday_start" => "08:00:00",
"friday_end"=> "16:00:00", "friday_end" => "16:00:00",
"saturday_start"=> "08:00:00", "saturday_start" => "08:00:00",
"saturday_end"=> "16:00:00", "saturday_end" => "16:00:00",
"sunday_start"=> "08:00:00", "sunday_start" => "08:00:00",
"sunday_end"=> "16:00:00", "sunday_end" => "16:00:00",
"created_by"=> $this->currentName "created_by" => $this->currentName
); );
OfficeHours::create($dataCreate); OfficeHours::create($dataCreate);
@ -145,15 +146,15 @@ class ProjectController extends Controller
{ {
$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);
$this->deleteRelative($id); $this->deleteRelative($id);
if(!$data->delete()) if (!$data->delete())
return response()->json(['status'=>'failed','message'=>'Delete failed!','code'=> 500], 500); return response()->json(['status' => 'failed', 'message' => 'Delete failed!', 'code' => 500], 500);
return response()->json(['status'=>'success','message'=>'Data deleted!','code'=>200], 200); return response()->json(['status' => 'success', 'message' => 'Data deleted!', 'code' => 200], 200);
} }
private function deleteRelative($project_id) private function deleteRelative($project_id)
@ -168,12 +169,12 @@ class ProjectController extends Controller
ProjectChecklists::where('proyek_id', $project_id)->delete(); ProjectChecklists::where('proyek_id', $project_id)->delete();
ProjectIssues::where('proyek_id', $project_id)->delete(); ProjectIssues::where('proyek_id', $project_id)->delete();
ProjectRisks::where('proyek_id', $project_id)->delete(); ProjectRisks::where('proyek_id', $project_id)->delete();
ProjectToChecklistK3::where('proyek_id', $project_id)->delete(); ProjectToChecklistK3::where('proyek_id', $project_id)->delete();
HierarchyFtth::where('project_id', $project_id)->delete(); HierarchyFtth::where('project_id', $project_id)->delete();
AssignTools::where('proyek_id', $project_id)->delete(); AssignTools::where('proyek_id', $project_id)->delete();
OfficeHours::where('proyek_id', $project_id)->delete(); OfficeHours::where('proyek_id', $project_id)->delete();
ReportK3::where('proyek_id', $project_id)->delete(); ReportK3::where('proyek_id', $project_id)->delete();
RequestMaterial::where('proyek_id', $project_id)->delete(); RequestMaterial::where('proyek_id', $project_id)->delete();
$this->deleteVersionGantt($project_id); $this->deleteVersionGantt($project_id);
$this->deleteDokumenProject($project_id); $this->deleteDokumenProject($project_id);
} }
@ -188,16 +189,16 @@ class ProjectController extends Controller
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::where("ref_id", $ra->id)->where("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) {
if(file_exists($this->pathActivityDocument.$ad->file)){ if (file_exists($this->pathActivityDocument . $ad->file)) {
unlink($this->pathActivityDocument.$ad->file); unlink($this->pathActivityDocument . $ad->file);
} }
} }
ActivityDokumen::whereIn("activity_id", $activityIds)->delete(); ActivityDokumen::whereIn("activity_id", $activityIds)->delete();
@ -215,8 +216,8 @@ class ProjectController extends Controller
$dataDokumen = DokumenProject::where("type_dokumen", "project-document-out-folder")->where('ref_id', $project_id)->get(); $dataDokumen = DokumenProject::where("type_dokumen", "project-document-out-folder")->where('ref_id', $project_id)->get();
foreach ($dataDokumen as $dokumen) { foreach ($dataDokumen as $dokumen) {
if(file_exists($this->pathDocument.$dokumen->file)){ if (file_exists($this->pathDocument . $dokumen->file)) {
unlink($this->pathDocument.$dokumen->file); unlink($this->pathDocument . $dokumen->file);
} }
} }
DokumenProject::where("type_dokumen", "project-document-out-folder")->where('ref_id', $project_id)->delete(); DokumenProject::where("type_dokumen", "project-document-out-folder")->where('ref_id', $project_id)->delete();
@ -225,8 +226,8 @@ class ProjectController extends Controller
$ref_ids = $dataFolder->all(); $ref_ids = $dataFolder->all();
$dataDokumen = DokumenProject::where("type_dokumen", "project-document-in-folder")->whereIn('ref_id', $ref_ids)->get(); $dataDokumen = DokumenProject::where("type_dokumen", "project-document-in-folder")->whereIn('ref_id', $ref_ids)->get();
foreach ($dataDokumen as $dokumen) { foreach ($dataDokumen as $dokumen) {
if(file_exists($this->pathDocument.$dokumen->file)){ if (file_exists($this->pathDocument . $dokumen->file)) {
unlink($this->pathDocument.$dokumen->file); unlink($this->pathDocument . $dokumen->file);
} }
} }
@ -240,11 +241,11 @@ class ProjectController extends Controller
$dataBuilder = $this->setUpPayload($payload, 'm_proyek'); $dataBuilder = $this->setUpPayload($payload, 'm_proyek');
$builder = $dataBuilder['builder']; $builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count']; $countBuilder = $dataBuilder['count'];
// $builder->where("selfTable.created_by",$this->currentName); // $builder->where("selfTable.created_by",$this->currentName);
$dataGet = $builder->get(); $dataGet = $builder->get();
$totalRecord = $countBuilder->count(); $totalRecord = $countBuilder->count();
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => $totalRecord], 200);
} }
public function list() public function list()
@ -286,101 +287,116 @@ class ProjectController extends Controller
'created_by', 'created_by',
'updated_at', 'updated_at',
'updated_by' 'updated_by'
)->orderBy('id', 'desc') )->orderBy('id', 'desc')
// ->where("created_by",$this->currentName) // ->where("created_by",$this->currentName)
->get(); ->get();
$countData = $data->count(); $countData = $data->count();
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);
$totalPlannedCost = array_sum(array_map('intval', array_column($data->toArray(), 'plannedCost'))); $totalPlannedCost = array_sum(array_map('intval', array_column($data->toArray(), 'plannedCost')));
$totalActualCost = $data->sum('actualCost'); $totalActualCost = $data->sum('actualCost');
$manpowers = User::count(); $manpowers = User::count();
$projectsOnDanger = Project::where('budget_health', 'overrun')->count(); $projectsOnDanger = Project::where('budget_health', 'overrun')->count();
$projectPhases = ProjectPhase::orderBy('order', 'asc')->pluck('name'); $projectPhases = ProjectPhase::orderBy('order', 'asc')->pluck('name');
$projectTypes = ProjectType::orderBy('id', 'asc')->pluck('name'); $projectTypes = ProjectType::orderBy('id', 'asc')->pluck('name');
try { try {
$projectsByPhase = DB::table('m_proyek') $projectsByPhase = DB::table('m_proyek')
->select('m_proyek_phase.name', 'm_proyek_phase.color', DB::raw('count(*) as total')) ->select('m_proyek_phase.name', 'm_proyek_phase.color', DB::raw('count(*) as total'))
->join('m_proyek_phase', 'm_proyek_phase.id', '=', 'm_proyek.phase_id') ->join('m_proyek_phase', 'm_proyek_phase.id', '=', 'm_proyek.phase_id')
->groupBy('m_proyek_phase.name', 'm_proyek_phase.color') ->groupBy('m_proyek_phase.name', 'm_proyek_phase.color')
->get(); ->get();
} catch (\Exception $e) { } catch (\Exception $e) {
return response()->json(['message' => $e->getMessage()]); return response()->json(['message' => $e->getMessage()]);
} }
try { try {
$projectsByType = DB::table('m_proyek') $projectsByType = DB::table('m_proyek')
->select('m_type_proyek.name', DB::raw('count(m_type_proyek.id) as total')) ->select('m_type_proyek.name', DB::raw('count(m_type_proyek.id) as total'))
->join('m_type_proyek', 'm_type_proyek.id', '=', 'm_proyek.type_proyek_id') ->join('m_type_proyek', 'm_type_proyek.id', '=', 'm_proyek.type_proyek_id')
->groupBy('m_type_proyek.name') ->groupBy('m_type_proyek.name')
->get(); ->get();
} catch (\Exception $e) { } catch (\Exception $e) {
return response()->json(['message' => $e->getMessage()]); return response()->json(['message' => $e->getMessage()]);
} }
return response()->json( return response()->json(
[ [
'status'=>'success', 'status' => 'success',
'code'=>200, 'code' => 200,
'data'=>$data, 'data' => $data,
'totalRecord'=>$countData, 'totalRecord' => $countData,
'totalPlannedCost' => $totalPlannedCost, 'totalPlannedCost' => $totalPlannedCost,
'totalActualCost' => $totalActualCost, 'totalActualCost' => $totalActualCost,
'totalRevenue' => $totalPlannedCost - $totalActualCost, 'totalRevenue' => $totalPlannedCost - $totalActualCost,
'manpowers' => $manpowers, 'manpowers' => $manpowers,
'projectsOnDanger'=> $projectsOnDanger, 'projectsOnDanger' => $projectsOnDanger,
'projectPhases' => $projectPhases, 'projectPhases' => $projectPhases,
'projectsByPhase' => $projectsByPhase, 'projectsByPhase' => $projectsByPhase,
'projectTypes' => $projectTypes, 'projectTypes' => $projectTypes,
'projectsByType' => $projectsByType, 'projectsByType' => $projectsByType,
], 200); ],
200
);
} }
public function getListProjectTask($id){ public function getListProjectTask($id)
$data = UserToActivity::select("assign_hr_to_activity.user_id as user_id","m_proyek.*") {
$data = UserToActivity::select("assign_hr_to_activity.user_id as user_id", "m_proyek.*")
->where("assign_hr_to_activity.user_id", $id) ->where("assign_hr_to_activity.user_id", $id)
->join('m_proyek', 'assign_hr_to_activity.proyek_id', '=', 'm_proyek.id') ->join('m_proyek', 'assign_hr_to_activity.proyek_id', '=', 'm_proyek.id')
->groupBy("m_proyek.proyek_id") ->groupBy("m_proyek.proyek_id")
->get(); ->get();
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);
return response()->json(['status'=>'success','code'=>200,'data'=>$data], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $data], 200);
} }
public function getSCurve(Request $request){ public function getSCurve(Request $request)
{
$data = MasterFunctionsHelper::getSCurve($request); $data = MasterFunctionsHelper::getSCurve($request);
return response()->json(['status'=>'success','code'=>200, 'data' => $data], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $data], 200);
} }
public function calculateSCurve(Request $request){ // testing
$sCurve = Project::select('scurve')->where('id', $request->project_id)->first(); public function calculateSCurvetest(Request $request)
return response()->json(['status'=>'success','code'=>200, 'data' => json_decode($sCurve->scurve)], 200); {
} $data = MasterFunctionsHelper::calculateSCurve($request->project_id);
return response()->json(['status' => 'success', 'code' => 200, 'data' => $data], 200);
}
public function sCurveCommand(Request $request){ public function calculateSCurve(Request $request)
Artisan::call('calculate:scurve', [ {
'project_id' => $request->project_id $sCurve = Project::select('scurve')->where('id', $request->project_id)->first();
]); return response()->json(['status' => 'success', 'code' => 200, 'data' => json_decode($sCurve->scurve)], 200);
// $project = Project::find($request->project_id); }
// if ($project) { public function sCurveCommand(Request $request)
// dispatch(new ProcessSCurve($project)); {
Artisan::call('calculate:scurve', [
'project_id' => $request->project_id
]);
// $project = Project::find($request->project_id);
// if ($project) {
// dispatch(new ProcessSCurve($project));
// return response()->json(['message' => 'S Curve calculation queued']); // return response()->json(['message' => 'S Curve calculation queued']);
// } // }
// return response()->json(['message' => 'Project not found'], 404); // return response()->json(['message' => 'Project not found'], 404);
} }
public function getLinearSCurve(Request $request){ public function getLinearSCurve(Request $request)
{
$data = MasterFunctionsHelper::getLinearSCurve($request); $data = MasterFunctionsHelper::getLinearSCurve($request);
return response()->json(['status'=>'success','code'=>200, 'data' => $data], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $data], 200);
} }
public static function setSyncDate($activity_id, $activity, $report) { public static function setSyncDate($activity_id, $activity, $report)
{
$status = AssignMaterial::where('activity_id', $activity_id)->first(); $status = AssignMaterial::where('activity_id', $activity_id)->first();
if (!isset($status)) { if (!isset($status)) {
$reports = array( $reports = array(
@ -412,17 +428,17 @@ class ProjectController extends Controller
return $reports; return $reports;
} }
public function synchronizeReport($gantt_id) public function synchronizeReport($gantt_id)
{ {
$activities = Activity::where("version_gantt_id", $gantt_id)->get(); $activities = Activity::where("version_gantt_id", $gantt_id)->get();
$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();
foreach($dataReports as $dr) { foreach ($dataReports as $dr) {
$reports[] = ProjectController::setSyncDate($activity_id, $activity, $dr); $reports[] = ProjectController::setSyncDate($activity_id, $activity, $dr);
} }
} }
@ -443,15 +459,15 @@ class ProjectController extends Controller
/* return response()->json(['status'=>'success','data'=> $reports,'code'=>200], 200); */ /* return response()->json(['status'=>'success','data'=> $reports,'code'=>200], 200); */
/* return response()->json(['status'=>'success','data'=> $activities,'code'=>200], 200); */ /* return response()->json(['status'=>'success','data'=> $activities,'code'=>200], 200); */
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']);
if($reports[$i]['status'] != 'done'){ if ($reports[$i]['status'] != 'done') {
$reports[$i]['max_date']->modify('-1 day'); $reports[$i]['max_date']->modify('-1 day');
}else if($reports[$i]['status'] == 'done'){ } else if ($reports[$i]['status'] == 'done') {
$activity->actual_end = $reports[$i]['max_date']->setTime(23,59,59); $activity->actual_end = $reports[$i]['max_date']->setTime(23, 59, 59);
} }
$activity->start_date = $reports[$i]['min_date']; //same early $activity->start_date = $reports[$i]['min_date']; //same early
$activity->end_date = $reports[$i]['max_date']->setTime(23,59,59); // same early $activity->end_date = $reports[$i]['max_date']->setTime(23, 59, 59); // same early
$startDate = new DateTime($activity->start_date); $startDate = new DateTime($activity->start_date);
$endDate = new DateTime($activity->end_date); $endDate = new DateTime($activity->end_date);
$duration = MasterFunctionsHelper::countDays($activity->version_gantt_id, $startDate, $endDate); $duration = MasterFunctionsHelper::countDays($activity->version_gantt_id, $startDate, $endDate);
@ -460,7 +476,7 @@ class ProjectController extends Controller
$activity->save(); $activity->save();
} }
return response()->json(['status'=>'success','message'=>'Synchronize to report success!','code'=>200], 200); return response()->json(['status' => 'success', 'message' => 'Synchronize to report success!', 'code' => 200], 200);
} }
public function setBaseline($gantt_id) public function setBaseline($gantt_id)
@ -469,127 +485,139 @@ 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,
"early_start"=>$activity->start_date, "early_start" => $activity->start_date,
"early_end"=>$activity->end_date, "early_end" => $activity->end_date,
]); ]);
} }
return response()->json(['status'=>'success','message'=>'Set baseline success!','code'=> 200], 200); return response()->json(['status' => 'success', 'message' => 'Set baseline success!', 'code' => 200], 200);
} }
public function getInvoiceIntegration(Request $request) { public function getInvoiceIntegration(Request $request)
$ganttCount = VersionGantt::where('proyek_id', $request->id)->count(); {
$ganttCount = VersionGantt::where('proyek_id', $request->id)->count();
$search = urlencode($request->search); $search = urlencode($request->search);
if(empty($search)) if (empty($search))
return response()->json(['status'=>'error', 'message'=>'Empty query string!'], 400); return response()->json(['status' => 'error', 'message' => 'Empty query string!'], 400);
$url = str_replace("SEARCH", $search, config('api.adw').'/project_cost?project_no=SEARCH'); $url = str_replace("SEARCH", $search, config('api.adw') . '/project_cost?project_no=SEARCH');
$response = MasterFunctionsHelper::curlReq($url); $response = MasterFunctionsHelper::curlReq($url);
if (isset($request->gantt_id)) { if (isset($request->gantt_id)) {
$response->data->total_cost = $response->data->total_cost / $ganttCount; $response->data->total_cost = $response->data->total_cost / $ganttCount;
} }
return response()->json(['status' => 'success', 'data' => $response, 'code' => 200], 200);
}
public function getByUser($id)
{
$alias = "utp";
$userProyek = UserToProyek::query()
->from('assign_hr_to_proyek AS ' . $alias)
->where([
['is_customer', true],
['user_id', $id]
])
->leftJoin('m_users', $alias . '.user_id', '=', 'm_users.id')
->leftJoin('m_proyek', $alias . '.proyek_id', '=', 'm_proyek.id')
->leftJoin('m_type_proyek', 'm_proyek.type_proyek_id', '=', 'm_type_proyek.id')
->select('m_proyek.*', 'm_type_proyek.name AS join_second_name', 'm_users.name AS join_first_name')
->get();
$totalRecord = $userProyek->count();
return response()->json(['status'=>'success', 'data'=> $response, 'code'=>200], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $userProyek, 'totalRecord' => $totalRecord], 200);
} }
public function getByUser($id) public function detail(Request $request, $id, $gantt_id = null, $s_curve = null)
{ {
$alias = "utp"; if (empty($id) || !is_int((int)$id))
$userProyek = UserToProyek::query() return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
->from('assign_hr_to_proyek AS ' . $alias)
->where([
['is_customer', true],
['user_id', $id]
])
->leftJoin('m_users', $alias.'.user_id', '=', 'm_users.id')
->leftJoin('m_proyek', $alias.'.proyek_id', '=', 'm_proyek.id')
->leftJoin('m_type_proyek', 'm_proyek.type_proyek_id', '=', 'm_type_proyek.id')
->select('m_proyek.*', 'm_type_proyek.name AS join_second_name','m_users.name AS join_first_name')
->get();
$totalRecord = $userProyek->count();
return response()->json(['status' => 'success', 'code' => 200, 'data' => $userProyek, 'totalRecord' => $totalRecord], 200);
}
public function detail(Request $request, $id, $gantt_id = null, $s_curve = null){
if(empty($id) || !is_int((int)$id))
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);
if (!isset($gantt_id)) { if (!isset($gantt_id)) {
$gantt = MasterFunctionsHelper::getLatestGantt($id); $gantt = MasterFunctionsHelper::getLatestGantt($id);
$ganttId = $gantt['last_gantt_id']; $ganttId = $gantt['last_gantt_id'];
} else { } else {
$ganttId = $gantt_id; $ganttId = $gantt_id;
} }
$result->projectManager = User::where('id', $result->pm_id)->value('name'); $result->projectManager = User::where('id', $result->pm_id)->value('name');
if (isset($s_curve)) { if (isset($s_curve)) {
$result->header = Activity::whereNull('parent_id')->where("proyek_id", $id)->first(); $result->header = Activity::whereNull('parent_id')->where("proyek_id", $id)->first();
$actualStartExist = Activity::where('proyek_id', $id)->whereNotNull('actual_start')->exists(); $actualStartExist = Activity::where('proyek_id', $id)->whereNotNull('actual_start')->exists();
if($result['type_proyek_id'] === 9) if ($result['type_proyek_id'] === 9) {
{ // $actualEndExist = Activity::where('proyek_id', $id)->exists();
$actualEndExist = Activity::where('proyek_id', $id)->exists(); $query = Activity::where('proyek_id', $id);
$query = Activity::where('proyek_id', $id); $maxEndDate = Activity::where('proyek_id', $id)->select('end_date')
}else{ ->orderBy('end_date', 'desc')
$actualEndExist = Activity::where('version_gantt_id', $ganttId)->exists(); ->first();
$query = Activity::where('version_gantt_id', $ganttId); } else {
} // $actualEndExist = Activity::where('version_gantt_id', $ganttId)->exists();
} else { $maxEndDate = Activity::where('version_gantt_id', $ganttId)->select('end_date')
$result->header = Activity::whereNull('parent_id')->where("proyek_id", $id)->where("version_gantt_id", $ganttId)->first(); ->orderBy('end_date', 'desc')
$actualStartExist = Activity::where('version_gantt_id', $ganttId)->whereNotNull('actual_start')->exists(); ->first();
$actualEndExist = Activity::where('version_gantt_id', $ganttId)->exists(); $query = Activity::where('version_gantt_id', $ganttId);
$query = Activity::where('version_gantt_id', $ganttId); }
} } else {
$result->header = Activity::whereNull('parent_id')->where("proyek_id", $id)->where("version_gantt_id", $ganttId)->first();
if ($actualStartExist) { $actualStartExist = Activity::where('version_gantt_id', $ganttId)->whereNotNull('actual_start')->exists();
$startDate = $query->orderBy('actual_start')->value('start_date'); // $actualEndExist = Activity::where('version_gantt_id', $ganttId)->exists();
} else { $maxEndDate = Activity::where('version_gantt_id', $ganttId)->select('end_date')
$startDate = $query->orderBy('start_date')->value('start_date'); ->orderBy('end_date', 'desc')
} ->first();
if($actualEndExist) $query = Activity::where('version_gantt_id', $ganttId);
{ }
$maxEndDate = $query->max('id');
$endDate = $query->where('id',$maxEndDate)->first()->end_date; if ($actualStartExist) {
} $startDate = $query->orderBy('actual_start')->value('start_date');
} else {
$plannedStart = Activity::where('version_gantt_id', $ganttId) $startDate = $query->orderBy('start_date')->value('start_date');
->orderBy('planned_start') }
->value('planned_start'); // if($actualEndExist)
$plannedEnd = Activity::where('version_gantt_id', $ganttId) // {
->orderByDesc('planned_end') // // $maxEndDate = $query->max('id');
->value('planned_end'); // // get last end_date
$result->header->start_date = $startDate; // // $endDate = $query->where('id',$maxEndDate)->first()->end_date;
$result->header->end_date = $endDate;
$result->header->planned_start = $plannedStart; // }
$result->header->planned_end = $plannedEnd;
return response()->json(['status'=>'success','code'=> 200,'data'=>$result, 'gantt'=>$ganttId], 200); $plannedStart = Activity::where('version_gantt_id', $ganttId)
->orderBy('planned_start')
->value('planned_start');
$plannedEnd = Activity::where('version_gantt_id', $ganttId)
->orderByDesc('planned_end')
->value('planned_end');
$result->header->start_date = $startDate;
$result->header->end_date = $maxEndDate->end_date;
$result->header->planned_start = $plannedStart;
$result->header->planned_end = $plannedEnd;
return response()->json(['status' => 'success', 'code' => 200, 'data' => $result, 'gantt' => $ganttId], 200);
} }
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']) || !is_int((int)$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);
$result = Project::find($payload['id']); $result = Project::find($payload['id']);
if(!$result) if (!$result)
return response()->json(['status'=>'failed','message'=> 'Project not found!','code'=> 404], 404); return response()->json(['status' => 'failed', 'message' => 'Project not found!', 'code' => 404], 404);
//TODO possible overdue bug //TODO possible overdue bug
$endDate = Activity::where('proyek_id', $payload['id']) $endDate = Activity::where('proyek_id', $payload['id'])
->orderByDesc('end_date') ->orderByDesc('end_date')
->value('end_date'); ->value('end_date');
if(isset($payload['till_date'])) { if (isset($payload['till_date'])) {
if (isset($payload['scurve'])) { if (isset($payload['scurve'])) {
$overdueActivities = Activity::where('proyek_id', $payload['id'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->whereDate('end_date','<=',$endDate)->orderBy('end_date', 'asc')->get(); $overdueActivities = Activity::join('m_version_gantt', 'm_activity.version_gantt_id', '=', 'm_version_gantt.id')->where('m_activity.proyek_id', $payload['id'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->whereDate('end_date', '<=', $endDate)->orderBy('end_date', 'asc')->get();
} else { } else {
$overdueActivities = Activity::where('version_gantt_id', $payload['gantt'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->whereDate('end_date','<=',$endDate)->orderBy('end_date', 'asc')->get(); $overdueActivities = Activity::join('m_version_gantt', 'm_activity.version_gantt_id', '=', 'm_version_gantt.id')->where('version_gantt_id', $payload['gantt'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->whereDate('end_date', '<=', $endDate)->orderBy('end_date', 'asc')->get();
} }
} } else {
else {
if (isset($payload['scurve'])) { if (isset($payload['scurve'])) {
$overdueActivities = Activity::where('proyek_id', $payload['id'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->orderBy('end_date', 'asc')->get(); $overdueActivities = Activity::where('proyek_id', $payload['id'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->orderBy('end_date', 'asc')->get();
} else { } else {
@ -598,53 +626,75 @@ class ProjectController extends Controller
} }
$result->overdueActivities = $overdueActivities; $result->overdueActivities = $overdueActivities;
return response()->json(['status'=>'success','code'=> 200,'data'=>$result], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200);
} }
public function getReportDistribution(Request $request){ public function getReportDistribution(Request $request)
{
$payload = $request->all(); $payload = $request->all();
if(empty($payload['project_id']) || !is_int((int)$payload['project_id'])) if (empty($payload['project_id']) || !is_int((int)$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('u.name', 'a.name as activity_name', 'ama.qty_planning', 'ram.qty as qty_real','rm.description as material_name', 'rm.uom as material_unit', ->select(
'ram.lat', 'ram.lon', 'ram.description as report_notes', 'ram.report_date') 'u.name',
'a.name as activity_name',
'ama.qty_planning',
'ram.qty as qty_real',
'rm.description as material_name',
'rm.uom as material_unit',
'ram.lat',
'ram.lon',
'ram.description as report_notes',
'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']]);
return response()->json(['status'=>'success', 'code'=> 200, 'data'=> $reports], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $reports], 200);
} }
public function getManpower($proyek_id){ public function getManpower($proyek_id)
{
$manCount = UserToProyek::where('proyek_id', $proyek_id)->count(); $manCount = UserToProyek::where('proyek_id', $proyek_id)->count();
return response()->json(['totalRecord'=>$manCount]); return response()->json(['totalRecord' => $manCount]);
} }
public function getAssignedHR($gantt_id){ public function getAssignedHR($gantt_id)
{
$results = UserToActivity::select('assign_hr_to_activity.proyek_id', 'assign_hr_to_activity.user_id', 'm_activity.id', 'm_activity.name', 'm_activity.start_date', 'm_activity.end_date') $results = UserToActivity::select('assign_hr_to_activity.proyek_id', 'assign_hr_to_activity.user_id', 'm_activity.id', 'm_activity.name', 'm_activity.start_date', 'm_activity.end_date')
->join('m_activity', 'm_activity.id', '=', 'assign_hr_to_activity.activity_id') ->join('m_activity', 'm_activity.id', '=', 'assign_hr_to_activity.activity_id')
->where('assign_hr_to_activity.version_gantt_id', $gantt_id) ->where('assign_hr_to_activity.version_gantt_id', $gantt_id)
->get(); ->get();
return response()->json(['data'=>$results]); return response()->json(['data' => $results]);
} }
public function dashboard($id) public function dashboard($id)
{ {
$data = DB::table('m_proyek as mp') $data = DB::table('m_proyek as mp')
->select('mp.kode_sortname', 'mp.nama as name_project', 'mp.mulai_proyek as start', 'mp.akhir_proyek as finish', ->select(
'mp.rencana_biaya', 'mp.company', 'mp.currency_symbol', 'mu.name as pm', 'mp.budget_health') 'mp.kode_sortname',
->join('m_users as mu', 'mu.id', '=', 'mp.pm_id') 'mp.nama as name_project',
->where('mp.id', $id) 'mp.mulai_proyek as start',
->first(); 'mp.akhir_proyek as finish',
'mp.rencana_biaya',
if(!$data) 'mp.company',
return response()->json(['status'=>'failed','message'=>'Data tidak ditemukan!','code'=> 404], 404); 'mp.currency_symbol',
'mu.name as pm',
'mp.budget_health'
)
->join('m_users as mu', 'mu.id', '=', 'mp.pm_id')
->where('mp.id', $id)
->first();
if (!$data)
return response()->json(['status' => 'failed', 'message' => 'Data tidak ditemukan!', 'code' => 404], 404);
$manpowers = UserToProyek::where('proyek_id', $id)->count(); $manpowers = UserToProyek::where('proyek_id', $id)->count();
$rootActivity = Activity::whereNull('parent_id')->where('proyek_id', $id)->orderBy('version_gantt_id', 'desc')->first(); $rootActivity = Activity::whereNull('parent_id')->where('proyek_id', $id)->orderBy('version_gantt_id', 'desc')->first();
@ -653,38 +703,42 @@ class ProjectController extends Controller
$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('mca.activity_id', 'mca.comment as comment', 'mca.created_by as comment_by', 'mca.created_at as comment_created', ->select(
'ma.name as activity') 'mca.activity_id',
->join('m_activity as ma', 'ma.id', '=', 'mca.activity_id') 'mca.comment as comment',
->where('ma.proyek_id', $id) 'mca.created_by as comment_by',
->orderBy('comment_by') 'mca.created_at as comment_created',
->take(2) 'ma.name as activity'
->get(); )
->join('m_activity as ma', 'ma.id', '=', 'mca.activity_id')
->where('ma.proyek_id', $id)
->orderBy('comment_by')
->take(2)
->get();
$data->actual_cost = $actualCost; $data->actual_cost = $actualCost;
$data->progress = $progress; $data->progress = $progress;
$data->comment = $commentActivity; $data->comment = $commentActivity;
$data->man_power = $manpowers; $data->man_power = $manpowers;
return response()->json(['status'=>'success','code'=>200,'data'=> $data], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $data], 200);
} }
private function httpReq($search){ private function httpReq($search)
$ch = curl_init(); {
curl_setopt($ch, CURLOPT_URL, str_replace("ADDR", $search, API_GEOLOCATION)); $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, str_replace("ADDR", $search, API_GEOLOCATION));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, true); curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_STDERR, fopen('php://stderr', 'w')); curl_setopt($ch, CURLOPT_STDERR, fopen('php://stderr', 'w'));
$info = curl_getinfo($ch); $info = curl_getinfo($ch);
$output = curl_exec($ch); $output = curl_exec($ch);
curl_close($ch); curl_close($ch);
return json_decode($output); return json_decode($output);
} }
} }

2
app/Models/Project.php

@ -23,8 +23,10 @@ class Project extends Model
'biaya_actual', 'biaya_actual',
'company', 'company',
'pm_id', 'pm_id',
'scoupe_of_work',
'type_proyek_id', 'type_proyek_id',
'divisi_id', 'divisi_id',
'value_proyek',
'persentase_progress', 'persentase_progress',
'keterangan', 'keterangan',
'durasi_proyek', 'durasi_proyek',

Loading…
Cancel
Save