Files
sam-api/app/Models/Tenants/Receiving.php
권혁성 5448f0e57d deploy: 2026-03-12 배포
- feat: [barobill] 바로빌 카드/은행/홈택스 REST API 구현
- feat: [equipment] 설비관리 API 백엔드 구현
- feat: [payroll] 급여관리 계산 엔진 및 일괄 처리 API
- feat: [QMS] 점검표 템플릿 관리 + 로트심사 개선
- feat: [생산/출하] 수주 단위 출하 자동생성 + 상태 흐름 개선
- feat: [receiving] 입고 성적서 파일 연결
- feat: [견적] 제어기 타입 체계 변경
- feat: [email] 테넌트 메일 설정 마이그레이션 및 모델
- feat: [pmis] 시공관리 테이블 마이그레이션
- feat: [R2] 파일 업로드 커맨드 + filesystems 설정
- feat: [배포] Jenkinsfile 롤백 기능 추가
- fix: [approval] SAM API 규칙 준수 코드 개선
- fix: [account-codes] 계정과목 중복 데이터 정리
- fix: [payroll] 일괄 생성 시 삭제된 사용자 건너뛰기
- fix: [db] codebridge DB 분리 후 깨진 FK 제약조건 제거
- refactor: [barobill] 바로빌 연동 코드 전면 개선
2026-03-12 15:20:20 +09:00

205 lines
4.7 KiB
PHP

<?php
namespace App\Models\Tenants;
use App\Traits\Auditable;
use App\Traits\BelongsToTenant;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
class Receiving extends Model
{
use Auditable, BelongsToTenant, SoftDeletes;
protected $fillable = [
'tenant_id',
'receiving_number',
'order_no',
'order_date',
'item_id',
'item_code',
'item_name',
'specification',
'supplier',
'order_qty',
'order_unit',
'due_date',
'receiving_qty',
'receiving_date',
'lot_no',
'supplier_lot',
'receiving_location',
'receiving_manager',
'status',
'remark',
'options',
'certificate_file_id',
'created_by',
'updated_by',
'deleted_by',
];
protected $casts = [
'order_date' => 'date',
'due_date' => 'date',
'receiving_date' => 'date',
'order_qty' => 'decimal:2',
'receiving_qty' => 'decimal:2',
'item_id' => 'integer',
'options' => 'array',
'certificate_file_id' => 'integer',
];
/**
* JSON 직렬화 시 자동 포함되는 접근자
*/
protected $appends = [
'manufacturer',
'material_no',
'inspection_status',
'inspection_date',
'inspection_result',
];
/**
* Options 키 상수 (확장 필드)
*/
public const OPTION_MANUFACTURER = 'manufacturer'; // 제조사
public const OPTION_MATERIAL_NO = 'material_no'; // 거래처 자재번호
public const OPTION_INSPECTION_STATUS = 'inspection_status'; // 수입검사 (적/부적/-)
public const OPTION_INSPECTION_DATE = 'inspection_date'; // 검사일
public const OPTION_INSPECTION_RESULT = 'inspection_result'; // 검사결과 (합격/불합격)
/**
* 상태 목록
*/
public const STATUSES = [
'order_completed' => '발주완료',
'shipping' => '배송중',
'inspection_pending' => '검사대기',
'receiving_pending' => '입고대기',
'completed' => '입고완료',
];
/**
* 품목 관계
*/
public function item(): BelongsTo
{
return $this->belongsTo(\App\Models\Items\Item::class);
}
/**
* 업체 제공 성적서 파일 관계
*/
public function certificateFile(): BelongsTo
{
return $this->belongsTo(\App\Models\Commons\File::class, 'certificate_file_id');
}
/**
* 생성자 관계
*/
public function creator(): BelongsTo
{
return $this->belongsTo(\App\Models\Members\User::class, 'created_by');
}
/**
* 상태 라벨
*/
public function getStatusLabelAttribute(): string
{
return self::STATUSES[$this->status] ?? $this->status;
}
/**
* Options에서 값 가져오기
*/
public function getOption(string $key, mixed $default = null): mixed
{
return $this->options[$key] ?? $default;
}
/**
* Options에 값 설정
*/
public function setOption(string $key, mixed $value): self
{
$options = $this->options ?? [];
$options[$key] = $value;
$this->options = $options;
return $this;
}
/**
* 제조사 접근자
*/
public function getManufacturerAttribute(): ?string
{
return $this->getOption(self::OPTION_MANUFACTURER);
}
/**
* 거래처 자재번호 접근자
*/
public function getMaterialNoAttribute(): ?string
{
return $this->getOption(self::OPTION_MATERIAL_NO);
}
/**
* 수입검사 상태 접근자
*/
public function getInspectionStatusAttribute(): ?string
{
return $this->getOption(self::OPTION_INSPECTION_STATUS);
}
/**
* 검사일 접근자
*/
public function getInspectionDateAttribute(): ?string
{
return $this->getOption(self::OPTION_INSPECTION_DATE);
}
/**
* 검사결과 접근자
*/
public function getInspectionResultAttribute(): ?string
{
return $this->getOption(self::OPTION_INSPECTION_RESULT);
}
/**
* 수정 가능 여부
*/
public function canEdit(): bool
{
return true;
}
/**
* 삭제 가능 여부
*/
public function canDelete(): bool
{
return $this->status !== 'completed';
}
/**
* 입고처리 가능 여부
*/
public function canProcess(): bool
{
return in_array($this->status, ['order_completed', 'shipping', 'inspection_pending', 'receiving_pending']);
}
}