mandiri inhealth

This commit is contained in:
Server D3 Linksehat
2024-08-31 15:03:52 +07:00
parent 4381fe6141
commit bfa21b97e4
3 changed files with 123 additions and 0 deletions

View File

@@ -19,6 +19,8 @@ class Organization extends Model
'part_of',
'main_address_id',
'corporate_id_partner',
'phone',
'email',
];
// public $with = [

View File

@@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('organizations', function (Blueprint $table) {
$table->string('phone')->nullable()->after('main_address_id');
$table->string('email')->nullable()->after('phone');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('organizations', function (Blueprint $table) {
$table->dropColumn('phone');
$table->dropColumn('email');
});
}
};

View File

@@ -0,0 +1,87 @@
<?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();
}
}