Primer commit proyecto Laravel

This commit is contained in:
2026-02-05 11:10:09 -06:00
commit e4559106d4
2153 changed files with 210301 additions and 0 deletions
+42
View File
@@ -0,0 +1,42 @@
<?php
namespace App\Livewire;
use App\Models\Carrera;
use App\Models\Nivel;
use App\Models\Plan;
use Livewire\Component;
class Carreras extends Component
{
public $niveles;
public $selectedNivel = null;
public $carreras = [];
public $selectedCarrera = null;
public Plan $plan;
public function mount(Plan $plan)
{
$this->plan = $plan;
$this->niveles = Nivel::all();
$this->selectedNivel = (int) $plan->nivel;
$this->selectedCarrera = (int) $plan->carrera;
$this->carreras = Carrera::where('nivel', $this->selectedNivel)->get();
}
// Este método se ejecuta cuando $selectedCountry cambia
public function updatedSelectedNivel($nivel)
{
$this->carreras = Carrera::where('nivel','=', $nivel)->get();
$this->selectedCarrera = null; // Reiniciar ciudad al cambiar país
}
public function render()
{
return view('livewire.carreras');
}
}
+44
View File
@@ -0,0 +1,44 @@
<?php
namespace App\Livewire;
use Carbon\Carbon;
use Livewire\Component;
use App\Models\Concepto;
use Livewire\Attributes\On;
use App\Models\TipoConcepto;
class Conceptos extends Component
{
public $concepto = null;
public $fecha_pago = null;
public $plane;
#[On('edit-concepto')]
public function editMaterial($id)
{
$this->concepto = Concepto::findOrFail($id);
$this->fecha_pago = $this->concepto->fecha_pago
? Carbon::parse($this->concepto->fecha_pago)->format('Y-m-d')
: null;
$this->dispatch('open-concepto-modal');
}
#[On('create-concepto')]
public function createMaterial()
{
$this->reset('concepto');
$this->dispatch('open-concepto-modal');
}
public function render()
{
return view('livewire.conceptos', [
'tipos'=> TipoConcepto::where('id','!=','3')->get(),
'conceptos'=> Concepto::where('tipo','=','3')->get(),
]);
}
}
+349
View File
@@ -0,0 +1,349 @@
<?php
namespace App\Livewire;
use App\Models\Pago;
use App\Models\Plan;
use App\Models\Medio;
use App\Models\Nivel;
use App\Models\Plane;
use App\Models\Turno;
use App\Models\Campan;
use App\Models\Plantel;
use Livewire\Component;
use App\Models\Concepto;
use App\Models\Prospecto;
use Livewire\Attributes\On;
use Illuminate\Validation\Rule;
use Spatie\Permission\Models\Role;
use Illuminate\Support\Facades\Auth;
use Illuminate\Validation\ValidationException;
class DataProspecto extends Component
{
public $full;
public $activeProspectId = null;
public $pname;
public $pemail;
public $ptelefono;
public $pdireccion;
public $ppassword;
public $pplantels;
public $proles;
public $selectedNivel;
public $selectedplan;
public $selectedplane;
public $pciclo;
public $pturno;
public $pmedio;
public $niveles = [];
public $plans = [];
public $turnos = [];
public $planesPago = [];
public $conceptos = [];
public $conceptosNombres = [];
public $active = "disabled";
public $prospecto = null;
public function failedValidation(ValidationException $e)
{
$this->dispatch('swal',
icon: 'error',
title: 'Error de validación',
text: $e->validator->errors()->first(),
timer: 2000,
confirm: false,
closeModal: true
);
throw $e;
}
public function updatedPplantels()
{
$this->selectedNivel = null;
$this->selectedplan = null;
$this->plans = [];
$this->niveles = Nivel::whereHas('nivelPlantel', fn($q) =>
$q->where('plantels.id', $this->pplantels)
)->get();
$this->turnos = Turno::whereHas('turnoPlantel', fn($q) =>
$q->where('plantels.id', $this->pplantels)
)->get();
}
public function updatedSelectedNivel()
{
if (!$this->selectedNivel || !$this->pplantels) {
$this->plans = [];
$this->active = "disabled";
return;
}
$this->plans = Plan::where('nivel', $this->selectedNivel)
->whereHas('planesPlantel', fn($q) =>
$q->where('plantels.id', $this->pplantels)
)->get();
$this->active = "";
}
public function updatedSelectedplane()
{
$this->conceptos = [];
if (!$this->selectedplane) {
return;
}
// $plane = Plane::with(['conceptos' => function ($query) {
// $query->where('tipo', 1);
// }])->find($this->selectedplane);
$plane = Plane::with('conceptos')->find($this->selectedplane);
if ($plane) {
$this->conceptos = $plane->conceptos;
}
}
public function actualizarProspecto()
{
$user = $this->prospecto->prospectos()->first();
if (!$user) return;
try {
$this->validate([
'pname' => 'required',
'pemail' => [
'required',
'email',
Rule::unique('users', 'email')->ignore($user->id),
],
'ptelefono' => [
'required',
'regex:/^[0-9]{10}$/',
Rule::unique('users', 'telefono')->ignore($user->id),
],
], [
'pname.required' => 'El nombre es obligatorio',
'pemail.required' => 'El correo es obligatorio',
'pemail.email' => 'El correo no es válido',
'pemail.unique' => 'Este correo ya está registrado',
'ptelefono.required' => 'El teléfono es obligatorio',
'ptelefono.regex' => 'El teléfono debe tener 10 dígitos numéricos',
'ptelefono.unique' => 'Este teléfono ya está registrado',
]);
} catch (ValidationException $e) {
$mensaje = collect($e->validator->errors()->all())->first();
$this->dispatch('swal',
icon: 'error',
title: 'Error de validación',
text: $mensaje,
timer: 2000,
confirm: false,
closeModal: true
);
return;
}
$user->update([
'name' => $this->pname,
'email' => $this->pemail,
'telefono' => $this->ptelefono,
'direccion' => $this->pdireccion,
]);
$user->plantelUsuarios()->sync([$this->pplantels]);
$this->prospecto->update([
'nivel' => $this->selectedNivel,
'plan_id' => $this->selectedplan,
'ciclo' => $this->pciclo,
'turno' => $this->pturno,
'medio' => $this->pmedio,
]);
$this->dispatch('swal',
icon: 'success',
title: 'Datos actualizados!',
text: 'Se modificaon los datos del prospecto',
timer: 2000,
confirm: false,
closeModal: true
);
}
#[On('edit-prospecto')]
public function editProspecto($id)
{
$this->activeProspectId = $id;
$this->resetForm();
$this->prospecto = Prospecto::findOrFail($id);
$user = $this->prospecto->prospectos()->first();
if (!$user) return;
$this->pname = $user->name;
$this->pemail = $user->email;
$this->ptelefono = $user->telefono;
$this->pdireccion = $user->direccion;
$this->proles = $user->roles()->pluck('id')->first();
$this->pplantels = $user->plantelUsuarios()->value('plantels.id');
$this->selectedNivel = $this->prospecto->nivel;
$this->pciclo = $this->prospecto->ciclo;
$this->pturno = $this->prospecto->turno;
$this->pmedio = $this->prospecto->medio;
$this->selectedplane = $this->prospecto->plane_id;
$plane = Plane::with(['conceptos' => function ($query) {
$query->where('tipo', 1);
}])->find($this->selectedplane);
if ($plane) {
$this->conceptos = $plane->conceptos;
}
$this->niveles = Nivel::whereHas('nivelPlantel', fn($q) =>
$q->where('plantels.id', $this->pplantels)
)->get();
$this->turnos = Turno::whereHas('turnoPlantel', fn($q) =>
$q->where('plantels.id', $this->pplantels)
)->get();
$this->plans = Plan::where('nivel', $this->selectedNivel)
->whereHas('planesPlantel', fn($q) =>
$q->where('plantels.id', $this->pplantels)
)->get();
$this->planesPago = Plane::whereHas('planPlantel', function ($q) {
$q->where('plantels.id', $this->pplantels);
})->get();
$this->conceptosNombres = Concepto::where('tipo','=','3' )->get();
$this->full = true;
$this->selectedplan = $this->prospecto->plan_id;
$this->active = "";
$this->dispatch('mark-active-prospect', id: $id);
}
public function plan()
{
if($this->prospecto->plane_id != $this->selectedplane){
Pago::where('user_id', '=', $this->prospecto->id)->delete();
$this->prospecto->update([
'plane_id' => $this->selectedplane,
]);
$promotor = Auth::user();
foreach($this->conceptos as $concepto){
Pago::create([
'plans_id' => $this->selectedplane,
'folio' => 0,
'concepto' => $concepto->name,
'beca' => 0,
'monto' => $concepto->monto,
'fecha_pago' => $concepto->fecha_pago,
'pago'=>0,
'user_id'=> $this->prospecto->id,
'asignacion' =>$promotor->id,
'status'=> 1
]);
}
$this->dispatch('swal',
icon: 'success',
title: 'Éxito!',
text: 'Plan de pago asignado',
timer: 2000,
confirm: false,
closeModal: true
);
}else{
$this->dispatch('swal',
icon: 'error',
title: 'Error!',
text: 'Plan de pago actualmente asignado',
timer: 2000,
confirm: false,
closeModal: true
);
}
}
public function resetForm()
{
// Usuario
$this->pname = null;
$this->pemail = null;
$this->ptelefono = null;
$this->pdireccion = null;
$this->ppassword = null;
$this->pplantels = null;
$this->proles = null;
// Prospecto
$this->selectedNivel = null;
$this->selectedplan = null;
$this->pciclo = null;
$this->pturno = null;
$this->pmedio = null;
// Selects
$this->niveles = [];
$this->plans = [];
$this->turnos = [];
$this->active = "disabled";
$this->prospecto = null;
}
public function render()
{
return view('livewire.data-prospecto', [
'roles' => Role::whereHas('areas', fn($q) => $q->where('areas.name', 'Promoción'))->get(),
'plantels'=> Plantel::all(),
'user' => Auth::user(),
'campans' => Campan::all(),
'medios' => Medio::all(),
]);
}
}
+33
View File
@@ -0,0 +1,33 @@
<?php
namespace App\Livewire;
use App\Models\Material;
use Livewire\Component;
use Livewire\Attributes\On;
class ModalMaterias extends Component
{
public $material = null;
public $carrera;
#[On('edit-material')]
public function editMaterial($id)
{
$this->material = Material::findOrFail($id);
$this->dispatch('open-material-modal');
}
#[On('create-material')]
public function createMaterial()
{
$this->reset('material');
$this->dispatch('open-material-modal');
}
public function render()
{
return view('livewire.modal-materias');
}
}
+169
View File
@@ -0,0 +1,169 @@
<?php
namespace App\Livewire;
use App\Models\Campan;
use App\Models\Medio;
use App\Models\User;
use App\Models\Nivel;
use App\Models\Plan;
use App\Models\Plantel;
use App\Models\Prospecto;
use App\Models\Turno;
use Livewire\Component;
use Spatie\Permission\Models\Role;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Livewire\Attributes\On;
class ModalProspecto extends Component
{
// Usuario
public $pname;
public $pemail;
public $ptelefono;
public $pdireccion;
public $ppassword;
public $pplantels;
public $proles;
// Prospecto
public $selectedNivel;
public $selectedplan;
public $pciclo;
public $pturno;
public $pmedio;
// Selects dependientes
public $niveles = [];
public $plans = [];
public $turnos = [];
public $active = "disabled";
public $prospecto = null;
/* ------------------ RESET REAL ------------------ */
private function resetForm()
{
$this->reset([
'pname',
'pemail',
'ptelefono',
'pdireccion',
'ppassword',
'pplantels',
'proles',
'selectedNivel',
'selectedplan',
'pciclo',
'pturno',
'pmedio',
'prospecto',
]);
$this->niveles = [];
$this->plans = [];
$this->turnos = [];
$this->active = "disabled";
}
/* ------------------ EDITAR ------------------ */
/* ------------------ NUEVO ------------------ */
#[On('create-prospecto')]
public function createProspecto()
{
$this->resetForm();
$this->dispatch('open-prospecto-modal');
}
/* ------------------ SELECTS ------------------ */
public function updatedPplantels()
{
$this->selectedNivel = null;
$this->selectedplan = null;
$this->plans = [];
$this->niveles = Nivel::whereHas('nivelPlantel', fn($q) =>
$q->where('plantels.id', $this->pplantels)
)->get();
$this->turnos = Turno::whereHas('turnoPlantel', fn($q) =>
$q->where('plantels.id', $this->pplantels)
)->get();
}
public function updatedSelectedNivel()
{
if (!$this->selectedNivel || !$this->pplantels) {
$this->plans = [];
$this->active = "disabled";
return;
}
$this->plans = Plan::where('nivel', $this->selectedNivel)
->whereHas('planesPlantel', fn($q) =>
$q->where('plantels.id', $this->pplantels)
)->get();
$this->active = "";
}
/* ------------------ GUARDAR ------------------ */
public function guardarProspecto()
{
if (User::where('email', $this->pemail)
->orWhere('telefono', $this->ptelefono)
->exists()) {
$this->dispatch('swal:error', [
'title' => 'Registro duplicado',
'text' => 'El correo o teléfono ya están registrados.'
]);
return;
}
$user = User::create([
'name' => $this->pname,
'email' => $this->pemail,
'telefono' => $this->ptelefono,
'direccion' => $this->pdireccion,
'password' => Hash::make($this->ppassword),
'status' => 1
]);
$user->roles()->sync($this->proles);
$user->plantelUsuarios()->sync([$this->pplantels]);
$prospecto = Prospecto::create([
'nivel' => $this->selectedNivel,
'plan_id' => $this->selectedplan,
'usuario_registro' => Auth::id(),
'ciclo' => $this->pciclo,
'turno' => $this->pturno,
'medio' => $this->pmedio,
]);
$prospecto->prospectos()->sync([$user->id]);
$this->dispatch('swal:success');
$this->dispatch('prospecto-creado');
$this->resetForm();
}
/* ------------------ RENDER ------------------ */
public function render()
{
return view('livewire.modal-prospecto', [
'roles' => Role::whereHas('areas', fn($q) => $q->where('areas.name', 'Promoción'))->get(),
'plantels'=> Plantel::all(),
'user' => Auth::user(),
'campans' => Campan::all(),
'medios' => Medio::all(),
]);
}
}