gruene-seele/database/seeders/InventoryStammdatenTestSeeder.php

315 lines
11 KiB
PHP
Raw Permalink 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\Models\Country;
use App\Models\Ingredient;
use App\Models\Location;
use App\Models\PackagingItem;
use App\Models\PackagingMaterial;
use App\Models\StockEntry;
use App\Models\Supplier;
use App\Models\SupplierCategory;
use App\User;
use Illuminate\Database\Seeder;
/**
* Befüllt Stammdaten der Warenwirtschaft mit erkennbaren Demo-/Testinhalten.
* Ruft zuerst {@see InventoryStammdatenSeeder} auf (Lagerorte, Qualitäten, Verpackungsmaterialien).
*
* Aufruf: php artisan db:seed --class=InventoryStammdatenTestSeeder
*/
class InventoryStammdatenTestSeeder extends Seeder
{
public function run(): void
{
$this->call(InventoryStammdatenSeeder::class);
$countryDe = Country::query()->firstOrCreate(
['code' => 'DE'],
[
'phone' => '49',
'en' => 'Germany',
'de' => 'Deutschland',
'es' => 'Alemania',
'fr' => 'Allemagne',
'it' => 'Germania',
'ru' => 'Германия',
'active' => true,
]
);
$locationExtra = Location::query()->firstOrCreate(
['name' => 'Demo Test-Zentrallager'],
['active' => true]
);
$catRohstoffe = SupplierCategory::query()->firstOrCreate(
['name' => 'Demo Rohstoffe'],
['pos' => 1]
);
$catVerpackung = SupplierCategory::query()->firstOrCreate(
['name' => 'Demo Verpackung & Zubehör'],
['pos' => 2]
);
$catDienst = SupplierCategory::query()->firstOrCreate(
['name' => 'Demo Dienstleistung'],
['pos' => 3]
);
$supplierOele = Supplier::query()->firstOrCreate(
['name' => 'Demo-Lieferant Naturöle GmbH'],
[
'url' => 'https://demo-naturoele.example.test',
'contact_person' => 'Erika Beispiel',
'email' => 'einkauf@demo-naturoele.example.test',
'phone' => '+49 221 5550100',
'country_id' => $countryDe->id,
'notes' => 'Seeder-Testdaten Rohstoffe (Öle, Butter).',
'active' => true,
]
);
$supplierOele->supplierCategories()->sync([
$catRohstoffe->id,
$catVerpackung->id,
]);
$supplierGlas = Supplier::query()->firstOrCreate(
['name' => 'Demo Verpackung Glas & Co.'],
[
'url' => 'https://demo-glas.example.test',
'contact_person' => 'Tom Test',
'email' => 'vertrieb@demo-glas.example.test',
'phone' => '+49 211 5550200',
'country_id' => $countryDe->id,
'notes' => 'Seeder-Testdaten Flaschen und Gläser.',
'active' => true,
]
);
$supplierGlas->supplierCategories()->sync([
$catVerpackung->id,
]);
$supplierLogistik = Supplier::query()->firstOrCreate(
['name' => 'Demo Logistik Partner'],
[
'url' => null,
'contact_person' => 'Lisa Versand',
'email' => 'buero@demo-logistik.example.test',
'phone' => '+49 40 5550300',
'country_id' => $countryDe->id,
'notes' => 'Seeder-Testdaten Kartons, Versandmaterial.',
'active' => true,
]
);
$supplierLogistik->supplierCategories()->sync([
$catVerpackung->id,
$catDienst->id,
]);
$materialGlas = PackagingMaterial::query()->where('name', 'Glas')->first();
$materialKunststoff = PackagingMaterial::query()->where('name', 'Kunststoff')->first();
$materialPappe = PackagingMaterial::query()->where('name', 'Pappe/Papier')->first();
if ($materialGlas) {
PackagingItem::query()->firstOrCreate(
['name' => 'Demo Braunglasflasche 30 ml'],
[
'packaging_material_id' => $materialGlas->id,
'supplier_id' => $supplierGlas->id,
'category' => 'packaging',
'weight_grams' => 45.5,
'min_stock_alert' => 200,
'product_id' => null,
'active' => true,
]
);
PackagingItem::query()->firstOrCreate(
['name' => 'Demo Tropferflasche Klarglas 10 ml'],
[
'packaging_material_id' => $materialGlas->id,
'supplier_id' => $supplierGlas->id,
'category' => 'packaging',
'weight_grams' => 22,
'min_stock_alert' => 500,
'product_id' => null,
'active' => true,
]
);
}
if ($materialKunststoff) {
PackagingItem::query()->firstOrCreate(
['name' => 'Demo Pumpspender 150 ml (PET)'],
[
'packaging_material_id' => $materialKunststoff->id,
'supplier_id' => $supplierGlas->id,
'category' => 'packaging',
'weight_grams' => 28.75,
'min_stock_alert' => 150,
'product_id' => null,
'active' => true,
]
);
}
if ($materialPappe) {
PackagingItem::query()->firstOrCreate(
['name' => 'Demo Faltschachtel S (bedruckt)'],
[
'packaging_material_id' => $materialPappe->id,
'supplier_id' => $supplierLogistik->id,
'category' => 'packaging',
'weight_grams' => 12,
'min_stock_alert' => 1000,
'product_id' => null,
'active' => true,
]
);
PackagingItem::query()->firstOrCreate(
['name' => 'Demo Versandkarton S'],
[
'packaging_material_id' => $materialPappe->id,
'supplier_id' => $supplierLogistik->id,
'category' => 'shipping',
'weight_grams' => 95,
'min_stock_alert' => 300,
'product_id' => null,
'active' => true,
]
);
PackagingItem::query()->firstOrCreate(
['name' => 'Demo Etikett Front 50×80 mm'],
[
'packaging_material_id' => $materialPappe->id,
'supplier_id' => $supplierOele->id,
'category' => 'shipping',
'weight_grams' => 1.2,
'min_stock_alert' => 5000,
'product_id' => null,
'active' => true,
]
);
}
$locationKoln = Location::query()->where('name', 'Köln')->first() ?? $locationExtra;
$orderUser = User::query()->firstOrCreate(
['email' => 'demo-wareneingang@example.test'],
[
'password' => bcrypt('password'),
'admin' => 7,
'confirmed' => true,
'active' => true,
'wizard' => 100,
'blocked' => false,
]
);
$ingShea = Ingredient::query()->firstOrCreate(
['name' => 'Demo Wareneingang Shea Butter'],
[
'trans_name' => '',
'inci' => 'Butyrospermum Parkii Butter',
'trans_inci' => '',
'effect' => '',
'trans_effect' => '',
'active' => true,
'pos' => 0,
]
);
$ingMandel = Ingredient::query()->firstOrCreate(
['name' => 'Demo Wareneingang Mandelöl'],
[
'trans_name' => '',
'inci' => 'Prunus Amygdalus Dulcis Oil',
'trans_inci' => '',
'effect' => '',
'trans_effect' => '',
'active' => true,
'pos' => 0,
]
);
StockEntry::factory()->create([
'ingredient_id' => $ingShea->id,
'supplier_id' => $supplierOele->id,
'location_id' => $locationKoln->id,
'ordered_by' => $orderUser->id,
'ordered_at' => now()->subDays(5)->format('Y-m-d'),
'ordered_quantity' => 10000,
'price_per_kg' => 8.5,
'entry_type' => 'ingredient',
'unit' => 'gram',
'packaging_item_id' => null,
'status' => 'pending',
]);
StockEntry::factory()->create([
'ingredient_id' => $ingMandel->id,
'supplier_id' => $supplierOele->id,
'location_id' => $locationKoln->id,
'ordered_by' => $orderUser->id,
'ordered_at' => now()->subDays(12)->format('Y-m-d'),
'ordered_quantity' => 5000,
'price_per_kg' => 9.95,
'entry_type' => 'ingredient',
'unit' => 'gram',
'packaging_item_id' => null,
'status' => 'pending',
]);
$demoPackagingItem = PackagingItem::query()
->where('name', 'like', 'Demo %')
->where('category', 'packaging')
->first();
if ($demoPackagingItem !== null) {
StockEntry::query()->create([
'entry_type' => 'packaging',
'ingredient_id' => null,
'packaging_item_id' => $demoPackagingItem->id,
'supplier_id' => $supplierGlas->id,
'location_id' => $locationKoln->id,
'unit' => 'piece',
'ordered_by' => $orderUser->id,
'ordered_at' => now()->subDays(2)->format('Y-m-d'),
'ordered_quantity' => 480,
'price_per_kg' => null,
'price_total' => 612.0,
'received_by' => null,
'received_at' => null,
'received_quantity' => null,
'batch_number' => null,
'best_before' => null,
'quality_id' => null,
'status' => 'pending',
]);
}
StockEntry::factory()->received()->create([
'ingredient_id' => $ingMandel->id,
'supplier_id' => $supplierOele->id,
'location_id' => $locationKoln->id,
'ordered_by' => $orderUser->id,
'ordered_at' => now()->subMonths(2)->format('Y-m-d'),
'ordered_quantity' => 3000,
'price_per_kg' => 9.5,
'entry_type' => 'ingredient',
'unit' => 'gram',
'packaging_item_id' => null,
]);
$this->command?->info(sprintf(
'Inventory-Stammdaten-Test: DE (countries.id=%d), Lagerort „%s“ (id=%d), Lieferanten-IDs %d / %d / %d; Verpackungsartikel mit Präfix „Demo …“; Demo-Wareneingänge (stock_entries) mit User %s.',
$countryDe->id,
$locationExtra->name,
$locationExtra->id,
$supplierOele->id,
$supplierGlas->id,
$supplierLogistik->id,
$orderUser->email
));
}
}