|
@@ -16,11 +16,93 @@ class DatabaseSeeder extends Seeder
|
16
|
16
|
*/
|
17
|
17
|
public function run(): void
|
18
|
18
|
{
|
19
|
|
- // \App\Models\User::factory(10)->create();
|
|
19
|
+ $startDate = today()->startOfYear();
|
|
20
|
+ $endDate = today();
|
20
|
21
|
|
21
|
|
- // \App\Models\User::factory()->create([
|
22
|
|
- // 'name' => 'Test User',
|
23
|
|
- // 'email' => 'test@example.com',
|
24
|
|
- // ]);
|
|
22
|
+ // Change Company Name to ERPSAAS after Login
|
|
23
|
+ $firstCompanyOwner = User::factory()
|
|
24
|
+ ->withPersonalCompany()
|
|
25
|
+ ->create([
|
|
26
|
+ 'name' => 'Admin',
|
|
27
|
+ 'email' => 'admin@gmail.com',
|
|
28
|
+ 'password' => bcrypt('password'),
|
|
29
|
+ 'current_company_id' => 1,
|
|
30
|
+ 'created_at' => $startDate->copy(),
|
|
31
|
+ ]);
|
|
32
|
+
|
|
33
|
+ $firstCompanyOwner->ownedCompanies->first()->update(['created_at' => $startDate->copy()]);
|
|
34
|
+
|
|
35
|
+ // Function to create employees for a company (also creates companies for the employees)
|
|
36
|
+ $createUsers = static function ($company_id, $userCount, $minPercentage, $maxPercentage) use ($endDate, $startDate) {
|
|
37
|
+ $users = User::factory($userCount)
|
|
38
|
+ ->withPersonalCompany()
|
|
39
|
+ ->create([
|
|
40
|
+ 'password' => bcrypt('password'),
|
|
41
|
+ 'current_company_id' => $company_id,
|
|
42
|
+ ]);
|
|
43
|
+
|
|
44
|
+ $dateRange = $endDate->diffInMinutes($startDate);
|
|
45
|
+ $minOffset = (int) ($dateRange * $minPercentage);
|
|
46
|
+ $maxOffset = (int) ($dateRange * $maxPercentage);
|
|
47
|
+
|
|
48
|
+ for ($i = 0; $i < $userCount; $i++) {
|
|
49
|
+ $increment = (int) ($minOffset + ($i * ($maxOffset - $minOffset) / $userCount));
|
|
50
|
+ $userCreatedAt = $startDate->copy()->addMinutes($increment);
|
|
51
|
+
|
|
52
|
+ $user = $users[$i];
|
|
53
|
+
|
|
54
|
+ // Randomly assign a role to the user
|
|
55
|
+ $roles = ['editor', 'admin'];
|
|
56
|
+ $role = $roles[array_rand($roles)];
|
|
57
|
+
|
|
58
|
+ $user->companies()->attach($company_id, compact('role'));
|
|
59
|
+
|
|
60
|
+ $user->update(['created_at' => $userCreatedAt]);
|
|
61
|
+ $user->ownedCompanies->first()?->update(['created_at' => $userCreatedAt]);
|
|
62
|
+
|
|
63
|
+ // Generate random created_at date for the company_user pivot table (for employees)
|
|
64
|
+ $user->companies->first()?->users()->updateExistingPivot($user->id, ['created_at' => $userCreatedAt]);
|
|
65
|
+ }
|
|
66
|
+ };
|
|
67
|
+
|
|
68
|
+ // Users for the first company (excluding the first company owner)
|
|
69
|
+ $createUsers(1, 5, 0, 0.1);
|
|
70
|
+
|
|
71
|
+ // Second company owner
|
|
72
|
+ $secondCompanyOwner = User::factory()
|
|
73
|
+ ->withPersonalCompany()
|
|
74
|
+ ->create([
|
|
75
|
+ 'password' => bcrypt('admin2'),
|
|
76
|
+ 'current_company_id' => 2,
|
|
77
|
+ 'created_at' => $startDate->addMinutes($endDate->diffInMinutes($startDate) * 0.1),
|
|
78
|
+ ]);
|
|
79
|
+
|
|
80
|
+ $secondCompanyOwner->ownedCompanies->first()->update(['created_at' => $startDate->addMinutes($endDate->diffInMinutes($startDate) * 0.1)]);
|
|
81
|
+
|
|
82
|
+ // Users for the second company (excluding the second company owner)
|
|
83
|
+ $createUsers(2, 5, 0.1, 0.2);
|
|
84
|
+
|
|
85
|
+ // Third company owner
|
|
86
|
+ $thirdCompanyOwner = User::factory()
|
|
87
|
+ ->withPersonalCompany()
|
|
88
|
+ ->create([
|
|
89
|
+ 'password' => bcrypt('admin3'),
|
|
90
|
+ 'current_company_id' => 3,
|
|
91
|
+ 'created_at' => $startDate->addMinutes($endDate->diffInMinutes($startDate) * 0.2),
|
|
92
|
+ ]);
|
|
93
|
+
|
|
94
|
+ $thirdCompanyOwner->ownedCompanies->first()->update(['created_at' => $startDate->addMinutes($endDate->diffInMinutes($startDate) * 0.2)]);
|
|
95
|
+
|
|
96
|
+ // Users for the third company (excluding the third company owner)
|
|
97
|
+ $createUsers(3, 5, 0.2, 0.3);
|
|
98
|
+
|
|
99
|
+ // Create employees for each company (each employee has a company)
|
|
100
|
+ $createUsers(4, 5, 0.3, 0.4);
|
|
101
|
+ $createUsers(5, 5, 0.4, 0.5);
|
|
102
|
+ $createUsers(6, 5, 0.5, 0.6);
|
|
103
|
+ $createUsers(7, 5, 0.6, 0.7);
|
|
104
|
+ $createUsers(8, 5, 0.7, 0.8);
|
|
105
|
+ $createUsers(9, 5, 0.8, 0.9);
|
|
106
|
+ $createUsers(10, 5, 0.9, 1);
|
25
|
107
|
}
|
26
|
108
|
}
|