Files
sam-api/app/Models/Tenants/Sale.php
hskwon cbed92a95c feat: 매출/매입 관리 API 구현
- 매출(Sale) 및 매입(Purchase) CRUD API 구현
- 문서번호 자동 생성 (SL/PU + YYYYMMDD + 시퀀스)
- 상태 관리 (draft → confirmed → invoiced)
- 확정(confirm) 및 요약(summary) 기능 추가
- BelongsToTenant, SoftDeletes 적용
- Swagger API 문서 작성 완료

추가된 파일:
- 마이그레이션: sales, purchases 테이블
- 모델: Sale, Purchase
- 서비스: SaleService, PurchaseService
- 컨트롤러: SaleController, PurchaseController
- FormRequest: Store/Update 4개
- Swagger: SaleApi.php, PurchaseApi.php

API 엔드포인트 (14개):
- GET/POST /v1/sales, /v1/purchases
- GET/PUT/DELETE /v1/{sales,purchases}/{id}
- POST /v1/{sales,purchases}/{id}/confirm
- GET /v1/{sales,purchases}/summary
2025-12-17 22:14:48 +09:00

106 lines
2.1 KiB
PHP

<?php
namespace App\Models\Tenants;
use App\Traits\BelongsToTenant;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
class Sale extends Model
{
use BelongsToTenant, SoftDeletes;
protected $fillable = [
'tenant_id',
'sale_number',
'sale_date',
'client_id',
'supply_amount',
'tax_amount',
'total_amount',
'description',
'status',
'tax_invoice_id',
'deposit_id',
'created_by',
'updated_by',
'deleted_by',
];
protected $casts = [
'sale_date' => 'date',
'supply_amount' => 'decimal:2',
'tax_amount' => 'decimal:2',
'total_amount' => 'decimal:2',
'client_id' => 'integer',
'tax_invoice_id' => 'integer',
'deposit_id' => 'integer',
];
/**
* 상태 목록
*/
public const STATUSES = [
'draft' => '임시저장',
'confirmed' => '확정',
'invoiced' => '세금계산서발행',
];
/**
* 거래처 관계
*/
public function client(): BelongsTo
{
return $this->belongsTo(Client::class);
}
/**
* 입금 관계
*/
public function deposit(): BelongsTo
{
return $this->belongsTo(Deposit::class);
}
/**
* 생성자 관계
*/
public function creator(): BelongsTo
{
return $this->belongsTo(\App\Models\User::class, 'created_by');
}
/**
* 상태 라벨
*/
public function getStatusLabelAttribute(): string
{
return self::STATUSES[$this->status] ?? $this->status;
}
/**
* 확정 가능 여부
*/
public function canConfirm(): bool
{
return $this->status === 'draft';
}
/**
* 수정 가능 여부
*/
public function canEdit(): bool
{
return $this->status === 'draft';
}
/**
* 삭제 가능 여부
*/
public function canDelete(): bool
{
return $this->status === 'draft';
}
}