55 lines
2.0 KiB
PHP
55 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace Modules\ShopFloor\Http\Controllers;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Http\Request;
|
|
use Modules\IndustrialEngineering\Models\Bom;
|
|
use Modules\IndustrialEngineering\Models\LineRevision;
|
|
use Modules\ShopFloor\Models\WorkInstruction;
|
|
|
|
class WorkInstructionController extends Controller
|
|
{
|
|
public function index(Request $request)
|
|
{
|
|
if (! auth()->user()->can('shopfloor.instructions.view')) {
|
|
abort(403);
|
|
}
|
|
|
|
$business_id = $request->session()->get('user.business_id');
|
|
$instructions = WorkInstruction::forBusiness($business_id)
|
|
->with(['bom', 'lineRevision'])
|
|
->latest('id')
|
|
->paginate(20);
|
|
|
|
$boms = Bom::where('business_id', $business_id)->orderByDesc('id')->limit(100)->pluck('bom_code', 'id');
|
|
$lineRevisions = LineRevision::where('business_id', $business_id)->orderByDesc('id')->limit(100)->pluck('revision_code', 'id');
|
|
|
|
return view('shopfloor::work_instructions.index', compact('instructions', 'boms', 'lineRevisions'));
|
|
}
|
|
|
|
public function store(Request $request)
|
|
{
|
|
if (! auth()->user()->can('shopfloor.instructions.view')) {
|
|
abort(403);
|
|
}
|
|
|
|
$business_id = $request->session()->get('user.business_id');
|
|
$validated = $request->validate([
|
|
'title' => 'required|string|max:255',
|
|
'content' => 'nullable|string',
|
|
'ie_bom_id' => 'nullable|integer|exists:ie_boms,id',
|
|
'ie_line_revision_id' => 'nullable|integer|exists:ie_line_revisions,id',
|
|
'version' => 'nullable|string|max:20',
|
|
'status' => 'required|in:draft,active,obsolete',
|
|
]);
|
|
|
|
WorkInstruction::create(array_merge($validated, [
|
|
'business_id' => $business_id,
|
|
'version' => $validated['version'] ?? '1.0',
|
|
]));
|
|
|
|
return redirect()->action([self::class, 'index'])->with('status', ['success' => 1, 'msg' => __('shopfloor::lang.instruction_created')]);
|
|
}
|
|
}
|