diff --git a/app/Http/Controllers/ContactoController.php b/app/Http/Controllers/ContactoController.php index 89b88168ecee75ab7a114731bcf9f0ee38525dbd..e3e6aadc2f0773916ee0dc56a0da75e6cd41f04e 100644 --- a/app/Http/Controllers/ContactoController.php +++ b/app/Http/Controllers/ContactoController.php @@ -8,6 +8,7 @@ use App\Models\Contacto; use App\Models\CorreoContactos; use App\Models\Grupos; +use App\Models\Instituciones; use App\Models\Profesion; use App\Models\Subgrupo; use App\Models\Telefono; @@ -17,7 +18,6 @@ use Illuminate\Http\Request; use Illuminate\Support\Str; use Illuminate\Support\Facades\Storage; -use Illuminate\Support\Facades\Log; class ContactoController extends Controller { @@ -42,7 +42,8 @@ public function create() $caracteristicas = Caracteristicas::get(); $subgrupos = Subgrupo::get(); $grupos = Grupos::get(); - return view('adminGen.contactos.create', compact('conyuges', 'profesiones', 'cargos', 'caracteristicas', 'subgrupos', 'grupos')); + $instituciones = Instituciones::get(); + return view('adminGen.contactos.create', compact('conyuges', 'profesiones', 'cargos', 'caracteristicas', 'subgrupos', 'grupos', 'instituciones')); } /** @@ -89,7 +90,7 @@ public function store(Request $request) 'caracteristica_id', 'mes_cump', 'dia_cump', - //institucion_id + 'institucion_id' ]; $requestData = $request->all(); foreach ($fieldsToCheck as $field) { @@ -169,9 +170,10 @@ public function edit(string $id) $cargos = cargos::get(); $caracteristicas = Caracteristicas::get(); $subgrupos = Subgrupo::get(); - $contacto = Contacto::with(['telefonos', 'redes', 'correos'])->findOrFail($id); - //dd($contacto); - return view('adminGen.contactos.edit', compact('contacto', 'conyuges', 'profesiones', 'cargos', 'caracteristicas', 'subgrupos')); + $grupos = Grupos::get(); + $instituciones = Instituciones::get(); + $contacto = Contacto::with(['telefonos', 'redes', 'correos', 'grupos', 'subgrupos'])->findOrFail($id); + return view('adminGen.contactos.edit', compact('contacto', 'conyuges', 'profesiones', 'cargos', 'caracteristicas', 'subgrupos', 'grupos', 'instituciones')); } /** @@ -197,7 +199,7 @@ public function update(Request $request, string $id) 'subgrupo_id', 'mes_cump', 'dia_cump', - //institucion_id + 'institucion_id' ]; $requestData = $request->all(); foreach ($fieldsToCheck as $field) { @@ -308,6 +310,15 @@ public function update(Request $request, string $id) if (!empty($changes)) { Auditoria::insert($changes); } + + // Sincronizar subgrupos y grupos + if ($request->has('subgrupo_id')) { + $contacto->subgrupos()->sync($request->input('subgrupo_id')); + } + + if ($request->has('grupo_id')) { + $contacto->grupos()->sync($request->input('grupo_id')); + } // Actualizar los datos del contacto $contacto->conyuge_id = $request->input('conyuge_id') !== 'null' ? $request->input('conyuge_id') : null; diff --git a/app/Models/Contacto.php b/app/Models/Contacto.php index 64d6ae5ab78cd23e304dc03e310000a8b287c959..79465e8ad42f073a060554f4103cbedeef2d9670 100644 --- a/app/Models/Contacto.php +++ b/app/Models/Contacto.php @@ -39,7 +39,7 @@ class Contacto extends Model 'profesion_id', 'cargo_id', 'caracteristica_id', - //'institucion_id', + 'institucion_id', ]; public function profesion(): BelongsTo @@ -86,4 +86,9 @@ public function grupos(): BelongsToMany { return $this->belongsToMany(Grupos::class, 'contactos_grupos', 'contacto_id', 'grupo_id'); } + + public function institucion(): BelongsTo + { + return $this->belongsTo(Instituciones::class); + } } diff --git a/app/Models/Instituciones.php b/app/Models/Instituciones.php index 7d97e1d95e4f930ef5bcb4647fb4fb17a9b552df..35723465601aa65688538ad9a2ee407cd35958d0 100644 --- a/app/Models/Instituciones.php +++ b/app/Models/Instituciones.php @@ -4,6 +4,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\HasMany; class Instituciones extends Model { @@ -40,4 +41,9 @@ public function telefonos() { return $this->hasMany(TelefonoInst::class, 'instituciones_id'); } + + public function contactos(): HasMany + { + return $this->hasMany(Contacto::class); + } } diff --git a/database/migrations/2024_06_23_201805_create_contactos_table.php b/database/migrations/2024_06_23_201805_create_contactos_table.php index 8a808d87da39c923741cde6f6a094fe85a8f0713..8478389fd10ad521ecb5805752b1bb70b798a07d 100644 --- a/database/migrations/2024_06_23_201805_create_contactos_table.php +++ b/database/migrations/2024_06_23_201805_create_contactos_table.php @@ -38,11 +38,11 @@ public function up(): void $table->unsignedBigInteger('profesion_id')->nullable(); $table->unsignedBigInteger('cargo_id')->nullable(); $table->unsignedBigInteger('caracteristica_id')->nullable(); - //$table->unsignedBigInteger('institucion_id')->nullable(); + $table->unsignedBigInteger('institucion_id')->nullable(); $table->foreign('conyuge_id')->references('id')->on('contactos')->nullable(); $table->foreign('profesion_id')->references('id')->on('profesions')->nullable(); - //$table->foreign('institucion_id')->references('id')->on('')->nullable(); + $table->foreign('institucion_id')->references('id')->on('instituciones')->nullable(); $table->foreign('cargo_id')->references('id')->on('cargos')->nullable(); $table->foreign('caracteristica_id')->references('id')->on('caracteristicas')->nullable(); diff --git a/public/assets/images/SGG_Color.png b/public/assets/images/SGG_Color.png new file mode 100644 index 0000000000000000000000000000000000000000..a88f5e66ea0d82eb174132deaccb34ad3f98c1ad Binary files /dev/null and b/public/assets/images/SGG_Color.png differ diff --git a/resources/views/adminGen/contactos/create.blade.php b/resources/views/adminGen/contactos/create.blade.php index 1fcd347d4a4ae719f7531309f9fd6aedfe1292f4..e0b1966dc82a4cdcdbe61036f3b13e31fc43587c 100644 --- a/resources/views/adminGen/contactos/create.blade.php +++ b/resources/views/adminGen/contactos/create.blade.php @@ -189,15 +189,7 @@