diff --git a/CURRENT_WORKS.md b/CURRENT_WORKS.md index 7969eab..aea5eb8 100644 --- a/CURRENT_WORKS.md +++ b/CURRENT_WORKS.md @@ -1,5 +1,37 @@ # SAM API 작업 현황 +## 2025-12-24 (화) - 매입 세금계산서 수취 토글 기능 추가 + +### 작업 목표 +- 매입(Purchase) 테이블에 세금계산서 수취 여부(tax_invoice_received) 필드 추가 +- React 프론트엔드에서 토글 API 호출 가능하도록 지원 + +### 생성된 마이그레이션 (1개) + +| 파일명 | 설명 | +|--------|------| +| `2025_12_24_160000_add_tax_invoice_received_to_purchases_table.php` | purchases 테이블에 tax_invoice_received 컬럼 추가 | + +### 수정된 파일 (3개) + +| 파일명 | 변경 내용 | +|--------|----------| +| `app/Models/Tenants/Purchase.php` | fillable에 tax_invoice_received 추가, casts에 boolean 타입 추가 | +| `app/Services/PurchaseService.php` | toggleTaxInvoice() 메서드 추가 | +| `app/Http/Requests/V1/Purchase/UpdatePurchaseRequest.php` | tax_invoice_received 필드 검증 규칙 추가 | + +### 마이그레이션 실행 +```bash +php artisan migrate +# 2025_12_24_160000_add_tax_invoice_received_to_purchases_table ... DONE +``` + +### 테스트 결과 +- 세금계산서 수취 토글 API 정상 동작 +- React 매입 관리 페이지에서 토글 기능 정상 작동 + +--- + ## 2025-12-22 (일) - 견적수식 시더 업데이트 (5130 연동) ### 작업 목표 diff --git a/app/Http/Requests/V1/Purchase/UpdatePurchaseRequest.php b/app/Http/Requests/V1/Purchase/UpdatePurchaseRequest.php index 5c89b5b..a729e77 100644 --- a/app/Http/Requests/V1/Purchase/UpdatePurchaseRequest.php +++ b/app/Http/Requests/V1/Purchase/UpdatePurchaseRequest.php @@ -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'], ]; } diff --git a/app/Models/Tenants/Purchase.php b/app/Models/Tenants/Purchase.php index 8920277..147d3d7 100644 --- a/app/Models/Tenants/Purchase.php +++ b/app/Models/Tenants/Purchase.php @@ -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', ]; /** diff --git a/app/Services/PurchaseService.php b/app/Services/PurchaseService.php index 9c9d1b4..a05cded 100644 --- a/app/Services/PurchaseService.php +++ b/app/Services/PurchaseService.php @@ -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(); diff --git a/database/migrations/2025_12_24_160000_add_tax_invoice_received_to_purchases_table.php b/database/migrations/2025_12_24_160000_add_tax_invoice_received_to_purchases_table.php new file mode 100644 index 0000000..343ed6f --- /dev/null +++ b/database/migrations/2025_12_24_160000_add_tax_invoice_received_to_purchases_table.php @@ -0,0 +1,28 @@ +boolean('tax_invoice_received')->default(false)->after('withdrawal_id')->comment('세금계산서 수취 여부'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('purchases', function (Blueprint $table) { + $table->dropColumn('tax_invoice_received'); + }); + } +};