|
|
@ -32,49 +32,46 @@ class DashboardBoDController extends Controller |
|
|
|
{ |
|
|
|
{ |
|
|
|
$totalExpenditure = $totalInvoice = $totalPaidInvoice = 0; |
|
|
|
$totalExpenditure = $totalInvoice = $totalPaidInvoice = 0; |
|
|
|
|
|
|
|
|
|
|
|
$totalBudgets = null; |
|
|
|
$totalBudgets = []; |
|
|
|
|
|
|
|
$projects = []; |
|
|
|
$role = urldecode($role_name); |
|
|
|
$role = urldecode($role_name); |
|
|
|
if (!empty($all_project) || $role === "Super Admin") { |
|
|
|
|
|
|
|
$totalBudgets = Project::sum(DB::raw('CAST("rencana_biaya" AS DOUBLE PRECISION)')); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
$totalBudgets = Project::where('created_by_id', $hierarchy) |
|
|
|
|
|
|
|
->sum(DB::raw('CAST("rencana_biaya" AS DOUBLE PRECISION)')); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
$totalBudgets = Project::sum(DB::raw('CAST("rencana_biaya" AS DOUBLE PRECISION)')); |
|
|
|
|
|
|
|
$projects = null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!empty($all_project) || $role === "Super Admin") { |
|
|
|
if ($all_project) { |
|
|
|
|
|
|
|
$totalBudgets = Project::select( |
|
|
|
|
|
|
|
DB::raw('SUM(CAST(COALESCE(NULLIF(REPLACE(rencana_biaya, \'.\', \'\'), \'\'), \'0\') AS DOUBLE PRECISION)) AS total_rencana_biaya'), |
|
|
|
|
|
|
|
DB::raw('SUM(CAST(COALESCE(NULLIF(REPLACE(value_proyek, \'.\', \'\'), \'\'), \'0\') AS DOUBLE PRECISION)) AS total_value_proyek'), |
|
|
|
|
|
|
|
DB::raw('SUM(CAST(COALESCE(NULLIF(REPLACE(income_year, \'.\', \'\'), \'\'), \'0\') AS DOUBLE PRECISION)) AS total_income_year') |
|
|
|
|
|
|
|
)->first(); |
|
|
|
$projects = Project::get(); |
|
|
|
$projects = Project::get(); |
|
|
|
|
|
|
|
Log::info(['dataTotal' => $totalBudgets]); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
$projects = Project::where('created_by_id', $hierarchy) |
|
|
|
$totalBudgets = Project::where('created_by_id', $hierarchy) |
|
|
|
->get(); |
|
|
|
->select( |
|
|
|
|
|
|
|
DB::raw('SUM(CAST(COALESCE(NULLIF(REPLACE(rencana_biaya, \'.\', \'\'), \'\'), \'0\') AS DOUBLE PRECISION)) AS total_rencana_biaya'), |
|
|
|
|
|
|
|
DB::raw('SUM(CAST(COALESCE(NULLIF(REPLACE(value_proyek, \'.\', \'\'), \'\'), \'0\') AS DOUBLE PRECISION)) AS total_value_proyek'), |
|
|
|
|
|
|
|
DB::raw('SUM(CAST(COALESCE(NULLIF(REPLACE(income_year, \'.\', \'\'), \'\'), \'0\') AS DOUBLE PRECISION)) AS total_income_year') |
|
|
|
|
|
|
|
)->first(); |
|
|
|
|
|
|
|
$projects = Project::where('created_by_id', $hierarchy)->get(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
foreach ($projects as $project) { |
|
|
|
foreach ($projects as $project) { |
|
|
|
$project->expenses = 0; |
|
|
|
$project->expenses = 0; |
|
|
|
$resp = null; |
|
|
|
|
|
|
|
if ($project->kode_sortname != "") { |
|
|
|
if ($project->kode_sortname != "") { |
|
|
|
|
|
|
|
|
|
|
|
// $resp = $this->getInvoiceIntegration($project->kode_sortname); |
|
|
|
|
|
|
|
// $cost = $resp->data->total_cost ?? 0; |
|
|
|
|
|
|
|
// $cost = substr($cost, 0, strpos($cost, ".")); |
|
|
|
|
|
|
|
$cost = 0; |
|
|
|
$cost = 0; |
|
|
|
$totalExpenditure = 0; |
|
|
|
$totalExpenditure = 0; |
|
|
|
$totalInvoice = 0; |
|
|
|
$totalInvoice = 0; |
|
|
|
$totalPaidInvoice = 0; |
|
|
|
$totalPaidInvoice = 0; |
|
|
|
|
|
|
|
|
|
|
|
// $totalExpenditure += (int) $cost; |
|
|
|
|
|
|
|
// $totalInvoice += $resp->data->total_invoice_amount ?? 0; |
|
|
|
|
|
|
|
// $totalPaidInvoice += $resp->data->total_invoice_paid_amount ?? 0; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return response()->json([ |
|
|
|
return response()->json([ |
|
|
|
'data' => [ |
|
|
|
'data' => [ |
|
|
|
'total_budget' => (int) $totalBudgets ?? 0, |
|
|
|
'total_budget' => (int) ($totalBudgets->total_rencana_biaya ?? 0), |
|
|
|
'total_expenditure' => $totalExpenditure, |
|
|
|
'total_expenditure' => $totalExpenditure, |
|
|
|
'total_invoice' => $totalInvoice, |
|
|
|
'total_invoice' => $totalInvoice, |
|
|
|
'total_paid_invoice' => $totalPaidInvoice, |
|
|
|
'total_paid_invoice' => $totalPaidInvoice, |
|
|
|
|
|
|
|
'total_value_proyek' => $totalBudgets->total_value_proyek ?? 0, |
|
|
|
|
|
|
|
'total_income_year' => $totalBudgets->total_income_year ?? 0 |
|
|
|
] |
|
|
|
] |
|
|
|
], 200); |
|
|
|
], 200); |
|
|
|
} |
|
|
|
} |
|
|
@ -460,8 +457,7 @@ class DashboardBoDController extends Controller |
|
|
|
|
|
|
|
|
|
|
|
public function getDetailExpenditure($all_project, $hierarchy, $role_name) |
|
|
|
public function getDetailExpenditure($all_project, $hierarchy, $role_name) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// $year = $this->interpolateYear($year); |
|
|
|
$projects = []; |
|
|
|
$projects = null; |
|
|
|
|
|
|
|
if ($all_project) { |
|
|
|
if ($all_project) { |
|
|
|
$projects = Project::orderBy('id', 'desc') |
|
|
|
$projects = Project::orderBy('id', 'desc') |
|
|
|
->get(); |
|
|
|
->get(); |
|
|
|