123 lines
4.1 KiB
PHP
123 lines
4.1 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use Illuminate\Database\Seeder;
|
|
use App\Models\User;
|
|
use App\Models\SalesPlan;
|
|
use App\Models\PlanTarget;
|
|
use Carbon\Carbon;
|
|
|
|
class GeoPlanSeeder extends Seeder
|
|
{
|
|
public function run(): void
|
|
{
|
|
// 1. Ensure Sales User Exists
|
|
$salesUser = User::where('employee_id', 'SLS001')->first();
|
|
|
|
if (!$salesUser) {
|
|
$salesUser = User::create([
|
|
'name' => 'Sales Person 1',
|
|
'email' => 'sales1@georeach.com',
|
|
'password' => bcrypt('password'),
|
|
'role' => 'sales',
|
|
'employee_id' => 'SLS001',
|
|
'color' => '#3B82F6', // Blue
|
|
'is_active' => true,
|
|
]);
|
|
$this->command->info('Created Sales User: SLS001');
|
|
} else {
|
|
$this->command->info('Using Existing Sales User: SLS001');
|
|
}
|
|
|
|
// 2. Create Sales Plan for Today
|
|
$today = Carbon::today();
|
|
|
|
// Check if plan already exists to avoid duplicates on re-run
|
|
$existingPlan = SalesPlan::where('user_id', $salesUser->id)
|
|
->whereDate('date', $today)
|
|
->first();
|
|
|
|
if ($existingPlan) {
|
|
$existingPlan->targets()->delete();
|
|
$existingPlan->delete();
|
|
$this->command->info('Cleaned up existing plan for today');
|
|
}
|
|
|
|
$plan = SalesPlan::create([
|
|
'user_id' => $salesUser->id,
|
|
'date' => $today,
|
|
'status' => 'pending',
|
|
'created_by' => $salesUser->id,
|
|
]);
|
|
|
|
$this->command->info('Created Sales Plan for Today: ' . $today->toDateString());
|
|
|
|
// 3. Create Plan Targets (The Dummy Data)
|
|
$targets = [
|
|
[
|
|
'name' => 'Toko Jaya Abadi',
|
|
'address' => 'Jl. Merdeka No. 123, Bandung',
|
|
'latitude' => -6.9175,
|
|
'longitude' => 107.6191,
|
|
'status' => true, // is_completed
|
|
'completed_at' => Carbon::parse('09:00'),
|
|
'notes' => 'Sales visit completed.',
|
|
],
|
|
[
|
|
'name' => 'Warung Makan Sederhana',
|
|
'address' => 'Jl. Sudirman No. 45, Bandung',
|
|
'latitude' => -6.9215,
|
|
'longitude' => 107.6098,
|
|
'status' => true,
|
|
'completed_at' => Carbon::parse('10:30'),
|
|
'notes' => 'Lunch and prospect.',
|
|
],
|
|
[
|
|
'name' => 'Minimarket Berkah',
|
|
'address' => 'Jl. Asia Afrika No. 78, Bandung',
|
|
'latitude' => -6.9218,
|
|
'longitude' => 107.6073,
|
|
'status' => false,
|
|
'completed_at' => null,
|
|
'notes' => null,
|
|
],
|
|
[
|
|
'name' => 'Apotek Sehat',
|
|
'address' => 'Jl. Braga No. 56, Bandung',
|
|
'latitude' => -6.9186,
|
|
'longitude' => 107.6097,
|
|
'status' => false,
|
|
'completed_at' => null,
|
|
'notes' => null,
|
|
],
|
|
[
|
|
'name' => 'Toko Elektronik Jaya',
|
|
'address' => 'Jl. Dago No. 89, Bandung',
|
|
'latitude' => -6.8853,
|
|
'longitude' => 107.6146,
|
|
'status' => false,
|
|
'completed_at' => null,
|
|
'notes' => null,
|
|
],
|
|
];
|
|
|
|
foreach ($targets as $index => $t) {
|
|
PlanTarget::create([
|
|
'sales_plan_id' => $plan->id,
|
|
'order' => $index + 1,
|
|
'name' => $t['name'],
|
|
'address' => $t['address'],
|
|
'latitude' => $t['latitude'],
|
|
'longitude' => $t['longitude'],
|
|
'is_completed' => $t['status'],
|
|
'completed_at' => $t['completed_at'] ? Carbon::today()->setTimeFrom(Carbon::parse($t['completed_at'])) : null,
|
|
'notes' => $t['notes'],
|
|
'source' => 'admin',
|
|
]);
|
|
}
|
|
|
|
$this->command->info('Seeded ' . count($targets) . ' targets.');
|
|
}
|
|
}
|