Browse Source

Merge pull request 'dev-wahyu' (#227) from dev-wahyu into staging

Reviewed-on: ordo/adw-backend#227
pull/3/head
farhantock 1 year ago
parent
commit
35bab84cfd
  1. 11
      app/Helpers/MasterFunctionsHelper.php
  2. 14
      app/Http/Controllers/ActivityController.php
  3. 2
      app/Http/Controllers/Controller.php
  4. 540
      app/Http/Controllers/ReportActivityController.php
  5. 7
      app/Http/Controllers/UserToActivityController.php

11
app/Helpers/MasterFunctionsHelper.php

@ -402,8 +402,9 @@ class MasterFunctionsHelper
// if($tempTtlPercentActual >= $keyGantt['progress'])
// $tempTtlPercentActual = $keyGantt['progress'];
if ($tempTtlPercentPlan >= 100)
$tempTtlPercentPlan = 100;
// todo
// if ($tempTtlPercentPlan >= 100)
// $tempTtlPercentPlan = 100;
// $sumPercentageActual > $keyGantt['progress'] ? $keyGantt['progress'] : $sumPercentageActual
// }
@ -707,9 +708,9 @@ class MasterFunctionsHelper
if (isset($dataPayload['period']) && $dataPayload['period'] == 'week') {
$tempTtlPercentPlan += $sumPercentagePlan;
$tempTtlPercentActual += $sumPercentageActual;
if ($tempTtlPercentPlan >= 100)
$tempTtlPercentPlan = 100;
// todo
// if ($tempTtlPercentPlan >= 100)
// $tempTtlPercentPlan = 100;
$currentACWP += $totalACWP;
$currentBCWP += $totalBCWP;

14
app/Http/Controllers/ActivityController.php

@ -544,10 +544,22 @@ class ActivityController extends Controller
{
$dataBuilder = $this->setUpPayload($request->all(), 'm_activity');
$builder = $dataBuilder['builder'];
$dataGet = $builder->select('selfTable.*','m_version_gantt.name_version', 'm_users.name as user_name')
$dataGet = $builder->select( 'selfTable.name', 'persentase_progress',
'm_version_gantt.name_version', 'm_users.name as user_name',
DB::raw('SUM(report_activity_material.qty) as qty'), 'assign_material_to_activity.qty_planning',
'assign_material_to_activity.id as join_third_id')
->join('m_version_gantt', 'm_version_gantt.id', '=', 'selfTable.version_gantt_id')
->join('assign_hr_to_activity', 'assign_hr_to_activity.activity_id', '=', 'selfTable.id')
->join('m_users', 'assign_hr_to_activity.user_id', '=', 'm_users.id')
->join('report_activity_material', 'report_activity_material.activity_id', '=', 'selfTable.id')
->join('assign_material_to_activity', 'assign_material_to_activity.activity_id', '=', 'selfTable.id')
->groupBy("selfTable.id")
->groupBy("selfTable.name")
->groupBy("selfTable.persentase_progress")
->groupBy("m_version_gantt.name_version")
->groupBy("m_users.name")
->groupBy("assign_material_to_activity.qty_planning")
->groupBy("assign_material_to_activity.id")
->get();
return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet ], 200);
}

2
app/Http/Controllers/Controller.php

@ -54,11 +54,13 @@ class Controller extends BaseController
$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++;
}

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

7
app/Http/Controllers/UserToActivityController.php

@ -6,6 +6,7 @@ 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
@ -134,6 +135,12 @@ class UserToActivityController extends Controller
$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("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);

Loading…
Cancel
Save