ultimatepos/database/seeders/ToiletPaperSampleSeeder.php

131 lines
6.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace Database\Seeders;
use App\Business;
use Illuminate\Database\Seeder;
use Modules\IndustrialEngineering\Models\ProductPlatform;
use Modules\IndustrialEngineering\Services\ProductDefinitionService;
class ToiletPaperSampleSeeder extends Seeder
{
public function run(): void
{
$business = Business::query()->first();
if (! $business) {
$this->command?->warn('No business found — skipping toilet paper sample seeder.');
return;
}
if (ProductPlatform::withTrashed()->where('business_id', $business->id)->where('platform_code', 'TP-001')->exists()) {
$this->command?->info('Toilet paper sample already exists.');
return;
}
/** @var ProductDefinitionService $svc */
$svc = app(ProductDefinitionService::class);
$product = $svc->createProduct($business->id, [
'platform_code' => 'TP-001',
'name' => 'دستمال کاغذی',
'description' => 'محصول نهایی دستمال کاغذی — نمونه داده PLM با دو خط تولید کامل',
'industry_segment' => 'بهداشت و مصرفی',
]);
$line1 = $svc->addProductionLine($product, [
'template_code' => 'LINE-TISSUE',
'name' => 'خط تولید تیشو',
'description' => 'خط اصلی تولید رول تیشو از خمیر تا رول نیمه‌کار',
]);
$line2 = $svc->addProductionLine($product, [
'template_code' => 'LINE-PACK',
'name' => 'خط بسته‌بندی تیشو',
'description' => 'خط بسته‌بندی، برش نهایی و بسته‌بندی دستمال کاغذی',
]);
$rev1 = $line1->revisions()->first();
$rev2 = $line2->revisions()->first();
$this->seedLine1($svc, $rev1);
$this->seedLine2($svc, $rev2);
$this->command?->info('Toilet paper PLM sample seeded for business #'.$business->id);
}
protected function seedLine1(ProductDefinitionService $svc, $revision): void
{
$machines = [
['name' => 'فول کات اتومات', 'item_code' => 'MCH-FULLCUT', 'position_code' => 'M01', 'parts' => [
['name' => 'تیغ برش استیل', 'item_type' => 'part', 'quantity' => 4],
['name' => 'موتور اصلی برش', 'item_type' => 'part', 'quantity' => 1],
['name' => 'سنسور طول برش', 'item_type' => 'part', 'quantity' => 2],
['name' => 'غلتک کششی', 'item_type' => 'part', 'quantity' => 6],
['name' => 'پنل کنترل PLC', 'item_type' => 'subassembly', 'quantity' => 1],
]],
['name' => 'لاکسا', 'item_code' => 'MCH-LAKSA', 'position_code' => 'M02', 'parts' => [
['name' => 'غلتک لاکسا اصلی', 'item_type' => 'part', 'quantity' => 2],
['name' => 'سیستم بخار', 'item_type' => 'subassembly', 'quantity' => 1],
['name' => 'شیر بخار ایمنی', 'item_type' => 'part', 'quantity' => 3],
['name' => 'ترموستات دما', 'item_type' => 'part', 'quantity' => 2],
]],
['name' => 'بسته‌بند', 'item_code' => 'MCH-PACKER', 'position_code' => 'M03', 'parts' => [
['name' => 'هدر بسته‌بندی', 'item_type' => 'part', 'quantity' => 1],
['name' => 'نوار نقاله', 'item_type' => 'part', 'quantity' => 2],
['name' => 'سیلندر پرس', 'item_type' => 'part', 'quantity' => 2],
['name' => 'سنسور شمارش', 'item_type' => 'part', 'quantity' => 1],
]],
];
foreach ($machines as $machine) {
$parts = $machine['parts'];
unset($machine['parts']);
$bomLine = $svc->addMachine($revision, $machine, $machine['item_code']);
foreach ($parts as $part) {
$svc->addPart($bomLine, $part, (float) $part['quantity']);
}
}
}
protected function seedLine2(ProductDefinitionService $svc, $revision): void
{
$machines = [
['name' => 'پمپ هوا', 'item_code' => 'MCH-AIRPUMP', 'position_code' => 'P01', 'parts' => [
['name' => 'الکتروموتور ۵.۵ کیلووات', 'item_type' => 'part', 'quantity' => 1],
['name' => 'پروانه پمپ', 'item_type' => 'part', 'quantity' => 1],
['name' => 'فیلتر هوا', 'item_type' => 'consumable', 'quantity' => 2],
['name' => 'شیر یکطرفه', 'item_type' => 'part', 'quantity' => 2],
]],
['name' => 'مکنده صنعتی', 'item_code' => 'MCH-VACUUM', 'position_code' => 'P02', 'parts' => [
['name' => 'موتور مکنده', 'item_type' => 'part', 'quantity' => 1],
['name' => 'کیسه فیلتر', 'item_type' => 'consumable', 'quantity' => 4],
['name' => 'شیلنگ مکش', 'item_type' => 'part', 'quantity' => 3],
['name' => 'فشارسنج', 'item_type' => 'part', 'quantity' => 1],
]],
['name' => 'برش و تا کن نهایی', 'item_code' => 'MCH-FOLD', 'position_code' => 'P03', 'parts' => [
['name' => 'تیغ برش نهایی', 'item_type' => 'part', 'quantity' => 2],
['name' => 'غلتک تا کن', 'item_type' => 'part', 'quantity' => 4],
['name' => 'سنسور تعداد لایه', 'item_type' => 'part', 'quantity' => 1],
['name' => 'نوار نقاله خروجی', 'item_type' => 'part', 'quantity' => 1],
]],
['name' => 'بسته‌بند نهایی شفاف', 'item_code' => 'MCH-SHRINK', 'position_code' => 'P04', 'parts' => [
['name' => 'تونل شیرینگ', 'item_type' => 'device', 'quantity' => 1],
['name' => 'هیتر تونل', 'item_type' => 'part', 'quantity' => 4],
['name' => 'فن خنک‌کن', 'item_type' => 'part', 'quantity' => 2],
['name' => 'برچسب‌زن', 'item_type' => 'subassembly', 'quantity' => 1],
]],
];
foreach ($machines as $machine) {
$parts = $machine['parts'];
unset($machine['parts']);
$bomLine = $svc->addMachine($revision, $machine, $machine['item_code']);
foreach ($parts as $part) {
$svc->addPart($bomLine, $part, (float) $part['quantity']);
}
}
}
}