diff --git a/app/Helpers/MasterFunctionsHelper.php b/app/Helpers/MasterFunctionsHelper.php index 6d75174..5c9764f 100644 --- a/app/Helpers/MasterFunctionsHelper.php +++ b/app/Helpers/MasterFunctionsHelper.php @@ -428,7 +428,7 @@ class MasterFunctionsHelper } $lastReal = $tempPercentageReal[count($tempPercentageReal) - 1]; - $totalBCWP = $lastReal * $totalBCWP; + $totalBCWP = $lastReal * $dataProject->rencana_biaya / 100; $dataResponse = array( "date" => $tempDate, "percentage" => $tempPercentage, @@ -723,7 +723,7 @@ class MasterFunctionsHelper } $lastReal = $tempPercentageReal[count($tempPercentageReal) - 1]; - $totalBCWP = $lastReal * $totalBCWP; + $totalBCWP = $lastReal * $dataProject->rencana_biaya / 100; $dataResponse = array( "date" => $tempDate, "percentage" => $tempPercentage, diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 3a204d7..48cb86e 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -30,6 +30,7 @@ use Illuminate\Support\Facades\DB; use App\Helpers\MasterFunctionsHelper; use App\Models\ReportActivityMaterial; use Illuminate\Support\Facades\Artisan; +use App\Jobs\ProcessSCurve; const API_GEOLOCATION = "https://nominatim.oslogdev.com/search/ADDR?format=json&addressdetails=1&limit=1"; @@ -328,9 +329,18 @@ class ProjectController extends Controller } public function sCurveCommand(Request $request){ - Artisan::call('calculate:scurve', [ - 'project_id' => $request->project_id - ]); + 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){ diff --git a/app/Jobs/ProcessSCurve.php b/app/Jobs/ProcessSCurve.php new file mode 100644 index 0000000..fe07ab9 --- /dev/null +++ b/app/Jobs/ProcessSCurve.php @@ -0,0 +1,36 @@ +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(); + } +} diff --git a/database/migrations/2023_08_29_130624_create_jobs_table.php b/database/migrations/2023_08_29_130624_create_jobs_table.php new file mode 100644 index 0000000..1be9e8a --- /dev/null +++ b/database/migrations/2023_08_29_130624_create_jobs_table.php @@ -0,0 +1,36 @@ +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'); + } +}