Compare commits

...

9 Commits

  1. 26
      app/Console/Commands/ActualProgressProject.php
  2. 19
      app/Http/Controllers/DashboardBoDController.php
  3. 17
      app/Http/Controllers/ProjectController.php

26
app/Console/Commands/ActualProgressProject.php

@ -3,9 +3,11 @@
namespace App\Console\Commands;
use App\Helpers\MasterFunctionsHelper;
use App\Models\HierarchyFtth;
use App\Models\Project;
use App\Models\VersionGantt;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
class ActualProgressProject extends Command
{
@ -40,7 +42,7 @@ class ActualProgressProject extends Command
*/
public function handle()
{
$projects = Project::join('m_type_proyek', 'm_proyek.type_proyek_id', '=', 'm_type_proyek.id')
$projects = Project::leftJoin('m_type_proyek', 'm_proyek.type_proyek_id', '=', 'm_type_proyek.id')
->select('m_proyek.*', 'm_type_proyek.is_multiLocation')
->get();
@ -52,9 +54,16 @@ class ActualProgressProject extends Command
->where('m_version_gantt.proyek_id', $project->id)
->get();
foreach ($versionGantt as $key => $gantt) {
$progress[$key] = $gantt->progress;
$hierarchy = HierarchyFtth::where('id',$gantt->hierarchy_ftth_id)->count();
// Perhitungan jika project memiliki gantt tetapi tidak ada hierarchy (Kasus perpindahan tipe project dari single location ke multi location)
if($hierarchy == 0){
$progress[$key] = 0;
} else {
$progress[$key] = $gantt->progress;
}
}
$actualProgress = round(array_sum($progress) / count($versionGantt), 2);
$progress = array(); // unset/kosongkan array progress untuk project selanjutnya
} else {
// untuk project single location
$gantt = MasterFunctionsHelper::getLatestGantt($project->id);
@ -65,12 +74,15 @@ class ActualProgressProject extends Command
'gantt_id' => $lastGantt,
'periode' => 'week'
];
$project->scurve = MasterFunctionsHelper::getSCurve(collect($arr));
$actualArray = $project->scurve[0]['data']['percentageReal'];
$actualProgress = !empty($actualArray) ? round(end($actualArray), 2) : 0;
// kondisi jika tidak ada gantt_id
if (empty($arr['gantt_id'])) {
$actualProgress = 0;
} else {
$project->scurve = MasterFunctionsHelper::getSCurve(collect($arr));
$actualArray = $project->scurve[0]['data']['percentageReal'];
$actualProgress = !empty($actualArray) ? round(end($actualArray), 2) : 0;
}
}
Project::where('id', $project->id)->update(['persentase_progress' => $actualProgress]);
}
}

19
app/Http/Controllers/DashboardBoDController.php

@ -66,11 +66,11 @@ class DashboardBoDController extends Controller
return response()->json([
'data' => [
'total_budget' => (int) ($totalBudgets->total_rencana_biaya ?? 0),
'total_budget' => $totalBudgets->total_value_proyek ?? 0,
'total_expenditure' => $totalExpenditure,
'total_invoice' => $totalInvoice,
'total_paid_invoice' => $totalPaidInvoice,
'total_value_proyek' => $totalBudgets->total_value_proyek ?? 0,
'total_value_proyek' => (int) ($totalBudgets->total_rencana_biaya ?? 0),
'total_income_year' => $totalBudgets->total_income_year ?? 0
]
], 200);
@ -288,10 +288,7 @@ class DashboardBoDController extends Controller
->pluck('id');
// arr overrun
if ($role === 'Super Admin') {
$response['data']['overrun'] = Project::where('budget_health', 'overrun')
->count();
} elseif ($all_project == 'true') {
if ($all_project) {
$response['data']['overrun'] = Project::whereIn('divisi_id', $divisi)
->where([['budget_health', 'overrun']])
->count();
@ -301,10 +298,7 @@ class DashboardBoDController extends Controller
->count();
}
// arr warning
if ($role === 'Super Admin') {
$response['data']['warning'] = Project::where('budget_health', 'warning')
->count();
} elseif ($all_project == 'true') {
if ($all_project) {
$response['data']['warning'] = Project::whereIn('divisi_id', $divisi)
->where([['budget_health', 'warning']])
->count();
@ -314,10 +308,7 @@ class DashboardBoDController extends Controller
->count();
}
// arr on-budget
if ($role === 'Super Admin') {
$response['data']['on-budget'] = Project::where('budget_health', 'on-budget')
->count();
} elseif ($all_project == 'true') {
if ($all_project) {
$response['data']['on-budget'] = Project::whereIn('divisi_id', $divisi)
->where([['budget_health', 'on-budget']])
->count();

17
app/Http/Controllers/ProjectController.php

@ -291,6 +291,23 @@ class ProjectController extends Controller
$builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count'];
$dataGet = $builder->get();
foreach($dataGet as $p) {
$project = Project::find($p->id);
if (!$project) continue;
$act = Activity::select('persentase_progress as total_progress')
->where([
['proyek_id', $p->id],
['parent_id', null]
])
->first();
if ($act) {
$project->persentase_progress = $act->total_progress;
} else {
$project->persentase_progress = 0;
}
$project->save();
}
$totalRecord = $countBuilder->count();
return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => $totalRecord], 200);
}

Loading…
Cancel
Save