feat: clients.is_active CHAR(1) → TINYINT(1) Boolean 마이그레이션

- DB: CHAR(1) 'Y'/'N' → TINYINT(1) 0/1 컬럼 타입 변경
- Model: boolean 캐스트 추가, scopeActive() 수정
- Service: toggle(), index() Boolean 로직 적용
- FormRequest: 'in:Y,N' → 'boolean' 검증 규칙 변경
- Swagger: is_active type string → boolean 변경
This commit is contained in:
2025-12-08 20:25:38 +09:00
parent 8d3ea4bb39
commit 5f200054ea
6 changed files with 60 additions and 97 deletions

View File

@@ -3,7 +3,6 @@
namespace App\Services;
use App\Models\Orders\Client;
use Illuminate\Support\Facades\Validator;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
@@ -30,7 +29,7 @@ public function index(array $params)
}
if ($onlyActive !== null) {
$query->where('is_active', $onlyActive ? 'Y' : 'N');
$query->where('is_active', (bool) $onlyActive);
}
$query->orderBy('client_code')->orderBy('id');
@@ -51,49 +50,9 @@ public function show(int $id)
}
/** 생성 */
public function store(array $params)
public function store(array $data)
{
$tenantId = $this->tenantId();
$uid = $this->apiUserId();
$v = Validator::make($params, [
'client_code' => 'required|string|max:50',
'name' => 'required|string|max:100',
'client_type' => 'nullable|in:매입,매출,매입매출',
'contact_person' => 'nullable|string|max:50',
'phone' => 'nullable|string|max:30',
'mobile' => 'nullable|string|max:20',
'fax' => 'nullable|string|max:20',
'email' => 'nullable|email|max:80',
'address' => 'nullable|string|max:255',
'manager_name' => 'nullable|string|max:50',
'manager_tel' => 'nullable|string|max:20',
'system_manager' => 'nullable|string|max:50',
'account_id' => 'nullable|string|max:50',
'account_password' => 'nullable|string|max:255',
'purchase_payment_day' => 'nullable|string|max:20',
'sales_payment_day' => 'nullable|string|max:20',
'business_no' => 'nullable|string|max:20',
'business_type' => 'nullable|string|max:50',
'business_item' => 'nullable|string|max:100',
'tax_agreement' => 'nullable|boolean',
'tax_amount' => 'nullable|numeric|min:0',
'tax_start_date' => 'nullable|date',
'tax_end_date' => 'nullable|date',
'bad_debt' => 'nullable|boolean',
'bad_debt_amount' => 'nullable|numeric|min:0',
'bad_debt_receive_date' => 'nullable|date',
'bad_debt_end_date' => 'nullable|date',
'bad_debt_progress' => 'nullable|in:협의중,소송중,회수완료,대손처리',
'memo' => 'nullable|string',
'is_active' => 'nullable|in:Y,N',
]);
if ($v->fails()) {
throw new BadRequestHttpException($v->errors()->first());
}
$data = $v->validated();
// client_code 중복 검사
$exists = Client::where('tenant_id', $tenantId)
@@ -104,72 +63,32 @@ public function store(array $params)
}
$data['tenant_id'] = $tenantId;
$data['is_active'] = $data['is_active'] ?? 'Y';
$data['is_active'] = $data['is_active'] ?? true;
return Client::create($data);
}
/** 수정 */
public function update(int $id, array $params)
public function update(int $id, array $data)
{
$tenantId = $this->tenantId();
$uid = $this->apiUserId();
$client = Client::where('tenant_id', $tenantId)->find($id);
if (! $client) {
throw new NotFoundHttpException(__('error.not_found'));
}
$v = Validator::make($params, [
'client_code' => 'sometimes|required|string|max:50',
'name' => 'sometimes|required|string|max:100',
'client_type' => 'nullable|in:매입,매출,매입매출',
'contact_person' => 'nullable|string|max:50',
'phone' => 'nullable|string|max:30',
'mobile' => 'nullable|string|max:20',
'fax' => 'nullable|string|max:20',
'email' => 'nullable|email|max:80',
'address' => 'nullable|string|max:255',
'manager_name' => 'nullable|string|max:50',
'manager_tel' => 'nullable|string|max:20',
'system_manager' => 'nullable|string|max:50',
'account_id' => 'nullable|string|max:50',
'account_password' => 'nullable|string|max:255',
'purchase_payment_day' => 'nullable|string|max:20',
'sales_payment_day' => 'nullable|string|max:20',
'business_no' => 'nullable|string|max:20',
'business_type' => 'nullable|string|max:50',
'business_item' => 'nullable|string|max:100',
'tax_agreement' => 'nullable|boolean',
'tax_amount' => 'nullable|numeric|min:0',
'tax_start_date' => 'nullable|date',
'tax_end_date' => 'nullable|date',
'bad_debt' => 'nullable|boolean',
'bad_debt_amount' => 'nullable|numeric|min:0',
'bad_debt_receive_date' => 'nullable|date',
'bad_debt_end_date' => 'nullable|date',
'bad_debt_progress' => 'nullable|in:협의중,소송중,회수완료,대손처리',
'memo' => 'nullable|string',
'is_active' => 'nullable|in:Y,N',
]);
if ($v->fails()) {
throw new BadRequestHttpException($v->errors()->first());
}
$payload = $v->validated();
// client_code 변경 시 중복 검사
if (isset($payload['client_code']) && $payload['client_code'] !== $client->client_code) {
if (isset($data['client_code']) && $data['client_code'] !== $client->client_code) {
$exists = Client::where('tenant_id', $tenantId)
->where('client_code', $payload['client_code'])
->where('client_code', $data['client_code'])
->exists();
if ($exists) {
throw new BadRequestHttpException(__('error.duplicate_code'));
}
}
$client->update($payload);
$client->update($data);
return $client->refresh();
}
@@ -203,7 +122,6 @@ public function toggle(int $id)
throw new NotFoundHttpException(__('error.not_found'));
}
// Model에서 is_active가 boolean으로 캐스팅되므로 boolean으로 토글
$client->is_active = ! $client->is_active;
$client->save();