Browse Source

Merge pull request 'dev-wahyun' (#1) from dev-wahyun into staging

Reviewed-on: ibnu/generic-ospro-backend#1
pull/3/head
farhantock 1 year ago
parent
commit
9f70e28fa4
  1. 3
      Dockerfile
  2. 29
      app/Console/Commands/CalculateSCurve.php
  3. 3
      app/Console/Kernel.php
  4. 1579
      app/Helpers/MasterFunctionsHelper.php
  5. 1654
      app/Http/Controllers/ActivityController.php
  6. 190
      app/Http/Controllers/ActivityDokumenController.php
  7. 436
      app/Http/Controllers/AssignMaterialController.php
  8. 186
      app/Http/Controllers/BroadcastController.php
  9. 617
      app/Http/Controllers/Controller.php
  10. 175
      app/Http/Controllers/DashboardBoDController.php
  11. 213
      app/Http/Controllers/DivisiController.php
  12. 128
      app/Http/Controllers/HierarchyFtthController.php
  13. 368
      app/Http/Controllers/HumanResourceController.php
  14. 96
      app/Http/Controllers/MapMonitoringController.php
  15. 310
      app/Http/Controllers/MenuController.php
  16. 1123
      app/Http/Controllers/PresenceController.php
  17. 355
      app/Http/Controllers/ProjectCarausellController.php
  18. 136
      app/Http/Controllers/ProjectChecklistsController.php
  19. 375
      app/Http/Controllers/ProjectController.php
  20. 9
      app/Http/Controllers/ProjectDokumenController.php
  21. 136
      app/Http/Controllers/ProjectIssuesController.php
  22. 137
      app/Http/Controllers/ProjectRisksController.php
  23. 540
      app/Http/Controllers/ReportActivityController.php
  24. 327
      app/Http/Controllers/ReportActivityMaterialController.php
  25. 210
      app/Http/Controllers/RoleController.php
  26. 204
      app/Http/Controllers/RoleMenuController.php
  27. 6
      app/Http/Controllers/ShowHideColumnController.php
  28. 450
      app/Http/Controllers/UserToActivityController.php
  29. 470
      app/Http/Controllers/UserToProyekController.php
  30. 241
      app/Http/Controllers/VersionGanttController.php
  31. 36
      app/Jobs/ProcessSCurve.php
  32. 486
      app/Models/Activity.php
  33. 90
      app/Models/AssignMaterial.php
  34. 2
      app/Models/Broadcast.php
  35. 44
      app/Models/CommentActivity.php
  36. 83
      app/Models/Divisi.php
  37. 19
      app/Models/HierarchyFtth.php
  38. 76
      app/Models/HumanResource.php
  39. 106
      app/Models/Project.php
  40. 23
      app/Models/ProjectChecklists.php
  41. 23
      app/Models/ProjectIssues.php
  42. 24
      app/Models/ProjectRisks.php
  43. 153
      app/Models/ReportActivityMaterial.php
  44. 34
      app/Models/Role.php
  45. 124
      app/Models/UserToActivity.php
  46. 38
      app/Models/UserToProyek.php
  47. 113
      app/Models/VersionGantt.php
  48. 49
      app/Services/FCMService.php
  49. 1
      bootstrap/app.php
  50. 2
      config/api.php
  51. 5
      config/fcm.php
  52. 36
      database/migrations/2023_08_29_130624_create_jobs_table.php
  53. 9
      docker/nginx/conf.d/default.conf
  54. 1947
      docker/php/php.ini
  55. 72
      rest-client.http
  56. 70
      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

29
app/Console/Commands/CalculateSCurve.php

@ -0,0 +1,29 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Helpers\MasterFunctionsHelper;
use App\Models\Project;
class CalculateSCurve extends Command
{
protected $signature = 'calculate:scurve {project_id}';
protected $description = 'Calculate S Curve';
public function handle()
{
$project_id = $this->argument('project_id');
$project = Project::find($project_id);
$project->calculation_status = true;
$project->save();
$data = MasterFunctionsHelper::CalculateSCurve($project_id);
$project->scurve = json_encode($data);
$project->calculation_status = true;
$project->save();
}
}

3
app/Console/Kernel.php

@ -13,7 +13,8 @@ class Kernel extends ConsoleKernel
* @var array
*/
protected $commands = [
Commands\syncHumanResourceIntegration::class
Commands\syncHumanResourceIntegration::class,
Commands\CalculateSCurve::class
];
/**

1579
app/Helpers/MasterFunctionsHelper.php

File diff suppressed because it is too large Load Diff

1654
app/Http/Controllers/ActivityController.php

File diff suppressed because it is too large Load Diff

190
app/Http/Controllers/ActivityDokumenController.php

@ -1,95 +1,95 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\ActivityDokumen;
class ActivityDokumenController extends Controller
{
public function dokumenByActivityId($id){
if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'activity id is required!','code'=>400], 400);
$dataDokumen = ActivityDokumen::where("activity_id", $id)->get();
return response()->json(['status'=>'success','data'=>$dataDokumen,'code'=>200], 200);
}
public function delete($id)
{
if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400);
$document = ActivityDokumen::find($id);
if(!$document)
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
if(file_exists($this->pathActivityDocument.$document->file))
unlink($this->pathActivityDocument.$document->file);
$document->delete();
return response()->json(['status'=>'success','message'=>'Dokumen deleted successfully!','code'=>200], 200);
}
public function uploadProjectDokumen(Request $request)
{
if(!$request->hasFile('dokumen'))
return response()->json(['status'=>'failed','message'=>'file is required!','code'=>400], 400);
$activity_id = $request->activity_id;
$document = $request->file('dokumen');
$name = $document->getClientOriginalName();
$result = $document->move($this->pathActivityDocument, $name);
if(!$result)
return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500);
$data = [
'activity_id' => (int)$activity_id,
'file' => $name,
'description' => $request->description
];
$result = ActivityDokumen::create($data);
if(!$result){
unlink($this->pathActivityDocument.$name);
return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500);
}
return response()->json(['status'=>'success','message'=>'Upload success!','code'=>200], 200);
}
public function searchDocProject(Request $request){
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'm_document_activity');
$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 downloadDokumen($id)
{
if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400);
$document = ActivityDokumen::find($id);
if(!$document)
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>400], 400);
if(file_exists($this->pathActivityDocument.$document->file)){
$pathToFile = $this->pathActivityDocument.$document->file;
return response()->download($pathToFile);
}
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>400], 400);
}
}
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\ActivityDokumen;
class ActivityDokumenController extends Controller
{
public function dokumenByActivityId($id){
if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'activity id is required!','code'=>400], 400);
$dataDokumen = ActivityDokumen::where("activity_id", $id)->get();
return response()->json(['status'=>'success','data'=>$dataDokumen,'code'=>200], 200);
}
public function delete($id)
{
if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400);
$document = ActivityDokumen::find($id);
if(!$document)
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
if(file_exists($this->pathActivityDocument.$document->file))
unlink($this->pathActivityDocument.$document->file);
$document->delete();
return response()->json(['status'=>'success','message'=>'Dokumen deleted successfully!','code'=>200], 200);
}
public function uploadProjectDokumen(Request $request)
{
if(!$request->hasFile('dokumen'))
return response()->json(['status'=>'failed','message'=>'file is required!','code'=>400], 400);
$activity_id = $request->activity_id;
$document = $request->file('dokumen');
$name = $document->getClientOriginalName();
$result = $document->move($this->pathActivityDocument, $name);
if(!$result)
return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500);
$data = [
'activity_id' => (int)$activity_id,
'file' => $name,
'description' => $request->description
];
$result = ActivityDokumen::create($data);
if(!$result){
unlink($this->pathActivityDocument.$name);
return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500);
}
return response()->json(['status'=>'success','message'=>'Upload success!','code'=>200], 200);
}
public function searchDocProject(Request $request){
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'm_document_activity');
$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 downloadDokumen($id)
{
if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400);
$document = ActivityDokumen::find($id);
if(!$document)
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>400], 400);
if(file_exists($this->pathActivityDocument.$document->file)){
$pathToFile = $this->pathActivityDocument.$document->file;
return response()->download($pathToFile);
}
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>400], 400);
}
}

436
app/Http/Controllers/AssignMaterialController.php

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

186
app/Http/Controllers/BroadcastController.php

@ -1,9 +1,177 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class BroadcastController extends Controller
{
}
<?php
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['created_by'] = $this->currentName;
if (isset($data['send_to_id'])) {
$idArray = $data['send_to_id'];
if (is_array($data['send_to_id'])) {
$data['send_to_id'] = implode(", ", $idArray);
}
}
$result = Broadcast::create($data);
if($result){
$data['status_send'] !== "registered" ? $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);
$status_send = $request->status_send;
if($status_send === 'resend' || $status_send === 'send' && !empty($data))
{
$data['status_send'] = $status_send;
$this->sendNotification($data);
}
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 'users':
$idArray = explode(", ", $data['send_to_id']);
foreach ($idArray as $key => $value) {
$user = User::where("id", $value)->whereNotNull('fcm_token')->first();
if (isset($user)) {
FCMService::send(
$user->fcm_token,
[
'title' => $data['title_notif'],
'body' => $data['message_notif'],
]
);
}
}
break;
default:
# code...
break;
}
}
}
}

617
app/Http/Controllers/Controller.php

@ -1,302 +1,315 @@
<?php
namespace App\Http\Controllers;
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 $currentDate;
protected $currentName;
protected $currentId;
public function __construct()
{
$this->currentDate = date("Y-m-d H:i:s");
$this->currentName = auth()->user() ? auth()->user()->name : "system";
$this->currentId = auth()->user() ? auth()->user()->id : 0;
$this->pathImage = config('assets.image');
$this->pathDocument = config('assets.project');
$this->pathActivityDocument = config('assets.activity');
}
protected function setUpPayload($condition, $tableSelf)
{
$alias = "selfTable";
$builder = DB::table($tableSelf." AS ".$alias);
$builder = $builder->select($alias.".*");
if($condition){
if(isset($condition['joins'])){
$selectColumn = [];
$no = 0;
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);
}
$builder = $builder->leftJoin($tableName, $tableJoin.".".$columnJoin, '=', $tableName.'.'.$columnSelf);
$no++;
}
}
if(isset($condition['columns'])){
$listWhere = $condition['columns'];
$builder = $builder->where(function ($query) use($listWhere, $alias){
foreach($listWhere as $where){
$value = $where['value'];
if($value && $value!="" && $value!=" "){
$column = $where['name'];
$operator = strtolower($where['logic_operator']); // like, =, <>, range
$value2 = isset($where['value1']) ? $where['value1'] : "";
$tableColumn = isset($where['table_name']) ? $where['table_name'] : $alias;
$query = $this->whereCondition($query, $operator, $tableColumn, $column, $value, $value2);
}
}
});
}
if(isset($condition['group_column'])){
$builder = $this->groupWhere($builder, $condition['group_column'], $alias);
}
$data['count'] = clone $builder;
if(isset($condition['paging'])){
$builder = $builder->offset($condition['paging']['start'])->limit($condition['paging']['length']);
}
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);
}
}
}
$data['builder'] = $builder;
return $data;
}
private function groupWhere($oldBuilder, $groupWhere, $alias)
{
$builder = $oldBuilder;
$listGroupWhere = $groupWhere;
$operator = $listGroupWhere['operator'];
$operatorGroup = $listGroupWhere['group_operator'];
$listWhere = $listGroupWhere['where'];
if(strtolower($operator)=="and"){
$builder = $builder->where(function($query) use($operatorGroup, $listWhere, $alias){
$no = 1;
foreach ($listWhere as $where) {
$value = $where['value'];
$column = $where['name'];
$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"){
$query = $this->whereCondition($query, $operator, $tableColumn, $column, $value, $value2);
}else{
if($no==1){
$query = $this->whereCondition($query, $operator, $tableColumn, $column, $value, $value2);
}else{
$query = $this->orWhereCondition($query, $operator, $tableColumn, $column, $value, $value2);
}
}
}
$no = $no+1;
}
});
}else if(strtolower($operator)=="or"){
$builder = $builder->orWhere(function($query) use($operatorGroup, $listWhere, $alias){
$no = 1;
foreach ($listWhere as $where) {
$value = $where['value'];
$column = $where['name'];
$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"){
$query = $this->whereCondition($query, $operator, $tableColumn, $column, $value, $value2);
}else{
if($no==1){
$query = $this->whereCondition($query, $operator, $tableColumn, $column, $value, $value2);
}else{
$query = $this->orWhereCondition($query, $operator, $tableColumn, $column, $value, $value2);
}
}
}
$no++;
}
});
}
return $builder;
}
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);
}
return $query;
}
private function whereConditionSingleTable($oldQuery, $operator, $column, $value, $value2){
$query = $oldQuery;
if($operator=="range"){
$query = $query->whereBetween($column, [$value, $value2]);
}else if($operator=="like"){
$query = $query->where($column, 'like', '%'.$value.'%');
}else if($operator=="ilike"){
$query = $query->where($column, '~*', $value);
}else if($operator=="="){
$query = $query->where($column, $value);
}else if($operator=="in"){
$query = $query->whereIn($column, $value);
}else if($operator=="notin"){
$query = $query->whereNotIn($column, $value);
}else{
$query = $query->where($column, $operator, $value);
}
return $query;
}
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);
}
return $query;
}
protected function calculateAllCost($activity_id, $proyek_id){
$humanCostPlanning = $this->calculateAllHumanCost($activity_id, $proyek_id);
$materialCostPlanning = $this->calculateMaterialCost($activity_id, $proyek_id);
$toolsCostPlanning = 0;
$allCost = $humanCostPlanning + $materialCostPlanning + $toolsCostPlanning;
return $allCost;
}
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")->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)
->get();
$totalCost = 0;
foreach ($dataHuman as $human) {
$uom = $human->uom_standart_rate;
$totalCost += $this->calculateHumanCost($human, $activity_id);
}
return $totalCost;
}
private function calculateHumanCost($human, $activity_id)
{
$activity = Activity::find($activity_id);
$duration = $activity->duration;
$standarRate = $human->standart_rate;
$maxUsed = $human->max_used/100;
$totalCost = ($standarRate*$duration)*$maxUsed;
return $totalCost;
}
private function calculateMaterialCost($activity_id, $proyek_id)
{
$totalCost = AssignMaterial::selectRaw("COALESCE(qty_planning,0)*COALESCE(budget,0) as totalCost")
->where("proyek_id", $proyek_id)
->where("activity_id", $activity_id)
->sum(AssignMaterial::raw("COALESCE(qty_planning, 0) * COALESCE(budget, 0)"));
return $totalCost;
}
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";
// $token = config('api.adw_token');
$response = $this->curlRequest($url);
return $response;
}
private function curlRequest($url){
$ch = curl_init();
// $headers = [
// 'Authorization: '.$token
// ];
curl_setopt($ch, CURLOPT_URL, $url);
// curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
if ($response === false)
$response = curl_error($ch);
curl_close($ch);
return json_decode($response);
}
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
);
ReportK3Detail::create($dataNew);
}
}
}
<?php
namespace App\Http\Controllers;
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 $currentDate;
protected $currentName;
protected $currentId;
public function __construct()
{
$this->currentDate = date("Y-m-d H:i:s");
$this->currentName = auth()->user() ? auth()->user()->name : "system";
$this->currentId = auth()->user() ? auth()->user()->id : 0;
$this->pathImage = config('assets.image');
$this->pathDocument = config('assets.project');
$this->pathActivityDocument = config('assets.activity');
}
protected function setUpPayload($condition, $tableSelf)
{
$alias = "selfTable";
$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){
$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
if (isset($join['column_results'])) {
$columnResult = $join['column_results'];
foreach($columnResult as $sColumn){
$builder = $builder->addSelect($tableName.".".$sColumn." as join_".$this->listJoinAll[$no]."_".$sColumn);
}
}
$builder = $builder->leftJoin($tableName, $tableJoin.".".$columnJoin, '=', $tableName.'.'.$columnSelf);
$no++;
}
}
if(isset($condition['columns'])){
$listWhere = $condition['columns'];
$builder = $builder->where(function ($query) use($listWhere, $alias){
foreach($listWhere as $where){
$value = $where['value'];
if($value && $value!="" && $value!=" "){
$column = $where['name'];
$operator = strtolower($where['logic_operator']); // like, =, <>, range
$value2 = isset($where['value1']) ? $where['value1'] : "";
$tableColumn = isset($where['table_name']) ? $where['table_name'] : $alias;
$query = $this->whereCondition($query, $operator, $tableColumn, $column, $value, $value2);
}
}
});
}
if(isset($condition['group_column'])){
$builder = $this->groupWhere($builder, $condition['group_column'], $alias);
}
$data['count'] = clone $builder;
if(isset($condition['paging'])){
$builder = $builder->offset($condition['paging']['start'])->limit($condition['paging']['length']);
}
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);
}
}
}
$data['builder'] = $builder;
return $data;
}
private function groupWhere($oldBuilder, $groupWhere, $alias)
{
$builder = $oldBuilder;
$listGroupWhere = $groupWhere;
$operator = $listGroupWhere['operator'];
$operatorGroup = $listGroupWhere['group_operator'];
$listWhere = $listGroupWhere['where'];
if(strtolower($operator)=="and"){
$builder = $builder->where(function($query) use($operatorGroup, $listWhere, $alias){
$no = 1;
foreach ($listWhere as $where) {
$value = $where['value'];
$column = $where['name'];
$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"){
$query = $this->whereCondition($query, $operator, $tableColumn, $column, $value, $value2);
}else{
if($no==1){
$query = $this->whereCondition($query, $operator, $tableColumn, $column, $value, $value2);
}else{
$query = $this->orWhereCondition($query, $operator, $tableColumn, $column, $value, $value2);
}
}
}
$no = $no+1;
}
});
}else if(strtolower($operator)=="or"){
$builder = $builder->orWhere(function($query) use($operatorGroup, $listWhere, $alias){
$no = 1;
foreach ($listWhere as $where) {
$value = $where['value'];
$column = $where['name'];
$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"){
$query = $this->whereCondition($query, $operator, $tableColumn, $column, $value, $value2);
}else{
if($no==1){
$query = $this->whereCondition($query, $operator, $tableColumn, $column, $value, $value2);
}else{
$query = $this->orWhereCondition($query, $operator, $tableColumn, $column, $value, $value2);
}
}
}
$no++;
}
});
}
return $builder;
}
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);
}
return $query;
}
private function whereConditionSingleTable($oldQuery, $operator, $column, $value, $value2){
$query = $oldQuery;
if($operator=="range"){
$query = $query->whereBetween($column, [$value, $value2]);
}else if($operator=="like"){
$query = $query->where($column, 'like', '%'.$value.'%');
}else if($operator=="ilike"){
$query = $query->where($column, '~*', $value);
}else if($operator=="="){
$query = $query->where($column, $value);
}else if($operator=="in"){
$query = $query->whereIn($column, $value);
}else if($operator=="notin"){
$query = $query->whereNotIn($column, $value);
}else{
$query = $query->where($column, $operator, $value);
}
return $query;
}
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);
}
return $query;
}
protected function calculateAllCost($activity_id, $proyek_id){
$humanCostPlanning = $this->calculateAllHumanCost($activity_id, $proyek_id);
$materialCostPlanning = $this->calculateMaterialCost($activity_id, $proyek_id);
$toolsCostPlanning = 0;
$allCost = $humanCostPlanning + $materialCostPlanning + $toolsCostPlanning;
return $allCost;
}
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")
->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)
->get();
$totalCost = 0;
foreach ($dataHuman as $human) {
$totalCost += $this->calculateHumanCost($human, $activity_id);
}
return $totalCost;
}
private function calculateHumanCost($human, $activity_id)
{
$activity = Activity::find($activity_id);
$duration = $activity->duration;
$standarRate = $human->standart_rate;
$maxUsed = $human->max_used/100;
if ($human->uom_standart_rate == "Hour") {
$totalCost = ($standarRate*8*$duration)*$maxUsed;
return $totalCost;
}
$totalCost = ($standarRate*$duration)*$maxUsed;
return $totalCost;
}
private function calculateMaterialCost($activity_id, $proyek_id)
{
$totalCost = AssignMaterial::selectRaw("COALESCE(qty_planning,0)*COALESCE(budget,0) as totalCost")
->where("proyek_id", $proyek_id)
->where("activity_id", $activity_id)
->sum(AssignMaterial::raw("COALESCE(qty_planning, 0) * COALESCE(budget, 0)"));
return $totalCost;
}
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";
// $token = config('api.adw_token');
$response = $this->curlRequest($url);
return $response;
}
private function curlRequest($url){
$ch = curl_init();
// $headers = [
// 'Authorization: '.$token
// ];
curl_setopt($ch, CURLOPT_URL, $url);
// curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
if ($response === false)
$response = curl_error($ch);
curl_close($ch);
return json_decode($response);
}
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
);
ReportK3Detail::create($dataNew);
}
}
}

175
app/Http/Controllers/DashboardBoDController.php

@ -10,19 +10,22 @@ use App\Models\User;
use App\Models\UserToVersionGantt;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
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);
@ -36,7 +39,8 @@ class DashboardBoDController extends Controller
return json_decode($response);
}
private function getInvoiceIntegration($search) {
private function getInvoiceIntegration($search)
{
if(empty($search))
return response()->json(['status'=>'error', 'message'=>'Empty query string!'], 400);
@ -51,30 +55,31 @@ class DashboardBoDController extends Controller
}
// to do
public function getCompanyCashFlow($year = '%') {
public function getCompanyCashFlow($year = '%')
{
$year = $this->interpolateYear($year);
$totalExpenditure = $totalInvoice = $totalPaidInvoice = 0;
// we can't use eloquent's sum() method because someone decided to use varchar as datatype in rencana_biaya field
$totalBudgets = Project::select(DB::raw('SUM(CAST("rencana_biaya" AS DOUBLE PRECISION))'))
->where('mulai_proyek', 'like', $year)
/* ->orWhere('akhir_proyek', 'like', $year) */
/* ->orWhere('akhir_proyek', 'like', $year) */
->pluck('sum')
->first();
$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;
}
@ -86,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,
@ -116,7 +122,8 @@ class DashboardBoDController extends Controller
], 200);
}
public function getTotalProjectPerScheduleHealth($year = '%'){
public function getTotalProjectPerScheduleHealth($year = '%')
{
$year = $this->interpolateYear($year);
$return = [
@ -126,47 +133,79 @@ class DashboardBoDController extends Controller
];
$projects = Project::where('mulai_proyek', 'like', $year)->get();
foreach($projects as $project) {
foreach ($projects as $index => $project) {
$project->scurve = MasterFunctionsHelper::getSCurve($project->id);
$selisihProgress = 0;
$planningProgress = 0;
$actualProgress = 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;
$actualProgress = !empty($actualArray) ? $actualArray[count($actualArray) - 1] : 0;
}
$selisihProgress = $planningProgress - $actualProgress;
try {
if(@$project->scurve['difference'] > 0 && @$project->scurve['difference'] <= 5)
$return['warning'] += 1;
elseif(@$project->scurve['difference'] > 5 && @$project->scurve['difference'] <= 100)
$return['behind-schedule'] += 1;
elseif(@$project->scurve['difference'] == 0)
$return['on-schedule'] += 1;
if ($selisihProgress > 0 && $selisihProgress <= 5){
$return['warning'] += 1;
$projects[$index]->status = 'warning';
}
elseif ($selisihProgress == 0){
$return['on-schedule'] += 1;
$projects[$index]->status = 'on-schedule';
}
else {
$return['behind-schedule'] += 1;
$projects[$index]->status = 'behind-schedule';
}
} catch (\Error $e) {
return response()->json(['msg' => $e->getMessage(), 'data' => $project], 200);
return response()->json(['msg' => $e->getMessage(), 'data' => $project], 200);
}
}
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 $index => $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)
$selisihProgress = 0;
$planningProgress = 0;
$actualProgress = 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;
$actualProgress = !empty($actualArray) ? $actualArray[count($actualArray) - 1] : 0;
}
$selisihProgress = $planningProgress - $actualProgress;
if ($selisihProgress > 0 && $selisihProgress <= 5){
$warning++;
elseif(@$project->scurve['difference'] > 5 && @$project->scurve['difference'] <= 100)
$behindSchedule++;
elseif(@$project->scurve['difference'] == 0)
}
elseif ($selisihProgress == 0){
$onSchedule++;
}
else {
$behindSchedule++;
}
}
$scheduleData->prepend($behindSchedule, 'behindSchedule');
$scheduleData->prepend($warning, 'warning');
$scheduleData->prepend($onSchedule, 'onSchedule');
$division->scheduleData = $scheduleData;
$divisions[$index]->scheduleData = $scheduleData;
}
return response()->json([
'data' => [
@ -175,7 +214,8 @@ class DashboardBoDController extends Controller
], 200);
}
public function getTotalProjectPerBudgetHealth($year = '%'){
public function getTotalProjectPerBudgetHealth($year = '%')
{
$year = $this->interpolateYear($year);
return response()->json([
'data' => [
@ -186,28 +226,30 @@ 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) */
/* ->orWhere('akhir_proyek', 'like', $year) */
->where('budget_health', $health)
->count();
}
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');
@ -215,7 +257,7 @@ class DashboardBoDController extends Controller
unset($division->children);
$division->budgetData = $budgetData;
}
foreach($divisions as $division){
foreach ($divisions as $division) {
}
return response()->json([
'data' => [
@ -224,14 +266,15 @@ 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) */
->count();
->where('mulai_proyek', 'like', $year)
/* ->orWhere('akhir_proyek', 'like', $year) */
->count();
}
return response()->json([
'data' => [
@ -240,24 +283,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','parent','color')
->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);
@ -268,27 +313,29 @@ 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) */
/* ->orWhere('akhir_proyek', 'like', $year) */
->where('divisi_id', $id)
->pluck('sum')
->first();
}
public function getTotalProjectValuePerDivision($year = '%') {
public function getTotalProjectValuePerDivision($year = '%')
{
$year = $this->interpolateYear($year);
$divisions = Divisi::select('id','name')
$divisions = Divisi::select('id', 'name', 'color')
->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);
@ -300,16 +347,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,
@ -319,8 +367,12 @@ 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(); */
$project->scurve = MasterFunctionsHelper::getSCurve($project->id);
$project->manPowers = UserToVersionGantt::where('version_gantt_id', $lastGantt['last_gantt_id'])->count();
if (!isset($lastGantt['last_gantt_id'])) {
$project->manPowers = 0;
} else {
$project->manPowers = UserToVersionGantt::where('version_gantt_id', $lastGantt['last_gantt_id'])->count();
$project->scurve = MasterFunctionsHelper::getSCurve($project->id);
}
$project->lastGanttId = MasterFunctionsHelper::getLatestGantt($project->id);
}
@ -330,4 +382,3 @@ class DashboardBoDController extends Controller
], 200);
}
}

213
app/Http/Controllers/DivisiController.php

@ -1,99 +1,114 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Divisi;
class DivisiController extends Controller
{
private function getAllChildren($divisi, $depth = 0, $array = []) {
$divisi->depth = $depth;
array_push($array, $divisi);
foreach($divisi->children as $child){
$array = $this->getAllChildren($child, $depth + 1, $array);
}
return $array;
}
public function add(Request $request){
$this->validate($request, [
'name' => 'required',
'description' => 'string',
'parent' => 'integer'
]);
$data = $request->all();
$data['created_by'] = $this->currentName;
$result = Divisi::create($data);
if(!$result)
return response()->json(['status'=>'failed','message'=>'Failed to add data','code'=> 500]);
return response()->json(['status'=>'success','message'=>'Data created!','code'=>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);
$data = Divisi::find($id);
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'=> 'Update failed!','code'=> 500], 500);
return response()->json(['status'=>'success','message'=>'Data added!','code'=>200], 200);
}
public function delete($id)
{
if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
$data = Divisi::find($id);
if(!$data)
return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404);
$delete = $data->delete();
if(!$delete)
return response()->json(['status'=>'failed','message'=> 'Delete failed!','code'=> 500], 500);
return response()->json(['status'=>'success','message'=> 'Data deleted!','code'=> 200], 200);
}
public function search()
{
return $this->list();
// cant use builder for this case
}
public function list()
{
$parentMenus = Divisi::whereNull('parent')->with('children')->get();
$divisions = [];
foreach($parentMenus as $menu){
$childs = $this->getAllChildren($menu);
foreach($childs as $d){
$d->displayName = ' ' . $d->name;
for($i=0; $i < $d->depth; $i++){
$d->displayName = '--' . $d->displayName ;
}
array_push($divisions, $d);
}
}
$countData = count($divisions);
if($countData == 0)
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
return response()->json(['status'=>'success','code'=>200,'data'=> $divisions, 'totalRecord'=> $countData], 200);
}
}
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Divisi;
class DivisiController extends Controller
{
private function getAllChildren($divisi, $depth = 0, $array = []) {
$divisi->depth = $depth;
array_push($array, $divisi);
foreach($divisi->children as $child){
$array = $this->getAllChildren($child, $depth + 1, $array);
}
return $array;
}
public function add(Request $request){
$this->validate($request, [
'name' => 'string|required|unique:m_divisi,name',
'description' => 'nullable|string',
'parent' => 'nullable|integer',
'color'=>'nullable|string|max:10'
]);
$data = $request->all();
$data['created_by'] = $this->currentName;
$result = Divisi::create($data);
if(!$result)
return response()->json(['status'=>'failed','message'=>'Failed to add data','code'=> 500]);
return response()->json(['status'=>'success','message'=>'Data created!','code'=>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);
$this->validate($request, [
'name' => 'string|required',
'description' => 'nullable|string',
'parent' => 'nullable|integer'
]);
$data = Divisi::find($id);
$request->name !== $data['name'] ? $this->validate($request,['name'=>'unique:m_divisi,name']) : '';
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'=> 'Update failed!','code'=> 500], 500);
return response()->json(['status'=>'success','message'=>'Data added!','code'=>200], 200);
}
public function delete($id)
{
if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
$data = Divisi::find($id);
if(!$data)
return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404);
$delete = $data->delete();
if(!$delete)
return response()->json(['status'=>'failed','message'=> 'Delete failed!','code'=> 500], 500);
return response()->json(['status'=>'success','message'=> 'Data deleted!','code'=> 200], 200);
}
public function search(Request $request)
{
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'm_divisi');
$builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count'];
$dataGet = $builder->get();
$totalRecord = $countBuilder->count();
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
//return $this->list();
// cant use builder for this case
}
public function list()
{
$parentMenus = Divisi::whereNull('parent')->with('children')->get();
$divisions = [];
foreach($parentMenus as $menu){
$childs = $this->getAllChildren($menu);
foreach($childs as $d){
$d->displayName = ' ' . $d->name;
for($i=0; $i < $d->depth; $i++){
$d->displayName = '--' . $d->displayName ;
}
array_push($divisions, $d);
}
}
$countData = count($divisions);
if($countData == 0)
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
return response()->json(['status'=>'success','code'=>200,'data'=> $divisions, 'totalRecord'=> $countData], 200);
}
}

128
app/Http/Controllers/HierarchyFtthController.php

@ -4,6 +4,8 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\HierarchyFtth;
use App\Models\VersionGantt;
use Illuminate\Support\Facades\Log;
class HierarchyFtthController extends Controller
{
@ -38,9 +40,11 @@ class HierarchyFtthController extends Controller
$hierarchyFtth = HierarchyFtth::create($attributes);
return response()->json([
'status'=>'success',
'code' => 200,
'message' => 'Hierarchy FTTH created successfully.',
'data' => $hierarchyFtth
]);
],200);
} catch (\Exception $e) {
return response()->json([
'message' => 'Failed to create hierarchy FTTH.',
@ -71,7 +75,7 @@ class HierarchyFtthController extends Controller
return response()->json([
'message' => 'Hierarchy FTTH updated successfully.',
'data' => $hierarchyFtth
]);
],200);
} catch (\Exception $e) {
return response()->json([
'message' => 'Failed to update hierarchy FTTH.',
@ -89,7 +93,7 @@ class HierarchyFtthController extends Controller
return response()->json([
'message' => 'Hierarchy FTTH deleted successfully.',
'data' => $hierarchyFtth
]);
],200);
} catch (\Exception $e) {
return response()->json([
'message' => 'Failed to delete hierarchy FTTH.',
@ -97,14 +101,104 @@ class HierarchyFtthController extends Controller
], 500);
}
}
public function countProgress($project_id) {
$ftthIds = VersionGantt::select('hierarchy_ftth_id')
->where('proyek_id', $project_id)
->groupBy('hierarchy_ftth_id')
->get();
if($ftthIds){
foreach ($ftthIds as $ftthId) {
$gantts = VersionGantt::where('hierarchy_ftth_id', $ftthId->hierarchy_ftth_id)->sum('progress');
$bobot_planning = VersionGantt::where('hierarchy_ftth_id', $ftthId->hierarchy_ftth_id)->sum('bobot');
$ganttCount = VersionGantt::where('hierarchy_ftth_id', $ftthId->hierarchy_ftth_id)->count();
$ftth = HierarchyFtth::find($ftthId->hierarchy_ftth_id);
if($ftth){
$round = $gantts/$ganttCount;
$round_bobot = $bobot_planning/$ganttCount;
$ftth->progress = round($round, 2);
$ftth->bobot_planning = round($round_bobot, 2);
try {
$ftth->save();
} catch (\Exception $e) {
// Log the error or handle it in some other way
Log::error($e->getMessage());
}
if($ftth->parent_id){
$this->countParent($ftth);
}
}
}
}
}
public function countParent($ftth){
$parent = HierarchyFtth::find($ftth->parent_id);
$children = HierarchyFtth::where('parent_id', $ftth->parent_id)->sum('progress');
$childrenCount = HierarchyFtth::where('parent_id', $ftth->parent_id)->count();
if($parent){
$round = $children/$childrenCount;
$parent->progress = round($round, 2);
try {
$parent->save();
} catch (\Exception $e) {
// Log the error or handle it in some other way
Log::error($e->getMessage());
}
if($parent->parent_id) {
$this->countParent($parent);
}
}
}
public function getTreeByGantt($gantt_id)
{
$finalData = [];
$gantt = VersionGantt::find($gantt_id);
if ($gantt->hierarchy_ftth_id) {
$ftth = HierarchyFtth::find($gantt->hierarchy_ftth_id);
array_push($finalData, $ftth);
if($ftth->parent_id){
$this->getParents($finalData, $ftth->parent_id);
}
} else {
return response()->json(['status'=>'success','data'=>$finalData,'code'=>200], 200);
}
return response()->json(['status'=>'success','data'=>$finalData,'code'=>200], 200);
}
public function getParents(&$data, $id){
$ftth = HierarchyFtth::find($id);
array_push($data, $ftth);
if ($ftth->parent_id) {
$this->getParents($data, $ftth->parent_id);
}
}
public function getTreeByProject($project_id)
{
$this->countProgress(intval($project_id));
$data = HierarchyFtth::where('project_id', $project_id)->whereNull('parent_id')->orderByRaw('id ASC')->get();
$finalData = [];
foreach($data as $objRow){
$objRow->children = $this->getChildren($project_id, $objRow->id);
$objRow->key = rand(1, 1000);
if (VersionGantt::where('hierarchy_ftth_id', $objRow->id)->exists()) {
$dataGantt = VersionGantt::where('hierarchy_ftth_id', $objRow->id)->get();
$progress = $this->ganttProgress('hierarchy_ftth_id', $objRow->id);
foreach ($dataGantt as $gantt) {
$gantt->key = $objRow->key;
foreach ($progress as $p) {
if ($p->id == $gantt->id) {
$gantt->progress = $p->persentase_progress;
$gantt->bobot_planning = $p->bobot_planning ? $p->bobot_planning : 0;
}
}
}
$objRow->dataGantt = $dataGantt;
}
$objRow->children = $this->getChildren($project_id, $objRow->id);
$finalData[] = $objRow;
}
@ -115,11 +209,37 @@ class HierarchyFtthController extends Controller
{
$finalData = [];
$data = HierarchyFtth::where('project_id', $project_id)->where('parent_id', $parent_id)->orderByRaw('id ASC')->get();
foreach($data as $objRow){
$objRow->key = rand(1, 1000);
if (VersionGantt::where('hierarchy_ftth_id', $objRow->id)->exists()) {
$dataGantt = VersionGantt::where('hierarchy_ftth_id', $objRow->id)->get();
$progress = $this->ganttProgress('hierarchy_ftth_id', $objRow->id);
foreach ($dataGantt as $gantt) {
$gantt->key = $objRow->key;
foreach ($progress as $p) {
if ($p->id == $gantt->id) {
$gantt->progress = $p->persentase_progress;
$gantt->bobot_planning = $p->bobot_planning ? $p->bobot_planning : 0;
}
}
}
$objRow->dataGantt = $dataGantt;
}
$objRow->children = $this->getChildren($project_id, $objRow->id);
$finalData[] = $objRow;
}
return $finalData;
}
public function ganttProgress($column, $value){
$progress = VersionGantt::select('m_version_gantt.id','m_activity.persentase_progress', 'm_activity.bobot_planning')
->join('m_activity', 'm_version_gantt.id', '=', 'm_activity.version_gantt_id')
->where("m_version_gantt.".$column, $value)
->where('m_activity.type_activity', "project")
->where('m_activity.parent_id', null)
->get();
return $progress;
}
}

368
app/Http/Controllers/HumanResourceController.php

@ -1,169 +1,199 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\HumanResource;
use App\Models\UserToActivity;
use App\Models\UserToProyek;
class HumanResourceController extends Controller
{
public function add(Request $request){
$this->validate($request, [
'role_id' => 'required',
'name' => 'required',
'ktp_number' => 'required',
'employee_type' => 'required'
]);
$data = $request->all();
if(isset($request->password) && $request->password!=""){
$data['password'] = md5($request->password);
}
$result = HumanResource::create($data);
if($result){
return response()->json(['status'=>'success','message'=>'Human Resource Pool successfull created','code'=>200]);
}else{
return response()->json(['status'=>'failed','message'=>'Human Resource Pool failed created','code'=>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 = HumanResource::find($id);
if($result){
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200);
}else{
return response()->json(['status'=>'failed','message'=>'failed get data human resource, 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);
}
$humanresource = HumanResource::find($id);
$data = $request->all();
if(isset($request->password) && $request->password!="" ){
$data['password'] = md5($request->password);
}
if($humanresource){
$result = $humanresource->update($data);
}else{
return response()->json(['status'=>'failed','message'=>'data Human Resource Pool not found!','code'=>400], 400);
die();
}
if($result){
return response()->json(['status'=>'success','message'=>'Human Resource Pool successfully updated!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'Human Resource Pool failed updated!','code'=>400], 400);
}
}
public function delete($id)
{
$data = HumanResource::find($id);
if($data){
$delete = $data->delete();
}else{
return response()->json(['status'=>'failed','message'=>'data Human Resource Pool not found!','code'=>400], 400);
die();
}
if($delete){
return response()->json(['status'=>'success','message'=>'Human Resource Pool successfully deleted!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'Human Resource Pool failed deleted!','code'=>400], 400);
}
}
public function search(Request $request)
{
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'm_users');
$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 = HumanResource::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 human resource, please try again later!','code'=>400], 400);
}
}
public function select(Request $request){
$search = $request->query('search');
$idActivity = (int)$request->query('idact');
$idProyek = (int)$request->query('idProyek');
$forbidden = [];
if($idActivity && $idActivity > 0){
$dataF = UserToActivity::select("user_id")->where("activity_id", $idActivity)->get();
foreach($dataF as $val){
$forbidden[] = $val->user_id;
}
}
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();
}
return response()->json($data);
}
public function checkOldPassword(Request $request, $id)
{
if(!$id || (int) $id < 0 || $id==""){
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
die();
}
$data = $request->all();
if(isset($request->old_password) && $request->old_password!="" ){
$result = HumanResource::find($id);
$data['old_password'] = md5($request->old_password);
if($data['old_password'] !== $result->password) {
return response()->json(['status'=>'failed','message'=>"old password seems doesn't match in records. please try again.",'code'=>400], 400);
}
elseif($data['old_password'] === $result->password) {
return response()->json(['status'=>'success','message'=>"old password match",'data'=>$result,'code'=>200], 200);
}
}
else {
return response()->json(['status'=>'failed','message'=>'old_password is required!','code'=>400], 400);
}
}
}
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\HumanResource;
use App\Models\UserToActivity;
use App\Models\UserToProyek;
use Illuminate\Support\Facades\Artisan;
class HumanResourceController extends Controller
{
public function add(Request $request)
{
$this->validate($request, [
'role_id' => 'required',
'name' => 'required',
'ktp_number' => 'required|numeric|unique:m_users,ktp_number',
'employee_type' => 'required'
]);
$data = $request->all();
if (isset($request->password) && $request->password != "") {
$data['password'] = md5($request->password);
}
$result = HumanResource::create($data);
if ($result) {
return response()->json(['status' => 'success', 'message' => 'Human Resource Pool successfull created', 'code' => 200]);
} else {
return response()->json(['status' => 'failed', 'message' => 'Human Resource Pool failed created', 'code' => 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 = HumanResource::find($id);
if ($result) {
return response()->json(['status' => 'success', 'code' => 200, 'data' => $result], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'failed get data human resource, 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);
}
$humanresource = HumanResource::find($id);
$request->ktp_number !== $humanresource['ktp_number'] ? $this->validate($request,['ktp_number'=>'unique:m_users,ktp_number|numeric']) : '';
$request->email !== $humanresource['email'] ? $this->validate($request,['email'=>'unique:m_users,email|email']) : '';
$request->password ? $this->validate($request,['password'=>'required|min:8']) : '';
$data = $request->all();
if (isset($request->password) && $request->password != "") {
$data['password'] = md5($request->password);
}
if (isset($data['username']) && HumanResource::where('username', $data['username'])->where('id', '<>', $id)->exists()) {
return response()->json(['status' => 'failed', 'message' => 'Username already exists!', 'code' => 400], 400);
}
if ($humanresource) {
$result = $humanresource->update($data);
} else {
return response()->json(['status' => 'failed', 'message' => 'data Human Resource Pool not found!', 'code' => 400], 400);
die();
}
if ($result) {
return response()->json(['status' => 'success', 'message' => 'Human Resource Pool successfully updated!', 'code' => 200], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'Human Resource Pool failed updated!', 'code' => 400], 400);
}
}
public function delete($id)
{
$data = HumanResource::find($id);
if ($data) {
$delete = $data->delete();
} else {
return response()->json(['status' => 'failed', 'message' => 'data Human Resource Pool not found!', 'code' => 400], 400);
die();
}
if ($delete) {
return response()->json(['status' => 'success', 'message' => 'Human Resource Pool successfully deleted!', 'code' => 200], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'Human Resource Pool failed deleted!', 'code' => 400], 400);
}
}
public function search(Request $request)
{
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'm_users');
$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 = HumanResource::select('id', 'name', 'role_id')->get();
$countData = $data->count();
if ($data) {
return response()->json(['status' => 'success', 'code' => 200, 'data' => $data, 'totalRecord' => $countData], 200);
} else {
return response()->json(['status' => 'failed', 'message' => 'failed get list human resource, please try again later!', 'code' => 400], 400);
}
}
public function select(Request $request)
{
$search = $request->query('search');
$idActivity = (int)$request->query('idact');
$idProyek = (int)$request->query('idProyek');
$forbidden = [];
if ($idActivity && $idActivity > 0) {
$dataF = UserToActivity::select("user_id")->where("activity_id", $idActivity)->get();
foreach ($dataF as $val) {
$forbidden[] = $val->user_id;
}
}
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);
}
public function checkOldPassword(Request $request, $id)
{
if (!$id || (int) $id < 0 || $id == "") {
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
die();
}
$data = $request->all();
if (isset($request->old_password) && $request->old_password != "") {
$result = HumanResource::find($id);
$data['old_password'] = md5($request->old_password);
if ($data['old_password'] !== $result->password) {
return response()->json(['status' => 'failed', 'message' => "old password seems doesn't match in records. please try again.", 'code' => 400], 400);
} elseif ($data['old_password'] === $result->password) {
return response()->json(['status' => 'success', 'message' => "old password match", 'data' => $result, 'code' => 200], 200);
}
} else {
return response()->json(['status' => 'failed', 'message' => 'old_password is required!', 'code' => 400], 400);
}
}
public function sync()
{
Artisan::call('sync:integration-human-resources');
}
}

96
app/Http/Controllers/MapMonitoringController.php

@ -15,56 +15,62 @@ class MapMonitoringController extends Controller
// default map monitoring shows today's presence lat lon in the map
public function search(Request $request)
{
{
$dateNow = Carbon::today()->addHour(7)->format('Y-m-d');
// get distinct human assign project
$hr_assign_project = DB::table('assign_hr_to_proyek')
->select('user_id')
->whereIn('proyek_id', $request->project_id)
->distinct()
->get();
->select('user_id')
->whereIn('proyek_id', $request->project_id)
->distinct()
->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')
->join('m_users as mu', 'mu.id', '=', 'tcio.user_id')
->where('mu.id', $key->user_id)
->orderBy('tcio.id', 'DESC')
->first();
$project = DB::table('assign_hr_to_proyek as ahtp')
->select('ahtp.proyek_id as id', 'mp.nama as project_name')
->join('m_proyek as mp', 'mp.id', '=', 'ahtp.proyek_id')
->whereIn('ahtp.proyek_id', $request->project_id)
->where('ahtp.user_id', $key->user_id)
->get();
if($presensi && isset($presensi->user_id)){
->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.clock_in', 'DESC')
->first();
$project = DB::table('assign_hr_to_proyek as ahtp')
->select('ahtp.proyek_id as id', 'mp.nama as project_name')
->join('m_proyek as mp', 'mp.id', '=', 'ahtp.proyek_id')
->whereIn('ahtp.proyek_id', $request->project_id)
->where('ahtp.user_id', $key->user_id)
->get();
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,
'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,
'projects' => $project
'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,
'clock_in_lat' => $presensi->clock_in_lat,
'clock_in_lng' => $presensi->clock_in_lng,
'clock_in_loc' => $presensi->clock_in_loc,
'clock_out_loc' => $presensi->clock_out_loc,
'name' => $presensi->fullname,
'image_selfie' => isset($image->image) ? $image->image : '-',
'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,12 +78,12 @@ 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);
}
}
}
}

310
app/Http/Controllers/MenuController.php

@ -1,151 +1,159 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Menu;
use App\Models\RoleMenu;
class MenuController extends Controller
{
public function add(Request $request)
{
$this->validate($request, [
'icon' => 'required',
'name' => 'required',
'url' => 'required',
'sequence' => 'required',
]);
$data = $request->all();
$data['created_by'] = $this->currentName;
$result = Menu::create($data);
if($result){
return response()->json(['status'=>'success','message'=>'add data menu successfully!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'add data menu 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 = Menu::find($id);
if($result){
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200);
}else{
return response()->json(['status'=>'failed','message'=>'failed get data menu, 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 = Menu::find($id);
if($data){
$result = $data->update($request->all());
}else{
return response()->json(['status'=>'failed','message'=>'data menu not found!','code'=>400], 400);
die();
}
if($result){
return response()->json(['status'=>'success','message'=>'data menu successfully updated!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'data menu failed updated!','code'=>400], 400);
}
}
public function delete($id)
{
$data = Menu::find($id);
if($data){
$delete = $data->delete();
}else{
return response()->json(['status'=>'failed','message'=>'data menu not found!','code'=>400], 400);
die();
}
if($delete){
return response()->json(['status'=>'success','message'=>'data menu successfully deleted!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'data menu failed deleted!','code'=>400], 400);
}
}
public function search(Request $request)
{
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'm_menu');
$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 listMenu($id)
{
$dataParent = RoleMenu::select("m_menu.*")
->join('m_menu', 'm_menu.id', '=', 't_roles_menu.menu_id')
->join('m_roles', 'm_roles.id', '=', 't_roles_menu.role_id')
->whereNull('m_menu.parent_id')
->where('m_roles.id', $id)
->orderBy('m_menu.sequence', 'ASC')
->get();
$finalData = [];
foreach($dataParent as $data){
$data->children = $this->getChildrenMenu($data->id, $id);
$finalData[] = $data;
}
return response()->json(['status'=>'success','code'=>200,'data'=>$finalData], 200);
}
protected function getChildrenMenu($id, $role_id)
{
$dataChildren = RoleMenu::select("m_menu.*")
->join('m_menu', 'm_menu.id', '=', 't_roles_menu.menu_id')
->join('m_roles', 'm_roles.id', '=', 't_roles_menu.role_id')
->where('m_roles.id', $role_id)
->where('m_menu.parent_id', $id)
->orderBy('m_menu.sequence', 'ASC')
->get();
$children = [];
if($dataChildren){
foreach($dataChildren as $data)
{
$data->children = $this->getChildrenMenu($data->id, $role_id);
$children[] = $data;
}
}
return $children;
}
public function list()
{
$data = Menu::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 menu, please try again later!','code'=>400], 400);
}
}
}
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Menu;
use App\Models\RoleMenu;
class MenuController extends Controller
{
public function add(Request $request)
{
$this->validate($request, [
'icon' => 'required',
'name' => 'string|required|unique:m_menu,name',
'url' => 'required|unique:m_menu,url',
'sequence' => 'required|integer',
]);
$data = $request->all();
$data['created_by'] = $this->currentName;
$result = Menu::create($data);
if($result){
return response()->json(['status'=>'success','message'=>'add data menu successfully!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'add data menu 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 = Menu::find($id);
if($result){
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200);
}else{
return response()->json(['status'=>'failed','message'=>'failed get data menu, 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);
}
$this->validate($request, [
'icon' => 'required',
'name' => 'string|required',
'url' => 'required',
'sequence' => 'required|integer',
]);
$data = Menu::find($id);
$request->name !== $data['name'] ? $this->validate($request,['name'=>'unique:m_menu,name']) : '';
$request->url !== $data['url'] ? $this->validate($request,['url'=>'unique:m_menu,url']) : '';
if($data){
$result = $data->update($request->all());
}else{
return response()->json(['status'=>'failed','message'=>'data menu not found!','code'=>400], 400);
die();
}
if($result){
return response()->json(['status'=>'success','message'=>'data menu successfully updated!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'data menu failed updated!','code'=>400], 400);
}
}
public function delete($id)
{
$data = Menu::find($id);
if($data){
$delete = $data->delete();
}else{
return response()->json(['status'=>'failed','message'=>'data menu not found!','code'=>400], 400);
die();
}
if($delete){
return response()->json(['status'=>'success','message'=>'data menu successfully deleted!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'data menu failed deleted!','code'=>400], 400);
}
}
public function search(Request $request)
{
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'm_menu');
$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 listMenu($id)
{
$dataParent = RoleMenu::select("m_menu.*")
->join('m_menu', 'm_menu.id', '=', 't_roles_menu.menu_id')
->join('m_roles', 'm_roles.id', '=', 't_roles_menu.role_id')
->whereNull('m_menu.parent_id')
->where('m_roles.id', $id)
->orderBy('m_menu.sequence', 'ASC')
->get();
$finalData = [];
foreach($dataParent as $data){
$data->children = $this->getChildrenMenu($data->id, $id);
$finalData[] = $data;
}
return response()->json(['status'=>'success','code'=>200,'data'=>$finalData], 200);
}
protected function getChildrenMenu($id, $role_id)
{
$dataChildren = RoleMenu::select("m_menu.*")
->join('m_menu', 'm_menu.id', '=', 't_roles_menu.menu_id')
->join('m_roles', 'm_roles.id', '=', 't_roles_menu.role_id')
->where('m_roles.id', $role_id)
->where('m_menu.parent_id', $id)
->orderBy('m_menu.sequence', 'ASC')
->get();
$children = [];
if($dataChildren){
foreach($dataChildren as $data)
{
$data->children = $this->getChildrenMenu($data->id, $role_id);
$children[] = $data;
}
}
return $children;
}
public function list()
{
$data = Menu::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 menu, please try again later!','code'=>400], 400);
}
}
}

1123
app/Http/Controllers/PresenceController.php

File diff suppressed because it is too large Load Diff

355
app/Http/Controllers/ProjectCarausellController.php

@ -0,0 +1,355 @@
<?php
namespace App\Http\Controllers;
use App\Models\{
User,
Project,
Activity,
HierarchyFtth,
ProjectComment,
VersionGantt,
UserToProyek,
UserToActivity,
Presence
};
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Helpers\MasterFunctionsHelper;
use Carbon\Carbon;
class ProjectCarausellController extends Controller
{
// public function invoke($id)
// {
// $dateStart = Carbon::now()->startOfDay();
// $dateEnd = Carbon::now()->endOfDay();
// // Mengatur waktu awal bulan dan mengurangkan 1 tahun
// $startDate = Carbon::now()->startOfMonth()->subYear()->format('Y-m-d');
// // Mengatur waktu saat ini dan mengurangkan 1 tahun
// $endDate = Carbon::now()->subYear()->format('Y-m-d');
// if(empty($id) || !is_int((int)$id)){
// return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
// }
// $result = Project::select('id','nama','budget_health','kode_sortname','pm_id','rencana_biaya','company','scurve','calculation_status')->find($id);
// if(!$result){
// return response()->json(['status'=>'failed','message'=> 'Project not found!','code'=> 404], 404);
// }
// $ganttData = VersionGantt::where('proyek_id', $id)
// ->select('id', 'name_version','hierarchy_ftth_id','cost_to_complete')
// ->get();
// // Get Id Gantt & hierarchy_ftth_id
// $gantt_id = $ganttData->pluck('id')->toArray();
// $hierarchy_ftth_id = $ganttData->pluck('hierarchy_ftth_id')->toArray();
// // Heararchy
// $finalData = [];
// if($hierarchy_ftth_id){
// $ftth = HierarchyFtth::whereIn('id',$hierarchy_ftth_id)->get();
// if($ftth->first() != null)
// {
// array_push($finalData, $ftth->first());
// }
// if($ftth->where('parent_id','!=', null)->first()){
// $this->getParents($finalData, $ftth->pluck('parent_id')->toArray());
// }
// } else {
// return $finalData;
// }
// // SCurve
// $SCurve = MasterFunctionsHelper::getSCurveCarausell($result['id'],$gantt_id,'week');
// // Overdue Activities
// $endDate = Activity::where('proyek_id', $result['id'])
// ->orderByDesc('end_date')
// ->value('end_date');
// $overdueActivities = Activity::whereIn('version_gantt_id', $gantt_id)->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->whereDate('end_date','<=',$endDate)->orderBy('end_date', 'asc')->get();
// // Project Comment
// $projectComment = ProjectComment::query()
// ->select('project_id','gantt_id','comment','created_at')
// ->where('project_id',$result['id'])
// ->whereIn('gantt_id',$gantt_id)
// ->get();
// // Manpower
// $manCount = UserToProyek::where('proyek_id', $result['id'])->count();
// // Assigned
// $utAct = UserToActivity::query()
// ->whereIn('version_gantt_id', $gantt_id)
// ->get();
// // Actual
// $presence = Presence::whereBetween('clock_in', [$dateStart, $dateEnd])
// ->select('m_users.name','m_users.ktp_number')
// ->join('m_users','t_clock_in_out.user_id','m_users.id')
// ->get();
// // Report distribution
// $reportsDistribution = 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')
// ->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')
// ->join('m_users as u', 'u.id', '=', 'ram.user_id')
// ->where('ama.proyek_id', '=', $result['id'])
// ->whereNotNull('ram.lat')
// ->whereBetween('ram.report_date', [$startDate, $startDate]);
// // Check Existing
// $actualStartExist = Activity::whereIn('version_gantt_id',$gantt_id)->whereNotNull('actual_start')->exists();
// $actualEndExist = Activity::whereIn('version_gantt_id',$gantt_id)->exists();
// $query = Activity::query()->whereIn('version_gantt_id', $gantt_id);
// // Start
// if ($actualStartExist) {
// $startDate = $query->select('version_gantt_id',DB::raw('MIN(start_date) as min_start'))
// ->groupBy('version_gantt_id')
// ->get();
// } else {
// $startDate = $query->select('version_gantt_id',DB::raw('MIN(start_date) as min_start','version_gantt_id'))
// ->groupBy('version_gantt_id')
// ->orderBy('min_start', 'ASC')
// ->get();
// }
// // End
// if($actualEndExist)
// {
// $maxIds = $query->selectRaw('MAX(id) as max_id')
// ->groupBy('version_gantt_id')
// ->pluck('max_id', 'version_gantt_id');
// $endDate = Activity::whereIn('id', $maxIds)->select('end_date','version_gantt_id')->get();
// }
// $plannedStart = $query->selectRaw('MIN(planned_start) as min_planned_start, version_gantt_id')
// ->groupBy('version_gantt_id')
// ->orderBy('min_planned_start')
// ->get();
// $plannedEnd = $query->selectRaw('MAX(planned_end) as max_planned_end, version_gantt_id')
// ->groupBy('version_gantt_id')
// ->orderByDesc('max_planned_end')
// ->get();
// $projectManager = User::whereId($result['pm_id'])->value('name');
// $key =1;
// foreach($ganttData as $gantt)
// {
// $pStart =$plannedStart->where('version_gantt_id',$gantt['id'])->first();
// $actStart =$startDate->where('version_gantt_id',$gantt['id'])->first();
// $actEnd =$endDate->where('version_gantt_id',$gantt['id'])->first();
// $pEnd =$plannedEnd->where('version_gantt_id',$gantt['id'])->first();
// $matchingActivities = $overdueActivities->where('version_gantt_id', $gantt['id']);
// $matchingProjectComment = $projectComment->where('version_gantt_id', $gantt['id']);
// $usAtc = $utAct->where('version_gantt_id', $gantt['id']);
// $arr[] =
// [
// 'gantt_id'=>$gantt['id'],
// 'projectManager'=>$projectManager,
// 'name_version'=>$gantt['name_version'],
// 'cost_to_complete'=>$gantt['cost_to_complete'],
// 'schedule' => [
// 'plannedStart'=> $pStart['min_planned_start'],
// 'actual_start'=>$actStart['min_start'],
// 'plannedFinish'=>$pEnd['max_planned_end'],
// 'estimatedFinish'=>$actEnd['end_date']
// ],
// 'manpower'=>$manCount,
// 'assigned'=>$usAtc->toArray(),
// 'actual'=>count($presence->toArray()),
// 'overdue_activities'=>$matchingActivities->toArray(),
// 'project_comment'=>$matchingProjectComment->toArray(),
// 'hierarchy'=>$finalData,
// 'proyek'=>$result,
// 'key'=>$key++
// ];
// }
// return response()->json(['status'=>'success','code'=> 200,'data'=>$arr,'report_distribution'=>$reportsDistribution,'sCurve'=>$SCurve, 'count'=>count($arr)], 200);
// }
// public function getParents(&$data, $id){
// $ftth = HierarchyFtth::whereIn('id',$id)->get();
// array_push($data, $ftth);
// if ($ftth->pluck('parent_id')->toArray()) {
// $this->getParents($data, $ftth->pluck('parent_id')->toArray());
// }
// }
public function invoke()
{
// Data Master
// Mengatur waktu awal bulan dan mengurangkan 1 tahun
$startDate = Carbon::now()->startOfMonth()->subYear()->format('Y-m-d');
// Mengatur waktu saat ini dan mengurangkan 1 tahun
$endDate = Carbon::now()->subYear()->format('Y-m-d');
$ganttData = VersionGantt::query()
->select('id', 'name_version','hierarchy_ftth_id','cost_to_complete','proyek_id')
->get();
$projectData = Project::query()
->select("id","nama","kode_sortname","pm_id","budget_health","calculation_status","mulai_proyek","akhir_proyek","rencana_biaya","company","scurve")
->get();
// nested looping
$arr = [];
foreach($projectData as $project) {
$ganttForProject = [];
foreach ($ganttData as $gantt) {
if ($gantt['proyek_id'] === $project['id']) {
// Gantt
$ganttForProject[] = [
"gantt_id" => $gantt['id'],
'proyek_id' => $gantt['proyek_id'],
"name_version" => $gantt['name_version'],
"hierarchy_ftth_id" => $gantt['hierarchy_ftth_id'],
"cost_to_complete" => $gantt['cost_to_complete'],
];
// Activity
$activity = Activity::query()
->select('id','name','proyek_id','version_gantt_id','type_activity','parent_id','kode_sortname','rencana_biaya','start_date','end_date','biaya_actual','persentase_bobot','persentase_progress','planned_start','planned_end','actual_start','actual_end')
->whereNull('parent_id')
->where([
["proyek_id", $project['id']],
["version_gantt_id", $gantt['id']]
])
->first();
$actualStartExist = Activity::query()
->where('version_gantt_id', $gantt['id'])
->whereNotNull('actual_start')
->exists();
$actualEndExist = Activity::query()
->where('version_gantt_id', $gantt['id'])
->exists();
$query = Activity::where('version_gantt_id', $gantt['id']);
if ($actualStartExist) {
$startDate = $query->orderBy('actual_start')->value('start_date');
} else {
$startDate = $query->orderBy('start_date')->value('start_date');
}
if($actualEndExist)
{
$maxEndDate = $query->max('id');
$endDate = $query->where('id',$maxEndDate)->first()->end_date;
}
$plannedStart = Activity::where('version_gantt_id', $gantt['id'])
->orderBy('planned_start')
->value('planned_start');
$plannedEnd = Activity::where('version_gantt_id', $gantt['id'])
->orderByDesc('planned_end')
->value('planned_end');
// SCurve
$req = (object)[
'project_id' => $project['id'],
'gantt_id' => $gantt['id'],
'period' => 'week',
];
$SCurve = MasterFunctionsHelper::getSCurveCarausell($req);
// Overdue
$endDate = Activity::where('proyek_id', $project['id'])
->orderByDesc('end_date')
->value('end_date');
$overdueActivities = Activity::query()
->where([
['version_gantt_id', $gantt['id']],
['persentase_progress', '!=', 100]
])
->whereNotNull('parent_id')
->whereDate('end_date','<=',$endDate)
->orderBy('end_date', 'asc')
->get();
// Manpower
$manCount = UserToProyek::where('proyek_id', $project['id'])->count();
// Assigned
$assigned = UserToActivity::query()
->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();
// Project Comment
$projectComment = ProjectComment::query()
->select('m_users.name','m_users.username','m_project_comment.project_id','m_project_comment.gantt_id','m_project_comment.comment','m_project_comment.created_at')
->join('m_users','m_project_comment.sender_id','m_users.id')
->where([
['project_id',$project['id']],
['gantt_id',$gantt['id']]
])
->get();
// Hierarchy
$finalData = [];
$ganttHierarchy = VersionGantt::find($gantt['id']);
if ($ganttHierarchy->hierarchy_ftth_id) {
$ftth = HierarchyFtth::find($ganttHierarchy->hierarchy_ftth_id);
array_push($finalData, $ftth);
if($ftth->parent_id){
$this->getParents($finalData, $ftth->parent_id);
}
}else{
$finalData = $finalData;
}
$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')
->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')
->join('m_users as u', 'u.id', '=', 'ram.user_id')
->where('ama.proyek_id', '=', $project['id'])
->whereNotNull('ram.lat')
->whereBetween('ram.report_date', [$startDate, $endDate]);
}
}
$projectManager = User::where('id', $project['pm_id'])->value('name');
$arr[]= [
"project"=> [
"id"=>$project['id'],
"pm_id"=>$project['pm_id'],
"nama"=>$project['nama'],
"kode_sortname"=>$project['kode_sortname'],
"budget_health"=>$project['budget_health'],
"calculation_status"=>$project['calculation_status'],
"mulai_proyek"=>$project['mulai_proyek'],
"akhir_proyek"=>$project['akhir_proyek'],
"rencana_biaya"=>$project['rencana_biaya'],
"company"=>$project['company'],
"scurve"=>$project['scurve'],
"gantt"=>$ganttForProject
],
"hierarchy"=>$finalData,
"manpower"=>$manCount,
"assigned"=>$assigned,
"actual"=>0,
"project_comment"=>$projectComment,
"project_manager"=> $projectManager,
"activity" => [
"data" => $activity,
"start_date"=>$startDate,
"end_date"=>$endDate,
"planned_start"=>$plannedStart,
"planned_end"=>$plannedEnd
],
"report_distribution"=>$reports,
"overdueActivities"=>$overdueActivities,
"SCurve"=>$SCurve
];
}
return response()->json(['status'=>'success','code'=> 200,'data'=>$arr, "count"=>count($arr)], 200);
}
public function getParents(&$data, $id){
$ftth = HierarchyFtth::find($id);
array_push($data, $ftth);
if ($ftth->parent_id) {
$this->getParents($data, $ftth->parent_id);
}
}
}

136
app/Http/Controllers/ProjectChecklistsController.php

@ -0,0 +1,136 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\ProjectChecklists;
class ProjectChecklistsController extends Controller
{
public function add(Request $request)
{
if ($request->status_exist==="") {
$request->merge(['status_exist' => true]);
}
$this->validate($request, [
'proyek_id' => 'required',
'item' => 'required|string',
'status_exist' => 'boolean'
]);
$data = $request->all();
$data['created_by'] = $this->currentName;
$result = ProjectChecklists::create($data);
if($result){
return response()->json(['status'=>'success','message'=>'add data project participants successfully!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'add data project participants 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 = ProjectChecklists::find($id);
if($result){
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200);
}else{
return response()->json(['status'=>'failed','message'=>'failed get data project participants, 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 = ProjectChecklists::find($id);
if($data){
$result = $data->update($request->all());
}else{
return response()->json(['status'=>'failed','message'=>'data project participants not found!','code'=>400], 400);
die();
}
if($result){
return response()->json(['status'=>'success','message'=>'data project participants successfully updated!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'data project participants failed updated!','code'=>400], 400);
}
}
public function delete($id)
{
$data = ProjectChecklists::find($id);
if($data){
$delete = $data->delete();
}else{
return response()->json(['status'=>'failed','message'=>'data project participants not found!','code'=>400], 400);
die();
}
if($delete){
return response()->json(['status'=>'success','message'=>'data project participants successfully deleted!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'data project participants failed deleted!','code'=>400], 400);
}
}
public function deleteByProyek($id)
{
$data = ProjectChecklists::where('proyek_id', $id)->delete();
if($data){
return response()->json(['status'=>'success','message'=>'data project participants successfully deleted!','code'=>200], 200);
}else{
return response()->json(['status'=>'success','message'=>'data project participants failed deleted, because data not found!','code'=>200], 200);
}
}
public function customWhere($where, $val)
{
$data = ProjectChecklists::where($where, $val)->orderBy('id', 'asc')->get();
if($data){
return response()->json(['status'=>'success','data'=> $data,'code'=>200], 200);
}else{
return response()->json(['status'=>'success','message'=>'data project participants not found!','code'=>400], 40);
}
}
public function search(Request $request)
{
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'project_charter_checklist');
$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 = ProjectChecklists::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 project participants, please try again later!','code'=>400], 400);
}
}
}

375
app/Http/Controllers/ProjectController.php

@ -2,33 +2,44 @@
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use DateTime;
use App\Models\Link;
use App\Models\User;
use App\Models\Image;
use App\Models\Holiday;
use App\Models\Project;
use App\Models\UserToProyek;
use App\Models\Activity;
use App\Models\UserToActivity;
use App\Models\User;
use App\Models\ReportK3;
use App\Jobs\ProcessSCurve;
use App\Models\AssignTools;
use App\Models\OfficeHours;
use App\Models\ProjectType;
use App\Models\ProjectPhase;
use App\Models\ProjectRisks;
use App\Models\UserToProyek;
use App\Models\VersionGantt;
use Illuminate\Http\Request;
use App\Models\HierarchyFtth;
use App\Models\ProjectIssues;
use App\Models\AssignMaterial;
use App\Models\DokumenProject;
use App\Models\FolderDocumentProyek;
use App\Models\ProjectCharter;
use App\Models\ProjectApproval;
use App\Models\ProjectPhase;
use App\Models\ProjectType;
use App\Models\ProjectMileStone;
use App\Models\ProjectParticipants;
use App\Models\ReportActivity;
use App\Models\ShowHideColumn;
use App\Models\VersionGantt;
use App\Models\Image;
use App\Models\CommentActivity;
use App\Models\Link;
use App\Models\UserToActivity;
use App\Models\ActivityDokumen;
use App\Models\Holiday;
use App\Models\ReportActivity;
use App\Models\OfficeHours;
use App\Models\CommentActivity;
use App\Models\ProjectApproval;
use App\Models\RequestMaterial;
use App\Models\ProjectMileStone;
use App\Models\ProjectChecklists;
use Illuminate\Support\Facades\DB;
use App\Models\ProjectParticipants;
use App\Models\FolderDocumentProyek;
use App\Models\ProjectToChecklistK3;
use App\Helpers\MasterFunctionsHelper;
use App\Models\ReportActivityMaterial;
use Illuminate\Support\Facades\Artisan;
const API_GEOLOCATION = "https://nominatim.oslogdev.com/search/ADDR?format=json&addressdetails=1&limit=1";
@ -39,7 +50,7 @@ class ProjectController extends Controller
{
$this->validate($request, [
'nama' => 'required',
'mulai_proyek' => 'required',
'mulai_proyek' => 'required',
'akhir_proyek' => 'required',
'rencana_biaya' => 'required',
'type_proyek_id' => 'required'
@ -63,11 +74,22 @@ class ProjectController extends Controller
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);
$result = Project::query()
->from('m_proyek AS mp')
->where('mp.id', $id)
->selectRaw('value_proyek,scoupe_of_work,kode_sortname,jumlah_stakeholder,nama,mulai_proyek,akhir_proyek,area_kerja,rencana_biaya,biaya_actual,company,pm_id,type_proyek_id,divisi_id,persentase_progress,keterangan,durasi_proyek,progress_by_worklog,currency_symbol,late_consequence,assumtion,currency_code,currency_name,project_objectives,considered_success_when,potential_risk,testing_environment,budget_health,phase_id,calculation_status');
if (!is_null($result->first()['divisi_id'])) {
$result->leftJoin('m_divisi', 'mp.divisi_id', '=', 'm_divisi.id')
->addSelect(DB::raw('m_divisi.name AS nama_divisi'));
}
$result = $result->first();
if(!$result)
return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404);
@ -143,6 +165,15 @@ class ProjectController extends Controller
ProjectApproval::where('proyek_id', $project_id)->delete();
ProjectMileStone::where('proyek_id', $project_id)->delete();
ProjectParticipants::where('proyek_id', $project_id)->delete();
ProjectChecklists::where('proyek_id', $project_id)->delete();
ProjectIssues::where('proyek_id', $project_id)->delete();
ProjectRisks::where('proyek_id', $project_id)->delete();
ProjectToChecklistK3::where('proyek_id', $project_id)->delete();
HierarchyFtth::where('project_id', $project_id)->delete();
AssignTools::where('proyek_id', $project_id)->delete();
OfficeHours::where('proyek_id', $project_id)->delete();
ReportK3::where('proyek_id', $project_id)->delete();
RequestMaterial::where('proyek_id', $project_id)->delete();
$this->deleteVersionGantt($project_id);
$this->deleteDokumenProject($project_id);
}
@ -209,6 +240,7 @@ class ProjectController extends Controller
$dataBuilder = $this->setUpPayload($payload, 'm_proyek');
$builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count'];
// $builder->where("selfTable.created_by",$this->currentName);
$dataGet = $builder->get();
$totalRecord = $countBuilder->count();
@ -217,64 +249,55 @@ class ProjectController extends Controller
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')
// ->where("created_by",$this->currentName)
->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 = $d->rencana_biaya - $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 = [];
}
}
$totalPlannedCost = $data->sum('plannedCost');
$totalPlannedCost = array_sum(array_map('intval', array_column($data->toArray(), 'plannedCost')));
$totalActualCost = $data->sum('actualCost');
$manpowers = User::count();
$projectsOnDanger = Project::where('budget_health', 'danger')->count();
$projectsOnDanger = Project::where('budget_health', 'overrun')->count();
$projectPhases = ProjectPhase::orderBy('order', 'asc')->pluck('name');
$projectTypes = ProjectType::orderBy('id', 'asc')->pluck('name');
try {
@ -288,7 +311,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();
@ -330,6 +353,63 @@ class ProjectController extends Controller
public function getSCurve(Request $request){
$data = MasterFunctionsHelper::getSCurve($request);
return response()->json(['status'=>'success','code'=>200, 'data' => $data], 200);
}
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);
}
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){
$data = MasterFunctionsHelper::getLinearSCurve($request);
return response()->json(['status'=>'success','code'=>200, 'data' => $data], 200);
}
public static function setSyncDate($activity_id, $activity, $report) {
$status = AssignMaterial::where('activity_id', $activity_id)->first();
if (!isset($status)) {
$reports = array(
'activity_id' => $activity_id,
'min_date' => new DateTime($activity->start_date),
'max_date' => new DateTime($activity->end_date),
'status' => 'open'
);
return $reports;
}
if (!isset($status->status_activity)) {
$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)
@ -343,31 +423,40 @@ class ProjectController extends Controller
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")
);
$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);
}
$successor = Link::where('t_activity_id', $activity->id)->first();
if ($successor) {
$predecessor = Activity::find($successor->s_activity_id);
$activity->start_date = $predecessor->end_date;
$end_date = new DateTime($activity->start_date);
$end_date->modify("+" . $activity->duration . " days");
$activity->end_date = $end_date->format("Y-m-d H:i:sO");
}
$activity->reports = $reports;
$activity->save();
}
/* 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++) {
$activity = Activity::find($reports[$i]['activity_id']);
$activity->start_date = $reports[$i]['min_date'];
$activity->end_date = $reports[$i]['max_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
$startDate = new DateTime($activity->start_date);
$endDate = new DateTime($activity->end_date);
$duration = MasterFunctionsHelper::countDays($activity->version_gantt_id, $startDate, $endDate);
$activity->duration = $duration;
$activity->actual_start = $reports[$i]['min_date'];
$activity->save();
}
@ -382,6 +471,8 @@ class ProjectController extends Controller
$activity->update([
"planned_start"=>$activity->start_date,
"planned_end"=>$activity->end_date,
"early_start"=>$activity->start_date,
"early_end"=>$activity->end_date,
]);
}
@ -389,18 +480,38 @@ class ProjectController extends Controller
}
public function getInvoiceIntegration(Request $request) {
$ganttCount = VersionGantt::where('proyek_id', $request->id)->count();
$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 = MasterFunctionsHelper::curlReq($url);
if (isset($request->gantt_id)) {
$response->data->total_cost = $response->data->total_cost / $ganttCount;
}
return response()->json(['status'=>'success', 'data'=> $response, 'code'=>200], 200);
}
public function detail($id){
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 detail(Request $request, $id, $gantt_id = null, $s_curve = null){
if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
@ -408,13 +519,56 @@ class ProjectController extends Controller
if(!$result)
return response()->json(['status'=>'failed','message'=> 'Data not found!','code'=> 404], 404);
$gantt = MasterFunctionsHelper::getLatestGantt($id);
if (!isset($gantt_id)) {
$gantt = MasterFunctionsHelper::getLatestGantt($id);
$ganttId = $gantt['last_gantt_id'];
} else {
$ganttId = $gantt_id;
}
$result->projectManager = User::where('id', $result->pm_id)->value('name');
$result->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], 200);
if (isset($s_curve)) {
$result->header = Activity::whereNull('parent_id')->where("proyek_id", $id)->first();
$actualStartExist = Activity::where('proyek_id', $id)->whereNotNull('actual_start')->exists();
if($result['type_proyek_id'] === 9)
{
$actualEndExist = Activity::where('proyek_id', $id)->exists();
$query = Activity::where('proyek_id', $id);
}else{
$actualEndExist = Activity::where('version_gantt_id', $ganttId)->exists();
$query = Activity::where('version_gantt_id', $ganttId);
}
} else {
$result->header = Activity::whereNull('parent_id')->where("proyek_id", $id)->where("version_gantt_id", $ganttId)->first();
$actualStartExist = Activity::where('version_gantt_id', $ganttId)->whereNotNull('actual_start')->exists();
$actualEndExist = Activity::where('version_gantt_id', $ganttId)->exists();
$query = Activity::where('version_gantt_id', $ganttId);
}
if ($actualStartExist) {
$startDate = $query->orderBy('actual_start')->value('start_date');
} else {
$startDate = $query->orderBy('start_date')->value('start_date');
}
if($actualEndExist)
{
$maxEndDate = $query->max('id');
$endDate = $query->where('id',$maxEndDate)->first()->end_date;
}
$plannedStart = Activity::where('version_gantt_id', $ganttId)
->orderBy('planned_start')
->value('planned_start');
$plannedEnd = Activity::where('version_gantt_id', $ganttId)
->orderByDesc('planned_end')
->value('planned_end');
$result->header->start_date = $startDate;
$result->header->end_date = $endDate;
$result->header->planned_start = $plannedStart;
$result->header->planned_end = $plannedEnd;
return response()->json(['status'=>'success','code'=> 200,'data'=>$result, 'gantt'=>$ganttId], 200);
}
public function getOverdueActivities(Request $request){
$payload = $request->all();
if(empty($payload['id']) || !is_int((int)$payload['id']))
@ -425,11 +579,23 @@ class ProjectController extends Controller
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
$overdueActivities = Activity::where('proyek_id', $payload['id'])->whereNotNull('parent_id')->where('persentase_progress', '!=', 100)->orderBy('end_date', 'asc')->get();
$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);
@ -451,14 +617,13 @@ class ProjectController extends Controller
->where('ama.proyek_id', '=', $payload['project_id'])
->whereNotNull('ram.lat')
->whereBetween('ram.report_date', [$payload['start_date'], $payload['end_date']]);
return response()->json(['status'=>'success', 'code'=> 200, 'data'=> $reports], 200);
}
public function getManpower($proyek_id){
$manPower = UserToProyek::where('proyek_id', $proyek_id)->get();
$manCount = $manPower->count();
return response()->json(['data'=>$manPower, 'totalRecord'=>$manCount]);
$manCount = UserToProyek::where('proyek_id', $proyek_id)->count();
return response()->json(['totalRecord'=>$manCount]);
}
public function getAssignedHR($gantt_id){

9
app/Http/Controllers/ProjectDokumenController.php

@ -94,7 +94,12 @@ class ProjectDokumenController extends Controller
if(!file_exists($this->pathDocument.$document->file))
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404);
$pathToFile = $this->pathDocument.$document->file;
return response()->download($pathToFile);
$pathToFile = $this->pathDocument.$document->file;
$name = pathinfo($pathToFile, PATHINFO_FILENAME) . "." . pathinfo($pathToFile, PATHINFO_EXTENSION);
$headers = [
'Content-Disposition' => 'attachment; filename="'.$name.'"'
];
// dd($name, $headers);
return response()->download($pathToFile, $name, $headers);
}
}

136
app/Http/Controllers/ProjectIssuesController.php

@ -0,0 +1,136 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\ProjectIssues;
class ProjectIssuesController extends Controller
{
public function add(Request $request)
{
if ($request->level_issue === "") {
$request->merge(['level_issue' => 0]);
}
$this->validate($request, [
'proyek_id' => 'required',
'description' => 'required|string',
'level_issue' => 'required|integer'
]);
$data = $request->all();
$data['created_by'] = $this->currentName;
$result = ProjectIssues::create($data);
if($result){
return response()->json(['status'=>'success','message'=>'add data project participants successfully!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'add data project participants 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 = ProjectIssues::find($id);
if($result){
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200);
}else{
return response()->json(['status'=>'failed','message'=>'failed get data project participants, 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 = ProjectIssues::find($id);
if($data){
$result = $data->update($request->all());
}else{
return response()->json(['status'=>'failed','message'=>'data project participants not found!','code'=>400], 400);
die();
}
if($result){
return response()->json(['status'=>'success','message'=>'data project participants successfully updated!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'data project participants failed updated!','code'=>400], 400);
}
}
public function delete($id)
{
$data = ProjectIssues::find($id);
if($data){
$delete = $data->delete();
}else{
return response()->json(['status'=>'failed','message'=>'data project participants not found!','code'=>400], 400);
die();
}
if($delete){
return response()->json(['status'=>'success','message'=>'data project participants successfully deleted!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'data project participants failed deleted!','code'=>400], 400);
}
}
public function deleteByProyek($id)
{
$data = ProjectIssues::where('proyek_id', $id)->delete();
if($data){
return response()->json(['status'=>'success','message'=>'data project participants successfully deleted!','code'=>200], 200);
}else{
return response()->json(['status'=>'success','message'=>'data project participants failed deleted, because data not found!','code'=>200], 200);
}
}
public function customWhere($where, $val)
{
$data = ProjectIssues::where($where, $val)->orderBy('id', 'asc')->get();
if($data){
return response()->json(['status'=>'success','data'=> $data,'code'=>200], 200);
}else{
return response()->json(['status'=>'success','message'=>'data project participants not found!','code'=>400], 40);
}
}
public function search(Request $request)
{
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'project_charter_issue');
$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 = ProjectIssues::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 project participants, please try again later!','code'=>400], 400);
}
}
}

137
app/Http/Controllers/ProjectRisksController.php

@ -0,0 +1,137 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\ProjectRisks;
class ProjectRisksController extends Controller
{
public function add(Request $request)
{
if ($request->level_risk === "") {
$request->merge(['level_risk' => 0]);
}
$this->validate($request, [
'proyek_id' => 'required',
'level_risk' => 'required|integer',
'description' => 'required|string',
'preventive_risk' => 'required|string'
]);
$data = $request->all();
$data['created_by'] = $this->currentName;
$result = ProjectRisks::create($data);
if($result){
return response()->json(['status'=>'success','message'=>'add data project participants successfully!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'add data project participants 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 = ProjectRisks::find($id);
if($result){
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200);
}else{
return response()->json(['status'=>'failed','message'=>'failed get data project participants, 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 = ProjectRisks::find($id);
if($data){
$result = $data->update($request->all());
}else{
return response()->json(['status'=>'failed','message'=>'data project participants not found!','code'=>400], 400);
die();
}
if($result){
return response()->json(['status'=>'success','message'=>'data project participants successfully updated!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'data project participants failed updated!','code'=>400], 400);
}
}
public function delete($id)
{
$data = ProjectRisks::find($id);
if($data){
$delete = $data->delete();
}else{
return response()->json(['status'=>'failed','message'=>'data project participants not found!','code'=>400], 400);
die();
}
if($delete){
return response()->json(['status'=>'success','message'=>'data project participants successfully deleted!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'data project participants failed deleted!','code'=>400], 400);
}
}
public function deleteByProyek($id)
{
$data = ProjectRisks::where('proyek_id', $id)->delete();
if($data){
return response()->json(['status'=>'success','message'=>'data project participants successfully deleted!','code'=>200], 200);
}else{
return response()->json(['status'=>'success','message'=>'data project participants failed deleted, because data not found!','code'=>200], 200);
}
}
public function customWhere($where, $val)
{
$data = ProjectRisks::where($where, $val)->orderBy('id', 'asc')->get();
if($data){
return response()->json(['status'=>'success','data'=> $data,'code'=>200], 200);
}else{
return response()->json(['status'=>'success','message'=>'data project participants not found!','code'=>400], 40);
}
}
public function search(Request $request)
{
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'project_charter_risk');
$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 = ProjectRisks::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 project participants, please try again later!','code'=>400], 400);
}
}
}

540
app/Http/Controllers/ReportActivityController.php

@ -1,270 +1,270 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\ReportActivity;
use App\Models\Activity;
use App\Models\Image;
use Datatables;
class ReportActivityController extends Controller
{
public function add(Request $request)
{
if($request->has('gantt')){
$this->validate($request, [
'activity_id' => 'required',
'user_id' => 'required',
'report_date' => 'required',
'job_count_report' => 'required'
]);
}else{
$this->validate($request, [
'activity_id' => 'required',
'user_id' => 'required',
'report_date' => 'required',
'job_count_report' => 'required',
'lat' => 'required',
'lon' => 'required',
]);
}
$data = $request->all();
$data['created_by'] = $this->currentName;
$result = ReportActivity::create($data);
if($result){
$this->countForProgress($request->activity_id);
if($request->hasFile("files")){
$this->uploadImage($request->file('files'), $result->id);
}
return response()->json(['status'=>'success','message'=>'add report activity, update progress activity successfully!','code'=>200,'last_inserted_id'=>$result->id], 200);
}else{
return response()->json(['status'=>'failed','message'=>'add report activity failed!','code'=>400], 400);
}
}
private function uploadImage($files, $ref_id)
{
$dokumen = $files;
$extension = $dokumen->extension();
$name = $ref_id.date("YmdHis").".".$extension;
$resultMove = $dokumen->move($this->pathImage, $name);
if($resultMove){
$data = [
'ref_id' => (int)$ref_id,
'image' => $name,
'category' => "report_activity"
];
$result = Image::create($data);
if($result){
return true;
}
}
}
public function edit($id){
if(!$id || (int) $id < 0 || $id==""){
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
die();
}
$result = ReportActivity::select("report_activity.*", "u.name as user_name")->where("report_activity.id", $id)->join("m_users as u", "u.id", "=", "report_activity.user_id")->first();
if($result){
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200);
}else{
return response()->json(['status'=>'failed','message'=>'failed get data report activity, 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 = ReportActivity::find($id);
if($data){
$dataUpdate = $request->all();
$result = $data->update($dataUpdate);
if($result){
if($request->hasFile("files")){
$this->updateImage($request->file('files'), $id);
}
$this->countForProgress($data->activity_id);
return response()->json(['status'=>'success','message'=>'data report activity successfully updated!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'data report activity failed updated!','code'=>400], 400);
}
}else{
return response()->json(['status'=>'failed','message'=>'data report activity not found!','code'=>400], 400);
die();
}
}
public function updateImage($files, $ref_id)
{
$image = Image::where("ref_id", $ref_id)->where("category", "report_activity")->first();
if($image){
if(file_exists($this->pathImage.$image->image)){
unlink($this->pathImage.$image->image);
}
$image->delete();
}
$dokumen = $files;
$extension = $dokumen->extension();
$name = $ref_id.date("YmdHis").".".$extension;
$resultMove = $dokumen->move($this->pathImage, $name);
if($resultMove){
$data = [
'ref_id' => (int)$ref_id,
'image' => $name,
'category' => "report_activity"
];
$result = Image::create($data);
if($result){
return true;
}
}
}
public function delete($id)
{
$data = ReportActivity::find($id);
if($data){
$delete = $data->delete();
}else{
return response()->json(['status'=>'failed','message'=>'data report activity not found!','code'=>400], 400);
die();
}
if($delete){
$image = Image::where("ref_id", $id)->where("category", "report_activity")->first();
if($image){
if(file_exists($this->pathImage.$image->image)){
unlink($this->pathImage.$image->image);
}
$image->delete();
}
return response()->json(['status'=>'success','message'=>'data report activity successfully deleted!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'data report activity failed deleted!','code'=>400], 400);
}
}
private function countForProgress($id)
{
$totalJobs = ReportActivity::where('activity_id', $id)->sum("job_count_report");
$dataActivity = Activity::find($id);
$jobsActivity = (int)$dataActivity->jumlah_pekerjaan;
if ($jobsActivity < 1) {
return false;
}
if ($totalJobs < 1) {
return false;
}
$persentaseActual = ($totalJobs/$jobsActivity)*100;
$dataUpdate = array(
"persentase_progress" => $persentaseActual,
"updated_by" => $this->currentName
);
return $dataActivity->update($dataUpdate);
}
public function search(Request $request)
{
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'report_activity');
$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 = ReportActivity::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 report activity, please try again later!','code'=>400], 400);
}
}
public function searchPoint(Request $request) {
$dataPayload = $request->all();
$reqActivityId = [];
foreach ($dataPayload['project_id'] as $val) {
$reqActivityId[] = $this->getActivityByProjectId($val);
}
$activity_id = [];
$getPoints = false;
if (count($reqActivityId) > 0) {
for ($i=0; $i < count($reqActivityId); $i++) {
if (count($reqActivityId[$i]) > 0) {
foreach($reqActivityId[$i] as $reqAct) {
array_push($activity_id, $reqAct->id);
}
}
}
}
if (count($activity_id) > 0) {
$getPoints = ReportActivity::select('report_activity.*', 'm_activity.name as activity_name', 'm_activity.jumlah_pekerjaan', 'm_proyek.nama as proyek_name')
->leftJoin('m_activity', 'm_activity.id', '=', 'report_activity.activity_id')
->leftJoin('m_proyek', 'm_proyek.id', '=', 'm_activity.proyek_id')
->whereIn('report_activity.activity_id', $activity_id)->get();
}
if($getPoints){
return response()->json(['status'=>'success','code'=>200,'data'=>$getPoints, 'totalRecord'=>count($getPoints)], 200);
}else{
return response()->json(['status'=>'failed','message'=>'failed get list points, please try again later!','code'=>400], 400);
}
}
public function getActivityByProjectId($projectId) {
$data = Activity::select('id')->where('proyek_id', $projectId)->get();
return $data;
}
public function datatables(Request $request){
$id_activity = $request->query('idact');
$data = ReportActivity::select("report_activity.*", "u.name as user_name")
->join("m_users as u", "u.id", "=", "report_activity.user_id")
->where('report_activity.activity_id', $id_activity)
->get();
return Datatables::of($data)
->addIndexColumn()
->addColumn('action', function($row){
$actionBtn = '<a href="javascript:void(0)" data-id="'.$row->id.'" class="delete btn btn-danger btn-sm btn_report_delete"><i class="fa fa-trash"></i></a>';
$actionBtn .= ' <a href="javascript:void(0)" data-id="'.$row->id.'" class="edit btn btn-primary btn-sm btn_report_edit"><i class="fa fa-edit"></i></a>';
return $actionBtn;
})
->editColumn('report_date', function($row) {
$date = date_create($row->report_date);
return date_format($date,"d-m-Y H:i:s");
})
->rawColumns(['action'])->make(true);
}
}
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\ReportActivity;
use App\Models\Activity;
use App\Models\Image;
use Datatables;
class ReportActivityController extends Controller
{
public function add(Request $request)
{
if($request->has('gantt')){
$this->validate($request, [
'activity_id' => 'required',
'user_id' => 'required',
'report_date' => 'required',
'job_count_report' => 'required'
]);
}else{
$this->validate($request, [
'activity_id' => 'required',
'user_id' => 'required',
'report_date' => 'required',
'job_count_report' => 'required',
'lat' => 'required',
'lon' => 'required',
]);
}
$data = $request->all();
$data['created_by'] = $this->currentName;
$result = ReportActivity::create($data);
if($result){
$this->countForProgress($request->activity_id);
if($request->hasFile("files")){
$this->uploadImage($request->file('files'), $result->id);
}
return response()->json(['status'=>'success','message'=>'add report activity, update progress activity successfully!','code'=>200,'last_inserted_id'=>$result->id], 200);
}else{
return response()->json(['status'=>'failed','message'=>'add report activity failed!','code'=>400], 400);
}
}
private function uploadImage($files, $ref_id)
{
$dokumen = $files;
$extension = $dokumen->extension();
$name = $ref_id.date("YmdHis").".".$extension;
$resultMove = $dokumen->move($this->pathImage, $name);
if($resultMove){
$data = [
'ref_id' => (int)$ref_id,
'image' => $name,
'category' => "report_activity"
];
$result = Image::create($data);
if($result){
return true;
}
}
}
public function edit($id){
if(!$id || (int) $id < 0 || $id==""){
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
die();
}
$result = ReportActivity::select("report_activity.*", "u.name as user_name")->where("report_activity.id", $id)->join("m_users as u", "u.id", "=", "report_activity.user_id")->first();
if($result){
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200);
}else{
return response()->json(['status'=>'failed','message'=>'failed get data report activity, 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 = ReportActivity::find($id);
if($data){
$dataUpdate = $request->all();
$result = $data->update($dataUpdate);
if($result){
if($request->hasFile("files")){
$this->updateImage($request->file('files'), $id);
}
$this->countForProgress($data->activity_id);
return response()->json(['status'=>'success','message'=>'data report activity successfully updated!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'data report activity failed updated!','code'=>400], 400);
}
}else{
return response()->json(['status'=>'failed','message'=>'data report activity not found!','code'=>400], 400);
die();
}
}
public function updateImage($files, $ref_id)
{
$image = Image::where("ref_id", $ref_id)->where("category", "report_activity")->first();
if($image){
if(file_exists($this->pathImage.$image->image)){
unlink($this->pathImage.$image->image);
}
$image->delete();
}
$dokumen = $files;
$extension = $dokumen->extension();
$name = $ref_id.date("YmdHis").".".$extension;
$resultMove = $dokumen->move($this->pathImage, $name);
if($resultMove){
$data = [
'ref_id' => (int)$ref_id,
'image' => $name,
'category' => "report_activity"
];
$result = Image::create($data);
if($result){
return true;
}
}
}
public function delete($id)
{
$data = ReportActivity::find($id);
if($data){
$delete = $data->delete();
}else{
return response()->json(['status'=>'failed','message'=>'data report activity not found!','code'=>400], 400);
die();
}
if($delete){
$image = Image::where("ref_id", $id)->where("category", "report_activity")->first();
if($image){
if(file_exists($this->pathImage.$image->image)){
unlink($this->pathImage.$image->image);
}
$image->delete();
}
return response()->json(['status'=>'success','message'=>'data report activity successfully deleted!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'data report activity failed deleted!','code'=>400], 400);
}
}
private function countForProgress($id)
{
$totalJobs = ReportActivity::where('activity_id', $id)->sum("job_count_report");
$dataActivity = Activity::find($id);
$jobsActivity = (int)$dataActivity->jumlah_pekerjaan;
if ($jobsActivity < 1) {
return false;
}
if ($totalJobs < 1) {
return false;
}
$persentaseActual = ($totalJobs/$jobsActivity)*100;
$dataUpdate = array(
"persentase_progress" => $persentaseActual,
"updated_by" => $this->currentName
);
return $dataActivity->update($dataUpdate);
}
public function search(Request $request)
{
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'report_activity');
$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 = ReportActivity::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 report activity, please try again later!','code'=>400], 400);
}
}
public function searchPoint(Request $request) {
$dataPayload = $request->all();
$reqActivityId = [];
foreach ($dataPayload['project_id'] as $val) {
$reqActivityId[] = $this->getActivityByProjectId($val);
}
$activity_id = [];
$getPoints = false;
if (count($reqActivityId) > 0) {
for ($i=0; $i < count($reqActivityId); $i++) {
if (count($reqActivityId[$i]) > 0) {
foreach($reqActivityId[$i] as $reqAct) {
array_push($activity_id, $reqAct->id);
}
}
}
}
if (count($activity_id) > 0) {
$getPoints = ReportActivity::select('report_activity.*', 'm_activity.name as activity_name', 'm_activity.jumlah_pekerjaan', 'm_proyek.nama as proyek_name')
->leftJoin('m_activity', 'm_activity.id', '=', 'report_activity.activity_id')
->leftJoin('m_proyek', 'm_proyek.id', '=', 'm_activity.proyek_id')
->whereIn('report_activity.activity_id', $activity_id)->get();
}
if($getPoints){
return response()->json(['status'=>'success','code'=>200,'data'=>$getPoints, 'totalRecord'=>count($getPoints)], 200);
}else{
return response()->json(['status'=>'failed','message'=>'failed get list points, please try again later!','code'=>400], 400);
}
}
public function getActivityByProjectId($projectId) {
$data = Activity::select('id')->where('proyek_id', $projectId)->get();
return $data;
}
public function datatables(Request $request){
$id_activity = $request->query('idact');
$data = ReportActivity::select("report_activity.*", "u.name as user_name")
->join("m_users as u", "u.id", "=", "report_activity.user_id")
->where('report_activity.activity_id', $id_activity)
->get();
return Datatables::of($data)
->addIndexColumn()
->addColumn('action', function($row){
$actionBtn = '<a href="javascript:void(0)" data-id="'.$row->id.'" class="delete btn btn-danger btn-sm btn_report_delete"><i class="fa fa-trash"></i></a>';
$actionBtn .= ' <a href="javascript:void(0)" data-id="'.$row->id.'" class="edit btn btn-primary btn-sm btn_report_edit"><i class="fa fa-edit"></i></a>';
return $actionBtn;
})
->editColumn('report_date', function($row) {
$date = date_create($row->report_date);
return date_format($date,"d-m-Y H:i:s");
})
->rawColumns(['action'])->make(true);
}
}

327
app/Http/Controllers/ReportActivityMaterialController.php

@ -1,140 +1,187 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\ReportActivityMaterial;
use App\Models\Activity;
use App\Models\AssignMaterial;
use Datatables;
class ReportActivityMaterialController extends Controller
{
private function sanitizeDecimal($number) {
$number = str_replace(".","",$number);
$number = str_replace(",",".",$number);
return $number;
}
public function add(Request $request){
$this->validate($request, [
'activity_id' => 'required',
'qty' => 'required'
]);
$activity = Activity::where('id', $request->activity_id)->first();
$start_date = $activity->start_date;
$start_date = substr($start_date, 0, 19); // remove the timezone offset
$startDate = new \DateTime(date("Y-m-d", strtotime($start_date)));
$reportDate = new \DateTime(date("Y-m-d", strtotime($request->report_date)));
$data = $request->all();
$data['created_by'] = $this->currentName;
/* $data['assign_material_id'] = AssignMaterial::where('activity_id', $request->activity_id)->pluck('id')->first(); */
$data['assign_material_id'] = $request->assign_material_id;
$data['qty'] = $this->sanitizeDecimal($data['qty']);
if($reportDate > $startDate){
$created = ReportActivityMaterial::create($data);
return response()->json(['status'=>'success','message'=>'Input progress report activity created','code'=>200,'data'=>array('report_id'=>$created->id)]);
} else {
return response()->json(['status'=>'failed','message'=>'Input progress report activity failed created','code'=>400,'data'=>null], 400);
}
}
public function updateStatusStartFinish(Request $request){
$payloadUpdate = array(
'start_activity' => $request->start_activity,
'finish_activity' => $request->finish_activity,
'status_activity' => $request->status_activity
);
$updateData = AssignMaterial::where('activity_id',$request->activity_id)
->update($payloadUpdate);
if($updateData){
if($request->status_activity == 'done'){
$dataUpdate = array(
"persentase_progress" => 100,
"updated_by" => $this->currentName
);
Activity::where('id', $request->activity_id)->update($dataUpdate);
}
return response()->json(['status'=>'success','message'=>'Update data status successfully ', 'code'=>200]);
}
else{
return response()->json(['status'=>'failed','message'=>'Update data status failed', 'code'=>400]);
}
}
public function delete($id)
{
if(!ReportActivityMaterial::findOrFail($id)->delete())
return response()->json(['status'=>'failed','message'=>'Failed to deleted the data!','code'=> 500], 500);
return response()->json(['status'=>'success','message'=> 'Data deleted!','code'=>200], 200);
}
public function search(Request $request)
{
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'report_activity_material');
$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 = ReportActivityMaterial::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 Repport Activity material, please try again later!','code'=>400], 400);
}
}
public function datatables(Request $request){
$id_activity = $request->query('idAct');
$type = $request->query('type');
$materialName = $request->query('materialName');
if($type == 'plan'){
$data = AssignMaterial::select("assign_material_to_activity.*","m.description as material_name", "m.uom as uom")
->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id")
->where('assign_material_to_activity.activity_id', $id_activity)
->where('m.description', $materialName)
->orderBy('assign_material_to_activity.id', 'asc')
->get();
return Datatables::of($data)
->addIndexColumn()
->addColumn('action', function($row){
$actionBtn = '<a href="javascript:void(0)" data-id="'.$row->id.'" class="info btn btn-info btn-sm btn-ram-image" data-toggle="tooltip" title="Lihat Foto Report" data-placement="top"><i class="fa fa-image"></i></a>';
$actionBtn .= '<a href="javascript:void(0)" data-id="'.$row->id.'" class="delete btn btn-danger btn-sm btn-ram-delete" data-toggle="tooltip" title="Hapus Report" data-placement="top"><i class="fa fa-trash"></i></a>';
return $actionBtn;
})
->rawColumns(['action'])->make(true);
}else{
$data = ReportActivityMaterial::select("report_activity_material.*", "u.name as human_resource")
->join("assign_material_to_activity as amta", "amta.id", "=", "report_activity_material.assign_material_id")
->join("m_req_material as m", "m.id", "=", "amta.material_id")
->join("m_users as u", "u.id", "=", "report_activity_material.user_id")
->where('report_activity_material.activity_id', $id_activity)
->where('m.description', $materialName)
->orderBy('report_activity_material.report_date', 'asc')
->get();
return Datatables::of($data)
->addIndexColumn()
->addColumn('action', function($row){
$actionBtn = '<a href="javascript:void(0)" data-id="'.$row->id.'" class="info btn btn-info btn-sm btn-ram-image" data-toggle="tooltip" title="Lihat Foto Report" data-placement="top"><i class="fa fa-image"></i></a>';
$actionBtn .= '<a href="javascript:void(0)" data-id="'.$row->id.'" class="delete btn btn-danger btn-sm btn-ram-delete" data-toggle="tooltip" title="Hapus Report" data-placement="top"><i class="fa fa-trash"></i></a>';
return $actionBtn;
})
->rawColumns(['action'])->make(true);
}
}
}
<?php
namespace App\Http\Controllers;
use App\Helpers\MasterFunctionsHelper;
use Illuminate\Http\Request;
use App\Models\ReportActivityMaterial;
use App\Models\Activity;
use App\Models\AssignMaterial;
use Datatables;
use DateTime;
class ReportActivityMaterialController extends Controller
{
private function sanitizeDecimal($number) {
$number = str_replace(".","",$number);
$number = str_replace(",",".",$number);
return $number;
}
public function add(Request $request){
$this->validate($request, [
'activity_id' => 'required',
'qty' => 'required'
]);
$activity = Activity::where('id', $request->activity_id)->first();
$start_date = $activity->start_date;
$start_date = substr($start_date, 0, 19); // remove the timezone offset
$startDate = new \DateTime(date("Y-m-d", strtotime($start_date)));
$reportDate = new \DateTime(date("Y-m-d", strtotime($request->report_date)));
$data = $request->all();
$data['created_by'] = $this->currentName;
/* $data['assign_material_id'] = AssignMaterial::where('activity_id', $request->activity_id)->pluck('id')->first(); */
$data['assign_material_id'] = $request->assign_material_id;
$data['qty'] = $this->sanitizeDecimal($data['qty']);
if($reportDate >= $startDate || isset($data['force']) && $data['force'] == "true"){
$created = ReportActivityMaterial::create($data);
return response()->json(['status'=>'success','message'=>'Input progress report activity created','code'=>200,'data'=>array('report_id'=>$created->id)]);
} else {
return response()->json(['status'=>'failed','message'=>'Report date is before early start, still wanna add data ?','code'=>400,'data'=>$data], 400);
}
}
public function updateStatusStartFinish(Request $request){
$payloadUpdate = array(
'start_activity' => $request->start_activity,
'finish_activity' => $request->finish_activity,
'status_activity' => $request->status_activity
);
$updateData = AssignMaterial::where('activity_id',$request->activity_id)
->update($payloadUpdate);
if($updateData){
if($request->status_activity == 'done'){
$dataUpdate = array(
"persentase_progress" => 100,
"updated_by" => $this->currentName
);
Activity::where('id', $request->activity_id)->update($dataUpdate);
} else {
$sumAssignMaterial = AssignMaterial::where('activity_id', $request->activity_id)->sum('qty_planning');
$sumReportActivityMaterial = ReportActivityMaterial::where('activity_id', $request->activity_id)->sum('qty');
$dataUpdate = array(
"actual_start" => null,
"actual_end" => null,
"persentase_progress" => $sumReportActivityMaterial/$sumAssignMaterial*100,
"updated_by" => $this->currentName
);
if ($sumReportActivityMaterial > 0) {
$data = [];
$reportActivityMaterial = ReportActivityMaterial::where('activity_id', $request->activity_id)->get();
foreach ($reportActivityMaterial as $value) {
$data[] = $value;
}
$actualStartValues = array_column(array_filter($data, function($item) {
return isset($item['report_date']);
}), 'report_date');
$dataUpdate["actual_start"] = min($actualStartValues);
}
Activity::where('id', $request->activity_id)->update($dataUpdate);
}
return response()->json(['status'=>'success','message'=>'Update data status successfully ', 'code'=>200]);
}
else{
return response()->json(['status'=>'failed','message'=>'Update data status failed', 'code'=>400]);
}
}
public function delete($id)
{
if(!ReportActivityMaterial::findOrFail($id)->delete())
return response()->json(['status'=>'failed','message'=>'Failed to deleted the data!','code'=> 500], 500);
return response()->json(['status'=>'success','message'=> 'Data deleted!','code'=>200], 200);
}
public function search(Request $request)
{
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'report_activity_material');
$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 = ReportActivityMaterial::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 Repport Activity material, please try again later!','code'=>400], 400);
}
}
public function datatables(Request $request){
$id_activity = $request->query('idAct');
$type = $request->query('type');
$materialName = $request->query('materialName');
if($type == 'plan'){
$activity = Activity::findOrFail($id_activity);
$baselineDuration = 0;
if (isset($activity->planned_start) && isset($activity->planned_end)) {
$baselineDuration = MasterFunctionsHelper::countDays($activity->version_gantt_id, new DateTime($activity->planned_start), new DateTime($activity->planned_end));
}
$data = AssignMaterial::select("assign_material_to_activity.*","m.description as material_name", "m.uom as uom")
->join("m_req_material as m", "m.id", "=", "assign_material_to_activity.material_id")
->where('assign_material_to_activity.activity_id', $id_activity)
->where('m.description', $materialName)
->orderBy('assign_material_to_activity.id', 'asc')
->get();
if ($baselineDuration > 0) {
foreach ($data as $key => $value) {
$data[$key]->qty_planning = number_format($value->qty_planning / $baselineDuration, 1);
}
}
return Datatables::of($data)
->addIndexColumn()
->addColumn('action', function($row){
$actionBtn = '<a href="javascript:void(0)" data-id="'.$row->id.'" class="info btn btn-info btn-sm btn-ram-image" data-toggle="tooltip" title="Lihat Foto Report" data-placement="top"><i class="fa fa-image"></i></a>';
if ($row->status_activity != 'done') {
$actionBtn .= '<a href="javascript:void(0)" data-id="'.$row->id.'" class="delete btn btn-danger btn-sm btn-ram-delete" data-toggle="tooltip" title="Hapus Report" data-placement="top"><i class="fa fa-trash"></i></a>';
}
return $actionBtn;
})
->rawColumns(['action'])->make(true);
}else{
$activity = Activity::findOrFail($id_activity);
$baselineDuration = 0;
if (isset($activity->planned_start) && isset($activity->planned_end)) {
$baselineDuration = MasterFunctionsHelper::countDays($activity->version_gantt_id, new DateTime($activity->planned_start), new DateTime($activity->planned_end));
}
$data = ReportActivityMaterial::select("report_activity_material.*", "u.name as human_resource", "amta.status_activity", "amta.qty_planning")
->join("assign_material_to_activity as amta", "amta.id", "=", "report_activity_material.assign_material_id")
->join("m_req_material as m", "m.id", "=", "amta.material_id")
->join("m_users as u", "u.id", "=", "report_activity_material.user_id")
->where('report_activity_material.activity_id', $id_activity)
->where('m.description', $materialName)
->orderBy('report_activity_material.report_date', 'asc')
->get();
if ($baselineDuration > 0) {
foreach ($data as $key => $value) {
$data[$key]->qty_planning = number_format($value->qty_planning / $baselineDuration, 1);
}
}
return Datatables::of($data)
->addIndexColumn()
->addColumn('action', function($row){
$actionBtn = '<a href="javascript:void(0)" data-id="'.$row->id.'" class="info btn btn-info btn-sm btn-ram-image" data-toggle="tooltip" title="Lihat Foto Report" data-placement="top"><i class="fa fa-image"></i></a>';
if ($row->status_activity != 'done') {
$actionBtn .= '<a href="javascript:void(0)" data-id="'.$row->id.'" class="delete btn btn-danger btn-sm btn-ram-delete" data-toggle="tooltip" title="Hapus Report" data-placement="top"><i class="fa fa-trash"></i></a>';
}
return $actionBtn;
})
->rawColumns(['action'])->make(true);
}
}
}

210
app/Http/Controllers/RoleController.php

@ -1,101 +1,109 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Role;
class RoleController extends Controller
{
public function add(Request $request)
{
$this->validate($request, [
'name' => 'required',
'description' => 'required'
]);
$data = $request->all();
$data['created_by'] = $this->currentName;
$result = Role::create($data);
if(!$result)
return response()->json(['status'=>'failed','message'=>'Failed to add data!','code'=>500], 500);
return response()->json(['status'=>'success','message'=>'Data added!','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);
$result = Role::find($id);
if(!$result)
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>404], 404);
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);
$data = Role::find($id);
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 the data!','code'=>500], 500);
return response()->json(['status'=>'success','message'=>'Data updated!','code'=>200], 200);
}
public function delete($id)
{
if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
$data = Role::find($id);
if(!$data)
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>404], 404);
$delete = $data->delete();
if(!$delete)
return response()->json(['status'=>'failed','message'=>'Failed to delete!','code'=>500], 500);
return response()->json(['status'=>'success','message'=>'Data deleted!','code'=>200], 200);
}
public function search(Request $request)
{
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'm_roles');
$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 = Role::all();
$countData = $data->count();
if(!$data)
return response()->json(['status'=>'failed','message'=>'failed get list role, please try again later!','code'=>400], 400);
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200);
}
}
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Role;
class RoleController extends Controller
{
public function add(Request $request)
{
$this->validate($request, [
'name' => 'string|required|unique:m_roles,name',
'description' => 'required'
]);
$data = $request->all();
$data['created_by'] = $this->currentName;
if (!isset($data['default_page'])) {
$data['default_page'] = 29; // dashboard
}
$result = Role::create($data);
if(!$result)
return response()->json(['status'=>'failed','message'=>'Failed to add data!','code'=>500], 500);
return response()->json(['status'=>'success','message'=>'Data added!','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);
$result = Role::find($id);
if(!$result)
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>404], 404);
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);
$this->validate($request, [
'name' => 'string|required',
'description' => 'required'
]);
$data = Role::find($id);
$request->name !== $data['name'] ? $this->validate($request,['name'=>'unique:m_roles,name']) : '';
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 the data!','code'=>500], 500);
return response()->json(['status'=>'success','message'=>'Data updated!','code'=>200], 200);
}
public function delete($id)
{
if(empty($id) || !is_int((int)$id))
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
$data = Role::find($id);
if(!$data)
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>404], 404);
$delete = $data->delete();
if(!$delete)
return response()->json(['status'=>'failed','message'=>'Failed to delete!','code'=>500], 500);
return response()->json(['status'=>'success','message'=>'Data deleted!','code'=>200], 200);
}
public function search(Request $request)
{
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'm_roles');
$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 = Role::all();
$countData = $data->count();
if(!$data)
return response()->json(['status'=>'failed','message'=>'failed get list role, please try again later!','code'=>400], 400);
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200);
}
}

204
app/Http/Controllers/RoleMenuController.php

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

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
);

450
app/Http/Controllers/UserToActivityController.php

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

470
app/Http/Controllers/UserToProyekController.php

@ -1,214 +1,256 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\UserToProyek;
use App\Models\UserToActivity;
use App\Models\ReportActivity;
use App\Models\Image;
class UserToProyekController extends Controller
{
public function add(Request $request)
{
$this->validate($request, [
'user_id' => 'required',
'proyek_id' => 'required'
]);
$data = $request->all();
$data['created_by'] = $this->currentName;
$result = UserToProyek::create($data);
if($result){
return response()->json(['status'=>'success','message'=>'assign hr to proyek successfully!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'assign hr to proyek 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 = UserToProyek::find($id);
if($result){
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200);
}else{
return response()->json(['status'=>'failed','message'=>'failed get data assign hr to proyek, 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 = UserToProyek::find($id);
if($data){
$result = $data->update($request->all());
}else{
return response()->json(['status'=>'failed','message'=>'data assign hr to proyek not found!','code'=>400], 400);
die();
}
if($result){
return response()->json(['status'=>'success','message'=>'data assign hr to proyek successfully updated!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'data assign hr to proyek failed updated!','code'=>400], 400);
}
}
public function delete($id)
{
$data = UserToProyek::find($id);
if($data){
$userId = $data->user_id;
$proyekId = $data->proyek_id;
$delete = $data->delete();
if($delete){
$this->deleteRelative($proyekId, $userId);
}
}else{
return response()->json(['status'=>'failed','message'=>'data assign hr to proyek not found!','code'=>400], 400);
die();
}
if($delete){
return response()->json(['status'=>'success','message'=>'data assign hr to proyek successfully deleted!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'data assign hr to proyek failed deleted!','code'=>400], 400);
}
}
private function deleteRelative($proyekId, $userId)
{
$uta = UserToActivity::where("proyek_id", $proyekId)->where("user_id", $userId)->get();
foreach ($uta as $value) {
$dataRa = ReportActivity::where("activity_id", $value->activity_id)->where("user_id", $value->user_id)->get();
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);
}
}
Image::where("ref_id", $ra->id)->where("category", "report_activity")->delete();
}
ReportActivity::where("activity_id", $value->activity_id)->where("user_id", $value->user_id)->delete();
}
UserToActivity::where("proyek_id", $proyekId)->where("user_id", $userId)->delete();
}
public function search(Request $request)
{
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'assign_hr_to_proyek');
$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 = UserToProyek::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 assign hr to proyek, please try again later!','code'=>400], 400);
}
}
public function select(Request $request){
$search = $request->query('search');
$idProyek = (int)$request->query('idProyek');
$idActivity = (int)$request->query('idact');
$include = [];
if($idActivity && $idActivity > 0){
$dataF = UserToActivity::select("user_id")->where("activity_id", $idActivity)->get();
foreach($dataF as $val){
$include[] = $val->user_id;
}
}
if($search && !empty($search)){
$data = UserToProyek::select("m_users.id as id", "m_users.name as name")->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.'%')->whereIn("m_users.id", $include)->get();
}else{
$data = UserToProyek::select("m_users.id as id", "m_users.name as name")->where("assign_hr_to_proyek.proyek_id", $idProyek)->join('m_users', 'm_users.id', '=', 'assign_hr_to_proyek.user_id')->whereIn("m_users.id", $include)->get();
}
if($data instanceof \Illuminate\Database\Eloquent\Collection){
$pm = array(
"id"=>$this->currentId,
"name"=> "Project Manager"
);
$data->push($pm);
}
return response()->json($data);
}
private function curlReq($url, $token){
$ch = curl_init();
$headers = [
'Authorization: '.$token
];
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
if ($response === false)
$response = curl_error($ch);
curl_close($ch);
return json_decode($response);
}
public function getEmployeeIntegration(Request $request) {
$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');
$token = config('api.adw_token');
$firstResponse = $this->curlReq($url, $token);
if($firstResponse->total == 0)
return response()->json(['status'=>'error', 'message' => 'Data not found!', 'code'=>404], 404);
$data = $firstResponse->data;
return response()->json([$data]);
$currentPage = 1;
if($firstResponse->last_page > 0) {
do {
$currentPage++;
$response = $this->curlReq($url.'&page='.$currentPage, $token);
foreach($response->data as $d){
array_push($data, $d);
}
} while ($currentPage < $firstResponse->last_page);
}
return response()->json(['status'=>'success', 'data'=> $data, 'total' => count($data), 'code'=>200], 200);
}
}
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\UserToProyek;
use App\Models\UserToActivity;
use App\Models\ReportActivity;
use App\Models\Image;
class UserToProyekController extends Controller
{
public function add(Request $request)
{
$this->validate($request, [
'user_id' => 'required',
'proyek_id' => 'required'
]);
$data = $request->all();
$data['created_by'] = $this->currentName;
$result = UserToProyek::create($data);
if($result){
return response()->json(['status'=>'success','message'=>'assign hr to proyek successfully!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'assign hr to proyek failed!','code'=>400], 400);
}
}
public function addMultiple(Request $request){
$user_IDs = $request->user_id;
$data = UserToProyek::where([
["proyek_id" , $request->proyek_id],
['is_customer',true]
]);
if($data){
$data->delete();
}
if(is_array($user_IDs) && count($user_IDs) > 0){
$countRes = 0;
foreach($user_IDs as $item){
$dataInsert = array(
"user_id" => $item,
"proyek_id" => $request->proyek_id,
"created_by" => $this->currentName,
'is_customer'=>true
);
$result = UserToProyek::create($dataInsert);
if($result){
$countRes++;
}else{
$countRes--;
}
}
if($countRes > 0){
return response()->json(['status'=>'success' ,'message'=>'Project customer successfull created','code'=>200]);
}else{
return response()->json(['status'=>'success' ,'message'=>'Project customer failed created','code'=>400]);
}
}else{
return response()->json(['status'=>'success' ,'message'=>'Project customer successfull created','code'=>200]);
}
}
public function edit($id){
if(!$id || (int) $id < 0 || $id==""){
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
die();
}
$result = UserToProyek::find($id);
if($result){
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200);
}else{
return response()->json(['status'=>'failed','message'=>'failed get data assign hr to proyek, 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 = UserToProyek::find($id);
if($data){
$result = $data->update($request->all());
}else{
return response()->json(['status'=>'failed','message'=>'data assign hr to proyek not found!','code'=>400], 400);
die();
}
if($result){
return response()->json(['status'=>'success','message'=>'data assign hr to proyek successfully updated!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'data assign hr to proyek failed updated!','code'=>400], 400);
}
}
public function delete($id)
{
$data = UserToProyek::find($id);
if($data){
$userId = $data->user_id;
$proyekId = $data->proyek_id;
$delete = $data->delete();
if($delete){
$this->deleteRelative($proyekId, $userId);
}
}else{
return response()->json(['status'=>'failed','message'=>'data assign hr to proyek not found!','code'=>400], 400);
die();
}
if($delete){
return response()->json(['status'=>'success','message'=>'data assign hr to proyek successfully deleted!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'data assign hr to proyek failed deleted!','code'=>400], 400);
}
}
private function deleteRelative($proyekId, $userId)
{
$uta = UserToActivity::where("proyek_id", $proyekId)->where("user_id", $userId)->get();
foreach ($uta as $value) {
$dataRa = ReportActivity::where("activity_id", $value->activity_id)->where("user_id", $value->user_id)->get();
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);
}
}
Image::where("ref_id", $ra->id)->where("category", "report_activity")->delete();
}
ReportActivity::where("activity_id", $value->activity_id)->where("user_id", $value->user_id)->delete();
}
UserToActivity::where("proyek_id", $proyekId)->where("user_id", $userId)->delete();
}
public function search(Request $request)
{
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'assign_hr_to_proyek');
$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 = UserToProyek::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 assign hr to proyek, please try again later!','code'=>400], 400);
}
}
public function select(Request $request){
$search = $request->query('search');
$idProyek = (int)$request->query('idProyek');
$idActivity = (int)$request->query('idact');
$include = [];
if($idActivity && $idActivity > 0){
$dataF = UserToActivity::select("user_id")->where("activity_id", $idActivity)->get();
foreach($dataF as $val){
$include[] = $val->user_id;
}
}
if($search && !empty($search)){
$data = UserToProyek::select("m_users.id as id", "m_users.name as name")->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.'%')->whereIn("m_users.id", $include)->get();
}else{
$data = UserToProyek::select("m_users.id as id", "m_users.name as name")->where("assign_hr_to_proyek.proyek_id", $idProyek)->join('m_users', 'm_users.id', '=', 'assign_hr_to_proyek.user_id')->whereIn("m_users.id", $include)->get();
}
if($data instanceof \Illuminate\Database\Eloquent\Collection){
$pm = array(
"id"=>$this->currentId,
"name"=> "Project Manager"
);
$data->push($pm);
}
return response()->json($data);
}
private function curlReq($url, $token){
$ch = curl_init();
$headers = [
'Authorization: '.$token
];
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
if ($response === false)
$response = curl_error($ch);
curl_close($ch);
return json_decode($response);
}
public function getEmployeeIntegration(Request $request) {
$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');
$token = config('api.adw_token');
$firstResponse = $this->curlReq($url, $token);
if($firstResponse->total == 0)
return response()->json(['status'=>'error', 'message' => 'Data not found!', 'code'=>404], 404);
$data = $firstResponse->data;
return response()->json([$data]);
$currentPage = 1;
if($firstResponse->last_page > 0) {
do {
$currentPage++;
$response = $this->curlReq($url.'&page='.$currentPage, $token);
foreach($response->data as $d){
array_push($data, $d);
}
} while ($currentPage < $firstResponse->last_page);
}
return response()->json(['status'=>'success', 'data'=> $data, 'total' => count($data), 'code'=>200], 200);
}
}

241
app/Http/Controllers/VersionGanttController.php

@ -1,102 +1,139 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\VersionGantt;
class VersionGanttController extends Controller
{
public function add(Request $request){
$this->validate($request, [
'name_version' => 'required',
'proyek_id' => 'required'
]);
$data = $request->all();
$data['created_by'] = $this->currentName;
$result = VersionGantt::create($data);
if($result){
return response()->json(['status'=>'success','message'=>'version gantt Project successfull created','code'=>200]);
}else{
return response()->json(['status'=>'failed','message'=>'version gantt Project failed created','code'=>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 = VersionGantt::find($id);
if($data){
$result = $data->update($request->all());
}else{
return response()->json(['status'=>'failed','message'=>'data version gantt Project not found!','code'=>400], 400);
die();
}
if($result){
return response()->json(['status'=>'success','message'=>'version gantt Project successfully updated!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'version gantt Project failed updated!','code'=>400], 400);
}
}
public function delete($id)
{
$data = VersionGantt::find($id);
if($data){
$delete = $data->delete();
}else{
return response()->json(['status'=>'failed','message'=>'data version gantt Project not found!','code'=>400], 400);
die();
}
if($delete){
return response()->json(['status'=>'success','message'=>'version gantt Project successfully deleted!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'version gantt Project failed deleted!','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 = VersionGantt::find($id);
if($result){
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200);
}else{
return response()->json(['status'=>'failed','message'=>'failed get data version gantt, please try again later!','code'=>400], 400);
}
}
public function search(Request $request)
{
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'm_version_gantt');
$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 = VersionGantt::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 version gantt, please try again later!','code'=>400], 400);
}
}
}
<?php
namespace App\Http\Controllers;
use App\Models\Link;
use App\Models\Holiday;
use App\Models\Activity;
use App\Models\VersionGantt;
use Illuminate\Http\Request;
use App\Models\ShowHideColumn;
use App\Models\UserToActivity;
use App\Models\UserToVersionGantt;
use App\Models\ActivityProgressLog;
class VersionGanttController extends Controller
{
public function add(Request $request){
$this->validate($request, [
'name_version' => 'required',
'proyek_id' => 'required'
]);
$data = $request->all();
$data['created_by'] = $this->currentName;
$result = VersionGantt::create($data);
if($result){
return response()->json(['status'=>'success','message'=>'version gantt Project successfull created','code'=>200]);
}else{
return response()->json(['status'=>'failed','message'=>'version gantt Project failed created','code'=>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 = VersionGantt::find($id);
if($data){
$result = $data->update($request->all());
}else{
return response()->json(['status'=>'failed','message'=>'data version gantt Project not found!','code'=>400], 400);
die();
}
if($result){
return response()->json(['status'=>'success','message'=>'version gantt Project successfully updated!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'version gantt Project failed updated!','code'=>400], 400);
}
}
public function delete($id)
{
$data = VersionGantt::find($id);
if($data){
$delete = $data->delete();
$this->deleteRelative($data['id']);
}else{
return response()->json(['status'=>'failed','message'=>'data version gantt Project not found!','code'=>400], 400);
die();
}
if($delete){
return response()->json(['status'=>'success','message'=>'version gantt Project successfully deleted!','code'=>200], 200);
}else{
return response()->json(['status'=>'failed','message'=>'version gantt Project failed deleted!','code'=>400], 400);
}
}
private function deleteRelative($version_gantt_id)
{
UserToActivity::where('version_gantt_id', $version_gantt_id)->delete();
Activity::where('version_gantt_id', $version_gantt_id)->delete();
ShowHideColumn::where('version_gantt_id', $version_gantt_id)->delete();
Link::where('version_gantt_id', $version_gantt_id)->delete();
UserToVersionGantt::where('version_gantt_id', $version_gantt_id)->delete();
Holiday::where('version_gantt_id', $version_gantt_id)->delete();
ActivityProgressLog::where('version_gantt_id', $version_gantt_id)->delete();
}
public function edit($id){
if(!$id || (int) $id < 0 || $id==""){
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
die();
}
$result = VersionGantt::find($id);
if($result){
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200);
}else{
return response()->json(['status'=>'failed','message'=>'failed get data version gantt, please try again later!','code'=>400], 400);
}
}
public function search(Request $request)
{
$payload = $request->all();
$dataBuilder = $this->setUpPayload($payload, 'm_version_gantt');
$builder = $dataBuilder['builder'];
// $countBuilder = $dataBuilder['count'];
$this->ganttProgress($request->columns[0]["name"], $request->columns[0]["value"]);
$dataGet = $builder->get();
// $totalRecord = $countBuilder->count();
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet], 200);
}
public function ganttProgress($column, $value){
$progress = VersionGantt::select('m_version_gantt.id','m_activity.persentase_progress', 'm_activity.bobot_planning')
->join('m_activity', 'm_version_gantt.id', '=', 'm_activity.version_gantt_id')
->where("m_version_gantt.".$column, $value)
// ->where('m_activity.type_activity', "project")
->where('m_activity.parent_id', null)
->get();
foreach($progress as $item) {
if($item->persentase_progress){
$item->progress = $item->persentase_progress;
$item->bobot = $item->bobot_planning;
$item->save();
}
}
}
public function list()
{
$data = VersionGantt::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 version gantt, please try again later!','code'=>400], 400);
}
}
}

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();
}
}

486
app/Models/Activity.php

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

90
app/Models/AssignMaterial.php

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

44
app/Models/CommentActivity.php

@ -1,22 +1,22 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class CommentActivity extends Model
{
protected $table = 'm_comment_activity';
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $fillable = [
'activity_id',
'comment',
'created_at',
'created_by',
'updated_at',
'updated_by'
];
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class CommentActivity extends Model
{
protected $table = 'm_comment_activity';
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $fillable = [
'activity_id',
'comment',
'created_at',
'created_by',
'updated_at',
'updated_by'
];
}

83
app/Models/Divisi.php

@ -1,41 +1,42 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Divisi extends Model
{
protected $table = 'm_divisi';
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $fillable = [
'name',
'parent',
'description',
'created_at',
'created_by',
'updated_at',
'updated_by'
];
public static function boot() {
parent::boot();
static::deleting(function($data) {
$data->children()->delete();
});
}
public function parent()
{
return $this->belongsTo('App\Models\Divisi','parent')->where('parent', null)->with('parent');
}
public function children()
{
return $this->hasMany('App\Models\Divisi','parent')->with('children');
}
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Divisi extends Model
{
protected $table = 'm_divisi';
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $fillable = [
'name',
'parent',
'description',
'color',
'created_at',
'created_by',
'updated_at',
'updated_by'
];
public static function boot() {
parent::boot();
static::deleting(function($data) {
$data->children()->delete();
});
}
public function parent()
{
return $this->belongsTo('App\Models\Divisi','parent')->where('parent', null)->with('parent');
}
public function children()
{
return $this->hasMany('App\Models\Divisi','parent')->with('children');
}
}

19
app/Models/HierarchyFtth.php

@ -3,6 +3,7 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use App\Models\VersionGantt;
class HierarchyFtth extends Model
{
@ -12,6 +13,22 @@ class HierarchyFtth extends Model
const UPDATED_AT = 'updated_at';
protected $fillable = [
'name', 'parent_id', 'project_id', 'created_at', 'updated_at'
'name', 'parent_id', 'project_id', 'created_at', 'updated_at', 'progress', 'bobot_planning'
];
public static function boot() {
parent::boot();
static::deleted(function($data) {
$ftths = HierarchyFtth::where('parent_id', $data->id)->get();
foreach ($ftths as $ftth) {
$ftth->delete();
}
$gantts = VersionGantt::where('hierarchy_ftth_id', $data->id)->get();
foreach ($gantts as $gantt) {
$gantt->delete();
}
});
}
}

76
app/Models/HumanResource.php

@ -1,38 +1,38 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class HumanResource extends Model
{
protected $table = 'm_users';
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $fillable = [
'role_id',
'username',
'password',
'session_login',
'name',
'phone_number',
'email',
'address',
'fcm_token',
'gender',
'birth_place',
'birth_date',
'blood_type',
'ktp_number',
'employee_type',
'status_resource',
'created_at',
'created_by',
'updated_at',
'updated_by',
'divisi_id',
'status_boundary'
];
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class HumanResource extends Model
{
protected $table = 'm_users';
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $fillable = [
'role_id',
'username',
'password',
'session_login',
'name',
'phone_number',
'email',
'address',
'fcm_token',
'gender',
'birth_place',
'birth_date',
'blood_type',
'ktp_number',
'employee_type',
'status_resource',
'created_at',
'created_by',
'updated_at',
'updated_by',
'divisi_id',
'status_boundary'
];
}

106
app/Models/Project.php

@ -1,52 +1,54 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Project extends Model
{
protected $table = 'm_proyek';
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $fillable = [
'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_simbol',
'currency_code',
'currency_name',
'project_objectives',
'considered_success_when',
'potential_risk',
'testing_environment',
'currency_code',
'currency_symbol',
'currency_name',
'budget_health',
'phase_id',
'created_at',
'created_by',
'updated_at',
'updated_by'
];
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Project extends Model
{
protected $table = 'm_proyek';
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $fillable = [
'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',
'budget_health',
'phase_id',
'late_consequence',
'assumtion',
'calculation_status',
'structur_organization',
'scurve',
'created_at',
'created_by',
'updated_at',
'updated_by'
];
}

23
app/Models/ProjectChecklists.php

@ -0,0 +1,23 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class ProjectChecklists extends Model
{
protected $table = 'project_charter_checklist';
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $fillable = [
'proyek_id',
'item',
'status_exist',
'created_at',
'created_by',
'updated_at',
'updated_by'
];
}

23
app/Models/ProjectIssues.php

@ -0,0 +1,23 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class ProjectIssues extends Model
{
protected $table = 'project_charter_issue';
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $fillable = [
'proyek_id',
'description',
'level_issue',
'created_at',
'created_by',
'updated_at',
'updated_by'
];
}

24
app/Models/ProjectRisks.php

@ -0,0 +1,24 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class ProjectRisks extends Model
{
protected $table = 'project_charter_risk';
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $fillable = [
'proyek_id',
'description',
'level_risk',
'preventive_risk',
'created_at',
'created_by',
'updated_at',
'updated_by'
];
}

153
app/Models/ReportActivityMaterial.php

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

34
app/Models/Role.php

@ -1,17 +1,17 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Role extends Model
{
protected $table = 'm_roles';
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $fillable = [
'name', 'description', 'created_at', 'created_by', 'updated_at', 'updated_by'
];
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Role extends Model
{
protected $table = 'm_roles';
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $fillable = [
'name', 'description', 'default_page', 'created_at', 'created_by', 'updated_at', 'updated_by'
];
}

124
app/Models/UserToActivity.php

@ -1,61 +1,63 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use App\Models\Activity;
class UserToActivity extends Model
{
protected $table = 'assign_hr_to_activity';
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $fillable = [
'user_id',
'proyek_id',
'version_gantt_id',
'role_proyek_id',
'activity_id',
'created_at',
'created_by',
'updated_at',
'updated_by'
];
public static function boot() {
parent::boot();
static::created(function($data) {
$activity = Activity::find($data->activity_id);
$getWorkingHours = UserToProyek::where('user_id', $data->user_id)->where('proyek_id', $activity->proyek_id)->first();
$salary = ($getWorkingHours->standart_rate * $activity->duration) * ($getWorkingHours->max_used / 100);
if($getWorkingHours->uom_standart_rate == "Hour")
$salary = ($getWorkingHours->standart_rate * 8) * $activity->duration * ($getWorkingHours->max_used / 100);
$activity->rencana_biaya += $salary;
$activity->save();
});
static::deleted(function($data) {
$activity = Activity::find($data->activity_id);
$getWorkingHours = UserToProyek::where('user_id', $data->user_id)->where('proyek_id', $activity->proyek_id)->first();
$salary = ($getWorkingHours->standart_rate * $activity->duration) * ($getWorkingHours->max_used / 100);
if($getWorkingHours->uom_standart_rate == "Hour"){
$salary = ($getWorkingHours->standart_rate * 8) * $activity->duration * ($getWorkingHours->max_used / 100);
}
$activity->rencana_biaya -= $salary;
if ($activity->rencana_biaya < 0) {
$activity->rencana_biaya = 0;
}
$activity->save();
});
}
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use App\Models\Activity;
class UserToActivity extends Model
{
protected $table = 'assign_hr_to_activity';
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $fillable = [
'user_id',
'proyek_id',
'version_gantt_id',
'role_proyek_id',
'activity_id',
'start_date',
'end_date',
'created_at',
'created_by',
'updated_at',
'updated_by'
];
public static function boot() {
parent::boot();
static::created(function($data) {
$activity = Activity::find($data->activity_id);
$getWorkingHours = UserToProyek::where('user_id', $data->user_id)->where('proyek_id', $activity->proyek_id)->first();
$salary = ($getWorkingHours->standart_rate * $activity->duration) * ($getWorkingHours->max_used / 100);
if($getWorkingHours->uom_standart_rate == "Hour")
$salary = ($getWorkingHours->standart_rate * 8) * $activity->duration * ($getWorkingHours->max_used / 100);
$activity->rencana_biaya += $salary;
$activity->save();
});
static::deleted(function($data) {
$activity = Activity::find($data->activity_id);
$getWorkingHours = UserToProyek::where('user_id', $data->user_id)->where('proyek_id', $activity->proyek_id)->first();
$salary = ($getWorkingHours->standart_rate * $activity->duration) * ($getWorkingHours->max_used / 100);
if($getWorkingHours->uom_standart_rate == "Hour"){
$salary = ($getWorkingHours->standart_rate * 8) * $activity->duration * ($getWorkingHours->max_used / 100);
}
$activity->rencana_biaya -= $salary;
if ($activity->rencana_biaya < 0) {
$activity->rencana_biaya = 0;
}
$activity->save();
});
}
}

38
app/Models/UserToProyek.php

@ -1,19 +1,19 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class UserToProyek extends Model
{
protected $table = 'assign_hr_to_proyek';
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $fillable = [
'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'
];
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class UserToProyek extends Model
{
protected $table = 'assign_hr_to_proyek';
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $fillable = [
'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', 'is_customer', 'created_at', 'created_by', 'updated_at', 'updated_by'
];
}

113
app/Models/VersionGantt.php

@ -1,29 +1,84 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class VersionGantt extends Model
{
protected $table = 'm_version_gantt';
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $fillable = [
'name_version',
'description',
'date_base_line',
'proyek_id',
'config_dayoff',
'auto_schedule',
'calculation_type',
'committed_cost',
'cost_to_complete',
'created_at',
'created_by',
'updated_at',
'updated_by'
];
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use App\Models\Activity;
use App\Models\Link;
use DateTime;
class VersionGantt extends Model
{
protected $table = 'm_version_gantt';
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $fillable = [
'name_version',
'description',
'date_base_line',
'proyek_id',
'config_dayoff',
'auto_schedule',
'calculation_type',
'committed_cost',
'cost_to_complete',
'progress',
'bobot',
'hierarchy_ftth_id',
'created_at',
'created_by',
'updated_at',
'updated_by'
];
public static function boot() {
parent::boot();
static::updated(function($data) {
$data->updateActDuration();
});
static::deleted(function ($data) {
$activities = Activity::where('version_gantt_id', $data->id)->get();
foreach ($activities as $activity) {
$activity->delete();
}
});
}
public function updateActDuration(){
$daysOff = explode(',', $this->config_dayoff);
if (in_array('0', $daysOff)) {
$key = array_search('0', $daysOff, false);
$daysOff[$key] = '7';
}
$activities = Activity::where('version_gantt_id', $this->id)->get();
foreach ($activities as $value) {
$exist = Link::where('t_activity_id', $value->id)->exists();
$startDate = new DateTime($value->start_date);
$endDate = new DateTime($value->end_date);
$duration = $endDate->diff($startDate)->days + 1;
if ($exist) {
$duration--;
}
// Iterate through each day and subtract the days off
for ($i = 0; $i < $duration; $i++) {
$currentDate = clone $startDate;
$currentDate->modify("+$i day");
$currentDayOfWeek = $currentDate->format('N'); // Get the day of the week (1 - Monday, 7 - Sunday)
if (in_array($currentDayOfWeek, $daysOff)) {
$duration--; // Subtract one day from the duration for each day off
}
}
// Update the activity duration
$value->duration = $duration;
$value->save();
}
}
}

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"
}

70
routes/web.php

@ -1,7 +1,7 @@
<?php
$router->get('/', function () use ($router) {
return $router->app->version();
return $router->app->version();
});
$router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($router) {
@ -53,11 +53,12 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout
$router->post('/document-activity/search', 'ActivityDokumenController@searchDocProject');
$router->get('/document-activity/download/{id}', 'ActivityDokumenController@downloadDokumen');
$router->get('/project-by-customer/{id}','ProjectController@getByUser');
$router->post('/project/search', 'ProjectController@search');
$router->post('/project/add', 'ProjectController@add');
$router->put('/project/update/{id}', 'ProjectController@update');
$router->get('/project/edit/{id}', 'ProjectController@edit');
$router->get('/project/detail/{id}', 'ProjectController@detail');
$router->get('/project/detail/{id}[/{gantt_id}[/{s_curve}]]', 'ProjectController@detail');
$router->delete('/project/delete/{id}', 'ProjectController@delete');
$router->get('/project/list', 'ProjectController@list');
$router->get('/project/set-baseline/{gantt_id}', 'ProjectController@setBaseline');
@ -66,6 +67,9 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout
$router->get('/project/manpower/assigned/{gantt_id}', 'ProjectController@getAssignedHR');
$router->post('/project/get-s-curve', 'ProjectController@getSCurve');
$router->post('/project/calculate-s-curve', 'ProjectController@calculateSCurve');
$router->post('/project/s-curve-command', 'ProjectController@sCurveCommand');
$router->post('/project/get-linear-s-curve', 'ProjectController@getLinearSCurve');
$router->post('/project/get-overdue-activities', 'ProjectController@getOverdueActivities');
$router->post('/project/get-integration-invoice', 'ProjectController@getInvoiceIntegration');
$router->post('/project/get-report-distribution', 'ProjectController@getReportDistribution');
@ -75,6 +79,7 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout
/* $router->get('/project/get-status-health-schedule/{id}', 'ProjectController@getStatusSchedule'); */
/* $router->get('/project/get-status-health-budget/{id}', 'ProjectController@getStatusBudget'); */
$router->get('/project-carausell','ProjectCarausellController@invoke');
$router->post('/project-charter/search', 'ProjectCharterController@search');
$router->post('/project-charter/add', 'ProjectCharterController@add');
@ -108,6 +113,7 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout
$router->get('/human-resource/list', 'HumanResourceController@list');
$router->get('/human-resource/select', 'HumanResourceController@select');
$router->post('/human-resource/check-old-password/{id}', 'HumanResourceController@checkOldPassword');
$router->get('/human-resource/sync', 'HumanResourceController@sync');
$router->post('/project-role/search', 'ProjectRoleController@search');
$router->post('/project-role/add', 'ProjectRoleController@add');
@ -192,6 +198,7 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout
$router->get('/user-to-activity/edit/{id}', 'UserToActivityController@edit');
$router->put('/user-to-activity/update/{id}', 'UserToActivityController@update');
$router->post('/user-to-activity/search', 'UserToActivityController@search');
$router->post('/user-to-activity/search-analysis', 'UserToActivityController@searchAnalysis');
$router->post('/user-to-activity/list-filtered', 'UserToActivityController@listFiltered');
$router->delete('/user-to-activity/delete/{id}', 'UserToActivityController@delete');
$router->get('/user-to-activity/list', 'UserToActivityController@list');
@ -199,8 +206,14 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout
$router->get('/sumVolActualM/{id}', 'ActivityController@sumVolumeActualMaterial');
$router->get('/activity/{id}/{proyek_id}/get', 'ActivityController@getByGanttId');
$router->get('/activity/search', 'ActivityController@search');
$router->post('/activity/search', 'ActivityController@search');
$router->post('/activity/search-analysis', 'ActivityController@searchAnalysis');
$router->post('/activity/search-analysis-prep', 'ActivityController@searchAnalysisPrep');
$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->get('/activity/update-schedule/{ganttId}', 'ActivityController@updateSchedule');
$router->post('/task', 'ActivityController@add');
$router->get('/task/edit/{id}', 'ActivityController@edit');
$router->put('/task/{id}', 'ActivityController@update');
@ -229,6 +242,7 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout
$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');
@ -283,6 +297,33 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout
$router->delete('/rate-sallary/delete/{id}', 'RateSallaryController@delete');
$router->get('/rate-sallary/list', 'RateSallaryController@list');
$router->post('/project-checklists/add', 'ProjectChecklistsController@add');
$router->get('/project-checklists/edit/{id}', 'ProjectChecklistsController@edit');
$router->put('/project-checklists/update/{id}', 'ProjectChecklistsController@update');
$router->post('/project-checklists/search', 'ProjectChecklistsController@search');
$router->delete('/project-checklists/delete/{id}', 'ProjectChecklistsController@delete');
$router->delete('/project-checklists/delete-by-proyek/{id}', 'ProjectChecklistsController@deleteByProyek');
$router->get('/project-checklists/list', 'ProjectChecklistsController@list');
$router->get('/project-checklists/{where}/{val}', 'ProjectChecklistsController@customWhere');
$router->post('/project-issues/add', 'ProjectIssuesController@add');
$router->get('/project-issues/edit/{id}', 'ProjectIssuesController@edit');
$router->put('/project-issues/update/{id}', 'ProjectIssuesController@update');
$router->post('/project-issues/search', 'ProjectIssuesController@search');
$router->delete('/project-issues/delete/{id}', 'ProjectIssuesController@delete');
$router->delete('/project-issues/delete-by-proyek/{id}', 'ProjectIssuesController@deleteByProyek');
$router->get('/project-issues/list', 'ProjectIssuesController@list');
$router->get('/project-issues/{where}/{val}', 'ProjectIssuesController@customWhere');
$router->post('/project-risks/add', 'ProjectRisksController@add');
$router->get('/project-risks/edit/{id}', 'ProjectRisksController@edit');
$router->put('/project-issues/update/{id}', 'ProjectRisksController@update');
$router->post('/project-risks/search', 'ProjectRisksController@search');
$router->delete('/project-risks/delete/{id}', 'ProjectRisksController@delete');
$router->delete('/project-risks/delete-by-proyek/{id}', 'ProjectRisksController@deleteByProyek');
$router->get('/project-risks/list', 'ProjectRisksController@list');
$router->get('/project-risks/{where}/{val}', 'ProjectRisksController@customWhere');
$router->post('/project-participants/add', 'ProjectParticipantsController@add');
$router->get('/project-participants/edit/{id}', 'ProjectParticipantsController@edit');
$router->put('/project-participants/update/{id}', 'ProjectParticipantsController@update');
@ -372,6 +413,7 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout
$router->get('/report-k3-detail/list', 'ReportK3DetailController@list');
$router->post('/user-to-proyek/add', 'UserToProyekController@add');
$router->post('/user-to-proyek/add-multiple', 'UserToProyekController@addMultiple');
$router->get('/user-to-proyek/edit/{id}', 'UserToProyekController@edit');
$router->put('/user-to-proyek/update/{id}', 'UserToProyekController@update');
$router->post('/user-to-proyek/search', 'UserToProyekController@search');
@ -439,15 +481,23 @@ $router->group(['prefix'=>'api', 'middleware' => 'cors'], function () use ($rout
$router->put('/project-comment/update/{id}', 'ProjectCommentController@update');
$router->post('/project-comment/search', 'ProjectCommentController@search');
$router->get('/hierarchy-ftths', 'HierarchyFtthController@index');
$router->post('/hierarchy-ftths', 'HierarchyFtthController@store');
$router->post('/hierarchy-ftths/search', 'HierarchyFtthController@search');
$router->get('/hierarchy-ftths/{id}', 'HierarchyFtthController@show');
$router->put('/hierarchy-ftths/{id}', 'HierarchyFtthController@update');
$router->delete('/hierarchy-ftths/{id}', 'HierarchyFtthController@destroy');
$router->get('/hierarchy-ftths/tree/{project_id}', 'HierarchyFtthController@getTreeByProject');
$router->get('/hierarchy-ftths', 'HierarchyFtthController@index');
$router->post('/hierarchy-ftths', 'HierarchyFtthController@store');
$router->post('/hierarchy-ftths/search', 'HierarchyFtthController@search');
$router->get('/hierarchy-ftths/{id}', 'HierarchyFtthController@show');
$router->put('/hierarchy-ftths/{id}', 'HierarchyFtthController@update');
$router->delete('/hierarchy-ftths/{id}', 'HierarchyFtthController@destroy');
$router->get('/hierarchy-ftths/tree/{project_id}', 'HierarchyFtthController@getTreeByProject');
$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