93 lines
3.0 KiB
PHP
93 lines
3.0 KiB
PHP
<?php
|
||
|
||
namespace Database\Seeders;
|
||
|
||
use Illuminate\Database\Seeder;
|
||
use Modules\IndustrialEngineering\Models\LineTemplate;
|
||
use Modules\IndustrialEngineering\Models\ProductPlatform;
|
||
use Modules\IndustrialEngineering\Services\BomTreeService;
|
||
|
||
/**
|
||
* Enriches toilet paper sample with deep nested assembly (e.g. air section → pump → motor).
|
||
*/
|
||
class ToiletPaperNestedStructureSeeder extends Seeder
|
||
{
|
||
public function run(): void
|
||
{
|
||
$platform = ProductPlatform::where('platform_code', 'TP-001')->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.');
|
||
}
|
||
}
|