Browse Source

Merge pull request 'Upload 2023-10-27' (#231) from staging into master

Reviewed-on: ordo/adw-backend#231
pull/3/head
farhantock 1 year ago
parent
commit
3bf8110bad
  1. 11
      app/Helpers/MasterFunctionsHelper.php
  2. 27
      app/Http/Controllers/ActivityController.php
  3. 2
      app/Http/Controllers/Controller.php
  4. 37
      app/Http/Controllers/DashboardBoDController.php
  5. 540
      app/Http/Controllers/ReportActivityController.php
  6. 7
      app/Http/Controllers/UserToActivityController.php
  7. 12
      app/Models/Activity.php
  8. 16
      app/Models/HierarchyFtth.php
  9. 7
      app/Models/VersionGantt.php
  10. 1
      routes/web.php

11
app/Helpers/MasterFunctionsHelper.php

@ -402,8 +402,9 @@ class MasterFunctionsHelper
// if($tempTtlPercentActual >= $keyGantt['progress']) // if($tempTtlPercentActual >= $keyGantt['progress'])
// $tempTtlPercentActual = $keyGantt['progress']; // $tempTtlPercentActual = $keyGantt['progress'];
if ($tempTtlPercentPlan >= 100) // todo
$tempTtlPercentPlan = 100; // if ($tempTtlPercentPlan >= 100)
// $tempTtlPercentPlan = 100;
// $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual // $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual
// } // }
@ -707,6 +708,9 @@ class MasterFunctionsHelper
if (isset($dataPayload['period']) && $dataPayload['period'] == 'week') { if (isset($dataPayload['period']) && $dataPayload['period'] == 'week') {
$tempTtlPercentPlan += $sumPercentagePlan; $tempTtlPercentPlan += $sumPercentagePlan;
$tempTtlPercentActual += $sumPercentageActual; $tempTtlPercentActual += $sumPercentageActual;
// todo
// if ($tempTtlPercentPlan >= 100)
// $tempTtlPercentPlan = 100;
$currentACWP += $totalACWP; $currentACWP += $totalACWP;
$currentBCWP += $totalBCWP; $currentBCWP += $totalBCWP;
@ -715,6 +719,9 @@ class MasterFunctionsHelper
$tempPercentagePlan[] = round($tempTtlPercentPlan, 2); $tempPercentagePlan[] = round($tempTtlPercentPlan, 2);
$tempPercentagePlanWhr[] = ["weekly period", $tempPercentagePlan]; $tempPercentagePlanWhr[] = ["weekly period", $tempPercentagePlan];
$tempPercentageReal[] = round($tempTtlPercentActual, 2); $tempPercentageReal[] = round($tempTtlPercentActual, 2);
if ($tempTtlPercentPlan >= 100 && $tempTtlPercentActual >= 100) {
break;
}
} else { } else {
$tempPercentage[] = array(round($sumPercentagePlan, 2), round($sumPercentageActual, 2)); $tempPercentage[] = array(round($sumPercentagePlan, 2), round($sumPercentageActual, 2));
$tempPercentagePlan[] = round($sumPercentagePlan, 2); $tempPercentagePlan[] = round($sumPercentagePlan, 2);

27
app/Http/Controllers/ActivityController.php

@ -527,14 +527,39 @@ class ActivityController extends Controller
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 searchAnalysisPrep(Request $request)
{
$data = $request->all();
$dataGet = DB::table('m_activity')
->select('m_activity.name')
->where('m_activity.proyek_id', $data['columns'][0]['value'])
->where('m_activity.type_activity', 'task')
->where('m_activity.persentase_progress', '>', 0)
->groupByRaw('m_activity.name')
->get();
return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet ], 200);
}
public function searchAnalysis(Request $request) public function searchAnalysis(Request $request)
{ {
$dataBuilder = $this->setUpPayload($request->all(), 'm_activity'); $dataBuilder = $this->setUpPayload($request->all(), 'm_activity');
$builder = $dataBuilder['builder']; $builder = $dataBuilder['builder'];
$dataGet = $builder->select('selfTable.*','m_version_gantt.name_version', 'm_users.name as user_name') $dataGet = $builder->select( 'selfTable.name', 'persentase_progress',
'm_version_gantt.name_version', 'm_users.name as user_name',
DB::raw('SUM(report_activity_material.qty) as qty'), 'assign_material_to_activity.qty_planning',
'assign_material_to_activity.id as join_third_id')
->join('m_version_gantt', 'm_version_gantt.id', '=', 'selfTable.version_gantt_id') ->join('m_version_gantt', 'm_version_gantt.id', '=', 'selfTable.version_gantt_id')
->join('assign_hr_to_activity', 'assign_hr_to_activity.activity_id', '=', 'selfTable.id') ->join('assign_hr_to_activity', 'assign_hr_to_activity.activity_id', '=', 'selfTable.id')
->join('m_users', 'assign_hr_to_activity.user_id', '=', 'm_users.id') ->join('m_users', 'assign_hr_to_activity.user_id', '=', 'm_users.id')
->join('report_activity_material', 'report_activity_material.activity_id', '=', 'selfTable.id')
->join('assign_material_to_activity', 'assign_material_to_activity.activity_id', '=', 'selfTable.id')
->groupBy("selfTable.id")
->groupBy("selfTable.name")
->groupBy("selfTable.persentase_progress")
->groupBy("m_version_gantt.name_version")
->groupBy("m_users.name")
->groupBy("assign_material_to_activity.qty_planning")
->groupBy("assign_material_to_activity.id")
->get(); ->get();
return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet ], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet ], 200);
} }

2
app/Http/Controllers/Controller.php

@ -54,11 +54,13 @@ class Controller extends BaseController
$tableName = $join['name']; $tableName = $join['name'];
$columnJoin = $join['column_join']; // foreign key table sini $columnJoin = $join['column_join']; // foreign key table sini
$columnSelf = isset($join['column_self']) ? $join['column_self'] : "id"; // primary key table lawan $columnSelf = isset($join['column_self']) ? $join['column_self'] : "id"; // primary key table lawan
if (isset($join['column_results'])) {
$columnResult = $join['column_results']; $columnResult = $join['column_results'];
foreach($columnResult as $sColumn){ foreach($columnResult as $sColumn){
$builder = $builder->addSelect($tableName.".".$sColumn." as join_".$this->listJoinAll[$no]."_".$sColumn); $builder = $builder->addSelect($tableName.".".$sColumn." as join_".$this->listJoinAll[$no]."_".$sColumn);
} }
}
$builder = $builder->leftJoin($tableName, $tableJoin.".".$columnJoin, '=', $tableName.'.'.$columnSelf); $builder = $builder->leftJoin($tableName, $tableJoin.".".$columnJoin, '=', $tableName.'.'.$columnSelf);
$no++; $no++;
} }

37
app/Http/Controllers/DashboardBoDController.php

@ -133,7 +133,7 @@ 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 $index => $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]) {
@ -144,12 +144,18 @@ class DashboardBoDController extends Controller
} }
$selisihProgress = $planningProgress - $actualProgress; $selisihProgress = $planningProgress - $actualProgress;
try { try {
if ($selisihProgress > 0 && $selisihProgress <= 5) if ($selisihProgress > 0 && $selisihProgress <= 5){
$return['warning'] += 1; $return['warning'] += 1;
elseif ($selisihProgress == 0) $projects[$index]->status = 'warning';
}
elseif ($selisihProgress == 0){
$return['on-schedule'] += 1; $return['on-schedule'] += 1;
else $projects[$index]->status = 'on-schedule';
}
else {
$return['behind-schedule'] += 1; $return['behind-schedule'] += 1;
$projects[$index]->status = 'behind-schedule';
}
} catch (\Error $e) { } catch (\Error $e) {
return response()->json(['msg' => $e->getMessage(), 'data' => $project], 200); return response()->json(['msg' => $e->getMessage(), 'data' => $project], 200);
} }
@ -163,7 +169,7 @@ class DashboardBoDController extends Controller
$year = $this->interpolateYear($year); $year = $this->interpolateYear($year);
$divisions = Divisi::whereNull('parent')->get(); $divisions = Divisi::whereNull('parent')->get();
foreach ($divisions as $division) { foreach ($divisions as $index => $division) {
$scheduleData = new Collection(); $scheduleData = new Collection();
$behindSchedule = $warning = $onSchedule = 0; $behindSchedule = $warning = $onSchedule = 0;
@ -171,18 +177,29 @@ class DashboardBoDController extends Controller
$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) $selisihProgress = 0;
if ($project->scurve && $project->scurve[0]) {
$planningArray = $project->scurve[0]['data']['percentagePlan'];
$actualArray = $project->scurve[0]['data']['percentageReal'];
$planningProgress = !empty($planningArray) ? $planningArray[count($planningArray) - 1] : 0;
$actualProgress = !empty($actualArray) ? $actualArray[count($actualArray) - 1] : 0;
}
$selisihProgress = $planningProgress - $actualProgress;
if ($selisihProgress > 0 && $selisihProgress <= 5){
$warning++; $warning++;
elseif (@$project->scurve['difference'] > 5 && @$project->scurve['difference'] <= 100) }
$behindSchedule++; elseif ($selisihProgress == 0){
elseif (@$project->scurve['difference'] == 0)
$onSchedule++; $onSchedule++;
}
else {
$behindSchedule++;
}
} }
$scheduleData->prepend($behindSchedule, 'behindSchedule'); $scheduleData->prepend($behindSchedule, 'behindSchedule');
$scheduleData->prepend($warning, 'warning'); $scheduleData->prepend($warning, 'warning');
$scheduleData->prepend($onSchedule, 'onSchedule'); $scheduleData->prepend($onSchedule, 'onSchedule');
$division->scheduleData = $scheduleData; $divisions[$index]->scheduleData = $scheduleData;
} }
return response()->json([ return response()->json([
'data' => [ 'data' => [

540
app/Http/Controllers/ReportActivityController.php

@ -1,270 +1,270 @@
<?php <?php
namespace App\Http\Controllers; namespace App\Http\Controllers;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\ReportActivity; use App\Models\ReportActivity;
use App\Models\Activity; use App\Models\Activity;
use App\Models\Image; use App\Models\Image;
use Datatables; use Datatables;
class ReportActivityController extends Controller class ReportActivityController extends Controller
{ {
public function add(Request $request) public function add(Request $request)
{ {
if($request->has('gantt')){ if($request->has('gantt')){
$this->validate($request, [ $this->validate($request, [
'activity_id' => 'required', 'activity_id' => 'required',
'user_id' => 'required', 'user_id' => 'required',
'report_date' => 'required', 'report_date' => 'required',
'job_count_report' => 'required' 'job_count_report' => 'required'
]); ]);
}else{ }else{
$this->validate($request, [ $this->validate($request, [
'activity_id' => 'required', 'activity_id' => 'required',
'user_id' => 'required', 'user_id' => 'required',
'report_date' => 'required', 'report_date' => 'required',
'job_count_report' => 'required', 'job_count_report' => 'required',
'lat' => 'required', 'lat' => 'required',
'lon' => 'required', 'lon' => 'required',
]); ]);
} }
$data = $request->all(); $data = $request->all();
$data['created_by'] = $this->currentName; $data['created_by'] = $this->currentName;
$result = ReportActivity::create($data); $result = ReportActivity::create($data);
if($result){ if($result){
$this->countForProgress($request->activity_id); $this->countForProgress($request->activity_id);
if($request->hasFile("files")){ if($request->hasFile("files")){
$this->uploadImage($request->file('files'), $result->id); $this->uploadImage($request->file('files'), $result->id);
} }
return response()->json(['status'=>'success','message'=>'add report activity, update progress activity successfully!','code'=>200,'last_inserted_id'=>$result->id], 200); return response()->json(['status'=>'success','message'=>'add report activity, update progress activity successfully!','code'=>200,'last_inserted_id'=>$result->id], 200);
}else{ }else{
return response()->json(['status'=>'failed','message'=>'add report activity failed!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'add report activity failed!','code'=>400], 400);
} }
} }
private function uploadImage($files, $ref_id) private function uploadImage($files, $ref_id)
{ {
$dokumen = $files; $dokumen = $files;
$extension = $dokumen->extension(); $extension = $dokumen->extension();
$name = $ref_id.date("YmdHis").".".$extension; $name = $ref_id.date("YmdHis").".".$extension;
$resultMove = $dokumen->move($this->pathImage, $name); $resultMove = $dokumen->move($this->pathImage, $name);
if($resultMove){ if($resultMove){
$data = [ $data = [
'ref_id' => (int)$ref_id, 'ref_id' => (int)$ref_id,
'image' => $name, 'image' => $name,
'category' => "report_activity" 'category' => "report_activity"
]; ];
$result = Image::create($data); $result = Image::create($data);
if($result){ if($result){
return true; return true;
} }
} }
} }
public function edit($id){ public function edit($id){
if(!$id || (int) $id < 0 || $id==""){ if(!$id || (int) $id < 0 || $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(); die();
} }
$result = ReportActivity::select("report_activity.*", "u.name as user_name")->where("report_activity.id", $id)->join("m_users as u", "u.id", "=", "report_activity.user_id")->first(); $result = ReportActivity::select("report_activity.*", "u.name as user_name")->where("report_activity.id", $id)->join("m_users as u", "u.id", "=", "report_activity.user_id")->first();
if($result){ if($result){
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200);
}else{ }else{
return response()->json(['status'=>'failed','message'=>'failed get data report activity, please try again later!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'failed get data report activity, please try again later!','code'=>400], 400);
} }
} }
public function update(Request $request, $id) public function update(Request $request, $id)
{ {
if(!$id || (int) $id < 0 || $id==""){ if(!$id || (int) $id < 0 || $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 = ReportActivity::find($id); $data = ReportActivity::find($id);
if($data){ if($data){
$dataUpdate = $request->all(); $dataUpdate = $request->all();
$result = $data->update($dataUpdate); $result = $data->update($dataUpdate);
if($result){ if($result){
if($request->hasFile("files")){ if($request->hasFile("files")){
$this->updateImage($request->file('files'), $id); $this->updateImage($request->file('files'), $id);
} }
$this->countForProgress($data->activity_id); $this->countForProgress($data->activity_id);
return response()->json(['status'=>'success','message'=>'data report activity successfully updated!','code'=>200], 200); return response()->json(['status'=>'success','message'=>'data report activity successfully updated!','code'=>200], 200);
}else{ }else{
return response()->json(['status'=>'failed','message'=>'data report activity failed updated!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'data report activity failed updated!','code'=>400], 400);
} }
}else{ }else{
return response()->json(['status'=>'failed','message'=>'data report activity not found!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'data report activity not found!','code'=>400], 400);
die(); die();
} }
} }
public function updateImage($files, $ref_id) public function updateImage($files, $ref_id)
{ {
$image = Image::where("ref_id", $ref_id)->where("category", "report_activity")->first(); $image = Image::where("ref_id", $ref_id)->where("category", "report_activity")->first();
if($image){ if($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->delete(); $image->delete();
} }
$dokumen = $files; $dokumen = $files;
$extension = $dokumen->extension(); $extension = $dokumen->extension();
$name = $ref_id.date("YmdHis").".".$extension; $name = $ref_id.date("YmdHis").".".$extension;
$resultMove = $dokumen->move($this->pathImage, $name); $resultMove = $dokumen->move($this->pathImage, $name);
if($resultMove){ if($resultMove){
$data = [ $data = [
'ref_id' => (int)$ref_id, 'ref_id' => (int)$ref_id,
'image' => $name, 'image' => $name,
'category' => "report_activity" 'category' => "report_activity"
]; ];
$result = Image::create($data); $result = Image::create($data);
if($result){ if($result){
return true; return true;
} }
} }
} }
public function delete($id) public function delete($id)
{ {
$data = ReportActivity::find($id); $data = ReportActivity::find($id);
if($data){ if($data){
$delete = $data->delete(); $delete = $data->delete();
}else{ }else{
return response()->json(['status'=>'failed','message'=>'data report activity not found!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'data report activity not found!','code'=>400], 400);
die(); die();
} }
if($delete){ if($delete){
$image = Image::where("ref_id", $id)->where("category", "report_activity")->first(); $image = Image::where("ref_id", $id)->where("category", "report_activity")->first();
if($image){ if($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->delete(); $image->delete();
} }
return response()->json(['status'=>'success','message'=>'data report activity successfully deleted!','code'=>200], 200); return response()->json(['status'=>'success','message'=>'data report activity successfully deleted!','code'=>200], 200);
}else{ }else{
return response()->json(['status'=>'failed','message'=>'data report activity failed deleted!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'data report activity failed deleted!','code'=>400], 400);
} }
} }
private function countForProgress($id) private function countForProgress($id)
{ {
$totalJobs = ReportActivity::where('activity_id', $id)->sum("job_count_report"); $totalJobs = ReportActivity::where('activity_id', $id)->sum("job_count_report");
$dataActivity = Activity::find($id); $dataActivity = Activity::find($id);
$jobsActivity = (int)$dataActivity->jumlah_pekerjaan; $jobsActivity = (int)$dataActivity->jumlah_pekerjaan;
if ($jobsActivity < 1) { if ($jobsActivity < 1) {
return false; return false;
} }
if ($totalJobs < 1) { if ($totalJobs < 1) {
return false; return false;
} }
$persentaseActual = ($totalJobs/$jobsActivity)*100; $persentaseActual = ($totalJobs/$jobsActivity)*100;
$dataUpdate = array( $dataUpdate = array(
"persentase_progress" => $persentaseActual, "persentase_progress" => $persentaseActual,
"updated_by" => $this->currentName "updated_by" => $this->currentName
); );
return $dataActivity->update($dataUpdate); return $dataActivity->update($dataUpdate);
} }
public function search(Request $request) public function search(Request $request)
{ {
$payload = $request->all(); $payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'report_activity'); $dataBuilder = $this->setUpPayload($payload, 'report_activity');
$builder = $dataBuilder['builder']; $builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count']; $countBuilder = $dataBuilder['count'];
$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()
{ {
$data = ReportActivity::all(); $data = ReportActivity::all();
$countData = $data->count(); $countData = $data->count();
if($data){ if($data){
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200);
}else{ }else{
return response()->json(['status'=>'failed','message'=>'failed get list report activity, please try again later!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'failed get list report activity, please try again later!','code'=>400], 400);
} }
} }
public function searchPoint(Request $request) { public function searchPoint(Request $request) {
$dataPayload = $request->all(); $dataPayload = $request->all();
$reqActivityId = []; $reqActivityId = [];
foreach ($dataPayload['project_id'] as $val) { foreach ($dataPayload['project_id'] as $val) {
$reqActivityId[] = $this->getActivityByProjectId($val); $reqActivityId[] = $this->getActivityByProjectId($val);
} }
$activity_id = []; $activity_id = [];
$getPoints = false; $getPoints = false;
if (count($reqActivityId) > 0) { if (count($reqActivityId) > 0) {
for ($i=0; $i < count($reqActivityId); $i++) { for ($i=0; $i < count($reqActivityId); $i++) {
if (count($reqActivityId[$i]) > 0) { if (count($reqActivityId[$i]) > 0) {
foreach($reqActivityId[$i] as $reqAct) { foreach($reqActivityId[$i] as $reqAct) {
array_push($activity_id, $reqAct->id); array_push($activity_id, $reqAct->id);
} }
} }
} }
} }
if (count($activity_id) > 0) { if (count($activity_id) > 0) {
$getPoints = ReportActivity::select('report_activity.*', 'm_activity.name as activity_name', 'm_activity.jumlah_pekerjaan', 'm_proyek.nama as proyek_name') $getPoints = ReportActivity::select('report_activity.*', 'm_activity.name as activity_name', 'm_activity.jumlah_pekerjaan', 'm_proyek.nama as proyek_name')
->leftJoin('m_activity', 'm_activity.id', '=', 'report_activity.activity_id') ->leftJoin('m_activity', 'm_activity.id', '=', 'report_activity.activity_id')
->leftJoin('m_proyek', 'm_proyek.id', '=', 'm_activity.proyek_id') ->leftJoin('m_proyek', 'm_proyek.id', '=', 'm_activity.proyek_id')
->whereIn('report_activity.activity_id', $activity_id)->get(); ->whereIn('report_activity.activity_id', $activity_id)->get();
} }
if($getPoints){ if($getPoints){
return response()->json(['status'=>'success','code'=>200,'data'=>$getPoints, 'totalRecord'=>count($getPoints)], 200); return response()->json(['status'=>'success','code'=>200,'data'=>$getPoints, 'totalRecord'=>count($getPoints)], 200);
}else{ }else{
return response()->json(['status'=>'failed','message'=>'failed get list points, please try again later!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'failed get list points, please try again later!','code'=>400], 400);
} }
} }
public function getActivityByProjectId($projectId) { public function getActivityByProjectId($projectId) {
$data = Activity::select('id')->where('proyek_id', $projectId)->get(); $data = Activity::select('id')->where('proyek_id', $projectId)->get();
return $data; return $data;
} }
public function datatables(Request $request){ public function datatables(Request $request){
$id_activity = $request->query('idact'); $id_activity = $request->query('idact');
$data = ReportActivity::select("report_activity.*", "u.name as user_name") $data = ReportActivity::select("report_activity.*", "u.name as user_name")
->join("m_users as u", "u.id", "=", "report_activity.user_id") ->join("m_users as u", "u.id", "=", "report_activity.user_id")
->where('report_activity.activity_id', $id_activity) ->where('report_activity.activity_id', $id_activity)
->get(); ->get();
return Datatables::of($data) return Datatables::of($data)
->addIndexColumn() ->addIndexColumn()
->addColumn('action', function($row){ ->addColumn('action', function($row){
$actionBtn = '<a href="javascript:void(0)" data-id="'.$row->id.'" class="delete btn btn-danger btn-sm btn_report_delete"><i class="fa fa-trash"></i></a>'; $actionBtn = '<a href="javascript:void(0)" data-id="'.$row->id.'" class="delete btn btn-danger btn-sm btn_report_delete"><i class="fa fa-trash"></i></a>';
$actionBtn .= ' <a href="javascript:void(0)" data-id="'.$row->id.'" class="edit btn btn-primary btn-sm btn_report_edit"><i class="fa fa-edit"></i></a>'; $actionBtn .= ' <a href="javascript:void(0)" data-id="'.$row->id.'" class="edit btn btn-primary btn-sm btn_report_edit"><i class="fa fa-edit"></i></a>';
return $actionBtn; return $actionBtn;
}) })
->editColumn('report_date', function($row) { ->editColumn('report_date', function($row) {
$date = date_create($row->report_date); $date = date_create($row->report_date);
return date_format($date,"d-m-Y H:i:s"); return date_format($date,"d-m-Y H:i:s");
}) })
->rawColumns(['action'])->make(true); ->rawColumns(['action'])->make(true);
} }
} }

7
app/Http/Controllers/UserToActivityController.php

@ -6,6 +6,7 @@ use Illuminate\Http\Request;
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 Illuminate\Support\Facades\DB;
use Datatables; use Datatables;
class UserToActivityController extends Controller class UserToActivityController extends Controller
@ -134,6 +135,12 @@ class UserToActivityController extends Controller
$dataBuilder = $this->setUpPayload($request->all(), 'assign_hr_to_activity'); $dataBuilder = $this->setUpPayload($request->all(), 'assign_hr_to_activity');
$builder = $dataBuilder['builder']; $builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count']; $countBuilder = $dataBuilder['count'];
$builder->addSelect(DB::raw('SUM(report_activity_material.qty) as volume_actual'));
$builder->groupBy("m_activity.id");
$builder->groupBy("selfTable.id");
$builder->groupBy("m_users.name");
$builder->groupBy("assign_material_to_activity.id");
$builder->groupBy("m_version_gantt.name_version");
$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);

12
app/Models/Activity.php

@ -79,8 +79,14 @@ class Activity extends Model
}); });
static::deleted(function($data) { static::deleted(function($data) {
if(Activity::where("parent_id", $data->parent_id)->count() == 0) if (isset($data->parent_id)) {
Activity::find($data->parent_id)->update(["type_activity"=>"task"]); if(Activity::where("parent_id", $data->parent_id)->count() == 0) {
$activity = Activity::find($data->parent_id);
if ($activity) {
$activity->update(["type_activity"=>"task"]);
}
}
}
$data->updateBobot(true); $data->updateBobot(true);
$data->updateCostPlanning(); $data->updateCostPlanning();
@ -100,7 +106,7 @@ class Activity extends Model
->whereNull('parent_id') ->whereNull('parent_id')
->first(); ->first();
if($root->rencana_biaya > 0){ if(isset($root) && $root->rencana_biaya > 0){
$activities = Activity::where("proyek_id", $this->proyek_id)->where("version_gantt_id", $this->version_gantt_id)->get(); $activities = Activity::where("proyek_id", $this->proyek_id)->where("version_gantt_id", $this->version_gantt_id)->get();
foreach ($activities as $activity) { foreach ($activities as $activity) {
if($isDelete && $activity->id == $this->id) if($isDelete && $activity->id == $this->id)

16
app/Models/HierarchyFtth.php

@ -3,6 +3,7 @@
namespace App\Models; namespace App\Models;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use App\Models\VersionGantt;
class HierarchyFtth extends Model class HierarchyFtth extends Model
{ {
@ -14,15 +15,20 @@ class HierarchyFtth extends Model
protected $fillable = [ protected $fillable = [
'name', 'parent_id', 'project_id', 'created_at', 'updated_at', 'progress', 'bobot_planning' 'name', 'parent_id', 'project_id', 'created_at', 'updated_at', 'progress', 'bobot_planning'
]; ];
public static function boot() { public static function boot() {
parent::boot(); parent::boot();
static::deleted(function($data) { static::deleted(function($data) {
$ftths = HierarchyFtth::where('parent_id', $data->id)->get(); $ftths = HierarchyFtth::where('parent_id', $data->id)->get();
foreach ($ftths as $ftth) { foreach ($ftths as $ftth) {
$ftth->delete(); $ftth->delete();
} }
$gantts = VersionGantt::where('hierarchy_ftth_id', $data->id)->get();
foreach ($gantts as $gantt) {
$gantt->delete();
}
}); });
} }
} }

7
app/Models/VersionGantt.php

@ -38,6 +38,13 @@ class VersionGantt extends Model
static::updated(function($data) { static::updated(function($data) {
$data->updateActDuration(); $data->updateActDuration();
});
static::deleted(function ($data) {
$activities = Activity::where('version_gantt_id', $data->id)->get();
foreach ($activities as $activity) {
$activity->delete();
}
}); });
} }

1
routes/web.php

@ -207,6 +207,7 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout
$router->get('/activity/{id}/{proyek_id}/get', 'ActivityController@getByGanttId'); $router->get('/activity/{id}/{proyek_id}/get', 'ActivityController@getByGanttId');
$router->post('/activity/search', 'ActivityController@search'); $router->post('/activity/search', 'ActivityController@search');
$router->post('/activity/search-analysis', 'ActivityController@searchAnalysis'); $router->post('/activity/search-analysis', 'ActivityController@searchAnalysis');
$router->post('/activity/search-analysis-prep', 'ActivityController@searchAnalysisPrep');
$router->post('/activity/import', 'ActivityController@import'); $router->post('/activity/import', 'ActivityController@import');
$router->post('/activity/import-update', 'ActivityController@importUpdate'); $router->post('/activity/import-update', 'ActivityController@importUpdate');
$router->post('/activity/import-old', 'ActivityController@importOld'); $router->post('/activity/import-old', 'ActivityController@importOld');

Loading…
Cancel
Save