Browse Source

Merge pull request 'update bcwp' (#174) from dev-wahyu into staging

Reviewed-on: ordo/adw-backend#174
pull/3/head
ibnu 1 year ago
parent
commit
75f31c9d6e
  1. 4
      app/Helpers/MasterFunctionsHelper.php
  2. 16
      app/Http/Controllers/ProjectController.php
  3. 36
      app/Jobs/ProcessSCurve.php
  4. 36
      database/migrations/2023_08_29_130624_create_jobs_table.php

4
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,

16
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){

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

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');
}
}
Loading…
Cancel
Save