133 lines
5.4 KiB
PHP
133 lines
5.4 KiB
PHP
<?php
|
|
|
|
namespace Modules\IndustrialEngineering\Http\Controllers;
|
|
|
|
use App\BusinessLocation;
|
|
use App\Contact;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Routing\Controller;
|
|
use Modules\IndustrialEngineering\Http\Controllers\Concerns\AuthorizesIndustrialEngineering;
|
|
use Modules\IndustrialEngineering\Models\Bom;
|
|
use Modules\IndustrialEngineering\Models\BomLine;
|
|
use Modules\IndustrialEngineering\Models\ItemMaster;
|
|
use Modules\IndustrialEngineering\Models\LineTemplate;
|
|
use Modules\IndustrialEngineering\Services\BomTemplateService;
|
|
use Modules\IndustrialEngineering\Services\BomTreeService;
|
|
use Modules\IndustrialEngineering\Services\LiveBomCostingService;
|
|
use Modules\IndustrialEngineering\Services\AutoIntegrationService;
|
|
use Modules\IndustrialEngineering\Services\ConnectionGateService;
|
|
use Modules\IndustrialEngineering\Support\CmmsAvailability;
|
|
use Yajra\DataTables\Facades\DataTables;
|
|
|
|
class ProductionLineController extends Controller
|
|
{
|
|
use AuthorizesIndustrialEngineering;
|
|
|
|
public function __construct(
|
|
protected BomTreeService $bomTreeService,
|
|
protected BomTemplateService $bomTemplateService,
|
|
protected LiveBomCostingService $liveCosting,
|
|
protected AutoIntegrationService $autoIntegration,
|
|
protected ConnectionGateService $connectionGate
|
|
) {
|
|
}
|
|
|
|
protected function authorizeProductionLine(): void
|
|
{
|
|
$user = auth()->user();
|
|
if ($user->can('ie.access') || $user->can('ie.view')
|
|
|| $user->can('ie.revisions.view') || $user->can('ie.bom.view')
|
|
|| $user->can('ie.platforms.view')) {
|
|
return;
|
|
}
|
|
abort(403, 'Unauthorized action.');
|
|
}
|
|
|
|
public function index(Request $request)
|
|
{
|
|
$this->authorizeProductionLine();
|
|
$businessId = $this->businessId();
|
|
|
|
if ($request->ajax()) {
|
|
$query = LineTemplate::forBusiness($businessId)
|
|
->productionLines()
|
|
->with(['productPlatform', 'revisions'])
|
|
->orderBy('sort_order');
|
|
|
|
return DataTables::of($query)
|
|
->addColumn('product_name', fn ($row) => $row->productPlatform?->name ?? '—')
|
|
->addColumn('revision_code', fn ($row) => $row->revisions->sortByDesc('id')->first()?->revision_code ?? '—')
|
|
->addColumn('status', fn ($row) => $row->revisions->sortByDesc('id')->first()?->status ?? '—')
|
|
->addColumn('action', function ($row) {
|
|
return '<a href="'.action([self::class, 'structure'], $row->id).'" class="btn btn-xs btn-primary"><i class="fa fa-sitemap"></i> '.e(__('industrialengineering::lang.edit_structure')).'</a>';
|
|
})
|
|
->rawColumns(['action'])
|
|
->make(true);
|
|
}
|
|
|
|
return view('industrialengineering::production_lines.index');
|
|
}
|
|
|
|
public function structure($id)
|
|
{
|
|
$this->authorizeProductionLine();
|
|
$with = ['productPlatform', 'revisions.boms'];
|
|
if (CmmsAvailability::isReady()) {
|
|
$with[] = 'maintenanceEquipment';
|
|
}
|
|
|
|
$line = LineTemplate::forBusiness($this->businessId())
|
|
->productionLines()
|
|
->with($with)
|
|
->findOrFail($id);
|
|
|
|
$ensured = $this->autoIntegration->ensureLineMbom($line);
|
|
$revision = $ensured['revision'];
|
|
$mbom = $ensured['mbom'];
|
|
$line->refresh();
|
|
|
|
$tree = $this->bomTreeService->buildEditorTree($mbom);
|
|
$liveAnalysis = $this->liveCosting->analyze($mbom, 1);
|
|
$liveComparison = $this->liveCosting->compareStandardVsLive($mbom, 1);
|
|
$connectionGate = $this->connectionGate->assessBom($mbom, 1);
|
|
|
|
$businessId = $this->businessId();
|
|
$flashMessages = [];
|
|
if ($ensured['created']) {
|
|
$flashMessages[] = ['type' => 'info', 'text' => __('industrialengineering::lang.auto_mbom_created_on_open')];
|
|
}
|
|
if (! CmmsAvailability::isReady()) {
|
|
$flashMessages[] = ['type' => 'warning', 'text' => __('industrialengineering::lang.cmms_not_installed')];
|
|
}
|
|
|
|
return view('industrialengineering::production_lines.structure', [
|
|
'line' => $line,
|
|
'revision' => $revision,
|
|
'mbom' => $mbom,
|
|
'tree' => $tree,
|
|
'liveAnalysis' => $liveAnalysis,
|
|
'liveComparison' => $liveComparison,
|
|
'connectionGate' => $connectionGate,
|
|
'integrationMessages' => $flashMessages,
|
|
'cmmsAvailable' => CmmsAvailability::isReady(),
|
|
'locations' => BusinessLocation::forDropdown($businessId, true),
|
|
'suppliers' => Contact::suppliersDropdown($businessId, false),
|
|
'itemTypes' => $this->itemTypes(),
|
|
'existingItems' => ItemMaster::forBusiness($businessId)->orderBy('name')->pluck('name', 'id'),
|
|
'structureTemplates' => $this->bomTemplateService->listForBusiness($businessId),
|
|
]);
|
|
}
|
|
|
|
protected function itemTypes(): array
|
|
{
|
|
return [
|
|
'assembly' => __('industrialengineering::lang.type_assembly'),
|
|
'subassembly' => __('industrialengineering::lang.type_subassembly'),
|
|
'device' => __('industrialengineering::lang.type_device'),
|
|
'part' => __('industrialengineering::lang.type_part'),
|
|
'tool' => __('industrialengineering::lang.type_tool'),
|
|
'consumable' => __('industrialengineering::lang.type_consumable'),
|
|
];
|
|
}
|
|
}
|