Files
sam-api/app/Models/Barobill/HometaxInvoice.php
김보곤 18a6f3e7aa refactor: [barobill] 바로빌 연동 코드 전면 개선
- config/services.php에 barobill 설정 등록 (운영/테스트 모드 분기 정상화)
- BarobillSetting 모델에 BelongsToTenant 적용 및 use_* 필드 casts 추가
- BarobillService API URL을 baroservice.com(SOAP)으로 수정
- BarobillService callApi 메서드 경로 하드코딩 제거 (서비스별 분기)
- BarobillService 예외 이중 래핑 문제 수정
- BarobillController URL 메서드 중복 코드 제거
- 누락 모델 16개 생성 (MNG 패턴 준수, BelongsToTenant 적용)
- 바로빌 전 테이블 options JSON 컬럼 추가 마이그레이션
2026-03-11 18:16:59 +09:00

159 lines
4.4 KiB
PHP

<?php
namespace App\Models\Barobill;
use App\Traits\BelongsToTenant;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
class HometaxInvoice extends Model
{
use BelongsToTenant, SoftDeletes;
protected $table = 'hometax_invoices';
// 과세유형
public const TAX_TYPE_TAXABLE = '01'; // 과세
public const TAX_TYPE_ZERO = '02'; // 영세
public const TAX_TYPE_EXEMPT = '03'; // 면세
// 영수/청구
public const PURPOSE_TYPE_RECEIPT = '01'; // 영수
public const PURPOSE_TYPE_CLAIM = '02'; // 청구
// 발급유형
public const ISSUE_TYPE_NORMAL = '01'; // 정발행
public const ISSUE_TYPE_REVERSE = '02'; // 역발행
protected $fillable = [
'tenant_id',
'nts_confirm_num',
'invoice_type',
'write_date',
'issue_date',
'send_date',
'invoicer_corp_num',
'invoicer_tax_reg_id',
'invoicer_corp_name',
'invoicer_ceo_name',
'invoicer_addr',
'invoicer_biz_type',
'invoicer_biz_class',
'invoicer_contact_id',
'invoicee_corp_num',
'invoicee_tax_reg_id',
'invoicee_corp_name',
'invoicee_ceo_name',
'invoicee_addr',
'invoicee_biz_type',
'invoicee_biz_class',
'invoicee_contact_id',
'supply_amount',
'tax_amount',
'total_amount',
'tax_type',
'purpose_type',
'issue_type',
'is_modified',
'original_nts_confirm_num',
'modify_code',
'remark1',
'remark2',
'remark3',
'item_name',
'item_count',
'item_unit_price',
'item_supply_amount',
'item_tax_amount',
'item_remark',
'account_code',
'account_name',
'deduction_type',
];
protected $casts = [
'supply_amount' => 'integer',
'tax_amount' => 'integer',
'total_amount' => 'integer',
'item_count' => 'integer',
'item_unit_price' => 'integer',
'item_supply_amount' => 'integer',
'item_tax_amount' => 'integer',
'is_modified' => 'boolean',
'write_date' => 'date',
'issue_date' => 'date',
'send_date' => 'date',
];
// =========================================================================
// 관계 정의
// =========================================================================
public function tenant(): BelongsTo
{
return $this->belongsTo(\App\Models\Tenants\Tenant::class);
}
public function journals(): HasMany
{
return $this->hasMany(HometaxInvoiceJournal::class, 'hometax_invoice_id');
}
// =========================================================================
// 스코프
// =========================================================================
public function scopeSales($query)
{
return $query->where('invoice_type', 'sales');
}
public function scopePurchase($query)
{
return $query->where('invoice_type', 'purchase');
}
public function scopePeriod($query, string $startDate, string $endDate)
{
return $query->whereBetween('write_date', [$startDate, $endDate]);
}
// =========================================================================
// 접근자
// =========================================================================
public function getTaxTypeNameAttribute(): string
{
return match ($this->tax_type) {
self::TAX_TYPE_TAXABLE => '과세',
self::TAX_TYPE_ZERO => '영세',
self::TAX_TYPE_EXEMPT => '면세',
default => $this->tax_type ?? '',
};
}
public function getPurposeTypeNameAttribute(): string
{
return match ($this->purpose_type) {
self::PURPOSE_TYPE_RECEIPT => '영수',
self::PURPOSE_TYPE_CLAIM => '청구',
default => $this->purpose_type ?? '',
};
}
public function getIssueTypeNameAttribute(): string
{
return match ($this->issue_type) {
self::ISSUE_TYPE_NORMAL => '정발행',
self::ISSUE_TYPE_REVERSE => '역발행',
default => $this->issue_type ?? '',
};
}
}