|
|
|
@ -54,36 +54,92 @@ class DashboardBoDController extends Controller
|
|
|
|
|
return $response; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// to do |
|
|
|
|
public function getCompanyCashFlow($year = '%') |
|
|
|
|
// OLD |
|
|
|
|
// public function getCompanyCashFlow($year = '%') |
|
|
|
|
// { |
|
|
|
|
// $year = $this->interpolateYear($year); |
|
|
|
|
// $totalExpenditure = $totalInvoice = $totalPaidInvoice = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// $totalBudgets = Project::select(DB::raw('SUM(CAST("rencana_biaya" AS DOUBLE PRECISION))')) |
|
|
|
|
// ->where('mulai_proyek', 'like', $year) |
|
|
|
|
// /* ->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, |
|
|
|
|
// ] |
|
|
|
|
// ], 200); |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
public function getCompanyCashFlow($year = '%', $company_id, $all_project, $hierarchy) |
|
|
|
|
{ |
|
|
|
|
$year = $this->interpolateYear($year); |
|
|
|
|
$totalExpenditure = $totalInvoice = $totalPaidInvoice = 0; |
|
|
|
|
|
|
|
|
|
// 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) |
|
|
|
|
/* ->orWhere('akhir_proyek', 'like', $year) */ |
|
|
|
|
->pluck('sum') |
|
|
|
|
->first(); |
|
|
|
|
$totalBudgets = null; |
|
|
|
|
if ($all_project) { |
|
|
|
|
$totalBudgets = Project::where('mulai_proyek', 'like', $year) |
|
|
|
|
->where('company_id', $company_id) |
|
|
|
|
->sum(DB::raw('CAST("rencana_biaya" AS DOUBLE PRECISION)')); |
|
|
|
|
} else { |
|
|
|
|
$totalBudgets = Project::where('mulai_proyek', 'like', $year) |
|
|
|
|
->where('created_by_id', $hierarchy) |
|
|
|
|
->sum(DB::raw('CAST("rencana_biaya" AS DOUBLE PRECISION)')); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$projects = null; |
|
|
|
|
if ($all_project) { |
|
|
|
|
$projects = Project::where('mulai_proyek', 'like', $year) |
|
|
|
|
/* ->orWhere('akhir_proyek', 'like', $year) */ |
|
|
|
|
->where('company_id', $company_id) |
|
|
|
|
->get(); |
|
|
|
|
} else { |
|
|
|
|
$projects = Project::where('mulai_proyek', 'like', $year) |
|
|
|
|
->where('created_by_id', $hierarchy) |
|
|
|
|
->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; |
|
|
|
|
} |
|
|
|
|
$cost = 0; |
|
|
|
|
$totalExpenditure = 0; |
|
|
|
|
$totalInvoice = 0; |
|
|
|
|
$totalPaidInvoice = 0; |
|
|
|
|
|
|
|
|
|
// $totalExpenditure += (int) $cost; |
|
|
|
|
// $totalInvoice += $resp->data->total_invoice_amount ?? 0; |
|
|
|
|
// $totalPaidInvoice += $resp->data->total_invoice_paid_amount ?? 0; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return response()->json([ |
|
|
|
@ -96,6 +152,7 @@ class DashboardBoDController extends Controller
|
|
|
|
|
], 200); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function getInvoiceOutstanding($year = '%') |
|
|
|
|
{ |
|
|
|
|
$year = $this->interpolateYear($year); |
|
|
|
@ -150,12 +207,10 @@ class DashboardBoDController extends Controller
|
|
|
|
|
if ($selisihProgress > 0 && $selisihProgress <= 5) { |
|
|
|
|
$return['warning'] += 1; |
|
|
|
|
$projects[$index]->status = 'warning'; |
|
|
|
|
} |
|
|
|
|
elseif ($selisihProgress == 0){ |
|
|
|
|
} elseif ($selisihProgress == 0) { |
|
|
|
|
$return['on-schedule'] += 1; |
|
|
|
|
$projects[$index]->status = 'on-schedule'; |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
} else { |
|
|
|
|
$return['behind-schedule'] += 1; |
|
|
|
|
$projects[$index]->status = 'behind-schedule'; |
|
|
|
|
} |
|
|
|
@ -193,11 +248,9 @@ class DashboardBoDController extends Controller
|
|
|
|
|
$selisihProgress = $planningProgress - $actualProgress; |
|
|
|
|
if ($selisihProgress > 0 && $selisihProgress <= 5) { |
|
|
|
|
$warning++; |
|
|
|
|
} |
|
|
|
|
elseif ($selisihProgress == 0){ |
|
|
|
|
} elseif ($selisihProgress == 0) { |
|
|
|
|
$onSchedule++; |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
} else { |
|
|
|
|
$behindSchedule++; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|