Seeder for test
This commit is contained in:
parent
ae7574045e
commit
67b15ab337
43
thanasoft-back/database/seeders/ContactSeeder.php
Normal file
43
thanasoft-back/database/seeders/ContactSeeder.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Client;
|
||||
use App\Models\Contact;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class ContactSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
Client::query()->orderBy('id')->get()->each(function (Client $client, int $index): void {
|
||||
Contact::updateOrCreate(
|
||||
[
|
||||
'client_id' => $client->id,
|
||||
'email' => sprintf('contact.%d@clients.thanasoft.test', $client->id),
|
||||
],
|
||||
[
|
||||
'first_name' => 'Contact',
|
||||
'last_name' => sprintf('Client %d', $client->id),
|
||||
'phone' => sprintf('+26134000%04d', $client->id),
|
||||
'role' => $index % 2 === 0 ? 'Responsable funéraire' : 'Assistant administratif',
|
||||
]
|
||||
);
|
||||
|
||||
if ($index < 8) {
|
||||
Contact::updateOrCreate(
|
||||
[
|
||||
'client_id' => $client->id,
|
||||
'email' => sprintf('famille.%d@clients.thanasoft.test', $client->id),
|
||||
],
|
||||
[
|
||||
'first_name' => 'Référent',
|
||||
'last_name' => sprintf('Famille %d', $client->id),
|
||||
'phone' => sprintf('+26135000%04d', $client->id),
|
||||
'role' => 'Référent famille',
|
||||
]
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -18,8 +18,12 @@ class DatabaseSeeder extends Seeder
|
||||
$this->call(AdminAccessSeeder::class);
|
||||
|
||||
$this->call(ProductCategorySeeder::class);
|
||||
$this->call(ProductSeeder::class);
|
||||
$this->call(EmployeeSeeder::class);
|
||||
$this->call(ThanatopractitionerSeeder::class);
|
||||
$this->call(ClientSeeder::class);
|
||||
$this->call(ContactSeeder::class);
|
||||
$this->call(DeceasedSeeder::class);
|
||||
$this->call(InterventionSeeder::class);
|
||||
}
|
||||
}
|
||||
|
||||
40
thanasoft-back/database/seeders/DeceasedSeeder.php
Normal file
40
thanasoft-back/database/seeders/DeceasedSeeder.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Deceased;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class DeceasedSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
$records = [
|
||||
['last_name' => 'Martin', 'first_name' => 'Jeanne', 'birth_date' => '1942-03-11', 'death_date' => '2026-04-12', 'place_of_death' => 'Antananarivo'],
|
||||
['last_name' => 'Rabe', 'first_name' => 'Joseph', 'birth_date' => '1951-07-22', 'death_date' => '2026-04-10', 'place_of_death' => 'Fianarantsoa'],
|
||||
['last_name' => 'Rakoto', 'first_name' => 'Marie', 'birth_date' => '1938-12-01', 'death_date' => '2026-04-08', 'place_of_death' => 'Mahajanga'],
|
||||
['last_name' => 'Dubois', 'first_name' => 'Henri', 'birth_date' => '1947-09-14', 'death_date' => '2026-04-05', 'place_of_death' => 'Toamasina'],
|
||||
['last_name' => 'Rasolo', 'first_name' => 'Lucienne', 'birth_date' => '1955-11-09', 'death_date' => '2026-04-02', 'place_of_death' => 'Antsirabe'],
|
||||
['last_name' => 'Petit', 'first_name' => 'Alain', 'birth_date' => '1960-01-19', 'death_date' => '2026-03-30', 'place_of_death' => 'Antananarivo'],
|
||||
['last_name' => 'Andriamihaingo', 'first_name' => 'Suzanne', 'birth_date' => '1949-06-17', 'death_date' => '2026-03-27', 'place_of_death' => 'Moramanga'],
|
||||
['last_name' => 'Ranaivo', 'first_name' => 'Claude', 'birth_date' => '1958-08-05', 'death_date' => '2026-03-22', 'place_of_death' => 'Antananarivo'],
|
||||
['last_name' => 'Simon', 'first_name' => 'Madeleine', 'birth_date' => '1940-10-03', 'death_date' => '2026-03-19', 'place_of_death' => 'Antsiranana'],
|
||||
['last_name' => 'Raharisoa', 'first_name' => 'Paul', 'birth_date' => '1953-04-24', 'death_date' => '2026-03-15', 'place_of_death' => 'Toliara'],
|
||||
];
|
||||
|
||||
foreach ($records as $record) {
|
||||
Deceased::updateOrCreate(
|
||||
[
|
||||
'last_name' => $record['last_name'],
|
||||
'first_name' => $record['first_name'],
|
||||
'death_date' => $record['death_date'],
|
||||
],
|
||||
[
|
||||
'birth_date' => $record['birth_date'],
|
||||
'place_of_death' => $record['place_of_death'],
|
||||
'notes' => 'Donnée de démonstration pour les interventions et le suivi défunt.',
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
91
thanasoft-back/database/seeders/InterventionSeeder.php
Normal file
91
thanasoft-back/database/seeders/InterventionSeeder.php
Normal file
@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Client;
|
||||
use App\Models\ClientLocation;
|
||||
use App\Models\Deceased;
|
||||
use App\Models\Intervention;
|
||||
use App\Models\Product;
|
||||
use App\Models\Thanatopractitioner;
|
||||
use App\Models\User;
|
||||
use Faker\Factory as Faker;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class InterventionSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
$faker = Faker::create('fr_FR');
|
||||
$products = Product::query()
|
||||
->whereHas('category', fn ($query) => $query->where('intervention', true))
|
||||
->get();
|
||||
$deceasedCollection = Deceased::query()->get();
|
||||
$practitioners = Thanatopractitioner::query()->get();
|
||||
$clients = Client::query()->limit(12)->get();
|
||||
$creatorId = User::query()->value('id');
|
||||
$types = ['thanatopraxie', 'toilette_mortuaire', 'exhumation', 'retrait_pacemaker', 'retrait_bijoux', 'autre'];
|
||||
$statuses = ['demande', 'planifie', 'en_cours', 'termine', 'annule'];
|
||||
|
||||
if ($products->isEmpty() || $deceasedCollection->isEmpty() || $clients->isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($clients as $index => $client) {
|
||||
$location = ClientLocation::updateOrCreate(
|
||||
[
|
||||
'client_id' => $client->id,
|
||||
'name' => 'Site principal',
|
||||
],
|
||||
[
|
||||
'address_line1' => $client->billing_address_line1,
|
||||
'address_line2' => $client->billing_address_line2,
|
||||
'postal_code' => $client->billing_postal_code,
|
||||
'city' => $client->billing_city,
|
||||
'country_code' => $client->billing_country_code ?: 'FR',
|
||||
'is_default' => true,
|
||||
]
|
||||
);
|
||||
|
||||
$intervention = Intervention::updateOrCreate(
|
||||
[
|
||||
'client_id' => $client->id,
|
||||
'scheduled_at' => now()->subDays($index)->format('Y-m-d H:i:s'),
|
||||
'type' => $types[$index % count($types)],
|
||||
],
|
||||
[
|
||||
'deceased_id' => optional($deceasedCollection->get($index % $deceasedCollection->count()))->id,
|
||||
'order_giver' => $faker->name,
|
||||
'location_id' => $location->id,
|
||||
'product_id' => optional($products->get($index % $products->count()))->id,
|
||||
'duration_min' => [60, 75, 90, 120][$index % 4],
|
||||
'status' => $statuses[$index % count($statuses)],
|
||||
'attachments_count' => 0,
|
||||
'notes' => $faker->sentence,
|
||||
'created_by' => $creatorId,
|
||||
]
|
||||
);
|
||||
|
||||
if ($practitioners->isNotEmpty()) {
|
||||
$principal = $practitioners->get($index % $practitioners->count());
|
||||
$assistant = $practitioners->get(($index + 1) % $practitioners->count());
|
||||
|
||||
$syncData = [
|
||||
$principal->id => [
|
||||
'role' => 'principal',
|
||||
'assigned_at' => now()->subDays($index),
|
||||
],
|
||||
];
|
||||
|
||||
if ($assistant && $assistant->id !== $principal->id) {
|
||||
$syncData[$assistant->id] = [
|
||||
'role' => 'assistant',
|
||||
'assigned_at' => now()->subDays($index)->addMinutes(10),
|
||||
];
|
||||
}
|
||||
|
||||
$intervention->practitioners()->sync($syncData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -12,89 +12,171 @@ class ProductCategorySeeder extends Seeder
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// Create root categories
|
||||
$electronique = ProductCategory::create([
|
||||
// Create generic root categories
|
||||
$electronique = ProductCategory::firstOrCreate([
|
||||
'code' => 'ELECTRONIQUE',
|
||||
], [
|
||||
'name' => 'Électronique',
|
||||
'description' => 'Produits électroniques et technologiques',
|
||||
'intervention' => false,
|
||||
'active' => true,
|
||||
]);
|
||||
|
||||
$alimentaire = ProductCategory::create([
|
||||
$alimentaire = ProductCategory::firstOrCreate([
|
||||
'code' => 'ALIMENTAIRE',
|
||||
], [
|
||||
'name' => 'Alimentaire',
|
||||
'description' => 'Produits alimentaires et boissons',
|
||||
'intervention' => false,
|
||||
'active' => true,
|
||||
]);
|
||||
|
||||
$medical = ProductCategory::create([
|
||||
$medical = ProductCategory::firstOrCreate([
|
||||
'code' => 'MEDICAL',
|
||||
], [
|
||||
'name' => 'Médical',
|
||||
'description' => 'Produits médicaux et pharmaceutiques',
|
||||
'intervention' => false,
|
||||
'active' => true,
|
||||
]);
|
||||
|
||||
$interventions = ProductCategory::firstOrCreate([
|
||||
'code' => 'INTERVENTIONS',
|
||||
], [
|
||||
'name' => 'Interventions',
|
||||
'description' => 'Catégories de soins et prestations dédiées aux interventions funéraires.',
|
||||
'intervention' => true,
|
||||
'active' => true,
|
||||
]);
|
||||
|
||||
$produits = ProductCategory::firstOrCreate([
|
||||
'code' => 'PRODUITS',
|
||||
], [
|
||||
'name' => 'Produits',
|
||||
'description' => 'Catégories de produits généraux et consommables.',
|
||||
'intervention' => false,
|
||||
'active' => true,
|
||||
]);
|
||||
|
||||
// Create subcategories
|
||||
ProductCategory::create([
|
||||
'parent_id' => $electronique->id,
|
||||
ProductCategory::firstOrCreate([
|
||||
'code' => 'TELEPHONE',
|
||||
], [
|
||||
'parent_id' => $electronique->id,
|
||||
'name' => 'Téléphones',
|
||||
'description' => 'Smartphones et téléphones mobiles',
|
||||
'intervention' => false,
|
||||
'active' => true,
|
||||
]);
|
||||
|
||||
ProductCategory::create([
|
||||
'parent_id' => $electronique->id,
|
||||
ProductCategory::firstOrCreate([
|
||||
'code' => 'ORDINATEUR',
|
||||
], [
|
||||
'parent_id' => $electronique->id,
|
||||
'name' => 'Ordinateurs',
|
||||
'description' => 'Ordinateurs portables et de bureau',
|
||||
'intervention' => false,
|
||||
'active' => true,
|
||||
]);
|
||||
|
||||
ProductCategory::create([
|
||||
'parent_id' => $alimentaire->id,
|
||||
ProductCategory::firstOrCreate([
|
||||
'code' => 'FRUITS',
|
||||
], [
|
||||
'parent_id' => $alimentaire->id,
|
||||
'name' => 'Fruits',
|
||||
'description' => 'Fruits frais et transformés',
|
||||
'intervention' => false,
|
||||
'active' => true,
|
||||
]);
|
||||
|
||||
ProductCategory::create([
|
||||
'parent_id' => $alimentaire->id,
|
||||
ProductCategory::firstOrCreate([
|
||||
'code' => 'LEGUMES',
|
||||
], [
|
||||
'parent_id' => $alimentaire->id,
|
||||
'name' => 'Légumes',
|
||||
'description' => 'Légumes frais et transformés',
|
||||
'intervention' => false,
|
||||
'active' => true,
|
||||
]);
|
||||
|
||||
ProductCategory::create([
|
||||
'parent_id' => $medical->id,
|
||||
ProductCategory::firstOrCreate([
|
||||
'code' => 'MEDICAMENT',
|
||||
], [
|
||||
'parent_id' => $medical->id,
|
||||
'name' => 'Médicaments',
|
||||
'description' => 'Médicaments et traitements',
|
||||
'intervention' => false,
|
||||
'active' => true,
|
||||
]);
|
||||
|
||||
ProductCategory::create([
|
||||
'parent_id' => $medical->id,
|
||||
ProductCategory::firstOrCreate([
|
||||
'code' => 'MATERIEL',
|
||||
], [
|
||||
'parent_id' => $medical->id,
|
||||
'name' => 'Matériel Médical',
|
||||
'description' => 'Équipements et instruments médicaux',
|
||||
'intervention' => false,
|
||||
'active' => true,
|
||||
]);
|
||||
|
||||
ProductCategory::firstOrCreate([
|
||||
'code' => 'SOINS_THANATO',
|
||||
], [
|
||||
'parent_id' => $interventions->id,
|
||||
'name' => 'Soins thanatopraxiques',
|
||||
'description' => 'Soins de conservation, présentation et préparation du défunt.',
|
||||
'intervention' => true,
|
||||
'active' => true,
|
||||
]);
|
||||
|
||||
ProductCategory::firstOrCreate([
|
||||
'code' => 'PREPARATION_DEFUNT',
|
||||
], [
|
||||
'parent_id' => $interventions->id,
|
||||
'name' => 'Préparation du défunt',
|
||||
'description' => 'Toilette mortuaire, habillage et préparation avant cérémonie.',
|
||||
'intervention' => true,
|
||||
'active' => true,
|
||||
]);
|
||||
|
||||
ProductCategory::firstOrCreate([
|
||||
'code' => 'ACCESSOIRES_FUNERAIRES',
|
||||
], [
|
||||
'parent_id' => $produits->id,
|
||||
'name' => 'Accessoires funéraires',
|
||||
'description' => 'Consommables et accessoires utilisés lors des prestations funéraires.',
|
||||
'intervention' => false,
|
||||
'active' => true,
|
||||
]);
|
||||
|
||||
ProductCategory::firstOrCreate([
|
||||
'code' => 'CONSOMMABLES_SOINS',
|
||||
], [
|
||||
'parent_id' => $produits->id,
|
||||
'name' => 'Consommables de soins',
|
||||
'description' => 'Produits consommables utilisés pendant les soins d\'intervention.',
|
||||
'intervention' => false,
|
||||
'active' => true,
|
||||
]);
|
||||
|
||||
// Create some inactive categories for testing
|
||||
ProductCategory::create([
|
||||
ProductCategory::firstOrCreate([
|
||||
'code' => 'COSMETIQUE',
|
||||
], [
|
||||
'code' => 'COSMETIQUE',
|
||||
'name' => 'Cosmétique',
|
||||
'description' => 'Produits cosmétiques et de beauté',
|
||||
'intervention' => false,
|
||||
'active' => false,
|
||||
]);
|
||||
|
||||
ProductCategory::create([
|
||||
ProductCategory::firstOrCreate([
|
||||
'code' => 'MENAGE',
|
||||
], [
|
||||
'code' => 'MENAGE',
|
||||
'name' => 'Ménage',
|
||||
'description' => 'Produits d\'entretien et de nettoyage',
|
||||
'intervention' => false,
|
||||
'active' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
121
thanasoft-back/database/seeders/ProductSeeder.php
Normal file
121
thanasoft-back/database/seeders/ProductSeeder.php
Normal file
@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Product;
|
||||
use App\Models\ProductCategory;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class ProductSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
$products = [
|
||||
[
|
||||
'nom' => 'Soin de thanatopraxie standard',
|
||||
'reference' => 'INT-THAN-001',
|
||||
'category_code' => 'SOINS_THANATO',
|
||||
'fabricant' => 'Thanasoft Care',
|
||||
'stock_actuel' => 50,
|
||||
'stock_minimum' => 10,
|
||||
'unite' => 'prestation',
|
||||
'prix_unitaire' => 320.00,
|
||||
'conditionnement_nom' => 'Unité',
|
||||
'conditionnement_quantite' => 1,
|
||||
'conditionnement_unite' => 'prestation',
|
||||
],
|
||||
[
|
||||
'nom' => 'Toilette mortuaire complète',
|
||||
'reference' => 'INT-TOIL-001',
|
||||
'category_code' => 'PREPARATION_DEFUNT',
|
||||
'fabricant' => 'Thanasoft Care',
|
||||
'stock_actuel' => 40,
|
||||
'stock_minimum' => 8,
|
||||
'unite' => 'prestation',
|
||||
'prix_unitaire' => 180.00,
|
||||
'conditionnement_nom' => 'Unité',
|
||||
'conditionnement_quantite' => 1,
|
||||
'conditionnement_unite' => 'prestation',
|
||||
],
|
||||
[
|
||||
'nom' => 'Retrait pacemaker',
|
||||
'reference' => 'INT-PACE-001',
|
||||
'category_code' => 'PREPARATION_DEFUNT',
|
||||
'fabricant' => 'Thanasoft Care',
|
||||
'stock_actuel' => 20,
|
||||
'stock_minimum' => 4,
|
||||
'unite' => 'prestation',
|
||||
'prix_unitaire' => 95.00,
|
||||
'conditionnement_nom' => 'Unité',
|
||||
'conditionnement_quantite' => 1,
|
||||
'conditionnement_unite' => 'prestation',
|
||||
],
|
||||
[
|
||||
'nom' => 'Kit de soins de conservation',
|
||||
'reference' => 'PROD-SOIN-001',
|
||||
'category_code' => 'CONSOMMABLES_SOINS',
|
||||
'fabricant' => 'Mortuary Supply',
|
||||
'stock_actuel' => 120,
|
||||
'stock_minimum' => 25,
|
||||
'unite' => 'kit',
|
||||
'prix_unitaire' => 42.50,
|
||||
'conditionnement_nom' => 'Carton',
|
||||
'conditionnement_quantite' => 10,
|
||||
'conditionnement_unite' => 'kit',
|
||||
],
|
||||
[
|
||||
'nom' => 'Housse funéraire premium',
|
||||
'reference' => 'PROD-HOUS-001',
|
||||
'category_code' => 'ACCESSOIRES_FUNERAIRES',
|
||||
'fabricant' => 'Funeral Equip',
|
||||
'stock_actuel' => 75,
|
||||
'stock_minimum' => 15,
|
||||
'unite' => 'unité',
|
||||
'prix_unitaire' => 28.90,
|
||||
'conditionnement_nom' => 'Paquet',
|
||||
'conditionnement_quantite' => 5,
|
||||
'conditionnement_unite' => 'unité',
|
||||
],
|
||||
[
|
||||
'nom' => 'Produit de désinfection mortuaire',
|
||||
'reference' => 'PROD-DES-001',
|
||||
'category_code' => 'CONSOMMABLES_SOINS',
|
||||
'fabricant' => 'Mortuary Supply',
|
||||
'stock_actuel' => 90,
|
||||
'stock_minimum' => 20,
|
||||
'unite' => 'litre',
|
||||
'prix_unitaire' => 14.75,
|
||||
'conditionnement_nom' => 'Bidon',
|
||||
'conditionnement_quantite' => 5,
|
||||
'conditionnement_unite' => 'litre',
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($products as $data) {
|
||||
$category = ProductCategory::where('code', $data['category_code'])->first();
|
||||
|
||||
if (! $category) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Product::updateOrCreate(
|
||||
['reference' => $data['reference']],
|
||||
[
|
||||
'nom' => $data['nom'],
|
||||
'categorie_id' => $category->id,
|
||||
'fabricant' => $data['fabricant'],
|
||||
'stock_actuel' => $data['stock_actuel'],
|
||||
'stock_minimum' => $data['stock_minimum'],
|
||||
'unite' => $data['unite'],
|
||||
'prix_unitaire' => $data['prix_unitaire'],
|
||||
'conditionnement_nom' => $data['conditionnement_nom'],
|
||||
'conditionnement_quantite' => $data['conditionnement_quantite'],
|
||||
'conditionnement_unite' => $data['conditionnement_unite'],
|
||||
'date_expiration' => null,
|
||||
'numero_lot' => null,
|
||||
'fournisseur_id' => null,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user