You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
162 lines
3.6 KiB
162 lines
3.6 KiB
1 year ago
|
<?php
|
||
|
|
||
|
namespace App\Http\Controllers\Administracion;
|
||
|
|
||
|
use App\Http\Controllers\Controller;
|
||
|
use App\Models\ArchivosNominas;
|
||
|
use App\Models\Empleados;
|
||
|
use App\Models\ExpirarContrasena;
|
||
|
use App\Models\User;
|
||
|
use Carbon\Carbon;
|
||
|
use Illuminate\Http\Request;
|
||
|
use Illuminate\Support\Facades\Auth;
|
||
|
use Illuminate\Support\Facades\Storage;
|
||
|
|
||
|
|
||
|
class EmpresasController extends Controller
|
||
|
{
|
||
|
/**
|
||
|
* Create a new controller instance.
|
||
|
*
|
||
|
* @return void
|
||
|
*/
|
||
|
public function __construct()
|
||
|
{
|
||
|
$this->middleware('auth');
|
||
|
}
|
||
|
|
||
|
|
||
|
public function index()
|
||
|
{
|
||
|
|
||
|
|
||
|
return view('administracion/empresas');
|
||
|
|
||
|
}
|
||
|
|
||
|
public function nuevoUsuario( Request $request ){
|
||
|
|
||
|
$datosUsuario = $request->usuario;
|
||
|
$datosEmpleado = $request->empleado;
|
||
|
|
||
|
$datosUsuario['password'] = bcrypt('123456');
|
||
|
|
||
|
$nuevoUsuario = User::create( $datosUsuario );
|
||
|
|
||
|
$datosEmpleado['fk_id_users'] = $nuevoUsuario->id;
|
||
|
|
||
|
Empleados::create( $datosEmpleado );
|
||
|
|
||
|
ExpirarContrasena::create([
|
||
|
|
||
|
'fk_id_users' => $nuevoUsuario->id,
|
||
|
'dias_expiracion' => 0,
|
||
|
'ultima_actualizacion' => Carbon::now()
|
||
|
|
||
|
]);
|
||
|
|
||
|
return 'Exito papuus';
|
||
|
|
||
|
}
|
||
|
|
||
|
public function editarUsuario( Request $request ){
|
||
|
|
||
|
$datosEmpleado = $request->empleado;
|
||
|
|
||
|
User::where('id',$request->usuario['id'])->update($request->usuario );
|
||
|
|
||
|
$datosEmpleado['fk_id_users'] = $request->usuario['id'];
|
||
|
Empleados::updateOrCreate( $datosEmpleado ) ;
|
||
|
|
||
|
|
||
|
return 'Exito papuus';
|
||
|
|
||
|
}
|
||
|
|
||
|
public function eliminarUsuario( Request $request ){
|
||
|
|
||
|
|
||
|
User::where('id',$request->id)->update([
|
||
|
'activo' => 0,
|
||
|
'eliminado' => 1
|
||
|
]);
|
||
|
|
||
|
return 'Exito';
|
||
|
|
||
|
}
|
||
|
|
||
|
public function cargarListasUsuarios(Request $request){
|
||
|
|
||
|
|
||
|
$fileContpaq = $this->convertirExcelArray($request->file('files'));
|
||
|
$this->generarUsuarios( $fileContpaq, $request) ;
|
||
|
|
||
|
return 'exito!!!';
|
||
|
|
||
|
}
|
||
|
|
||
|
public function convertirExcelArray($file){
|
||
|
|
||
|
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
|
||
|
$reader->setReadDataOnly(true);
|
||
|
$excel = $reader->load($file);
|
||
|
$sheet = $excel->getSheet(0);
|
||
|
$sheetData = $sheet->toArray(null, false, true, true);
|
||
|
|
||
|
return $sheetData;
|
||
|
|
||
|
}
|
||
|
|
||
|
public function generarUsuarios($file, $request )
|
||
|
{
|
||
|
|
||
|
|
||
|
|
||
|
foreach ($file as $row => $val){
|
||
|
|
||
|
if( $row > 1 ){
|
||
|
|
||
|
if( !is_null($val['A']) && !is_null($val['B']) ){
|
||
|
|
||
|
$nuevoUsuario = User::create([
|
||
|
'name' => $val['B'],
|
||
|
'fk_id_roles' => 3,
|
||
|
'fk_id_grupos' => 0,
|
||
|
'email' => $val['B'],
|
||
|
'password' => bcrypt('123456'),
|
||
|
]);
|
||
|
|
||
|
Empleados::create([
|
||
|
'clave_contpaq' => $val['A'],
|
||
|
'nombre_completo' => $val['B'],
|
||
|
'fk_id_users' => $nuevoUsuario->id
|
||
|
]);
|
||
|
|
||
|
ExpirarContrasena::create([
|
||
|
|
||
|
'fk_id_users' => $nuevoUsuario->id,
|
||
|
'dias_expiracion' => 0,
|
||
|
'ultima_actualizacion' => Carbon::now()
|
||
|
|
||
|
]);
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return 'Exito';
|
||
|
|
||
|
}
|
||
|
|
||
|
public function expirarContrasena( Request $request ){
|
||
|
|
||
|
ExpirarContrasena::where('fk_id_users',$request->id)->update(['dias_expiracion' => 0]);
|
||
|
|
||
|
User::where('id',$request->id)->update(['password' => bcrypt('123456')]);
|
||
|
|
||
|
}
|
||
|
|
||
|
}
|