feat: 매입 세금계산서 수취 토글 기능 추가

- Purchase 모델에 tax_invoice_received 필드 추가
- PurchaseService에 toggleTaxInvoice() 메서드 추가
- UpdatePurchaseRequest에 tax_invoice_received 검증 규칙 추가
- 마이그레이션: purchases 테이블에 tax_invoice_received 컬럼 추가
This commit is contained in:
2025-12-24 16:16:53 +09:00
parent 1e161c16b0
commit 6ee3378377
5 changed files with 72 additions and 2 deletions

View File

@@ -21,6 +21,7 @@ public function rules(): array
'total_amount' => ['sometimes', 'numeric', 'min:0'],
'description' => ['nullable', 'string', 'max:1000'],
'withdrawal_id' => ['nullable', 'integer', 'exists:withdrawals,id'],
'tax_invoice_received' => ['sometimes', 'boolean'],
];
}

View File

@@ -22,6 +22,7 @@ class Purchase extends Model
'description',
'status',
'withdrawal_id',
'tax_invoice_received',
'created_by',
'updated_by',
'deleted_by',
@@ -34,6 +35,7 @@ class Purchase extends Model
'total_amount' => 'decimal:2',
'client_id' => 'integer',
'withdrawal_id' => 'integer',
'tax_invoice_received' => 'boolean',
];
/**

View File

@@ -117,8 +117,12 @@ public function update(int $id, array $data): Purchase
->where('tenant_id', $tenantId)
->findOrFail($id);
// 확정 후에는 수정 불가
if (! $purchase->canEdit()) {
// 토글 필드만 업데이트하는 경우는 canEdit 체크 건너뛰기
$toggleOnlyFields = ['tax_invoice_received'];
$isToggleOnly = count(array_diff(array_keys($data), $toggleOnlyFields)) === 0;
// 확정 후에는 수정 불가 (토글 필드만 업데이트하는 경우 제외)
if (! $isToggleOnly && ! $purchase->canEdit()) {
throw new \Exception(__('error.purchase.cannot_edit'));
}
@@ -143,6 +147,9 @@ public function update(int $id, array $data): Purchase
if (array_key_exists('withdrawal_id', $data)) {
$purchase->withdrawal_id = $data['withdrawal_id'];
}
if (array_key_exists('tax_invoice_received', $data)) {
$purchase->tax_invoice_received = $data['tax_invoice_received'];
}
$purchase->updated_by = $userId;
$purchase->save();