Update Data Organization Inhealth
This commit is contained in:
@@ -21,6 +21,10 @@ class Organization extends Model
|
||||
'corporate_id_partner',
|
||||
'phone',
|
||||
'email',
|
||||
'operational_day',
|
||||
'operational_hour',
|
||||
'operational_day_other',
|
||||
'operational_hour_other',
|
||||
];
|
||||
|
||||
// public $with = [
|
||||
|
||||
@@ -16,7 +16,7 @@ class ApotekMandiriInhealtSeeder extends Seeder
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$file_path = resource_path('files/Data_Provider_Pharmacy_Delivery_Mandiri_Inhealth_-_10_Juni_2024.xlsx');
|
||||
$file_path = resource_path('files/data-apotik-layanan-pharmacy-delivery.xlsx');
|
||||
$reader = ReaderEntityFactory::createReaderFromFile($file_path);
|
||||
$reader->open($file_path);
|
||||
|
||||
@@ -35,48 +35,102 @@ class ApotekMandiriInhealtSeeder extends Seeder
|
||||
];
|
||||
|
||||
foreach ($reader->getSheetIterator() as $sheet) {
|
||||
$previousCells = null;
|
||||
foreach ($sheet->getRowIterator() as $index => $row) {
|
||||
if ($index >= 4) {
|
||||
$cells = $row->getCells();
|
||||
$data = [
|
||||
'code' => $cells[3]->getValue(),
|
||||
'name' => $cells[4]->getValue(),
|
||||
'type' => 'hospital',
|
||||
'corporate_id_partner' => 5, // Mandiri Inhealth
|
||||
'phone' => $cells[11]->getValue(),
|
||||
'email' => isset($cells[12]) ? $cells[12]->getValue() : null,
|
||||
];
|
||||
|
||||
// Update or create organization
|
||||
$organization = Organization::updateOrCreate(
|
||||
['code' => $cells[3]->getValue()],
|
||||
$data
|
||||
);
|
||||
|
||||
$data = [];
|
||||
|
||||
// Update or create address
|
||||
$geo = str_replace("'", "", $cells[9]->getValue()); // Hilangkan tanda petik tunggal
|
||||
$datageo = explode(",", $geo);
|
||||
// Check Merging
|
||||
if ($cells[0]->getValue() == '' && $cells[1]->getValue() == '' && $cells[2]->getValue() == '' && $cells[3]->getValue() == '' && $cells[4]->getValue() == '' && $cells[5]->getValue() == '' && $cells[6]->getValue() == '' && $cells[9]->getValue() == '' && $cells[10]->getValue() == '' && $cells[11]->getValue() == '' && $cells[12]->getValue() == '') {
|
||||
$data = [
|
||||
'code' => $previousCells[3]->getValue(),
|
||||
'name' => $previousCells[4]->getValue(),
|
||||
'type' => 'hospital',
|
||||
'corporate_id_partner' => 5, // Mandiri Inhealth
|
||||
'phone' => $previousCells[11]->getValue(),
|
||||
'email' => isset($previousCells[12]) ? $previousCells[12]->getValue() : null,
|
||||
'operational_day' => $this->expandDaysRange($previousCells[7]->getValue(), [$cells[7]->getValue()]),
|
||||
'operational_hour' => $previousCells[8]->getValue() == "24 jam" ? "00:00-24:00" : $previousCells[8]->getValue(),
|
||||
'operational_day_other' => $cells[7]->getValue(),
|
||||
'operational_hour_other' => $cells[8]->getValue()
|
||||
];
|
||||
|
||||
// Pastikan $datageo memiliki dua elemen sebelum mencoba mengaksesnya
|
||||
$lat = isset($datageo[0]) ? $datageo[0] : null;
|
||||
$lng = isset($datageo[1]) ? $datageo[1] : null;
|
||||
// Update or create organization
|
||||
$organization = Organization::updateOrCreate(
|
||||
['code' => $previousCells[3]->getValue()],
|
||||
$data
|
||||
);
|
||||
|
||||
|
||||
$address = $organization->addresses()->updateOrCreate(
|
||||
['addressable_id' => $organization->id],
|
||||
[
|
||||
'use' => 'both',
|
||||
'type' => 'physical',
|
||||
'text' => $cells[5]->getValue(),
|
||||
'postal_code' => $cells[6]->getValue(),
|
||||
'lat' => $lat,
|
||||
'lng' => $lng,
|
||||
]
|
||||
);
|
||||
|
||||
// Set main address id
|
||||
$organization->main_address_id = $address->id;
|
||||
$organization->save();
|
||||
// Update or create address
|
||||
$geo = str_replace("'", "", $previousCells[9]->getValue()); // Hilangkan tanda petik tunggal
|
||||
$datageo = explode(",", $geo);
|
||||
|
||||
// Pastikan $datageo memiliki dua elemen sebelum mencoba mengaksesnya
|
||||
$lat = isset($datageo[0]) ? $datageo[0] : null;
|
||||
$lng = isset($datageo[1]) ? $datageo[1] : null;
|
||||
|
||||
$address = $organization->addresses()->updateOrCreate(
|
||||
['addressable_id' => $organization->id],
|
||||
[
|
||||
'use' => 'both',
|
||||
'type' => 'physical',
|
||||
'text' => $previousCells[5]->getValue(),
|
||||
'postal_code' => $previousCells[6]->getValue(),
|
||||
'lat' => $lat,
|
||||
'lng' => $lng,
|
||||
]
|
||||
);
|
||||
|
||||
// Set main address id
|
||||
$organization->main_address_id = $address->id;
|
||||
$organization->save();
|
||||
} else {
|
||||
$data = [
|
||||
'code' => $cells[3]->getValue(),
|
||||
'name' => $cells[4]->getValue(),
|
||||
'type' => 'hospital',
|
||||
'corporate_id_partner' => 5, // Mandiri Inhealth
|
||||
'phone' => $cells[11]->getValue(),
|
||||
'email' => isset($cells[12]) ? $cells[12]->getValue() : null,
|
||||
'operational_day' => $this->expandDaysRange($cells[7]->getValue()),
|
||||
'operational_hour' => $cells[8]->getValue() == "24 jam" ? "00:00-24:00" : $cells[8]->getValue(),
|
||||
];
|
||||
|
||||
// Update or create organization
|
||||
$organization = Organization::updateOrCreate(
|
||||
['code' => $cells[3]->getValue()],
|
||||
$data
|
||||
);
|
||||
|
||||
|
||||
// Update or create address
|
||||
$geo = str_replace("'", "", $cells[9]->getValue()); // Hilangkan tanda petik tunggal
|
||||
$datageo = explode(",", $geo);
|
||||
|
||||
// Pastikan $datageo memiliki dua elemen sebelum mencoba mengaksesnya
|
||||
$lat = isset($datageo[0]) ? $datageo[0] : null;
|
||||
$lng = isset($datageo[1]) ? $datageo[1] : null;
|
||||
|
||||
$address = $organization->addresses()->updateOrCreate(
|
||||
['addressable_id' => $organization->id],
|
||||
[
|
||||
'use' => 'both',
|
||||
'type' => 'physical',
|
||||
'text' => $cells[5]->getValue(),
|
||||
'postal_code' => $cells[6]->getValue(),
|
||||
'lat' => $lat,
|
||||
'lng' => $lng,
|
||||
]
|
||||
);
|
||||
|
||||
// Set main address id
|
||||
$organization->main_address_id = $address->id;
|
||||
$organization->save();
|
||||
}
|
||||
|
||||
$previousCells = $cells;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -84,4 +138,36 @@ class ApotekMandiriInhealtSeeder extends Seeder
|
||||
$reader->close();
|
||||
|
||||
}
|
||||
|
||||
private function expandDaysRange($input, $excludedDays = []) {
|
||||
// Daftar hari dalam seminggu
|
||||
$daysOfWeek = ["Senin", "Selasa", "Rabu", "Kamis", "Jumat", "Sabtu", "Minggu"];
|
||||
|
||||
// Pisahkan input berdasarkan tanda "-"
|
||||
$range = array_map('trim', explode('-', $input));
|
||||
|
||||
if (count($range) == 2) {
|
||||
// Cari posisi hari pertama dan hari terakhir di dalam array $daysOfWeek
|
||||
$startIndex = array_search($range[0], $daysOfWeek);
|
||||
$endIndex = array_search($range[1], $daysOfWeek);
|
||||
|
||||
// Jika ditemukan, ambil rentang hari
|
||||
if ($startIndex !== false && $endIndex !== false && $startIndex <= $endIndex) {
|
||||
// Ambil hari-hari dalam rentang tersebut
|
||||
$daysRange = array_slice($daysOfWeek, $startIndex, ($endIndex - $startIndex + 1));
|
||||
|
||||
// Jika ada hari yang ingin di-exclude, hapus dari $daysRange
|
||||
if (!empty($excludedDays)) {
|
||||
$daysRange = array_diff($daysRange, $excludedDays);
|
||||
}
|
||||
|
||||
// Gabungkan menjadi string dengan koma
|
||||
return implode(', ', $daysRange);
|
||||
} else {
|
||||
return "Hari tidak valid atau rentang tidak benar.";
|
||||
}
|
||||
} else {
|
||||
return "Format input tidak sesuai.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BIN
resources/files/data-apotik-layanan-pharmacy-delivery.xlsx
Normal file
BIN
resources/files/data-apotik-layanan-pharmacy-delivery.xlsx
Normal file
Binary file not shown.
BIN
resources/files/~$data-apotik-layanan-pharmacy-delivery.xlsx
Normal file
BIN
resources/files/~$data-apotik-layanan-pharmacy-delivery.xlsx
Normal file
Binary file not shown.
Reference in New Issue
Block a user