Skip to content

Commit 657fe39

Browse files
fix(ContractSeeder): update contract creation logic to handle multiple contracts based on hire date and current date
1 parent ad96843 commit 657fe39

1 file changed

Lines changed: 22 additions & 7 deletions

File tree

database/seeders/ContractSeeder.php

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class ContractSeeder extends Seeder
1313
*/
1414
public function run(): void
1515
{
16+
$now = Carbon::today();
17+
1618
foreach (EmployeeInfo::all() as $employee) {
1719
$employeePosition = $employee->position;
1820

@@ -23,13 +25,26 @@ public function run(): void
2325
default => fake()->numberBetween(2000, 4000),
2426
};
2527

26-
$employee->contracts()->create([
27-
'start_date' => $employee->hire_date,
28-
'end_date' => Carbon::parse($employee->hire_date)->addYear(),
29-
'rate_type' => 'monthly',
30-
'rate' => $rate,
31-
'contract_type' => 'full_time',
32-
]);
28+
$hireDate = Carbon::parse($employee->hire_date);
29+
$startDate = $hireDate->copy();
30+
31+
while ($startDate->lessThan($now)) {
32+
$endDate = $startDate->copy()->addYear();
33+
34+
if ($endDate->greaterThan($now)) {
35+
$endDate = $now->copy();
36+
}
37+
38+
$employee->contracts()->create([
39+
'start_date' => $startDate,
40+
'end_date' => $endDate,
41+
'rate_type' => 'monthly',
42+
'rate' => $rate,
43+
'contract_type' => 'full_time',
44+
]);
45+
46+
$startDate = $endDate;
47+
}
3348
}
3449
}
3550
}

0 commit comments

Comments
 (0)