>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6 class DashboardBoDController extends Controller { private function interpolateYear($year){ if($year) $year = '%'.$year.'%'; return $year; } <<<<<<< HEAD private function curlReq($url, $token){ $ch = curl_init(); $headers = [ 'Authorization: '.$token ]; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $response = curl_exec($ch); if ($response === false) $response = curl_error($ch); curl_close($ch); return json_decode($response); } private function getInvoiceIntegration($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'); $token = config('api.adw_token'); $response = $this->curlReq($url, $token); if(@$response->data->project_no == "") return null; return $response; } // to do public function getCompanyCashFlow($year = '%') { $year = $this->interpolateYear($year); $totalExpenditure = $totalInvoice = $totalPaidInvoice = 0; ======= public function getCompanyCashFlow($year = '%') { $year = $this->interpolateYear($year); >>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6 // we can't use eloquent's sum() method because someone decided to use varchar as datatype in rencana_biaya field $totalBudgets = Project::select(DB::raw('SUM(CAST("rencana_biaya" AS DOUBLE PRECISION))')) ->where('mulai_proyek', 'like', $year) <<<<<<< HEAD /* ->orWhere('akhir_proyek', 'like', $year) */ ->pluck('sum') ->first(); $projects = Project::where('mulai_proyek', 'like', $year) /* ->orWhere('akhir_proyek', 'like', $year) */ ->get(); foreach($projects as $project){ $project->expenses = 0; $resp = null; if($project->kode_sortname != ""){ $resp = $this->getInvoiceIntegration($project->kode_sortname); /* $resp = $project->kode_sortname; */ $cost = $resp->data->total_cost ?? 0; $cost = substr($cost, 0, strpos($cost, ".")); $totalExpenditure+= (int) $cost; $totalInvoice += $resp->data->total_invoice_amount ?? 0; $totalPaidInvoice += $resp->data->total_invoice_paid_amount ?? 0; } } return response()->json([ 'data' => [ 'total_budget' => (int) $totalBudgets ?? 0, 'total_expenditure' => $totalExpenditure, 'total_invoice' => $totalInvoice, 'total_paid_invoice' => $totalPaidInvoice , ======= ->pluck('sum') ->first(); return response()->json([ 'data' => [ 'total_budget' => (int) $totalBudgets ?? rand(0,10), 'total_expenditure' => rand(0,10), // to do integrasi 'total_invoice' => rand(0,10), 'total_paid_invoice' => rand(0,10), >>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6 ] ], 200); } <<<<<<< HEAD public function getInvoiceOutstanding($year = '%'){ $year = $this->interpolateYear($year); $projects = Project::where('mulai_proyek', 'like', $year) /* ->orWhere('akhir_proyek', 'like', $year) */ ->get(); $return = []; foreach($projects as $project){ $resp = null; if($project->kode_sortname != ""){ $resp = $this->getInvoiceIntegration($project->kode_sortname); array_push($return, [ 'project' => $project->nama, 'project_code' => $project->kode_sortname, 'invoiced' => $resp->data->total_invoice_amount ?? 0, 'paid' => $resp->data->total_invoice_paid_amount ?? 0, 'response' => $resp, ]); } } return response()->json([ 'data' => $return ], 200); } public function getTotalProjectPerScheduleHealth($year = '%'){ $year = $this->interpolateYear($year); $return = [ 'behind-schedule' => 0, 'warning' => 0, 'on-schedule' => 0, ]; $projects = Project::where('mulai_proyek', 'like', $year)->get(); foreach($projects as $project) { $project->scurve = MasterFunctionsHelper::getSCurve($project->id); try { if(@$project->scurve['difference'] > 0 && @$project->scurve['difference'] <= 5) $return['warning'] += 1; elseif(@$project->scurve['difference'] > 5 && @$project->scurve['difference'] <= 100) $return['behind-schedule'] += 1; elseif(@$project->scurve['difference'] == 0) $return['on-schedule'] += 1; } catch (\Error $e) { return response()->json(['msg' => $e->getMessage(), 'data' => $project], 200); } } return response()->json(['data' => $return, 'q' => $projects], 200); } public function getTotalProjectScheduleHealthPerDivision($year = '%'){ ======= public function getProjectPerScheduleHealth($year = '%'){ $year = $this->interpolateYear($year); // get data plan (vol) in % // get data actual in % return response()->json([ 'data' => [ 'behind-schedule' => rand(0,10), 'warning' => rand(0,10), 'on-schedule' => rand(0,10), ] ], 200); } public function getProjectScheduleHealthPerDivision($year = '%'){ >>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6 $year = $this->interpolateYear($year); $divisions = Divisi::whereNull('parent')->get(); foreach($divisions as $division){ <<<<<<< HEAD $scheduleData = new Collection(); $behindSchedule = $warning = $onSchedule = 0; $projects = Project::where('mulai_proyek', 'like', $year)->where('divisi_id', $division->id)->get(); foreach($projects as $project) { $project->scurve = MasterFunctionsHelper::getSCurve($project->id); if(@$project->scurve['difference'] > 0 && @$project->scurve['difference'] <= 5) $warning++; elseif(@$project->scurve['difference'] > 5 && @$project->scurve['difference'] <= 100) $behindSchedule++; elseif(@$project->scurve['difference'] == 0) $onSchedule++; } $scheduleData->prepend($behindSchedule, 'behindSchedule'); $scheduleData->prepend($warning, 'warning'); $scheduleData->prepend($onSchedule, 'onSchedule'); ======= $scheduleData = new Collection(); $scheduleData->prepend(rand(0, 10), 'behindSchedule'); $scheduleData->prepend(rand(0, 10), 'warning'); $scheduleData->prepend(rand(0, 10), 'onSchedule'); >>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6 $division->scheduleData = $scheduleData; } return response()->json([ 'data' => [ $divisions ] ], 200); } <<<<<<< HEAD public function getTotalProjectPerBudgetHealth($year = '%'){ $year = $this->interpolateYear($year); return response()->json([ 'data' => [ 'overrun' => Project::where('mulai_proyek', 'like', $year)->where('budget_health', 'overrun')->count(), 'warning' => Project::where('mulai_proyek', 'like', $year)->where('budget_health', 'warning')->count(), 'on-budget' => Project::where('mulai_proyek', 'like', $year)->where('budget_health', 'on-budget')->count(), ======= public function getProjectPerBudgetHealth($year = '%'){ $year = $this->interpolateYear($year); return response()->json([ 'data' => [ 'overrun' => rand(0,10), 'warning' => rand(0,10), 'on-budget' => rand(0,10), >>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6 ] ], 200); } <<<<<<< HEAD private function countTotalProjectByBudgetHealthInDivision($divisi, $year, $health){ return Project::where('divisi_id', $divisi) ->where('mulai_proyek', 'like', $year) /* ->orWhere('akhir_proyek', 'like', $year) */ ->where('budget_health', $health) ->count(); } public function getTotalProjectBudgetHealthPerDivision($year = '%'){ $year = $this->interpolateYear($year); $divisions = Divisi::select('id','name') ->with('children') ->whereNull('parent') ->get(); // to do : count in more than 1 level child foreach($divisions as $division){ $budgetData = new Collection(); $budgetData->prepend($this->countTotalProjectByBudgetHealthInDivision($division->id, $year, 'overrun'), 'overrun'); $budgetData->prepend($this->countTotalProjectByBudgetHealthInDivision($division->id, $year, 'warning'), 'warning'); $budgetData->prepend($this->countTotalProjectByBudgetHealthInDivision($division->id, $year, 'on-budget'), 'on-budget'); foreach($division->children as $d){ $budgetData['overrun'] += $this->countTotalProjectByBudgetHealthInDivision($d->id, $year, 'overrun'); $budgetData['warning'] += $this->countTotalProjectByBudgetHealthInDivision($d->id, $year, 'warning'); $budgetData['on-budget'] += $this->countTotalProjectByBudgetHealthInDivision($d->id, $year, 'on-budget'); } unset($division->children); $division->budgetData = $budgetData; } foreach($divisions as $division){ } ======= public function getProjectBudgetHealthPerDivision($year = '%'){ $year = $this->interpolateYear($year); $divisions = Divisi::whereNull('parent')->get(); foreach($divisions as $division){ $budgetData = new Collection(); $budgetData->prepend(rand(0, 10), 'overrun'); $budgetData->prepend(rand(0, 10), 'warning'); $budgetData->prepend(rand(0, 10), 'onBudget'); $division->budgetData = $budgetData; } >>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6 return response()->json([ 'data' => [ $divisions ] ], 200); } <<<<<<< HEAD public function getTotalProjectPerPhase($year = '%'){ $year = $this->interpolateYear($year); $projectPhases = ProjectPhase::orderBy('order')->get(); foreach($projectPhases as $phase){ $phase->totalProject = Project::where('phase_id', $phase->id) ->where('mulai_proyek', 'like', $year) /* ->orWhere('akhir_proyek', 'like', $year) */ ->count(); ======= public function getProjectPerPhase($year = '%'){ $year = $this->interpolateYear($year); $projectPhases = ProjectPhase::orderBy('order')->get(); foreach($projectPhases as $phase){ $phase->totalProject = rand(0,10); >>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6 } return response()->json([ 'data' => [ $projectPhases ] ], 200); } private function countTotalProjectInDivision($id, $year){ return Project::where('divisi_id', $id) ->where('mulai_proyek', 'like', $year) <<<<<<< HEAD /* ->orWhere('akhir_proyek', 'like', $year) */ ======= >>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6 ->count(); } public function getTotalProjectPerDivision($year = '%') { $year = $this->interpolateYear($year); <<<<<<< HEAD $divisions = Divisi::select('id','name') ======= $totalProjectPerDivision = Divisi::select('id','name') >>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6 ->with('children') ->whereNull('parent') ->get(); // to do : count in more than 1 level child <<<<<<< HEAD foreach($divisions as $v){ ======= foreach($totalProjectPerDivision as $v){ >>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6 $v->total = $this->countTotalProjectInDivision($v->id, $year); foreach($v->children as $d){ $v->total += $this->countTotalProjectInDivision($d->id, $year); } unset($v->children); } return response()->json([ <<<<<<< HEAD 'data' => $divisions ======= 'data' => $totalProjectPerDivision >>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6 ], 200); } private function countTotalProjectValueInDivision($id, $year){ return Project::select(DB::raw('SUM(CAST("rencana_biaya" AS DOUBLE PRECISION))')) ->where('mulai_proyek', 'like', $year) <<<<<<< HEAD /* ->orWhere('akhir_proyek', 'like', $year) */ ======= >>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6 ->where('divisi_id', $id) ->pluck('sum') ->first(); } public function getTotalProjectValuePerDivision($year = '%') { $year = $this->interpolateYear($year); <<<<<<< HEAD $divisions = Divisi::select('id','name') ======= $totalProjectValuePerDivision = Divisi::select('id','name') >>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6 ->with('children') ->whereNull('parent') ->get(); // to do : count in more than 1 level child <<<<<<< HEAD foreach($divisions as $v){ ======= foreach($totalProjectValuePerDivision as $v){ >>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6 $v->total = $this->countTotalProjectValueInDivision($v->id, $year); foreach($v->children as $d){ $v->total += $this->countTotalProjectValueInDivision($d->id, $year); } unset($v->children); } return response()->json([ <<<<<<< HEAD 'data' => $divisions ], 200); } public function getDetailExpenditure($year = '%'){ $year = $this->interpolateYear($year); $projects = Project::where('mulai_proyek', 'like', $year) /* ->orWhere('akhir_proyek', 'like', $year) */ ->orderBy('id', 'desc') ->get(); foreach($projects as $project){ $lastGantt = MasterFunctionsHelper::getLatestGantt($project->id); if($project->kode_sortname != ""){ $resp = $this->getInvoiceIntegration($project->kode_sortname); $project->invoice = [ 'invoiced' => $resp->data->total_invoice_amount ?? 0, 'paid' => $resp->data->total_invoice_paid_amount ?? 0, ]; } $project->pm = User::find($project->pm_id); /* $project->header = Activity::where('proyek_id', $project->id)->where('version_gantt_id', $lastGantt['last_gantt_id'])->whereNull('parent_id')->first(); */ $project->scurve = MasterFunctionsHelper::getSCurve($project->id); $project->manPowers = UserToVersionGantt::where('version_gantt_id', $lastGantt['last_gantt_id'])->count(); $project->lastGanttId = MasterFunctionsHelper::getLatestGantt($project->id); } return response()->json([ 'data' => $projects, 'total_manpowers' => User::count() ], 200); } ======= 'data' => $totalProjectValuePerDivision ], 200); } >>>>>>> 3f193ec38ec78bd3d323b4aa304c5e1ab52425b6 }