73 lines
2.2 KiB
PHP
73 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace Modules\QualityManagement\Http\Controllers\Portal;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Modules\Portal\Http\Controllers\BasePortalController;
|
|
use Modules\QualityManagement\Models\NcrReport;
|
|
use Modules\QualityManagement\Services\NcrWorkflowService;
|
|
use Modules\QualityManagement\Services\QmsIntegrationService;
|
|
|
|
class NcrController extends BasePortalController
|
|
{
|
|
public function index()
|
|
{
|
|
$this->ensurePortalAccess();
|
|
$contactId = $this->contactId();
|
|
$businessId = $this->businessId();
|
|
|
|
$ncrs = NcrReport::forBusiness($businessId)
|
|
->where(function ($q) use ($contactId) {
|
|
$q->where('contact_id', $contactId)
|
|
->orWhere('source', 'customer');
|
|
})
|
|
->latest('id')
|
|
->paginate(20);
|
|
|
|
return view('qualitymanagement::portal.ncr.index', compact('ncrs'));
|
|
}
|
|
|
|
public function create()
|
|
{
|
|
$this->ensurePortalAccess();
|
|
|
|
return view('qualitymanagement::portal.ncr.create');
|
|
}
|
|
|
|
public function store(Request $request, NcrWorkflowService $workflow, QmsIntegrationService $integration)
|
|
{
|
|
$this->ensurePortalAccess();
|
|
|
|
$validated = $request->validate([
|
|
'title' => 'required|string|max:255',
|
|
'description' => 'nullable|string',
|
|
'severity' => 'required|in:minor,major,critical',
|
|
]);
|
|
|
|
$workflow->createNcr($this->businessId(), array_merge($validated, [
|
|
'source' => 'customer',
|
|
'contact_id' => $this->contactId(),
|
|
'status' => 'open',
|
|
]), $integration);
|
|
|
|
return redirect()->action([self::class, 'index'])
|
|
->with('status', ['success' => 1, 'msg' => __('qualitymanagement::lang.ncr_created')]);
|
|
}
|
|
|
|
public function show($id)
|
|
{
|
|
$this->ensurePortalAccess();
|
|
$contactId = $this->contactId();
|
|
|
|
$ncr = NcrReport::forBusiness($this->businessId())
|
|
->where(function ($q) use ($contactId) {
|
|
$q->where('contact_id', $contactId)
|
|
->orWhere('source', 'customer');
|
|
})
|
|
->with('capaActions')
|
|
->findOrFail($id);
|
|
|
|
return view('qualitymanagement::portal.ncr.show', compact('ncr'));
|
|
}
|
|
}
|