diff --git a/app/Console/Commands/ExecuteScraping.php b/app/Console/Commands/ExecuteScraping.php deleted file mode 100644 index d440889..0000000 --- a/app/Console/Commands/ExecuteScraping.php +++ /dev/null @@ -1,40 +0,0 @@ -onQueue('default'); - Log::info("running scheduler daily scraping"); - } -} diff --git a/app/Http/Controllers/RequestAssignment/PbgTaskController.php b/app/Http/Controllers/RequestAssignment/PbgTaskController.php index 98677e6..d772072 100644 --- a/app/Http/Controllers/RequestAssignment/PbgTaskController.php +++ b/app/Http/Controllers/RequestAssignment/PbgTaskController.php @@ -56,7 +56,7 @@ class PbgTaskController extends Controller */ public function show(string $id) { - $data = PbgTask::with(['pbg_task_retributions','pbg_task_index_integrations', 'pbg_task_retributions.pbg_task_prasarana'])->findOrFail($id); + $data = PbgTask::with(['pbg_task_retributions','pbg_task_index_integrations', 'pbg_task_retributions.pbg_task_prasarana', 'pbg_task_detail'])->findOrFail($id); $statusOptions = PbgTaskStatus::getStatuses(); $applicationTypes = PbgTaskApplicationTypes::labels(); return view("pbg_task.show", compact("data", 'statusOptions', 'applicationTypes')); diff --git a/app/Jobs/ScrapingDataJob.php b/app/Jobs/ScrapingDataJob.php index c8fd86c..a013ba3 100644 --- a/app/Jobs/ScrapingDataJob.php +++ b/app/Jobs/ScrapingDataJob.php @@ -32,6 +32,7 @@ class ScrapingDataJob implements ShouldQueue */ public function handle() { + $failed_uuid = null; try { $client = app(Client::class); @@ -48,8 +49,6 @@ class ScrapingDataJob implements ShouldQueue 'failed_uuid' => null ]); - $failed_uuid = null; - // Run the scraping services $service_google_sheet->run_service(); $service_pbg_task->run_service(); @@ -79,6 +78,7 @@ class ScrapingDataJob implements ShouldQueue if (isset($import_datasource)) { $import_datasource->update([ 'status' => 'failed', + 'message' => 'Terjadi kesalahan, Syncronize tidak selesai', 'response_body' => 'Terjadi kesalahan, Syncronize tidak selesai', 'finish_time' => now(), 'failed_uuid' => $failed_uuid, diff --git a/app/Jobs/SyncronizeSIMBG.php b/app/Jobs/SyncronizeSIMBG.php deleted file mode 100644 index d9551be..0000000 --- a/app/Jobs/SyncronizeSIMBG.php +++ /dev/null @@ -1,80 +0,0 @@ -first(); - - if (!$import_datasource) { - $import_datasource = ImportDatasource::create([ - 'message' => 'Initiating scraping...', - 'response_body' => null, - 'status' => 'processing' - ]); - } - try { - // Create an instance of GuzzleHttp\Client inside handle() - $client = new Client(); - - // Create instances of services inside handle() - $service_pbg_task = app(ServicePbgTask::class); - $service_tab_pbg_task = app(ServiceTabPbgTask::class); - - // Create a record with "processing" status - - - // Run the service - $service_google_sheet = new ServiceGoogleSheet(); - \Log::info('Starting Google Sheet service'); - $service_google_sheet->run_service(); - \Log::info('Google Sheet service completed'); - - \Log::info('Starting PBG Task service'); - $service_pbg_task->run_service(); - \Log::info('PBG Task service completed'); - - \Log::info('Starting Tab PBG Task service'); - $service_tab_pbg_task->run_service(); - \Log::info('Tab PBG Task service completed'); - - // Update the record status to "success" after completion - $import_datasource->update([ - 'status' => 'success', - 'message' => 'Scraping completed successfully.' - ]); - } catch (\Exception $e) { - \Log::error("SyncronizeSIMBG Job Failed: " . $e->getMessage(), [ - 'exception' => $e, - ]); - $import_datasource->update([ - 'status' => 'failed', - 'message' => 'Failed job' - ]); - $this->fail($e); // Mark the job as failed - } - } -} diff --git a/app/Services/ServiceGoogleSheet.php b/app/Services/ServiceGoogleSheet.php index 7389bc2..039a44e 100644 --- a/app/Services/ServiceGoogleSheet.php +++ b/app/Services/ServiceGoogleSheet.php @@ -36,7 +36,7 @@ class ServiceGoogleSheet public function run_service(){ try{ - $this->sync_big_data(); + // $this->sync_big_data(); $this->sync_google_sheet_data(); }catch(Exception $e){ throw $e; @@ -135,7 +135,11 @@ class ServiceGoogleSheet } // Count occurrences of each no_registrasi - $registrasiCounts = array_count_values(array_column($mapUpsert, 'no_registrasi')); + // Filter out null values before counting to avoid array_count_values error + $registrationNumbers = array_filter(array_column($mapUpsert, 'no_registrasi'), function($value) { + return $value !== null && $value !== ''; + }); + $registrasiCounts = array_count_values($registrationNumbers); // Filter duplicates (those appearing more than once) $duplicates = array_filter($registrasiCounts, function ($count) { @@ -146,8 +150,14 @@ class ServiceGoogleSheet Log::warning("Duplicate no_registrasi found", ['duplicates' => array_keys($duplicates)]); } - // Remove duplicates before upsert - $mapUpsert = collect($mapUpsert)->unique('no_registrasi')->values()->all(); + // Remove duplicates before upsert - filter out entries with null no_registrasi + $mapUpsert = collect($mapUpsert) + ->filter(function($item) { + return !empty($item['no_registrasi']); + }) + ->unique('no_registrasi') + ->values() + ->all(); $batchSize = 1000; $chunks = array_chunk($mapUpsert, $batchSize); @@ -200,9 +210,19 @@ class ServiceGoogleSheet } foreach ($data_setting_result as $key => $value) { + // Ensure value is not null before saving to database + $processedValue = 0; // Default to 0 instead of null + if ($value !== null && $value !== '') { + if (strpos($key, '_COUNT') !== false) { + $processedValue = $this->convertToInteger($value) ?? 0; + } else { + $processedValue = $this->convertToDecimal($value) ?? 0; + } + } + DataSetting::updateOrInsert( ["key" => $key], // Find by key - ["value" => $value] // Update or insert value + ["value" => $processedValue] // Update or insert value ); } @@ -294,9 +314,22 @@ class ServiceGoogleSheet ]; foreach ($dataSettings as $key => $value) { + // Ensure value is not null before saving to database + $processedValue = null; + if ($value !== null && $value !== '') { + // Try to convert to appropriate type based on key name + if (strpos($key, '_COUNT') !== false) { + $processedValue = $this->convertToInteger($value) ?? 0; + } else { + $processedValue = $this->convertToDecimal($value) ?? 0; + } + } else { + $processedValue = 0; // Default to 0 instead of null + } + DataSetting::updateOrInsert( ['key' => $key], - ['value' => $this->convertToInteger($value) ?? 0] + ['value' => $processedValue] ); } diff --git a/resources/views/pbg_task/show.blade.php b/resources/views/pbg_task/show.blade.php index 5a5d573..a444b73 100644 --- a/resources/views/pbg_task/show.blade.php +++ b/resources/views/pbg_task/show.blade.php @@ -122,6 +122,11 @@ Penugasan +
@@ -280,6 +285,119 @@
+
+ @if ($data->pbg_task_detail) +
+
+
Fungsi Bangunan
+
{{$data->pbg_task_detail->building_purpose}}
+
Jenis Prototipe
+
{{$data->pbg_task_detail->prototype ?? '-'}}
+
+
+
Sub Fungsi Bangunan
+
{{$data->pbg_task_detail->building_use}}
+
+
+
Nama Bangunan
+
{{$data->pbg_task_detail->name_building}}
+
+
+
+
+
Spesifikasi Bangunan
+
+
+
+
+
Luas Bangunan
+
{{$data->pbg_task_detail->total_area ?? '-'}} m2
+
Jumlah Lapis Basemen
+
{{$data->pbg_task_detail->basement ?? '-'}}
+
Estimasi Jumlah Penghuni
+
{{$data->pbg_task_detail->occupancy ?? '-'}}
+
+
+
Ketinggian Bangunan
+
{{$data->pbg_task_detail->height ?? '-'}} m
+
Luas Basemen
+
{{$data->pbg_task_detail->basement_area ?? '-'}}
+
+
+
Jumlah Lantai
+
{{$data->pbg_task_detail->floor ?? '-'}}
+
Jumlah Unit
+
{{$data->pbg_task_detail->unit ?? '-'}}
+
+
+
+
+
+
+
+
+
Intensitas Bangunan
+
+
+
+
+
Nomor KKPR / KRK
+
{{$data->pbg_task_detail->kkr_number ?? '-'}}
+
Koefisien Lantai Bangunan (KLB)
+
{{$data->pbg_task_detail->koefisien_lantai_bangunan ?? '-'}}
+
+
+
Garis Sempadan Bangunan (GSB)
+
{{$data->pbg_task_detail->gsb ?? '-'}}
+
Koefisien Dasar Hijau (KDH)
+
{{$data->pbg_task_detail->koefisien_dasar_hijau ?? '-'}}
+
+
+
Koefisien Dasar Bangunan (KDB)
+
{{$data->pbg_task_detail->koefisien_dasar_bangunan ?? '-'}}
+
+
+
+
+
+
+
+
+
Lokasi Bangunan
+
+
+
+
+
Provinsi
+
{{$data->pbg_task_detail->building_province_name ?? '-'}}
+
Desa / Kelurahan
+
{{$data->pbg_task_detail->building_ward_name ?? '-'}}
+
+
+
Kabupaten / Kota
+
{{$data->pbg_task_detail->building_regency_name ?? '-'}}
+
Alamat Lengkap
+
{{$data->pbg_task_detail->building_address ?? '-'}}
+
+
+
Kecamatan
+
{{$data->pbg_task_detail->building_district_name ?? '-'}}
+
Koordinat Latitude dan Longitude
+
{{$data->pbg_task_detail->latitude ?? '-'}}, {{$data->pbg_task_detail->longitude ?? '-'}}
+
+
+
+
+
+
+ @else +
+
+ Data Not Available +
+
+ @endif +