From f86800f3d15e0f0e8c8eb9217269d05d7933fdee Mon Sep 17 00:00:00 2001 From: wahyun Date: Mon, 22 Jul 2024 08:42:05 +0700 Subject: [PATCH 1/7] fix: upload report image --- app/Http/Controllers/ImageController.php | 69 +++++------------------- 1 file changed, 14 insertions(+), 55 deletions(-) diff --git a/app/Http/Controllers/ImageController.php b/app/Http/Controllers/ImageController.php index ece127e..8b8cdd4 100644 --- a/app/Http/Controllers/ImageController.php +++ b/app/Http/Controllers/ImageController.php @@ -25,62 +25,21 @@ class ImageController extends Controller $extension = $dokumen->extension(); $category = $request->category; $name = $ref_id.date("YmdHis").".".$extension; - // Limited Storage - $company = Company::where('company_name', $request->company_name)->first(); - if($company) { - $destinationPath = $this->setCustomeDirectoryUpload($company['company_name']); - $getLimitStorage = $this->setLimitsStorage($company, $dokumen, $destinationPath['pathImage'], $destinationPath); - } - if(isset($getLimitStorage)) { - if($getLimitStorage === false) { - DB::rollBack(); - return response()->json(['status' => 'failed', 'message' => 'Limited storage maximum!', 'code' => 500], 500); - } - $data = [ - 'ref_id' => (int)$ref_id, - 'image' => $name, - 'category' => $category - ]; - - $result = Image::create($data); - - $company = Company::find((int)$ref_id); - if($company && $category === 'company_logo_login') { - $dataArray = json_decode($company['logo_login'], true); - if(isset($dataArray['slider'])) { - $jsonImageSlider['login'] = $name; - $jsonImageSlider['slider'] = $dataArray['slider']; - } else { - $jsonImageSlider['login'] = $name; - } - $company->update([ - 'logo_login' => $jsonImageSlider - ]); - } - - if($company && $category === 'company_logo_header') { - $company->update([ - 'logo_header' => array('content' => $name) - ]); - } - - if($company && $category === 'company_favicon') { - $company->update([ - 'favicon_image' => array('content' => $name) - ]); - } - if($dokumen->move($destinationPath['pathImage'], $name) && $result) { - DB::commit(); - return response()->json(['status' => 'success', "name_image" => $name,'message' => 'image upload is successfully!','code' => 200], 200); - } else { - DB::rollBack(); - unlink($destinationPath['pathImage'].$name); - return response()->json(['status' => 'failed','message' => 'image upload is failed!' ,'code' => 400], 400); - } - + $destinationPath = $this->setCustomeDirectoryUpload(); + $data = [ + 'ref_id' => (int)$ref_id, + 'image' => $name, + 'category' => $category + ]; + + $result = Image::create($data); + if($dokumen->move($destinationPath['pathImage'], $name) && $result) { + DB::commit(); + return response()->json(['status' => 'success', "name_image" => $name,'message' => 'image upload is successfully!','code' => 200], 200); } else { DB::rollBack(); - return response()->json(['status'=>'failed','message'=>'image upload is failed!','code'=>400], 400); + unlink($destinationPath['pathImage'].$name); + return response()->json(['status' => 'failed','message' => 'image upload is failed!' ,'code' => 400], 400); } } else { DB::rollBack(); @@ -123,7 +82,7 @@ class ImageController extends Controller $totalSize += filesize($folderPath . '/' . $file); } } - $totalSize += $sizeFile; + $totalSize += $sizeFile; } foreach ($dokumen as $file) { $extension = $file->extension(); From 66d526115820282190bfb866c81c5fbae00273b2 Mon Sep 17 00:00:00 2001 From: Fuad Hadisurya Date: Mon, 22 Jul 2024 15:00:30 +0700 Subject: [PATCH 2/7] [FIX] method delete activityController --- app/Http/Controllers/ActivityController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index b247ed8..1cc186c 100755 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -649,7 +649,7 @@ class ActivityController extends Controller DB::rollBack(); return response()->json(['status' => 'failed', 'action' => 'error', 'message' => 'Data activity failed deleted!', 'code' => 500], 500); } - DB::rollBack(); + DB::commit(); return response()->json(['status' => 'success', "action" => "deleted", 'message' => 'Data activity successfully deleted!', 'code' => 200], 200); } From c0a7841b4184ba83c99d0f73f79e9cc41844c842 Mon Sep 17 00:00:00 2001 From: wahyun Date: Mon, 22 Jul 2024 16:00:03 +0700 Subject: [PATCH 3/7] fix: parameter dashboard bod --- app/Http/Controllers/DashboardBoDController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/DashboardBoDController.php b/app/Http/Controllers/DashboardBoDController.php index 931e685..4c32b41 100644 --- a/app/Http/Controllers/DashboardBoDController.php +++ b/app/Http/Controllers/DashboardBoDController.php @@ -275,7 +275,7 @@ class DashboardBoDController extends Controller return response()->json(['data' => $divisions], 200); } - public function getTotalProjectPerBudgetHealth($role_name, $all_project, $hierarchy) + public function getTotalProjectPerBudgetHealth($all_project, $hierarchy, $role_name) { $role = urldecode($role_name); $replaceHierarchy = preg_replace('/[\[\]]/', '', $hierarchy); From 42189f7544d65ae5eba8e05222ab6d2a4343ff15 Mon Sep 17 00:00:00 2001 From: Fuad Hadisurya Date: Wed, 24 Jul 2024 17:17:19 +0700 Subject: [PATCH 4/7] [Feat] Menambah command untuk update actual Progress Project --- .../Commands/ActualProgressProject.php | 77 +++++++++++++++++++ app/Console/Commands/ScheduleHealth.php | 2 +- app/Console/Kernel.php | 3 +- app/Http/Controllers/ProjectController.php | 2 +- 4 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 app/Console/Commands/ActualProgressProject.php diff --git a/app/Console/Commands/ActualProgressProject.php b/app/Console/Commands/ActualProgressProject.php new file mode 100644 index 0000000..de21595 --- /dev/null +++ b/app/Console/Commands/ActualProgressProject.php @@ -0,0 +1,77 @@ +select('m_proyek.*', 'm_type_proyek.is_multiLocation') + ->get(); + + foreach ($projects as $project) { + if ($project->is_multiLocation == 1) { + // untuk project multi location + $versionGantt = VersionGantt::join('m_proyek', 'm_version_gantt.proyek_id', 'm_proyek.id') + ->select('m_version_gantt.*') + ->where('m_version_gantt.proyek_id', $project->id) + ->get(); + foreach ($versionGantt as $key => $gantt) { + $progress[$key] = $gantt->progress; + } + $actualProgress = round(array_sum($progress) / count($versionGantt), 2); + } else { + // untuk project single location + $gantt = MasterFunctionsHelper::getLatestGantt($project->id); + isset($gantt['last_gantt_id']) ? $lastGantt = $gantt['last_gantt_id'] : $lastGantt = 0; + + $arr = [ + 'project_id' => $project->id, + 'gantt_id' => $lastGantt, + 'periode' => 'week' + ]; + + $project->scurve = MasterFunctionsHelper::getSCurve(collect($arr)); + $actualArray = $project->scurve[0]['data']['percentageReal']; + $actualProgress = !empty($actualArray) ? round(end($actualArray), 2) : 0; + } + + Project::where('id', $project->id)->update(['persentase_progress' => $actualProgress]); + } + } +} diff --git a/app/Console/Commands/ScheduleHealth.php b/app/Console/Commands/ScheduleHealth.php index 9c4e618..87ff9de 100644 --- a/app/Console/Commands/ScheduleHealth.php +++ b/app/Console/Commands/ScheduleHealth.php @@ -45,7 +45,7 @@ class ScheduleHealth extends Command echo "\n------------------------------------------\n"; echo "Command Start. \n"; Log::info("Command Start."); - $projects = Project::where('company_id', 5)->get(); + $projects = Project::get(); $totalProjects = $projects->count(); $updatedProjects = []; Log::info($totalProjects); diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 1cafb1c..767ab7e 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -15,7 +15,8 @@ class Kernel extends ConsoleKernel protected $commands = [ Commands\ScheduleHealth::class, Commands\CalculateSCurve::class, - Commands\CalculateProgressGantt::class + Commands\CalculateProgressGantt::class, + Commands\ActualProgressProject::class ]; /** diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index caeb455..0dc108e 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -292,7 +292,7 @@ class ProjectController extends Controller $countBuilder = $dataBuilder['count']; $dataGet = $builder->get(); $totalRecord = $countBuilder->count(); - + Artisan::call('calculate:ActualProgressProject'); return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => $totalRecord], 200); } From 84c731370f801cff95fd76a847f2dc8426247dc7 Mon Sep 17 00:00:00 2001 From: wahyun Date: Wed, 24 Jul 2024 17:49:27 +0700 Subject: [PATCH 5/7] fix: SCurve progress bar --- app/Http/Controllers/ProjectController.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index caeb455..b898a56 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -415,7 +415,22 @@ class ProjectController extends Controller 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); + $dcdScurve = json_decode($sCurve['scurve'],true); + $dataScurve = $dcdScurve[0]['data']; + $today = date('Y-m-d'); + $progressPlanBar = 0; + foreach($dataScurve['date'] as $index => $dateArray) { + if (isset($dateArray[0])) { + $date = $dateArray[0]; + if($date <= $today) { + if (isset($dataScurve['percentagePlan'][$index])) { + $progressPlanBar = round($dataScurve['percentagePlan'][$index], 2); + } + } + } + } + $dcdScurve[0]['data']['progressPlanToDay'] = round($progressPlanBar,2); + return response()->json(['status' => 'success', 'code' => 200, 'data' => $dcdScurve], 200); } public function sCurveCommand(Request $request) From 5911a5ced96f0c7d0ebc0395577f8e2b6c93ba9f Mon Sep 17 00:00:00 2001 From: wahyun Date: Wed, 24 Jul 2024 17:49:58 +0700 Subject: [PATCH 6/7] fix: project expenditure update label, and value --- .../Controllers/DashboardBoDController.php | 90 +++++++++---------- 1 file changed, 43 insertions(+), 47 deletions(-) diff --git a/app/Http/Controllers/DashboardBoDController.php b/app/Http/Controllers/DashboardBoDController.php index 4c32b41..bf47cf8 100644 --- a/app/Http/Controllers/DashboardBoDController.php +++ b/app/Http/Controllers/DashboardBoDController.php @@ -32,51 +32,48 @@ class DashboardBoDController extends Controller { $totalExpenditure = $totalInvoice = $totalPaidInvoice = 0; - $totalBudgets = null; - $role = urldecode($role_name); - if (!empty($all_project) || $role === "Super Admin") { - $totalBudgets = Project::sum(DB::raw('CAST("rencana_biaya" AS DOUBLE PRECISION)')); - } else { - $totalBudgets = Project::where('created_by_id', $hierarchy) - ->sum(DB::raw('CAST("rencana_biaya" AS DOUBLE PRECISION)')); - } - $totalBudgets = Project::sum(DB::raw('CAST("rencana_biaya" AS DOUBLE PRECISION)')); - $projects = null; - - if (!empty($all_project) || $role === "Super Admin") { - $projects = Project::get(); - } else { - $projects = Project::where('created_by_id', $hierarchy) - ->get(); - } - - foreach ($projects as $project) { - $project->expenses = 0; - $resp = null; - if ($project->kode_sortname != "") { - - // $resp = $this->getInvoiceIntegration($project->kode_sortname); - // $cost = $resp->data->total_cost ?? 0; - // $cost = substr($cost, 0, strpos($cost, ".")); - $cost = 0; - $totalExpenditure = 0; - $totalInvoice = 0; - $totalPaidInvoice = 0; - - // $totalExpenditure += (int) $cost; - // $totalInvoice += $resp->data->total_invoice_amount ?? 0; - // $totalPaidInvoice += $resp->data->total_invoice_paid_amount ?? 0; - } - } - - return response()->json([ - 'data' => [ - 'total_budget' => (int) $totalBudgets ?? 0, - 'total_expenditure' => $totalExpenditure, - 'total_invoice' => $totalInvoice, - 'total_paid_invoice' => $totalPaidInvoice, - ] - ], 200); + $totalBudgets = []; + $projects = []; + $role = urldecode($role_name); + + if ($all_project) { + $totalBudgets = Project::select( + DB::raw('SUM(CAST(COALESCE(NULLIF(REPLACE(rencana_biaya, \'.\', \'\'), \'\'), \'0\') AS DOUBLE PRECISION)) AS total_rencana_biaya'), + DB::raw('SUM(CAST(COALESCE(NULLIF(REPLACE(value_proyek, \'.\', \'\'), \'\'), \'0\') AS DOUBLE PRECISION)) AS total_value_proyek'), + DB::raw('SUM(CAST(COALESCE(NULLIF(REPLACE(income_year, \'.\', \'\'), \'\'), \'0\') AS DOUBLE PRECISION)) AS total_income_year') + )->first(); + $projects = Project::get(); + Log::info(['dataTotal' => $totalBudgets]); + } else { + $totalBudgets = Project::where('created_by_id', $hierarchy) + ->select( + DB::raw('SUM(CAST(COALESCE(NULLIF(REPLACE(rencana_biaya, \'.\', \'\'), \'\'), \'0\') AS DOUBLE PRECISION)) AS total_rencana_biaya'), + DB::raw('SUM(CAST(COALESCE(NULLIF(REPLACE(value_proyek, \'.\', \'\'), \'\'), \'0\') AS DOUBLE PRECISION)) AS total_value_proyek'), + DB::raw('SUM(CAST(COALESCE(NULLIF(REPLACE(income_year, \'.\', \'\'), \'\'), \'0\') AS DOUBLE PRECISION)) AS total_income_year') + )->first(); + $projects = Project::where('created_by_id', $hierarchy)->get(); + } + + foreach ($projects as $project) { + $project->expenses = 0; + if ($project->kode_sortname != "") { + $cost = 0; + $totalExpenditure = 0; + $totalInvoice = 0; + $totalPaidInvoice = 0; + } + } + + return response()->json([ + 'data' => [ + 'total_budget' => (int) ($totalBudgets->total_rencana_biaya ?? 0), + 'total_expenditure' => $totalExpenditure, + 'total_invoice' => $totalInvoice, + 'total_paid_invoice' => $totalPaidInvoice, + 'total_value_proyek' => $totalBudgets->total_value_proyek ?? 0, + 'total_income_year' => $totalBudgets->total_income_year ?? 0 + ] + ], 200); } public function getDetailExpenditureColor($role_name) @@ -460,8 +457,7 @@ class DashboardBoDController extends Controller public function getDetailExpenditure($all_project, $hierarchy, $role_name) { - // $year = $this->interpolateYear($year); - $projects = null; + $projects = []; if ($all_project) { $projects = Project::orderBy('id', 'desc') ->get(); From 1bb2f02341afb36ccf1e1dafbd345e4450c796eb Mon Sep 17 00:00:00 2001 From: wahyun Date: Wed, 24 Jul 2024 19:57:28 +0700 Subject: [PATCH 7/7] feat: add endpoint calculate project actual progress --- app/Http/Controllers/ProjectController.php | 14 ++++---------- routes/web.php | 1 + 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index dcf18e9..916c81e 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -292,7 +292,6 @@ class ProjectController extends Controller $countBuilder = $dataBuilder['count']; $dataGet = $builder->get(); $totalRecord = $countBuilder->count(); - Artisan::call('calculate:ActualProgressProject'); return response()->json(['status' => 'success', 'code' => 200, 'data' => $dataGet, 'totalRecord' => $totalRecord], 200); } @@ -438,17 +437,12 @@ class ProjectController extends Controller 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 ActualProgressProjectCommand() { + Artisan::call('calculate:ActualProgressProject'); + } + public function getLinearSCurve(Request $request) { $data = MasterFunctionsHelper::getLinearSCurve($request); diff --git a/routes/web.php b/routes/web.php index b5fcde2..5165f44 100644 --- a/routes/web.php +++ b/routes/web.php @@ -93,6 +93,7 @@ $router->group(['prefix' => 'api', 'middleware' => 'cors'], function () use ($ro $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->get('/project/actual-progress-project-command', 'ProjectController@ActualProgressProjectCommand'); $router->post('/project/s-curve-command-test', 'ProjectController@calculateSCurvetest'); $router->post('/project/get-linear-s-curve', 'ProjectController@getLinearSCurve'); $router->post('/project/get-overdue-activities', 'ProjectController@getOverdueActivities');