Initial commit - construprogress app
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class DatabaseSeeder extends Seeder
|
||||
{
|
||||
use WithoutModelEvents;
|
||||
|
||||
/**
|
||||
* Seed the application's database.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// User::factory(10)->create();
|
||||
|
||||
/*User::factory()->create([
|
||||
'name' => 'Test User',
|
||||
'email' => 'test@example.com',
|
||||
]);*/
|
||||
|
||||
|
||||
$this->call([
|
||||
RolesAndPermissionsSeeder::class,
|
||||
ProjectExampleSeeder::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use App\Models\Project;
|
||||
use App\Models\Phase;
|
||||
use App\Models\Layer;
|
||||
use App\Models\Feature;
|
||||
use App\Models\InspectionTemplate;
|
||||
use App\Models\User;
|
||||
|
||||
class ProjectExampleSeeder extends Seeder
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
// Obtener usuario admin
|
||||
$admin = User::where('email', 'admin@email.com')->first();
|
||||
if (!$admin) {
|
||||
$admin = User::first();
|
||||
}
|
||||
|
||||
// Crear proyecto
|
||||
$project = Project::create([
|
||||
'name' => 'Edificio Central',
|
||||
'address' => 'Av. Principal 123, Ciudad',
|
||||
'lat' => 40.416775,
|
||||
'lng' => -3.703790,
|
||||
'start_date' => now(),
|
||||
'end_date_estimated' => now()->addMonths(12),
|
||||
'status' => 'in_progress',
|
||||
'created_by' => $admin->id,
|
||||
]);
|
||||
|
||||
$project->users()->attach($admin->id, ['role_in_project' => 'supervisor']);
|
||||
|
||||
// Crear fases
|
||||
$phases = [
|
||||
['name' => 'Cimientos', 'order' => 1, 'color' => '#ef4444'],
|
||||
['name' => 'Estructura', 'order' => 2, 'color' => '#3b82f6'],
|
||||
['name' => 'Instalaciones', 'order' => 3, 'color' => '#10b981'],
|
||||
['name' => 'Acabados', 'order' => 4, 'color' => '#f59e0b'],
|
||||
];
|
||||
|
||||
foreach ($phases as $phaseData) {
|
||||
Phase::create(array_merge($phaseData, ['project_id' => $project->id, 'progress_percent' => 0]));
|
||||
}
|
||||
|
||||
$phaseCimientos = Phase::where('project_id', $project->id)->where('name', 'Cimientos')->first();
|
||||
|
||||
// Crear templates de inspección
|
||||
$templateHormigon = InspectionTemplate::create([
|
||||
'project_id' => $project->id,
|
||||
'name' => 'Control de hormigón',
|
||||
'fields' => [
|
||||
['name' => 'progress', 'label' => 'Progreso de vertido', 'type' => 'percentage', 'required' => true],
|
||||
['name' => 'calidad', 'label' => 'Calidad del hormigón', 'type' => 'select', 'options' => 'Excelente,Bueno,Regular,Deficiente', 'required' => true],
|
||||
['name' => 'observaciones', 'label' => 'Observaciones', 'type' => 'textarea', 'required' => false],
|
||||
]
|
||||
]);
|
||||
|
||||
$templateAcero = InspectionTemplate::create([
|
||||
'project_id' => $project->id,
|
||||
'name' => 'Control de acero',
|
||||
'fields' => [
|
||||
['name' => 'progress', 'label' => '% de acero colocado', 'type' => 'percentage', 'required' => true],
|
||||
['name' => 'diametros', 'label' => 'Diámetros verificados', 'type' => 'text', 'required' => false],
|
||||
]
|
||||
]);
|
||||
|
||||
// Crear capa (sin geojson_data)
|
||||
$layer = Layer::create([
|
||||
'project_id' => $project->id,
|
||||
'phase_id' => $phaseCimientos->id,
|
||||
'name' => 'Plano de cimientos',
|
||||
'original_file' => null,
|
||||
'uploaded_by' => $admin->id,
|
||||
]);
|
||||
|
||||
// Crear features (elementos geográficos)
|
||||
$feature1 = Feature::create([
|
||||
'layer_id' => $layer->id,
|
||||
'name' => 'Zapata A1',
|
||||
'geometry' => [
|
||||
'type' => 'Polygon',
|
||||
'coordinates' => [[
|
||||
[-3.705, 40.415],
|
||||
[-3.702, 40.415],
|
||||
[-3.702, 40.418],
|
||||
[-3.705, 40.418],
|
||||
[-3.705, 40.415]
|
||||
]]
|
||||
],
|
||||
'properties' => ['description' => 'Zapata esquina noroeste'],
|
||||
'template_id' => $templateHormigon->id,
|
||||
'progress' => 45,
|
||||
'responsible' => 'Ing. Gómez',
|
||||
]);
|
||||
|
||||
$feature2 = Feature::create([
|
||||
'layer_id' => $layer->id,
|
||||
'name' => 'Zapata B1',
|
||||
'geometry' => [
|
||||
'type' => 'Polygon',
|
||||
'coordinates' => [[
|
||||
[-3.700, 40.415],
|
||||
[-3.697, 40.415],
|
||||
[-3.697, 40.418],
|
||||
[-3.700, 40.418],
|
||||
[-3.700, 40.415]
|
||||
]]
|
||||
],
|
||||
'properties' => ['description' => 'Zapata lado este'],
|
||||
'template_id' => $templateAcero->id,
|
||||
'progress' => 80,
|
||||
'responsible' => 'Arq. Martínez',
|
||||
]);
|
||||
|
||||
Feature::create([
|
||||
'layer_id' => $layer->id,
|
||||
'name' => 'Punto de control topográfico',
|
||||
'geometry' => [
|
||||
'type' => 'Point',
|
||||
'coordinates' => [-3.703, 40.4165]
|
||||
],
|
||||
'properties' => ['tipo' => 'estación total'],
|
||||
'template_id' => null,
|
||||
'progress' => 100,
|
||||
'responsible' => 'Topógrafo Pérez',
|
||||
]);
|
||||
|
||||
// (Opcional) Crear una inspección de ejemplo
|
||||
\App\Models\Inspection::create([
|
||||
'project_id' => $project->id,
|
||||
'layer_id' => $layer->id,
|
||||
'feature_id' => $feature1->id,
|
||||
'template_id' => $templateHormigon->id,
|
||||
'user_id' => $admin->id,
|
||||
'data' => [
|
||||
'progress' => 45,
|
||||
'calidad' => 'Bueno',
|
||||
'observaciones' => 'Vertido completado en un 45%, sin fisuras aparentes.'
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Spatie\Permission\Models\Role;
|
||||
use Spatie\Permission\Models\Permission;
|
||||
use App\Models\User;
|
||||
|
||||
class RolesAndPermissionsSeeder extends Seeder
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
// Reset cached roles and permissions
|
||||
app()[\Spatie\Permission\PermissionRegistrar::class]->forgetCachedPermissions();
|
||||
|
||||
// Create permissions
|
||||
$permissions = [
|
||||
'view projects', 'create projects', 'edit projects', 'delete projects',
|
||||
'assign users', 'upload layers', 'update progress', 'view reports', 'manage all'
|
||||
];
|
||||
foreach ($permissions as $perm) {
|
||||
Permission::firstOrCreate(['name' => $perm]);
|
||||
}
|
||||
|
||||
// Create roles and assign permissions
|
||||
$admin = Role::firstOrCreate(['name' => 'Admin']);
|
||||
$admin->givePermissionTo(Permission::all());
|
||||
|
||||
$supervisor = Role::firstOrCreate(['name' => 'Supervisor']);
|
||||
$supervisor->givePermissionTo(['view projects', 'upload layers', 'update progress']);
|
||||
|
||||
$consultor = Role::firstOrCreate(['name' => 'Consultor']);
|
||||
$consultor->givePermissionTo(['view projects', 'view reports']);
|
||||
|
||||
$cliente = Role::firstOrCreate(['name' => 'Cliente']);
|
||||
$cliente->givePermissionTo(['view projects']);
|
||||
|
||||
// Create default admin user
|
||||
$user = User::factory()->create([
|
||||
'name' => 'Admin User',
|
||||
'email' => 'admin@email.com',
|
||||
'password' => bcrypt('password'),
|
||||
]);
|
||||
$user->assignRole('Admin');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user