Files
sam-api/database/seeders/Dummy/DummyLeaveGrantSeeder.php
kent be90c351fa chore(API): Seeder 파일 정리
- Dummy Seeder 파일들 정리 및 개선
- ApprovalTestDataSeeder 수정
- PositionSeeder, StockReceivingSeeder 수정

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-13 19:49:28 +09:00

97 lines
3.2 KiB
PHP

<?php
namespace Database\Seeders\Dummy;
use App\Models\Tenants\LeaveGrant;
use Database\Seeders\DummyDataSeeder;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class DummyLeaveGrantSeeder extends Seeder
{
public function run(): void
{
$tenantId = DummyDataSeeder::TENANT_ID;
$userId = DummyDataSeeder::USER_ID;
// 테넌트 소속 사용자 조회
$userIds = DB::table('user_tenants')
->where('tenant_id', $tenantId)
->pluck('user_id')
->toArray();
if (empty($userIds)) {
$this->command->warn(' ⚠ leave_grants: 사용자가 없습니다');
return;
}
$year = 2025;
$count = 0;
// 각 사용자별 연차/월차 부여
foreach ($userIds as $uId) {
// 연차 부여 (1월 1일)
$existing = LeaveGrant::where('tenant_id', $tenantId)
->where('user_id', $uId)
->where('grant_type', 'annual')
->whereYear('grant_date', $year)
->exists();
if (! $existing) {
LeaveGrant::create([
'tenant_id' => $tenantId,
'user_id' => $uId,
'grant_type' => 'annual',
'grant_date' => sprintf('%04d-01-01', $year),
'grant_days' => rand(12, 20), // 12~20일
'reason' => sprintf('%d년 연차 부여', $year),
'created_by' => $userId,
]);
$count++;
}
// 월차 부여 (월별, 12건)
for ($month = 1; $month <= 12; $month++) {
$grantDate = sprintf('%04d-%02d-01', $year, $month);
$monthlyExists = LeaveGrant::where('tenant_id', $tenantId)
->where('user_id', $uId)
->where('grant_type', 'monthly')
->where('grant_date', $grantDate)
->exists();
if (! $monthlyExists) {
LeaveGrant::create([
'tenant_id' => $tenantId,
'user_id' => $uId,
'grant_type' => 'monthly',
'grant_date' => $grantDate,
'grant_days' => 1,
'reason' => sprintf('%d년 %d월 월차', $year, $month),
'created_by' => $userId,
]);
$count++;
}
}
// 포상 휴가 (일부 사용자에게 랜덤)
if (rand(1, 5) === 1) { // 20% 확률
$rewardMonth = rand(3, 11);
LeaveGrant::create([
'tenant_id' => $tenantId,
'user_id' => $uId,
'grant_type' => 'reward',
'grant_date' => sprintf('%04d-%02d-15', $year, $rewardMonth),
'grant_days' => rand(1, 3),
'reason' => '우수 사원 포상 휴가',
'created_by' => $userId,
]);
$count++;
}
}
$this->command->info(' ✓ leave_grants: '.$count.'건 생성');
}
}