fix:바로빌 사용량 조회 운영모드 필터 및 건수 집계 구현

- 테스트 모드 제외하고 운영(production) 모드만 조회하도록 필터 추가
- getTaxInvoiceCount(): HometaxInvoice 테이블에서 매출 세금계산서 건수 카운트
- getHometaxCount(): HometaxInvoice 테이블에서 매입/매출 전체 건수 카운트
- 기존 TODO로 표시된 메서드 구현 완료

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
김보곤
2026-02-03 20:44:56 +09:00
parent ff1eea4853
commit d4fb2582fd

View File

@@ -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;
}
}
/**