Browse Source

Merge branch 'staging' of https://git.oslog.id/ordo/adw-backend into dev-wahyun

pull/3/head
wahyuun 1 year ago
parent
commit
b91c66d36d
  1. 20
      app/Helpers/MasterFunctionsHelper.php
  2. 43
      app/Http/Controllers/ActivityController.php
  3. 1259
      app/Http/Controllers/PresenceController.php
  4. 30
      app/Http/Controllers/ProjectController.php
  5. 304
      app/Http/Controllers/ReportActivityMaterialController.php
  6. 433
      app/Http/Controllers/UserToActivityController.php
  7. 124
      app/Models/UserToActivity.php
  8. 1
      routes/web.php

20
app/Helpers/MasterFunctionsHelper.php

@ -36,6 +36,26 @@ class MasterFunctionsHelper
return json_decode($output); return json_decode($output);
} }
public static function countDays($ganttId, $start, $end){
$dayOffs = VersionGantt::where('id', $ganttId)->first()->config_dayoff;
$diff = date_diff($start, $end);
$endCount = clone $end;
$duration = $diff->days + 1;
$daysRemaining = $duration;
// Loop until the remaining days become zero
while ($daysRemaining > 0) {
$endCount->modify('-1 day');
// Check if the current day is a day off (Sunday or Saturday)
$currentDayOfWeek = (int) $endCount->format('w');
if (strpos($dayOffs, (string) $currentDayOfWeek) !== false) {
// continue; // Skip the day off and continue to the next day
$duration--;
}
$daysRemaining--; // Decrease the remaining days by one
}
return $duration;
}
public function getLatestGantt($id) public function getLatestGantt($id)
{ {
$maxGanttId = VersionGantt::where("proyek_id", $id)->max("id"); $maxGanttId = VersionGantt::where("proyek_id", $id)->max("id");

43
app/Http/Controllers/ActivityController.php

@ -1,6 +1,7 @@
<?php <?php
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Helpers\MasterFunctionsHelper;
use App\Models\Activity; use App\Models\Activity;
use App\Models\CommentActivity; use App\Models\CommentActivity;
use App\Models\Link; use App\Models\Link;
@ -412,6 +413,39 @@ class ActivityController extends Controller
return response()->json(['status' => 'success', 'message' => 'Activity Updated!', 'code' => 200], 200); return response()->json(['status' => 'success', 'message' => 'Activity Updated!', 'code' => 200], 200);
} }
public function updateSchedule($ganttId){
if (empty($ganttId) || !is_int((int) $ganttId))
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
$activities = Activity::where('version_gantt_id', $ganttId)->get();
if (!$activities)
return response()->json(['status' => 'failed', 'message' => 'Activities not found!', 'code' => 404], 404);
$duration = 0;
foreach ($activities as $key => $activity) {
if (isset($activity->planned_start) && isset($activity->planned_end)) {
$today = new DateTime();
$endDate = new DateTime($activity->end_date);
$startDate = new DateTime($activity->start_date);
$plannedStart = new DateTime($activity->planned_start);
$plannedEnd = new DateTime($activity->planned_end);
$duration = MasterFunctionsHelper::countDays($ganttId, $plannedStart, $plannedEnd);
if ($today >= $endDate) {
$endDate = $today;
$rerataBobot = $duration > 0 ? $activity->bobot_planning / $duration : 0;
$bobotActual = $activity->progress * $activity->bobot_planning;
$sisaBobot = $activity->bobot_planning - $bobotActual;
$sisaHari = $rerataBobot > 0 ? $sisaBobot / $rerataBobot : 0;
$endDate->modify("+".$sisaHari." Days");
$actualDuration = MasterFunctionsHelper::countDays($ganttId, $startDate, $endDate);
$activity->duration = $actualDuration;
$activity->end_date = $endDate;
$activity->save();
}
}
}
return response()->json(['status' => 'success', 'message' => 'Activities Updated!', 'code' => 200], 200);
}
public function batchUpdate(Request $request, $ganttId) public function batchUpdate(Request $request, $ganttId)
{ {
$entities = $request->all(); $entities = $request->all();
@ -428,15 +462,18 @@ class ActivityController extends Controller
$activityToUpdate = $activity->firstWhere('id', $entity['data']['id']); $activityToUpdate = $activity->firstWhere('id', $entity['data']['id']);
$entity['data']['name'] = $entity['data']['text']; $entity['data']['name'] = $entity['data']['text'];
$entity['data']['persentase_progress'] = $entity['data']['progress'] * 100; $entity['data']['persentase_progress'] = $entity['data']['progress'] * 100;
if (isset($entity['data']['rencana_biaya'])) {
$entity['data']['rencana_biaya'] = str_replace(",", ".", $entity['data']['rencana_biaya']);
}
if (isset($entity['data']['target'])) { if (isset($entity['data']['target'])) {
$this->updateOrder($entity['data']['id'], $entity['data']['target']); $this->updateOrder($entity['data']['id'], $entity['data']['target']);
} }
if(!$activityToUpdate->update($entity['data'])) if (!$activityToUpdate->update($entity['data']))
return response()->json(['status' => 'failed', 'message' => 'Failed to update activity !', 'code' => 500], 500); return response()->json(['status' => 'failed', 'message' => 'Failed to update activity !', 'code' => 500], 500);
$updatedJobsDone = $activityToUpdate->jobs_done; $updatedJobsDone = $activityToUpdate->jobs_done;
} else if ($entity['entity'] == "link"){ } else if ($entity['entity'] == "link") {
$linkToUpdate = $link->firstWhere('id', $entity['data']['id']); $linkToUpdate = $link->firstWhere('id', $entity['data']['id']);
if(!$linkToUpdate->update($entity['data'])) if (!$linkToUpdate->update($entity['data']))
return response()->json(['status' => 'failed', 'message' => 'Failed to update link !', 'code' => 500], 500); return response()->json(['status' => 'failed', 'message' => 'Failed to update link !', 'code' => 500], 500);
} }
} }

1259
app/Http/Controllers/PresenceController.php

File diff suppressed because it is too large Load Diff

30
app/Http/Controllers/ProjectController.php

@ -416,17 +416,21 @@ 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);
} }
$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','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); */
for ($i=0; $i < count($reports); $i++) { for ($i=0; $i < count($reports); $i++) {
$activity = Activity::find($reports[$i]['activity_id']); $activity = Activity::find($reports[$i]['activity_id']);
$successor = Link::where('t_activity_id', $activity->id)->first();
if ($successor) {
$predecessor = Activity::find($successor->s_activity_id);
$activity->start_date = $predecessor->end_date;
}
if($reports[$i]['status'] != 'done'){ if($reports[$i]['status'] != 'done'){
$reports[$i]['max_date']->modify('-1 day'); $reports[$i]['max_date']->modify('-1 day');
}else if($reports[$i]['status'] == 'done'){ }else if($reports[$i]['status'] == 'done'){
@ -434,22 +438,14 @@ class ProjectController extends Controller
} }
$activity->start_date = $reports[$i]['min_date']; //same early $activity->start_date = $reports[$i]['min_date']; //same early
$activity->end_date = $reports[$i]['max_date']->setTime(23,59,59); // same early $activity->end_date = $reports[$i]['max_date']->setTime(23,59,59); // same early
$startDate = new DateTime($activity->start_date);
$endDate = new DateTime($activity->end_date);
$duration = MasterFunctionsHelper::countDays($activity->version_gantt_id, $startDate, $endDate);
$activity->duration = $duration;
$activity->actual_start = $reports[$i]['min_date']; $activity->actual_start = $reports[$i]['min_date'];
$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);
} }

304
app/Http/Controllers/ReportActivityMaterialController.php

@ -1,152 +1,152 @@
<?php <?php
namespace App\Http\Controllers; namespace App\Http\Controllers;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\ReportActivityMaterial; use App\Models\ReportActivityMaterial;
use App\Models\Activity; use App\Models\Activity;
use App\Models\AssignMaterial; use App\Models\AssignMaterial;
use Datatables; use Datatables;
class ReportActivityMaterialController extends Controller class ReportActivityMaterialController 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',
'qty' => 'required' 'qty' => 'required'
]); ]);
$activity = Activity::where('id', $request->activity_id)->first(); $activity = Activity::where('id', $request->activity_id)->first();
$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)));
$reportDate = new \DateTime(date("Y-m-d", strtotime($request->report_date))); $reportDate = new \DateTime(date("Y-m-d", strtotime($request->report_date)));
$data = $request->all(); $data = $request->all();
$data['created_by'] = $this->currentName; $data['created_by'] = $this->currentName;
/* $data['assign_material_id'] = AssignMaterial::where('activity_id', $request->activity_id)->pluck('id')->first(); */ /* $data['assign_material_id'] = AssignMaterial::where('activity_id', $request->activity_id)->pluck('id')->first(); */
$data['assign_material_id'] = $request->assign_material_id; $data['assign_material_id'] = $request->assign_material_id;
$data['qty'] = $this->sanitizeDecimal($data['qty']); $data['qty'] = $this->sanitizeDecimal($data['qty']);
if($reportDate >= $startDate){ if($reportDate >= $startDate || isset($data['force']) && $data['force'] == "true"){
$created = ReportActivityMaterial::create($data); $created = ReportActivityMaterial::create($data);
return response()->json(['status'=>'success','message'=>'Input progress report activity created','code'=>200,'data'=>array('report_id'=>$created->id)]); return response()->json(['status'=>'success','message'=>'Input progress report activity created','code'=>200,'data'=>array('report_id'=>$created->id)]);
} else { } else {
return response()->json(['status'=>'failed','message'=>'Input progress report activity failed created','code'=>400,'data'=>null], 400); return response()->json(['status'=>'failed','message'=>'Report date is before early start, still wanna add data ?','code'=>400,'data'=>$data], 400);
} }
} }
public function updateStatusStartFinish(Request $request){ public function updateStatusStartFinish(Request $request){
$payloadUpdate = array( $payloadUpdate = array(
'start_activity' => $request->start_activity, 'start_activity' => $request->start_activity,
'finish_activity' => $request->finish_activity, 'finish_activity' => $request->finish_activity,
'status_activity' => $request->status_activity 'status_activity' => $request->status_activity
); );
$updateData = AssignMaterial::where('activity_id',$request->activity_id) $updateData = AssignMaterial::where('activity_id',$request->activity_id)
->update($payloadUpdate); ->update($payloadUpdate);
if($updateData){ if($updateData){
if($request->status_activity == 'done'){ if($request->status_activity == 'done'){
$dataUpdate = array( $dataUpdate = array(
"persentase_progress" => 100, "persentase_progress" => 100,
"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 { } else {
$sumAssignMaterial = AssignMaterial::where('activity_id', $request->activity_id)->sum('qty_planning'); $sumAssignMaterial = AssignMaterial::where('activity_id', $request->activity_id)->sum('qty_planning');
$sumReportActivityMaterial = ReportActivityMaterial::where('activity_id', $request->activity_id)->sum('qty'); $sumReportActivityMaterial = ReportActivityMaterial::where('activity_id', $request->activity_id)->sum('qty');
$dataUpdate = array( $dataUpdate = array(
"persentase_progress" => $sumReportActivityMaterial/$sumAssignMaterial*100, "persentase_progress" => $sumReportActivityMaterial/$sumAssignMaterial*100,
"updated_by" => $this->currentName "updated_by" => $this->currentName
); );
Activity::where('id', $request->activity_id)->update($dataUpdate); 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]);
} }
else{ else{
return response()->json(['status'=>'failed','message'=>'Update data status failed', 'code'=>400]); return response()->json(['status'=>'failed','message'=>'Update data status failed', 'code'=>400]);
} }
} }
public function delete($id) public function delete($id)
{ {
if(!ReportActivityMaterial::findOrFail($id)->delete()) if(!ReportActivityMaterial::findOrFail($id)->delete())
return response()->json(['status'=>'failed','message'=>'Failed to deleted the data!','code'=> 500], 500); return response()->json(['status'=>'failed','message'=>'Failed to deleted the data!','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(); $payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'report_activity_material'); $dataBuilder = $this->setUpPayload($payload, 'report_activity_material');
$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);
} }
public function list() public function list()
{ {
$data = ReportActivityMaterial::all(); $data = ReportActivityMaterial::all();
$countData = $data->count(); $countData = $data->count();
if($data){ if($data){
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200);
}else{ }else{
return response()->json(['status'=>'failed','message'=>'failed get Repport Activity material, please try again later!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'failed get Repport Activity material, please try again later!','code'=>400], 400);
} }
} }
public function datatables(Request $request){ public function datatables(Request $request){
$id_activity = $request->query('idAct'); $id_activity = $request->query('idAct');
$type = $request->query('type'); $type = $request->query('type');
$materialName = $request->query('materialName'); $materialName = $request->query('materialName');
if($type == 'plan'){ if($type == 'plan'){
$data = AssignMaterial::select("assign_material_to_activity.*","m.description as material_name", "m.uom as uom") $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") ->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id")
->where('assign_material_to_activity.activity_id', $id_activity) ->where('assign_material_to_activity.activity_id', $id_activity)
->where('m.description', $materialName) ->where('m.description', $materialName)
->orderBy('assign_material_to_activity.id', 'asc') ->orderBy('assign_material_to_activity.id', 'asc')
->get(); ->get();
return Datatables::of($data) return Datatables::of($data)
->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>';
if ($row->status_activity != 'done') { 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>'; $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", "amta.status_activity") $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")
->where('report_activity_material.activity_id', $id_activity) ->where('report_activity_material.activity_id', $id_activity)
->where('m.description', $materialName) ->where('m.description', $materialName)
->orderBy('report_activity_material.report_date', 'asc') ->orderBy('report_activity_material.report_date', 'asc')
->get(); ->get();
return Datatables::of($data) return Datatables::of($data)
->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>';
if ($row->status_activity != 'done') { 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>'; $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);
} }
} }
} }

433
app/Http/Controllers/UserToActivityController.php

@ -1,199 +1,234 @@
<?php <?php
namespace App\Http\Controllers; namespace App\Http\Controllers;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\UserToActivity; use App\Models\UserToActivity;
use App\Models\Activity; use App\Models\Activity;
use Datatables; use App\Models\AssignMaterial;
use Datatables;
class UserToActivityController extends Controller
{ class UserToActivityController extends Controller
public function add(Request $request){ {
$this->validate($request, [ public function add(Request $request){
'activity_id' => 'required', $this->validate($request, [
'user_id' => 'required' 'activity_id' => 'required',
]); 'user_id' => 'required'
]);
$data = $request->all();
$data['created_by'] = $this->currentName; $data = $request->all();
$data['created_by'] = $this->currentName;
if(!UserToActivity::create($data))
return response()->json(['status'=>'failed','message'=>'Failed to add data!','code'=> 500]); if(!UserToActivity::create($data))
return response()->json(['status'=>'failed','message'=>'Failed to add data!','code'=> 500]);
return response()->json(['status'=>'success','message'=>'Data added!', 'code'=> 200]);
} return response()->json(['status'=>'success','message'=>'Data added!', 'code'=> 200]);
}
public function addMultiple(Request $request){
$users_id = $request->user_id; public function addMultiple(Request $request){
$users_role = $request->role_proyek_id; $users_id = $request->user_id;
$users_role = $request->role_proyek_id;
// $data = UserToActivity::where("activity_id", $request->activity_id);
// if($data){ // $data = UserToActivity::where("activity_id", $request->activity_id);
// $data->delete(); // if($data){
// } // $data->delete();
// }
if(is_array($users_id) && count($users_id) > 0){
$countRes = 0; if(is_array($users_id) && count($users_id) > 0){
foreach($users_id as $index => $item){ $countRes = 0;
$dataInsert = array( foreach($users_id as $index => $item){
"user_id" => $item, $dataInsert = array(
"activity_id" => $request->activity_id, "user_id" => $item,
"role_proyek_id" => $users_role[$index], "activity_id" => $request->activity_id,
"proyek_id" => $request->proyek_id, "role_proyek_id" => $users_role[$index],
"created_by" => $this->currentName, "proyek_id" => $request->proyek_id,
"version_gantt_id" => $request->version_gantt_id "start_date" => $request->start_date,
); "end_date" => $request->end_date,
$result = UserToActivity::create($dataInsert); "created_by" => $this->currentName,
if($result){ "version_gantt_id" => $request->version_gantt_id
$countRes++; );
}else{ $result = UserToActivity::create($dataInsert);
$countRes--; if($result){
} $countRes++;
} }else{
$countRes--;
if($countRes == 0) }
return response()->json(['status'=>'failed' ,'message'=>'Failed to add data!','code'=> 500]); }
$allCost = $this->calculateAllCost($request->activity_id, $request->proyek_id); if($countRes == 0)
$dataUpdateCost = array( return response()->json(['status'=>'failed' ,'message'=>'Failed to add data!','code'=> 500]);
"rencana_biaya"=>$allCost,
"updated_by"=> $this->currentName $allCost = $this->calculateAllCost($request->activity_id, $request->proyek_id);
); $dataUpdateCost = array(
$actUpdate = Activity::find($request->activity_id); "rencana_biaya"=>$allCost,
if($actUpdate){ "updated_by"=> $this->currentName
$actUpdate->update($dataUpdateCost); );
if($actUpdate->parent_id){ $actUpdate = Activity::find($request->activity_id);
$this->updatedCostPlanning($actUpdate->parent_id); if($actUpdate){
} $actUpdate->update($dataUpdateCost);
} if($actUpdate->parent_id){
return response()->json(['status'=>'success' ,'message'=>'Data added!','code'=>200]); $this->updatedCostPlanning($actUpdate->parent_id);
}else{ }
return response()->json(['status'=>'success' ,'message'=>'Data added!','code'=>200]); }
} return response()->json(['status'=>'success' ,'message'=>'Data added!','code'=>200]);
}else{
} return response()->json(['status'=>'success' ,'message'=>'Data added!','code'=>200]);
}
private function updatedCostPlanning($parent_id) {
$sumBiaya = Activity::selectRaw('sum(cast(rencana_biaya as double precision))') }
->where("parent_id", $parent_id)
->first(); private function updatedCostPlanning($parent_id) {
if($parent = Activity::find($parent_id)){ $sumBiaya = Activity::selectRaw('sum(cast(rencana_biaya as double precision))')
$parent->update([ ->where("parent_id", $parent_id)
"rencana_biaya" => $sumBiaya->sum, ->first();
]); if($parent = Activity::find($parent_id)){
} $parent->update([
} "rencana_biaya" => $sumBiaya->sum,
]);
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);
public function update(Request $request, $id){
$data = UserToActivity::find($id); if(empty($id) || !is_int((int)$id))
if(!$data) return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
$data = UserToActivity::find($id);
if(!$data->update($request->all())); if(!$data)
return response()->json(['status'=>'failed','message'=>'Failed to update!','code'=> 500], 500); return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
return response()->json(['status'=>'success','message'=>'Data updated!','code'=>200], 200); if(!$data->update($request->all()));
} return response()->json(['status'=>'failed','message'=>'Failed to update!','code'=> 500], 500);
public function delete($id) return response()->json(['status'=>'success','message'=>'Data updated!','code'=>200], 200);
{ }
$data = UserToActivity::find($id);
if(!$data) public function delete($id)
return response()->json(['status'=>'failed','message'=>'data user to activity gantt Project not found!','code'=>400], 400); {
$data = UserToActivity::find($id);
if($data->delete()){ if(!$data)
return response()->json(['status'=>'success','message'=>'Data deleted!','code'=>200], 200); return response()->json(['status'=>'failed','message'=>'data user to activity gantt Project not found!','code'=>400], 400);
}
if($data->delete()){
return response()->json(['status'=>'failed','message'=>'Failed to delete!','code'=> 500], 500); return response()->json(['status'=>'success','message'=>'Data deleted!','code'=>200], 200);
} }
public function edit($id){ return response()->json(['status'=>'failed','message'=>'Failed to delete!','code'=> 500], 500);
if(!$id || (int) $id < 0 || $id==""){ }
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
die(); public function edit($id){
} if(!$id || (int) $id < 0 || $id==""){
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
$result = UserToActivity::find($id); die();
}
if(!$result)
return response()->json(['status'=>'failed','message'=>'failed get data tools resource, please try again later!','code'=>400], 400); $result = UserToActivity::find($id);
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); if(!$result)
} return response()->json(['status'=>'failed','message'=>'failed get data tools resource, please try again later!','code'=>400], 400);
public function search(Request $request) return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200);
{ }
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'assign_hr_to_activity'); public function search(Request $request)
$builder = $dataBuilder['builder']; {
$countBuilder = $dataBuilder['count']; $payload = $request->all();
$dataGet = $builder->get(); if (isset($payload['join_column'])) {
$totalRecord = $countBuilder->count(); $join_column = $payload['join_column'];
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); unset($payload['join_column']);
} }
public function list() $dataBuilder = $this->setUpPayload($payload, 'assign_hr_to_activity');
{ $builder = $dataBuilder['builder'];
$data = UserToActivity::all(); $countBuilder = $dataBuilder['count'];
$countData = $data->count(); if (isset($join_column)) {
$startDate = $join_column['start_date'];
if($data){ $endDate = $join_column['end_date'];
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); $status = $join_column['status'];
}else{ $startDate = date("Y-m-d H:i:sO", strtotime($startDate));
return response()->json(['status'=>'failed','message'=>'failed get list user to activity gantt, please try again later!','code'=>400], 400); $endDate = date("Y-m-d H:i:sO", strtotime($endDate));
} $builder->where(function ($query) use ($startDate, $endDate) {
} $query
->where('m_proyek.mulai_proyek', '>=', $startDate)
public function listFiltered(Request $request) ->where('m_proyek.akhir_proyek', '<=', $endDate)
{ ->where(function ($query) use ($endDate, $startDate) {
$startDate = $request->start_date; $query
$endDate = $request->end_date; ->where('m_activity.start_date', '>=', $startDate)
$userId = $request->user_id; ->where('m_activity.end_date', '<=', $endDate);
$proyekId = $request->proyek_id; });
});
if (isset($proyekId)) { }
$data = UserToActivity::select('assign_hr_to_activity.id', 'assign_hr_to_activity.activity_id', 'm_activity.name', 'm_activity.kode_sortname', 'm_activity.start_date', 'm_activity.end_date') $dataGet = $builder->get();
->join('m_activity', 'assign_hr_to_activity.activity_id', '=', 'm_activity.id') if (isset($status) && $status != "") {
->where('m_activity.start_date', '=', $startDate) $filteredData = [];
->where('m_activity.end_date', '=', $endDate) foreach ($dataGet as $value) {
->where('assign_hr_to_activity.user_id', '=', $userId) $assignMaterial = AssignMaterial::where('activity_id', $value->activity_id)->first();
->where('assign_hr_to_activity.proyek_id', '=', $proyekId) if ($assignMaterial->status_activity == $status) {
->get(); $filteredData[] = $value;
}else { }
$data = UserToActivity::select('assign_hr_to_activity.id', 'assign_hr_to_activity.activity_id', 'm_activity.name', 'm_activity.kode_sortname', 'm_activity.start_date', 'm_activity.end_date') }
->join('m_activity', 'assign_hr_to_activity.activity_id', '=', 'm_activity.id') $dataGet = $filteredData;
->where('m_activity.start_date', '=', $startDate) }
->where('m_activity.end_date', '=', $endDate) $totalRecord = $countBuilder->count();
->where('assign_hr_to_activity.user_id', '=', $userId) return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
->get(); }
}
$countData = $data->count(); public function list()
{
if($data){ $data = UserToActivity::all();
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); $countData = $data->count();
}else{
return response()->json(['status'=>'failed','message'=>'failed get list user to activity gantt, please try again later!','code'=>400], 400); if($data){
} return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200);
} }else{
return response()->json(['status'=>'failed','message'=>'failed get list user to activity gantt, please try again later!','code'=>400], 400);
public function datatables(Request $request){ }
$id_activity = $request->query('idact'); }
$data = UserToActivity::select("assign_hr_to_activity.id as id", "u.name as user_name", "mrp.name as role_name")
->join("m_role_proyek as mrp", "mrp.id", "=", "assign_hr_to_activity.role_proyek_id") public function listFiltered(Request $request)
->join("m_users as u", "u.id", "=", "assign_hr_to_activity.user_id") {
->where('assign_hr_to_activity.activity_id', $id_activity) $startDate = $request->start_date;
->get(); $endDate = $request->end_date;
return Datatables::of($data) $userId = $request->user_id;
->addIndexColumn() $proyekId = $request->proyek_id;
->addColumn('action', function($row){
$actionBtn = '<a href="javascript:void(0)" data-id="'.$row->id.'" class="delete btn btn-danger btn-sm btn-hr-delete"><i class="fa fa-trash"></i></a>'; if (isset($proyekId)) {
return $actionBtn; $data = UserToActivity::select('assign_hr_to_activity.id', 'assign_hr_to_activity.activity_id', 'm_activity.name', 'm_activity.kode_sortname', 'm_activity.start_date', 'm_activity.end_date')
}) ->join('m_activity', 'assign_hr_to_activity.activity_id', '=', 'm_activity.id')
->rawColumns(['action'])->make(true); ->where('m_activity.start_date', '=', $startDate)
} ->where('m_activity.end_date', '=', $endDate)
} ->where('assign_hr_to_activity.user_id', '=', $userId)
->where('assign_hr_to_activity.proyek_id', '=', $proyekId)
->get();
}else {
$data = UserToActivity::select('assign_hr_to_activity.id', 'assign_hr_to_activity.activity_id', 'm_activity.name', 'm_activity.kode_sortname', 'm_activity.start_date', 'm_activity.end_date')
->join('m_activity', 'assign_hr_to_activity.activity_id', '=', 'm_activity.id')
->where('m_activity.start_date', '=', $startDate)
->where('m_activity.end_date', '=', $endDate)
->where('assign_hr_to_activity.user_id', '=', $userId)
->get();
}
$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 list user to activity gantt, please try again later!','code'=>400], 400);
}
}
public function datatables(Request $request){
$id_activity = $request->query('idact');
$data = UserToActivity::select("assign_hr_to_activity.id as id", "assign_hr_to_activity.start_date", "assign_hr_to_activity.end_date", "u.name as user_name", "mrp.name as role_name")
->join("m_role_proyek as mrp", "mrp.id", "=", "assign_hr_to_activity.role_proyek_id")
->join("m_users as u", "u.id", "=", "assign_hr_to_activity.user_id")
->where('assign_hr_to_activity.activity_id', $id_activity)
->get();
return Datatables::of($data)
->addIndexColumn()
->addColumn('action', function($row){
$actionBtn = '<a href="javascript:void(0)" data-id="'.$row->id.'" class="delete btn btn-danger btn-sm btn-hr-delete"><i class="fa fa-trash"></i></a>';
return $actionBtn;
})
->rawColumns(['action'])->make(true);
}
}

124
app/Models/UserToActivity.php

@ -1,61 +1,63 @@
<?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;
class UserToActivity extends Model class UserToActivity extends Model
{ {
protected $table = 'assign_hr_to_activity'; protected $table = 'assign_hr_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 = [
'user_id', 'user_id',
'proyek_id', 'proyek_id',
'version_gantt_id', 'version_gantt_id',
'role_proyek_id', 'role_proyek_id',
'activity_id', 'activity_id',
'created_at', 'start_date',
'created_by', 'end_date',
'updated_at', 'created_at',
'updated_by' 'created_by',
]; 'updated_at',
'updated_by'
public static function boot() { ];
parent::boot();
public static function boot() {
static::created(function($data) { parent::boot();
$activity = Activity::find($data->activity_id);
$getWorkingHours = UserToProyek::where('user_id', $data->user_id)->where('proyek_id', $activity->proyek_id)->first(); static::created(function($data) {
$activity = Activity::find($data->activity_id);
$salary = ($getWorkingHours->standart_rate * $activity->duration) * ($getWorkingHours->max_used / 100); $getWorkingHours = UserToProyek::where('user_id', $data->user_id)->where('proyek_id', $activity->proyek_id)->first();
if($getWorkingHours->uom_standart_rate == "Hour") $salary = ($getWorkingHours->standart_rate * $activity->duration) * ($getWorkingHours->max_used / 100);
$salary = ($getWorkingHours->standart_rate * 8) * $activity->duration * ($getWorkingHours->max_used / 100);
if($getWorkingHours->uom_standart_rate == "Hour")
$activity->rencana_biaya += $salary; $salary = ($getWorkingHours->standart_rate * 8) * $activity->duration * ($getWorkingHours->max_used / 100);
$activity->save();
}); $activity->rencana_biaya += $salary;
$activity->save();
static::deleted(function($data) { });
$activity = Activity::find($data->activity_id);
static::deleted(function($data) {
$getWorkingHours = UserToProyek::where('user_id', $data->user_id)->where('proyek_id', $activity->proyek_id)->first(); $activity = Activity::find($data->activity_id);
$salary = ($getWorkingHours->standart_rate * $activity->duration) * ($getWorkingHours->max_used / 100);
if($getWorkingHours->uom_standart_rate == "Hour"){ $getWorkingHours = UserToProyek::where('user_id', $data->user_id)->where('proyek_id', $activity->proyek_id)->first();
$salary = ($getWorkingHours->standart_rate * 8) * $activity->duration * ($getWorkingHours->max_used / 100); $salary = ($getWorkingHours->standart_rate * $activity->duration) * ($getWorkingHours->max_used / 100);
} if($getWorkingHours->uom_standart_rate == "Hour"){
$salary = ($getWorkingHours->standart_rate * 8) * $activity->duration * ($getWorkingHours->max_used / 100);
$activity->rencana_biaya -= $salary; }
if ($activity->rencana_biaya < 0) {
$activity->rencana_biaya = 0; $activity->rencana_biaya -= $salary;
} if ($activity->rencana_biaya < 0) {
$activity->save(); $activity->rencana_biaya = 0;
}); }
$activity->save();
} });
} }
}

1
routes/web.php

@ -209,6 +209,7 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout
$router->post('/activity/import-update', 'ActivityController@importUpdate'); $router->post('/activity/import-update', 'ActivityController@importUpdate');
$router->post('/activity/import-old', 'ActivityController@importOld'); $router->post('/activity/import-old', 'ActivityController@importOld');
$router->post('/activity/batch-update/{ganttId}', 'ActivityController@batchUpdate'); $router->post('/activity/batch-update/{ganttId}', 'ActivityController@batchUpdate');
$router->get('/activity/update-schedule/{ganttId}', 'ActivityController@updateSchedule');
$router->post('/task', 'ActivityController@add'); $router->post('/task', 'ActivityController@add');
$router->get('/task/edit/{id}', 'ActivityController@edit'); $router->get('/task/edit/{id}', 'ActivityController@edit');
$router->put('/task/{id}', 'ActivityController@update'); $router->put('/task/{id}', 'ActivityController@update');

Loading…
Cancel
Save