83 lines
2.8 KiB
PHP
83 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace Modules\IndustrialEngineering\Http\Controllers\Portal;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Modules\IndustrialEngineering\Models\CpqConfiguration;
|
|
use Modules\IndustrialEngineering\Models\ProductPlatform;
|
|
use Modules\IndustrialEngineering\Services\CpqService;
|
|
use Modules\Portal\Http\Controllers\BasePortalController;
|
|
|
|
class CpqController extends BasePortalController
|
|
{
|
|
public function index()
|
|
{
|
|
$this->ensurePortalAccess();
|
|
$contactId = $this->contactId();
|
|
|
|
$configurations = CpqConfiguration::forBusiness($this->businessId())
|
|
->where('contact_id', $contactId)
|
|
->with('productPlatform')
|
|
->latest('id')
|
|
->paginate(20);
|
|
|
|
return view('industrialengineering::portal.cpq.index', compact('configurations'));
|
|
}
|
|
|
|
public function create(CpqService $cpq)
|
|
{
|
|
$this->ensurePortalAccess();
|
|
|
|
$platforms = ProductPlatform::where('business_id', $this->businessId())
|
|
->where('status', 'active')
|
|
->orderBy('name')
|
|
->get()
|
|
->filter(fn ($p) => ! empty($cpq->getConfigurator($this->businessId(), $p->id)['groups']));
|
|
|
|
return view('industrialengineering::portal.cpq.create', compact('platforms'));
|
|
}
|
|
|
|
public function configure($platformId, CpqService $cpq)
|
|
{
|
|
$this->ensurePortalAccess();
|
|
|
|
$platform = ProductPlatform::where('business_id', $this->businessId())->findOrFail($platformId);
|
|
$configurator = $cpq->getConfigurator($this->businessId(), (int) $platformId);
|
|
|
|
return view('industrialengineering::portal.cpq.configure', compact('platform', 'configurator'));
|
|
}
|
|
|
|
public function store(Request $request, CpqService $cpq)
|
|
{
|
|
$this->ensurePortalAccess();
|
|
|
|
$validated = $request->validate([
|
|
'product_platform_id' => 'required|integer',
|
|
'name' => 'required|string|max:255',
|
|
'selected_options' => 'nullable|array',
|
|
]);
|
|
|
|
$selected = $cpq->applyRules($validated['selected_options'] ?? [], $this->businessId());
|
|
|
|
$cpq->buildConfiguration($this->businessId(), array_merge($validated, [
|
|
'contact_id' => $this->contactId(),
|
|
'selected_options' => $selected,
|
|
]));
|
|
|
|
return redirect()->action([self::class, 'index'])
|
|
->with('status', ['success' => 1, 'msg' => __('industrialengineering::lang.cpq_created')]);
|
|
}
|
|
|
|
public function show($id)
|
|
{
|
|
$this->ensurePortalAccess();
|
|
|
|
$configuration = CpqConfiguration::forBusiness($this->businessId())
|
|
->where('contact_id', $this->contactId())
|
|
->with('productPlatform')
|
|
->findOrFail($id);
|
|
|
|
return view('industrialengineering::portal.cpq.show', compact('configuration'));
|
|
}
|
|
}
|