Browse Source

Merge branch 'dev-msy' into staging

pull/3/head
Yusuf 2 years ago
parent
commit
b1d3c5a75d
  1. 17
      app/Http/Controllers/Controller.php
  2. 50
      app/Models/Activity.php
  3. 1
      bootstrap/app.php
  4. 5
      config/decimal.php
  5. 2
      routes/web.php

17
app/Http/Controllers/Controller.php

@ -250,21 +250,4 @@ class Controller extends BaseController
$totalCost = AssignMaterial::selectRaw("ISNULL(qty_planning,0)*ISNULL(budget,0) as totalCost")->where("proyek_id", $proyek_id)->where("activity_id", $activity_id)->sum("totalCost");
return $totalCost;
}
protected function updatedCostPlanning($id)
{
$sumBiaya = Activity::select(DB::raw('sum(cast(rencana_biaya as double precision))'))->where("parent_id", $id)->first();
$dataActivity = Activity::find($id);
$dataUpdate = array(
"rencana_biaya" => $sumBiaya->sum,
"updated_by" => $this->currentName
);
$dataActivity->update($dataUpdate);
if($dataActivity){
$parent = $dataActivity->parent_id;
if($parent && (int)$parent > 0){
$this->updateCostPlanning($parent);
}
}
}
}

50
app/Models/Activity.php

@ -38,30 +38,47 @@ class Activity extends Model
parent::boot();
static::updated(function($data) {
$data->updateBobot();
$data->updateCostPlanning();
$data->updatePersentaseProgress();
$data->updateCostActual();
});
static::deleted(function($data) {
if(Activity::where("parent_id", $data->parent_id)->count() == 0)
Activity::find($data->parent_id)->update(["type_activity"=>"task"]);
// update bobot
if(Activity::where('version_gantt_id', $data->version_gantt_id)->where("proyek_id", $data->proyek_id)->where('type_activity', 'header')->count() == 0)
$data->updateCostPlanning();
$data->updatePersentaseProgress();
$data->updateCostActual();
});
}
private function updateBobot()
{
if(Activity::where('version_gantt_id', $this->version_gantt_id)->where("proyek_id", $this->proyek_id)->where('type_activity', 'header')->count() == 0)
$totalCost = Activity::select(
DB::raw('sum(cast(rencana_biaya as double precision))')
)
->where("proyek_id", $data->proyek_id)
->where("version_gantt_id", $data->version_gantt_id)
->where("proyek_id", $this->proyek_id)
->where("version_gantt_id", $this->version_gantt_id)
->whereNull("parent_id")
->first();
$rootActivity = Activity::where('version_gantt_id', $data->version_gantt_id)
->where("proyek_id", $data->proyek_id)
$rootActivity = Activity::where('version_gantt_id', $this->version_gantt_id)
->where("proyek_id", $this->proyek_id)
->where('type_activity', 'header')
->first();
$totalCost = Activity::select(DB::raw('sum(cast(rencana_biaya as double precision))'))
->where("proyek_id", $data->proyek_id)
->where("version_gantt_id", $data->version_gantt_id)
->where("proyek_id", $this->proyek_id)
->where("version_gantt_id", $this->version_gantt_id)
->where("parent_id", $rootActivity->id)
->first();
if($totalCost->sum > 0){
$activities = Activity::where("proyek_id", $data->proyek_id)->where("version_gantt_id", $data->version_gantt_id)->get();
$activities = Activity::where("proyek_id", $this->proyek_id)->where("version_gantt_id", $this->version_gantt_id)->get();
foreach ($activities as $activity) {
$activity->update([
"bobot_planning" => ( (int)$activity->rencana_biaya / $totalCost->sum ) * 100,
@ -70,21 +87,6 @@ class Activity extends Model
$activity->save();
}
}
$data->updateCostPlanning();
$data->updatePersentaseProgress();
$data->updateCostActual();
});
static::deleted(function($data) {
if(Activity::where("parent_id", $data->parent_id)->count() == 0)
Activity::find($data->parent_id)->update(["type_activity"=>"task"]);
$data->updateCostPlanning();
$data->updatePersentaseProgress();
$data->updateCostActual();
});
}
private function updateCostActual()

1
bootstrap/app.php

@ -84,6 +84,7 @@ $app->middleware([
$app->routeMiddleware([
'auth' => App\Http\Middleware\Authenticate::class,
'cors' => App\Http\Middleware\CorsMiddleware::class
]);
/*

5
config/decimal.php

@ -0,0 +1,5 @@
<?php
return [
'precision' => 5,
];
?>

2
routes/web.php

@ -21,7 +21,7 @@ $router->group(['prefix'=>'api'], function () use ($router) {
$router->post('/role-menu/search', 'RoleMenuController@search');
$router->get('/role-menu/get-role/{id}', 'RoleMenuController@listMenu');
$router->group(['middleware' => 'auth'], function () use ($router) {
$router->group(['middleware' => ['auth', 'cors']], function () use ($router) {
$router->post('/role/search', 'RoleController@search');
$router->post('/role/add', 'RoleController@add');

Loading…
Cancel
Save