'decimal:2', 'tax' => 'decimal:2', 'service_charge' => 'decimal:2', 'modified_supply_amount' => 'decimal:2', 'modified_tax' => 'decimal:2', 'is_manual' => 'boolean', ]; /** * 테넌트 관계 */ public function tenant(): BelongsTo { return $this->belongsTo(Tenant::class); } /** * 거래 고유 키 생성 (매칭용) */ public function getUniqueKeyAttribute(): string { return implode('|', [ $this->card_num, $this->use_dt, $this->approval_num, (int) $this->approval_amount, ]); } /** * 바로빌 로그 데이터로부터 고유 키 생성 (정적 메서드) */ public static function generateUniqueKey(array $log): string { return implode('|', [ $log['cardNum'] ?? '', $log['useDt'] ?? '', $log['approvalNum'] ?? '', (int) ($log['approvalAmount'] ?? 0), ]); } /** * 테넌트별 거래 내역 조회 (기간별) */ public static function getByDateRange(int $tenantId, string $startDate, string $endDate, ?string $cardNum = null) { $query = self::where('tenant_id', $tenantId) ->whereBetween('use_date', [$startDate, $endDate]) ->orderBy('use_date', 'desc') ->orderBy('use_time', 'desc'); if ($cardNum) { $query->where('card_num', $cardNum); } return $query->get()->keyBy(fn($item) => $item->unique_key); } }