fix data and dashboard count and sum
This commit is contained in:
@@ -356,39 +356,63 @@ class ServiceGoogleSheet
|
||||
|
||||
public function get_big_resume_data(){
|
||||
try {
|
||||
$sheet_big_data = $this->get_data_by_sheet();
|
||||
$data_setting_result = []; // Initialize result storage
|
||||
$sections = [
|
||||
'TARGET_PAD' => "TARGET PAD 2024",
|
||||
'KEKURANGAN_POTENSI' => "DEVIASI TARGET DENGAN POTENSI TOTAL BERKAS",
|
||||
'TOTAL_POTENSI_BERKAS' => "•TOTAL BERKAS 2025",
|
||||
'BELUM_TERVERIFIKASI' => "•BERKAS AKTUAL BELUM TERVERIFIKASI (POTENSI):",
|
||||
'TERVERIFIKASI' => "•BERKAS AKTUAL TERVERIFIKASI DINAS TEKNIS 2025:",
|
||||
'NON_USAHA' => "•NON USAHA: HUNIAN, SOSBUD, KEAGAMAAN",
|
||||
'USAHA' => "•USAHA: USAHA, CAMPURAN, KOLEKTIF, PRASARANA",
|
||||
'PROSES_DINAS_TEKNIS' => "•TERPROSES DI DPUTR: belum selesai rekomtek'",
|
||||
'WAITING_KLIK_DPMPTSP' => "•TERPROSES DI PTSP: Pengiriman SKRD/ Validasi di PTSP",
|
||||
'REALISASI_TERBIT_PBG' => "•BERKAS YANG TERBIT PBG 2025:"
|
||||
];
|
||||
|
||||
$found_section = null; // Track which section is found
|
||||
$result = [];
|
||||
|
||||
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;
|
||||
foreach ($sections as $key => $identifier) {
|
||||
$values = $this->get_values_from_section($identifier, [10, 11], 8);
|
||||
|
||||
if (!empty($values)) {
|
||||
$result[$key] = [
|
||||
'identifier' => $identifier,
|
||||
'total' => $values[0] ?? null, // index 0 untuk total/jumlah
|
||||
'nominal' => $values[1] ?? null // index 1 untuk nominal
|
||||
];
|
||||
}
|
||||
}
|
||||
return $data_setting_result;
|
||||
|
||||
// Save data settings
|
||||
$dataSettings = [
|
||||
'TARGET_PAD' => $this->convertToDecimal($result['TARGET_PAD']['nominal']) ?? 0,
|
||||
'KEKURANGAN_POTENSI' => $this->convertToDecimal($result['KEKURANGAN_POTENSI']['nominal']) ?? 0,
|
||||
'REALISASI_TERBIT_PBG_COUNT' => $this->convertToInteger($result['REALISASI_TERBIT_PBG']['total']) ?? 0,
|
||||
'REALISASI_TERBIT_PBG_SUM' => $this->convertToDecimal($result['REALISASI_TERBIT_PBG']['nominal']) ?? 0,
|
||||
'MENUNGGU_KLIK_DPMPTSP_COUNT' => $this->convertToInteger($result['WAITING_KLIK_DPMPTSP']['total']) ?? 0,
|
||||
'MENUNGGU_KLIK_DPMPTSP_SUM' => $this->convertToDecimal($result['WAITING_KLIK_DPMPTSP']['nominal']) ?? 0,
|
||||
'PROSES_DINAS_TEKNIS_COUNT' => $this->convertToInteger($result['PROSES_DINAS_TEKNIS']['total']) ?? 0,
|
||||
'PROSES_DINAS_TEKNIS_SUM' => $this->convertToDecimal($result['PROSES_DINAS_TEKNIS']['nominal']) ?? 0,
|
||||
];
|
||||
|
||||
foreach ($dataSettings as $key => $value) {
|
||||
// Ensure value is not null before saving to database
|
||||
$processedValue = 0; // Default to 0 instead of 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;
|
||||
}
|
||||
}
|
||||
|
||||
DataSetting::updateOrCreate(
|
||||
['key' => $key],
|
||||
['value' => $processedValue]
|
||||
);
|
||||
}
|
||||
return $dataSettings;
|
||||
}catch(Exception $exception){
|
||||
Log::error("Error getting big resume data", ['error' => $exception->getMessage()]);
|
||||
throw $exception;
|
||||
|
||||
Reference in New Issue
Block a user