diff --git a/app/Jobs/ScrapingDataJob.php b/app/Jobs/ScrapingDataJob.php index d9cc039..42b338c 100644 --- a/app/Jobs/ScrapingDataJob.php +++ b/app/Jobs/ScrapingDataJob.php @@ -2,6 +2,7 @@ namespace App\Jobs; +use App\Models\BigdataResume; use App\Models\ImportDatasource; use App\Services\ServiceGoogleSheet; use App\Services\ServicePbgTask; @@ -51,6 +52,11 @@ class ScrapingDataJob implements ShouldQueue $service_pbg_task->run_service(); $service_tab_pbg_task->run_service(); + $data_setting_result = $service_google_sheet->get_big_resume_data(); + + BigdataResume::generateResumeData($import_datasource->id, "all", $data_setting_result); + BigdataResume::generateResumeData($import_datasource->id, now()->year, $data_setting_result); + // Update status to success $import_datasource->update([ 'status' => 'success', diff --git a/app/Services/ServiceGoogleSheet.php b/app/Services/ServiceGoogleSheet.php index 4881856..ae3b1bd 100644 --- a/app/Services/ServiceGoogleSheet.php +++ b/app/Services/ServiceGoogleSheet.php @@ -44,7 +44,7 @@ class ServiceGoogleSheet if (empty($sheet_data) || count($sheet_data) < 2) { Log::warning("sync_google_sheet_data: No valid data found."); - throw new \Exception("sync_google_sheet_data: No valid data found."); + throw new Exception("sync_google_sheet_data: No valid data found."); } $cleanValue = function ($value) { @@ -210,6 +210,47 @@ class ServiceGoogleSheet } } + public function get_big_resume_data(){ + try { + $sheet_big_data = $this->get_data_by_sheet(); + $data_setting_result = []; // Initialize result storage + + $found_section = null; // Track which section is found + + foreach ($sheet_big_data as $row) { + // Check for section headers + if (in_array("•PROSES PENERBITAN:", $row)) { + $found_section = "MENUNGGU_KLIK_DPMPTSP"; + } elseif (in_array("•BERKAS AKTUAL TERVERIFIKASI DINAS TEKNIS 2024:", $row)) { + $found_section = "REALISASI_TERBIT_PBG"; + } elseif (in_array("•TERPROSES DI DPUTR: belum selesai rekomtek'", $row)) { + $found_section = "PROSES_DINAS_TEKNIS"; + } + + // If a section is found and we reach "Grand Total", save the corresponding values + if ($found_section && isset($row[0]) && trim($row[0]) === "Grand Total") { + if ($found_section === "MENUNGGU_KLIK_DPMPTSP") { + $data_setting_result["MENUNGGU_KLIK_DPMPTSP_COUNT"] = $this->convertToInteger($row[2]) ?? null; + $data_setting_result["MENUNGGU_KLIK_DPMPTSP_SUM"] = $this->convertToDecimal($row[3]) ?? null; + } elseif ($found_section === "REALISASI_TERBIT_PBG") { + $data_setting_result["REALISASI_TERBIT_PBG_COUNT"] = $this->convertToInteger($row[2]) ?? null; + $data_setting_result["REALISASI_TERBIT_PBG_SUM"] = $this->convertToDecimal($row[4]) ?? null; + } elseif ($found_section === "PROSES_DINAS_TEKNIS") { + $data_setting_result["PROSES_DINAS_TEKNIS_COUNT"] = $this->convertToInteger($row[2]) ?? null; + $data_setting_result["PROSES_DINAS_TEKNIS_SUM"] = $this->convertToDecimal($row[3]) ?? null; + } + + // Reset section tracking after capturing "Grand Total" + $found_section = null; + } + } + return $data_setting_result; + }catch(Exception $exception){ + Log::error("Error getting big resume data", ['error' => $exception->getMessage()]); + throw $exception; + } + } + private function get_data_by_sheet($no_sheet = 1){ $spreadsheet = $this->service->spreadsheets->get($this->spreadsheetID); $sheets = $spreadsheet->getSheets(); diff --git a/app/Services/ServiceTabPbgTask.php b/app/Services/ServiceTabPbgTask.php index 79229b7..1d5c170 100644 --- a/app/Services/ServiceTabPbgTask.php +++ b/app/Services/ServiceTabPbgTask.php @@ -37,7 +37,7 @@ class ServiceTabPbgTask public function run_service() { try { - $pbg_tasks = PbgTask::all(); + $pbg_tasks = PbgTask::take(5)->get(); foreach ($pbg_tasks as $pbg_task) { $this->scraping_task_assignments($pbg_task->uuid);