feat: [pmis] 자재관리 CRUD 구현
- 자재등록 탭: 등록/수정/삭제, 페이지네이션, 검색, 필터 - 입고현황 탭: 자재 목록 기반 입고 현황 조회 - 기준자재정보 모달: 30종 건설자재 선택 등록 - 번개 아이콘 랜덤 데이터 등록 기능
This commit is contained in:
87
app/Http/Controllers/Juil/PmisMaterialController.php
Normal file
87
app/Http/Controllers/Juil/PmisMaterialController.php
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Juil;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Juil\PmisMaterial;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class PmisMaterialController extends Controller
|
||||
{
|
||||
private function tenantId(): int
|
||||
{
|
||||
return (int) session('current_tenant_id', 1);
|
||||
}
|
||||
|
||||
public function list(Request $request): JsonResponse
|
||||
{
|
||||
$query = PmisMaterial::tenant($this->tenantId())
|
||||
->orderByDesc('id');
|
||||
|
||||
if ($request->filled('company')) {
|
||||
$query->where('company_name', 'like', '%' . $request->company . '%');
|
||||
}
|
||||
if ($request->filled('material_name')) {
|
||||
$query->where('material_name', 'like', '%' . $request->material_name . '%');
|
||||
}
|
||||
if ($request->filled('search')) {
|
||||
$s = $request->search;
|
||||
$query->where(function ($q) use ($s) {
|
||||
$q->where('material_name', 'like', "%{$s}%")
|
||||
->orWhere('material_code', 'like', "%{$s}%")
|
||||
->orWhere('specification', 'like', "%{$s}%");
|
||||
});
|
||||
}
|
||||
|
||||
$perPage = $request->integer('per_page', 15);
|
||||
$materials = $query->paginate($perPage);
|
||||
|
||||
return response()->json($materials);
|
||||
}
|
||||
|
||||
public function store(Request $request): JsonResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'company_name' => 'required|string|max:200',
|
||||
'material_code' => 'nullable|string|max:50',
|
||||
'material_name' => 'required|string|max:200',
|
||||
'specification' => 'nullable|string|max:300',
|
||||
'unit' => 'nullable|string|max:50',
|
||||
'design_quantity' => 'nullable|numeric|min:0',
|
||||
]);
|
||||
|
||||
$validated['tenant_id'] = $this->tenantId();
|
||||
$validated['design_quantity'] = $validated['design_quantity'] ?? 0;
|
||||
|
||||
$material = PmisMaterial::create($validated);
|
||||
|
||||
return response()->json($material, 201);
|
||||
}
|
||||
|
||||
public function update(Request $request, int $id): JsonResponse
|
||||
{
|
||||
$material = PmisMaterial::tenant($this->tenantId())->findOrFail($id);
|
||||
|
||||
$validated = $request->validate([
|
||||
'company_name' => 'sometimes|required|string|max:200',
|
||||
'material_code' => 'nullable|string|max:50',
|
||||
'material_name' => 'sometimes|required|string|max:200',
|
||||
'specification' => 'nullable|string|max:300',
|
||||
'unit' => 'nullable|string|max:50',
|
||||
'design_quantity' => 'nullable|numeric|min:0',
|
||||
]);
|
||||
|
||||
$material->update($validated);
|
||||
|
||||
return response()->json($material);
|
||||
}
|
||||
|
||||
public function destroy(int $id): JsonResponse
|
||||
{
|
||||
$material = PmisMaterial::tenant($this->tenantId())->findOrFail($id);
|
||||
$material->delete();
|
||||
|
||||
return response()->json(['message' => '삭제되었습니다.']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user