Files
sam-manage/app/Models/Barobill/BarobillBillingRecord.php
김보곤 8291cdc39b feat: [database] codebridge DB 분리 - 118개 MNG 전용 테이블 connection 설정
- config/database.php에 codebridge connection 추가
- 78개 MNG 전용 모델에 $connection = 'codebridge' 설정
  - Admin (15): PM, 로드맵, API Explorer
  - Sales (16): 영업파트너, 수수료, 가망고객
  - Finance (9): 법인카드, 자금관리, 홈택스
  - Barobill (12): 은행/카드 동기화 관리
  - Interview (1), ESign (6), Equipment (2)
  - AI (3), Audit (3), 기타 (11)
2026-03-07 11:31:27 +09:00

118 lines
2.6 KiB
PHP

<?php
namespace App\Models\Barobill;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* 바로빌 과금 기록 모델
*/
class BarobillBillingRecord extends Model
{
protected $connection = 'codebridge';
protected $table = 'barobill_billing_records';
protected $fillable = [
'member_id',
'billing_month',
'service_type',
'billing_type',
'quantity',
'unit_price',
'total_amount',
'billed_at',
'description',
];
protected $casts = [
'quantity' => 'integer',
'unit_price' => 'integer',
'total_amount' => 'integer',
'billed_at' => 'date',
'created_at' => 'datetime',
'updated_at' => 'datetime',
];
/**
* 서비스 유형 라벨
*/
public const SERVICE_TYPES = [
'tax_invoice' => '전자세금계산서',
'bank_account' => '계좌조회',
'card' => '카드내역',
'hometax' => '홈텍스 매입/매출',
];
/**
* 과금 유형 라벨
*/
public const BILLING_TYPES = [
'subscription' => '월정액',
'usage' => '건별',
];
/**
* 건별 단가 (원)
*/
public const USAGE_UNIT_PRICES = [
'tax_invoice' => 100, // 전자세금계산서 건당 100원
];
/**
* 바로빌 회원사 관계
*/
public function member(): BelongsTo
{
return $this->belongsTo(BarobillMember::class, 'member_id');
}
/**
* 서비스 유형 라벨
*/
public function getServiceTypeLabelAttribute(): string
{
return self::SERVICE_TYPES[$this->service_type] ?? $this->service_type;
}
/**
* 과금 유형 라벨
*/
public function getBillingTypeLabelAttribute(): string
{
return self::BILLING_TYPES[$this->billing_type] ?? $this->billing_type;
}
/**
* 특정 월 조회
*/
public function scopeOfMonth($query, string $billingMonth)
{
return $query->where('billing_month', $billingMonth);
}
/**
* 월정액만 조회
*/
public function scopeSubscription($query)
{
return $query->where('billing_type', 'subscription');
}
/**
* 건별만 조회
*/
public function scopeUsage($query)
{
return $query->where('billing_type', 'usage');
}
/**
* 특정 서비스 조회
*/
public function scopeOfService($query, string $serviceType)
{
return $query->where('service_type', $serviceType);
}
}