diff --git a/app/Http/Livewire/Import.php b/app/Http/Livewire/Import.php index 8a2aa25..a66ea08 100644 --- a/app/Http/Livewire/Import.php +++ b/app/Http/Livewire/Import.php @@ -1,6 +1,7 @@ photo); - $this->photo=null; + $data = Excel::import(new UsersImport, $this->photo); + $this->photo = null; $this->importado = 'true'; // aquí se puede procesar los datos obtenidos } diff --git a/app/Http/Livewire/ShowPlanes.php b/app/Http/Livewire/ShowPlanes.php index d3034b0..46edcbb 100644 --- a/app/Http/Livewire/ShowPlanes.php +++ b/app/Http/Livewire/ShowPlanes.php @@ -222,17 +222,6 @@ class ShowPlanes extends Component /* ------------- CREAR ------------- */ public function createNewCuenta() { - // $this->validate([ - // 'servicio_newCuenta' => 'required', - // 'usuario_newCuenta' => 'required', - // 'password_newCuenta' => 'required', - // 'fecha_inicial' => 'required', - // 'fecha_final' => 'required', - // 'estado' => 'required', - // ]); - - - if ($consulta_cuenta = Cuentas::where('correo', $this->usuario_newCuenta)->exists()) { $this->alert('warning', 'La cuenta ya existe', [ 'position' => 'top' diff --git a/app/Http/Livewire/ShowPromociones.php b/app/Http/Livewire/ShowPromociones.php index 39736ff..4b312bf 100644 --- a/app/Http/Livewire/ShowPromociones.php +++ b/app/Http/Livewire/ShowPromociones.php @@ -289,6 +289,7 @@ class ShowPromociones extends Component ]); } $cuenta = null; + $this->modalComprarPromo = false; } } if (count($this->f) > 0) { diff --git a/app/Imports/UsersImport.php b/app/Imports/UsersImport.php index 3184239..0b47e57 100644 --- a/app/Imports/UsersImport.php +++ b/app/Imports/UsersImport.php @@ -1,53 +1,74 @@ $row[0], - 'password'=> $row[1], - 'estado'=> $row[2], - 'inicio'=> \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($row[3]), - 'vencimiento'=> \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($row[4]), - 'servicio_id'=> $row[5], - + $cuenta = new Cuentas([ + 'correo' => $row[0], + 'password' => $row[1], + 'estado' => $row[2], + 'inicio' => \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($row[3]), + 'vencimiento' => \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($row[4]), + 'servicio_id' => $row[5], ]); - + + $cuenta->save(); + + // Aquí realizamos operaciones similares a las cuentas manuales + if ($row[2] === 'activo') { + $servicioPantallas = Servicio::find($row[5])->pantallas; + + $cuentasPendientes = Pendientes::where('estado', 'pendiente') + ->where('servicio_id', $row[5]) + ->take($servicioPantallas) + ->get(); + + foreach ($cuentasPendientes as $i => $cuentaPendiente) { + $historial_cuenta = new Historial_cuenta(); + $historial_cuenta->historial_id = $cuentaPendiente->historial_id; + $historial_cuenta->cuenta_id = $cuenta->id; + $historial_cuenta->perfil = $i + 1; + $historial_cuenta->save(); + $cuentaPendiente->update(['estado' => 'cerrado']); + } + } + + return $cuenta; } public function headingRow(): int { return 1; } - + public function batchSize(): int { return 1000; } - + public function chunkSize(): int { return 1000; } - + public function getDateFormats(): array { return [ - 'Y-m-d', - ]; } } diff --git a/resources/views/livewire/import.blade.php b/resources/views/livewire/import.blade.php index 065ac5d..6b4eda1 100644 --- a/resources/views/livewire/import.blade.php +++ b/resources/views/livewire/import.blade.php @@ -1,27 +1,40 @@