diff --git a/LOGICAL_RELATIONSHIPS.md b/LOGICAL_RELATIONSHIPS.md index e85a746..e545bf6 100644 --- a/LOGICAL_RELATIONSHIPS.md +++ b/LOGICAL_RELATIONSHIPS.md @@ -1,6 +1,6 @@ # 논리적 데이터베이스 관계 문서 -> **자동 생성**: 2026-01-21 20:45:47 +> **자동 생성**: 2026-01-22 22:44:22 > **소스**: Eloquent 모델 관계 분석 ## 📊 모델별 관계 현황 @@ -377,11 +377,13 @@ ### orders - **client()**: belongsTo → `clients` - **writer()**: belongsTo → `users` - **item()**: belongsTo → `items` +- **sale()**: belongsTo → `sales` - **items()**: hasMany → `order_items` - **histories()**: hasMany → `order_histories` - **versions()**: hasMany → `order_versions` - **workOrders()**: hasMany → `work_orders` - **shipments()**: hasMany → `shipments` +- **sales()**: hasMany → `sales` ### order_historys **모델**: `App\Models\Orders\OrderHistory` @@ -800,6 +802,7 @@ ### purchases - **client()**: belongsTo → `clients` - **withdrawal()**: belongsTo → `withdrawals` +- **approval()**: belongsTo → `approvals` - **creator()**: belongsTo → `users` ### receivings @@ -819,6 +822,8 @@ ### salarys ### sales **모델**: `App\Models\Tenants\Sale` +- **order()**: belongsTo → `orders` +- **shipment()**: belongsTo → `shipments` - **client()**: belongsTo → `clients` - **deposit()**: belongsTo → `deposits` - **creator()**: belongsTo → `users` diff --git a/app/Http/Controllers/Api/V1/PurchaseController.php b/app/Http/Controllers/Api/V1/PurchaseController.php index a95b71b..ff917de 100644 --- a/app/Http/Controllers/Api/V1/PurchaseController.php +++ b/app/Http/Controllers/Api/V1/PurchaseController.php @@ -89,6 +89,16 @@ public function confirm(int $id) return ApiResponse::success($purchase, __('message.purchase.confirmed')); } + /** + * 대시보드 상세 조회 (CEO 대시보드 모달용) + */ + public function dashboardDetail() + { + $data = $this->service->dashboardDetail(); + + return ApiResponse::success($data, __('message.fetched')); + } + /** * 매입 요약 (기간별 합계) */ diff --git a/app/Services/ApprovalService.php b/app/Services/ApprovalService.php index 4cadce7..2e08e3f 100644 --- a/app/Services/ApprovalService.php +++ b/app/Services/ApprovalService.php @@ -392,9 +392,18 @@ public function inbox(array $params): LengthAwarePaginator $q->where('approver_id', $userId) ->whereIn('step_type', [ApprovalLine::STEP_TYPE_APPROVAL, ApprovalLine::STEP_TYPE_AGREEMENT]); }) - ->with(['form:id,name,code,category', 'drafter:id,name', 'steps' => function ($q) use ($userId) { - $q->where('approver_id', $userId); - }]); + ->with([ + 'form:id,name,code,category', + 'drafter:id,name', + 'drafter.tenantProfile:id,user_id,position_key,department_id', + 'drafter.tenantProfile.department:id,name', + 'steps' => function ($q) use ($userId) { + $q->where('approver_id', $userId); + }, + 'steps.approver:id,name', + 'steps.approver.tenantProfile:id,user_id,position_key,department_id', + 'steps.approver.tenantProfile.department:id,name', + ]); // 상태 필터 if (! empty($params['status'])) { diff --git a/app/Services/CardTransactionService.php b/app/Services/CardTransactionService.php index 9ecb406..adde710 100644 --- a/app/Services/CardTransactionService.php +++ b/app/Services/CardTransactionService.php @@ -267,13 +267,14 @@ public function destroy(int $id): bool /** * 카드 거래 대시보드 데이터 * - * CEO 대시보드 카드/가지급금 관리 섹션의 cm1 모달용 상세 데이터 제공 + * CEO 대시보드 카드/가지급금 관리 섹션(cm1) 및 당월 예상 지출내역 카드(me2) 모달용 상세 데이터 제공 * * @return array{ * summary: array{ * current_month_total: float, * previous_month_total: float, * change_rate: float, + * current_month_count: int, * unprocessed_count: int * }, * monthly_trend: array, @@ -299,6 +300,12 @@ public function dashboard(): array ? round((($currentMonthTotal - $previousMonthTotal) / $previousMonthTotal) * 100, 1) : ($currentMonthTotal > 0 ? 100 : 0); + // 당월 이용 건수 + $currentMonthCount = Withdrawal::query() + ->where('payment_method', 'card') + ->whereBetween(DB::raw('DATE(COALESCE(used_at, withdrawal_date))'), [$currentMonthStart, $currentMonthEnd]) + ->count(); + // 미정리 건수 (account_code가 없는 건) $unprocessedCount = Withdrawal::query() ->where('payment_method', 'card') @@ -319,6 +326,7 @@ public function dashboard(): array 'current_month_total' => (float) $currentMonthTotal, 'previous_month_total' => (float) $previousMonthTotal, 'change_rate' => $changeRate, + 'current_month_count' => $currentMonthCount, 'unprocessed_count' => $unprocessedCount, ], 'monthly_trend' => $monthlyTrend, diff --git a/app/Services/SaleService.php b/app/Services/SaleService.php index 31fa262..a906cc7 100644 --- a/app/Services/SaleService.php +++ b/app/Services/SaleService.php @@ -69,7 +69,25 @@ public function show(int $id): Sale return Sale::query() ->where('tenant_id', $tenantId) - ->with(['client:id,name', 'deposit', 'creator:id,name']) + ->with([ + 'client:id,name', + 'deposit', + 'creator:id,name', + 'order.items' => function ($query) { + $query->select([ + 'id', + 'order_id', + 'item_name', + 'quantity', + 'unit_price', + 'supply_amount', + 'tax_amount', + 'total_amount', + 'note', + 'sort_order', + ])->orderBy('sort_order'); + }, + ]) ->findOrFail($id); } diff --git a/app/Swagger/v1/CardTransactionApi.php b/app/Swagger/v1/CardTransactionApi.php index f1081b8..73ba991 100644 --- a/app/Swagger/v1/CardTransactionApi.php +++ b/app/Swagger/v1/CardTransactionApi.php @@ -90,7 +90,7 @@ * * @OA\Schema( * schema="CardTransactionDashboard", - * description="카드 거래 대시보드 데이터 (CEO 대시보드 cm1 모달용)", + * description="카드 거래 대시보드 데이터 (CEO 대시보드 cm1 및 당월 예상 지출 me2 모달용)", * * @OA\Property( * property="summary", @@ -99,6 +99,7 @@ * @OA\Property(property="current_month_total", type="number", format="float", description="당월 카드 사용액", example=30123000), * @OA\Property(property="previous_month_total", type="number", format="float", description="전월 카드 사용액", example=27250000), * @OA\Property(property="change_rate", type="number", format="float", description="전월 대비 증감률 (%)", example=10.5), + * @OA\Property(property="current_month_count", type="integer", description="당월 이용 건수", example=42), * @OA\Property(property="unprocessed_count", type="integer", description="미정리 건수", example=5) * ), * @OA\Property(