65 lines
4.5 KiB
PHP
65 lines
4.5 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use App\Models\Employee;
|
|
use App\Models\StockMovement;
|
|
use App\Models\UniformItem;
|
|
use App\Models\User;
|
|
// use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
|
use Illuminate\Database\Seeder;
|
|
|
|
class DatabaseSeeder extends Seeder
|
|
{
|
|
/**
|
|
* Seed the application's database.
|
|
*/
|
|
public function run(): void
|
|
{
|
|
User::updateOrCreate(
|
|
['email' => env('ADMIN_EMAIL', 'admin@uniformflow.local')],
|
|
['name' => 'System Administrator', 'password' => env('ADMIN_PASSWORD', 'Admin@12345'), 'is_admin' => true, 'email_verified_at' => now()]
|
|
);
|
|
|
|
$employees = [
|
|
['employee_no' => 'EMP-001', 'name' => 'Nadeesha Perera', 'department' => 'Operations', 'designation' => 'Operations Executive', 'joined_at' => '2024-02-12'],
|
|
['employee_no' => 'EMP-002', 'name' => 'Kasun Silva', 'department' => 'Warehouse', 'designation' => 'Store Assistant', 'joined_at' => '2023-08-21'],
|
|
['employee_no' => 'EMP-003', 'name' => 'Tharushi Fernando', 'department' => 'Front Office', 'designation' => 'Receptionist', 'joined_at' => '2025-01-15'],
|
|
['employee_no' => 'EMP-004', 'name' => 'Dinuka Jayasinghe', 'department' => 'Security', 'designation' => 'Security Officer', 'joined_at' => '2024-05-06'],
|
|
['employee_no' => 'EMP-005', 'name' => 'Sachini Wickramasinghe', 'department' => 'Housekeeping', 'designation' => 'Room Attendant', 'joined_at' => '2025-03-17'],
|
|
['employee_no' => 'EMP-006', 'name' => 'Lahiru Madushanka', 'department' => 'Maintenance', 'designation' => 'Maintenance Technician', 'joined_at' => '2023-11-02'],
|
|
['employee_no' => 'EMP-007', 'name' => 'Amaya Gunawardena', 'department' => 'Human Resources', 'designation' => 'HR Executive', 'joined_at' => '2024-09-23'],
|
|
['employee_no' => 'EMP-008', 'name' => 'Ravindu Senanayake', 'department' => 'Food & Beverage', 'designation' => 'Service Associate', 'joined_at' => '2025-06-09'],
|
|
['employee_no' => 'EMP-009', 'name' => 'Shenali de Silva', 'department' => 'Finance', 'designation' => 'Accounts Assistant', 'joined_at' => '2024-07-01'],
|
|
['employee_no' => 'EMP-010', 'name' => 'Isuru Bandara', 'department' => 'Kitchen', 'designation' => 'Commis Chef', 'joined_at' => '2025-02-10'],
|
|
['employee_no' => 'EMP-011', 'name' => 'Piumi Karunaratne', 'department' => 'Sales & Marketing', 'designation' => 'Sales Coordinator', 'joined_at' => '2024-10-14'],
|
|
['employee_no' => 'EMP-012', 'name' => 'Dulanjana Herath', 'department' => 'IT', 'designation' => 'IT Support Officer', 'joined_at' => '2025-04-21'],
|
|
];
|
|
|
|
foreach ($employees as $employee) {
|
|
Employee::updateOrCreate(['employee_no' => $employee['employee_no']], $employee);
|
|
}
|
|
|
|
$catalogue = [
|
|
['code' => 'SHIRT-NVY', 'name' => 'Navy Work Shirt', 'sizes' => ['S' => 8, 'M' => 14, 'L' => 9, 'XL' => 3]],
|
|
['code' => 'TROUSER-GRY', 'name' => 'Grey Work Trouser', 'sizes' => ['28' => 4, '30' => 9, '32' => 12, '34' => 6, '36' => 2]],
|
|
['code' => 'POLO-WHT', 'name' => 'White Polo Shirt', 'sizes' => ['S' => 7, 'M' => 10, 'L' => 5, 'XL' => 0]],
|
|
['code' => 'SEC-SHIRT', 'name' => 'Security Officer Shirt', 'sizes' => ['S' => 6, 'M' => 12, 'L' => 10, 'XL' => 5, '2XL' => 2]],
|
|
['code' => 'HK-TUNIC', 'name' => 'Housekeeping Tunic', 'sizes' => ['XS' => 4, 'S' => 9, 'M' => 11, 'L' => 7, 'XL' => 3]],
|
|
['code' => 'CHEF-COAT', 'name' => 'White Chef Coat', 'sizes' => ['S' => 5, 'M' => 8, 'L' => 8, 'XL' => 4, '2XL' => 2]],
|
|
['code' => 'VEST-HV', 'name' => 'High Visibility Safety Vest', 'sizes' => ['S' => 8, 'M' => 15, 'L' => 14, 'XL' => 7, '2XL' => 4]],
|
|
['code' => 'BLAZER-BLK', 'name' => 'Black Front Office Blazer', 'sizes' => ['XS' => 2, 'S' => 5, 'M' => 7, 'L' => 5, 'XL' => 2]],
|
|
];
|
|
|
|
foreach ($catalogue as $data) {
|
|
$item = UniformItem::updateOrCreate(['code' => $data['code']], ['name' => $data['name']]);
|
|
foreach ($data['sizes'] as $size => $quantity) {
|
|
$variant = $item->variants()->firstOrCreate(['size' => $size], ['quantity' => $quantity, 'new_quantity' => $quantity, 'reorder_level' => 4]);
|
|
if ($variant->wasRecentlyCreated && $quantity) {
|
|
StockMovement::create(['stock_variant_id' => $variant->id, 'type' => 'opening_stock', 'quantity_change' => $quantity, 'stock_category' => 'new', 'unit_value' => 0, 'notes' => 'Opening stock balance']);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|