feat: 매출 세금계산서/거래명세서 토글 API 연동
- UpdateSaleRequest: tax_invoice_issued, transaction_statement_issued 필드 추가 - SaleService: 토글 필드 업데이트 로직 추가 (canEdit 우회) - Sale 모델: fillable에 토글 필드 추가 - 마이그레이션: sales 테이블에 토글 컬럼 추가
This commit is contained in:
@@ -21,6 +21,8 @@ public function rules(): array
|
||||
'total_amount' => ['sometimes', 'numeric', 'min:0'],
|
||||
'description' => ['nullable', 'string', 'max:1000'],
|
||||
'deposit_id' => ['nullable', 'integer', 'exists:deposits,id'],
|
||||
'tax_invoice_issued' => ['sometimes', 'boolean'],
|
||||
'transaction_statement_issued' => ['sometimes', 'boolean'],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,8 @@ class Sale extends Model
|
||||
'total_amount',
|
||||
'description',
|
||||
'status',
|
||||
'tax_invoice_issued',
|
||||
'transaction_statement_issued',
|
||||
'tax_invoice_id',
|
||||
'deposit_id',
|
||||
'created_by',
|
||||
@@ -29,11 +31,13 @@ class Sale extends Model
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'sale_date' => 'date',
|
||||
'sale_date' => 'date:Y-m-d',
|
||||
'supply_amount' => 'decimal:2',
|
||||
'tax_amount' => 'decimal:2',
|
||||
'total_amount' => 'decimal:2',
|
||||
'client_id' => 'integer',
|
||||
'tax_invoice_issued' => 'boolean',
|
||||
'transaction_statement_issued' => 'boolean',
|
||||
'tax_invoice_id' => 'integer',
|
||||
'deposit_id' => 'integer',
|
||||
];
|
||||
|
||||
@@ -117,8 +117,12 @@ public function update(int $id, array $data): Sale
|
||||
->where('tenant_id', $tenantId)
|
||||
->findOrFail($id);
|
||||
|
||||
// 확정 후에는 수정 불가
|
||||
if (! $sale->canEdit()) {
|
||||
// 토글 필드만 업데이트하는 경우는 canEdit 체크 건너뛰기
|
||||
$toggleOnlyFields = ['tax_invoice_issued', 'transaction_statement_issued'];
|
||||
$isToggleOnly = count(array_diff(array_keys($data), $toggleOnlyFields)) === 0;
|
||||
|
||||
// 확정 후에는 수정 불가 (토글 필드만 업데이트하는 경우 제외)
|
||||
if (! $isToggleOnly && ! $sale->canEdit()) {
|
||||
throw new \Exception(__('error.sale.cannot_edit'));
|
||||
}
|
||||
|
||||
@@ -143,6 +147,12 @@ public function update(int $id, array $data): Sale
|
||||
if (array_key_exists('deposit_id', $data)) {
|
||||
$sale->deposit_id = $data['deposit_id'];
|
||||
}
|
||||
if (array_key_exists('tax_invoice_issued', $data)) {
|
||||
$sale->tax_invoice_issued = $data['tax_invoice_issued'];
|
||||
}
|
||||
if (array_key_exists('transaction_statement_issued', $data)) {
|
||||
$sale->transaction_statement_issued = $data['transaction_statement_issued'];
|
||||
}
|
||||
|
||||
$sale->updated_by = $userId;
|
||||
$sale->save();
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('sales', function (Blueprint $table) {
|
||||
$table->boolean('tax_invoice_issued')->default(false)->after('status')->comment('세금계산서 발행완료');
|
||||
$table->boolean('transaction_statement_issued')->default(false)->after('tax_invoice_issued')->comment('거래명세서 발행완료');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('sales', function (Blueprint $table) {
|
||||
$table->dropColumn(['tax_invoice_issued', 'transaction_statement_issued']);
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user