Browse Source

update filter company_id for dashboard and project

pull/1/head
farhantock 1 year ago
parent
commit
a0a8b1b752
  1. 117
      app/Http/Controllers/DashboardBoDController.php
  2. 3
      app/Models/Project.php
  3. 2
      routes/web.php

117
app/Http/Controllers/DashboardBoDController.php

@ -41,49 +41,105 @@ class DashboardBoDController extends Controller
private function getInvoiceIntegration($search) private function getInvoiceIntegration($search)
{ {
if(empty($search)) if (empty($search))
return response()->json(['status'=>'error', 'message'=>'Empty query string!'], 400); return response()->json(['status' => 'error', 'message' => 'Empty query string!'], 400);
$url = str_replace("SEARCH", $search, config('api.adw').'/project_cost?project_no=SEARCH'); $url = str_replace("SEARCH", $search, config('api.adw') . '/project_cost?project_no=SEARCH');
$token = config('api.adw_token'); $token = config('api.adw_token');
$response = $this->curlReq($url, $token); $response = $this->curlReq($url, $token);
if(@$response->data->project_no == "") if (@$response->data->project_no == "")
return null; return null;
return $response; return $response;
} }
// to do // OLD
public function getCompanyCashFlow($year = '%') // 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); $year = $this->interpolateYear($year);
$totalExpenditure = $totalInvoice = $totalPaidInvoice = 0; $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 = null;
$totalBudgets = Project::select(DB::raw('SUM(CAST("rencana_biaya" AS DOUBLE PRECISION))')) if ($all_project) {
->where('mulai_proyek', 'like', $year) $totalBudgets = Project::where('mulai_proyek', 'like', $year)
/* ->orWhere('akhir_proyek', 'like', $year) */ ->where('company_id', $company_id)
->pluck('sum') ->sum(DB::raw('CAST("rencana_biaya" AS DOUBLE PRECISION)'));
->first(); } 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)
->where('company_id', $company_id)
->get();
} else {
$projects = Project::where('mulai_proyek', 'like', $year)
->where('created_by_id', $hierarchy)
->get();
}
$projects = Project::where('mulai_proyek', 'like', $year)
/* ->orWhere('akhir_proyek', 'like', $year) */
->get();
foreach ($projects as $project) { foreach ($projects as $project) {
$project->expenses = 0; $project->expenses = 0;
$resp = null; $resp = null;
if ($project->kode_sortname != "") { if ($project->kode_sortname != "") {
$resp = $this->getInvoiceIntegration($project->kode_sortname); $resp = $this->getInvoiceIntegration($project->kode_sortname);
/* $resp = $project->kode_sortname; */
$cost = $resp->data->total_cost ?? 0; $cost = $resp->data->total_cost ?? 0;
$cost = substr($cost, 0, strpos($cost, ".")); $cost = substr($cost, 0, strpos($cost, "."));
$totalExpenditure += (int) $cost; $cost = 0;
$totalInvoice += $resp->data->total_invoice_amount ?? 0; $totalExpenditure = 0;
$totalPaidInvoice += $resp->data->total_invoice_paid_amount ?? 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([ return response()->json([
@ -96,6 +152,7 @@ class DashboardBoDController extends Controller
], 200); ], 200);
} }
public function getInvoiceOutstanding($year = '%') public function getInvoiceOutstanding($year = '%')
{ {
$year = $this->interpolateYear($year); $year = $this->interpolateYear($year);
@ -147,15 +204,13 @@ class DashboardBoDController extends Controller
} }
$selisihProgress = $planningProgress - $actualProgress; $selisihProgress = $planningProgress - $actualProgress;
try { try {
if ($selisihProgress > 0 && $selisihProgress <= 5){ if ($selisihProgress > 0 && $selisihProgress <= 5) {
$return['warning'] += 1; $return['warning'] += 1;
$projects[$index]->status = 'warning'; $projects[$index]->status = 'warning';
} } elseif ($selisihProgress == 0) {
elseif ($selisihProgress == 0){
$return['on-schedule'] += 1; $return['on-schedule'] += 1;
$projects[$index]->status = 'on-schedule'; $projects[$index]->status = 'on-schedule';
} } else {
else {
$return['behind-schedule'] += 1; $return['behind-schedule'] += 1;
$projects[$index]->status = 'behind-schedule'; $projects[$index]->status = 'behind-schedule';
} }
@ -191,13 +246,11 @@ class DashboardBoDController extends Controller
$actualProgress = !empty($actualArray) ? $actualArray[count($actualArray) - 1] : 0; $actualProgress = !empty($actualArray) ? $actualArray[count($actualArray) - 1] : 0;
} }
$selisihProgress = $planningProgress - $actualProgress; $selisihProgress = $planningProgress - $actualProgress;
if ($selisihProgress > 0 && $selisihProgress <= 5){ if ($selisihProgress > 0 && $selisihProgress <= 5) {
$warning++; $warning++;
} } elseif ($selisihProgress == 0) {
elseif ($selisihProgress == 0){
$onSchedule++; $onSchedule++;
} } else {
else {
$behindSchedule++; $behindSchedule++;
} }
} }
@ -294,7 +347,7 @@ class DashboardBoDController extends Controller
{ {
$year = $this->interpolateYear($year); $year = $this->interpolateYear($year);
$divisions = Divisi::select('id', 'name','parent','color') $divisions = Divisi::select('id', 'name', 'parent', 'color')
->with('children') ->with('children')
->whereNull('parent') ->whereNull('parent')
->get(); ->get();

3
app/Models/Project.php

@ -48,6 +48,7 @@ class Project extends Model
'created_by', 'created_by',
'updated_at', 'updated_at',
'updated_by', 'updated_by',
'created_by_id' 'created_by_id',
'company_id'
]; ];
} }

2
routes/web.php

@ -23,7 +23,7 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro
$router->group(['middleware' => ['auth', 'cors']], function () use ($router) { $router->group(['middleware' => ['auth', 'cors']], function () use ($router) {
$router->get('/dashboard/get-company-cashflow[/{year}]', 'DashboardBoDController@getCompanyCashFlow'); // project expenditure $router->get('/dashboard/get-company-cashflow/{year}/{company_id}/{all_project}/{hierarchy}', 'DashboardBoDController@getCompanyCashFlow'); // project expenditure
$router->get('/dashboard/get-invoice-outstanding[/{year}]', 'DashboardBoDController@getInvoiceOutstanding'); // project invoice vs cash in $router->get('/dashboard/get-invoice-outstanding[/{year}]', 'DashboardBoDController@getInvoiceOutstanding'); // project invoice vs cash in
$router->get('/dashboard/get-total-project-per-schedule-health[/{year}]', 'DashboardBoDController@getTotalProjectPerScheduleHealth'); $router->get('/dashboard/get-total-project-per-schedule-health[/{year}]', 'DashboardBoDController@getTotalProjectPerScheduleHealth');
$router->get('/dashboard/get-total-project-per-budget-health[/{year}]', 'DashboardBoDController@getTotalProjectPerBudgetHealth'); $router->get('/dashboard/get-total-project-per-budget-health[/{year}]', 'DashboardBoDController@getTotalProjectPerBudgetHealth');

Loading…
Cancel
Save