fix error sync google sheet

This commit is contained in:
arifal
2025-06-24 13:00:48 +07:00
parent 2f43ebe97e
commit a01b6f5611
2 changed files with 100 additions and 6 deletions

View File

@@ -137,8 +137,13 @@ class ServiceGoogleSheet
// Count occurrences of each 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 !== '';
// Ensure only string and integer values are counted
return $value !== null && $value !== '' && (is_string($value) || is_int($value));
});
// Additional safety check: convert all values to strings
$registrationNumbers = array_map('strval', $registrationNumbers);
$registrasiCounts = array_count_values($registrationNumbers);
// Filter duplicates (those appearing more than once)
@@ -220,7 +225,7 @@ class ServiceGoogleSheet
}
}
DataSetting::updateOrInsert(
DataSetting::updateOrCreate(
["key" => $key], // Find by key
["value" => $processedValue] // Update or insert value
);
@@ -315,7 +320,7 @@ class ServiceGoogleSheet
foreach ($dataSettings as $key => $value) {
// Ensure value is not null before saving to database
$processedValue = null;
$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) {
@@ -323,11 +328,9 @@ class ServiceGoogleSheet
} else {
$processedValue = $this->convertToDecimal($value) ?? 0;
}
} else {
$processedValue = 0; // Default to 0 instead of null
}
DataSetting::updateOrInsert(
DataSetting::updateOrCreate(
['key' => $key],
['value' => $processedValue]
);