first(); if (! $platform) { $this->command?->warn('Run ToiletPaperSampleSeeder first.'); return; } $packLine = LineTemplate::where('template_code', 'LINE-PACK')->where('product_platform_id', $platform->id)->first(); if (! $packLine) { return; } $revision = $packLine->revisions()->latest('id')->first(); $mbom = $revision?->boms()->where('bom_type', 'mbom')->first(); if (! $mbom) { return; } /** @var BomTreeService $tree */ $tree = app(BomTreeService::class); if ($mbom->lines()->whereHas('itemMaster', fn ($q) => $q->where('item_code', 'ASM-AIR'))->exists()) { $this->command?->info('Nested air assembly already exists.'); return; } $airSection = $tree->addNode($mbom, null, [ 'item_code' => 'ASM-AIR', 'name' => 'قسمت باد (مجموعه)', 'item_type' => 'assembly', 'position_code' => 'P-AIR', 'quantity' => 1, ]); $pump = $tree->addNode($mbom, $airSection->id, [ 'item_code' => 'SUB-PUMP', 'name' => 'پمپ هوا (زیرمجموعه)', 'item_type' => 'subassembly', 'position_code' => 'P-AIR-01', 'quantity' => 1, ]); $tree->addNode($mbom, $airSection->id, [ 'item_code' => 'SUB-DRYER', 'name' => 'خشک‌کن (درایر)', 'item_type' => 'subassembly', 'position_code' => 'P-AIR-02', 'quantity' => 1, ]); $tree->addNode($mbom, $airSection->id, [ 'item_code' => 'SUB-TANK', 'name' => 'مخزن هوا', 'item_type' => 'subassembly', 'position_code' => 'P-AIR-03', 'quantity' => 1, ]); foreach ([ ['MOT-5KW', 'الکتروموتور ۵.۵ کیلووات', 'part'], ['MOT-BENZ', 'موتور بنزینی کمکی', 'part'], ['SNS-PRESS', 'سنسور فشار (درجه‌سنج)', 'part'], ['VLV-CHECK', 'شیر یکطرفه', 'part'], ] as [$code, $name, $type]) { $tree->addNode($mbom, $pump->id, [ 'item_code' => $code, 'name' => $name, 'item_type' => $type, 'quantity' => 1, ]); } $this->command?->info('Nested air assembly structure added to LINE-PACK.'); } }