152 lines
5.7 KiB
PHP
152 lines
5.7 KiB
PHP
<?php
|
|
|
|
namespace Modules\IndustrialEngineering\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Routing\Controller;
|
|
use Modules\IndustrialEngineering\Http\Controllers\Concerns\AuthorizesIndustrialEngineering;
|
|
use Modules\IndustrialEngineering\Http\Controllers\Concerns\ResolvesIeCodes;
|
|
use Modules\IndustrialEngineering\Models\BomLine;
|
|
use Modules\IndustrialEngineering\Models\LineRevision;
|
|
use Modules\IndustrialEngineering\Models\ProductPlatform;
|
|
use Modules\IndustrialEngineering\Services\ProductDefinitionService;
|
|
use Yajra\DataTables\Facades\DataTables;
|
|
|
|
class ProductHubController extends Controller
|
|
{
|
|
use AuthorizesIndustrialEngineering;
|
|
use ResolvesIeCodes;
|
|
|
|
public function __construct(protected ProductDefinitionService $productDefinition)
|
|
{
|
|
}
|
|
|
|
public function index(Request $request)
|
|
{
|
|
$this->authorizeIe('ie.platforms.view');
|
|
$businessId = $this->businessId();
|
|
|
|
if ($request->ajax()) {
|
|
return DataTables::of(ProductPlatform::forBusiness($businessId))
|
|
->addColumn('auto_code', fn ($row) => $row->auto_code ?? '—')
|
|
->addColumn('lines_count', fn ($row) => $row->lineTemplates()->whereNull('parent_template_id')->count())
|
|
->addColumn('action', fn ($row) => '<a href="'.action([self::class, 'show'], $row->id).'" class="btn btn-xs btn-primary"><i class="fa fa-sitemap"></i> '.e(__('industrialengineering::lang.manage')).'</a>')
|
|
->rawColumns(['action'])
|
|
->make(true);
|
|
}
|
|
|
|
return view('industrialengineering::product_hub.index');
|
|
}
|
|
|
|
public function create()
|
|
{
|
|
$this->authorizeIe('ie.platforms.create');
|
|
|
|
return view('industrialengineering::product_hub.create', [
|
|
'suggestedCode' => $this->suggestCode('product'),
|
|
]);
|
|
}
|
|
|
|
public function store(Request $request)
|
|
{
|
|
$this->authorizeIe('ie.platforms.create');
|
|
$data = $request->validate([
|
|
'platform_code' => 'nullable|string|max:100',
|
|
'name' => 'required|string|max:255',
|
|
'description' => 'nullable|string',
|
|
'industry_segment' => 'nullable|string|max:100',
|
|
]);
|
|
|
|
$platform = $this->productDefinition->createProduct($this->businessId(), $data);
|
|
|
|
return redirect()->action([self::class, 'show'], $platform->id)
|
|
->with('status', ['success' => true, 'msg' => __('industrialengineering::lang.product_created')]);
|
|
}
|
|
|
|
public function show($id)
|
|
{
|
|
$this->authorizeIe('ie.platforms.view');
|
|
$platform = ProductPlatform::forBusiness($this->businessId())->findOrFail($id);
|
|
$structure = $this->productDefinition->loadProductStructure($platform);
|
|
|
|
return view('industrialengineering::product_hub.show', [
|
|
'platform' => $platform,
|
|
'structure' => $structure,
|
|
'suggestedLineCode' => $this->suggestCode('line'),
|
|
'itemTypes' => $this->itemTypes(),
|
|
]);
|
|
}
|
|
|
|
public function storeLine(Request $request, $id)
|
|
{
|
|
$this->authorizeIe('ie.platforms.create');
|
|
$platform = ProductPlatform::forBusiness($this->businessId())->findOrFail($id);
|
|
|
|
$data = $request->validate([
|
|
'template_code' => 'nullable|string|max:100',
|
|
'name' => 'required|string|max:255',
|
|
'description' => 'nullable|string',
|
|
]);
|
|
|
|
$result = $this->productDefinition->addProductionLine($platform, $data);
|
|
|
|
return back()
|
|
->with('status', ['success' => true, 'msg' => __('industrialengineering::lang.line_added')])
|
|
->with('integration_messages', $result['integration_messages'] ?? []);
|
|
}
|
|
|
|
public function storeMachine(Request $request, $platformId, $revisionId)
|
|
{
|
|
$this->authorizeIe('ie.bom.create');
|
|
$revision = LineRevision::forBusiness($this->businessId())->findOrFail($revisionId);
|
|
|
|
$data = $request->validate([
|
|
'item_code' => 'nullable|string|max:100',
|
|
'name' => 'required|string|max:255',
|
|
'description' => 'nullable|string',
|
|
'position_code' => 'nullable|string|max:100',
|
|
'standard_cost' => 'nullable|numeric|min:0',
|
|
]);
|
|
|
|
$this->productDefinition->addMachine($revision, $data, $data['item_code'] ?? null);
|
|
|
|
return back()->with('status', ['success' => true, 'msg' => __('industrialengineering::lang.machine_added')]);
|
|
}
|
|
|
|
public function storePart(Request $request, $platformId, $parentLineId)
|
|
{
|
|
$this->authorizeIe('ie.bom.create');
|
|
$parentLine = BomLine::forBusiness($this->businessId())->findOrFail($parentLineId);
|
|
|
|
$data = $request->validate([
|
|
'item_code' => 'nullable|string|max:100',
|
|
'name' => 'required|string|max:255',
|
|
'item_type' => 'nullable|string',
|
|
'quantity' => 'required|numeric|min:0.0001',
|
|
'position_code' => 'nullable|string|max:100',
|
|
'standard_cost' => 'nullable|numeric|min:0',
|
|
'is_serviceable' => 'nullable|boolean',
|
|
]);
|
|
|
|
$this->productDefinition->addPart(
|
|
$parentLine,
|
|
$data,
|
|
(float) $data['quantity'],
|
|
$data['item_code'] ?? null
|
|
);
|
|
|
|
return back()->with('status', ['success' => true, 'msg' => __('industrialengineering::lang.part_added')]);
|
|
}
|
|
|
|
protected function itemTypes(): array
|
|
{
|
|
return [
|
|
'part' => __('industrialengineering::lang.type_part'),
|
|
'subassembly' => __('industrialengineering::lang.type_subassembly'),
|
|
'device' => __('industrialengineering::lang.type_device'),
|
|
'tool' => __('industrialengineering::lang.type_tool'),
|
|
'consumable' => __('industrialengineering::lang.type_consumable'),
|
|
];
|
|
}
|
|
}
|