partial update add page laporan pimpinan and fix upload big data excel pdam

This commit is contained in:
arifal
2025-02-27 19:23:06 +07:00
parent 01fda22c89
commit b0bab784d1
13 changed files with 394 additions and 73 deletions

View File

@@ -11,42 +11,87 @@ use Maatwebsite\Excel\Concerns\WithHeadingRow;
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
use Illuminate\Contracts\Queue\ShouldQueue;
use Maatwebsite\Excel\Concerns\WithBatchInserts;
use Illuminate\Support\Facades\Log;
class CustomersImport implements ToCollection, WithMultipleSheets
class CustomersImport implements ToCollection, WithMultipleSheets, WithChunkReading, WithBatchInserts, ShouldQueue, WithHeadingRow
{
/**
* @param Collection $collection
*/
*/
public function collection(Collection $collection)
{
$batchData = [];
$batchSize = 1000; // Process in smaller chunks
foreach ($collection->skip(1) as $row) {
if (!isset($row[0]) || empty($row[0])) {
continue;
foreach ($collection as $row) {
if (!isset($row['nomor_pelanggan']) || empty($row['nomor_pelanggan'])) {
continue; // Skip rows without 'nomor_pelanggan'
}
$latitude = filter_var($row[4], FILTER_VALIDATE_FLOAT) ? bcadd($row[4], '0', 18) : null;
$longitude = filter_var($row[5], FILTER_VALIDATE_FLOAT) ? bcadd($row[5], '0', 18) : null;
// Default values
$latitude = '0';
$longitude = '0';
// Convert and normalize latitude
if (isset($row['latkor']) && !empty(trim($row['latkor']))) {
$latitude = str_replace(',', '.', trim($row['latkor'])); // Replace comma with dot
if (is_numeric($latitude)) {
$latitude = bcadd($latitude, '0', 18); // Convert to decimal with 18 precision
} else {
$latitude = '0'; // Default fallback
}
} else {
$latitude = '0';
}
// Convert and normalize longitude
if (isset($row['lonkor']) && !empty(trim($row['lonkor']))) {
$longitude = str_replace(',', '.', trim($row['lonkor'])); // Replace comma with dot
if (is_numeric($longitude)) {
$longitude = bcadd($longitude, '0', 18); // Convert to decimal with 18 precision
} else {
$longitude = '0'; // Default fallback
}
} else {
$longitude = '0';
}
$batchData[] = [
'nomor_pelanggan' => $row[0],
'kota_pelayanan' => $row[1],
'nama' => $row[2],
'alamat' => $row[3],
'nomor_pelanggan' => $row['nomor_pelanggan'] ?? '',
'kota_pelayanan' => $row['kota_pelayanan'] ?? '',
'nama' => $row['nama'] ?? '',
'alamat' => $row['alamat'] ?? '',
'latitude' => $latitude,
'longitude' => $longitude,
];
// Batch insert every 1000 rows
if (count($batchData) >= $batchSize) {
Customer::upsert($batchData, ['nomor_pelanggan'], ['kota_pelayanan', 'nama', 'alamat', 'latitude', 'longitude']);
$batchData = []; // Clear the batch
}
}
// Insert remaining data
if (!empty($batchData)) {
Customer::upsert($batchData, ['nomor_pelanggan'], ['kota_pelayanan', 'nama', 'alamat', 'latitude', 'longitude']);
}
}
public function sheets(): array {
return [
0 => $this
];
}
public function chunkSize(): int
{
return 1000;
}
public function batchSize(): int
{
return 1000;
}
}