From 83a438a030b13d822cfa9d20bee356e770eccbfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=B3=B4=EA=B3=A4?= Date: Tue, 3 Feb 2026 09:56:30 +0900 Subject: [PATCH] =?UTF-8?q?fix:=EA=B3=84=EC=A0=95=EA=B3=BC=EB=AA=A9?= =?UTF-8?q?=EC=9D=84=20=EA=B8=80=EB=A1=9C=EB=B2=8C=20=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=84=B0=EB=A1=9C=20=EB=B3=80=EA=B2=BD=20(=ED=85=8C=EB=84=8C?= =?UTF-8?q?=ED=8A=B8=20=EB=AC=B4=EA=B4=80)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Barobill/EaccountController.php | 48 ++++++------------- app/Models/Barobill/AccountCode.php | 23 +++++++-- 2 files changed, 35 insertions(+), 36 deletions(-) diff --git a/app/Http/Controllers/Barobill/EaccountController.php b/app/Http/Controllers/Barobill/EaccountController.php index b3d81894..1edc6e93 100644 --- a/app/Http/Controllers/Barobill/EaccountController.php +++ b/app/Http/Controllers/Barobill/EaccountController.php @@ -584,12 +584,11 @@ private function getBankName(string $code): string } /** - * 계정과목 목록 조회 + * 계정과목 목록 조회 (글로벌 데이터) */ public function accountCodes(): JsonResponse { - $tenantId = session('selected_tenant_id', self::HEADQUARTERS_TENANT_ID); - $codes = AccountCode::getActiveByTenant($tenantId); + $codes = AccountCode::getActive(); return response()->json([ 'success' => true, @@ -603,15 +602,11 @@ public function accountCodes(): JsonResponse } /** - * 전체 계정과목 목록 조회 (설정용, 비활성 포함) + * 전체 계정과목 목록 조회 (설정용, 비활성 포함, 글로벌 데이터) */ public function accountCodesAll(): JsonResponse { - $tenantId = session('selected_tenant_id', self::HEADQUARTERS_TENANT_ID); - $codes = AccountCode::where('tenant_id', $tenantId) - ->orderBy('sort_order') - ->orderBy('code') - ->get(); + $codes = AccountCode::getAll(); return response()->json([ 'success' => true, @@ -620,23 +615,19 @@ public function accountCodesAll(): JsonResponse } /** - * 계정과목 추가 + * 계정과목 추가 (글로벌 데이터) */ public function accountCodeStore(Request $request): JsonResponse { try { - $tenantId = session('selected_tenant_id', self::HEADQUARTERS_TENANT_ID); - $validated = $request->validate([ 'code' => 'required|string|max:10', 'name' => 'required|string|max:100', 'category' => 'nullable|string|max:50', ]); - // 중복 체크 - $exists = AccountCode::where('tenant_id', $tenantId) - ->where('code', $validated['code']) - ->exists(); + // 중복 체크 (글로벌) + $exists = AccountCode::where('code', $validated['code'])->exists(); if ($exists) { return response()->json([ @@ -645,10 +636,10 @@ public function accountCodeStore(Request $request): JsonResponse ], 422); } - $maxSort = AccountCode::where('tenant_id', $tenantId)->max('sort_order') ?? 0; + $maxSort = AccountCode::max('sort_order') ?? 0; $accountCode = AccountCode::create([ - 'tenant_id' => $tenantId, + 'tenant_id' => self::HEADQUARTERS_TENANT_ID, // 글로벌 데이터는 기본 테넌트에 저장 'code' => $validated['code'], 'name' => $validated['name'], 'category' => $validated['category'] ?? null, @@ -670,16 +661,12 @@ public function accountCodeStore(Request $request): JsonResponse } /** - * 계정과목 수정 + * 계정과목 수정 (글로벌 데이터) */ public function accountCodeUpdate(Request $request, int $id): JsonResponse { try { - $tenantId = session('selected_tenant_id', self::HEADQUARTERS_TENANT_ID); - - $accountCode = AccountCode::where('tenant_id', $tenantId) - ->where('id', $id) - ->first(); + $accountCode = AccountCode::find($id); if (!$accountCode) { return response()->json([ @@ -695,10 +682,9 @@ public function accountCodeUpdate(Request $request, int $id): JsonResponse 'is_active' => 'sometimes|boolean', ]); - // 코드 변경 시 중복 체크 + // 코드 변경 시 중복 체크 (글로벌) if (isset($validated['code']) && $validated['code'] !== $accountCode->code) { - $exists = AccountCode::where('tenant_id', $tenantId) - ->where('code', $validated['code']) + $exists = AccountCode::where('code', $validated['code']) ->where('id', '!=', $id) ->exists(); @@ -726,16 +712,12 @@ public function accountCodeUpdate(Request $request, int $id): JsonResponse } /** - * 계정과목 삭제 + * 계정과목 삭제 (글로벌 데이터) */ public function accountCodeDestroy(int $id): JsonResponse { try { - $tenantId = session('selected_tenant_id', self::HEADQUARTERS_TENANT_ID); - - $accountCode = AccountCode::where('tenant_id', $tenantId) - ->where('id', $id) - ->first(); + $accountCode = AccountCode::find($id); if (!$accountCode) { return response()->json([ diff --git a/app/Models/Barobill/AccountCode.php b/app/Models/Barobill/AccountCode.php index aafa2c7d..7c295872 100644 --- a/app/Models/Barobill/AccountCode.php +++ b/app/Models/Barobill/AccountCode.php @@ -36,14 +36,31 @@ public function tenant(): BelongsTo } /** - * 테넌트별 활성 계정과목 조회 + * 테넌트별 활성 계정과목 조회 (하위 호환용) */ public static function getActiveByTenant(int $tenantId) { - return self::where('tenant_id', $tenantId) - ->where('is_active', true) + return self::getActive(); + } + + /** + * 전체 활성 계정과목 조회 (글로벌) + */ + public static function getActive() + { + return self::where('is_active', true) ->orderBy('sort_order') ->orderBy('code') ->get(); } + + /** + * 전체 계정과목 조회 (글로벌) + */ + public static function getAll() + { + return self::orderBy('sort_order') + ->orderBy('code') + ->get(); + } }