From d4fb2582fd7e076d0ca12bf81fecc0927712fa24 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 20:44:56 +0900 Subject: [PATCH] =?UTF-8?q?fix:=EB=B0=94=EB=A1=9C=EB=B9=8C=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=EB=9F=89=20=EC=A1=B0=ED=9A=8C=20=EC=9A=B4=EC=98=81?= =?UTF-8?q?=EB=AA=A8=EB=93=9C=20=ED=95=84=ED=84=B0=20=EB=B0=8F=20=EA=B1=B4?= =?UTF-8?q?=EC=88=98=20=EC=A7=91=EA=B3=84=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 테스트 모드 제외하고 운영(production) 모드만 조회하도록 필터 추가 - getTaxInvoiceCount(): HometaxInvoice 테이블에서 매출 세금계산서 건수 카운트 - getHometaxCount(): HometaxInvoice 테이블에서 매입/매출 전체 건수 카운트 - 기존 TODO로 표시된 메서드 구현 완료 Co-Authored-By: Claude Opus 4.5 --- .../Barobill/BarobillUsageService.php | 57 +++++++++++++++---- 1 file changed, 45 insertions(+), 12 deletions(-) diff --git a/app/Services/Barobill/BarobillUsageService.php b/app/Services/Barobill/BarobillUsageService.php index 9cc38e28..2d79cbe0 100644 --- a/app/Services/Barobill/BarobillUsageService.php +++ b/app/Services/Barobill/BarobillUsageService.php @@ -4,6 +4,7 @@ use App\Models\Barobill\BarobillMember; use App\Models\Barobill\BarobillPricingPolicy; +use App\Models\Barobill\HometaxInvoice; use Illuminate\Support\Facades\Log; use Illuminate\Support\Collection; @@ -33,14 +34,20 @@ public function __construct(BarobillService $barobillService) * @param string $startDate 시작일 (YYYYMMDD) * @param string $endDate 종료일 (YYYYMMDD) * @param int|null $tenantId 특정 테넌트만 조회 (null이면 전체) + * @param bool $productionOnly 운영 모드만 조회 (기본값: true) * @return array */ - public function getUsageList(string $startDate, string $endDate, ?int $tenantId = null): array + public function getUsageList(string $startDate, string $endDate, ?int $tenantId = null, bool $productionOnly = true): array { $query = BarobillMember::query() ->where('status', 'active') ->with('tenant:id,company_name'); + // 운영 모드만 조회 (테스트 모드 제외) + if ($productionOnly) { + $query->where('server_mode', 'production'); + } + if ($tenantId) { $query->where('tenant_id', $tenantId); } @@ -133,16 +140,29 @@ public function aggregateStats(array $usageList): array /** * 전자세금계산서 발행 건수 조회 * - * 바로빌 API에 직접적인 세금계산서 건수 조회 API가 없어서 - * 임시로 0을 반환합니다. 실제 구현 시 발행 내역 조회 API 활용 필요. + * HometaxInvoice 테이블에서 해당 테넌트의 매출 세금계산서 건수를 카운트합니다. + * (매출 = 발행한 세금계산서) */ protected function getTaxInvoiceCount(BarobillMember $member, string $startDate, string $endDate): int { - // TODO: 세금계산서 발행 내역 조회 API 연동 - // 현재 바로빌 API에서 제공하는 세금계산서 목록 조회 기능 활용 필요 - // GetTaxInvoiceList 등의 API 활용 + try { + // YYYYMMDD -> YYYY-MM-DD 형식 변환 + $start = substr($startDate, 0, 4) . '-' . substr($startDate, 4, 2) . '-' . substr($startDate, 6, 2); + $end = substr($endDate, 0, 4) . '-' . substr($endDate, 4, 2) . '-' . substr($endDate, 6, 2); - return 0; + return HometaxInvoice::where('tenant_id', $member->tenant_id) + ->where('invoice_type', 'sales') // 매출 (발행한 세금계산서) + ->whereBetween('write_date', [$start, $end]) + ->count(); + } catch (\Exception $e) { + Log::warning('세금계산서 건수 조회 실패', [ + 'member_id' => $member->id, + 'tenant_id' => $member->tenant_id, + 'error' => $e->getMessage(), + ]); + + return 0; + } } /** @@ -216,15 +236,28 @@ protected function getCardCount(BarobillMember $member, string $startDate, strin /** * 홈텍스 매입/매출 건수 조회 * - * 바로빌 API에서 홈텍스 매입/매출 조회 API 활용 필요. - * 현재는 임시로 0 반환. + * HometaxInvoice 테이블에서 해당 테넌트의 전체 세금계산서 건수를 카운트합니다. + * (매입 + 매출 모두 포함) */ protected function getHometaxCount(BarobillMember $member, string $startDate, string $endDate): int { - // TODO: 홈텍스 매입/매출 조회 API 연동 - // GetHomeTaxTaxInvoice 등의 API 활용 필요 + try { + // YYYYMMDD -> YYYY-MM-DD 형식 변환 + $start = substr($startDate, 0, 4) . '-' . substr($startDate, 4, 2) . '-' . substr($startDate, 6, 2); + $end = substr($endDate, 0, 4) . '-' . substr($endDate, 4, 2) . '-' . substr($endDate, 6, 2); - return 0; + return HometaxInvoice::where('tenant_id', $member->tenant_id) + ->whereBetween('write_date', [$start, $end]) + ->count(); + } catch (\Exception $e) { + Log::warning('홈텍스 건수 조회 실패', [ + 'member_id' => $member->id, + 'tenant_id' => $member->tenant_id, + 'error' => $e->getMessage(), + ]); + + return 0; + } } /**