Browse Source

Merge branch 'staging' into dev-wahyun

pull/3/head
wahyun 1 year ago
parent
commit
f9a6d1f4fa
  1. 1962
      app/Helpers/MasterFunctionsHelper.php
  2. 1826
      app/Http/Controllers/ActivityController.php
  3. 436
      app/Http/Controllers/AssignMaterialController.php
  4. 5
      app/Http/Controllers/DivisiController.php
  5. 91
      app/Http/Controllers/ProjectController.php
  6. 18
      app/Http/Controllers/ReportActivityMaterialController.php
  7. 204
      app/Http/Controllers/RoleMenuController.php
  8. 492
      app/Models/Activity.php
  9. 92
      app/Models/AssignMaterial.php
  10. 146
      app/Models/ReportActivityMaterial.php
  11. 2
      routes/web.php

1962
app/Helpers/MasterFunctionsHelper.php

File diff suppressed because it is too large Load Diff

1826
app/Http/Controllers/ActivityController.php

File diff suppressed because it is too large Load Diff

436
app/Http/Controllers/AssignMaterialController.php

@ -1,215 +1,221 @@
<?php <?php
namespace App\Http\Controllers; namespace App\Http\Controllers;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\AssignMaterial; use App\Models\AssignMaterial;
use App\Models\RequestMaterial; use App\Models\RequestMaterial;
use App\Models\Activity; use App\Models\Activity;
use App\Models\ReportActivityMaterial; use App\Models\ReportActivityMaterial;
use Datatables; use Datatables;
class AssignMaterialController extends Controller class AssignMaterialController extends Controller
{ {
private function sanitizeDecimal($number) { private function sanitizeDecimal($number) {
$number = str_replace(".","",$number); $number = str_replace(".","",$number);
$number = str_replace(",",".",$number); $number = str_replace(",",".",$number);
return $number; return $number;
} }
public function add(Request $request){ public function add(Request $request){
$this->validate($request, [ $this->validate($request, [
'activity_id' => 'required', 'activity_id' => 'required',
'material_id' => 'required', 'material_id' => 'required',
'qty_planning' => 'required' 'qty_planning' => 'required'
]); ]);
$activity = Activity::where('id', $request->activity_id)->first(); $activity = Activity::where('id', $request->activity_id)->first();
$checkStock = RequestMaterial::where("id", $request->material_id)->first(); $checkStock = RequestMaterial::where("id", $request->material_id)->first();
$currentStock = $checkStock->qty; $currentStock = $checkStock->qty;
if((int)$currentStock < (int)$request->qty_planning){ if((int)$currentStock < (int)$request->qty_planning){
return response()->json(['status'=>'failed','message'=>'Stock is not enough!','code'=> 500]); return response()->json(['status'=>'failed','message'=>'Stock is not enough!','code'=> 500]);
} }
$start_date = $activity->start_date; $start_date = $activity->start_date;
$start_date = substr($start_date, 0, 19); // remove the timezone offset $start_date = substr($start_date, 0, 19); // remove the timezone offset
$startDate = new \DateTime(date("Y-m-d", strtotime($start_date))); $startDate = new \DateTime(date("Y-m-d", strtotime($start_date)));
$planDate = new \DateTime(date("Y-m-d", strtotime($request->plan_date))); $planDate = new \DateTime(date("Y-m-d", strtotime($request->plan_date)));
$data = $request->all(); $data = $request->all();
$data['created_by'] = $this->currentName; $data['created_by'] = $this->currentName;
$data['budget'] = $checkStock->price; $data['budget'] = $checkStock->price;
$data['qty_planning'] = $this->sanitizeDecimal($data['qty_planning']); $data['qty_planning'] = $this->sanitizeDecimal($data['qty_planning']);
if ($planDate >= $startDate) { if ($planDate >= $startDate) {
$result = AssignMaterial::create($data); $result = AssignMaterial::create($data);
return response()->json(['status'=>'success','message'=>'Data added!', 'code'=>200], 200); return response()->json(['status'=>'success','message'=>'Data added!', 'code'=>200], 200);
}else{ }else{
return response()->json(['status'=>'failed','message'=>'Failed to add data!','code'=> 400], 400); return response()->json(['status'=>'failed','message'=>'Failed to add data!','code'=> 400], 400);
} }
} }
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);
$data = AssignMaterial::find($id); $data = AssignMaterial::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);
$result = $data->update($request->all()); $result = $data->update($request->all());
if($result) if($result)
return response()->json(['status'=>'success','message'=> 'Data updated!','code'=> 200], 200); return response()->json(['status'=>'success','message'=> 'Data updated!','code'=> 200], 200);
return response()->json(['status'=>'failed','message'=>'Failed to update!','code'=> 500], 500); return response()->json(['status'=>'failed','message'=>'Failed to update!','code'=> 500], 500);
} }
public function delete($id) public function delete($id)
{ {
$data = AssignMaterial::where('id', $id)->first(); $data = AssignMaterial::where('id', $id)->first();
$reports = ReportActivityMaterial::where('assign_material_id', $data->id)->get();
if($data->delete()) if (isset($reports)) {
return response()->json(['status'=>'success','message'=>'Data deleted!','code'=> 200], 200); foreach ($reports as $report) {
$report->delete();
return response()->json(['status'=>'failed','message'=>'Failed to delete!','code'=> 500], 500); }
} }
public function edit($id){ if($data->delete())
if(empty($id) || !is_int((int)$id)) return response()->json(['status'=>'success','message'=>'Data deleted!','code'=> 200], 200);
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
return response()->json(['status'=>'failed','message'=>'Failed to delete!','code'=> 500], 500);
$result = AssignMaterial::find($id); }
if($result) public function edit($id){
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); 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'=>'Data not found!','code'=> 404], 404);
} $result = AssignMaterial::find($id);
public function search(Request $request) if($result)
{ return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200);
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'assign_material_to_activity'); return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
$builder = $dataBuilder['builder']; }
$countBuilder = $dataBuilder['count'];
$dataGet = $builder->get(); public function search(Request $request)
$totalRecord = $countBuilder->count(); {
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); $payload = $request->all();
} $dataBuilder = $this->setUpPayload($payload, 'assign_material_to_activity');
$builder = $dataBuilder['builder'];
public function list() $countBuilder = $dataBuilder['count'];
{ $dataGet = $builder->get();
$data = AssignMaterial::all(); $totalRecord = $countBuilder->count();
$countData = $data->count(); return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
}
if($data)
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); public function list()
{
return response()->json(['status'=>'failed','message'=>'Failed to get the data!','code'=> 500], 500); $data = AssignMaterial::all();
} $countData = $data->count();
public function datatables(Request $request){ if($data)
$id_activity = $request->query('idact'); return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200);
$type = $request->query('type') ?? "material";
$data = AssignMaterial::select( return response()->json(['status'=>'failed','message'=>'Failed to get the data!','code'=> 500], 500);
"assign_material_to_activity.*","m.description as material_name", "m.uom as uom" }
)
->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id") public function datatables(Request $request){
->where('assign_material_to_activity.activity_id', $id_activity) $id_activity = $request->query('idact');
->where('assign_material_to_activity.type', $type) $type = $request->query('type') ?? "material";
->orderBy('plan_date', 'desc') $data = AssignMaterial::select(
->get(); "assign_material_to_activity.*","m.description as material_name", "m.uom as uom"
return Datatables::of($data) )
->addIndexColumn() ->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id")
->addColumn('action', function($row){ ->where('assign_material_to_activity.activity_id', $id_activity)
$actionBtn = '<a href="javascript:void(0)" data-id="'.$row->id.'" class="delete btn btn-danger btn-sm btn-material-delete"><i class="fa fa-trash"></i></a>'; ->where('assign_material_to_activity.type', $type)
return $actionBtn; ->orderBy('plan_date', 'desc')
}) ->get();
->rawColumns(['action'])->make(true); return Datatables::of($data)
} ->addIndexColumn()
->addColumn('action', function($row){
public function datatablesForReportActivity(Request $request){ $actionBtn = '<a href="javascript:void(0)" data-id="'.$row->id.'" class="delete btn btn-danger btn-sm btn-material-delete"><i class="fa fa-trash"></i></a>';
$id_activity = $request->query('idact'); return $actionBtn;
$data = })
AssignMaterial::select( ->rawColumns(['action'])->make(true);
AssignMaterial::raw('SUM(qty_planning) as qty_planning'), }
"m.description as material_name",
"assign_material_to_activity.activity_id", public function datatablesForReportActivity(Request $request){
"assign_material_to_activity.type" $id_activity = $request->query('idact');
// "assign_material_to_activity.material_id", $data =
) AssignMaterial::select(
->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id") AssignMaterial::raw('SUM(qty_planning) as qty_planning'),
->groupBy("m.description") "m.description as material_name",
->groupBy("assign_material_to_activity.activity_id") "assign_material_to_activity.activity_id",
->groupBy("assign_material_to_activity.type") "assign_material_to_activity.type"
->where("assign_material_to_activity.activity_id", $id_activity)->get(); // "assign_material_to_activity.material_id",
return Datatables::of($data) )
->addIndexColumn() ->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id")
->addColumn('qty_sum', function($row){ ->groupBy("m.description")
$val_qty_act = AssignMaterial::select(ReportActivityMaterial::raw('SUM(ram.qty) as qty_sum'),"m.description as material_name1") ->groupBy("assign_material_to_activity.activity_id")
->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id") ->groupBy("assign_material_to_activity.type")
->join("report_activity_material as ram", "ram.assign_material_id", "=", "assign_material_to_activity.id") ->where("assign_material_to_activity.activity_id", $id_activity)->get();
->groupBy("m.description") return Datatables::of($data)
->where("m.description", strval($row->material_name)) ->addIndexColumn()
->where("ram.activity_id", $row->activity_id)->first(); ->addColumn('qty_sum', function($row){
return $val_qty_act ? $val_qty_act->qty_sum : '-'; $val_qty_act = AssignMaterial::select(ReportActivityMaterial::raw('SUM(ram.qty) as qty_sum'),"m.description as material_name1")
}) ->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id")
->addColumn('status_activity', function($row){ ->join("report_activity_material as ram", "ram.assign_material_id", "=", "assign_material_to_activity.id")
$val_status = AssignMaterial::select("status_activity") ->groupBy("m.description")
->join('m_req_material as m', 'm.id', '=', 'assign_material_to_activity.material_id') ->where("m.description", strval($row->material_name))
->where('m.description', '=', $row->material_name) ->where("ram.activity_id", $row->activity_id)->first();
->where("assign_material_to_activity.activity_id", $row->activity_id)->first(); return $val_qty_act ? $val_qty_act->qty_sum : '-';
return $val_status ? $val_status->status_activity : null; })
}) ->addColumn('status_activity', function($row){
->addColumn('start_activity', function($row){ $val_status = AssignMaterial::select("status_activity")
$val_start = AssignMaterial::select("start_activity") ->join('m_req_material as m', 'm.id', '=', 'assign_material_to_activity.material_id')
->join('m_req_material as m', 'm.id', '=', 'assign_material_to_activity.material_id') ->where('m.description', '=', $row->material_name)
->where('m.description', '=', $row->material_name) ->where("assign_material_to_activity.activity_id", $row->activity_id)->first();
->where("assign_material_to_activity.activity_id", $row->activity_id)->first(); return $val_status ? $val_status->status_activity : null;
return $val_start ? $val_start->start_activity : null; })
}) ->addColumn('start_activity', function($row){
->addColumn('finish_activity', function($row){ $val_start = AssignMaterial::select("start_activity")
$val_finish = AssignMaterial::select("finish_activity") ->join('m_req_material as m', 'm.id', '=', 'assign_material_to_activity.material_id')
->join('m_req_material as m', 'm.id', '=', 'assign_material_to_activity.material_id') ->where('m.description', '=', $row->material_name)
->where('m.description', '=', $row->material_name) ->where("assign_material_to_activity.activity_id", $row->activity_id)->first();
->where("assign_material_to_activity.activity_id", $row->activity_id)->first(); return $val_start ? $val_start->start_activity : null;
return $val_finish ? $val_finish->finish_activity : null; })
}) ->addColumn('finish_activity', function($row){
->addColumn('uom', function($row){ $val_finish = AssignMaterial::select("finish_activity")
$val_uom = RequestMaterial::select("uom") ->join('m_req_material as m', 'm.id', '=', 'assign_material_to_activity.material_id')
->where('description', '=', $row->material_name)->first(); ->where('m.description', '=', $row->material_name)
return $val_uom ? $val_uom->uom : null; ->where("assign_material_to_activity.activity_id", $row->activity_id)->first();
}) return $val_finish ? $val_finish->finish_activity : null;
->addColumn('assign_material_id', function($row){ })
$assignMaterial =AssignMaterial::select('assign_material_to_activity.id')->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id") ->addColumn('uom', function($row){
->where('activity_id', $row->activity_id)->where('m.description', $row->material_name)->first(); $val_uom = RequestMaterial::select("uom")
return $assignMaterial ? $assignMaterial->id : null; ->where('description', '=', $row->material_name)->first();
}) return $val_uom ? $val_uom->uom : null;
->addColumn('action', function($row){ })
$dataPlan = AssignMaterial::select('assign_material_to_activity.id')->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id") ->addColumn('assign_material_id', function($row){
->where('activity_id', $row->activity_id)->where('m.description', $row->material_name)->first(); $assignMaterial =AssignMaterial::select('assign_material_to_activity.id')->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id")
$actionBtn = '<a href="javascript:void(0)" data-id="'.$dataPlan->id.'" data-activity_id="'.$row->activity_id.'" data-material-name="'.$row->material_name.'" class="primary btn btn-primary btn-sm btn-lihat-plan" data-toggle="tooltip" title="Lihat Plan" data-placement="top"><i class="fa fa-align-justify"></i></a>'; ->where('activity_id', $row->activity_id)->where('m.description', $row->material_name)->first();
$actionBtn .= '<a href="javascript:void(0)" data-id="'.$dataPlan->id.'" data-activity_id="'.$row->activity_id.'" data-material-name="'.$row->material_name.'" class="warning btn btn-warning btn-sm btn-lihat-actual" data-toggle="tooltip" title="Input Progress" data-placement="top"><i class="fa fa-edit" aria-hidden="true"></i></a>'; return $assignMaterial ? $assignMaterial->id : null;
return $actionBtn; })
}) ->addColumn('action', function($row){
->rawColumns(['action'])->make(true); $dataPlan = AssignMaterial::select('assign_material_to_activity.id')->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id")
} ->where('activity_id', $row->activity_id)->where('m.description', $row->material_name)->first();
$actionBtn = '<a href="javascript:void(0)" data-id="'.$dataPlan->id.'" data-activity_id="'.$row->activity_id.'" data-material-name="'.$row->material_name.'" class="primary btn btn-primary btn-sm btn-lihat-plan" data-toggle="tooltip" title="Lihat Plan" data-placement="top"><i class="fa fa-align-justify"></i></a>';
public function ForReportActivityByMaterial(Request $request){ $actionBtn .= '<a href="javascript:void(0)" data-id="'.$dataPlan->id.'" data-activity_id="'.$row->activity_id.'" data-material-name="'.$row->material_name.'" class="warning btn btn-warning btn-sm btn-lihat-actual" data-toggle="tooltip" title="Input Progress" data-placement="top"><i class="fa fa-edit" aria-hidden="true"></i></a>';
$id_activity = $request->idact; return $actionBtn;
$data = AssignMaterial::select("assign_material_to_activity.*","m.description as material_name", "m.uom as uom") })
->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id") ->rawColumns(['action'])->make(true);
->where('assign_material_to_activity.activity_id', $id_activity)->get(); }
foreach ($data as $key) {
$val_qty_sum = ReportActivityMaterial::where('assign_material_id', '=', $key->id)->sum("qty"); public function ForReportActivityByMaterial(Request $request){
} $id_activity = $request->idact;
$countData = $data->count(); $data = AssignMaterial::select("assign_material_to_activity.*","m.description as material_name", "m.uom as uom")
if($data){ ->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id")
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); ->where('assign_material_to_activity.activity_id', $id_activity)->get();
}else{ foreach ($data as $key) {
return response()->json(['status'=>'failed','message'=>'failed get Assign material, please try again later!','code'=>400], 400); $val_qty_sum = ReportActivityMaterial::where('assign_material_id', '=', $key->id)->sum("qty");
} }
} $countData = $data->count();
} if($data){
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200);
}else{
return response()->json(['status'=>'failed','message'=>'failed get Assign material, please try again later!','code'=>400], 400);
}
}
}

5
app/Http/Controllers/DivisiController.php

@ -78,7 +78,7 @@ class DivisiController extends Controller
} }
public function search(Request $request) public function search(Request $request)
{ {
$payload = $request->all(); $payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'm_divisi'); $dataBuilder = $this->setUpPayload($payload, 'm_divisi');
$builder = $dataBuilder['builder']; $builder = $dataBuilder['builder'];
@ -86,7 +86,8 @@ class DivisiController extends Controller
$dataGet = $builder->get(); $dataGet = $builder->get();
$totalRecord = $countBuilder->count(); $totalRecord = $countBuilder->count();
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
//return $this->list();
// cant use builder for this case
} }
public function list() public function list()

91
app/Http/Controllers/ProjectController.php

@ -2,6 +2,7 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use DateTime;
use App\Models\Link; use App\Models\Link;
use App\Models\User; use App\Models\User;
use App\Models\Image; use App\Models\Image;
@ -366,7 +367,16 @@ class ProjectController extends Controller
} }
public static function setSyncDate($activity_id, $activity, $report) { public static function setSyncDate($activity_id, $activity, $report) {
$status = AssignMaterial::select('status_activity')->where('activity_id', $activity_id)->first(); $status = AssignMaterial::where('activity_id', $activity_id)->first();
if (!isset($status)) {
$reports = array(
'activity_id' => $activity_id,
'min_date' => new DateTime($activity->start_date),
'max_date' => new DateTime($activity->end_date),
'status' => 'open'
);
return $reports;
}
if (!isset($status->status_activity)) { if (!isset($status->status_activity)) {
$status->status_activity = 'open'; $status->status_activity = 'open';
} }
@ -406,7 +416,6 @@ class ProjectController extends Controller
$firstReport = ReportActivityMaterial::where('activity_id', $activity_id)->orderBy('report_date')->first(); $firstReport = ReportActivityMaterial::where('activity_id', $activity_id)->orderBy('report_date')->first();
$reports[] = ProjectController::setSyncDate($activity_id, $activity, $firstReport); $reports[] = ProjectController::setSyncDate($activity_id, $activity, $firstReport);
} }
$activity->reports = $reports;
} }
/* return response()->json(['status'=>'success','data'=> $reports,'code'=>200], 200); */ /* return response()->json(['status'=>'success','data'=> $reports,'code'=>200], 200); */
/* return response()->json(['status'=>'success','data'=> $activities,'code'=>200], 200); */ /* return response()->json(['status'=>'success','data'=> $activities,'code'=>200], 200); */
@ -429,6 +438,18 @@ class ProjectController extends Controller
$activity->save(); $activity->save();
} }
foreach($activities as $activity) {
$successor = Link::where('t_activity_id', $activity->id)->first();
if ($successor) {
$predecessor = Activity::find($successor->s_activity_id);
$activity->start_date = $predecessor->end_date;
$end_date = new DateTime($activity->start_date);
$end_date->modify("+" . $activity->duration . " days");
$activity->end_date = $end_date->format("Y-m-d H:i:sO");
}
$activity->save();
}
return response()->json(['status'=>'success','message'=>'Synchronize to report success!','code'=>200], 200); return response()->json(['status'=>'success','message'=>'Synchronize to report success!','code'=>200], 200);
} }
@ -476,7 +497,7 @@ class ProjectController extends Controller
return response()->json(['status' => 'success', 'code' => 200, 'data' => $userProyek, 'totalRecord' => $totalRecord], 200); return response()->json(['status' => 'success', 'code' => 200, 'data' => $userProyek, 'totalRecord' => $totalRecord], 200);
} }
public function detail($id){ public function detail(Request $request, $id, $gantt_id = null, $s_curve = null){
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);
@ -484,37 +505,49 @@ class ProjectController extends Controller
if(!$result) if(!$result)
return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404); return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404);
if (!isset($gantt_id)) {
$gantt = MasterFunctionsHelper::getLatestGantt($id); $gantt = MasterFunctionsHelper::getLatestGantt($id);
$ganttId = $gantt['last_gantt_id'];
} else {
$ganttId = $gantt_id;
}
$result->projectManager = User::where('id', $result->pm_id)->value('name'); $result->projectManager = User::where('id', $result->pm_id)->value('name');
$result->header = Activity::whereNull('parent_id')->where("proyek_id", $id)->where("version_gantt_id", $gantt['last_gantt_id'])->first();
// dd($result->header->start_date);
$ganttId = $gantt['last_gantt_id'];
$actualStartExist = Activity::where('version_gantt_id', $ganttId)->whereNotNull('actual_start')->exists(); if (isset($s_curve)) {
$actualEndExist = Activity::where('version_gantt_id', $ganttId)->whereNotNull('actual_end')->exists(); $result->header = Activity::whereNull('parent_id')->where("proyek_id", $id)->first();
$actualStartExist = Activity::where('proyek_id', $id)->whereNotNull('actual_start')->exists();
$actualEndExist = Activity::where('proyek_id', $id)->whereNotNull('actual_end')->exists();
$query = Activity::where('proyek_id', $id);
} else {
$result->header = Activity::whereNull('parent_id')->where("proyek_id", $id)->where("version_gantt_id", $ganttId)->first();
$actualStartExist = Activity::where('version_gantt_id', $ganttId)->whereNotNull('actual_start')->exists();
$actualEndExist = Activity::where('version_gantt_id', $ganttId)->whereNotNull('actual_end')->exists();
$query = Activity::where('version_gantt_id', $ganttId);
}
if ($actualStartExist) { if ($actualStartExist) {
$startDate = Activity::where('version_gantt_id', $ganttId) $startDate = $query->orderBy('actual_start')->value('start_date');
->orderBy('actual_start') } else {
->value('start_date'); $startDate = $query->orderBy('start_date')->value('start_date');
} else { }
$startDate = Activity::where('version_gantt_id', $ganttId)
->orderBy('start_date') if ($actualEndExist) {
->value('start_date'); $endDate = $query->orderByDesc('actual_end')->value('end_date');
} } else {
if ($actualEndExist) { $endDate = $query->orderByDesc('end_date')->value('end_date');
$endDate = Activity::where('version_gantt_id', $ganttId) }
->orderByDesc('actual_end')
->value('end_date'); $plannedStart = Activity::where('version_gantt_id', $ganttId)
} else { ->orderBy('planned_start')
$endDate = Activity::where('version_gantt_id', $ganttId) ->value('planned_start');
->orderByDesc('end_date') $plannedEnd = Activity::where('version_gantt_id', $ganttId)
->value('end_date'); ->orderByDesc('planned_end')
} ->value('planned_end');
$result->header->start_date = $startDate; $result->header->start_date = $startDate;
$result->header->end_date = $endDate; $result->header->end_date = $endDate;
return response()->json(['status'=>'success','code'=> 200,'data'=>$result, 'gantt'=>$gantt], 200); $result->header->planned_start = $plannedStart;
$result->header->planned_end = $plannedEnd;
return response()->json(['status'=>'success','code'=> 200,'data'=>$result, 'gantt'=>$ganttId], 200);
} }
public function getOverdueActivities(Request $request){ public function getOverdueActivities(Request $request){

18
app/Http/Controllers/ReportActivityMaterialController.php

@ -59,6 +59,14 @@ class ReportActivityMaterialController extends Controller
"updated_by" => $this->currentName "updated_by" => $this->currentName
); );
Activity::where('id', $request->activity_id)->update($dataUpdate); Activity::where('id', $request->activity_id)->update($dataUpdate);
} else {
$sumAssignMaterial = AssignMaterial::where('activity_id', $request->activity_id)->sum('qty_planning');
$sumReportActivityMaterial = ReportActivityMaterial::where('activity_id', $request->activity_id)->sum('qty');
$dataUpdate = array(
"persentase_progress" => $sumReportActivityMaterial/$sumAssignMaterial*100,
"updated_by" => $this->currentName
);
Activity::where('id', $request->activity_id)->update($dataUpdate);
} }
return response()->json(['status'=>'success','message'=>'Update data status successfully ', 'code'=>200]); return response()->json(['status'=>'success','message'=>'Update data status successfully ', 'code'=>200]);
@ -114,12 +122,14 @@ class ReportActivityMaterialController extends Controller
->addIndexColumn() ->addIndexColumn()
->addColumn('action', function($row){ ->addColumn('action', function($row){
$actionBtn = '<a href="javascript:void(0)" data-id="'.$row->id.'" class="info btn btn-info btn-sm btn-ram-image" data-toggle="tooltip" title="Lihat Foto Report" data-placement="top"><i class="fa fa-image"></i></a>'; $actionBtn = '<a href="javascript:void(0)" data-id="'.$row->id.'" class="info btn btn-info btn-sm btn-ram-image" data-toggle="tooltip" title="Lihat Foto Report" data-placement="top"><i class="fa fa-image"></i></a>';
$actionBtn .= '<a href="javascript:void(0)" data-id="'.$row->id.'" class="delete btn btn-danger btn-sm btn-ram-delete" data-toggle="tooltip" title="Hapus Report" data-placement="top"><i class="fa fa-trash"></i></a>'; if ($row->status_activity != 'done') {
$actionBtn .= '<a href="javascript:void(0)" data-id="'.$row->id.'" class="delete btn btn-danger btn-sm btn-ram-delete" data-toggle="tooltip" title="Hapus Report" data-placement="top"><i class="fa fa-trash"></i></a>';
}
return $actionBtn; return $actionBtn;
}) })
->rawColumns(['action'])->make(true); ->rawColumns(['action'])->make(true);
}else{ }else{
$data = ReportActivityMaterial::select("report_activity_material.*", "u.name as human_resource") $data = ReportActivityMaterial::select("report_activity_material.*", "u.name as human_resource", "amta.status_activity")
->join("assign_material_to_activity as amta", "amta.id", "=", "report_activity_material.assign_material_id") ->join("assign_material_to_activity as amta", "amta.id", "=", "report_activity_material.assign_material_id")
->join("m_req_material as m", "m.id", "=", "amta.material_id") ->join("m_req_material as m", "m.id", "=", "amta.material_id")
->join("m_users as u", "u.id", "=", "report_activity_material.user_id") ->join("m_users as u", "u.id", "=", "report_activity_material.user_id")
@ -131,7 +141,9 @@ class ReportActivityMaterialController extends Controller
->addIndexColumn() ->addIndexColumn()
->addColumn('action', function($row){ ->addColumn('action', function($row){
$actionBtn = '<a href="javascript:void(0)" data-id="'.$row->id.'" class="info btn btn-info btn-sm btn-ram-image" data-toggle="tooltip" title="Lihat Foto Report" data-placement="top"><i class="fa fa-image"></i></a>'; $actionBtn = '<a href="javascript:void(0)" data-id="'.$row->id.'" class="info btn btn-info btn-sm btn-ram-image" data-toggle="tooltip" title="Lihat Foto Report" data-placement="top"><i class="fa fa-image"></i></a>';
$actionBtn .= '<a href="javascript:void(0)" data-id="'.$row->id.'" class="delete btn btn-danger btn-sm btn-ram-delete" data-toggle="tooltip" title="Hapus Report" data-placement="top"><i class="fa fa-trash"></i></a>'; if ($row->status_activity != 'done') {
$actionBtn .= '<a href="javascript:void(0)" data-id="'.$row->id.'" class="delete btn btn-danger btn-sm btn-ram-delete" data-toggle="tooltip" title="Hapus Report" data-placement="top"><i class="fa fa-trash"></i></a>';
}
return $actionBtn; return $actionBtn;
}) })
->rawColumns(['action'])->make(true); ->rawColumns(['action'])->make(true);

204
app/Http/Controllers/RoleMenuController.php

@ -1,102 +1,102 @@
<?php <?php
namespace App\Http\Controllers; namespace App\Http\Controllers;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\Menu; use App\Models\Menu;
use App\Models\RoleMenu; use App\Models\RoleMenu;
class RoleMenuController extends Controller class RoleMenuController extends Controller
{ {
public function add(Request $request) public function add(Request $request)
{ {
$this->validate($request, [ $this->validate($request, [
'role_id' => 'required', 'role_id' => 'required',
'menu_id' => 'required', 'menu_id' => 'required',
]); ]);
$data = $request->all(); $data = $request->all();
$data['created_by'] = $this->currentName; $data['created_by'] = $this->currentName;
$result = RoleMenu::create($data); $result = RoleMenu::create($data);
if($result){ if($result){
return response()->json(['status'=>'success','message'=>'add data role menu successfully!','code'=>200], 200); return response()->json(['status'=>'success','message'=>'add data role menu successfully!','code'=>200], 200);
}else{ }else{
return response()->json(['status'=>'failed','message'=>'add data role menu failed!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'add data role menu failed!','code'=>400], 400);
} }
} }
public function update(Request $request, $id) public function update(Request $request, $id)
{ {
if(!$id || (int) $id < 0 || $id==""){ if(!$id || (int) $id < 0 || $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 = RoleMenu::find($id); $data = RoleMenu::find($id);
if($data){ if($data){
$result = $data->update($request->all()); $result = $data->update($request->all());
}else{ }else{
return response()->json(['status'=>'failed','message'=>'data role menu not found!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'data role menu not found!','code'=>400], 400);
die(); die();
} }
if($result){ if($result){
return response()->json(['status'=>'success','message'=>'data role menu successfully updated!','code'=>200], 200); return response()->json(['status'=>'success','message'=>'data role menu successfully updated!','code'=>200], 200);
}else{ }else{
return response()->json(['status'=>'failed','message'=>'data role menu failed updated!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'data role menu failed updated!','code'=>400], 400);
} }
} }
public function delete($id) public function delete($id)
{ {
$data = RoleMenu::find($id); $data = RoleMenu::find($id);
if($data){ if($data){
$delete = $data->delete(); $delete = $data->delete();
}else{ }else{
return response()->json(['status'=>'failed','message'=>'data role menu not found!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'data role menu not found!','code'=>400], 400);
die(); die();
} }
if($delete){ if($delete){
return response()->json(['status'=>'success','message'=>'data role menu successfully deleted!','code'=>200], 200); return response()->json(['status'=>'success','message'=>'data role menu successfully deleted!','code'=>200], 200);
}else{ }else{
return response()->json(['status'=>'failed','message'=>'data role menu failed deleted!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'data role menu failed deleted!','code'=>400], 400);
} }
} }
public function deleteByRole($id) public function deleteByRole($id)
{ {
$data = RoleMenu::where("role_id", $id); $data = RoleMenu::where("role_id", $id);
if($data){ if($data){
$delete = $data->delete(); $delete = $data->delete();
}else{ }else{
return response()->json(['status'=>'failed','message'=>'data role menu not found!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'data role menu not found!','code'=>400], 400);
die(); die();
} }
if($delete){ if($delete){
return response()->json(['status'=>'success','message'=>'data role menu successfully deleted!','code'=>200], 200); return response()->json(['status'=>'success','message'=>'data role menu successfully deleted!','code'=>200], 200);
}else{ }else{
return response()->json(['status'=>'failed','message'=>'data role menu failed deleted!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'data role menu failed deleted!','code'=>400], 400);
} }
} }
public function search(Request $request) public function search(Request $request)
{ {
$payload = $request->all(); $payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 't_roles_menu'); $dataBuilder = $this->setUpPayload($payload, 't_roles_menu');
$builder = $dataBuilder['builder']; $builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count']; $countBuilder = $dataBuilder['count'];
$dataGet = $builder->get(); $dataGet = $builder->get();
$totalRecord = $countBuilder->count(); $totalRecord = $countBuilder->count();
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
} }
} }

492
app/Models/Activity.php

@ -1,246 +1,246 @@
<?php <?php
namespace App\Models; namespace App\Models;
use App\Models\AssignMaterial; use App\Models\AssignMaterial;
use App\Models\ActivityProgressLog; use App\Models\ActivityProgressLog;
use App\Models\AssignTools; use App\Models\AssignTools;
use App\Models\ReportActivityMaterial; use App\Models\ReportActivityMaterial;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr; use Illuminate\Support\Arr;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Carbon\Carbon; use Carbon\Carbon;
class Activity extends Model class Activity extends Model
{ {
protected $table = 'm_activity'; protected $table = 'm_activity';
const CREATED_AT = 'created_at'; const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at'; const UPDATED_AT = 'updated_at';
// persentase bobot gak kepake yg dipakenya bobot_planning // persentase bobot gak kepake yg dipakenya bobot_planning
protected $fillable = [ protected $fillable = [
'proyek_id', 'parent_id', 'kode_sortname', 'name', 'rencana_biaya', 'start_date', 'proyek_id', 'parent_id', 'kode_sortname', 'name', 'rencana_biaya', 'start_date',
'end_date', 'area_kerja', 'biaya_actual', 'persentase_bobot', 'persentase_progress', 'end_date', 'area_kerja', 'biaya_actual', 'persentase_bobot', 'persentase_progress',
'buffer_radius', 'duration', 'color_progress', 'jumlah_pekerjaan', 'satuan', 'buffer_radius', 'duration', 'color_progress', 'jumlah_pekerjaan', 'satuan',
'description', 'priority', 'bobot_planning', 'type_activity', 'open', 'geom', 'description', 'priority', 'bobot_planning', 'type_activity', 'open', 'geom',
'version_gantt_id', 'budget_plan', 'biaya_material_plan', 'biaya_human_plan', 'biaya_tools_plan', 'version_gantt_id', 'budget_plan', 'biaya_material_plan', 'biaya_human_plan', 'biaya_tools_plan',
'planned_start', 'planned_end', 'satuan_id', 'actual_start', 'actual_end', 'planned_start', 'planned_end', 'satuan_id', 'actual_start', 'actual_end',
'created_at', 'created_by', 'updated_at', 'updated_by', 'sortorder' 'created_at', 'created_by', 'updated_at', 'updated_by', 'sortorder'
]; ];
protected $appends = [ protected $appends = [
'jobs_done', 'assign_hr', 'assign_material', 'assign_tools', 'assign_expense' 'jobs_done', 'assign_hr', 'assign_material', 'assign_tools', 'assign_expense'
]; ];
public function getStartDateAttribute($value) public function getStartDateAttribute($value)
{ {
if ($value instanceof \DateTime) { if ($value instanceof \DateTime) {
return Carbon::instance($value) return Carbon::instance($value)
->timezone(env('APP_TIMEZONE')) ->timezone(env('APP_TIMEZONE'))
->toDateTimeString(); ->toDateTimeString();
} }
return Carbon::createFromTimestamp(strtotime($value)) return Carbon::createFromTimestamp(strtotime($value))
->timezone(env('APP_TIMEZONE')) ->timezone(env('APP_TIMEZONE'))
->toDateTimeString(); ->toDateTimeString();
} }
public function getEndDateAttribute($value) public function getEndDateAttribute($value)
{ {
if ($value instanceof \DateTime) { if ($value instanceof \DateTime) {
return Carbon::instance($value) return Carbon::instance($value)
->timezone(env('APP_TIMEZONE')) ->timezone(env('APP_TIMEZONE'))
->toDateTimeString(); ->toDateTimeString();
} }
return Carbon::createFromTimestamp(strtotime($value)) return Carbon::createFromTimestamp(strtotime($value))
->timezone(env('APP_TIMEZONE')) ->timezone(env('APP_TIMEZONE'))
->toDateTimeString(); ->toDateTimeString();
} }
public static function boot() { public static function boot() {
parent::boot(); parent::boot();
static::updating(function($data) { static::updating(function($data) {
$data->logPersentaseProgress(); $data->logPersentaseProgress();
}); });
static::updated(function($data) { static::updated(function($data) {
$data->updateBobot(); $data->updateBobot();
$data->updateCostPlanning(); $data->updateCostPlanning();
if($data->bobot_planning){ if($data->bobot_planning){
$data->updatePersentaseProgress(); $data->updatePersentaseProgress();
} }
$data->updateCostActual(); $data->updateCostActual();
// if($data->start_date != request()->start_date || $data->end_date != request()->end_date) { // if($data->start_date != request()->start_date || $data->end_date != request()->end_date) {
// $data->updateStartEndDateHeader(); // $data->updateStartEndDateHeader();
// } // }
}); });
static::deleted(function($data) { static::deleted(function($data) {
if(Activity::where("parent_id", $data->parent_id)->count() == 0) if(Activity::where("parent_id", $data->parent_id)->count() == 0)
Activity::find($data->parent_id)->update(["type_activity"=>"task"]); Activity::find($data->parent_id)->update(["type_activity"=>"task"]);
$data->updateBobot(true); $data->updateBobot(true);
$data->updateCostPlanning(); $data->updateCostPlanning();
if($data->bobot_planning){ if($data->bobot_planning){
$data->updatePersentaseProgress(); $data->updatePersentaseProgress();
} }
$data->updateCostActual(); $data->updateCostActual();
$data->updateStartEndDateHeader(); $data->updateStartEndDateHeader();
}); });
} }
private function updateBobot($isDelete = false) private function updateBobot($isDelete = false)
{ {
$root = Activity::where('version_gantt_id', $this->version_gantt_id) $root = Activity::where('version_gantt_id', $this->version_gantt_id)
->where("proyek_id", $this->proyek_id) ->where("proyek_id", $this->proyek_id)
->whereNull('parent_id') ->whereNull('parent_id')
->first(); ->first();
if($root->rencana_biaya > 0){ if($root->rencana_biaya > 0){
$activities = Activity::where("proyek_id", $this->proyek_id)->where("version_gantt_id", $this->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) { foreach ($activities as $activity) {
if($isDelete && $activity->id == $this->id) if($isDelete && $activity->id == $this->id)
continue; continue;
$activity->bobot_planning = ( (int)$activity->rencana_biaya / $root->rencana_biaya) * 100; $activity->bobot_planning = ( (int)$activity->rencana_biaya / $root->rencana_biaya) * 100;
$activity->updated_by = auth()->user() ? auth()->user()->name : "system"; $activity->updated_by = auth()->user() ? auth()->user()->name : "system";
$activity->saveQuietly(); $activity->saveQuietly();
} }
} else { } else {
if($parent = Activity::find($this->parent_id)){ if($parent = Activity::find($this->parent_id)){
$totalChildWeight = Activity::where("parent_id", $this->parent_id)->sum('bobot_planning'); $totalChildWeight = Activity::where("parent_id", $this->parent_id)->sum('bobot_planning');
$parent->update([ $parent->update([
"bobot_planning" => $totalChildWeight "bobot_planning" => $totalChildWeight
]); ]);
} }
} }
} }
private function updateCostActual() private function updateCostActual()
{ {
$actualCost = Activity::where("parent_id", $this->parent_id)->sum("biaya_actual"); $actualCost = Activity::where("parent_id", $this->parent_id)->sum("biaya_actual");
$this->biaya_actual = $actualCost; $this->biaya_actual = $actualCost;
if($parent = Activity::find($this->parent_id)){ if($parent = Activity::find($this->parent_id)){
$parent->update([ $parent->update([
"biaya_actual" => $actualCost "biaya_actual" => $actualCost
]); ]);
} }
} }
private function updatePersentaseProgress() private function updatePersentaseProgress()
{ {
if($parent = Activity::find($this->parent_id)){ if($parent = Activity::find($this->parent_id)){
$parentActWeight = $parent->bobot_planning; $parentActWeight = $parent->bobot_planning;
if ($parentActWeight == 0) { if ($parentActWeight == 0) {
$parent->update([ $parent->update([
"persentase_progress" => 0 "persentase_progress" => 0
]); ]);
return; return;
} }
$totalChildProportionalProgress = 0; $totalChildProportionalProgress = 0;
$childs = Activity::where("parent_id", $parent->id)->get(); $childs = Activity::where("parent_id", $parent->id)->get();
foreach($childs as $child){ foreach($childs as $child){
$currentActWeight = $child->bobot_planning; $currentActWeight = $child->bobot_planning;
$currentActProportionalProgress = ($currentActWeight / $parentActWeight) * $child->persentase_progress; $currentActProportionalProgress = ($currentActWeight / $parentActWeight) * $child->persentase_progress;
$totalChildProportionalProgress += $currentActProportionalProgress; $totalChildProportionalProgress += $currentActProportionalProgress;
} }
$parent->update([ $parent->update([
"persentase_progress" => $totalChildProportionalProgress "persentase_progress" => $totalChildProportionalProgress
]); ]);
} }
} }
private function updateCostPlanning() { private function updateCostPlanning() {
$sumBiaya = Activity::select(DB::raw('sum(cast(rencana_biaya as double precision))')) $sumBiaya = Activity::select(DB::raw('sum(cast(rencana_biaya as double precision))'))
->where("parent_id", $this->parent_id) ->where("parent_id", $this->parent_id)
->first(); ->first();
$this->rencana_biaya = $sumBiaya->sum; $this->rencana_biaya = $sumBiaya->sum;
if($parent = Activity::find($this->parent_id)){ if($parent = Activity::find($this->parent_id)){
$parent->update([ $parent->update([
"rencana_biaya" => $sumBiaya->sum, "rencana_biaya" => $sumBiaya->sum,
]); ]);
} }
} }
private function logPersentaseProgress() private function logPersentaseProgress()
{ {
ActivityProgressLog::create([ ActivityProgressLog::create([
'version_gantt_id' => $this->version_gantt_id, 'version_gantt_id' => $this->version_gantt_id,
'activity_id' => request()->id, 'activity_id' => request()->id,
'old_percentage' => $this->persentase_progress, 'old_percentage' => $this->persentase_progress,
'new_percentage' => request()->persentase_progress, 'new_percentage' => request()->persentase_progress,
'variance' => $this->persentase_progress - request()->persentase_progress, 'variance' => $this->persentase_progress - request()->persentase_progress,
'created_by'=> "system" 'created_by'=> "system"
]); ]);
} }
private function updateStartEndDateHeader() private function updateStartEndDateHeader()
{ {
$earliestStartDate = Activity::where('version_gantt_id', $this->version_gantt_id)->whereNotNull('parent_id')->oldest('start_date')->pluck('start_date')->first(); $earliestStartDate = Activity::where('version_gantt_id', $this->version_gantt_id)->whereNotNull('parent_id')->oldest('start_date')->pluck('start_date')->first();
$latestEndDate = Activity::where('version_gantt_id', $this->version_gantt_id)->whereNotNull('parent_id')->latest('end_date')->pluck('end_date')->first(); $latestEndDate = Activity::where('version_gantt_id', $this->version_gantt_id)->whereNotNull('parent_id')->latest('end_date')->pluck('end_date')->first();
if($header = Activity::where('version_gantt_id', $this->version_gantt_id)->whereNull('parent_id')->first()) { if($header = Activity::where('version_gantt_id', $this->version_gantt_id)->whereNull('parent_id')->first()) {
$header->start_date = $earliestStartDate; $header->start_date = $earliestStartDate;
$header->end_date = $latestEndDate; $header->end_date = $latestEndDate;
$header->saveQuietly(); $header->saveQuietly();
} }
} }
public function getJobsDoneAttribute() public function getJobsDoneAttribute()
{ {
if(!ReportActivityMaterial::where('activity_id', $this->id)->first()) if(!ReportActivityMaterial::where('activity_id', $this->id)->first())
return 0; return 0;
if(!$dataPlan = AssignMaterial::where('activity_id', $this->id)->get()) if(!$dataPlan = AssignMaterial::where('activity_id', $this->id)->get())
return 0; return 0;
if($dataPlan->isEmpty()) if($dataPlan->isEmpty())
return 0; return 0;
if($dataPlan[0]->status_activity == 'done') if($dataPlan[0]->status_activity == 'done')
return 100; return 100;
return $this->persentase_progress; return $this->persentase_progress;
} }
public function getAssignHrAttribute() public function getAssignHrAttribute()
{ {
return Arr::flatten(UserToActivity::select("u.name as name") return Arr::flatten(UserToActivity::select("u.name as name")
->join("m_users as u", "u.id", "=", "assign_hr_to_activity.user_id") ->join("m_users as u", "u.id", "=", "assign_hr_to_activity.user_id")
->where('assign_hr_to_activity.activity_id', $this->id) ->where('assign_hr_to_activity.activity_id', $this->id)
->get() ->get()
->toArray()); ->toArray());
} }
public function getAssignMaterialAttribute() public function getAssignMaterialAttribute()
{ {
return Arr::flatten(AssignMaterial::select("m.description as name") return Arr::flatten(AssignMaterial::select("m.description as name")
->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id") ->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id")
->where('assign_material_to_activity.activity_id', $this->id) ->where('assign_material_to_activity.activity_id', $this->id)
->where('assign_material_to_activity.type', "material") ->where('assign_material_to_activity.type', "material")
->get() ->get()
->toArray()); ->toArray());
} }
public function getAssignExpenseAttribute() public function getAssignExpenseAttribute()
{ {
return Arr::flatten(AssignMaterial::select("m.description as name") return Arr::flatten(AssignMaterial::select("m.description as name")
->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id") ->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id")
->where('assign_material_to_activity.activity_id', $this->id) ->where('assign_material_to_activity.activity_id', $this->id)
->where('assign_material_to_activity.type', "expense") ->where('assign_material_to_activity.type', "expense")
->get() ->get()
->toArray()); ->toArray());
} }
public function getAssignToolsAttribute() public function getAssignToolsAttribute()
{ {
return Arr::flatten(AssignTools::select("m.name as name") return Arr::flatten(AssignTools::select("m.name as name")
->join("m_tools_resource as m", "m.id", "=", "assign_tools_to_activity.tools_id") ->join("m_tools_resource as m", "m.id", "=", "assign_tools_to_activity.tools_id")
->where('assign_tools_to_activity.activity_id', $this->id) ->where('assign_tools_to_activity.activity_id', $this->id)
->get() ->get()
->toArray()); ->toArray());
} }
} }

92
app/Models/AssignMaterial.php

@ -1,46 +1,46 @@
<?php <?php
namespace App\Models; namespace App\Models;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use App\Models\RequestMaterial; use App\Models\RequestMaterial;
use App\Models\Activity; use App\Models\Activity;
use App\Models\ReportActivityMaterial; use App\Models\ReportActivityMaterial;
class AssignMaterial extends Model class AssignMaterial extends Model
{ {
protected $table = 'assign_material_to_activity'; protected $table = 'assign_material_to_activity';
const CREATED_AT = 'created_at'; const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at'; const UPDATED_AT = 'updated_at';
protected $fillable = [ protected $fillable = [
'proyek_id', 'activity_id', 'material_id', 'qty_planning', 'proyek_id', 'activity_id', 'material_id', 'qty_planning',
'budget', 'plan_date', 'status_activity', 'type', 'budget', 'plan_date', 'status_activity', 'type',
'created_at', 'created_by', 'updated_at', 'updated_by' 'created_at', 'created_by', 'updated_at', 'updated_by'
]; ];
protected $casts = [ protected $casts = [
'id' => 'integer', 'id' => 'integer',
'budget' => 'string', 'budget' => 'string',
]; ];
public static function boot() { public static function boot() {
parent::boot(); parent::boot();
static::created(function($data) { static::created(function($data) {
$activity = Activity::find($data->activity_id); $activity = Activity::find($data->activity_id);
$material = RequestMaterial::where("id", $data->material_id)->first(); $material = RequestMaterial::where("id", $data->material_id)->first();
$activity->rencana_biaya += floatval($material->price) * floatval($data->qty_planning); $activity->rencana_biaya += floatval($material->price) * floatval($data->qty_planning);
$activity->save(); $activity->save();
}); });
static::deleted(function($data) { static::deleted(function($data) {
$reportActivities = ReportActivityMaterial::where('assign_material_id', $data->id)->delete(); $reportActivities = ReportActivityMaterial::where('assign_material_id', $data->id)->delete();
$activity = Activity::where('id', $data->activity_id)->first(); $activity = Activity::where('id', $data->activity_id)->first();
$activity->rencana_biaya -= floatval($data->budget) * floatval($data->qty_planning); $activity->rencana_biaya -= floatval($data->budget) * floatval($data->qty_planning);
$activity->save(); $activity->save();
}); });
} }
} }

146
app/Models/ReportActivityMaterial.php

@ -1,73 +1,73 @@
<?php <?php
namespace App\Models; namespace App\Models;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use App\Models\Activity; use App\Models\Activity;
use App\Models\AssignMaterial; use App\Models\AssignMaterial;
use Carbon\Carbon; use Carbon\Carbon;
class ReportActivityMaterial extends Model class ReportActivityMaterial extends Model
{ {
protected $table = 'report_activity_material'; protected $table = 'report_activity_material';
const CREATED_AT = 'created_at'; const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at'; const UPDATED_AT = 'updated_at';
protected $fillable = [ protected $fillable = [
'activity_id', 'user_id', 'qty', 'lat', 'lon','assign_material_id', 'activity_id', 'user_id', 'qty', 'lat', 'lon','assign_material_id',
'report_date', 'description', 'created_at', 'created_by', 'updated_at', 'updated_by' 'report_date', 'description', 'created_at', 'created_by', 'updated_at', 'updated_by'
]; ];
public function getReportDateAttribute($value) public function getReportDateAttribute($value)
{ {
return Carbon::createFromTimestamp(strtotime($value)) return Carbon::createFromTimestamp(strtotime($value))
->timezone(env('APP_TIMEZONE')) ->timezone(env('APP_TIMEZONE'))
->toDateTimeString(); ->toDateTimeString();
} }
public static function boot() { public static function boot() {
parent::boot(); parent::boot();
static::created(function($data) { static::created(function($data) {
$activity = Activity::find($data->activity_id); $activity = Activity::find($data->activity_id);
$assignedMaterial = AssignMaterial::find($data->assign_material_id); $assignedMaterial = AssignMaterial::find($data->assign_material_id);
$biayaActual = $activity->biaya_actual + floatval($assignedMaterial->budget) * floatval($data->qty); $biayaActual = $activity->biaya_actual + floatval($assignedMaterial->budget) * floatval($data->qty);
$dataPlan = AssignMaterial::where('activity_id', $activity->id)->get(); $dataPlan = AssignMaterial::where('activity_id', $activity->id)->get();
if($dataPlan[0]->status_activity == 'done'){ if($dataPlan[0]->status_activity == 'done'){
$percentage = 100; $percentage = 100;
} else { } else {
$totalPlan = $dataPlan->sum('qty_planning'); $totalPlan = $dataPlan->sum('qty_planning');
$totalVolumeActual = ReportActivityMaterial::where('activity_id', '=', $activity->id)->sum("qty"); $totalVolumeActual = ReportActivityMaterial::where('activity_id', '=', $activity->id)->sum("qty");
$percentage = ($totalVolumeActual * 100) / $totalPlan; $percentage = ($totalVolumeActual * 100) / $totalPlan;
$percentage = $percentage >= config('app.max_percentage_not_done') ? config('app.max_percentage_not_done') : $percentage; $percentage = $percentage >= config('app.max_percentage_not_done') ? config('app.max_percentage_not_done') : $percentage;
} }
$activity->update([ $activity->update([
"persentase_progress" => $percentage, "persentase_progress" => $percentage,
"biaya_actual" => $biayaActual, "biaya_actual" => $biayaActual,
]); ]);
$activity->save(); $activity->save();
}); });
static::deleted(function($data) { static::deleted(function($data) {
$activity = Activity::find($data->activity_id); $activity = Activity::find($data->activity_id);
$assignedMaterial = AssignMaterial::find($data->assign_material_id); $assignedMaterial = AssignMaterial::find($data->assign_material_id);
$activity->biaya_actual -= floatval($assignedMaterial->budget) * floatval($data->qty); $activity->biaya_actual -= floatval($assignedMaterial->budget) * floatval($data->qty);
$dataPlan = AssignMaterial::where('activity_id', $activity->id)->get(); $dataPlan = AssignMaterial::where('activity_id', $activity->id)->get();
$totalPlan = $dataPlan->sum('qty_planning'); $totalPlan = $dataPlan->sum('qty_planning');
$totalVolumeActual = ReportActivityMaterial::where('activity_id', '=', $activity->id)->sum("qty"); $totalVolumeActual = ReportActivityMaterial::where('activity_id', '=', $activity->id)->sum("qty");
$percentage = ($totalVolumeActual * 100) / $totalPlan; $percentage = ($totalVolumeActual * 100) / $totalPlan;
$activity->persentase_progress = $percentage >= config('app.max_percentage_not_done') ? config('app.max_percentage_not_done') : $percentage; $activity->persentase_progress = $percentage >= config('app.max_percentage_not_done') ? config('app.max_percentage_not_done') : $percentage;
$activity->save(); $activity->save();
}); });
} }
} }

2
routes/web.php

@ -58,7 +58,7 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout
$router->post('/project/add', 'ProjectController@add'); $router->post('/project/add', 'ProjectController@add');
$router->put('/project/update/{id}', 'ProjectController@update'); $router->put('/project/update/{id}', 'ProjectController@update');
$router->get('/project/edit/{id}', 'ProjectController@edit'); $router->get('/project/edit/{id}', 'ProjectController@edit');
$router->get('/project/detail/{id}', 'ProjectController@detail'); $router->get('/project/detail/{id}[/{gantt_id}[/{s_curve}]]', 'ProjectController@detail');
$router->delete('/project/delete/{id}', 'ProjectController@delete'); $router->delete('/project/delete/{id}', 'ProjectController@delete');
$router->get('/project/list', 'ProjectController@list'); $router->get('/project/list', 'ProjectController@list');
$router->get('/project/set-baseline/{gantt_id}', 'ProjectController@setBaseline'); $router->get('/project/set-baseline/{gantt_id}', 'ProjectController@setBaseline');

Loading…
Cancel
Save