feat: eliminar método createWarehouse y agregar WarehouseSeeder para inicializar almacén principal
This commit is contained in:
parent
86ef5931e1
commit
920dcb2cc9
@ -16,26 +16,6 @@ public function getMainWarehouse(): ?Warehouse
|
|||||||
return Warehouse::main()->first();
|
return Warehouse::main()->first();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Crear nuevo almacén
|
|
||||||
*/
|
|
||||||
public function createWarehouse(array $data): Warehouse
|
|
||||||
{
|
|
||||||
return DB::transaction(function () use ($data) {
|
|
||||||
// Si se marca como principal, desactivar otros principales
|
|
||||||
if ($data['is_main'] ?? false) {
|
|
||||||
Warehouse::where('is_main', true)->update(['is_main' => false]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Si no hay almacenes principales, este debe serlo
|
|
||||||
if (!Warehouse::main()->exists()) {
|
|
||||||
$data['is_main'] = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Warehouse::create($data);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Actualizar almacén
|
* Actualizar almacén
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -24,5 +24,6 @@ public function run(): void
|
|||||||
$this->call(SettingSeeder::class);
|
$this->call(SettingSeeder::class);
|
||||||
$this->call(ClientTierSeeder::class);
|
$this->call(ClientTierSeeder::class);
|
||||||
$this->call(UnitsSeeder::class);
|
$this->call(UnitsSeeder::class);
|
||||||
|
$this->call(WarehouseSeeder::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,5 +24,6 @@ public function run(): void
|
|||||||
$this->call(SettingSeeder::class);
|
$this->call(SettingSeeder::class);
|
||||||
$this->call(ClientTierSeeder::class);
|
$this->call(ClientTierSeeder::class);
|
||||||
$this->call(UnitsSeeder::class);
|
$this->call(UnitsSeeder::class);
|
||||||
|
$this->call(WarehouseSeeder::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
19
database/seeders/WarehouseSeeder.php
Normal file
19
database/seeders/WarehouseSeeder.php
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?php namespace Database\Seeders;
|
||||||
|
|
||||||
|
use App\Models\Warehouse;
|
||||||
|
use Illuminate\Database\Seeder;
|
||||||
|
|
||||||
|
class WarehouseSeeder extends Seeder
|
||||||
|
{
|
||||||
|
public function run(): void
|
||||||
|
{
|
||||||
|
Warehouse::firstOrCreate(
|
||||||
|
['code' => 'MAIN'],
|
||||||
|
[
|
||||||
|
'name' => 'Almacén Principal',
|
||||||
|
'is_active' => true,
|
||||||
|
'is_main' => true,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user