- STOCK 주문 생성 시 담당자(manager_name) 미입력이면 로그인 사용자명 자동 설정
- GET /bending/material-lots?material={재질}: 수입검사 완료 입고의 LOT 목록 조회
- 취소→등록 복원은 기존 CANCELLED→DRAFT 전환으로 이미 지원됨 (프론트 UI만 필요)
120 lines
4.0 KiB
PHP
120 lines
4.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\V1;
|
|
|
|
use App\Helpers\ApiResponse;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Tenants\Receiving;
|
|
use App\Services\BendingCodeService;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
class BendingController extends Controller
|
|
{
|
|
public function __construct(
|
|
private readonly BendingCodeService $service
|
|
) {}
|
|
|
|
/**
|
|
* 절곡품 코드맵 조회 (캐스케이딩 드롭다운용)
|
|
*/
|
|
public function codeMap(): JsonResponse
|
|
{
|
|
return ApiResponse::handle(function () {
|
|
return $this->service->getCodeMap();
|
|
}, __('message.fetched'));
|
|
}
|
|
|
|
/**
|
|
* 드롭다운 선택 → 품목 매핑 조회
|
|
*/
|
|
public function resolveItem(Request $request): JsonResponse
|
|
{
|
|
return ApiResponse::handle(function () use ($request) {
|
|
$prodCode = $request->query('prod');
|
|
$specCode = $request->query('spec');
|
|
$lengthCode = $request->query('length');
|
|
|
|
if (! $prodCode || ! $specCode || ! $lengthCode) {
|
|
return ['error' => 'MISSING_PARAMS', 'code' => 400, 'message' => 'prod, spec, length 파라미터가 필요합니다.'];
|
|
}
|
|
|
|
$item = $this->service->resolveItem($prodCode, $specCode, $lengthCode);
|
|
|
|
if (! $item) {
|
|
return ['error' => 'NOT_MAPPED', 'code' => 404, 'message' => '해당 조합에 매핑된 품목이 없습니다.'];
|
|
}
|
|
|
|
return $item;
|
|
}, __('message.fetched'));
|
|
}
|
|
|
|
/**
|
|
* 원자재 LOT 목록 조회 (수입검사 완료 입고 기준)
|
|
*
|
|
* 재질(material)이 일치하는 입고 LOT 목록 반환
|
|
*/
|
|
public function materialLots(Request $request): JsonResponse
|
|
{
|
|
return ApiResponse::handle(function () use ($request) {
|
|
$material = $request->query('material');
|
|
|
|
$query = Receiving::where('status', 'completed')
|
|
->whereNotNull('lot_no')
|
|
->where('lot_no', '!=', '');
|
|
|
|
// 재질(item_name 또는 specification)으로 필터링
|
|
if ($material) {
|
|
$query->where(function ($q) use ($material) {
|
|
$q->where('item_name', 'LIKE', "%{$material}%")
|
|
->orWhere('specification', 'LIKE', "%{$material}%");
|
|
});
|
|
}
|
|
|
|
return $query->select([
|
|
'id',
|
|
'lot_no',
|
|
'supplier_lot',
|
|
'item_name',
|
|
'specification',
|
|
'receiving_qty',
|
|
'receiving_date',
|
|
'supplier',
|
|
'options',
|
|
])
|
|
->orderByDesc('receiving_date')
|
|
->limit(50)
|
|
->get();
|
|
}, __('message.fetched'));
|
|
}
|
|
|
|
/**
|
|
* LOT 번호 생성 (프리뷰 + 일련번호 확정)
|
|
*/
|
|
public function generateLotNumber(Request $request): JsonResponse
|
|
{
|
|
return ApiResponse::handle(function () use ($request) {
|
|
$prodCode = $request->input('prod_code');
|
|
$specCode = $request->input('spec_code');
|
|
$lengthCode = $request->input('length_code');
|
|
$regDate = $request->input('reg_date', now()->toDateString());
|
|
|
|
if (! $prodCode || ! $specCode || ! $lengthCode) {
|
|
return ['error' => 'MISSING_PARAMS', 'code' => 400, 'message' => 'prod_code, spec_code, length_code가 필요합니다.'];
|
|
}
|
|
|
|
$dateCode = BendingCodeService::generateDateCode($regDate);
|
|
$lotBase = "{$prodCode}{$specCode}{$dateCode}-{$lengthCode}";
|
|
$lotNumber = $this->service->generateLotNumber($lotBase);
|
|
$material = BendingCodeService::getMaterial($prodCode, $specCode);
|
|
|
|
return [
|
|
'lot_base' => $lotBase,
|
|
'lot_number' => $lotNumber,
|
|
'date_code' => $dateCode,
|
|
'material' => $material,
|
|
];
|
|
}, __('message.fetched'));
|
|
}
|
|
}
|