feat: Schedule 테이블 및 글로벌 일정 시스템 구현

- schedules 테이블 마이그레이션 추가 (tenant_id NULL 허용)
- Schedule 모델 생성 (type/recurrence 상수, forTenant 스코프)
- CalendarService에 getGeneralSchedules 메서드 추가
- StatusBoardService 하드코딩된 부가세 마감일 → Schedule 조회로 변경
- TaxScheduleSeeder 추가 (분기별 부가세 신고 마감일)
- i18n tax_no_schedule 키 추가
This commit is contained in:
2026-01-21 20:46:53 +09:00
parent e0dc8291fa
commit 289fd3744c
6 changed files with 445 additions and 29 deletions

View File

@@ -0,0 +1,224 @@
<?php
namespace App\Models\Tenants;
use App\Models\Members\User;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* 캘린더 일정 모델
*
* tenant_id가 NULL이면 전체 테넌트 공통 일정 (본사 등록)
* tenant_id가 있으면 해당 테넌트 전용 일정
*/
class Schedule extends Model
{
use SoftDeletes;
protected $table = 'schedules';
protected $fillable = [
'tenant_id',
'title',
'description',
'start_date',
'end_date',
'start_time',
'end_time',
'is_all_day',
'type',
'is_recurring',
'recurrence_rule',
'color',
'is_active',
'created_by',
'updated_by',
'deleted_by',
];
protected $casts = [
'start_date' => 'date',
'end_date' => 'date',
'is_all_day' => 'boolean',
'is_recurring' => 'boolean',
'is_active' => 'boolean',
];
protected $attributes = [
'is_all_day' => true,
'type' => 'event',
'is_recurring' => false,
'is_active' => true,
];
// =========================================================================
// 일정 유형 상수
// =========================================================================
public const TYPE_TAX = 'tax'; // 세금 신고
public const TYPE_HOLIDAY = 'holiday'; // 공휴일
public const TYPE_EVENT = 'event'; // 일반 이벤트
public const TYPE_NOTICE = 'notice'; // 공지/알림
public const TYPE_MEETING = 'meeting'; // 회의
public const TYPE_OTHER = 'other'; // 기타
public const TYPES = [
self::TYPE_TAX => '세금 신고',
self::TYPE_HOLIDAY => '공휴일',
self::TYPE_EVENT => '이벤트',
self::TYPE_NOTICE => '공지',
self::TYPE_MEETING => '회의',
self::TYPE_OTHER => '기타',
];
// =========================================================================
// 반복 규칙 상수
// =========================================================================
public const RECURRENCE_YEARLY = 'yearly'; // 매년
public const RECURRENCE_QUARTERLY = 'quarterly'; // 매분기
public const RECURRENCE_MONTHLY = 'monthly'; // 매월
public const RECURRENCE_WEEKLY = 'weekly'; // 매주
public const RECURRENCE_RULES = [
self::RECURRENCE_YEARLY => '매년',
self::RECURRENCE_QUARTERLY => '매분기',
self::RECURRENCE_MONTHLY => '매월',
self::RECURRENCE_WEEKLY => '매주',
];
// =========================================================================
// 관계 정의
// =========================================================================
/**
* 생성자
*/
public function creator(): BelongsTo
{
return $this->belongsTo(User::class, 'created_by');
}
/**
* 수정자
*/
public function updater(): BelongsTo
{
return $this->belongsTo(User::class, 'updated_by');
}
// =========================================================================
// 스코프
// =========================================================================
/**
* 특정 테넌트 + 글로벌 일정 조회
*/
public function scopeForTenant(Builder $query, int $tenantId): Builder
{
return $query->where(function ($q) use ($tenantId) {
$q->where('tenant_id', $tenantId)
->orWhereNull('tenant_id'); // 글로벌 일정 포함
});
}
/**
* 글로벌 일정만 조회 (본사 등록)
*/
public function scopeGlobal(Builder $query): Builder
{
return $query->whereNull('tenant_id');
}
/**
* 활성 일정만
*/
public function scopeActive(Builder $query): Builder
{
return $query->where('is_active', true);
}
/**
* 특정 유형
*/
public function scopeOfType(Builder $query, string $type): Builder
{
return $query->where('type', $type);
}
/**
* 세금 관련 일정
*/
public function scopeTax(Builder $query): Builder
{
return $query->where('type', self::TYPE_TAX);
}
/**
* 기간 내 일정 (겹치는 일정 포함)
*/
public function scopeBetweenDates(Builder $query, string $startDate, string $endDate): Builder
{
return $query->where(function ($q) use ($startDate, $endDate) {
$q->where('start_date', '<=', $endDate)
->where(function ($inner) use ($startDate) {
$inner->where('end_date', '>=', $startDate)
->orWhereNull('end_date');
});
});
}
/**
* 특정 날짜 이후 가장 가까운 일정
*/
public function scopeUpcoming(Builder $query, ?string $fromDate = null): Builder
{
$fromDate = $fromDate ?? now()->format('Y-m-d');
return $query->where('start_date', '>=', $fromDate)
->orderBy('start_date');
}
// =========================================================================
// 헬퍼 메서드
// =========================================================================
/**
* 글로벌 일정인지 확인
*/
public function isGlobal(): bool
{
return $this->tenant_id === null;
}
/**
* 유형 라벨
*/
public function getTypeLabelAttribute(): string
{
return self::TYPES[$this->type] ?? $this->type;
}
/**
* 반복 규칙 라벨
*/
public function getRecurrenceRuleLabelAttribute(): ?string
{
if (! $this->recurrence_rule) {
return null;
}
return self::RECURRENCE_RULES[$this->recurrence_rule] ?? $this->recurrence_rule;
}
}

View File

@@ -5,6 +5,7 @@
use App\Models\Construction\Contract; use App\Models\Construction\Contract;
use App\Models\Production\WorkOrder; use App\Models\Production\WorkOrder;
use App\Models\Tenants\Leave; use App\Models\Tenants\Leave;
use App\Models\Tenants\Schedule;
use Carbon\Carbon; use Carbon\Carbon;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
@@ -15,6 +16,7 @@
* - 작업지시(WorkOrder): 생산 일정 * - 작업지시(WorkOrder): 생산 일정
* - 계약(Contract): 시공 일정 * - 계약(Contract): 시공 일정
* - 휴가(Leave): 직원 휴가 일정 * - 휴가(Leave): 직원 휴가 일정
* - 일정(Schedule): 본사 공통 일정 + 테넌트 일정 (세금 신고, 공휴일 등)
*/ */
class CalendarService extends Service class CalendarService extends Service
{ {
@@ -56,6 +58,13 @@ public function getSchedules(
); );
} }
// 범용 일정 (본사 공통 + 테넌트 일정): 항상 포함 또는 'other' 필터 시
if ($type === null || $type === 'other') {
$schedules = $schedules->merge(
$this->getGeneralSchedules($tenantId, $startDate, $endDate)
);
}
// startDate 기준 정렬 // startDate 기준 정렬
$sortedSchedules = $schedules $sortedSchedules = $schedules
->sortBy('startDate') ->sortBy('startDate')
@@ -217,4 +226,38 @@ private function getLeaveSchedules(
]; ];
}); });
} }
/**
* 범용 일정 조회 (본사 공통 + 테넌트 일정)
*/
private function getGeneralSchedules(
int $tenantId,
string $startDate,
string $endDate
): Collection {
$schedules = Schedule::query()
->forTenant($tenantId)
->active()
->betweenDates($startDate, $endDate)
->with(['creator:id,name'])
->orderBy('start_date')
->limit(100)
->get();
return $schedules->map(function ($schedule) {
return [
'id' => 'schedule_'.$schedule->id,
'title' => $schedule->title,
'startDate' => $schedule->start_date?->format('Y-m-d'),
'endDate' => $schedule->end_date?->format('Y-m-d') ?? $schedule->start_date?->format('Y-m-d'),
'startTime' => $schedule->start_time,
'endTime' => $schedule->end_time,
'isAllDay' => $schedule->is_all_day,
'type' => 'other',
'department' => null,
'personName' => $schedule->creator?->name,
'color' => $schedule->color,
];
});
}
} }

View File

@@ -5,10 +5,10 @@
use App\Models\BadDebts\BadDebt; use App\Models\BadDebts\BadDebt;
use App\Models\Orders\Client; use App\Models\Orders\Client;
use App\Models\Orders\Order; use App\Models\Orders\Order;
use App\Models\Tenants\Approval;
use App\Models\Tenants\ApprovalStep; use App\Models\Tenants\ApprovalStep;
use App\Models\Tenants\Leave; use App\Models\Tenants\Leave;
use App\Models\Tenants\Purchase; use App\Models\Tenants\Purchase;
use App\Models\Tenants\Schedule;
use App\Models\Tenants\Stock; use App\Models\Tenants\Stock;
use Carbon\Carbon; use Carbon\Carbon;
@@ -50,7 +50,7 @@ private function getOrdersStatus(int $tenantId, Carbon $today): array
$count = Order::query() $count = Order::query()
->where('tenant_id', $tenantId) ->where('tenant_id', $tenantId)
->whereDate('created_at', $today) ->whereDate('created_at', $today)
->where('status_code', 'confirmed') // 확정된 수주만 ->where('status_code', Order::STATUS_CONFIRMED) // 확정된 수주만
->count(); ->count();
return [ return [
@@ -69,7 +69,7 @@ private function getBadDebtStatus(int $tenantId): array
{ {
$count = BadDebt::query() $count = BadDebt::query()
->where('tenant_id', $tenantId) ->where('tenant_id', $tenantId)
->where('status', 'in_progress') // 추심 진행 중 ->where('status', BadDebt::STATUS_COLLECTING) // 추심 진행 중
->count(); ->count();
return [ return [
@@ -105,33 +105,32 @@ private function getSafetyStockStatus(int $tenantId): array
/** /**
* 세금 신고 현황 (부가세 신고 D-day) * 세금 신고 현황 (부가세 신고 D-day)
*
* Schedule 테이블에서 type='tax'인 가장 가까운 일정 조회
* - 본사(tenant_id=NULL) 등록 글로벌 일정 + 테넌트 전용 일정 모두 포함
*/ */
private function getTaxDeadlineStatus(int $tenantId, Carbon $today): array private function getTaxDeadlineStatus(int $tenantId, Carbon $today): array
{ {
// 부가세 신고 마감일 계산 (분기별: 1/25, 4/25, 7/25, 10/25) // Schedule 테이블에서 가장 가까운 세금 신고 일정 조회
$quarter = $today->quarter; $nextTaxSchedule = Schedule::query()
$deadlineMonth = match ($quarter) { ->forTenant($tenantId)
1 => 1, // 1분기 → 1월 25일 ->active()
2 => 4, // 2분기 → 4월 25일 ->tax()
3 => 7, // 3분기 → 7월 25일 ->upcoming($today->format('Y-m-d'))
4 => 10, // 4분기 → 10월 25일 ->first();
};
$deadlineYear = $today->year; if (! $nextTaxSchedule) {
// 1분기 마감일이 지났으면 다음 분기 마감일 // 등록된 세금 일정이 없는 경우
if ($today->month > $deadlineMonth || ($today->month == $deadlineMonth && $today->day > 25)) { return [
$deadlineMonth = match ($quarter) { 'id' => 'tax_deadline',
1 => 4, 'label' => __('message.status_board.tax_deadline'),
2 => 7, 'count' => __('message.status_board.tax_no_schedule'),
3 => 10, 'path' => '/accounting/tax',
4 => 1, // 다음 해 'isHighlighted' => false,
}; ];
if ($deadlineMonth == 1) {
$deadlineYear++;
}
} }
$deadline = Carbon::create($deadlineYear, $deadlineMonth, 25); $deadline = $nextTaxSchedule->start_date;
$daysUntil = $today->diffInDays($deadline, false); $daysUntil = $today->diffInDays($deadline, false);
$countText = $daysUntil >= 0 $countText = $daysUntil >= 0
@@ -194,7 +193,7 @@ private function getPurchaseStatus(int $tenantId): array
{ {
$count = Purchase::query() $count = Purchase::query()
->where('tenant_id', $tenantId) ->where('tenant_id', $tenantId)
->where('status', 'pending') // 대기 중인 발주 ->where('status', 'draft') // 대기 중인 발주 (임시저장 상태)
->count(); ->count();
return [ return [
@@ -228,4 +227,4 @@ private function getApprovalStatus(int $tenantId, int $userId): array
'isHighlighted' => $count > 0, 'isHighlighted' => $count > 0,
]; ];
} }
} }

View File

@@ -0,0 +1,50 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('schedules', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('tenant_id')->nullable()->comment('NULL이면 전체 테넌트 공통 (본사 등록)');
$table->string('title', 200)->comment('일정 제목');
$table->text('description')->nullable()->comment('일정 설명');
$table->date('start_date')->comment('시작일');
$table->date('end_date')->nullable()->comment('종료일 (NULL이면 당일)');
$table->time('start_time')->nullable()->comment('시작 시간');
$table->time('end_time')->nullable()->comment('종료 시간');
$table->boolean('is_all_day')->default(true)->comment('종일 여부');
$table->string('type', 50)->default('event')->comment('일정 유형: tax, holiday, event, notice, meeting, other');
$table->boolean('is_recurring')->default(false)->comment('반복 일정 여부');
$table->string('recurrence_rule', 50)->nullable()->comment('반복 규칙: yearly, quarterly, monthly, weekly');
$table->string('color', 20)->nullable()->comment('캘린더 표시 색상');
$table->boolean('is_active')->default(true)->comment('활성 여부');
$table->unsignedBigInteger('created_by')->nullable()->comment('생성자');
$table->unsignedBigInteger('updated_by')->nullable()->comment('수정자');
$table->unsignedBigInteger('deleted_by')->nullable()->comment('삭제자');
$table->timestamps();
$table->softDeletes();
// 인덱스
$table->index('tenant_id');
$table->index('type');
$table->index('start_date');
$table->index(['tenant_id', 'type', 'start_date']);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('schedules');
}
};

View File

@@ -0,0 +1,89 @@
<?php
namespace Database\Seeders;
use App\Models\Tenants\Schedule;
use Illuminate\Database\Seeder;
/**
* 부가세 신고 마감일 시드
*
* 본사(HQ)에서 등록하는 글로벌 일정 (tenant_id = NULL)
* 모든 테넌트에서 조회 가능
*
* 분기별 마감일:
* - 1분기: 1월 25일 (전년도 4분기분)
* - 2분기: 4월 25일 (1분기분)
* - 3분기: 7월 25일 (2분기분)
* - 4분기: 10월 25일 (3분기분)
*/
class TaxScheduleSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
$year = now()->year;
$taxDeadlines = [
[
'title' => "{$year}년 1분기 부가세 신고",
'description' => '전년도 4분기분 부가세 예정신고 마감일',
'start_date' => "{$year}-01-25",
'type' => Schedule::TYPE_TAX,
'is_recurring' => true,
'recurrence_rule' => Schedule::RECURRENCE_YEARLY,
'color' => '#EF4444', // red-500
],
[
'title' => "{$year}년 2분기 부가세 신고",
'description' => '1분기분 부가세 예정신고 마감일',
'start_date' => "{$year}-04-25",
'type' => Schedule::TYPE_TAX,
'is_recurring' => true,
'recurrence_rule' => Schedule::RECURRENCE_YEARLY,
'color' => '#EF4444', // red-500
],
[
'title' => "{$year}년 3분기 부가세 신고",
'description' => '2분기분 부가세 예정신고 마감일',
'start_date' => "{$year}-07-25",
'type' => Schedule::TYPE_TAX,
'is_recurring' => true,
'recurrence_rule' => Schedule::RECURRENCE_YEARLY,
'color' => '#EF4444', // red-500
],
[
'title' => "{$year}년 4분기 부가세 신고",
'description' => '3분기분 부가세 예정신고 마감일',
'start_date' => "{$year}-10-25",
'type' => Schedule::TYPE_TAX,
'is_recurring' => true,
'recurrence_rule' => Schedule::RECURRENCE_YEARLY,
'color' => '#EF4444', // red-500
],
];
foreach ($taxDeadlines as $deadline) {
Schedule::firstOrCreate(
[
'tenant_id' => null, // 글로벌 일정
'title' => $deadline['title'],
'start_date' => $deadline['start_date'],
],
[
'description' => $deadline['description'],
'type' => $deadline['type'],
'is_all_day' => true,
'is_recurring' => $deadline['is_recurring'],
'recurrence_rule' => $deadline['recurrence_rule'],
'color' => $deadline['color'],
'is_active' => true,
]
);
}
$this->command->info("부가세 신고 마감일 {$year}년 일정이 등록되었습니다.");
}
}

View File

@@ -490,6 +490,7 @@
'tax_deadline' => '세금 신고', 'tax_deadline' => '세금 신고',
'tax_d_day' => '부가세 신고 D-:days', 'tax_d_day' => '부가세 신고 D-:days',
'tax_overdue' => '부가세 신고 :days일 초과', 'tax_overdue' => '부가세 신고 :days일 초과',
'tax_no_schedule' => '일정 없음',
'new_clients' => '신규 업체 등록', 'new_clients' => '신규 업체 등록',
'leaves' => '연차', 'leaves' => '연차',
'purchases' => '발주', 'purchases' => '발주',
@@ -505,20 +506,30 @@
'approval_request' => '결재 요청', 'approval_request' => '결재 요청',
// 이슈 내용 메시지 // 이슈 내용 메시지
'order_register' => ':client 신규 수주 :amount원 등록',
'collection_issue' => ':client 미수금 :amount원 연체 :days일 추심중',
'safety_stock_alert' => ':item 안전재고 미달',
'expense_pending' => ':title (:amount원) 승인대기',
'tax_vat_deadline' => ':quarter분기 부가세 신고 D-:days',
'approval_pending' => ':title 승인 요청 (:drafter)',
'new_client' => '신규 거래처 :name 등록 완료',
// 하위 호환성 (deprecated)
'order_success' => ':client 신규 수주 :amount원 확정', 'order_success' => ':client 신규 수주 :amount원 확정',
'receivable_overdue' => ':client 미수금 :amount원 연체 :days일', 'receivable_overdue' => ':client 미수금 :amount원 연체 :days일',
'stock_below_safety' => ':item 재고 부족 경고', 'stock_below_safety' => ':item 재고 부족 경고',
'expense_pending_multiple' => ':title 외 :count건 (:amount원)', 'expense_pending_multiple' => ':title 외 :count건 (:amount원)',
'expense_pending_single' => ':title (:amount원)', 'expense_pending_single' => ':title (:amount원)',
'tax_vat_deadline' => ':quarter분기 부가세 신고 D-:days',
'approval_pending' => ':title 승인 요청 (:drafter)',
'new_client' => '신규 거래처 :name 등록 완료',
// 상대 시간 // 상대 시간
'time_minutes_ago' => ':minutes분 전', 'time_minutes_ago' => ':minutes분 전',
'time_hours_ago' => ':hours시간 전', 'time_hours_ago' => ':hours시간 전',
'time_yesterday' => '어제', 'time_yesterday' => '어제',
'time_days_ago' => ':days일 전', 'time_days_ago' => ':days일 전',
// 읽음 처리
'marked_as_read' => '알림을 읽음 처리했습니다.',
'all_marked_as_read' => '모든 알림을 읽음 처리했습니다.',
], ],
// CEO 대시보드 캘린더 // CEO 대시보드 캘린더