Refactor script
This commit is contained in:
115
database/seeders/AppMenuSeeder.php
Normal file
115
database/seeders/AppMenuSeeder.php
Normal file
@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use App\Models\AppMenu;
|
||||
|
||||
class AppMenuSeeder extends Seeder
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
// Reset
|
||||
AppMenu::truncate();
|
||||
|
||||
$menus = [
|
||||
[
|
||||
'label' => 'Dashboard',
|
||||
'key' => 'dashboard',
|
||||
'icon' => 'HomeIcon', // Adjust with exact icon name used in frontend
|
||||
'route' => 'dashboard',
|
||||
'order' => 10,
|
||||
'is_active' => true,
|
||||
],
|
||||
[
|
||||
'label' => 'GeoTrack',
|
||||
'key' => 'geotrack',
|
||||
'icon' => 'MapIcon',
|
||||
'route' => 'geotrack', // Assuming this triggers internal navigation logic
|
||||
'order' => 20,
|
||||
'is_active' => true,
|
||||
],
|
||||
[
|
||||
'label' => 'GeoPlan',
|
||||
'key' => 'geoplan',
|
||||
'icon' => 'CalendarIcon',
|
||||
'route' => 'geoplan',
|
||||
'order' => 30,
|
||||
'is_active' => true,
|
||||
],
|
||||
[
|
||||
'label' => 'Grid Management',
|
||||
'key' => 'grid',
|
||||
'icon' => 'GridIcon', // ViewGridIcon
|
||||
'route' => 'grid',
|
||||
'order' => 40,
|
||||
'is_active' => true,
|
||||
],
|
||||
[
|
||||
'label' => 'Merchants',
|
||||
'key' => 'merchants',
|
||||
'icon' => 'ShopIcon', // ShoppingBagIcon
|
||||
'route' => 'merchants',
|
||||
'order' => 50,
|
||||
'is_active' => true,
|
||||
],
|
||||
[
|
||||
'label' => 'Staff Management',
|
||||
'key' => 'staff',
|
||||
'icon' => 'UsersIcon',
|
||||
'route' => 'staff',
|
||||
'order' => 60,
|
||||
'is_active' => true,
|
||||
],
|
||||
[
|
||||
'label' => 'Customer Management',
|
||||
'key' => 'customer',
|
||||
'icon' => 'UserGroupIcon',
|
||||
'route' => 'customer',
|
||||
'order' => 70,
|
||||
'is_active' => true,
|
||||
],
|
||||
// System Submenu
|
||||
[
|
||||
'label' => 'System Access',
|
||||
'key' => 'system',
|
||||
'icon' => 'CogIcon',
|
||||
'route' => null, // Parent
|
||||
'order' => 90,
|
||||
'is_active' => true,
|
||||
'children' => [
|
||||
[
|
||||
'label' => 'Menu Management',
|
||||
'key' => 'system.menu',
|
||||
'icon' => 'MenuIcon',
|
||||
'route' => 'system-menu',
|
||||
'order' => 1,
|
||||
'is_active' => true,
|
||||
],
|
||||
[
|
||||
'label' => 'Role & Permission',
|
||||
'key' => 'system.role',
|
||||
'icon' => 'ShieldCheckIcon',
|
||||
'route' => 'system-role',
|
||||
'order' => 2,
|
||||
'is_active' => true,
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
foreach ($menus as $m) {
|
||||
$children = $m['children'] ?? [];
|
||||
unset($m['children']);
|
||||
|
||||
$parent = AppMenu::create($m);
|
||||
|
||||
if (!empty($children)) {
|
||||
foreach ($children as $c) {
|
||||
$c['parent_id'] = $parent->id;
|
||||
AppMenu::create($c);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
45
database/seeders/FixMasterAgentSeeder.php
Normal file
45
database/seeders/FixMasterAgentSeeder.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use App\Models\Agent;
|
||||
|
||||
class FixMasterAgentSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$id = 'AGT-MASTER';
|
||||
|
||||
// Cek existing
|
||||
$agent = Agent::where('agent_id', $id)->first();
|
||||
|
||||
$data = [
|
||||
'agent_id' => $id,
|
||||
'company_name' => 'Kartsandy', // Case insensitive lookup will handle 'kartsandy'
|
||||
'employee_id' => 'gurubesar', // [NEW] User preference
|
||||
// 'username' => 'gurunesar', // Deprecated preference
|
||||
'email' => 'andy@gmail.com',
|
||||
'phone' => '08123456789',
|
||||
'address' => 'Jakarta Headquarters',
|
||||
'subscription_duration' => 9999, // Forever
|
||||
'is_active' => true,
|
||||
'role' => 'master',
|
||||
'ip_whitelist' => [],
|
||||
'api_secret_key' => 'sk_live_' . $id, // sk_live_AGT-MASTER matches frontend default
|
||||
'password' => Hash::make('abcd1234'),
|
||||
];
|
||||
|
||||
if ($agent) {
|
||||
$agent->update($data);
|
||||
$this->command->info("Updated Agent: {$id}");
|
||||
} else {
|
||||
Agent::create($data);
|
||||
$this->command->info("Created Agent: {$id}");
|
||||
}
|
||||
}
|
||||
}
|
||||
69
database/seeders/MerchantSeeder.php
Normal file
69
database/seeders/MerchantSeeder.php
Normal file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use App\Models\Merchant;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use App\Models\Customer; // Added Customer model
|
||||
|
||||
class MerchantSeeder extends Seeder
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
$path = base_path('merchants.json');
|
||||
|
||||
if (!File::exists($path)) {
|
||||
$this->command->error('merchants.json not found!');
|
||||
return;
|
||||
}
|
||||
|
||||
$json = File::get($path);
|
||||
$data = json_decode($json, true);
|
||||
|
||||
if ($data) {
|
||||
// Find Agent Master to assign customers to
|
||||
$agent = \App\Models\Agent::where('agent_id', 'AGT-MASTER')->first();
|
||||
$agentId = $agent ? $agent->id : null;
|
||||
|
||||
if (!$agentId) {
|
||||
$this->command->warn("Agent AGT-MASTER not found. Customers will be unassigned.");
|
||||
}
|
||||
|
||||
$count = 0;
|
||||
foreach ($data as $item) {
|
||||
// Ensure numeric values are properly cast
|
||||
if (isset($item['latitude']))
|
||||
$item['latitude'] = (float) $item['latitude'];
|
||||
if (isset($item['longitude']))
|
||||
$item['longitude'] = (float) $item['longitude'];
|
||||
|
||||
// Consistently use Customer model only
|
||||
// Mapping fields
|
||||
Customer::updateOrCreate(
|
||||
[
|
||||
'name' => $item['name'],
|
||||
// Use lat/lng as composite key to avoid duplicates if name matches but location diff
|
||||
'latitude' => $item['latitude'],
|
||||
'longitude' => $item['longitude']
|
||||
],
|
||||
[
|
||||
'name' => $item['name'],
|
||||
'address' => $item['address'] ?? '',
|
||||
'city' => $item['city'] ?? '',
|
||||
'latitude' => $item['latitude'],
|
||||
'longitude' => $item['longitude'],
|
||||
'category' => $item['category'] ?? 'other', // Map category from json
|
||||
'agent_id' => $agentId, // Assign to agent
|
||||
'owner_name' => 'Owner ' . $item['name'], // Dummy owner
|
||||
'phone' => '0812' . rand(10000000, 99999999), // Dummy phone
|
||||
// pic_sales_id left null for now
|
||||
]
|
||||
);
|
||||
|
||||
$count++;
|
||||
}
|
||||
$this->command->info("Seeded {$count} Customers from merchants.json for Agent: " . ($agent ? 'AGT-MASTER' : 'None'));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user