first commit
This commit is contained in:
24
database/seeders/DatabaseSeeder.php
Normal file
24
database/seeders/DatabaseSeeder.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class DatabaseSeeder extends Seeder
|
||||
{
|
||||
use WithoutModelEvents;
|
||||
|
||||
/**
|
||||
* Seed the application's database.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// User::factory(10)->create();
|
||||
|
||||
// Seed GeoPlan Data
|
||||
$this->call(GeoPlanSeeder::class);
|
||||
}
|
||||
|
||||
}
|
||||
122
database/seeders/GeoPlanSeeder.php
Normal file
122
database/seeders/GeoPlanSeeder.php
Normal file
@ -0,0 +1,122 @@
|
||||
<?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.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user