Browse Source

Merge pull request 'Dev-Farhan' (#311) from Dev-Farhan into staging

Reviewed-on: ordo/adw-backend#311
pull/1/head
farhantock 12 months ago
parent
commit
3e30162eaf
  1. 82
      app/Http/Controllers/DashboardBoDController.php
  2. 92
      app/Http/Controllers/DivisiController.php
  3. 20
      app/Http/Controllers/ProjectController.php
  4. 3
      app/Models/Project.php
  5. 20
      routes/web.php

82
app/Http/Controllers/DashboardBoDController.php

@ -122,9 +122,9 @@ class DashboardBoDController extends Controller
], 200); ], 200);
} }
public function getTotalProjectPerScheduleHealth($year = '%') public function getTotalProjectPerScheduleHealth()
{ {
$year = $this->interpolateYear($year); // $year = $this->interpolateYear($year);
$return = [ $return = [
'behind-schedule' => 0, 'behind-schedule' => 0,
@ -132,7 +132,7 @@ class DashboardBoDController extends Controller
'on-schedule' => 0, 'on-schedule' => 0,
]; ];
$projects = Project::where('mulai_proyek', 'like', $year)->get(); $projects = Project::get();
foreach ($projects as $index => $project) { foreach ($projects as $index => $project) {
$project->scurve = MasterFunctionsHelper::getSCurve($project->id); $project->scurve = MasterFunctionsHelper::getSCurve($project->id);
$selisihProgress = 0; $selisihProgress = 0;
@ -165,9 +165,9 @@ class DashboardBoDController extends Controller
return response()->json(['data' => $return, 'q' => $projects], 200); return response()->json(['data' => $return, 'q' => $projects], 200);
} }
public function getTotalProjectScheduleHealthPerDivision($year = '%') public function getTotalProjectScheduleHealthPerDivision()
{ {
$year = $this->interpolateYear($year); // $year = $this->interpolateYear($year);
$divisions = Divisi::whereNull('parent')->get(); $divisions = Divisi::whereNull('parent')->get();
foreach ($divisions as $index => $division) { foreach ($divisions as $index => $division) {
@ -175,7 +175,7 @@ class DashboardBoDController extends Controller
$scheduleData = new Collection(); $scheduleData = new Collection();
$behindSchedule = $warning = $onSchedule = 0; $behindSchedule = $warning = $onSchedule = 0;
$projects = Project::where('mulai_proyek', 'like', $year)->where('divisi_id', $division->id)->get(); $projects = Project::where('divisi_id', $division->id)->get();
foreach ($projects as $project) { foreach ($projects as $project) {
$project->scurve = MasterFunctionsHelper::getSCurve($project->id); $project->scurve = MasterFunctionsHelper::getSCurve($project->id);
$selisihProgress = 0; $selisihProgress = 0;
@ -210,31 +210,30 @@ class DashboardBoDController extends Controller
], 200); ], 200);
} }
public function getTotalProjectPerBudgetHealth($year = '%') public function getTotalProjectPerBudgetHealth()
{ {
$year = $this->interpolateYear($year);
return response()->json([ return response()->json([
'data' => [ 'data' => [
'overrun' => Project::where('mulai_proyek', 'like', $year)->where('budget_health', 'overrun')->count(), 'overrun' => Project::where('budget_health', 'overrun')->count(),
'warning' => Project::where('mulai_proyek', 'like', $year)->where('budget_health', 'warning')->count(), 'warning' => Project::where('budget_health', 'warning')->count(),
'on-budget' => Project::where('mulai_proyek', 'like', $year)->where('budget_health', 'on-budget')->count(), 'on-budget' => Project::where('budget_health', 'on-budget')->count(),
] ]
], 200); ], 200);
} }
private function countTotalProjectByBudgetHealthInDivision($divisi, $year, $health) private function countTotalProjectByBudgetHealthInDivision($divisi, $health)
{ {
return Project::where('divisi_id', $divisi) return Project::where('divisi_id', $divisi)
->where('mulai_proyek', 'like', $year) // ->where('mulai_proyek', 'like', $year)
/* ->orWhere('akhir_proyek', 'like', $year) */ /* ->orWhere('akhir_proyek', 'like', $year) */
->where('budget_health', $health) ->where('budget_health', $health)
->count(); ->count();
} }
public function getTotalProjectBudgetHealthPerDivision($year = '%') public function getTotalProjectBudgetHealthPerDivision()
{ {
$year = $this->interpolateYear($year); // $year = $this->interpolateYear($year);
$divisions = Divisi::select('id', 'name') $divisions = Divisi::select('id', 'name')
->with('children') ->with('children')
->whereNull('parent') ->whereNull('parent')
@ -242,13 +241,13 @@ class DashboardBoDController extends Controller
// to do : count in more than 1 level child // to do : count in more than 1 level child
foreach ($divisions as $division) { foreach ($divisions as $division) {
$budgetData = new Collection(); $budgetData = new Collection();
$budgetData->prepend($this->countTotalProjectByBudgetHealthInDivision($division->id, $year, 'overrun'), 'overrun'); $budgetData->prepend($this->countTotalProjectByBudgetHealthInDivision($division->id, 'overrun'), 'overrun');
$budgetData->prepend($this->countTotalProjectByBudgetHealthInDivision($division->id, $year, 'warning'), 'warning'); $budgetData->prepend($this->countTotalProjectByBudgetHealthInDivision($division->id, 'warning'), 'warning');
$budgetData->prepend($this->countTotalProjectByBudgetHealthInDivision($division->id, $year, 'on-budget'), 'on-budget'); $budgetData->prepend($this->countTotalProjectByBudgetHealthInDivision($division->id, 'on-budget'), 'on-budget');
foreach ($division->children as $d) { foreach ($division->children as $d) {
$budgetData['overrun'] += $this->countTotalProjectByBudgetHealthInDivision($d->id, $year, 'overrun'); $budgetData['overrun'] += $this->countTotalProjectByBudgetHealthInDivision($d->id, 'overrun');
$budgetData['warning'] += $this->countTotalProjectByBudgetHealthInDivision($d->id, $year, 'warning'); $budgetData['warning'] += $this->countTotalProjectByBudgetHealthInDivision($d->id, 'warning');
$budgetData['on-budget'] += $this->countTotalProjectByBudgetHealthInDivision($d->id, $year, 'on-budget'); $budgetData['on-budget'] += $this->countTotalProjectByBudgetHealthInDivision($d->id, 'on-budget');
} }
unset($division->children); unset($division->children);
$division->budgetData = $budgetData; $division->budgetData = $budgetData;
@ -262,13 +261,13 @@ class DashboardBoDController extends Controller
], 200); ], 200);
} }
public function getTotalProjectPerPhase($year = '%') public function getTotalProjectPerPhase()
{ {
$year = $this->interpolateYear($year); // $year = $this->interpolateYear($year);
$projectPhases = ProjectPhase::orderBy('order')->get(); $projectPhases = ProjectPhase::orderBy('order')->get();
foreach ($projectPhases as $phase) { foreach ($projectPhases as $phase) {
$phase->totalProject = Project::where('phase_id', $phase->id) $phase->totalProject = Project::where('phase_id', $phase->id)
->where('mulai_proyek', 'like', $year) // ->where('mulai_proyek', 'like', $year)
/* ->orWhere('akhir_proyek', 'like', $year) */ /* ->orWhere('akhir_proyek', 'like', $year) */
->count(); ->count();
} }
@ -279,16 +278,16 @@ class DashboardBoDController extends Controller
], 200); ], 200);
} }
private function countTotalProjectInDivision($id, $year) private function countTotalProjectInDivision($id)
{ {
return Project::where('divisi_id', $id) return Project::where('divisi_id', $id)
->where('mulai_proyek', 'like', $year) // ->where('mulai_proyek', 'like', $year)
->count(); ->count();
} }
public function getTotalProjectPerDivision($year = '%') public function getTotalProjectPerDivision()
{ {
$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')
@ -297,9 +296,9 @@ class DashboardBoDController extends Controller
// to do : count in more than 1 level child // to do : count in more than 1 level child
foreach ($divisions as $v) { foreach ($divisions as $v) {
$v->total = $this->countTotalProjectInDivision($v->id, $year); $v->total = $this->countTotalProjectInDivision($v->id);
foreach ($v->children as $d) { foreach ($v->children as $d) {
$v->total += $this->countTotalProjectInDivision($d->id, $year); $v->total += $this->countTotalProjectInDivision($d->id);
} }
unset($v->children); unset($v->children);
} }
@ -309,20 +308,18 @@ class DashboardBoDController extends Controller
], 200); ], 200);
} }
private function countTotalProjectValueInDivision($id, $year) private function countTotalProjectValueInDivision($id)
{ {
return Project::select(DB::raw("SUM(CAST(REPLACE(rencana_biaya, ',', '.') AS DOUBLE PRECISION))")) return Project::select(DB::raw("SUM(CAST(REPLACE(rencana_biaya, ',', '.') AS DOUBLE PRECISION))"))
->where('mulai_proyek', 'like', $year) // ->where('mulai_proyek', 'like', $year)
/* ->orWhere('akhir_proyek', 'like', $year) */ /* ->orWhere('akhir_proyek', 'like', $year) */
->where('divisi_id', $id) ->where('divisi_id', $id)
->pluck('sum') ->pluck('sum')
->first(); ->first();
} }
public function getTotalProjectValuePerDivision($year = '%') public function getTotalProjectValuePerDivision()
{ {
$year = $this->interpolateYear($year);
$divisions = Divisi::select('id', 'name', 'color') $divisions = Divisi::select('id', 'name', 'color')
->with('children') ->with('children')
->whereNull('parent') ->whereNull('parent')
@ -330,9 +327,9 @@ class DashboardBoDController extends Controller
// to do : count in more than 1 level child // to do : count in more than 1 level child
foreach ($divisions as $v) { foreach ($divisions as $v) {
$v->total = $this->countTotalProjectValueInDivision($v->id, $year); $v->total = $this->countTotalProjectValueInDivision($v->id);
foreach ($v->children as $d) { foreach ($v->children as $d) {
$v->total += $this->countTotalProjectValueInDivision($d->id, $year); $v->total += $this->countTotalProjectValueInDivision($d->id);
} }
unset($v->children); unset($v->children);
} }
@ -343,12 +340,13 @@ class DashboardBoDController extends Controller
} }
public function getDetailExpenditure($year = '%') public function getDetailExpenditure()
{ {
$year = $this->interpolateYear($year); // $year = $this->interpolateYear($year);
$projects = Project::select('m_proyek.*', 'md.name as divisi_name') $projects = Project::select('m_proyek.*', 'md.name as divisi_name', 'tpy.name as project_type_name')
->where('mulai_proyek', 'like', $year) // ->where('mulai_proyek', 'like', $year)
->join('m_divisi as md', 'md.id', '=', 'm_proyek.divisi_id') ->join('m_divisi as md', 'md.id', '=', 'm_proyek.divisi_id')
->join('m_type_proyek as tpy', 'tpy.id', '=', 'm_proyek.type_proyek_id')
->orderBy('id', 'desc') ->orderBy('id', 'desc')
->get(); ->get();
foreach ($projects as $project) { foreach ($projects as $project) {

92
app/Http/Controllers/DivisiController.php

@ -8,21 +8,23 @@ use App\Models\Divisi;
class DivisiController extends Controller class DivisiController extends Controller
{ {
private function getAllChildren($divisi, $depth = 0, $array = []) { private function getAllChildren($divisi, $depth = 0, $array = [])
{
$divisi->depth = $depth; $divisi->depth = $depth;
array_push($array, $divisi); array_push($array, $divisi);
foreach($divisi->children as $child){ foreach ($divisi->children as $child) {
$array = $this->getAllChildren($child, $depth + 1, $array); $array = $this->getAllChildren($child, $depth + 1, $array);
} }
return $array; return $array;
} }
public function add(Request $request){ public function add(Request $request)
{
$this->validate($request, [ $this->validate($request, [
'name' => 'string|required|unique:m_divisi,name', 'name' => 'string|required|unique:m_divisi,name',
'description' => 'nullable|string', 'description' => 'nullable|string',
'parent' => 'nullable|integer', 'parent' => 'nullable|integer',
'color'=>'nullable|string|max:10' 'color' => 'nullable|string|max:10'
]); ]);
$data = $request->all(); $data = $request->all();
@ -30,15 +32,16 @@ class DivisiController extends Controller
$result = Divisi::create($data); $result = Divisi::create($data);
if(!$result) if (!$result)
return response()->json(['status'=>'failed','message'=>'Failed to add data','code'=> 500]); return response()->json(['status' => 'failed', 'message' => 'Failed to add data', 'code' => 500]);
return response()->json(['status'=>'success','message'=>'Data created!','code'=>200]); return response()->json(['status' => 'success', 'message' => 'Data created!', 'code' => 200]);
} }
public function update(Request $request, $id){ public function update(Request $request, $id)
if(empty($id) || !is_int((int)$id)) {
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); if (empty($id) || !is_int((int)$id))
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
$this->validate($request, [ $this->validate($request, [
'name' => 'string|required', 'name' => 'string|required',
@ -47,46 +50,59 @@ class DivisiController extends Controller
]); ]);
$data = Divisi::find($id); $data = Divisi::find($id);
$request->name !== $data['name'] ? $this->validate($request,['name'=>'unique:m_divisi,name']) : ''; $request->name !== $data['name'] ? $this->validate($request, ['name' => 'unique:m_divisi,name']) : '';
if(!$data) if (!$data)
return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404); return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
$result = $data->update($request->all()); $result = $data->update($request->all());
if(!$result) if (!$result)
return response()->json(['status'=>'failed','message'=> 'Update failed!','code'=> 500], 500); return response()->json(['status' => 'failed', 'message' => 'Update failed!', 'code' => 500], 500);
return response()->json(['status'=>'success','message'=>'Data added!','code'=>200], 200); return response()->json(['status' => 'success', 'message' => 'Data added!', 'code' => 200], 200);
} }
public function delete($id) public function delete($id)
{ {
if(empty($id) || !is_int((int)$id)) if (empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
$data = Divisi::find($id); $data = Divisi::find($id);
if(!$data) if (!$data)
return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404); return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
$delete = $data->delete(); $delete = $data->delete();
if(!$delete) if (!$delete)
return response()->json(['status'=>'failed','message'=> 'Delete failed!','code'=> 500], 500); return response()->json(['status' => 'failed', 'message' => 'Delete failed!', 'code' => 500], 500);
return response()->json(['status'=>'success','message'=> 'Data deleted!','code'=> 200], 200); return response()->json(['status' => 'success', 'message' => 'Data deleted!', 'code' => 200], 200);
} }
public function search(Request $request) public function search(Request $request)
{ {
$payload = $request->all(); $parentDivisi = Divisi::whereNull('parent')->with('children')->get();
$dataBuilder = $this->setUpPayload($payload, 'm_divisi'); $divisions = [];
$builder = $dataBuilder['builder']; foreach ($parentDivisi as $objRow) {
$countBuilder = $dataBuilder['count']; $objRow->children = $this->getAllChildren($objRow);
$dataGet = $builder->get(); // $objRow->key = rand(1, 1000);
$totalRecord = $countBuilder->count(); $divisions[] = $objRow;
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); }
$countData = count($divisions);
if ($countData == 0)
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
return response()->json(['status' => 'success', 'code' => 200, 'data' => $divisions, 'totalRecord' => $countData], 200);
// $payload = $request->all();
// $dataBuilder = $this->setUpPayload($payload, 'm_divisi');
// $builder = $dataBuilder['builder'];
// $countBuilder = $dataBuilder['count'];
// $dataGet = $builder->get();
// $totalRecord = $countBuilder->count();
// return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => $totalRecord], 200);
//return $this->list(); //return $this->list();
// cant use builder for this case // cant use builder for this case
} }
@ -95,20 +111,20 @@ class DivisiController extends Controller
{ {
$parentMenus = Divisi::whereNull('parent')->with('children')->get(); $parentMenus = Divisi::whereNull('parent')->with('children')->get();
$divisions = []; $divisions = [];
foreach($parentMenus as $menu){ foreach ($parentMenus as $menu) {
$childs = $this->getAllChildren($menu); $childs = $this->getAllChildren($menu);
foreach($childs as $d){ foreach ($childs as $d) {
$d->displayName = ' ' . $d->name; $d->displayName = ' ' . $d->name;
for($i=0; $i < $d->depth; $i++){ for ($i = 0; $i < $d->depth; $i++) {
$d->displayName = '--' . $d->displayName ; $d->displayName = '--' . $d->displayName;
} }
array_push($divisions, $d); array_push($divisions, $d);
} }
} }
$countData = count($divisions); $countData = count($divisions);
if($countData == 0) if ($countData == 0)
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
return response()->json(['status'=>'success','code'=>200,'data'=> $divisions, 'totalRecord'=> $countData], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $divisions, 'totalRecord' => $countData], 200);
} }
} }

20
app/Http/Controllers/ProjectController.php

@ -123,7 +123,8 @@ class ProjectController extends Controller
'phase_id', 'phase_id',
'calculation_status', 'calculation_status',
'md.name as divisi_name', 'md.name as divisi_name',
'nickname' 'nickname',
'sponsor'
) )
->join('m_divisi as md', 'md.id', '=', 'm_proyek.divisi_id') ->join('m_divisi as md', 'md.id', '=', 'm_proyek.divisi_id')
->where('m_proyek.id', $id) ->where('m_proyek.id', $id)
@ -322,7 +323,8 @@ class ProjectController extends Controller
'created_at', 'created_at',
'created_by', 'created_by',
'updated_at', 'updated_at',
'updated_by' 'updated_by',
'sponsor'
)->orderBy('id', 'desc') )->orderBy('id', 'desc')
// ->where("created_by",$this->currentName) // ->where("created_by",$this->currentName)
->get(); ->get();
@ -620,19 +622,19 @@ class ProjectController extends Controller
// } // }
$plannedStart = Activity::where('version_gantt_id', $ganttId) $plannedStart = Activity::where('version_gantt_id', $ganttId)
->orderBy('planned_start') ->orderBy('planned_start')
->value('planned_start'); ->value('planned_start');
$plannedEnd = Activity::where('version_gantt_id', $ganttId) $plannedEnd = Activity::where('version_gantt_id', $ganttId)
->orderByDesc('planned_end') ->orderByDesc('planned_end')
->value('planned_end'); ->value('planned_end');
if (isset($result->header)) { if (isset($result->header)) {
$result->header->start_date = $startDate; $result->header->start_date = $startDate;
$result->header->end_date = $maxEndDate->end_date; $result->header->end_date = $maxEndDate->end_date;
$result->header->planned_start = $plannedStart; $result->header->planned_start = $plannedStart;
$result->header->planned_end = $plannedEnd; $result->header->planned_end = $plannedEnd;
} }
return response()->json(['status'=>'success','code'=> 200,'data'=>$result, 'gantt'=>$ganttId], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $result, 'gantt' => $ganttId], 200);
} }
public function getOverdueActivities(Request $request) public function getOverdueActivities(Request $request)

3
app/Models/Project.php

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

20
routes/web.php

@ -23,16 +23,16 @@ $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', 'DashboardBoDController@getCompanyCashFlow'); // project expenditure
$router->get('/dashboard/get-invoice-outstanding[/{year}]', 'DashboardBoDController@getInvoiceOutstanding'); // project invoice vs cash in $router->get('/dashboard/get-invoice-outstanding', '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', 'DashboardBoDController@getTotalProjectPerScheduleHealth');
$router->get('/dashboard/get-total-project-per-budget-health[/{year}]', 'DashboardBoDController@getTotalProjectPerBudgetHealth'); $router->get('/dashboard/get-total-project-per-budget-health', 'DashboardBoDController@getTotalProjectPerBudgetHealth');
$router->get('/dashboard/get-total-project-schedule-health-per-division[/{year}]', 'DashboardBoDController@getTotalProjectScheduleHealthPerDivision'); $router->get('/dashboard/get-total-project-schedule-health-per-division', 'DashboardBoDController@getTotalProjectScheduleHealthPerDivision');
$router->get('/dashboard/get-total-project-budget-health-per-division[/{year}]', 'DashboardBoDController@getTotalProjectBudgetHealthPerDivision'); $router->get('/dashboard/get-total-project-budget-health-per-division', 'DashboardBoDController@getTotalProjectBudgetHealthPerDivision');
$router->get('/dashboard/get-total-project-per-phase[/{year}]', 'DashboardBoDController@getTotalProjectPerPhase'); $router->get('/dashboard/get-total-project-per-phase', 'DashboardBoDController@getTotalProjectPerPhase');
$router->get('/dashboard/get-total-project-per-division[/{year}]', 'DashboardBoDController@getTotalProjectPerDivision'); $router->get('/dashboard/get-total-project-per-division', 'DashboardBoDController@getTotalProjectPerDivision');
$router->get('/dashboard/get-total-project-value-per-division[/{year}]', 'DashboardBoDController@getTotalProjectValuePerDivision'); $router->get('/dashboard/get-total-project-value-per-division', 'DashboardBoDController@getTotalProjectValuePerDivision');
$router->get('/dashboard/get-detail-expenditure[/{year}]', 'DashboardBoDController@getDetailExpenditure'); $router->get('/dashboard/get-detail-expenditure', 'DashboardBoDController@getDetailExpenditure');
$router->post('/role/search', 'RoleController@search'); $router->post('/role/search', 'RoleController@search');
$router->post('/role/add', 'RoleController@add'); $router->post('/role/add', 'RoleController@add');

Loading…
Cancel
Save