From 71a33d79cca009e4f7933b00473740c3cf2589ff Mon Sep 17 00:00:00 2001 From: kent Date: Sat, 27 Dec 2025 16:47:26 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EB=A7=A4=EC=9E=85=EC=9C=A0=ED=98=95(pu?= =?UTF-8?q?rchase=5Ftype)=20=ED=95=84=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 마이그레이션: purchases 테이블에 purchase_type 컬럼 추가 - Purchase 모델: $fillable 및 PURCHASE_TYPES 상수 추가 - StorePurchaseRequest: purchase_type validation 추가 - UpdatePurchaseRequest: purchase_type validation 추가 - PurchaseService: store/update에 purchase_type 처리 추가 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .../V1/Purchase/StorePurchaseRequest.php | 1 + .../V1/Purchase/UpdatePurchaseRequest.php | 1 + app/Models/Tenants/Purchase.php | 23 +++++++++++++++ app/Services/PurchaseService.php | 4 +++ ...9_add_purchase_type_to_purchases_table.php | 28 +++++++++++++++++++ 5 files changed, 57 insertions(+) create mode 100644 database/migrations/2025_12_27_164149_add_purchase_type_to_purchases_table.php diff --git a/app/Http/Requests/V1/Purchase/StorePurchaseRequest.php b/app/Http/Requests/V1/Purchase/StorePurchaseRequest.php index e8e17f9..d051e81 100644 --- a/app/Http/Requests/V1/Purchase/StorePurchaseRequest.php +++ b/app/Http/Requests/V1/Purchase/StorePurchaseRequest.php @@ -19,6 +19,7 @@ public function rules(): array 'supply_amount' => ['required', 'numeric', 'min:0'], 'tax_amount' => ['required', 'numeric', 'min:0'], 'total_amount' => ['required', 'numeric', 'min:0'], + 'purchase_type' => ['nullable', 'string', 'max:50'], 'description' => ['nullable', 'string', 'max:1000'], 'withdrawal_id' => ['nullable', 'integer', 'exists:withdrawals,id'], ]; diff --git a/app/Http/Requests/V1/Purchase/UpdatePurchaseRequest.php b/app/Http/Requests/V1/Purchase/UpdatePurchaseRequest.php index a729e77..377796a 100644 --- a/app/Http/Requests/V1/Purchase/UpdatePurchaseRequest.php +++ b/app/Http/Requests/V1/Purchase/UpdatePurchaseRequest.php @@ -19,6 +19,7 @@ public function rules(): array 'supply_amount' => ['sometimes', 'numeric', 'min:0'], 'tax_amount' => ['sometimes', 'numeric', 'min:0'], 'total_amount' => ['sometimes', 'numeric', 'min:0'], + 'purchase_type' => ['nullable', 'string', 'max:50'], '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 147d3d7..d72f68b 100644 --- a/app/Models/Tenants/Purchase.php +++ b/app/Models/Tenants/Purchase.php @@ -21,6 +21,7 @@ class Purchase extends Model 'total_amount', 'description', 'status', + 'purchase_type', 'withdrawal_id', 'tax_invoice_received', 'created_by', @@ -28,6 +29,28 @@ class Purchase extends Model 'deleted_by', ]; + /** + * 매입 유형 목록 + */ + public const PURCHASE_TYPES = [ + 'unset' => '미설정', + 'raw_material' => '원재료매입', + 'subsidiary_material' => '부재료매입', + 'product' => '상품매입', + 'outsourcing' => '외주가공비', + 'consumables' => '소모품비', + 'repair' => '수선비', + 'transportation' => '운반비', + 'office_supplies' => '사무용품비', + 'rent' => '임차료', + 'utilities' => '수도광열비', + 'communication' => '통신비', + 'vehicle' => '차량유지비', + 'entertainment' => '접대비', + 'insurance' => '보험료', + 'other_service' => '기타용역비', + ]; + protected $casts = [ 'purchase_date' => 'date', 'supply_amount' => 'decimal:2', diff --git a/app/Services/PurchaseService.php b/app/Services/PurchaseService.php index a05cded..57b9869 100644 --- a/app/Services/PurchaseService.php +++ b/app/Services/PurchaseService.php @@ -93,6 +93,7 @@ public function store(array $data): Purchase $purchase->supply_amount = $data['supply_amount']; $purchase->tax_amount = $data['tax_amount']; $purchase->total_amount = $data['total_amount']; + $purchase->purchase_type = $data['purchase_type'] ?? null; $purchase->description = $data['description'] ?? null; $purchase->status = 'draft'; $purchase->withdrawal_id = $data['withdrawal_id'] ?? null; @@ -147,6 +148,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('purchase_type', $data)) { + $purchase->purchase_type = $data['purchase_type']; + } if (array_key_exists('tax_invoice_received', $data)) { $purchase->tax_invoice_received = $data['tax_invoice_received']; } diff --git a/database/migrations/2025_12_27_164149_add_purchase_type_to_purchases_table.php b/database/migrations/2025_12_27_164149_add_purchase_type_to_purchases_table.php new file mode 100644 index 0000000..d4d04fe --- /dev/null +++ b/database/migrations/2025_12_27_164149_add_purchase_type_to_purchases_table.php @@ -0,0 +1,28 @@ +string('purchase_type', 50)->nullable()->after('status')->comment('매입유형'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('purchases', function (Blueprint $table) { + $table->dropColumn('purchase_type'); + }); + } +};