@ -6,8 +6,7 @@ use Illuminate\Http\Request;
use App\Models\Project;
use App\Models\Project;
use App\Models\Activity;
use App\Models\Activity;
use App\Models\ReportActivity;
use App\Models\ReportActivity;
use App\Models\UserToActivity;
use App\Models\Role;
use DB;
class DashboardController extends Controller
class DashboardController extends Controller
{
{
@ -25,11 +24,10 @@ class DashboardController extends Controller
$dataFinal[] = array("proyek_id" => $val['proyek_id'], "proyek_name" => isset($data) & & count($data) > 0 ? $data[0]['proyek_name'] : "-", "version_gantt_id" => $val['last_version_gantt'], "data" => $data);
$dataFinal[] = array("proyek_id" => $val['proyek_id'], "proyek_name" => isset($data) & & count($data) > 0 ? $data[0]['proyek_name'] : "-", "version_gantt_id" => $val['last_version_gantt'], "data" => $data);
}
}
if($dataPayload){
if(!$dataFinal)
return response()->json(['status'=>'failed','message'=>'Data not found','code'=> 404], 404);
return response()->json(['status'=>'success','code'=>200,'data'=>$dataFinal, 'totalRecord'=>1], 200);
return response()->json(['status'=>'success','code'=>200,'data'=>$dataFinal, 'totalRecord'=>1], 200);
}else{
return response()->json(['status'=>'failed','message'=>'failed get list role, please try again later!','code'=>400], 400);
}
}
}
public function getMaxVersionGantt($id){
public function getMaxVersionGantt($id){
@ -48,14 +46,12 @@ class DashboardController extends Controller
foreach ($dataMaxVersionGantt as $val) {
foreach ($dataMaxVersionGantt as $val) {
$data = Activity::select('m_activity.id', 'm_activity.proyek_id', 'm_activity.name', 'm_activity.kode_sortname', 'm_activity.persentase_progress', 'm_activity.persentase_bobot', 'm_activity.bobot_planning', 'mp.nama as proyek_name')->join("m_proyek as mp", "m_activity.proyek_id", "=", "mp.id")->where('proyek_id', $val['proyek_id'])->where('version_gantt_id', $val['last_version_gantt'])->whereNull('parent_id')->orderBy('id', 'asc')->get();
$data = Activity::select('m_activity.id', 'm_activity.proyek_id', 'm_activity.name', 'm_activity.kode_sortname', 'm_activity.persentase_progress', 'm_activity.persentase_bobot', 'm_activity.bobot_planning', 'mp.nama as proyek_name')->join("m_proyek as mp", "m_activity.proyek_id", "=", "mp.id")->where('proyek_id', $val['proyek_id'])->where('version_gantt_id', $val['last_version_gantt'])->whereNull('parent_id')->orderBy('id', 'asc')->get();
$dataFinal[] = array("proyek_id" => $val['proyek_id'], "proyek_name" => isset($data) & & count($data) > 0 ? $data[0]['proyek_name'] : "-", "version_gantt_id" => $val['last_version_gantt'], "data" => $data);
$dataFinal[] = array("proyek_id" => $val['proyek_id'], "proyek_name" => isset($data) & & count($data) > 0 ? $data[0]['proyek_name'] : "-", "version_gantt_id" => $val['last_version_gantt'], "data" => $data);
}
}
if($dataPayload){
if(!$dataFinal)
return response()->json(['status'=>'success','code'=>200,'data'=>$dataFinal, 'totalRecord'=>1], 200);
}else{
return response()->json(['status'=>'failed','message'=>'failed get list role, please try again later!','code'=>400], 400);
return response()->json(['status'=>'failed','message'=>'failed get list role, please try again later!','code'=>400], 400);
}
return response()->json(['status'=>'success','code'=>200,'data'=>$dataFinal, 'totalRecord'=>1], 200);
}
}
public function list()
public function list()
@ -63,30 +59,22 @@ class DashboardController extends Controller
$data = Role::all();
$data = Role::all();
$countData = $data->count();
$countData = $data->count();
if($data){
if(!$data)
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200);
}else{
return response()->json(['status'=>'failed','message'=>'failed get list role, please try again later!','code'=>400], 400);
return response()->json(['status'=>'failed','message'=>'failed get list role, please try again later!','code'=>400], 400);
}
}
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200);
}
public function getActivityByProjectId($projectId) {
public function getActivityByProjectId($projectId) {
$output = [];
$output = [];
$data = Activity::select('id')->where('proyek_id', $projectId)->get();
$data = Activity::select('id')->where('proyek_id', $projectId)->get();
if (count($data) > 0) {
foreach ($data as $actData) {
foreach ($data as $actData) {
$output[] = $actData->id;
$output[] = $actData->id;
}
}
}
return $output;
return $output;
}
}
/* for statusProyek, I want something output like this
/*
const statusProyek = [
const statusProyek = [
{
{
"id": "1",
"id": "1",
@ -109,17 +97,14 @@ class DashboardController extends Controller
*/
*/
public function statusProyek(Request $request) {
public function statusProyek(Request $request) {
$dataPayload = $request->all();
$dataPayload = $request->all();
$reqProject = [];
$reqProject = $dataFinal = [];
$dataFinal = [];
if (!isset($dataPayload['project_id'])) {
if (!isset($dataPayload['project_id']))
return response()->json(['status'=>'failed','message'=>'Undefined project_id','code'=>400], 400);
return response()->json(['status'=>'failed','message'=>'Undefined project_id','code'=>400], 400);
}
foreach ($dataPayload['project_id'] as $val) {
foreach ($dataPayload['project_id'] as $val) {
$prj["project_id"] = $val;
$prj["project_id"] = $val;
$prj["activity_id"] = $this->getActivityByProjectId($val);
$prj["activity_id"] = $this->getActivityByProjectId($val);
$reqProject[] = $prj;
$reqProject[] = $prj;
}
}
@ -133,24 +118,20 @@ class DashboardController extends Controller
$sum_jumlah_pekerjaan = Activity::where('proyek_id', $reqProject[$i]['project_id'])->where('version_gantt_id', $last_version_gantt)->sum("jumlah_pekerjaan");
$sum_jumlah_pekerjaan = Activity::where('proyek_id', $reqProject[$i]['project_id'])->where('version_gantt_id', $last_version_gantt)->sum("jumlah_pekerjaan");
$count_activity = Activity::where('proyek_id', $reqProject[$i]['project_id'])->where('version_gantt_id', $last_version_gantt)->count("id");
$count_activity = Activity::where('proyek_id', $reqProject[$i]['project_id'])->where('version_gantt_id', $last_version_gantt)->count("id");
$count_activity_done = Activity::where('proyek_id', $reqProject[$i]['project_id'])->where('persentase_progress', '100')->where('version_gantt_id', $last_version_gantt)->count("id");
$count_activity_done = Activity::where('proyek_id', $reqProject[$i]['project_id'])->where('persentase_progress', '100')->where('version_gantt_id', $last_version_gantt)->count("id");
$progress_percentage = Activity::where('proyek_id', $reqProject[$i]['project_id'])->whereNull('parent_id')->where('version_gantt_id', $last_version_gantt)->sum("persentase_progress");
$count_progress_percentage = Activity::where('proyek_id', $reqProject[$i]['project_id'])->whereNull('parent_id')->where('version_gantt_id', $last_version_gantt)->count("persentase_progress");
$count_progress_percentage = Activity::where('proyek_id', $reqProject[$i]['project_id'])->whereNull('parent_id')->where('version_gantt_id', $last_version_gantt)->count("persentase_progress");
$progress_actual = Activity::select('id', 'bobot_planning', 'persentase_progress')->where('proyek_id', $reqProject[$i]['project_id'])->whereNull('parent_id')->where('version_gantt_id', $last_version_gantt)->get();
$progress_actual = Activity::select('id', 'bobot_planning', 'persentase_progress')->where('proyek_id', $reqProject[$i]['project_id'])->whereNull('parent_id')->where('version_gantt_id', $last_version_gantt)->get();
$current_progress = 0;
$current_progress = 0;
foreach($progress_actual as $objRow) {
foreach($progress_actual as $objRow) {
$current_progress += ($objRow->bobot_planning * $objRow->persentase_progress) / 100;
$current_progress += ($objRow->bobot_planning * $objRow->persentase_progress) / 100;
}
}
if (count($reqProject[$i]['activity_id']) > 0) {
if (count($reqProject[$i]['activity_id']) > 0) {
for ($j=0; $j < count ( $ reqProject [ $ i ] [ ' activity_id ' ] ) ; $ j + + ) {
for ($j=0; $j < count ( $ reqProject [ $ i ] [ ' activity_id ' ] ) ; $ j + + ) {
$sum_job_count_report = ReportActivity::whereIn('activity_id', $reqProject[$i]['activity_id'])->sum("job_count_report");
$sum_job_count_report = ReportActivity::whereIn('activity_id', $reqProject[$i]['activity_id'])->sum("job_count_report");
}
}
}
}
if (!isset($queryProject->id))
if (!isset($queryProject->id)) {
return response()->json(['status'=>'failed','message'=>'Project with id='.$reqProject[$i]['project_id'].' is not found!','code'=>400], 400);
return response()->json(['status'=>'failed','message'=>'Project with id='.$reqProject[$i]['project_id'].' is not found!','code'=>400], 400);
}
$now = time();
$now = time();
$akhir_proyek = strtotime($queryProject->akhir_proyek);
$akhir_proyek = strtotime($queryProject->akhir_proyek);
@ -176,31 +157,28 @@ class DashboardController extends Controller
}
}
}
}
if($dataFinal){
if(empty($dataFinal))
return response()->json(['status'=>'success','code'=>200,'data'=>$dataFinal, 'totalRecord'=>count($dataFinal)], 200);
}else{
return response()->json(['status'=>'failed','message'=>'failed get status proyek, please try again later!','code'=>400], 400);
return response()->json(['status'=>'failed','message'=>'failed get status proyek, please try again later!','code'=>400], 400);
}
return response()->json(['status'=>'success','code'=>200,'data'=>$dataFinal, 'totalRecord'=>count($dataFinal)], 200);
}
}
public function curvaS(Request $request)
public function curvaS(Request $request)
{
{
$dataPayload = $request->all();
$dataPayload = $request->all();
$dataMaxVersionGantt = [];
$dataMaxVersionGantt = [];
$dataFinal=[];
foreach ($dataPayload['project_id'] as $val) {
foreach ($dataPayload['project_id'] as $val) {
$dataMaxVersionGantt[] = $this->getMaxVersionGantt($val);
$dataMaxVersionGantt[] = $this->getMaxVersionGantt($val);
}
}
$dataFinal=[];
foreach ($dataMaxVersionGantt as $val) {
foreach ($dataMaxVersionGantt as $val) {
$data = Activity::select('m_activity.id', 'm_activity.proyek_id', 'm_activity.name', 'm_activity.kode_sortname', 'm_activity.persentase_progress', 'm_activity.persentase_bobot', 'm_activity.bobot_planning', 'm_activity.biaya_actual', 'mp.nama as proyek_name')->join("m_proyek as mp", "m_activity.proyek_id", "=", "mp.id")->where('proyek_id', $val['proyek_id'])->where('version_gantt_id', $val['last_version_gantt'])->whereNull('parent_id')->orderBy('id', 'asc')->get();
$data = Activity::select('m_activity.id', 'm_activity.proyek_id', 'm_activity.name', 'm_activity.kode_sortname', 'm_activity.persentase_progress', 'm_activity.persentase_bobot', 'm_activity.bobot_planning', 'm_activity.biaya_actual', 'mp.nama as proyek_name')->join("m_proyek as mp", "m_activity.proyek_id", "=", "mp.id")->where('proyek_id', $val['proyek_id'])->where('version_gantt_id', $val['last_version_gantt'])->whereNull('parent_id')->orderBy('id', 'asc')->get();
$totalCostPlanning = Activity::where('proyek_id', $val['proyek_id'])->where('version_gantt_id', $val['last_version_gantt'])->whereNull('parent_id')->sum('rencana_biaya');
$totalCostPlanning = Activity::where('proyek_id', $val['proyek_id'])->where('version_gantt_id', $val['last_version_gantt'])->whereNull('parent_id')->sum('rencana_biaya');
$dataBobotPlan =[];
for ($i=0; $i < count ( $ data ) ; $ i + + ) {
for ($i=0; $i < count ( $ data ) ; $ i + + ) {
$tmpp = 0;
$tmpp = $tmpa = $tmpbc = $tmpac = 0;
$tmpa = 0;
$tmpbc = 0;
$tmpac = 0;
for ($x=$i; $x >= 0 ; $x--) {
for ($x=$i; $x >= 0 ; $x--) {
$tmpp += $data[$x]['bobot_planning'];
$tmpp += $data[$x]['bobot_planning'];
$tmpa += ($data[$x]['persentase_progress'] * $data[$x]['bobot_planning'])/100;
$tmpa += ($data[$x]['persentase_progress'] * $data[$x]['bobot_planning'])/100;
@ -209,6 +187,7 @@ class DashboardController extends Controller
}
}
$data[$i]['cal_bobot_p'] = round($tmpp,2);
$data[$i]['cal_bobot_p'] = round($tmpp,2);
if($i > 0 ){
if($i > 0 ){
if($data[$i-1]['cal_bobot_a'] != null){
if($data[$i-1]['cal_bobot_a'] != null){
if($data[$i-1]['cal_bobot_a'] == round($tmpa,2)){
if($data[$i-1]['cal_bobot_a'] == round($tmpa,2)){
@ -219,12 +198,6 @@ class DashboardController extends Controller
}else{
}else{
$data[$i]['cal_bobot_a'] = null;
$data[$i]['cal_bobot_a'] = null;
}
}
}else{
$data[$i]['cal_bobot_a'] = round($tmpa,2);
}
$data[$i]['cal_budget_cost'] = round($tmpbc,2);
if($i > 0 ){
if($data[$i-1]['cal_actual_cost'] != null){
if($data[$i-1]['cal_actual_cost'] != null){
if($data[$i-1]['cal_actual_cost'] == round($tmpac,2)){
if($data[$i-1]['cal_actual_cost'] == round($tmpac,2)){
$data[$i]['cal_actual_cost'] = null;
$data[$i]['cal_actual_cost'] = null;
@ -235,18 +208,18 @@ class DashboardController extends Controller
$data[$i]['cal_actual_cost'] = null;
$data[$i]['cal_actual_cost'] = null;
}
}
}else{
}else{
$data[$i]['cal_bobot_a'] = round($tmpa,2);
$data[$i]['cal_actual_cost'] = round($tmpac,2);
$data[$i]['cal_actual_cost'] = round($tmpac,2);
}
}
$data[$i]['cal_budget_cost'] = round($tmpbc,2);
}
}
$dataFinal[] = array("proyek_id" => $val['proyek_id'], "proyek_name" => isset($data) & & count($data) > 0 ? $data[0]['proyek_name'] : "-", "version_gantt_id" => $val['last_version_gantt'], "data" => $data);
$dataFinal[] = array("proyek_id" => $val['proyek_id'], "proyek_name" => isset($data) & & count($data) > 0 ? $data[0]['proyek_name'] : "-", "version_gantt_id" => $val['last_version_gantt'], "data" => $data);
}
}
if($dataPayload){
if(!$dataFinal)
return response()->json(['status'=>'success','code'=>200, 'data'=>$dataFinal, 'totalRecord'=>1], 200);
}else{
return response()->json(['status'=>'failed','message'=>'failed get list role, please try again later!','code'=>400], 400);
return response()->json(['status'=>'failed','message'=>'failed get list role, please try again later!','code'=>400], 400);
}
return response()->json(['status'=>'success','code'=>200, 'data'=>$dataFinal, 'totalRecord'=>1], 200);
}
}
}
}