Browse Source

Merge pull request 'staging upload 23-04-04' (#12) from staging into master

Reviewed-on: ordo/adw-backend#12
pull/3/head
ibnu 2 years ago
parent
commit
93f67ac751
  1. 8
      app/Http/Controllers/Controller.php
  2. 34
      app/Http/Controllers/HierarchyFtthController.php
  3. 4
      app/Http/Controllers/HumanResourceController.php
  4. 4
      app/Http/Controllers/ProjectController.php
  5. 11
      app/Http/Controllers/UserToActivityController.php
  6. 7
      routes/web.php

8
app/Http/Controllers/Controller.php

@ -3,6 +3,9 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Http;
use App\Models\UserToActivity;
use App\Models\Activity;
use App\Models\AssignMaterial;
use Laravel\Lumen\Routing\Controller as BaseController; use Laravel\Lumen\Routing\Controller as BaseController;
use App\Models\ReportK3Detail; use App\Models\ReportK3Detail;
@ -250,7 +253,10 @@ class Controller extends BaseController
private function calculateMaterialCost($activity_id, $proyek_id) private function calculateMaterialCost($activity_id, $proyek_id)
{ {
$totalCost = AssignMaterial::selectRaw("ISNULL(qty_planning,0)*ISNULL(budget,0) as totalCost")->where("proyek_id", $proyek_id)->where("activity_id", $activity_id)->sum("totalCost"); $totalCost = AssignMaterial::selectRaw("COALESCE(qty_planning,0)*COALESCE(budget,0) as totalCost")
->where("proyek_id", $proyek_id)
->where("activity_id", $activity_id)
->sum(AssignMaterial::raw("COALESCE(qty_planning, 0) * COALESCE(budget, 0)"));
return $totalCost; return $totalCost;
} }

34
app/Http/Controllers/HierarchyFtthController.php

@ -49,8 +49,9 @@ class HierarchyFtthController extends Controller
} }
} }
public function show(HierarchyFtth $hierarchyFtth) public function show($id)
{ {
$hierarchyFtth = HierarchyFtth::where('id', $id)->first();
try { try {
return response()->json($hierarchyFtth); return response()->json($hierarchyFtth);
} catch (\Exception $e) { } catch (\Exception $e) {
@ -61,8 +62,9 @@ class HierarchyFtthController extends Controller
} }
} }
public function update(Request $request, HierarchyFtth $hierarchyFtth) public function update(Request $request, $id)
{ {
$hierarchyFtth = HierarchyFtth::where('id', $id)->first();
try { try {
$hierarchyFtth->update($request->all()); $hierarchyFtth->update($request->all());
@ -78,8 +80,9 @@ class HierarchyFtthController extends Controller
} }
} }
public function destroy(HierarchyFtth $hierarchyFtth) public function destroy($id)
{ {
$hierarchyFtth = HierarchyFtth::where('id', $id)->first();
try { try {
$hierarchyFtth->delete(); $hierarchyFtth->delete();
@ -94,4 +97,29 @@ class HierarchyFtthController extends Controller
], 500); ], 500);
} }
} }
public function getTreeByProject($project_id)
{
$data = HierarchyFtth::where('project_id', $project_id)->whereNull('parent_id')->orderByRaw('id ASC')->get();
$finalData = [];
foreach($data as $objRow){
$objRow->children = $this->getChildren($project_id, $objRow->id);
$objRow->key = rand(1, 1000);
$finalData[] = $objRow;
}
return response()->json(['status'=>'success','data'=>$finalData,'code'=>200], 200);
}
private function getChildren($project_id, $parent_id)
{
$finalData = [];
$data = HierarchyFtth::where('project_id', $project_id)->where('parent_id', $parent_id)->orderByRaw('id ASC')->get();
foreach($data as $objRow){
$objRow->key = rand(1, 1000);
$objRow->children = $this->getChildren($project_id, $objRow->id);
$finalData[] = $objRow;
}
return $finalData;
}
} }

4
app/Http/Controllers/HumanResourceController.php

@ -60,6 +60,10 @@ class HumanResourceController extends Controller
if(isset($request->password) && $request->password!="" ){ if(isset($request->password) && $request->password!="" ){
$data['password'] = md5($request->password); $data['password'] = md5($request->password);
} }
if(isset($data['username']) && HumanResource::where('username', $data['username'])->where('id', '<>', $id)->exists()){
return response()->json(['status'=>'failed','message'=>'Username already exists!','code'=>400], 400);
}
if($humanresource){ if($humanresource){
$result = $humanresource->update($data); $result = $humanresource->update($data);

4
app/Http/Controllers/ProjectController.php

@ -231,7 +231,7 @@ class ProjectController extends Controller
$scheduleHealth = "on-track"; $scheduleHealth = "on-track";
$rootActivity = Activity::whereNull('parent_id')->where('proyek_id', $d->id)->orderBy('version_gantt_id', 'desc')->first(); $rootActivity = Activity::whereNull('parent_id')->where('proyek_id', $d->id)->orderBy('version_gantt_id', 'desc')->first();
if($rootActivity){ if($rootActivity){
$costVariance = $d->rencana_biaya - $rootActivity->biaya_actual; $costVariance = (int)$d->rencana_biaya - (int)$rootActivity->biaya_actual;
$actualCost = $rootActivity->biaya_actual ?? 0; $actualCost = $rootActivity->biaya_actual ?? 0;
$progress = $rootActivity->persentase_progress ?? 0; $progress = $rootActivity->persentase_progress ?? 0;
@ -271,7 +271,7 @@ class ProjectController extends Controller
} }
} }
$totalPlannedCost = $data->sum('plannedCost'); $totalPlannedCost = array_sum(array_map('intval', array_column($data->toArray(), 'plannedCost')));
$totalActualCost = $data->sum('actualCost'); $totalActualCost = $data->sum('actualCost');
$manpowers = User::count(); $manpowers = User::count();
$projectsOnDanger = Project::where('budget_health', 'danger')->count(); $projectsOnDanger = Project::where('budget_health', 'danger')->count();

11
app/Http/Controllers/UserToActivityController.php

@ -72,6 +72,17 @@ class UserToActivityController extends Controller
} }
private function updatedCostPlanning($parent_id) {
$sumBiaya = Activity::selectRaw('sum(cast(rencana_biaya as double precision))')
->where("parent_id", $parent_id)
->first();
if($parent = Activity::find($parent_id)){
$parent->update([
"rencana_biaya" => $sumBiaya->sum,
]);
}
}
public function update(Request $request, $id){ public function update(Request $request, $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);

7
routes/web.php

@ -442,9 +442,10 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout
$router->get('/hierarchy-ftths', 'HierarchyFtthController@index'); $router->get('/hierarchy-ftths', 'HierarchyFtthController@index');
$router->post('/hierarchy-ftths', 'HierarchyFtthController@store'); $router->post('/hierarchy-ftths', 'HierarchyFtthController@store');
$router->post('/hierarchy-ftths/search', 'HierarchyFtthController@search'); $router->post('/hierarchy-ftths/search', 'HierarchyFtthController@search');
$router->get('/hierarchy-ftths/{hierarchyFtth}', 'HierarchyFtthController@show'); $router->get('/hierarchy-ftths/{id}', 'HierarchyFtthController@show');
$router->put('/hierarchy-ftths/{hierarchyFtth}', 'HierarchyFtthController@update'); $router->put('/hierarchy-ftths/{id}', 'HierarchyFtthController@update');
$router->delete('/hierarchy-ftths/{hierarchyFtth}', 'HierarchyFtthController@destroy'); $router->delete('/hierarchy-ftths/{id}', 'HierarchyFtthController@destroy');
$router->get('/hierarchy-ftths/tree/{project_id}', 'HierarchyFtthController@getTreeByProject');
$router->post('/map-monitoring/search', 'MapMonitoringController@search'); $router->post('/map-monitoring/search', 'MapMonitoringController@search');
}); });

Loading…
Cancel
Save