88 lines
3.0 KiB
PHP
88 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
|
use Illuminate\Database\Seeder;
|
|
use App\Models\Organization;
|
|
use Box\Spout\Reader\Common\Creator\ReaderEntityFactory;
|
|
|
|
class ApotekMandiriInhealtSeeder extends Seeder
|
|
{
|
|
/**
|
|
* Run the database seeds.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function run()
|
|
{
|
|
$file_path = resource_path('files/Data_Provider_Pharmacy_Delivery_Mandiri_Inhealth_-_10_Juni_2024.xlsx');
|
|
$reader = ReaderEntityFactory::createReaderFromFile($file_path);
|
|
$reader->open($file_path);
|
|
|
|
$cell_map = [ // Urutan kolom di excel
|
|
'No',
|
|
'Nama KOP',
|
|
'Nama KLY',
|
|
'Kode Provider',
|
|
'Nama Provider',
|
|
'Jalan',
|
|
'KODEPOS',
|
|
'OPERASIONAL DAY',
|
|
'OPERASIONAL HOUR',
|
|
'AVAILABLE Brozo',
|
|
'Geo Tag'
|
|
];
|
|
|
|
foreach ($reader->getSheetIterator() as $sheet) {
|
|
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
|
|
);
|
|
|
|
|
|
// 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();
|
|
}
|
|
}
|
|
}
|
|
|
|
$reader->close();
|
|
|
|
}
|
|
}
|