Browse Source

get pull

pull/3/head
wahyuun 1 year ago
parent
commit
3d62b5cdd3
  1. 3
      Dockerfile
  2. 6
      app/Console/Commands/syncHumanResourceIntegration.php
  3. 42
      app/Helpers/MasterFunctionsHelper.php
  4. 525
      app/Http/Controllers/ActivityController.php
  5. 153
      app/Http/Controllers/BroadcastController.php
  6. 194
      app/Http/Controllers/Controller.php
  7. 133
      app/Http/Controllers/DashboardBoDController.php
  8. 27
      app/Http/Controllers/HumanResourceController.php
  9. 44
      app/Http/Controllers/MapMonitoringController.php
  10. 147
      app/Http/Controllers/PresenceController.php
  11. 497
      app/Http/Controllers/ProjectController.php
  12. 2
      app/Http/Controllers/RequestMaterialController.php
  13. 6
      app/Http/Controllers/ShowHideColumnController.php
  14. 2
      app/Http/Controllers/UserToProyekController.php
  15. 36
      app/Jobs/ProcessSCurve.php
  16. 6
      app/Models/Activity.php
  17. 2
      app/Models/AssignMaterial.php
  18. 2
      app/Models/Broadcast.php
  19. 4
      app/Models/UserToProyek.php
  20. 49
      app/Services/FCMService.php
  21. 1
      bootstrap/app.php
  22. 2
      config/api.php
  23. 5
      config/fcm.php
  24. 36
      database/migrations/2023_08_29_130624_create_jobs_table.php
  25. 9
      docker/nginx/conf.d/default.conf
  26. 1947
      docker/php/php.ini
  27. 72
      rest-client.http
  28. 12
      routes/web.php

3
Dockerfile

@ -29,6 +29,9 @@ RUN docker-php-ext-install \
pgsql \
tokenizer
# Copy php.ini to the container
COPY /docker/php/php.ini /usr/local/etc/php/
#Install Extensions
RUN docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql

6
app/Console/Commands/syncHumanResourceIntegration.php

@ -39,9 +39,9 @@ class syncHumanResourceIntegration extends Command
*/
public function handle()
{
// $url = config('api.adw').'/employees?page=1';
// echo "Requesting to " . $url;
$response = null;
$url = config('api.adw').'/employees?page=1';
echo "Requesting to " . $url;
$response = MasterFunctionsHelper::curlReq($url);
if(!$response)
return;

42
app/Helpers/MasterFunctionsHelper.php

@ -189,13 +189,18 @@ class MasterFunctionsHelper
/* $interval = \DateInterval::createFromDateString('1 day'); */// should be using this but its bugged
$interval = new \DateInterval('P7D');
} else {
$maxDate = DB::table('assign_material_to_activity as ama')
$actualMaxDate = DB::table('assign_material_to_activity as ama')
->where("ama.proyek_id", $keyGantt['proyek_id'])
->join('m_activity as a', 'a.id', '=', 'ama.activity_id')
->where('a.version_gantt_id', '=', $keyGantt['id'])
->max("plan_date"); // plan date overlapped with assign_material_to_activity's, it should be m_activity's
$end = new \DateTime($maxDate . ' Friday');
$end->modify('next Friday');
->max("a.end_date"); // plan date overlapped with assign_material_to_activity's, it should be m_activity's
$plannedMaxDate = DB::table('assign_material_to_activity as ama')
->where("ama.proyek_id", $keyGantt['proyek_id'])
->join('m_activity as a', 'a.id', '=', 'ama.activity_id')
->where('a.version_gantt_id', '=', $keyGantt['id'])
->max("a.planned_end"); // plan date overlapped with assign_material_to_activity's, it should be m_activity'
$maxDate = max(new \DateTime($plannedMaxDate), new \DateTime($actualMaxDate));
$end = new \DateTime($maxDate->format('Y-m-d') . ' Friday');
$end->modify('next Friday');
$interval = new \DateInterval('P7D');
}
@ -422,6 +427,8 @@ class MasterFunctionsHelper
$potential = $costDeviation == 0 ? "ON BUDGET" : "OVERRUN";
}
$lastReal = $tempPercentageReal[count($tempPercentageReal) - 1];
$totalBCWP = $lastReal * $dataProject->rencana_biaya / 100;
$dataResponse = array(
"date" => $tempDate,
"percentage" => $tempPercentage,
@ -600,6 +607,12 @@ class MasterFunctionsHelper
->where('activity_id', '=', $keyActualM->activity_id)
->groupBy('activity_id')
->first();
if (!isset($sumVolActual)) {
$sumVolActual = (object) [
'activity_id' => $keyActualM->activity_id,
'ttl_qty_plan' => "0"
];
}
$sumReportActual = DB::table('report_activity_material')
->where('activity_id', $keyActualM->activity_id)
->sum('qty');
@ -619,18 +632,29 @@ class MasterFunctionsHelper
->where('activity_id', '=', $keyActualM->activity_id)
->orderBy('status_activity', 'ASC')
->first();
$dataTempReport[$w]['percentage'] = ($keyActualM->qty / $sumVolActual->ttl_qty_plan) * $keyActualM->bobot_planning;
if (!isset($checkStatusActivity)) {
$checkStatusActivity = (object) [
'activity_id' => $keyActualM->activity_id,
'status_activity' => 'open'
];
}
if ($sumVolActual->ttl_qty_plan == "0") {
$actual = 0;
} else {
$actual = $keyActualM->qty / $sumVolActual->ttl_qty_plan;
}
$dataTempReport[$w]['percentage'] = $actual * $keyActualM->bobot_planning;
// $sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning;
// if($keyActualM->qty/$sumVolActual->ttl_qty_plan >= 1){
if ($checkStatusActivity->status_activity == 'done') {
$sumPercentageActual += $keyActualM->bobot_planning / $reportCount;
// $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual;
} else {
if ($keyActualM->qty / $sumVolActual->ttl_qty_plan >= 1 || (int) $sumVolActual->ttl_qty_plan == (int) $sumReportActual) {
$sumPercentageActual += (($keyActualM->qty / $sumVolActual->ttl_qty_plan) * $keyActualM->bobot_planning) * (95 / 100);
if ( $actual >= 1 || (int) $sumVolActual->ttl_qty_plan == (int) $sumReportActual) {
$sumPercentageActual += ($actual * $keyActualM->bobot_planning) * (95 / 100);
// $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual;
} else {
$sumPercentageActual += ($keyActualM->qty / $sumVolActual->ttl_qty_plan) * $keyActualM->bobot_planning;
$sumPercentageActual += $actual * $keyActualM->bobot_planning;
// $sumPercentageActual = $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual;
}
}
@ -698,6 +722,8 @@ class MasterFunctionsHelper
$potential = $costDeviation == 0 ? "ON BUDGET" : "OVERRUN";
}
$lastReal = $tempPercentageReal[count($tempPercentageReal) - 1];
$totalBCWP = $lastReal * $dataProject->rencana_biaya / 100;
$dataResponse = array(
"date" => $tempDate,
"percentage" => $tempPercentage,

525
app/Http/Controllers/ActivityController.php

@ -21,8 +21,8 @@ class ActivityController extends Controller
public function getByGanttId($id, $proyek_id)
{
$gantt = VersionGantt::find($id);
if(Activity::where('proyek_id', $proyek_id)->where("version_gantt_id", $id)->count() == 0) {
if(!$gantt->hierarchy_ftth_id) {
if (Activity::where('proyek_id', $proyek_id)->where("version_gantt_id", $id)->count() == 0) {
if (!$gantt->hierarchy_ftth_id) {
$this->cloneTemplate($id, $proyek_id);
} else {
$this->cloneTemplate($id, $proyek_id, $gantt->hierarchy_ftth_id);
@ -31,46 +31,59 @@ class ActivityController extends Controller
$dataGantt = $this->getDataActivity($id);
return response()->json(['status'=>'success','data'=> $dataGantt,'code'=>200], 200);
return response()->json(['status' => 'success', 'data' => $dataGantt, 'code' => 200], 200);
}
private function getDataActivity($id)
{
$checkHeader = Activity::where('version_gantt_id', $id)->where('type_activity', 'header')->count(); $finalData = [];
if($checkHeader > 0){
$checkHeader = Activity::where('version_gantt_id', $id)->where('type_activity', 'header')->count();
$finalData = [];
if ($checkHeader > 0) {
$dataHeader = Activity::where('version_gantt_id', $id)->where('type_activity', 'header')->first();
$startDate = date_create($dataHeader->start_date);
$endDate = date_create($dataHeader->end_date);
$dataHeader->start_date = date_format($startDate,"Y-m-d H:i:s");
$dataHeader->end_date = date_format($endDate,"Y-m-d H:i:s");
$dataHeader->start_date = date_format($startDate, "Y-m-d H:i:s");
$dataHeader->end_date = date_format($endDate, "Y-m-d H:i:s");
$dataHeader->progress = $dataHeader->persentase_progress / 100;
$dataHeader->planned_start = isset($dataHeader->planned_start) ? date_format(date_create($dataHeader->planned_start),"Y-m-d H:i:s") : NULL;
$dataHeader->planned_end = isset($dataHeader->planned_end) ? date_format(date_create($dataHeader->planned_end),"Y-m-d H:i:s") : NULL;
$dataHeader->planned_start = isset($dataHeader->planned_start) ? date_format(date_create($dataHeader->planned_start), "Y-m-d H:i:s") : NULL;
$dataHeader->planned_end = isset($dataHeader->planned_end) ? date_format(date_create($dataHeader->planned_end), "Y-m-d H:i:s") : NULL;
$actualStart = $this->getActivityFirst($dataHeader->id);
$dataHeader->actual_start = date_format(date_create($actualStart), "Y-m-d");
$actualEnd = $this->getActivityLast($dataHeader->id);
$dataHeader->actual_end = isset($actualEnd) ? date_format(date_create($actualEnd), "Y-m-d") : NULL;
$dataHeader->type = "header";
$dataHeader->text = $dataHeader->name;
$finalData[] = $dataHeader;
$data = Activity::where('version_gantt_id', $id)->where('parent_id', $dataHeader->id)->orderBy('sortorder', 'asc')->get();
}else{
} else {
$data = Activity::where('version_gantt_id', $id)->whereNull('parent_id')->orderBy('sortorder', 'asc')->get();
}
foreach($data as $objRow){
foreach ($data as $objRow) {
$type = "project";
$dataChildren = $this->getChildren($id, $objRow->id);
$startDate = date_create($objRow->start_date);
$endDate = date_create($objRow->end_date);
if($objRow->type_activity=="milestone")
if ($objRow->type_activity == "milestone")
$type = $objRow->type_activity;
if(empty($dataChildren))
if (empty($dataChildren))
$type = "task";
$objRow->text = $objRow->name;
$objRow->parent = $objRow->parent_id ? $objRow->parent_id : null;
$objRow->start_date = date_format($startDate,"Y-m-d H:i:s");
$objRow->end_date = date_format($endDate,"Y-m-d H:i:s");
$objRow->planned_start = isset($objRow->planned_start) ? date_format(date_create($objRow->planned_start),"Y-m-d H:i:s") : NULL;
$objRow->planned_end = isset($objRow->planned_end) ? date_format(date_create($objRow->planned_end),"Y-m-d H:i:s") : NULL;
$objRow->start_date = date_format($startDate, "Y-m-d H:i:s");
$objRow->end_date = date_format($endDate, "Y-m-d H:i:s");
$objRow->planned_start = isset($objRow->planned_start) ? date_format(date_create($objRow->planned_start), "Y-m-d H:i:s") : NULL;
$objRow->planned_end = isset($objRow->planned_end) ? date_format(date_create($objRow->planned_end), "Y-m-d H:i:s") : NULL;
$actualStart = $this->getActivityFirst($objRow->id);
$objRow->actual_start = isset($actualStart) ? date_format(date_create($actualStart), "Y-m-d") : NULL;
$actualEnd = $this->getActivityLast($objRow->id);
$objRow->actual_end = isset($actualEnd) ? date_format(date_create($actualEnd), "Y-m-d") : NULL;
$objRow->progress = $objRow->persentase_progress / 100;
$objRow->type = $type;
$finalData[] = $objRow;
@ -79,23 +92,22 @@ class ActivityController extends Controller
$dataLink = Link::where('version_gantt_id', $id)->get();
$finalLink = [];
foreach($dataLink as $objRow)
{
foreach ($dataLink as $objRow) {
$dataRow = array(
'id'=>$objRow->id,
'source'=>$objRow->s_activity_id,
'target'=>$objRow->t_activity_id,
'type'=>$objRow->type_link,
'code'=>$objRow->code_link
'id' => $objRow->id,
'source' => $objRow->s_activity_id,
'target' => $objRow->t_activity_id,
'type' => $objRow->type_link,
'code' => $objRow->code_link
);
if($objRow->lag)
if ($objRow->lag)
$dataRow['lag'] = $objRow->lag;
$finalLink[] = $dataRow;
}
$resultData = array(
"data"=>$finalData,
"links"=>$finalLink
"data" => $finalData,
"links" => $finalLink
);
return $resultData;
@ -105,23 +117,35 @@ class ActivityController extends Controller
{
$finalData = [];
$data = Activity::where('version_gantt_id', $gantt_id)->where('parent_id', $parent_id)->orderBy('sortorder', 'asc')->get();
foreach($data as $objRow){
foreach ($data as $objRow) {
$objRow->parent = $parent_id;
$objRow->text = $objRow->name;
$objRow->progress = (float)$objRow->persentase_progress/100;
$objRow->progress = (float) $objRow->persentase_progress / 100;
$startDate = date_create($objRow->start_date);
$endDate = date_create($objRow->end_date);
$objRow->start_date = date_format($startDate,"Y-m-d H:i:s");
$objRow->end_date = date_format($endDate,"Y-m-d H:i:s");
$objRow->planned_start = isset($objRow->planned_start) ? date_format(date_create($objRow->planned_start),"Y-m-d H:i:s") : NULL;
$objRow->planned_end = isset($objRow->planned_end) ? date_format(date_create($objRow->planned_end),"Y-m-d H:i:s") : NULL;
$objRow->start_date = date_format($startDate, "Y-m-d H:i:s");
$objRow->end_date = date_format($endDate, "Y-m-d H:i:s");
$objRow->planned_start = isset($objRow->planned_start) ? date_format(date_create($objRow->planned_start), "Y-m-d H:i:s") : NULL;
$objRow->planned_end = isset($objRow->planned_end) ? date_format(date_create($objRow->planned_end), "Y-m-d H:i:s") : NULL;
$dataChildren = $this->getChildren($gantt_id, $objRow->id);
if($objRow->type_activity=="milestone"){
if ($objRow->type_activity == "milestone") {
$objRow->type = $objRow->type_activity;
}elseif(empty($dataChildren)){
$objRow->actual_start = isset($objRow->actual_start) ? date_format(date_create($objRow->actual_start), "Y-m-d") : NULL;
} elseif (empty($dataChildren)) {
$objRow->type = "task";
}else{
$objRow->actual_start = isset($objRow->actual_start) ? date_format(date_create($objRow->actual_start), "Y-m-d") : NULL;
$objRow->actual_end = isset($objRow->actual_end) ? date_format(date_create($objRow->actual_end), "Y-m-d") : NULL;
if(isset($objRow->actual_start)){
$objRow->auto_scheduling = false;
}
} else {
$objRow->type = "project";
$actualStart = $this->getActivityFirst($objRow->id);
$objRow->actual_start = isset($actualStart) ? date_format(date_create($actualStart), "Y-m-d") : NULL;
$actualEnd = $this->getActivityLast($objRow->id);
$objRow->actual_end = isset($actualEnd) ? date_format(date_create($actualEnd), "Y-m-d") : NULL;
}
$finalData[] = $objRow;
$finalData = array_merge($finalData, $dataChildren);
@ -129,33 +153,62 @@ class ActivityController extends Controller
return $finalData;
}
private function cloneTemplate($id, $proyek_id, $hierarchy_ftth_id = null) {
public function getActivityFirst($parentId){
$activity = Activity::where('parent_id', $parentId)->orderByRaw('actual_start ASC')->first();
if (!isset($activity)) {
return null;
}
if($activity->type_activity == "task"){
// Log::info("activity ", [$activity]);
return $activity->actual_start;
}else{
return $this->getActivityFirst($activity->id);
}
}
public function getActivityLast($parentId){
$activity = Activity::where('parent_id', $parentId)->orderByRaw('actual_end DESC')->first();
if (!isset($activity)) {
return null;
}
if($activity->type_activity == "task"){
// Log::info("activity ", [$activity]);
return $activity->actual_end;
}else{
return $this->getActivityLast($activity->id);
}
}
private function cloneTemplate($id, $proyek_id, $hierarchy_ftth_id = null)
{
$project = Project::find($proyek_id);
if($hierarchy_ftth_id){
if ($hierarchy_ftth_id) {
$gantt = VersionGantt::find($id);
$rootActivity = Activity::create([
'version_gantt_id'=>$id,
'proyek_id'=>$proyek_id,
'name'=> $gantt->name_version,
'start_date'=> $project->mulai_proyek,
'end_date'=> $project->akhir_proyek,
'rencana_biaya'=> $project->rencana_biaya,
'type_activity'=> 'project',
'created_by'=>$this->currentName,
'sortorder'=>1
'version_gantt_id' => $id,
'proyek_id' => $proyek_id,
'name' => $gantt->name_version,
'start_date' => $project->mulai_proyek,
'end_date' => $project->akhir_proyek,
'rencana_biaya' => $project->rencana_biaya,
'type_activity' => 'project',
'created_by' => $this->currentName,
'sortorder' => 1
]);
} else {
$rootActivity = Activity::create([
'version_gantt_id'=>$id,
'proyek_id'=>$proyek_id,
'name'=> $project->nama,
'kode_sortname'=>$project->kode_sortname,
'start_date'=> $project->mulai_proyek,
'end_date'=> $project->akhir_proyek,
'rencana_biaya'=> $project->rencana_biaya,
'type_activity'=> 'project',
'created_by'=>$this->currentName,
'sortorder'=>1
'version_gantt_id' => $id,
'proyek_id' => $proyek_id,
'name' => $project->nama,
'kode_sortname' => $project->kode_sortname,
'start_date' => $project->mulai_proyek,
'end_date' => $project->akhir_proyek,
'rencana_biaya' => $project->rencana_biaya,
'type_activity' => 'project',
'created_by' => $this->currentName,
'sortorder' => 1
]);
}
@ -164,19 +217,19 @@ class ActivityController extends Controller
->orderByRaw('id ASC')
->get();
foreach($resultTypeProject as $objRow){
foreach ($resultTypeProject as $objRow) {
$childActivities = TemplateGantt::where("parent_id", $objRow->id)->count();
$max = Activity::where('version_gantt_id', $id)->max('sortorder');
$resultNew = Activity::create([
'type_activity'=> $childActivities > 0 ? "project" : "task",
'version_gantt_id'=>$id,
'parent_id'=>$rootActivity->id,
'proyek_id'=>$proyek_id,
'name'=> $objRow->name_activity,
'start_date'=>date("Y-m-d H:i:s"),
'end_date'=>date("Y-m-d H:i:s"),
'created_by'=>$this->currentName,
'sortorder'=>$max+1
'type_activity' => $childActivities > 0 ? "project" : "task",
'version_gantt_id' => $id,
'parent_id' => $rootActivity->id,
'proyek_id' => $proyek_id,
'name' => $objRow->name_activity,
'start_date' => date("Y-m-d H:i:s"),
'end_date' => date("Y-m-d H:i:s"),
'created_by' => $this->currentName,
'sortorder' => $max + 1
]);
$this->getChildrenTemplate($id, $objRow->id, $project->type_project_id, $proyek_id, $resultNew->id, $project->mulai_proyek);
}
@ -185,19 +238,19 @@ class ActivityController extends Controller
private function getChildrenTemplate($id, $parent_id, $type_proyek_id, $proyek_id, $parent_new, $firstDay)
{
$data = TemplateGantt::where('parent_id', $parent_id)->orderByRaw('id ASC')->get();
foreach($data as $objRow){
foreach ($data as $objRow) {
$childActivities = TemplateGantt::where("parent_id", $objRow->id)->count();
$max = Activity::where('version_gantt_id', $id)->max('sortorder');
$resultNew = Activity::create([
'type_activity'=> $childActivities > 0 ? "project" : "task",
'version_gantt_id'=>$id,
'parent_id'=>$parent_new,
'proyek_id'=>$proyek_id,
'name'=> $objRow->name_activity,
'start_date'=>$firstDay,
'end_date'=>$firstDay,
'created_by'=>$this->currentName,
'sortorder'=>$max+1
'type_activity' => $childActivities > 0 ? "project" : "task",
'version_gantt_id' => $id,
'parent_id' => $parent_new,
'proyek_id' => $proyek_id,
'name' => $objRow->name_activity,
'start_date' => $firstDay,
'end_date' => $firstDay,
'created_by' => $this->currentName,
'sortorder' => $max + 1
]);
$this->getChildrenTemplate($id, $objRow->id, $type_proyek_id, $proyek_id, $resultNew->id, $firstDay);
}
@ -206,7 +259,7 @@ class ActivityController extends Controller
public function add(Request $request)
{
$this->validate($request, [
'version_gantt_id'=>'required'
'version_gantt_id' => 'required'
]);
$data = $request->all();
@ -215,75 +268,79 @@ class ActivityController extends Controller
$data['created_by'] = $this->currentName;
$max = Activity::where('version_gantt_id', $request->version_gantt_id)->max('sortorder');
$data['sortorder'] = $max + 1;
if (!isset($data['type_activity'])) {
$data['type_activity'] = "task";
}
$parent = $data['parent_id'] ?? null;
if($parent){
if ($parent) {
$parentData = Activity::find($parent);
if($parentData->parent_id) {
if ($parentData->parent_id) {
$parentData->update(["type_activity" => "project"]);
}
CommentActivity::where('activity_id', $parent)->delete();
UserToActivity::where('activity_id', $parent)->delete();
}
if(!$result = Activity::create($data))
return response()->json(['status'=>'failed','action'=>'error','code'=> 500], 500);
if (!$result = Activity::create($data))
return response()->json(['status' => 'failed', 'action' => 'error', 'code' => 500], 500);
return response()->json(['status'=>'success','action'=>'inserted', 'tid'=>$result->id,'code'=>200], 200);
return response()->json(['status' => 'success', 'action' => 'inserted', 'tid' => $result->id, 'code' => 200], 200);
}
public function edit($id){
if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
public function edit($id)
{
if (empty($id) || !is_int((int) $id))
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
if(!$result = Activity::find($id))
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
if (!$result = Activity::find($id))
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
return response()->json(['status'=>'success','code'=>200,'data'=> $result], 200);
return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200);
}
public function update(Request $request, $id)
{
if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed', 'action'=>'error','message'=>'id is required!','code'=>400], 400);
if (empty($id) || !is_int((int) $id))
return response()->json(['status' => 'failed', 'action' => 'error', 'message' => 'id is required!', 'code' => 400], 400);
$updateBobot = true;
if(!$data = Activity::find($id))
return response()->json(['status'=>'failed', 'action'=>'error','message'=>'Data not found!','code'=> 404], 404);
if (!$data = Activity::find($id))
return response()->json(['status' => 'failed', 'action' => 'error', 'message' => 'Data not found!', 'code' => 404], 404);
$dataUpdate = $request->all();
$dataUpdate['name'] = $request->text;
$dataUpdate['persentase_progress'] = $request->progress*100;
$dataUpdate['persentase_progress'] = $request->progress * 100;
$dataUpdate['updated_by'] = $this->currentName;
unset($dataUpdate['sortorder']);
if($data->type_activity!='header')
if ($data->type_activity != 'header')
$dataUpdate['type_activity'] = $request->type;
if($request->has("target")){
if ($request->has("target")) {
$this->updateOrder($id, $request->target);
}
if(!$data->update($dataUpdate))
return response()->json(['status'=>'failed', 'action'=>'error','message'=>'data activity failed updated!','code'=>400], 400);
if (!$data->update($dataUpdate))
return response()->json(['status' => 'failed', 'action' => 'error', 'message' => 'data activity failed updated!', 'code' => 400], 400);
return response()->json(['status'=>'success','update_bobot'=> $updateBobot, 'data'=>$dataUpdate, 'action'=>'updated','message'=>'Activity updated!','code'=>200], 200);
return response()->json(['status' => 'success', 'update_bobot' => $updateBobot, 'data' => $dataUpdate, 'action' => 'updated', 'message' => 'Activity updated!', 'code' => 200], 200);
}
private function updateOrder($taskId, $target){
private function updateOrder($taskId, $target)
{
$nextTask = false;
$targetId = $target;
if(strpos($target, "next:") === 0){
if (strpos($target, "next:") === 0) {
$targetId = substr($target, strlen("next:"));
$nextTask = true;
}
if($targetId == "null")
if ($targetId == "null")
return;
$targetOrder = Activity::find($targetId)->sortorder;
if($nextTask)
if ($nextTask)
$targetOrder++;
Activity::where("sortorder", ">=", $targetOrder)->increment("sortorder");
@ -293,40 +350,72 @@ class ActivityController extends Controller
$updatedTask->save();
}
public function updateRegular(Request $request, $id){
if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
public function updateRegular(Request $request, $id)
{
if (empty($id) || !is_int((int) $id))
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
$data = Activity::find($id);
if(!$data = Activity::find($id))
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
if (!$data = Activity::find($id))
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
if(!$data->update($request->all()))
return response()->json(['status'=>'failed','message'=>'Failed to update!','code'=> 500], 500);
if (!$data->update($request->all()))
return response()->json(['status' => 'failed', 'message' => 'Failed to update!', 'code' => 500], 500);
return response()->json(['status'=>'success','message'=>'Activity Updated!','code'=> 200], 200);
return response()->json(['status' => 'success', 'message' => 'Activity Updated!', 'code' => 200], 200);
}
public function batchUpdate(Request $request, $ganttId)
{
$entities = $request->all();
if (empty($ganttId) || !is_int((int) $ganttId))
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
$activity = Activity::where('version_gantt_id',$ganttId)->get();
$link = Link::where('version_gantt_id', $ganttId)->get();
if (!$activity)
return response()->json(['status' => 'failed', 'message' => 'Activity not found!', 'code' => 404], 404);
if (!$link)
return response()->json(['status' => 'failed', 'message' => 'Link not found!', 'code' => 404], 404);
foreach ($entities as $entity) {
if ($entity['entity'] == "task") {
$activityToUpdate = $activity->firstWhere('id', $entity['data']['id']);
$entity['data']['name'] = $entity['data']['text'];
$entity['data']['persentase_progress'] = $entity['data']['progress'] * 100;
if (isset($entity['data']['target'])) {
$this->updateOrder($entity['data']['id'], $entity['data']['target']);
}
if(!$activityToUpdate->update($entity['data']))
return response()->json(['status' => 'failed', 'message' => 'Failed to update activity !', 'code' => 500], 500);
$updatedJobsDone = $activityToUpdate->jobs_done;
} else if ($entity['entity'] == "link"){
$linkToUpdate = $link->firstWhere('id', $entity['data']['id']);
if(!$linkToUpdate->update($entity['data']))
return response()->json(['status' => 'failed', 'message' => 'Failed to update link !', 'code' => 500], 500);
}
}
return response()->json(['status' => 'success', 'message' => 'Activity Updated!', 'code' => 200], 200);
}
public function delete($id)
{
if(!$data = Activity::find($id))
return response()->json(['status'=>'failed', 'action'=>'error','message'=> 'Data not found!','code'=> 404], 404);
if (!$data = Activity::find($id))
return response()->json(['status' => 'failed', 'action' => 'error', 'message' => 'Data not found!', 'code' => 404], 404);
if(!$data->delete())
return response()->json(['status'=>'failed', 'action'=>'error','message'=>'data activity failed deleted!','code'=> 500], 500);
if (!$data->delete())
return response()->json(['status' => 'failed', 'action' => 'error', 'message' => 'data activity failed deleted!', 'code' => 500], 500);
return response()->json(['status'=>'success', "action"=>"deleted",'message'=>'data activity successfully deleted!','code'=>200], 200);
return response()->json(['status' => 'success', "action" => "deleted", 'message' => 'data activity successfully deleted!', 'code' => 200], 200);
}
public function getUpdate($id)
{
if(!$data = Activity::find($id))
return response()->json(['status'=>'failed', 'action'=>'error','message'=> 'Data not found!','code'=>400], 400);
if (!$data = Activity::find($id))
return response()->json(['status' => 'failed', 'action' => 'error', 'message' => 'Data not found!', 'code' => 400], 400);
$data->progress = (float) $data->persentase_progress / 100;
$data->rencana_biaya = str_replace(".", ",", $data->rencana_biaya);
return response()->json(['status'=>'success', "data"=> $data,'code'=>200], 200);
return response()->json(['status' => 'success', "data" => $data, 'code' => 200], 200);
}
public function search(Request $request)
@ -336,7 +425,7 @@ class ActivityController extends Controller
$countBuilder = $dataBuilder['count'];
$dataGet = $builder->get();
$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);
}
// before upload file
@ -349,46 +438,46 @@ class ActivityController extends Controller
Activity::where('version_gantt_id', $data['ganttId'])->delete();
$projectId = VersionGantt::where('id', $data['ganttId'])->first()->proyek_id;
$dayOffs = VersionGantt::find($data['ganttId'])->first()->config_dayoff;
$dayOffs = VersionGantt::where('id', $data['ganttId'])->first()->config_dayoff;
$activityStack = [];
$hasWeight = false;
foreach ($data['activities'] as $key => $value) {
if(isset($value['weight']) && $value['weight'] != null && $value['weight'] != 0){
if (isset($value['weight']) && $value['weight'] != null && $value['weight'] != 0) {
$hasWeight = true;
break;
}
}
if(!$hasWeight){
if (!$hasWeight) {
foreach ($data['activities'] as $key => $value) {
if($key == 0){
if ($key == 0) {
$data['activities'][$key]['weight'] = 100;
} else {
$parentWeight = 0;
$siblingsCount = 1;
$i = $key;
while($i > 0){
if ($data['activities'][$i - 1]['level'] == $data['activities'][$key]['level']-1){
while ($i > 0) {
if ($data['activities'][$i - 1]['level'] == $data['activities'][$key]['level'] - 1) {
$parentWeight = $data['activities'][$i - 1]['weight'];
break;
}
if ($data['activities'][$key]['level'] == $data['activities'][$i]['level']){
if ($data['activities'][$key]['level'] == $data['activities'][$i]['level']) {
$siblingsCount++;
}
$i--;
}
$i = $key+1;
while($i < count($data['activities'])){
if ($data['activities'][$i]['level'] == $data['activities'][$key]['level']-1){
$i = $key + 1;
while ($i < count($data['activities'])) {
if ($data['activities'][$i]['level'] == $data['activities'][$key]['level'] - 1) {
break;
}
// Log::info('level '.$data['activities'][$key]['level'].' i level '.$data['activities'][$i]['level']);
if ($data['activities'][$key]['level'] == $data['activities'][$i]['level']){
if ($data['activities'][$key]['level'] == $data['activities'][$i]['level']) {
$siblingsCount++;
}
$i++;
@ -396,7 +485,8 @@ class ActivityController extends Controller
$data['activities'][$key]['weight'] = $parentWeight / $siblingsCount;
}
};
}
;
}
$projectStart = Project::select('mulai_proyek')->where('id', $projectId)->first();
foreach ($data['activities'] as $i => $activity_row) {
@ -410,8 +500,8 @@ class ActivityController extends Controller
$endDate->modify('+1 day');
// Check if the current day is a day off (Sunday or Saturday)
$currentDayOfWeek = (int)$endDate->format('w');
if (strpos($dayOffs, (string)$currentDayOfWeek) !== false) {
$currentDayOfWeek = (int) $endDate->format('w');
if (strpos($dayOffs, (string) $currentDayOfWeek) !== false) {
continue; // Skip the day off and continue to the next day
}
@ -457,8 +547,12 @@ class ActivityController extends Controller
do {
array_pop($activityStack);
$lastStack = end($activityStack);
if ($lastStack) {
if ($activity->level > $lastStack->level)
$lastStackIsNotRight = false;
} else {
$lastStackIsNotRight = false;
}
} while ($lastStackIsNotRight);
}
@ -527,7 +621,8 @@ class ActivityController extends Controller
return response()->json(['stack' => $activityStack, 'status' => 'success', 'message' => 'Data imported!', 'projectId' => $projectId, 'code' => 200], 200);
}
private function getLatestGantt($id){
private function getLatestGantt($id)
{
$maxGanttId = VersionGantt::where("proyek_id", $id)->max("id");
$data = array(
"last_gantt_id" => $maxGanttId,
@ -540,20 +635,20 @@ class ActivityController extends Controller
{
$dataPayload = $request->all();
$allGantt = [];
if(isset($dataPayload['gannt_id'])){
if (isset($dataPayload['gannt_id'])) {
$allGantt = $dataPayload['gannt_id'];
}else{
} else {
foreach ($dataPayload['project_id'] as $val) {
$allGantt[] = $this->getLatestGantt($val);
}
}
$dataFinal=[];
$dataFinal = [];
foreach ($allGantt as $keyGantt) {
$dataProject = Project::find($keyGantt['proyek_id']);
$dataHeader = Activity::where('type_activity', 'header')->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['last_gantt_id'])->first();
if($dataHeader){
if ($dataHeader) {
$totalRencanaBudget = Activity::where('parent_id', $dataHeader->id)->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['last_gantt_id'])->sum("rencana_biaya");
}else{
} else {
$totalRencanaBudget = Activity::whereNull('parent_id')->where("proyek_id", $keyGantt['proyek_id'])->where("version_gantt_id", $keyGantt['last_gantt_id'])->sum("rencana_biaya");
}
$minDate = DB::table('assign_material_to_activity as ama')
@ -574,8 +669,8 @@ class ActivityController extends Controller
$arr_ActualM = [];
$tempDate = [];
$tempPercentage = [];
$tempTtlPercentPlan=0;
$tempTtlPercentActual=0;
$tempTtlPercentPlan = 0;
$tempTtlPercentActual = 0;
$currentACWP = 0;
$budgetControlACWP = 0;
$currentProgressActivity = 0;
@ -598,7 +693,7 @@ class ActivityController extends Controller
->get();
$dataTempPlan = [];
$x = 0;
$sumPercentagePlan=0;
$sumPercentagePlan = 0;
$totalACWP = isset($totalACWP) ? $totalACWP : 0;
$totalBCWP = isset($totalBCWP) ? $totalBCWP : 0;
foreach ($dataPlanM as $keyPlanM) {
@ -607,99 +702,100 @@ class ActivityController extends Controller
->where('activity_id', '=', $keyPlanM->activity_id)
->groupBy('activity_id')
->first();
$dataTempPlan [$x]['activity_id'] = $keyPlanM->activity_id;
$dataTempPlan [$x]['qty_plan'] = $keyPlanM->qty_planning;
$dataTempPlan [$x]['plan_date'] = $keyPlanM->plan_date;
$dataTempPlan [$x]['start_activity'] = $keyPlanM->start_activity;
$dataTempPlan [$x]['bobot_planning'] = $keyPlanM->bobot_planning;
$dataTempPlan [$x]['ttl_plan'] = $sumVolPlan->ttl_qty_plan;
$dataTempPlan [$x]['biaya_actual'] = $keyPlanM->biaya_actual;
$dataTempPlan [$x]['duration'] = $keyPlanM->duration;
$dataTempPlan [$x]['persentase_progress'] = $keyPlanM->persentase_progress;
$dataTempPlan [$x]['percentage'] = ($keyPlanM->qty_planning/$sumVolPlan->ttl_qty_plan)*$keyPlanM->bobot_planning;
$sumPercentagePlan+=($keyPlanM->qty_planning/$sumVolPlan->ttl_qty_plan)*$keyPlanM->bobot_planning;
$totalBCWP += (((($keyPlanM->persentase_progress*$keyPlanM->bobot_planning)/100)/$keyPlanM->duration)* $totalRencanaBudget)/100;
$dataTempPlan [$x]['totalBCWP'] = $totalBCWP;
$dataTempPlan[$x]['activity_id'] = $keyPlanM->activity_id;
$dataTempPlan[$x]['qty_plan'] = $keyPlanM->qty_planning;
$dataTempPlan[$x]['plan_date'] = $keyPlanM->plan_date;
$dataTempPlan[$x]['start_activity'] = $keyPlanM->start_activity;
$dataTempPlan[$x]['bobot_planning'] = $keyPlanM->bobot_planning;
$dataTempPlan[$x]['ttl_plan'] = $sumVolPlan->ttl_qty_plan;
$dataTempPlan[$x]['biaya_actual'] = $keyPlanM->biaya_actual;
$dataTempPlan[$x]['duration'] = $keyPlanM->duration;
$dataTempPlan[$x]['persentase_progress'] = $keyPlanM->persentase_progress;
$dataTempPlan[$x]['percentage'] = ($keyPlanM->qty_planning / $sumVolPlan->ttl_qty_plan) * $keyPlanM->bobot_planning;
$sumPercentagePlan += ($keyPlanM->qty_planning / $sumVolPlan->ttl_qty_plan) * $keyPlanM->bobot_planning;
$totalBCWP += (((($keyPlanM->persentase_progress * $keyPlanM->bobot_planning) / 100) / $keyPlanM->duration) * $totalRencanaBudget) / 100;
$dataTempPlan[$x]['totalBCWP'] = $totalBCWP;
$x++;
}
$w = 0;
$dataTempReport = [];
$sumPercentageActual=0;
$sumPercentageActual = 0;
foreach ($dataActualM as $keyActualM) {
$sumVolActual = DB::table('assign_material_to_activity')
->select('activity_id', DB::raw('SUM(qty_planning) as ttl_qty_plan'))
->where('activity_id', '=', $keyActualM->activity_id)
->groupBy('activity_id')
->first();
$dataTempReport [$w]['activity_id'] = $keyActualM->activity_id;
$dataTempReport [$w]['qty'] = $keyActualM->qty;
$dataTempReport [$w]['report_date'] = $keyActualM->report_date;
$dataTempReport [$w]['bobot_planning'] = $keyActualM->bobot_planning;
$dataTempReport [$w]['ttl_plan'] = $sumVolActual->ttl_qty_plan;
$dataTempReport [$w]['biaya_actual'] = $keyActualM->biaya_actual;
$dataTempReport [$w]['duration'] = $keyActualM->duration;
$dataTempReport [$w]['persentase_progress'] = $keyActualM->persentase_progress;
$dataTempReport [$w]['percentage'] = ($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning;
$sumPercentageActual+=($keyActualM->qty/$sumVolActual->ttl_qty_plan)*$keyActualM->bobot_planning;
$totalACWP += $keyActualM->biaya_actual/$keyActualM->duration;
$dataTempReport [$w]['totalacwp'] = $totalACWP;
$dataTempReport[$w]['activity_id'] = $keyActualM->activity_id;
$dataTempReport[$w]['qty'] = $keyActualM->qty;
$dataTempReport[$w]['report_date'] = $keyActualM->report_date;
$dataTempReport[$w]['bobot_planning'] = $keyActualM->bobot_planning;
$dataTempReport[$w]['ttl_plan'] = $sumVolActual->ttl_qty_plan;
$dataTempReport[$w]['biaya_actual'] = $keyActualM->biaya_actual;
$dataTempReport[$w]['duration'] = $keyActualM->duration;
$dataTempReport[$w]['persentase_progress'] = $keyActualM->persentase_progress;
$dataTempReport[$w]['percentage'] = ($keyActualM->qty / $sumVolActual->ttl_qty_plan) * $keyActualM->bobot_planning;
$sumPercentageActual += ($keyActualM->qty / $sumVolActual->ttl_qty_plan) * $keyActualM->bobot_planning;
$totalACWP += $keyActualM->biaya_actual / $keyActualM->duration;
$dataTempReport[$w]['totalacwp'] = $totalACWP;
$w++;
}
$arr_ActualM[] = array(
'date'=>$dt->format("Y-m-d"),
'percentPlan'=>$sumPercentagePlan,
'percentActual'=>$sumPercentageActual,
'plan'=>$dataTempPlan,
'actual'=>$dataTempReport,
'date' => $dt->format("Y-m-d"),
'percentPlan' => $sumPercentagePlan,
'percentActual' => $sumPercentageActual,
'plan' => $dataTempPlan,
'actual' => $dataTempReport,
);
if(isset($dataPayload['period']) && $dataPayload['period'] == 'week'){
if($dt->format("w")==1){
if($totalACWP > 0 ){
if (isset($dataPayload['period']) && $dataPayload['period'] == 'week') {
if ($dt->format("w") == 1) {
if ($totalACWP > 0) {
$budgetControlACWP = $currentACWP + $totalACWP;
}
if($totalBCWP > 0 ){
if ($totalBCWP > 0) {
$budgetControlBCWP = $currentBCWP + $totalBCWP;
}
$tempTtlPercentPlan+= $sumPercentagePlan;
$tempTtlPercentActual+= $sumPercentageActual;
$tempTtlPercentPlan += $sumPercentagePlan;
$tempTtlPercentActual += $sumPercentageActual;
$currentACWP += $totalACWP;
$currentBCWP += $totalBCWP;
$tempPercentage[] = array(round($tempTtlPercentPlan,2), round($tempTtlPercentActual,2));
$tempPercentage[] = array(round($tempTtlPercentPlan, 2), round($tempTtlPercentActual, 2));
$tempDate[] = array($dt->format("Y-m-d"), 0, 0);
}else if($dt->format("Y-m-d") == $end2->format("Y-m-d")) {
$tempTtlPercentPlan+= $sumPercentagePlan;
$tempTtlPercentActual+= $sumPercentageActual;
} else if ($dt->format("Y-m-d") == $end2->format("Y-m-d")) {
$tempTtlPercentPlan += $sumPercentagePlan;
$tempTtlPercentActual += $sumPercentageActual;
$currentACWP += $totalACWP;
$currentBCWP += $totalBCWP;
$tempPercentage[] = array(round($tempTtlPercentPlan,2), round($tempTtlPercentActual,2));
$tempPercentage[] = array(round($tempTtlPercentPlan, 2), round($tempTtlPercentActual, 2));
$tempDate[] = array($dt->format("Y-m-d"), 0, 0);
$tempTtlPercentPlan = 0;
$tempTtlPercentActual = 0;
}
}else{
$tempPercentage[] = array(round($sumPercentagePlan,2), round($sumPercentageActual,2));
} else {
$tempPercentage[] = array(round($sumPercentagePlan, 2), round($sumPercentageActual, 2));
$tempDate[] = array($dt->format("Y-m-d"), 0, 0);
}
}
if(round($totalACWP,0) > $totalRencanaBudget){
$estimatedCost = round($totalACWP,0)+0;
}else{
$estimatedCost = ($totalRencanaBudget+0);
if (round($totalACWP, 0) > $totalRencanaBudget) {
$estimatedCost = round($totalACWP, 0) + 0;
} else {
$estimatedCost = ($totalRencanaBudget + 0);
}
$costDeviation = $totalRencanaBudget - $estimatedCost;
if($costDeviation > 0){
if ($costDeviation > 0) {
$potential = "SAVING";
} else {
$potential = $costDeviation == 0 ? "ON BUDGET" : "OVERRUN";
}
$dataResponse = array(
"date" =>$tempDate,
"percentage" =>$tempPercentage,
"data_details" =>$arr_ActualM,
"budget_control" =>array("current_budget"=> $totalRencanaBudget,
"acwp" => round($totalACWP,0),
"bcwp" => round($totalBCWP,0),
"rem_to_complete" => ($totalRencanaBudget - round($totalACWP,0)),
"date" => $tempDate,
"percentage" => $tempPercentage,
"data_details" => $arr_ActualM,
"budget_control" => array(
"current_budget" => $totalRencanaBudget,
"acwp" => round($totalACWP, 0),
"bcwp" => round($totalBCWP, 0),
"rem_to_complete" => ($totalRencanaBudget - round($totalACWP, 0)),
"add_cost_to_complete" => 0,
"estimated_at_completion" => $estimatedCost,
"cost_deviation" => $costDeviation,
@ -707,12 +803,12 @@ class ActivityController extends Controller
)
);
$dataFinal[] = array(
"proyek_name"=> $dataProject->nama,
"data"=>$dataResponse,
"allGant"=>$allGantt
"proyek_name" => $dataProject->nama,
"data" => $dataResponse,
"allGant" => $allGantt
);
}
return response()->json(['status'=>'success','code'=>200, 'data' => $dataFinal], 200);
return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataFinal], 200);
}
public function import(Request $request)
@ -729,34 +825,35 @@ class ActivityController extends Controller
public function uploadTmpImport(Request $request)
{
if($request->hasFile('dokumen')){
if ($request->hasFile('dokumen')) {
$document = $request->file('dokumen');
$gantt_id = $request->gantt_id;
$name = $document->getClientOriginalName();
$result = $document->move($this->pathTmpImport, $name);
if($result){
if ($result) {
$data = [
'gantt_id' => (int)$gantt_id,
'gantt_id' => (int) $gantt_id,
'file' => $name,
'type_dokumen' => $request->type_dokumen
];
$result = TmpImport::create($data);
if(!$result){
unlink($this->pathTmpImport.$name);
return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500);
if (!$result) {
unlink($this->pathTmpImport . $name);
return response()->json(['status' => 'failed', 'message' => 'Upload failed!', 'code' => 500], 500);
}
return response()->json(['status'=>'success','message'=>'Upload successful!','code'=>200], 200);
return response()->json(['status' => 'success', 'message' => 'Upload successful!', 'code' => 200], 200);
}
return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500);
return response()->json(['status' => 'failed', 'message' => 'Upload failed!', 'code' => 500], 500);
}
return response()->json(['status'=>'failed','message'=>'File is required!','code'=>400], 400);
return response()->json(['status' => 'failed', 'message' => 'File is required!', 'code' => 400], 400);
}
public function importUpdate(Request $request) {
public function importUpdate(Request $request)
{
$data = $request->all();
foreach ($data as $value) {
$activity = Activity::find($value['id']);
@ -765,6 +862,6 @@ class ActivityController extends Controller
$activity->end_date = $value['end_date'];
$activity->save();
}
return response()->json(['status'=>'success','data'=>$request,'message'=>'Update successful!','code'=>200], 200);
return response()->json(['status' => 'success', 'data' => $request, 'message' => 'Update successful!', 'code' => 200], 200);
}
}

153
app/Http/Controllers/BroadcastController.php

@ -3,7 +3,160 @@
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Broadcast;
use App\Models\User;
use App\Services\FCMService;
class BroadcastController extends Controller
{
public function add(Request $request)
{
$data = $request->all();
$data['status_send'] = true;
$data['created_by'] = $this->currentName;
// dd($data);
$result = Broadcast::create($data);
if($result){
$this->sendNotification($data);
return response()->json(['status'=>'success','message'=>'add broadcast successfully!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'add broadcast failed!','code'=>400], 400);
}
}
public function edit($id){
if(!$id || (int) $id < 0 || $id==""){
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
die();
}
$result = Broadcast::find($id);
if($result){
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200);
}else{
return response()->json(['status'=>'failed','message'=>'failed get data broadcast, please try again later!','code'=>400], 400);
}
}
public function update(Request $request, $id)
{
if(!$id || (int) $id < 0 || $id==""){
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
}
$data = Broadcast::find($id);
if($data){
$result = $data->update($request->all());
}else{
return response()->json(['status'=>'failed','message'=>'data broadcast not found!','code'=>400], 400);
die();
}
if($result){
return response()->json(['status'=>'success','message'=>'data broadcast successfully updated!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'data broadcast failed updated!','code'=>400], 400);
}
}
public function delete($id)
{
$data = Broadcast::find($id);
if($data){
$delete = $data->delete();
}else{
return response()->json(['status'=>'failed','message'=>'data broadcast not found!','code'=>400], 400);
die();
}
if($delete){
return response()->json(['status'=>'success','message'=>'data broadcast successfully deleted!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'data broadcast failed deleted!','code'=>400], 400);
}
}
public function search(Request $request)
{
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'm_broadcast');
$builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count'];
$dataGet = $builder->get();
$totalRecord = $countBuilder->count();
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
}
public function list()
{
$data = Broadcast::all();
$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 broadcast, please try again later!','code'=>400], 400);
}
}
public function sendNotification($data)
{
// send_to_type (all, roles, user)
if (isset($data['send_to_type'])) {
switch ($data['send_to_type']) {
case 'all':
$users = User::whereNotNull('fcm_token')->get();
if (isset($users)) {
foreach ($users as $user) {
FCMService::send(
$user->fcm_token,
[
'title' => $data['title_notif'],
'body' => $data['message_notif'],
]
);
}
}
break;
case 'roles':
$users = User::where("role_id", $data['send_to_id'])->whereNotNull('fcm_token')->get();
if (isset($users)) {
foreach ($users as $user) {
FCMService::send(
$user->fcm_token,
[
'title' => $data['title_notif'],
'body' => $data['message_notif'],
]
);
}
}
break;
case 'user':
$user = User::where("id", $data['send_to_id'])->whereNotNull('fcm_token')->first();
if (isset($user)) {
FCMService::send(
$user->fcm_token,
[
'title' => $data['title_notif'],
'body' => $data['message_notif'],
]
);
}
break;
default:
# code...
break;
}
}
}
}

194
app/Http/Controllers/Controller.php

@ -1,27 +1,23 @@
<?php
namespace App\Http\Controllers;
use App\Models\Activity;
use App\Models\UserToProyek;
use App\Models\AssignMaterial;
use App\Models\ReportK3Detail;
use App\Models\UserToActivity;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Http;
use App\Models\UserToActivity;
use App\Models\Activity;
use App\Models\AssignMaterial;
use Laravel\Lumen\Routing\Controller as BaseController;
use App\Models\ReportK3Detail;
class Controller extends BaseController
{
protected $pathImage = "assets/image/";
protected $pathDocument = "assets/file/project/";
protected $pathTmpImport = "assets/file/tmpimport/";
protected $pathActivityDocument = "assets/file/activity/";
protected $listJoinAll = [
'first', 'second', 'third', 'fourth', 'fifth',
'sixth', 'seventh', 'eighth', 'ninth', 'tenth'
];
protected $listJoinAll = ['first', 'second', 'third', 'fourth', 'fifth',
'sixth', 'seventh', 'eighth', 'ninth', 'tenth'];
protected $currentDate;
protected $currentName;
protected $currentId;
@ -40,34 +36,41 @@ class Controller extends BaseController
protected function setUpPayload($condition, $tableSelf)
{
$alias = "selfTable";
$builder = DB::table($tableSelf . " AS " . $alias);
$builder = $builder->select($alias . ".*");
if ($condition) {
if (isset($condition['joins'])) {
$builder = DB::table($tableSelf." AS ".$alias);
// $builder = $builder->select($alias.".*");
if($condition){
if(isset($condition['select'])){
foreach($condition['select'] as $select){
$builder = $builder->addSelect($alias.".".$select);
}
}else{
$builder = $builder->addSelect($alias.".*");
}
if(isset($condition['joins'])){
$selectColumn = [];
$no = 0;
foreach ($condition['joins'] as $join) {
foreach($condition['joins'] as $join){
$tableJoin = isset($join['name1']) ? $join['name1'] : $alias;
$tableName = $join['name'];
$columnJoin = $join['column_join']; // foreign key table sini
$columnSelf = isset($join['column_self']) ? $join['column_self'] : "id"; // primary key table lawan
$columnResult = $join['column_results'];
foreach ($columnResult as $sColumn) {
$builder = $builder->addSelect($tableName . "." . $sColumn . " as join_" . $this->listJoinAll[$no] . "_" . $sColumn);
foreach($columnResult as $sColumn){
$builder = $builder->addSelect($tableName.".".$sColumn." as join_".$this->listJoinAll[$no]."_".$sColumn);
}
$builder = $builder->leftJoin($tableName, $tableJoin . "." . $columnJoin, '=', $tableName . '.' . $columnSelf);
$builder = $builder->leftJoin($tableName, $tableJoin.".".$columnJoin, '=', $tableName.'.'.$columnSelf);
$no++;
}
}
if (isset($condition['columns'])) {
if(isset($condition['columns'])){
$listWhere = $condition['columns'];
$builder = $builder->where(function ($query) use ($listWhere, $alias) {
foreach ($listWhere as $where) {
$builder = $builder->where(function ($query) use($listWhere, $alias){
foreach($listWhere as $where){
$value = $where['value'];
if ($value && $value != "" && $value != " ") {
if($value && $value!="" && $value!=" "){
$column = $where['name'];
$operator = strtolower($where['logic_operator']); // like, =, <>, range
$value2 = isset($where['value1']) ? $where['value1'] : "";
@ -78,22 +81,22 @@ class Controller extends BaseController
});
}
if (isset($condition['group_column'])) {
if(isset($condition['group_column'])){
$builder = $this->groupWhere($builder, $condition['group_column'], $alias);
}
$data['count'] = clone $builder;
if (isset($condition['paging'])) {
if(isset($condition['paging'])){
$builder = $builder->offset($condition['paging']['start'])->limit($condition['paging']['length']);
}
if (isset($condition['orders'])) {
if(isset($condition['orders'])){
$orders = $condition['orders'];
$sortBy = $orders['ascending'] ? "ASC" : "DESC";
$columnOrder = $orders['columns'];
foreach ($columnOrder as $column) {
$builder = $builder->orderBy($alias . "." . $column, $sortBy);
foreach($columnOrder as $column){
$builder = $builder->orderBy($alias.".".$column, $sortBy);
}
}
}
@ -108,8 +111,8 @@ class Controller extends BaseController
$operator = $listGroupWhere['operator'];
$operatorGroup = $listGroupWhere['group_operator'];
$listWhere = $listGroupWhere['where'];
if (strtolower($operator) == "and") {
$builder = $builder->where(function ($query) use ($operatorGroup, $listWhere, $alias) {
if(strtolower($operator)=="and"){
$builder = $builder->where(function($query) use($operatorGroup, $listWhere, $alias){
$no = 1;
foreach ($listWhere as $where) {
$value = $where['value'];
@ -117,22 +120,22 @@ class Controller extends BaseController
$operator = strtolower($where['logic_operator']);
$value2 = isset($where['value1']) ? $where['value1'] : "";
$tableColumn = isset($where['table_name']) ? $where['table_name'] : $alias;
if ($value && $value != "" && $value != " ") {
if ($operatorGroup == "and") {
if($value && $value!="" && $value!=" "){
if($operatorGroup=="and"){
$query = $this->whereCondition($query, $operator, $tableColumn, $column, $value, $value2);
} else {
if ($no == 1) {
}else{
if($no==1){
$query = $this->whereCondition($query, $operator, $tableColumn, $column, $value, $value2);
} else {
}else{
$query = $this->orWhereCondition($query, $operator, $tableColumn, $column, $value, $value2);
}
}
}
$no = $no + 1;
$no = $no+1;
}
});
} else if (strtolower($operator) == "or") {
$builder = $builder->orWhere(function ($query) use ($operatorGroup, $listWhere, $alias) {
}else if(strtolower($operator)=="or"){
$builder = $builder->orWhere(function($query) use($operatorGroup, $listWhere, $alias){
$no = 1;
foreach ($listWhere as $where) {
$value = $where['value'];
@ -140,13 +143,13 @@ class Controller extends BaseController
$operator = strtolower($where['logic_operator']);
$value2 = isset($where['value1']) ? $where['value1'] : "";
$tableColumn = isset($where['table_name']) ? $where['table_name'] : $alias;
if ($value && $value != "" && $value != " ") {
if ($operatorGroup == "and") {
if($value && $value!="" && $value!=" "){
if($operatorGroup=="and"){
$query = $this->whereCondition($query, $operator, $tableColumn, $column, $value, $value2);
} else {
if ($no == 1) {
}else{
if($no==1){
$query = $this->whereCondition($query, $operator, $tableColumn, $column, $value, $value2);
} else {
}else{
$query = $this->orWhereCondition($query, $operator, $tableColumn, $column, $value, $value2);
}
}
@ -161,40 +164,39 @@ class Controller extends BaseController
private function whereCondition($oldQuery, $operator, $tableColumn, $column, $value, $value2)
{
$query = $oldQuery;
if ($operator == "range") {
$query = $query->whereBetween($tableColumn . "." . $column, [$value, $value2]);
} else if ($operator == "like") {
$query = $query->where($tableColumn . "." . $column, 'like', '%' . $value . '%');
} else if ($operator == "ilike") {
$query = $query->where($tableColumn . "." . $column, '~*', $value);
} else if ($operator == "=") {
$query = $query->where($tableColumn . "." . $column, $value);
} else if ($operator == "in") {
$query = $query->whereIn($tableColumn . "." . $column, $value);
} else if ($operator == "notin") {
$query = $query->whereNotIn($tableColumn . "." . $column, $value);
} else {
$query = $query->where($tableColumn . "." . $column, $operator, $value);
if($operator=="range"){
$query = $query->whereBetween($tableColumn.".".$column, [$value, $value2]);
}else if($operator=="like"){
$query = $query->where($tableColumn.".".$column, 'like', '%'.$value.'%');
}else if($operator=="ilike"){
$query = $query->where($tableColumn.".".$column, '~*', $value);
}else if($operator=="="){
$query = $query->where($tableColumn.".".$column, $value);
}else if($operator=="in"){
$query = $query->whereIn($tableColumn.".".$column, $value);
}else if($operator=="notin"){
$query = $query->whereNotIn($tableColumn.".".$column, $value);
}else{
$query = $query->where($tableColumn.".".$column, $operator, $value);
}
return $query;
}
private function whereConditionSingleTable($oldQuery, $operator, $column, $value, $value2)
{
private function whereConditionSingleTable($oldQuery, $operator, $column, $value, $value2){
$query = $oldQuery;
if ($operator == "range") {
if($operator=="range"){
$query = $query->whereBetween($column, [$value, $value2]);
} else if ($operator == "like") {
$query = $query->where($column, 'like', '%' . $value . '%');
} else if ($operator == "ilike") {
}else if($operator=="like"){
$query = $query->where($column, 'like', '%'.$value.'%');
}else if($operator=="ilike"){
$query = $query->where($column, '~*', $value);
} else if ($operator == "=") {
}else if($operator=="="){
$query = $query->where($column, $value);
} else if ($operator == "in") {
}else if($operator=="in"){
$query = $query->whereIn($column, $value);
} else if ($operator == "notin") {
}else if($operator=="notin"){
$query = $query->whereNotIn($column, $value);
} else {
}else{
$query = $query->where($column, $operator, $value);
}
return $query;
@ -203,26 +205,25 @@ class Controller extends BaseController
private function orWhereCondition($oldQuery, $operator, $tableColumn, $column, $value, $value2)
{
$query = $oldQuery;
if ($operator == "range") {
$query = $query->orWhereBetween($tableColumn . "." . $column, [$value, $value2]);
} else if ($operator == "like") {
$query = $query->orWhere($tableColumn . "." . $column, 'like', '%' . $value . '%');
} else if ($operator == "ilike") {
$query = $query->where($tableColumn . "." . $column, '~*', $value);
} else if ($operator == "=") {
$query = $query->orWhere($tableColumn . "." . $column, $value);
} else if ($operator == "in") {
$query = $query->orWhereIn($tableColumn . "." . $column, $value);
} else if ($operator == "notin") {
$query = $query->orWhereNotIn($tableColumn . "." . $column, $value);
} else {
$query = $query->orWhere($tableColumn . "." . $column, $operator, $value);
if($operator=="range"){
$query = $query->orWhereBetween($tableColumn.".".$column, [$value, $value2]);
}else if($operator=="like"){
$query = $query->orWhere($tableColumn.".".$column, 'like', '%'.$value.'%');
}else if($operator=="ilike"){
$query = $query->where($tableColumn.".".$column, '~*', $value);
}else if($operator=="="){
$query = $query->orWhere($tableColumn.".".$column, $value);
}else if($operator=="in"){
$query = $query->orWhereIn($tableColumn.".".$column, $value);
}else if($operator=="notin"){
$query = $query->orWhereNotIn($tableColumn.".".$column, $value);
}else{
$query = $query->orWhere($tableColumn.".".$column, $operator, $value);
}
return $query;
}
protected function calculateAllCost($activity_id, $proyek_id)
{
protected function calculateAllCost($activity_id, $proyek_id){
$humanCostPlanning = $this->calculateAllHumanCost($activity_id, $proyek_id);
$materialCostPlanning = $this->calculateMaterialCost($activity_id, $proyek_id);
$toolsCostPlanning = 0;
@ -233,7 +234,7 @@ class Controller extends BaseController
private function calculateAllHumanCost($activity_id, $proyek_id)
{
$dataHuman = UserToActivity::select("ahp.standart_rate as standart_rate", "ahp.max_used as max_used", "ahp.cost_per_used as cost_per_used", "ahp.uom_standart_rate as uom_standart_rate")
$dataHuman = UserToActivity::select("ahp.standart_rate as standart_rate","ahp.max_used as max_used", "ahp.cost_per_used as cost_per_used", "ahp.uom_standart_rate as uom_standart_rate")
->leftJoin("assign_hr_to_proyek as ahp", "assign_hr_to_activity.user_id", "=", "ahp.user_id")
->where("assign_hr_to_activity.activity_id", $activity_id)->where("assign_hr_to_activity.proyek_id", $proyek_id)
->where("ahp.proyek_id", $proyek_id)
@ -252,12 +253,12 @@ class Controller extends BaseController
$activity = Activity::find($activity_id);
$duration = $activity->duration;
$standarRate = $human->standart_rate;
$maxUsed = $human->max_used / 100;
$maxUsed = $human->max_used/100;
if ($human->uom_standart_rate == "Hour") {
$totalCost = ($standarRate * 8 * $duration) * $maxUsed;
$totalCost = ($standarRate*8*$duration)*$maxUsed;
return $totalCost;
}
$totalCost = ($standarRate * $duration) * $maxUsed;
$totalCost = ($standarRate*$duration)*$maxUsed;
return $totalCost;
}
@ -270,19 +271,17 @@ class Controller extends BaseController
return $totalCost;
}
protected function getLoc($lat, $lng)
{
protected function getLoc($lat, $lng){
// $response = Http::get(config('api.nominatim') . "/reverse?lat=".$lat."&lon=".$lng."&format=json");
// return $response->json;
$url = config('api.nominatim') . "/reverse?lat=" . $lat . "&lon=" . $lng . "&format=json";
$url = config('api.nominatim') . "/reverse?lat=".$lat."&lon=".$lng."&format=json";
// $token = config('api.adw_token');
$response = $this->curlRequest($url);
return $response;
}
private function curlRequest($url)
{
private function curlRequest($url){
$ch = curl_init();
// $headers = [
// 'Authorization: '.$token
@ -299,14 +298,13 @@ class Controller extends BaseController
return json_decode($response);
}
protected function addDetailK3($dataDetail, $report_id)
{
protected function addDetailK3($dataDetail, $report_id){
foreach ($dataDetail as $value) {
$dataNew = array(
"report_k3_id" => $report_id,
"checklist_k3_id" => $value['checklist_id'],
"name_checklist_k3" => $value['checklist_name'],
"created_by" => $this->currentName
"report_k3_id"=>$report_id,
"checklist_k3_id"=>$value['checklist_id'],
"name_checklist_k3"=>$value['checklist_name'],
"created_by"=>$this->currentName
);
ReportK3Detail::create($dataNew);

133
app/Http/Controllers/DashboardBoDController.php

@ -14,16 +14,18 @@ use Illuminate\Support\Facades\Log;
class DashboardBoDController extends Controller
{
private function interpolateYear($year){
if($year)
$year = '%'.$year.'%';
private function interpolateYear($year)
{
if ($year)
$year = '%' . $year . '%';
return $year;
}
private function curlReq($url, $token){
private function curlReq($url, $token)
{
$ch = curl_init();
$headers = [
'Authorization: '.$token
'Authorization: ' . $token
];
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
@ -37,22 +39,24 @@ class DashboardBoDController extends Controller
return json_decode($response);
}
private function getInvoiceIntegration($search) {
// if(empty($search))
// return response()->json(['status'=>'error', 'message'=>'Empty query string!'], 400);
//
// $url = str_replace("SEARCH", $search, config('api.adw').'/project_cost?project_no=SEARCH');
// $token = config('api.adw_token');
// $response = $this->curlReq($url, $token);
//
// if(@$response->data->project_no == "")
// return null;
//
private function getInvoiceIntegration($search)
{
if(empty($search))
return response()->json(['status'=>'error', 'message'=>'Empty query string!'], 400);
$url = str_replace("SEARCH", $search, config('api.adw').'/project_cost?project_no=SEARCH');
$token = config('api.adw_token');
$response = $this->curlReq($url, $token);
if(@$response->data->project_no == "")
return null;
return $response;
}
// to do
public function getCompanyCashFlow($year = '%') {
public function getCompanyCashFlow($year = '%')
{
$year = $this->interpolateYear($year);
$totalExpenditure = $totalInvoice = $totalPaidInvoice = 0;
@ -66,16 +70,16 @@ class DashboardBoDController extends Controller
$projects = Project::where('mulai_proyek', 'like', $year)
/* ->orWhere('akhir_proyek', 'like', $year) */
->get();
foreach($projects as $project){
foreach ($projects as $project) {
$project->expenses = 0;
$resp = null;
if($project->kode_sortname != ""){
if ($project->kode_sortname != "") {
$resp = $this->getInvoiceIntegration($project->kode_sortname);
/* $resp = $project->kode_sortname; */
$cost = $resp->data->total_cost ?? 0;
$cost = substr($cost, 0, strpos($cost, "."));
$totalExpenditure+= (int) $cost;
$totalExpenditure += (int) $cost;
$totalInvoice += $resp->data->total_invoice_amount ?? 0;
$totalPaidInvoice += $resp->data->total_invoice_paid_amount ?? 0;
}
@ -87,20 +91,21 @@ class DashboardBoDController extends Controller
'total_budget' => (int) $totalBudgets ?? 0,
'total_expenditure' => $totalExpenditure,
'total_invoice' => $totalInvoice,
'total_paid_invoice' => $totalPaidInvoice ,
'total_paid_invoice' => $totalPaidInvoice,
]
], 200);
}
public function getInvoiceOutstanding($year = '%'){
public function getInvoiceOutstanding($year = '%')
{
$year = $this->interpolateYear($year);
$projects = Project::where('mulai_proyek', 'like', $year)
/* ->orWhere('akhir_proyek', 'like', $year) */
->get();
$return = [];
foreach($projects as $project){
foreach ($projects as $project) {
$resp = null;
if($project->kode_sortname != ""){
if ($project->kode_sortname != "") {
$resp = $this->getInvoiceIntegration($project->kode_sortname);
array_push($return, [
'project' => $project->nama,
@ -117,7 +122,8 @@ class DashboardBoDController extends Controller
], 200);
}
public function getTotalProjectPerScheduleHealth($year = '%'){
public function getTotalProjectPerScheduleHealth($year = '%')
{
$year = $this->interpolateYear($year);
$return = [
@ -127,10 +133,10 @@ class DashboardBoDController extends Controller
];
$projects = Project::where('mulai_proyek', 'like', $year)->get();
foreach($projects as $project) {
foreach ($projects as $project) {
$project->scurve = MasterFunctionsHelper::getSCurve($project->id);
$selisihProgress = 0;
if($project->scurve && $project->scurve[0]){
if ($project->scurve && $project->scurve[0]) {
$planningArray = $project->scurve[0]['data']['percentagePlan'];
$actualArray = $project->scurve[0]['data']['percentageReal'];
$planningProgress = !empty($planningArray) ? $planningArray[count($planningArray) - 1] : 0;
@ -138,9 +144,9 @@ class DashboardBoDController extends Controller
}
$selisihProgress = $planningProgress - $actualProgress;
try {
if($selisihProgress > 0 && $selisihProgress <= 5)
if ($selisihProgress > 0 && $selisihProgress <= 5)
$return['warning'] += 1;
elseif($selisihProgress == 0)
elseif ($selisihProgress == 0)
$return['on-schedule'] += 1;
else
$return['behind-schedule'] += 1;
@ -152,23 +158,24 @@ class DashboardBoDController extends Controller
return response()->json(['data' => $return, 'q' => $projects], 200);
}
public function getTotalProjectScheduleHealthPerDivision($year = '%'){
public function getTotalProjectScheduleHealthPerDivision($year = '%')
{
$year = $this->interpolateYear($year);
$divisions = Divisi::whereNull('parent')->get();
foreach($divisions as $division){
foreach ($divisions as $division) {
$scheduleData = new Collection();
$behindSchedule = $warning = $onSchedule = 0;
$projects = Project::where('mulai_proyek', 'like', $year)->where('divisi_id', $division->id)->get();
foreach($projects as $project) {
foreach ($projects as $project) {
$project->scurve = MasterFunctionsHelper::getSCurve($project->id);
if(@$project->scurve['difference'] > 0 && @$project->scurve['difference'] <= 5)
if (@$project->scurve['difference'] > 0 && @$project->scurve['difference'] <= 5)
$warning++;
elseif(@$project->scurve['difference'] > 5 && @$project->scurve['difference'] <= 100)
elseif (@$project->scurve['difference'] > 5 && @$project->scurve['difference'] <= 100)
$behindSchedule++;
elseif(@$project->scurve['difference'] == 0)
elseif (@$project->scurve['difference'] == 0)
$onSchedule++;
}
@ -184,7 +191,8 @@ class DashboardBoDController extends Controller
], 200);
}
public function getTotalProjectPerBudgetHealth($year = '%'){
public function getTotalProjectPerBudgetHealth($year = '%')
{
$year = $this->interpolateYear($year);
return response()->json([
'data' => [
@ -195,7 +203,8 @@ class DashboardBoDController extends Controller
], 200);
}
private function countTotalProjectByBudgetHealthInDivision($divisi, $year, $health){
private function countTotalProjectByBudgetHealthInDivision($divisi, $year, $health)
{
return Project::where('divisi_id', $divisi)
->where('mulai_proyek', 'like', $year)
/* ->orWhere('akhir_proyek', 'like', $year) */
@ -204,19 +213,20 @@ class DashboardBoDController extends Controller
}
public function getTotalProjectBudgetHealthPerDivision($year = '%'){
public function getTotalProjectBudgetHealthPerDivision($year = '%')
{
$year = $this->interpolateYear($year);
$divisions = Divisi::select('id','name')
$divisions = Divisi::select('id', 'name')
->with('children')
->whereNull('parent')
->get();
// to do : count in more than 1 level child
foreach($divisions as $division){
foreach ($divisions as $division) {
$budgetData = new Collection();
$budgetData->prepend($this->countTotalProjectByBudgetHealthInDivision($division->id, $year, 'overrun'), 'overrun');
$budgetData->prepend($this->countTotalProjectByBudgetHealthInDivision($division->id, $year, 'warning'), 'warning');
$budgetData->prepend($this->countTotalProjectByBudgetHealthInDivision($division->id, $year, 'on-budget'), 'on-budget');
foreach($division->children as $d){
foreach ($division->children as $d) {
$budgetData['overrun'] += $this->countTotalProjectByBudgetHealthInDivision($d->id, $year, 'overrun');
$budgetData['warning'] += $this->countTotalProjectByBudgetHealthInDivision($d->id, $year, 'warning');
$budgetData['on-budget'] += $this->countTotalProjectByBudgetHealthInDivision($d->id, $year, 'on-budget');
@ -224,7 +234,7 @@ class DashboardBoDController extends Controller
unset($division->children);
$division->budgetData = $budgetData;
}
foreach($divisions as $division){
foreach ($divisions as $division) {
}
return response()->json([
'data' => [
@ -233,10 +243,11 @@ class DashboardBoDController extends Controller
], 200);
}
public function getTotalProjectPerPhase($year = '%'){
public function getTotalProjectPerPhase($year = '%')
{
$year = $this->interpolateYear($year);
$projectPhases = ProjectPhase::orderBy('order')->get();
foreach($projectPhases as $phase){
foreach ($projectPhases as $phase) {
$phase->totalProject = Project::where('phase_id', $phase->id)
->where('mulai_proyek', 'like', $year)
/* ->orWhere('akhir_proyek', 'like', $year) */
@ -249,24 +260,26 @@ class DashboardBoDController extends Controller
], 200);
}
private function countTotalProjectInDivision($id, $year){
private function countTotalProjectInDivision($id, $year)
{
return Project::where('divisi_id', $id)
->where('mulai_proyek', 'like', $year)
->count();
}
public function getTotalProjectPerDivision($year = '%') {
public function getTotalProjectPerDivision($year = '%')
{
$year = $this->interpolateYear($year);
$divisions = Divisi::select('id','name')
$divisions = Divisi::select('id', 'name')
->with('children')
->whereNull('parent')
->get();
// to do : count in more than 1 level child
foreach($divisions as $v){
foreach ($divisions as $v) {
$v->total = $this->countTotalProjectInDivision($v->id, $year);
foreach($v->children as $d){
foreach ($v->children as $d) {
$v->total += $this->countTotalProjectInDivision($d->id, $year);
}
unset($v->children);
@ -277,7 +290,8 @@ class DashboardBoDController extends Controller
], 200);
}
private function countTotalProjectValueInDivision($id, $year){
private function countTotalProjectValueInDivision($id, $year)
{
return Project::select(DB::raw('SUM(CAST("rencana_biaya" AS DOUBLE PRECISION))'))
->where('mulai_proyek', 'like', $year)
/* ->orWhere('akhir_proyek', 'like', $year) */
@ -286,18 +300,19 @@ class DashboardBoDController extends Controller
->first();
}
public function getTotalProjectValuePerDivision($year = '%') {
public function getTotalProjectValuePerDivision($year = '%')
{
$year = $this->interpolateYear($year);
$divisions = Divisi::select('id','name')
$divisions = Divisi::select('id', 'name')
->with('children')
->whereNull('parent')
->get();
// to do : count in more than 1 level child
foreach($divisions as $v){
foreach ($divisions as $v) {
$v->total = $this->countTotalProjectValueInDivision($v->id, $year);
foreach($v->children as $d){
foreach ($v->children as $d) {
$v->total += $this->countTotalProjectValueInDivision($d->id, $year);
}
unset($v->children);
@ -309,16 +324,17 @@ class DashboardBoDController extends Controller
}
public function getDetailExpenditure($year = '%'){
public function getDetailExpenditure($year = '%')
{
$year = $this->interpolateYear($year);
$projects = Project::where('mulai_proyek', 'like', $year)
/* ->orWhere('akhir_proyek', 'like', $year) */
->orderBy('id', 'desc')
->get();
foreach($projects as $project){
foreach ($projects as $project) {
$lastGantt = MasterFunctionsHelper::getLatestGantt($project->id);
if($project->kode_sortname != ""){
if ($project->kode_sortname != "") {
$resp = $this->getInvoiceIntegration($project->kode_sortname);
$project->invoice = [
'invoiced' => $resp->data->total_invoice_amount ?? 0,
@ -328,7 +344,7 @@ class DashboardBoDController extends Controller
$project->pm = User::find($project->pm_id);
/* $project->header = Activity::where('proyek_id', $project->id)->where('version_gantt_id', $lastGantt['last_gantt_id'])->whereNull('parent_id')->first(); */
if(!isset($lastGantt['last_gantt_id'])){
if (!isset($lastGantt['last_gantt_id'])) {
$project->manPowers = 0;
} else {
$project->manPowers = UserToVersionGantt::where('version_gantt_id', $lastGantt['last_gantt_id'])->count();
@ -343,4 +359,3 @@ class DashboardBoDController extends Controller
], 200);
}
}

27
app/Http/Controllers/HumanResourceController.php

@ -112,7 +112,7 @@ class HumanResourceController extends Controller
public function list()
{
$data = HumanResource::all();
$data = HumanResource::select('id', 'name')->get();
$countData = $data->count();
if($data){
@ -138,11 +138,26 @@ class HumanResourceController extends Controller
}
}
if($search && !empty($search)){
$data = UserToProyek::select("m_users.id as id", "m_users.name as name", "assign_hr_to_proyek.project_role as proyek_role")->join('m_users', 'm_users.id', '=', 'assign_hr_to_proyek.user_id')
->where("assign_hr_to_proyek.proyek_id", $idProyek)->where("m_users.name", 'like', '%'.$search.'%')->whereNotIn("m_users.id", $forbidden)->get();
}else{
$data = UserToProyek::select("m_users.id as id", "m_users.name as name", "assign_hr_to_proyek.project_role as proyek_role")->where("assign_hr_to_proyek.proyek_id", $idProyek)->join('m_users', 'm_users.id', '=', 'assign_hr_to_proyek.user_id')->whereNotIn("m_users.id", $forbidden)->get();
if ($search && !empty($search)) {
$data = UserToProyek::select("m_users.id as id", "m_users.name as name", "assign_hr_to_proyek.project_role as proyek_role")
->join('m_users', 'm_users.id', '=', 'assign_hr_to_proyek.user_id')
->where("assign_hr_to_proyek.proyek_id", $idProyek)
->where(function ($query) {
$query->where("assign_hr_to_proyek.is_customer", "!=", true)
->orWhereNull("assign_hr_to_proyek.is_customer");
})
->where("m_users.name", 'like', '%' . $search . '%')
->whereNotIn("m_users.id", $forbidden)->get();
} else {
$data = UserToProyek::select("m_users.id as id", "m_users.name as name", "assign_hr_to_proyek.project_role as proyek_role")
->where("assign_hr_to_proyek.proyek_id", $idProyek)
->where(function ($query) {
$query->where("assign_hr_to_proyek.is_customer", "!=", true)
->orWhereNull("assign_hr_to_proyek.is_customer");
})
->join('m_users', 'm_users.id', '=', 'assign_hr_to_proyek.user_id')
->whereNotIn("m_users.id", $forbidden)
->get();
}
return response()->json($data);

44
app/Http/Controllers/MapMonitoringController.php

@ -25,14 +25,23 @@ class MapMonitoringController extends Controller
->get();
// get position hr in presensi
$tmp = [];
foreach($hr_assign_project as $key){
foreach ($hr_assign_project as $key) {
$presensi = DB::table('t_clock_in_out as tcio')
->select('tcio.id as clock_in_out_id','mu.id as user_id', 'mu.name as fullname', 'tcio.clock_in', 'tcio.clock_out', 'tcio.clock_in_lat', 'tcio.clock_in_lng',
'tcio.clock_out_lat', 'tcio.clock_out_lng', 'tcio.clock_in_loc', 'tcio.clock_out_loc', 'tcio.clock_in_boundary',
'tcio.clock_out_boundary', 'mu.username', 'tcio.date_presence', 'tcio.created_at')
->select(
'tcio.id as clock_in_out_id',
'mu.id as user_id',
'mu.name as fullname',
'tcio.clock_in',
'tcio.clock_out',
'tcio.clock_in_lat',
'tcio.clock_in_lng',
'tcio.clock_in_loc',
'tcio.clock_out_loc',
'tcio.date_presence'
)
->join('m_users as mu', 'mu.id', '=', 'tcio.user_id')
->where('mu.id', $key->user_id)
->orderBy('tcio.id', 'DESC')
->orderBy('tcio.clock_in', 'DESC')
->first();
$project = DB::table('assign_hr_to_proyek as ahtp')
->select('ahtp.proyek_id as id', 'mp.nama as project_name')
@ -40,31 +49,28 @@ class MapMonitoringController extends Controller
->whereIn('ahtp.proyek_id', $request->project_id)
->where('ahtp.user_id', $key->user_id)
->get();
if($presensi && isset($presensi->user_id)){
if ($presensi && isset($presensi->user_id)) {
$image = DB::table('m_image')->select('image')->where('category', 'presensi')->where('ref_id', $presensi->clock_in_out_id)->first();
$waypoint = DB::table('m_waypoint')->select('lat', 'lon', 'wptime')->where('user_id', $presensi->user_id)->orderBy('wptime', 'DESC')->first();
$tmp[] = array(
'user_id' => $presensi->user_id,
'wp_lat' => isset($waypoint) ? $waypoint->lat : $presensi->clock_in_lat,
'wp_lon' => isset($waypoint) ? $waypoint->lon : $presensi->clock_in_lng,
'wp_time' => isset($waypoint) ? $waypoint->wptime : $presensi->clock_in,
'clock_in' => $presensi->clock_in,
'clock_out' => $presensi->clock_out,
'date_presence' => $presensi->date_presence,
'clock_in_lat' => $presensi->clock_in_lat,
'clock_in_lng' => $presensi->clock_in_lng,
'clock_out_lat' => $presensi->clock_out_lat,
'clock_out_lng' => $presensi->clock_out_lng,
'clock_in_loc' => $presensi->clock_in_loc,
'clock_out_loc' => $presensi->clock_out_loc,
'clock_in_boundary' => $presensi->clock_in_boundary,
'clock_out_boundary' => $presensi->clock_out_boundary,
'username' => $presensi->username,
'name' => $presensi->fullname,
'image_selfie' => isset($image->image) ? $image->image : '-',
'created_at' => $presensi->created_at,
'presence_status' => $presensi->date_presence == $dateNow ? true : false,//true, //status date_presence,
'presence_status' => $presensi->date_presence == $dateNow ? true : false, //true, //status date_presence,
'projects' => $project
);
}
}
return response()->json(['status'=>'success','code'=>200, 'data' => $tmp, 'totalRecord'=>count($tmp)], 200);
return response()->json(['status' => 'success', 'code' => 200, 'data' => $tmp, 'totalRecord' => count($tmp)], 200);
}
public function list()
@ -72,10 +78,10 @@ class MapMonitoringController extends Controller
$data = Presence::all();
$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 presence, 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 presence, please try again later!', 'code' => 400], 400);
}
}

147
app/Http/Controllers/PresenceController.php

@ -2,6 +2,7 @@
namespace App\Http\Controllers;
use App\Models\HumanResource;
use Log;
use Illuminate\Http\Request;
use App\Models\Presence;
@ -24,7 +25,10 @@ class PresenceController extends Controller
if(count($checkLocation) > 0 && $checkLocation[0]['boundary']){
$statusBoundary = true;
}
$statusRestriction = HumanResource::select('status_boundary')->where('id', $request->user_id)->first();
if ($statusRestriction->status_boundary) {
$statusBoundary = true;
}
// not assign
if(!$checkLocation[0]['status_assign'] && $checkLocation[0]['boundary'] == false){
$data=array(
@ -134,7 +138,10 @@ class PresenceController extends Controller
if(count($checkLocation) > 0 && $checkLocation[0]['boundary']){
$statusBoundary = true;
}
$statusRestriction = HumanResource::select('status_boundary')->where('id', $request->user_id)->first();
if ($statusRestriction->status_boundary) {
$statusBoundary = true;
}
// not assign
if(!$checkLocation[0]['status_assign'] && $checkLocation[0]['boundary'] == false){
$data=array(
@ -263,12 +270,148 @@ class PresenceController extends Controller
foreach($geom as $dataGeom){
$valGeom = json_decode($dataGeom->geom);
if($params->clock_in_out['type']=="out"){
if($valGeom->type == "FeatureCollection"){
$multiArea = $valGeom->features;
foreach($multiArea as $area){
if ($area->geometry->type === "Point") {
$pointCoordinates = $area->geometry->coordinates;
$pointLng = $pointCoordinates[0];
$pointLat = $pointCoordinates[1];
$check = DB::select(DB::raw("SELECT ST_Distance(
ST_GeomFromGeoJSON('" . json_encode($area->geometry) . "'),
ST_GeomFromText('POINT(" . $params->clock_in_out['clock_in_lng'] . " " . $params->clock_in_out['clock_in_lat'] . ")', 4326)
) <= " . $area->properties->radius . " as within_radius"));
if ($check[0]->within_radius) {
break;
}
}
$check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($area->geometry)."'),
ST_GeomFromText('POINT(".$params->clock_in_out['clock_out_lng']." ".$params->clock_in_out['clock_out_lat'].")', 4326)) as boundary"));
if($check[0]->boundary){
break;
}
}
}else{
$check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($valGeom->geometry)."'),
ST_GeomFromText('POINT(".$params->clock_in_out['clock_out_lng']." ".$params->clock_in_out['clock_out_lat'].")', 4326)) as boundary"));
}
}else{
if($valGeom->type == "FeatureCollection"){
$multiArea = $valGeom->features;
foreach($multiArea as $area){
if ($area->geometry->type === "Point") {
$pointCoordinates = $area->geometry->coordinates;
$pointLng = $pointCoordinates[0];
$pointLat = $pointCoordinates[1];
$check = DB::select(DB::raw("SELECT ST_Distance(
ST_GeomFromGeoJSON('" . json_encode($area->geometry) . "'),
ST_GeomFromText('POINT(" . $params->clock_in_out['clock_in_lng'] . " " . $params->clock_in_out['clock_in_lat'] . ")', 4326)
) <= " . $area->properties->radius . " as within_radius"));
if ($check[0]->within_radius) {
break;
}
}
$check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($area->geometry)."'),
ST_GeomFromText('POINT(".$params->clock_in_out['clock_in_lng']." ".$params->clock_in_out['clock_in_lat'].")', 4326)) as boundary"));
if($check[0]->boundary){
break;
}
}
}else{
$check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($valGeom->geometry)."'),
ST_GeomFromText('POINT(".$params->clock_in_out['clock_in_lng']." ".$params->clock_in_out['clock_in_lat'].")', 4326)) as boundary"));
}
}
if(count($check)>0){
if(isset($check[0]->boundary) && $check[0]->boundary){
$temp[]=array(
"activity_id" => $dataGeom->id,
"boundary" => $check[0]->boundary,
"status_assign" => true
);
} else if (isset($check[0]->within_radius) && $check[0]->within_radius) {
$temp[]=array(
"activity_id" => $dataGeom->id,
"boundary" => $check[0]->within_radius,
"status_assign" => true
);
}
}
}
// assign and not in boundary
if(count($temp) < 1){
$temp[]=array(
"activity_id" => null,
"boundary" => false,
"status_assign" => true
// "geom" => $geom,
// "cek" => $check[0]->boundary
);
}
}
else{
// not assign
$temp[]=array(
"activity_id" => null,
"boundary" => false,
"status_assign" => false
);
}
return $temp;
}
public function checkLocationTest(Request $request){
// cek user tersebut apakah punya assign task yang ada bondary nya
// geom ada di table activity
// $clock_time =
$params = $request;
$geom = DB::table("assign_hr_to_activity as ahta")->select("ma.geom", "ma.id")
->join("m_activity as ma", "ma.id", "=", "ahta.activity_id")
->where("ahta.user_id", $params->user_id)
->whereNotNull("ma.geom")
->whereDate("ma.start_date", "<=", $params->time)
->whereDate("ma.end_date", ">=", $params->time)
->get();
$temp = [];
// return json_encode($geom);
if (count($geom) > 0) {
foreach($geom as $dataGeom){
$valGeom = json_decode($dataGeom->geom);
if($params->clock_in_out['type']=="out"){
if($valGeom->type == "FeatureCollection"){
// return count($valGeom->features);
$multiArea = $valGeom->features;
foreach($multiArea as $area){
$check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($area->geometry)."'),
ST_GeomFromText('POINT(".$params->clock_in_out['clock_out_lng']." ".$params->clock_in_out['clock_out_lat'].")', 4326)) as boundary"));
if($check[0]->boundary){
break;
}
}
}else{
$check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($valGeom->geometry)."'),
ST_GeomFromText('POINT(".$params->clock_in_out['clock_out_lng']." ".$params->clock_in_out['clock_out_lat'].")', 4326)) as boundary"));
}
}else{
if($valGeom->type == "FeatureCollection"){
// return count($valGeom->features);
$multiArea = $valGeom->features;
foreach($multiArea as $area){
$check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($area->geometry)."'),
ST_GeomFromText('POINT(".$params->clock_in_out['clock_in_lng']." ".$params->clock_in_out['clock_in_lat'].")', 4326)) as boundary"));
if($check[0]->boundary){
break;
}
}
}else{
$check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($valGeom->geometry)."'),
ST_GeomFromText('POINT(".$params->clock_in_out['clock_in_lng']." ".$params->clock_in_out['clock_in_lat'].")', 4326)) as boundary"));
}
}
if(count($check)>0){
if($check[0]->boundary){
$temp[]=array(

497
app/Http/Controllers/ProjectController.php

@ -30,6 +30,7 @@ use Illuminate\Support\Facades\DB;
use App\Helpers\MasterFunctionsHelper;
use App\Models\ReportActivityMaterial;
use Illuminate\Support\Facades\Artisan;
use App\Jobs\ProcessSCurve;
const API_GEOLOCATION = "https://nominatim.oslogdev.com/search/ADDR?format=json&addressdetails=1&limit=1";
@ -50,70 +51,69 @@ class ProjectController extends Controller
$data['created_by'] = $this->currentName;
if (empty($data['phase_id']))
if(empty($data['phase_id']))
$data['phase_id'] = 1;
$result = Project::create($data);
if (!$result)
return response()->json(['status' => 'failed', 'message' => 'Failed to add data!', 'code' => 500], 500);
if(!$result)
return response()->json(['status'=>'failed','message'=>'Failed to add data!','code'=> 500], 500);
$this->createOfficeHours($result->id);
$dataResultInsert = Project::where('nama', $data['nama'])->where('mulai_proyek', $data['mulai_proyek'])->first();
return response()->json(['status' => 'success', 'message' => 'Data added!', 'data_result' => $dataResultInsert, 'code' => 200], 200);
return response()->json(['status'=>'success','message'=>'Data added!', 'data_result' =>$dataResultInsert, 'code'=> 200], 200);
}
public function edit($id)
{
if (empty($id) || !is_int((int)$id))
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
public function edit($id){
if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
$result = Project::find($id);
if (!$result)
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
if(!$result)
return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404);
return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200);
return response()->json(['status'=>'success','code'=> 200,'data'=>$result], 200);
}
public function update(Request $request, $id)
{
if (empty($id) || !is_int((int)$id))
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
$data = Project::find($id);
if (!$data)
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
if(!$data)
return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404);
$result = $data->update($request->all());
if (!$result)
return response()->json(['status' => 'failed', 'message' => 'Failed to update!', 'code' => 500], 500);
if(!$result)
return response()->json(['status'=>'failed','message'=> 'Failed to update!','code'=> 500], 500);
return response()->json(['status' => 'success', 'message' => 'Data updated!', 'code' => 200], 200);
return response()->json(['status'=>'success','message'=>'Data updated!','code' => 200], 200);
}
private function createOfficeHours($proyek_id)
{
$dataCreate = array(
"proyek_id" => $proyek_id,
"monday_start" => "08:00:00",
"monday_end" => "16:00:00",
"tuesday_start" => "08:00:00",
"tuesday_end" => "16:00:00",
"wednesday_start" => "08:00:00",
"wednesday_end" => "16:00:00",
"thursday_start" => "08:00:00",
"thursday_end" => "16:00:00",
"friday_start" => "08:00:00",
"friday_end" => "16:00:00",
"saturday_start" => "08:00:00",
"saturday_end" => "16:00:00",
"sunday_start" => "08:00:00",
"sunday_end" => "16:00:00",
"created_by" => $this->currentName
"proyek_id"=>$proyek_id,
"monday_start"=> "08:00:00",
"monday_end"=> "16:00:00",
"tuesday_start"=> "08:00:00",
"tuesday_end"=> "16:00:00",
"wednesday_start"=> "08:00:00",
"wednesday_end"=> "16:00:00",
"thursday_start"=> "08:00:00",
"thursday_end"=> "16:00:00",
"friday_start"=> "08:00:00",
"friday_end"=> "16:00:00",
"saturday_start"=> "08:00:00",
"saturday_end"=> "16:00:00",
"sunday_start"=> "08:00:00",
"sunday_end"=> "16:00:00",
"created_by"=> $this->currentName
);
OfficeHours::create($dataCreate);
@ -125,15 +125,15 @@ class ProjectController extends Controller
{
$data = Project::find($id);
if (!$data)
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
if(!$data)
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
$this->deleteRelative($id);
if (!$data->delete())
return response()->json(['status' => 'failed', 'message' => 'Delete failed!', 'code' => 500], 500);
if(!$data->delete())
return response()->json(['status'=>'failed','message'=>'Delete failed!','code'=> 500], 500);
return response()->json(['status' => 'success', 'message' => 'Data deleted!', 'code' => 200], 200);
return response()->json(['status'=>'success','message'=>'Data deleted!','code'=>200], 200);
}
private function deleteRelative($project_id)
@ -159,16 +159,16 @@ class ProjectController extends Controller
foreach ($dataRa as $ra) {
$images = Image::where("ref_id", $ra->id)->where("category", "report_activity")->get();
foreach ($images as $image) {
if (file_exists($this->pathImage . $image->image)) {
unlink($this->pathImage . $image->image);
if(file_exists($this->pathImage.$image->image)){
unlink($this->pathImage.$image->image);
}
}
Image::where("ref_id", $ra->id)->where("category", "report_activity")->delete();
}
$dataAd = ActivityDokumen::whereIn("activity_id", $activityIds)->get();
foreach ($dataAd as $ad) {
if (file_exists($this->pathActivityDocument . $ad->file)) {
unlink($this->pathActivityDocument . $ad->file);
if(file_exists($this->pathActivityDocument.$ad->file)){
unlink($this->pathActivityDocument.$ad->file);
}
}
ActivityDokumen::whereIn("activity_id", $activityIds)->delete();
@ -186,8 +186,8 @@ class ProjectController extends Controller
$dataDokumen = DokumenProject::where("type_dokumen", "project-document-out-folder")->where('ref_id', $project_id)->get();
foreach ($dataDokumen as $dokumen) {
if (file_exists($this->pathDocument . $dokumen->file)) {
unlink($this->pathDocument . $dokumen->file);
if(file_exists($this->pathDocument.$dokumen->file)){
unlink($this->pathDocument.$dokumen->file);
}
}
DokumenProject::where("type_dokumen", "project-document-out-folder")->where('ref_id', $project_id)->delete();
@ -196,33 +196,14 @@ class ProjectController extends Controller
$ref_ids = $dataFolder->all();
$dataDokumen = DokumenProject::where("type_dokumen", "project-document-in-folder")->whereIn('ref_id', $ref_ids)->get();
foreach ($dataDokumen as $dokumen) {
if (file_exists($this->pathDocument . $dokumen->file)) {
unlink($this->pathDocument . $dokumen->file);
if(file_exists($this->pathDocument.$dokumen->file)){
unlink($this->pathDocument.$dokumen->file);
}
}
DokumenProject::where("type_dokumen", "project-document-in-folder")->whereIn('ref_id', $ref_ids)->delete();
}
public function getByUser($id)
{
$alias = "utp";
$userProyek = UserToProyek::query()
->from('assign_hr_to_proyek AS ' . $alias)
->where([
['is_customer', true],
['user_id', $id]
])
->leftJoin('m_users', $alias.'.user_id', '=', 'm_users.id')
->leftJoin('m_proyek', $alias.'.proyek_id', '=', 'm_proyek.id')
->leftJoin('m_type_proyek', 'm_proyek.type_proyek_id', '=', 'm_type_proyek.id')
->select('m_proyek.*', 'm_type_proyek.name AS join_second_name','m_users.name AS join_first_name')
->get();
$totalRecord = $userProyek->count();
return response()->json(['status' => 'success', 'code' => 200, 'data' => $userProyek, 'totalRecord' => $totalRecord], 200);
}
public function search(Request $request)
{
$payload = $request->all();
@ -233,64 +214,53 @@ class ProjectController extends Controller
$dataGet = $builder->get();
$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()
{
$data = Project::orderBy('id', 'desc')->get();
$data = Project::select(
'id',
'kode_sortname',
'jumlah_stakeholder',
'nama',
'mulai_proyek',
'akhir_proyek',
'area_kerja',
'lokasi_kantor',
'rencana_biaya',
'biaya_actual',
'company',
'pm_id',
'type_proyek_id',
'divisi_id',
'persentase_progress',
'keterangan',
'durasi_proyek',
'progress_by_worklog',
'status',
'currency_symbol',
'currency_code',
'currency_name',
'project_objectives',
'considered_success_when',
'potential_risk',
'testing_environment',
'currency_code',
'currency_symbol',
'currency_name',
'budget_health',
'phase_id',
'calculation_status',
'created_at',
'created_by',
'updated_at',
'updated_by'
)->orderBy('id', 'desc')->get();
$countData = $data->count();
if (!$data)
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
$scheduleWarningThreshold = 10;
$scheduleDangerThreshold = 5;
foreach ($data as $d) {
$progress = $costVariance = $actualCost = 0;
$lastActivity = null;
$scheduleHealth = "on-track";
$rootActivity = Activity::whereNull('parent_id')->where('proyek_id', $d->id)->orderBy('version_gantt_id', 'desc')->first();
if ($rootActivity) {
$costVariance = (int)$d->rencana_biaya - (int)$rootActivity->biaya_actual;
$actualCost = $rootActivity->biaya_actual ?? 0;
$progress = $rootActivity->persentase_progress ?? 0;
$timeleft = strtotime($d->mulai_proyek) - strtotime($rootActivity->end_date);
$date1 = new \DateTime(date("Y-m-d", strtotime($d->mulai_proyek)));
$date2 = new \DateTime(date("Y-m-d", strtotime($rootActivity->end_date)));
$daysRemaining = $date2->diff($date1);
$daysRemaining = $daysRemaining->d;
if ($daysRemaining <= $scheduleDangerThreshold) {
$scheduleHealth = "danger";
} elseif ($daysRemaining <= $scheduleWarningThreshold) {
$scheduleHealth = "warning";
}
$lastActivity = date("d/m/Y", strtotime($rootActivity->end_date));
}
$d->plannedInterval = date("d/m/Y", strtotime($d->mulai_proyek)) . " - " . date("d/m/Y", strtotime($d->akhir_proyek));
$d->plannedCost = $d->rencana_biaya;
$d->actualCost = $actualCost;
$d->lastActivity = $lastActivity ?? "-";
$d->costVariance = $costVariance;
$d->costHealth = $d->budget_health;
$d->scheduleHealth = $scheduleHealth;
$d->progress = $progress;
$d->lastGanttId = VersionGantt::where("proyek_id", $d->id)->orderBy('id', 'desc')->first()->id ?? null;
$d->manpower = UserToProyek::where("proyek_id", $d->id)->count() ?? 0;
$d->projectManager = DB::table('m_proyek')
->join('m_users', 'm_users.id', '=', 'm_proyek.pm_id')
->where('m_proyek.id', $d->id)
->pluck('m_users.name')
->first();
if ($d->area_kerja != '') {
$d->geolocation = $this->httpReq($d->area_kerja);
$d->geolocation = [];
} else {
$d->geolocation = [];
}
}
if(!$data)
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
$totalPlannedCost = array_sum(array_map('intval', array_column($data->toArray(), 'plannedCost')));
$totalActualCost = $data->sum('actualCost');
@ -309,7 +279,7 @@ class ProjectController extends Controller
}
try {
$projectsByType = DB::table('m_proyek')
->select('m_type_proyek.name', DB::raw('count(*) as total'))
->select('m_type_proyek.name', DB::raw('count(m_type_proyek.id) as total'))
->join('m_type_proyek', 'm_type_proyek.id', '=', 'm_proyek.type_proyek_id')
->groupBy('m_type_proyek.name')
->get();
@ -319,61 +289,86 @@ class ProjectController extends Controller
return response()->json(
[
'status' => 'success',
'code' => 200,
'data' => $data,
'totalRecord' => $countData,
'status'=>'success',
'code'=>200,
'data'=>$data,
'totalRecord'=>$countData,
'totalPlannedCost' => $totalPlannedCost,
'totalActualCost' => $totalActualCost,
'totalRevenue' => $totalPlannedCost - $totalActualCost,
'manpowers' => $manpowers,
'projectsOnDanger' => $projectsOnDanger,
'projectsOnDanger'=> $projectsOnDanger,
'projectPhases' => $projectPhases,
'projectsByPhase' => $projectsByPhase,
'projectTypes' => $projectTypes,
'projectsByType' => $projectsByType,
],
200
);
], 200);
}
public function getListProjectTask($id)
{
$data = UserToActivity::select("assign_hr_to_activity.user_id as user_id", "m_proyek.*")
public function getListProjectTask($id){
$data = UserToActivity::select("assign_hr_to_activity.user_id as user_id","m_proyek.*")
->where("assign_hr_to_activity.user_id", $id)
->join('m_proyek', 'assign_hr_to_activity.proyek_id', '=', 'm_proyek.id')
->groupBy("m_proyek.proyek_id")
->get();
if (!$data)
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
if(!$data)
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
return response()->json(['status' => 'success', 'code' => 200, 'data' => $data], 200);
return response()->json(['status'=>'success','code'=>200,'data'=>$data], 200);
}
public function getSCurve(Request $request)
{
public function getSCurve(Request $request){
$data = MasterFunctionsHelper::getSCurve($request);
return response()->json(['status' => 'success', 'code' => 200, 'data' => $data], 200);
return response()->json(['status'=>'success','code'=>200, 'data' => $data], 200);
}
public function calculateSCurve(Request $request)
{
public function calculateSCurve(Request $request){
$sCurve = Project::select('scurve')->where('id', $request->project_id)->first();
return response()->json(['status' => 'success', 'code' => 200, 'data' => json_decode($sCurve->scurve)], 200);
return response()->json(['status'=>'success','code'=>200, 'data' => json_decode($sCurve->scurve)], 200);
}
public function sCurveCommand(Request $request)
{
public function sCurveCommand(Request $request){
Artisan::call('calculate:scurve', [
'project_id' => $request->project_id
]);
// $project = Project::find($request->project_id);
// if ($project) {
// dispatch(new ProcessSCurve($project));
// return response()->json(['message' => 'S Curve calculation queued']);
// }
// return response()->json(['message' => 'Project not found'], 404);
}
public function getLinearSCurve(Request $request)
{
public function getLinearSCurve(Request $request){
$data = MasterFunctionsHelper::getLinearSCurve($request);
return response()->json(['status' => 'success', 'code' => 200, 'data' => $data], 200);
return response()->json(['status'=>'success','code'=>200, 'data' => $data], 200);
}
public static function setSyncDate($activity_id, $activity, $report) {
$status = AssignMaterial::select('status_activity')->where('activity_id', $activity_id)->first();
if (!isset($status->status_activity)) {
$status->status_activity = 'open';
}
if ($status->status_activity != 'done') {
$minDate = date_create($report->report_date);
$maxDate = date_create($report->report_date);
date_add($maxDate, date_interval_create_from_date_string($activity->duration . " days"));
} else {
$material = AssignMaterial::where('activity_id', $activity_id)->first();
$minDate = date_create($material->start_activity);
$maxDate = date_create($material->finish_activity);
}
$reports = array(
'activity_id' => $activity_id,
'min_date' => $minDate,
'max_date' => $maxDate,
'status' => $status->status_activity
);
return $reports;
}
public function synchronizeReport($gantt_id)
@ -381,41 +376,43 @@ class ProjectController extends Controller
$activities = Activity::where("version_gantt_id", $gantt_id)->get();
$reports = [];
foreach ($activities as $activity) {
foreach($activities as $activity) {
$activity_id = $activity->id;
$countReports = ReportActivityMaterial::where('activity_id', $activity_id)->count();
if ($countReports === 1) {
$dataReports = ReportActivityMaterial::where('activity_id', $activity_id)->orderBy('report_date')->get();
foreach ($dataReports as $dr) {
$reports[] = array(
'activity_id' => $activity_id,
'min_date' => $dr->report_date,
'max_date' => date_modify(date_create($dr->report_date), "1 days")
);
foreach($dataReports as $dr) {
$reports[] = ProjectController::setSyncDate($activity_id, $activity, $dr);
}
}
if ($countReports > 1) {
$firstReport = ReportActivityMaterial::where('activity_id', $activity_id)->orderBy('report_date')->first();
$lastReport = ReportActivityMaterial::where('activity_id', $activity_id)->orderByDesc('report_date')->first();
$reports[] = array(
'activity_id' => $activity_id,
'min_date' => $firstReport->report_date,
'max_date' => date_modify(date_create($lastReport->report_date), "1 days")
);
$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'=> $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->start_date = $reports[$i]['min_date'];
$activity->end_date = $reports[$i]['max_date'];
$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'){
$reports[$i]['max_date']->modify('-1 day');
}else if($reports[$i]['status'] == 'done'){
$activity->actual_end = $reports[$i]['max_date']->setTime(23,59,59);
}
$activity->start_date = $reports[$i]['min_date']; //same early
$activity->end_date = $reports[$i]['max_date']->setTime(23,59,59); // same early
$activity->actual_start = $reports[$i]['min_date'];
$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);
}
public function setBaseline($gantt_id)
@ -424,84 +421,127 @@ class ProjectController extends Controller
foreach ($activities as $activity) {
$activity->update([
"planned_start" => $activity->start_date,
"planned_end" => $activity->end_date,
"planned_start"=>$activity->start_date,
"planned_end"=>$activity->end_date,
"early_start"=>$activity->start_date,
"early_end"=>$activity->end_date,
]);
}
return response()->json(['status' => 'success', 'message' => 'Set baseline success!', 'code' => 200], 200);
return response()->json(['status'=>'success','message'=>'Set baseline success!','code'=> 200], 200);
}
public function getInvoiceIntegration(Request $request)
{
// $search = urlencode($request->search);
// if(empty($search))
// return response()->json(['status'=>'error', 'message'=>'Empty query string!'], 400);
// $url = str_replace("SEARCH", $search, config('api.adw').'/project_cost?project_no=SEARCH');
public function getInvoiceIntegration(Request $request) {
$search = urlencode($request->search);
if(empty($search))
return response()->json(['status'=>'error', 'message'=>'Empty query string!'], 400);
$url = str_replace("SEARCH", $search, config('api.adw').'/project_cost?project_no=SEARCH');
$response = null;
$response = MasterFunctionsHelper::curlReq($url);
// return response()->json(['status'=>'success', 'data'=> $response, 'code'=>200], 200);
return response()->json(['status' => 'success', 'data' => '', 'code' => 200], 200);
return response()->json(['status'=>'success', 'data'=> '', 'code'=>200], 200);
}
public function detail($id)
public function getByUser($id)
{
if (empty($id) || !is_int((int)$id))
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
$alias = "utp";
$userProyek = UserToProyek::query()
->from('assign_hr_to_proyek AS ' . $alias)
->where([
['is_customer', true],
['user_id', $id]
])
->leftJoin('m_users', $alias.'.user_id', '=', 'm_users.id')
->leftJoin('m_proyek', $alias.'.proyek_id', '=', 'm_proyek.id')
->leftJoin('m_type_proyek', 'm_proyek.type_proyek_id', '=', 'm_type_proyek.id')
->select('m_proyek.*', 'm_type_proyek.name AS join_second_name','m_users.name AS join_first_name')
->get();
$totalRecord = $userProyek->count();
return response()->json(['status' => 'success', 'code' => 200, 'data' => $userProyek, 'totalRecord' => $totalRecord], 200);
}
public function detail($id){
if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
$result = Project::find($id);
if (!$result)
return response()->json(['status' => 'failed', 'message' => 'Data not found!', 'code' => 404], 404);
if(!$result)
return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404);
$gantt = MasterFunctionsHelper::getLatestGantt($id);
$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();
return response()->json(['status' => 'success', 'code' => 200, 'data' => $result, 'gantt' => $gantt], 200);
// dd($result->header->start_date);
$ganttId = $gantt['last_gantt_id'];
$actualStartExist = Activity::where('version_gantt_id', $ganttId)->whereNotNull('actual_start')->exists();
$actualEndExist = Activity::where('version_gantt_id', $ganttId)->whereNotNull('actual_end')->exists();
if ($actualStartExist) {
$startDate = Activity::where('version_gantt_id', $ganttId)
->orderBy('actual_start')
->value('start_date');
} else {
$startDate = Activity::where('version_gantt_id', $ganttId)
->orderBy('start_date')
->value('start_date');
}
if ($actualEndExist) {
$endDate = Activity::where('version_gantt_id', $ganttId)
->orderByDesc('actual_end')
->value('end_date');
} else {
$endDate = Activity::where('version_gantt_id', $ganttId)
->orderByDesc('end_date')
->value('end_date');
}
$result->header->start_date = $startDate;
$result->header->end_date = $endDate;
return response()->json(['status'=>'success','code'=> 200,'data'=>$result, 'gantt'=>$gantt], 200);
}
public function getOverdueActivities(Request $request)
{
public function getOverdueActivities(Request $request){
$payload = $request->all();
if (empty($payload['id']) || !is_int((int)$payload['id']))
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
if(empty($payload['id']) || !is_int((int)$payload['id']))
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
$result = Project::find($payload['id']);
if (!$result)
return response()->json(['status' => 'failed', 'message' => 'Project not found!', 'code' => 404], 404);
if(!$result)
return response()->json(['status'=>'failed','message'=> 'Project not found!','code'=> 404], 404);
//TODO possible overdue bug
if (isset($payload['till_date']))
$overdueActivities = Activity::where('proyek_id', $payload['id'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->whereDate('end_date', '<=', $payload['till_date'])->orderBy('end_date', 'asc')->get();
else
$endDate = Activity::where('proyek_id', $payload['id'])
->orderByDesc('end_date')
->value('end_date');
if(isset($payload['till_date'])) {
if (isset($payload['scurve'])) {
$overdueActivities = Activity::where('proyek_id', $payload['id'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->whereDate('end_date','<=',$endDate)->orderBy('end_date', 'asc')->get();
} else {
$overdueActivities = Activity::where('version_gantt_id', $payload['gantt'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->whereDate('end_date','<=',$endDate)->orderBy('end_date', 'asc')->get();
}
}
else {
if (isset($payload['scurve'])) {
$overdueActivities = Activity::where('proyek_id', $payload['id'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->orderBy('end_date', 'asc')->get();
} else {
$overdueActivities = Activity::where('version_gantt_id', $payload['gantt'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->orderBy('end_date', 'asc')->get();
}
}
$result->overdueActivities = $overdueActivities;
return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200);
return response()->json(['status'=>'success','code'=> 200,'data'=>$result], 200);
}
public function getReportDistribution(Request $request)
{
public function getReportDistribution(Request $request){
$payload = $request->all();
if (empty($payload['project_id']) || !is_int((int)$payload['project_id']))
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
if(empty($payload['project_id']) || !is_int((int)$payload['project_id']))
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
$reports = DB::table('assign_material_to_activity as ama')
->select(
'u.name',
'a.name as activity_name',
'ama.qty_planning',
'ram.qty as qty_real',
'rm.description as material_name',
'rm.uom as material_unit',
'ram.lat',
'ram.lon',
'ram.description as report_notes',
'ram.report_date'
)
->select('u.name', 'a.name as activity_name', 'ama.qty_planning', 'ram.qty as qty_real','rm.description as material_name', 'rm.uom as material_unit',
'ram.lat', 'ram.lon', 'ram.description as report_notes', 'ram.report_date')
->join('report_activity_material as ram', 'ram.assign_material_id', '=', 'ama.id')
->join('m_req_material as rm', 'rm.id', '=', 'ama.material_id')
->join('m_activity as a', 'a.id', '=', 'ama.activity_id')
@ -510,44 +550,33 @@ class ProjectController extends Controller
->whereNotNull('ram.lat')
->whereBetween('ram.report_date', [$payload['start_date'], $payload['end_date']]);
return response()->json(['status' => 'success', 'code' => 200, 'data' => $reports], 200);
return response()->json(['status'=>'success', 'code'=> 200, 'data'=> $reports], 200);
}
public function getManpower($proyek_id)
{
public function getManpower($proyek_id){
$manCount = UserToProyek::where('proyek_id', $proyek_id)->count();
return response()->json(['totalRecord' => $manCount]);
return response()->json(['totalRecord'=>$manCount]);
}
public function getAssignedHR($gantt_id)
{
public function getAssignedHR($gantt_id){
$results = UserToActivity::select('assign_hr_to_activity.proyek_id', 'assign_hr_to_activity.user_id', 'm_activity.id', 'm_activity.name', 'm_activity.start_date', 'm_activity.end_date')
->join('m_activity', 'm_activity.id', '=', 'assign_hr_to_activity.activity_id')
->where('assign_hr_to_activity.version_gantt_id', $gantt_id)
->get();
return response()->json(['data' => $results]);
return response()->json(['data'=>$results]);
}
public function dashboard($id)
{
$data = DB::table('m_proyek as mp')
->select(
'mp.kode_sortname',
'mp.nama as name_project',
'mp.mulai_proyek as start',
'mp.akhir_proyek as finish',
'mp.rencana_biaya',
'mp.company',
'mp.currency_symbol',
'mu.name as pm',
'mp.budget_health'
)
->select('mp.kode_sortname', 'mp.nama as name_project', 'mp.mulai_proyek as start', 'mp.akhir_proyek as finish',
'mp.rencana_biaya', 'mp.company', 'mp.currency_symbol', 'mu.name as pm', 'mp.budget_health')
->join('m_users as mu', 'mu.id', '=', 'mp.pm_id')
->where('mp.id', $id)
->first();
if (!$data)
return response()->json(['status' => 'failed', 'message' => 'Data tidak ditemukan!', 'code' => 404], 404);
if(!$data)
return response()->json(['status'=>'failed','message'=>'Data tidak ditemukan!','code'=> 404], 404);
$manpowers = UserToProyek::where('proyek_id', $id)->count();
$rootActivity = Activity::whereNull('parent_id')->where('proyek_id', $id)->orderBy('version_gantt_id', 'desc')->first();
@ -556,13 +585,8 @@ class ProjectController extends Controller
$progress = @$rootActivity->persentase_progress ?? 0;
$commentActivity = DB::table('m_comment_activity as mca')
->select(
'mca.activity_id',
'mca.comment as comment',
'mca.created_by as comment_by',
'mca.created_at as comment_created',
'ma.name as activity'
)
->select('mca.activity_id', 'mca.comment as comment', 'mca.created_by as comment_by', 'mca.created_at as comment_created',
'ma.name as activity')
->join('m_activity as ma', 'ma.id', '=', 'mca.activity_id')
->where('ma.proyek_id', $id)
->orderBy('comment_by')
@ -574,11 +598,10 @@ class ProjectController extends Controller
$data->comment = $commentActivity;
$data->man_power = $manpowers;
return response()->json(['status' => 'success', 'code' => 200, 'data' => $data], 200);
return response()->json(['status'=>'success','code'=>200,'data'=> $data], 200);
}
private function httpReq($search)
{
private function httpReq($search){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, str_replace("ADDR", $search, API_GEOLOCATION));
@ -594,4 +617,6 @@ class ProjectController extends Controller
return json_decode($output);
}
}

2
app/Http/Controllers/RequestMaterialController.php

@ -170,7 +170,7 @@ class RequestMaterialController extends Controller
}
public function getMaterialIntegration(Request $request) {
$search = null;
$search = urlencode($request->name);
if(empty($search))
return response()->json(['status'=>'error', 'message'=>'Empty query string!'], 400);
$url = str_replace("SEARCH", $search, config('api.adw').'/stock_master?name=SEARCH');

6
app/Http/Controllers/ShowHideColumnController.php

@ -45,12 +45,12 @@ class ShowHideColumnController extends Controller
$success = 0;
foreach ($columns as $column) {
foreach ($columns as $key => $column) {
$dataAdd = array(
'version_gantt_id'=>$request->version_gantt_id,
'user_id'=>$this->currentId,
'column_name'=>$column,
'show'=>true,
'column_name'=>$key,
'show'=>$column,
'created_by'=>$this->currentName
);

2
app/Http/Controllers/UserToProyekController.php

@ -185,7 +185,7 @@ class UserToProyekController extends Controller
}
public function getEmployeeIntegration(Request $request) {
$search = null;
$search = urlencode($request->name);
if(empty($search))
return response()->json(['status'=>'error', 'message'=>'Empty query string!'], 400);
$url = str_replace("SEARCH", $search, config('api.adw').'/employees?emp_name=SEARCH');

36
app/Jobs/ProcessSCurve.php

@ -0,0 +1,36 @@
<?php
namespace App\Jobs;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Queue;
use App\Helpers\MasterFunctionsHelper;
use App\Models\Project;
class ProcessSCurve extends Job
{
protected $project;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct(Project $project)
{
$this->project = $project;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$data = MasterFunctionsHelper::CalculateSCurve($this->project->id);
$this->project->scurve = json_encode($data);
$this->project->calculation_status = true;
$this->project->save();
}
}

6
app/Models/Activity.php

@ -25,7 +25,7 @@ class Activity extends Model
'buffer_radius', 'duration', 'color_progress', 'jumlah_pekerjaan', 'satuan',
'description', 'priority', 'bobot_planning', 'type_activity', 'open', 'geom',
'version_gantt_id', 'budget_plan', 'biaya_material_plan', 'biaya_human_plan', 'biaya_tools_plan',
'planned_start', 'planned_end', 'satuan_id',
'planned_start', 'planned_end', 'satuan_id', 'actual_start', 'actual_end',
'created_at', 'created_by', 'updated_at', 'updated_by', 'sortorder'
];
@ -71,8 +71,8 @@ class Activity extends Model
$data->updateCostPlanning();
if($data->bobot_planning){
$data->updatePersentaseProgress();
$data->updateCostActual();
}
$data->updateCostActual();
// if($data->start_date != request()->start_date || $data->end_date != request()->end_date) {
// $data->updateStartEndDateHeader();
// }
@ -86,8 +86,8 @@ class Activity extends Model
$data->updateCostPlanning();
if($data->bobot_planning){
$data->updatePersentaseProgress();
$data->updateCostActual();
}
$data->updateCostActual();
$data->updateStartEndDateHeader();
});

2
app/Models/AssignMaterial.php

@ -5,6 +5,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use App\Models\RequestMaterial;
use App\Models\Activity;
use App\Models\ReportActivityMaterial;
class AssignMaterial extends Model
{
@ -35,6 +36,7 @@ class AssignMaterial extends Model
});
static::deleted(function($data) {
$reportActivities = ReportActivityMaterial::where('assign_material_id', $data->id)->delete();
$activity = Activity::where('id', $data->activity_id)->first();
$activity->rencana_biaya -= floatval($data->budget) * floatval($data->qty_planning);
$activity->save();

2
app/Models/Broadcast.php

@ -12,6 +12,6 @@ class Broadcast extends Model
const UPDATED_AT = 'updated_at';
protected $fillable = [
'title_notif', 'message_notif', 'description', 'send_to_type', 'created_at', 'created_by', 'updated_at', 'updated_by'
'title_notif', 'message_notif', 'description', 'send_to_type', 'send_to_id', 'status_send', 'created_at', 'created_by', 'updated_at', 'updated_by'
];
}

4
app/Models/UserToProyek.php

@ -12,8 +12,8 @@ class UserToProyek extends Model
const UPDATED_AT = 'updated_at';
protected $fillable = [
'user_id', 'proyek_id', 'rbs', 'project_role', 'group_r', 'max_used', 'is_customer', 'standart_rate',
'user_id', 'proyek_id', 'rbs', 'project_role', 'group_r', 'max_used', 'standart_rate',
'uom_standart_rate', 'overtime_rate', 'uom_overtime_rate', 'cost_per_used', 'accrue_at',
'base_calender', 'created_at', 'created_by', 'updated_at', 'updated_by'
'base_calender', 'is_customer', 'created_at', 'created_by', 'updated_at', 'updated_by'
];
}

49
app/Services/FCMService.php

@ -0,0 +1,49 @@
<?php
namespace App\Services;
use Illuminate\Support\Facades\Http;
class FCMService
{
public static function send($fcm_token, $notification)
{
$url = 'https://fcm.googleapis.com/fcm/send';
// $url = 'https://fcm.googleapis.com/v1/projects/594814396007/messages:send';
$serverKey = config('fcm.server_key');
$data = [
"registration_ids" => [$fcm_token],
"notification" => [
"title" => $notification['title'],
"body" => $notification['body'],
]
];
$encodedData = json_encode($data);
$headers = [
'Authorization:key=' . $serverKey,
'Content-Type: application/json',
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
// Disabling SSL Certificate support temporarly
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $encodedData);
$result = curl_exec($ch);
if ($result === FALSE) {
return array("success"=> false, "message"=> curl_error($ch));
}
// Close connection
curl_close($ch);
return array("success"=> true, "message"=> $result);
}
}

1
bootstrap/app.php

@ -63,6 +63,7 @@ $app->configure('auth');
$app->configure('api');
$app->configure('assets');
$app->configure('app');
$app->configure('fcm');
/*
|--------------------------------------------------------------------------

2
config/api.php

@ -2,6 +2,6 @@
return [
'nominatim' => env('API_NOMINATIM', 'https://nominatim.oslogdev.com'),
'adw' => env('API_ADW', 'http://ospro-api.adyawinsa.com:9083/api'),
'adw_token' => env('API_ADW_TOKEN', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIxMjAyIiwiZXhwIjoxNjkxODMwNDkzfQ.DvBQIOZsdFndWsliPCZT65Y6G5Xx4vWBKz8Rhe7rvRA')
'adw_token' => env('API_ADW_TOKEN', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIxMjAyIiwiZXhwIjoxNzI0Mzk1NTExfQ.z9_Q7vjZbcbr8Mook4EmlOuOByNP12_DEDSabf0zanU')
];
?>

5
config/fcm.php

@ -0,0 +1,5 @@
<?php
return [
'server_key' => "AAAAin2zZmc:APA91bHFIYDzZGyVyXvt2C8I09wC2k8siWPQIo4b1Db0QjxCzQR5SRQU9KY1iNRIUhTL6OoLUs2x6UAiP1BNv-mwOlSR7C_405msoNL2p33JVBxrtqc7hdMc5TEdTBB4ZGRVH7ltQzSe",
];

36
database/migrations/2023_08_29_130624_create_jobs_table.php

@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateJobsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('jobs', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('queue')->index();
$table->longText('payload');
$table->unsignedTinyInteger('attempts');
$table->unsignedInteger('reserved_at')->nullable();
$table->unsignedInteger('available_at');
$table->unsignedInteger('created_at');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('jobs');
}
}

9
docker/nginx/conf.d/default.conf

@ -15,6 +15,15 @@ server {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
client_max_body_size 100M;
client_body_buffer_size 5M;
fastcgi_read_timeout 900;
keepalive_timeout 900;
send_timeout 300;
proxy_read_timeout 900;
proxy_connect_timeout 900;
proxy_send_timeout 900;
}
location / {

1947
docker/php/php.ini

File diff suppressed because it is too large Load Diff

72
rest-client.http

@ -1,10 +1,12 @@
@token = eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9sb2NhbGhvc3Q6ODQ0NFwvYXBpXC9sb2dpbiIsImlhdCI6MTY3NzQ3NzIzMSwiZXhwIjoxNjc4MDgyMDMxLCJuYmYiOjE2Nzc0NzcyMzEsImp0aSI6ImR5WWhRY3ZIbUJEcmFKMG0iLCJzdWIiOjEsInBydiI6IjIzYmQ1Yzg5NDlmNjAwYWRiMzllNzAxYzQwMDg3MmRiN2E1OTc2ZjcifQ.9zT6CBbQholzIdQ9ZBDoxMvrR-PKvIYkGzdNB6bim0Y
@token = eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9sb2NhbGhvc3Q6ODQ0NFwvYXBpXC9sb2dpbiIsImlhdCI6MTY5MTc2MDYyNCwiZXhwIjoxNjkyMzY1NDI0LCJuYmYiOjE2OTE3NjA2MjQsImp0aSI6Ikd2bEFPTE4yZ2FuRFdVbjEiLCJzdWIiOjEsInBydiI6IjIzYmQ1Yzg5NDlmNjAwYWRiMzllNzAxYzQwMDg3MmRiN2E1OTc2ZjcifQ.XNGbsmcgQ-CkV8vLlvnItGKM0R1am5X5b6qUFOR1DRo
@tokenS = eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9hZHctYXBpLm9zcHJvLmlkXC9hcGlcL2xvZ2luIiwiaWF0IjoxNjkxNTcyMTIwLCJleHAiOjE2OTIxNzY5MjAsIm5iZiI6MTY5MTU3MjEyMCwianRpIjoiVUdqbnhLRVdlZzYyTTBnayIsInN1YiI6MSwicHJ2IjoiMjNiZDVjODk0OWY2MDBhZGIzOWU3MDFjNDAwODcyZGI3YTU5NzZmNyJ9.5QqK0dLW5jzbVOkSCSW0mFo0K7ycGOBW9NCG_2Zldm4
@hostname = https://adw-api.ospro.id/api
# @hostname = https://adw-api.ospro.id/api
# @hostname = https://ospro-api.ospro.id/api
# @hostname = https://api-iu.ospro.id/api
# @hostname = https://api-staging-adw.ospro.id/api
# @hostname = http://localhost:8444/api
@hostname = http://localhost:8444/api
# @hostname = http://103.73.125.81:8444/api
# @hostname = http://localhost:8444/adw-backend/api
@ -402,6 +404,59 @@ GET {{hostname}}/project/list
Authorization: Bearer {{token}}
content-type: application/json
###
POST {{hostname}}/project/search
Authorization: Bearer {{token}}
content-type: application/json
{
"columns": [
{
"name": "nama",
"logic_operator": "ilike",
"value": "",
"operator": "AND"
}
],
"select": ["kode_sortname", "nama", "mulai_proyek"],
"joins": [
{
"name": "m_users",
"column_join": "pm_id",
"column_results": [
"name",
"username"
]
},
{
"name": "m_type_proyek",
"column_join": "type_proyek_id",
"column_results": [
"name",
"description"
]
}
],
"orders": {
"columns": [
"id"
],
"ascending": false
},
"paging": {
"start": 0,
"length": 10
}
}
###
POST https://adw-api.ospro.id/api/project/search
Authorization: Bearer {{tokenS}}
content-type: application/json
{
"columns":[{"name":"nama","logic_operator":"ilike","value":"","operator":"AND"}],"joins":[{"name":"m_users","column_join":"pm_id","column_results":["name","username"]},{"name":"m_type_proyek","column_join":"type_proyek_id","column_results":["name","description"]}],"orders":{"columns":["id"],"ascending":false},"paging":{"start":0,"length":10}
}
### add
POST {{hostname}}/project/add
@ -1103,3 +1158,14 @@ content-type: application/json
}
}
#######
POST {{hostname}}/project/get-s-curve
Authorization: Bearer {{token}}
content-type: application/json
{
"period":"week",
"project_id":"118",
"gantt_id":"287"
}

12
routes/web.php

@ -4,7 +4,7 @@ $router->get('/', function () use ($router) {
return $router->app->version();
});
$router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($router) {
$router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($router) {
$router->post('/login', 'AuthController@login');
$router->post('/menu/add', 'MenuController@add');
@ -208,6 +208,7 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro
$router->post('/activity/import', 'ActivityController@import');
$router->post('/activity/import-update', 'ActivityController@importUpdate');
$router->post('/activity/import-old', 'ActivityController@importOld');
$router->post('/activity/batch-update/{ganttId}', 'ActivityController@batchUpdate');
$router->post('/task', 'ActivityController@add');
$router->get('/task/edit/{id}', 'ActivityController@edit');
$router->put('/task/{id}', 'ActivityController@update');
@ -236,6 +237,7 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro
$router->get('/comment-activity/list', 'CommentActivityController@list');
$router->post('/presence/add', 'PresenceController@add');
$router->post('/presence/test', 'PresenceController@checkLocationTest');
$router->get('/presence/edit/{id}', 'PresenceController@edit');
$router->put('/presence/update/{id}', 'PresenceController@update');
$router->post('/presence/search', 'PresenceController@search');
@ -456,5 +458,13 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro
$router->get('/hierarchy-ftths/tree-gantt/{gantt_id}', 'HierarchyFtthController@getTreeByGantt');
$router->post('/map-monitoring/search', 'MapMonitoringController@search');
$router->post('/broadcast/add', 'BroadcastController@add');
$router->get('/broadcast/edit/{id}', 'BroadcastController@edit');
$router->put('/broadcast/update/{id}', 'BroadcastController@update');
$router->post('/broadcast/search', 'BroadcastController@search');
$router->delete('/broadcast/delete/{id}', 'BroadcastController@delete');
$router->get('/broadcast/list', 'BroadcastController@list');
});
});

Loading…
Cancel
Save