diff --git a/app/Http/Controllers/Api/PbgTaskController.php b/app/Http/Controllers/Api/PbgTaskController.php index 354392a..8ba3ab8 100644 --- a/app/Http/Controllers/Api/PbgTaskController.php +++ b/app/Http/Controllers/Api/PbgTaskController.php @@ -6,6 +6,7 @@ use App\Enums\ImportDatasourceStatus; use App\Http\Controllers\Controller; use App\Http\Requests\PbgTaskMultiStepRequest; use App\Http\Resources\PbgTaskResource; +use App\Models\DataSetting; use App\Models\ImportDatasource; use App\Models\PbgTask; use App\Models\PbgTaskGoogleSheet; @@ -109,18 +110,55 @@ class PbgTaskController extends Controller } public function syncPbgFromGoogleSheet(){ + $import_datasource = ImportDatasource::create([ + "message" => "initialization", + "response_body" => null, + "status" => ImportDatasourceStatus::Processing->value, + ]); try{ $totalRowCount = $this->googleSheetService->getLastRowByColumn("C"); $sheetData = $this->googleSheetService->getSheetDataCollection($totalRowCount); + $sheet_big_data = $this->googleSheetService->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"] = $row[2] ?? null; + $data_setting_result["MENUNGGU_KLIK_DPMPTSP_SUM"] = $row[3] ?? null; + } elseif ($found_section === "REALISASI_TERBIT_PBG") { + $data_setting_result["REALISASI_TERBIT_PBG_COUNT"] = $row[2] ?? null; + $data_setting_result["REALISASI_TERBIT_PBG_SUM"] = $row[4] ?? null; + } elseif ($found_section === "PROSES_DINAS_TEKNIS") { + $data_setting_result["PROSES_DINAS_TEKNIS_COUNT"] = $row[2] ?? null; + $data_setting_result["PROSES_DINAS_TEKNIS_SUM"] = $row[3] ?? null; + } + + // Reset section tracking after capturing "Grand Total" + $found_section = null; + } + } + foreach ($data_setting_result as $key => $value) { + DataSetting::updateOrInsert( + ["key" => $key], // Find by key + ["value" => $value] // Update or insert value + ); + } $mapToUpsert = []; $count = 0; - $import_datasource = ImportDatasource::create([ - "message" => "initialization", - "response_body" => null, - "status" => ImportDatasourceStatus::Processing->value, - ]); - foreach($sheetData as $data){ $mapToUpsert[] = [ diff --git a/app/Services/GoogleSheetService.php b/app/Services/GoogleSheetService.php index 488b2e8..ad60527 100644 --- a/app/Services/GoogleSheetService.php +++ b/app/Services/GoogleSheetService.php @@ -140,4 +140,13 @@ class GoogleSheetService throw $e; } } + public function get_data_by_sheet($no_sheet = 1){ + $spreadsheet = $this->service->spreadsheets->get($this->spreadsheetID); + $sheets = $spreadsheet->getSheets(); + $sheetTitle = $sheets[$no_sheet]->getProperties()->getTitle(); + $range = "{$sheetTitle}"; + $response = $this->service->spreadsheets_values->get($this->spreadsheetID, $range); + $values = $response->getValues(); + return!empty($values)? $values : []; + } } diff --git a/app/Services/ServiceSIMBG.php b/app/Services/ServiceSIMBG.php index 11176e0..e700cee 100644 --- a/app/Services/ServiceSIMBG.php +++ b/app/Services/ServiceSIMBG.php @@ -29,10 +29,15 @@ class ServiceSIMBG */ public function __construct() { - $this->email = trim((string) GlobalSetting::where('key','SIMBG_EMAIL')->firstOrFail()->value); - $this->password = trim((string) GlobalSetting::where('key','SIMBG_PASSWORD')->firstOrFail()->value); - $this->simbg_host = trim((string)GlobalSetting::where('key','SIMBG_HOST')->firstOrFail()->value); - $this->fetch_per_page = trim((string)GlobalSetting::where('key','FETCH_PER_PAGE')->firstOrFail()->value); + $settings = GlobalSetting::whereIn('key', [ + 'SIMBG_EMAIL', 'SIMBG_PASSWORD', 'SIMBG_HOST', 'FETCH_PER_PAGE' + ])->pluck('value', 'key'); + + $this->email = trim((string) ($settings['SIMBG_EMAIL'] ?? "")); + $this->password = trim((string) ($settings['SIMBG_PASSWORD'] ?? "")); + $this->simbg_host = trim((string) ($settings['SIMBG_HOST'] ?? "")); + $this->fetch_per_page = trim((string) ($settings['FETCH_PER_PAGE'] ?? "")); + $this->service_client = new ServiceClient($this->simbg_host); } diff --git a/public/build/.vite/manifest.json b/public/build/.vite/manifest.json index 4b579e5..69fbf06 100644 --- a/public/build/.vite/manifest.json +++ b/public/build/.vite/manifest.json @@ -102,7 +102,7 @@ "isEntry": true }, "resources/js/dashboards/bigdata.js": { - "file": "assets/bigdata-DYDUaCEC.js", + "file": "assets/bigdata-Cyb9tZIY.js", "name": "bigdata", "src": "resources/js/dashboards/bigdata.js", "isEntry": true, @@ -391,7 +391,7 @@ "isEntry": true }, "resources/scss/dashboards/_bigdata.scss": { - "file": "assets/_bigdata-0hCjAhYp.css", + "file": "assets/_bigdata-Syu0AGbZ.css", "src": "resources/scss/dashboards/_bigdata.scss", "isEntry": true }, @@ -401,7 +401,7 @@ "isEntry": true }, "resources/scss/style.scss": { - "file": "assets/style-DUYVmgAM.css", + "file": "assets/style-H92i7DXd.css", "src": "resources/scss/style.scss", "isEntry": true }