103 lines
2.0 KiB
PHP
103 lines
2.0 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 Purchase extends Model
|
||
|
|
{
|
||
|
|
use BelongsToTenant, SoftDeletes;
|
||
|
|
|
||
|
|
protected $fillable = [
|
||
|
|
'tenant_id',
|
||
|
|
'purchase_number',
|
||
|
|
'purchase_date',
|
||
|
|
'client_id',
|
||
|
|
'supply_amount',
|
||
|
|
'tax_amount',
|
||
|
|
'total_amount',
|
||
|
|
'description',
|
||
|
|
'status',
|
||
|
|
'withdrawal_id',
|
||
|
|
'created_by',
|
||
|
|
'updated_by',
|
||
|
|
'deleted_by',
|
||
|
|
];
|
||
|
|
|
||
|
|
protected $casts = [
|
||
|
|
'purchase_date' => 'date',
|
||
|
|
'supply_amount' => 'decimal:2',
|
||
|
|
'tax_amount' => 'decimal:2',
|
||
|
|
'total_amount' => 'decimal:2',
|
||
|
|
'client_id' => 'integer',
|
||
|
|
'withdrawal_id' => 'integer',
|
||
|
|
];
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 상태 목록
|
||
|
|
*/
|
||
|
|
public const STATUSES = [
|
||
|
|
'draft' => '임시저장',
|
||
|
|
'confirmed' => '확정',
|
||
|
|
];
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 거래처 관계
|
||
|
|
*/
|
||
|
|
public function client(): BelongsTo
|
||
|
|
{
|
||
|
|
return $this->belongsTo(Client::class);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 출금 관계
|
||
|
|
*/
|
||
|
|
public function withdrawal(): BelongsTo
|
||
|
|
{
|
||
|
|
return $this->belongsTo(Withdrawal::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';
|
||
|
|
}
|
||
|
|
}
|