| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698 |
- <?php
- /*
- Nombre del programador: Cordourier Rojas Mathew
- Ultima fecha de modificación: [ 24 / Marzo / 2023 ]
- Descripción: Controlador del submodulo Personal. Perteneciente al Módulo 13 - Gestion del Personal de Mantenimiento
- */
- namespace App\Http\Controllers;
- use Carbon\Carbon;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Storage;
- use Illuminate\Support\Facades\Validator;
- use PhpOffice\PhpSpreadsheet\IOFactory;
- use PhpOffice\PhpSpreadsheet\Spreadsheet;
- use stdClass;
- use Throwable;
- class EmployeeController extends Controller
- {
- private $response_controller;
- private $encrypt_controller;
- private $documents_controller;
- public function __construct()
- {
- $this->response_controller = new ResponseController();
- $this->encrypt_controller = new EncryptionController();
- $this->documents_controller = new DocumentsController();
- }
- // Metodo para obtener datos del personal
- public function getConsultOfEmployees($line_number)
- {
- try {
- $employees = DB::table('S002V01TPERS')
- ->select(
- 'S002V01TPERS.PERS_IDPE as ID_EMPLOYEE',
- DB::raw('TRIM(CONCAT(S002V01TUSUA.USUA_NOMB, " " , S002V01TUSUA.USUA_APPA, " ", COALESCE(S002V01TUSUA.USUA_APMA,""))) as NAME'),
- 'S002V01TPERS.PERS_TICO as CONTRACT_TYPE',
- 'S002V01TPERS.PERS_ESPE as SPECIALITY',
- 'S002V01TPERS.PERS_FERE as REGISTER_DATE',
- 'S002V01TPERS.PERS_USRE as REGISTERED_BY_USER',
- 'S002V01TPERS.PERS_FEMO as UPDATE_DATE',
- 'S002V01TPERS.PERS_USMO as UPDATED_BY_USER',
- 'S002V01TPERS.PERS_ESTA as STATUS'
- )
- // ->where('S002V01TPERS.PERS_ESTA', '=', 'Activo')
- ->where('S002V01TPERS.PERS_NULI', '=', $line_number)
- ->where('S002V01TUSUA.USUA_NULI', '=', $line_number)
- ->join('S002V01TUSUA', 'S002V01TPERS.PERS_IDUS', '=', 'S002V01TUSUA.USUA_IDUS')
- ->get();
- // Verifica si el objeto esta vacio
- if (!isset($employees[0]) && empty($employees[0])) {
- return $this->response_controller
- ->makeResponse(TRUE, 'ERR_PERSONAL_REG001: No se encontraron datos', $employees, 500);
- }
- $users = DB::table('S002V01TUSUA')
- ->select('USUA_IDUS as ID', DB::raw('TRIM(CONCAT(USUA_NOMB, " " , USUA_APPA, " ", COALESCE(USUA_APMA,""))) as NAME'))
- ->where('USUA_NULI', '=', $line_number)
- ->get();
- // Verifica si el objeto esta vacio
- if (!isset($users[0]) && empty($users[0])) {
- return $this->response_controller
- ->makeResponse(TRUE, 'ERR_USUARIO_REG002: No se encontraron datos', $users, 500);
- }
- $workteams = DB::table('S002V01TEQMA')
- ->select('S002V01TEQMA.EQMA_NOMB as NAME', 'S002V01TPEEM.PEEM_IDPE as ID_EMPLOYEE')
- ->where('S002V01TEQMA.EQMA_NULI', '=', $line_number)
- ->where('S002V01TPEEM.PEEM_NULI', '=', $line_number)
- ->join('S002V01TPEEM', 'S002V01TEQMA.EQMA_IDEQ', '=', 'S002V01TPEEM.PEEM_IDEM')
- ->get();
- // Verifica si el objeto esta vacio
- if (!isset($workteams[0]) && empty($workteams[0])) {
- return $this->response_controller
- ->makeResponse(TRUE, 'ERR_EQUIPO_TRABAJO_REG003: No se encontraron datos', $workteams, 500);
- }
- foreach ($employees as $employee) {
- // Introduce los equipos de trabajo a los que pertenece
- foreach ($workteams as $workteam) {
- if ($employee->ID_EMPLOYEE == $workteam->ID_EMPLOYEE) {
- $employee->WORKTEAMS = $workteam->NAME;
- }
- }
- // Introduce la persona que lo registro
- foreach ($users as $user) {
- if ($employee->REGISTERED_BY_USER == $user->ID) {
- $employee->REGISTERED_BY_USER = $user->NAME;
- }
- // Si hubo actualización, introduce a la persona que lo actualizo
- if ($employee->UPDATED_BY_USER != null) {
- if ($employee->UPDATED_BY_USER == $user->ID) {
- $employee->UPDATED_BY_USER = $user->NAME;
- }
- }
- }
- // Introduce la fecha en que se registro y actualizo al empleado (si hubo actualización)
- $employee->REGISTER_DATE = Carbon::create($employee->REGISTER_DATE)->format("d-m-Y h:i:s A");
- if ($employee->UPDATE_DATE != null) {
- $employee->UPDATE_DATE = Carbon::create($employee->UPDATE_DATE)->format("d-m-Y h:i:s A");
- }
- }
- return $this->response_controller
- ->makeResponse(FALSE, "Consulta exitosa", $employees);
- } catch (Throwable $th) {
- return $this->response_controller
- ->makeResponse(TRUE, 'ERR_PERSONAL_REG004: Error inesperado', strtoupper($th->getMessage()), 500);
- }
- }
- // Metodo para ver el listado de documentos de un empleado
- public function getDocumentsByEmployee($id_employee, $line_number)
- {
- try {
- // Busca si existe el empleado
- $employee_found = DB::table('S002V01TPERS')
- ->select('PERS_IDPE')
- ->where('PERS_IDPE', '=', $id_employee)
- ->where('PERS_NULI', '=', $line_number)
- ->first();
- // Verifica si el objeto esta vacio
- if (!isset($employee_found) && empty($employee_found)) {
- return $this->response_controller
- ->makeResponse(TRUE, 'ERR_PERSONAL_REG001: No se encontró al empleado', [], 500);
- }
- // Busca si el empleado tiene documentos
- $documents_by_employee = DB::table('S002V01TDOCU_P')
- ->select('DOCU_LIDO as DOCUMENT_LINK')
- ->where('DOCU_IDPE', '=', $id_employee)
- ->where('DOCU_NULI', '=', $line_number)
- ->get();
- // Verifica si el objeto esta vacio
- if (!isset($documents_by_employee[0]) && empty($documents_by_employee[0])) {
- return $this->response_controller
- ->makeResponse(FALSE, 'El empleado no tiene documentos', []);
- }
- // Encripta la liga de cada documento
- foreach ($documents_by_employee as $doc) {
- $doc->DOCUMENT_NAME = $doc->DOCUMENT_LINK;
- $doc->DOCUMENT_LINK = Storage::disk('pdf')->url($doc->DOCUMENT_LINK);
- $doc->DOCUMENT_LINK = $this->encrypt_controller->encrypt($doc->DOCUMENT_LINK);
- }
- return $this->response_controller
- ->makeResponse(FALSE, "Consulta exitosa", $documents_by_employee);
- } catch (Throwable $th) {
- return $this->response_controller
- ->makeResponse(TRUE, 'ERR_PERSONAL_REG003: Error inesperado', strtoupper($th->getMessage()), 500);
- }
- }
- public function getLastDocumentsByEmployee($id_employee, $line_number)
- {
- try {
- // Busca si existe el empleado
- $employee_found = DB::table('S002V01TPERS')
- ->select('PERS_IDPE')
- ->where('PERS_IDPE', '=', $id_employee)
- ->where('PERS_NULI', '=', $line_number)
- ->first();
- // Verifica si el objeto esta vacio
- if (!isset($employee_found) && empty($employee_found)) {
- return $this->response_controller
- ->makeResponse(TRUE, 'ERR_PERSONAL_REG001: No se encontró al empleado', [], 500);
- }
- // Busca si el empleado tiene documentos
- $documents_by_employee = DB::table('S002V01TDOCU_P')
- ->select('DOCU_LIDO as DOCUMENT_LINK', 'DOCU_NUSE as SEQUENCE')
- ->where('DOCU_IDPE', '=', $id_employee)
- ->where('DOCU_NULI', '=', $line_number)
- ->get();
- // Busca los numeros de secuencia
- $documents_sequence = DB::table('S002V01TDOCU_P')
- ->select('DOCU_NUSE as SEQUENCE')
- ->where('DOCU_IDPE', '=', $id_employee)
- ->where('DOCU_NULI', '=', $line_number)
- ->groupBy('DOCU_NUSE')
- ->get();
- $test = [];
- for ($i = 0; $i < sizeof($documents_sequence); $i++) {
- foreach ($documents_by_employee as $doc) {
- if ($doc->SEQUENCE == $documents_sequence[$i]->SEQUENCE) {
- if (isset($test[$i]) && !empty($test[$i])) {
- if (substr($doc->DOCUMENT_LINK, 25, 2) > substr($test[$i], 25, 2)) {
- $test[$i] = $doc->DOCUMENT_LINK;
- }
- } else {
- $test[$i] = $doc->DOCUMENT_LINK;
- }
- }
- }
- }
- return $this->response_controller
- ->makeResponse(FALSE, "Consulta exitosa", $test);
- } catch (Throwable $th) {
- return $this->response_controller
- ->makeResponse(TRUE, 'ERR_PERSONAL_REG003: Error inesperado', strtoupper($th->getMessage()), 500);
- }
- }
- // Metodo para obtener todas las intervenciones relacionadas a un empleado
- public function getInterventionsByEmployee($id_employee, $line_number)
- {
- try {
- // Verifica si el empleado existe
- $employee_exist = DB::table('S002V01TPERS')
- ->select('PERS_IDPE')
- ->where('PERS_IDPE', '=', $id_employee)
- ->where('PERS_NULI', '=', $line_number)
- ->first();
- // Verifica si el objeto esta vacio
- if (!isset($employee_exist) && empty($employee_exist)) {
- return $this->response_controller
- ->makeResponse(TRUE, 'ERR_PERSONAL_REG001: No se encontró al empleado', [], 500);
- }
- // Obtiene las intervenciones del empleado
- $employee_interventions = DB::table('S002V01TPERS')
- ->select(
- 'S002V01TEQMA.EQMA_NOMB as WORKTEAM_NAME',
- 'S002V01TINTE_P.INTE_NOMB as INTERVENTION_NAME',
- 'S002V01TEQMA.EQMA_NOMB as WORKTEAM_NAME',
- 'S002V01TINTE_P.INTE_IDIN as INTERVENTION_ID',
- 'S002V01TINTE_P.INTE_DESC as INTERVENTION_DESCRIPTION',
- )
- ->where('S002V01TPERS.PERS_IDPE', '=', $id_employee)
- ->where('S002V01TPERS.PERS_NULI', '=', $line_number)
- ->where('S002V01TPEEM.PEEM_NULI', '=', $line_number)
- ->where('S002V01TEQMA.EQMA_NULI', '=', $line_number)
- ->where('S002V01TEMIN.EMIN_NULI', '=', $line_number)
- ->where('S002V01TINTE_P.INTE_NULI', '=', $line_number)
- ->join('S002V01TPEEM', 'S002V01TPERS.PERS_IDPE', '=', 'S002V01TPEEM.PEEM_IDPE')
- ->join('S002V01TEQMA', 'S002V01TPEEM.PEEM_IDEM', '=', 'S002V01TEQMA.EQMA_IDEQ')
- ->join('S002V01TEMIN', 'S002V01TEQMA.EQMA_IDEQ', '=', 'S002V01TEMIN.EMIN_IDEM')
- ->join('S002V01TINTE_P', 'S002V01TEMIN.EMIN_IDIN', '=', 'S002V01TINTE_P.INTE_IDIN')
- ->get();
- // Verifica si el objeto esta vacio
- if (!isset($employee_interventions[0]) && empty($employee_interventions[0])) {
- return $this->response_controller
- ->makeResponse(TRUE, 'ERR_PERSONAL_REG002: El empleado no tiene intervenciones', [], 500);
- }
- return $this->response_controller
- ->makeResponse(FALSE, "Consulta exitosa", $employee_interventions);
- } catch (Throwable $th) {
- return $this->response_controller
- ->makeResponse(TRUE, 'ERR_PERSONAL_REG003: Error inesperado', strtoupper($th->getMessage()), 500);
- }
- }
- // Metodo para la eliminación logica de un empleado
- public function updateToInactiveStatus(Request $request, $id_employee)
- {
- try {
- $request['SAVED_BY_USER'] = $this->encrypt_controller->decrypt($request->SAVED_BY_USER);
- $validator = Validator::make($request->all(), [
- "SAVED_BY_USER" => ['required', 'digits:10']
- ]);
- if ($validator->fails()) {
- return $this->response_controller->makeResponse(
- TRUE,
- 'ERR_PERSONAL_REG001: Uno o más errores encontrados',
- $this->response_controller->makeErrors($validator->errors()->messages()),
- 400
- );
- }
- // Busca si el empleado existe
- $search_employee = DB::table("S002V01TPERS")
- ->select("PERS_IDPE")
- ->where("PERS_IDPE", "=", $id_employee)
- ->where('PERS_NULI', '=', $request->LINE_NUMBER)
- ->first();
- // Verifica si el objeto esta vacio
- if (!isset($search_employee) && empty($search_employee)) {
- return $this->response_controller
- ->makeResponse(TRUE, "ERR_PERSONAL_REG002: No se encontró al empleado", $search_employee, 500);
- }
- $user_register = DB::table('S002V01TUSUA')
- ->select('USUA_IDUS as ID_USER')
- ->where('USUA_IDUS', '=', $request->SAVED_BY_USER)
- ->where('USUA_NULI', '=', $request->LINE_NUMBER)
- ->first();
- // Verifica si el objeto esta vacio
- if (!isset($user_register) && empty($user_register)) {
- return $this->response_controller
- ->makeResponse(TRUE, "ERR_USUARIO_REG003: Tu usuario no es válido para eliminar empleados", [], 500);
- }
- // Busca si el empleado tiene intervenciones activas
- $search_employee = DB::table("S002V01TPERS")
- ->select("S002V01TINTE_P.INTE_NOMB")
- ->where("S002V01TPERS.PERS_IDPE", "=", $id_employee)
- ->where("S002V01TINTE_P.INTE_ESTA", "=", "Activo")
- ->where("S002V01TEMIN.EMIN_ESTA", "=", "Activo")
- ->where("S002V01TPERS.PERS_NULI", "=", $request->LINE_NUMBER)
- ->where('S002V01TPEEM.PEEM_NULI', '=', $request->LINE_NUMBER)
- ->where('S002V01TEQMA.EQMA_NULI', '=', $request->LINE_NUMBER)
- ->where('S002V01TEMIN.EMIN_NULI', '=', $request->LINE_NUMBER)
- ->where('S002V01TINTE_P.INTE_NULI', '=', $request->LINE_NUMBER)
- ->groupBy('S002V01TINTE_P.INTE_NOMB')
- ->join("S002V01TPEEM", "S002V01TPERS.PERS_IDPE", "=", "S002V01TPEEM.PEEM_IDPE")
- ->join("S002V01TEQMA", "S002V01TPEEM.PEEM_IDEM", "=", "S002V01TEQMA.EQMA_IDEQ")
- ->join("S002V01TEMIN", "S002V01TEQMA.EQMA_IDEQ", "=", "S002V01TEMIN.EMIN_IDEM")
- ->join("S002V01TINTE_P", "S002V01TEMIN.EMIN_IDIN", "=", "S002V01TINTE_P.INTE_IDIN")
- ->get();
- // Verifica si el objeto contiene algo
- if (isset($search_employee[0]) && !empty($search_employee[0])) {
- return $this->response_controller
- ->makeResponse(TRUE, "ERR_PERSONAL_REG004: Empleado ocupado con intervenciones", $search_employee, 500);
- } else {
- DB::beginTransaction(); # Para impedir que las actualizaciones queden incompletas
- $UPDATE_DATE = Carbon::now()->timezone('America/Mexico_City')->toDateTimeString();
- $delete_employee = DB::table('S002V01TPERS')
- ->where('PERS_IDPE', $id_employee)
- ->where('PERS_NULI', '=', $request->LINE_NUMBER)
- ->update([
- "PERS_ESTA" => "Eliminado",
- "PERS_USMO" => trim($request->SAVED_BY_USER),
- "PERS_FEMO" => $UPDATE_DATE,
- "PERS_FEAR" => DB::raw('CURRENT_TIMESTAMP')
- ]);
- // Verifica que la actualización fuera exitosa
- if ($delete_employee < 1) {
- return $this->response_controller
- ->makeResponse(TRUE, 'ERR_PERSONAL_REG005: Algo salió mal, error eliminando al empleado', [], 500);
- }
- $delete_employee = DB::table('S002V01TPEEM')
- ->where('PEEM_IDPE', $id_employee)
- ->where('PEEM_NULI', '=', $request->LINE_NUMBER)
- ->update([
- "PEEM_ESTA" => "Eliminado",
- "PEEM_USMO" => trim($request->SAVED_BY_USER),
- "PEEM_FEMO" => $UPDATE_DATE,
- "PEEM_FEAR" => DB::raw('CURRENT_TIMESTAMP')
- ]);
- // Verifica que la actualización fuera exitosa
- if ($delete_employee < 1) {
- DB::rollBack(); # Si no se logra eliminar al empleado en el equipo, se revierten los cambios previos
- return $this->response_controller
- ->makeResponse(TRUE, 'ERR_PERSONAL_REG006: Algo salió mal, error eliminando al empleado del equipo', [], 500);
- }
- }
- DB::commit(); # Para guardar los cambios en la base de datos
- return $this->response_controller->makeResponse(FALSE, "Eliminado exitoso");
- } catch (Throwable $th) {
- return $this->response_controller
- ->makeResponse(TRUE, 'ERR_PERSONAL_REG007: Error inesperado', strtoupper($th->getMessage()), 500);
- }
- }
- // Metodo para la activación logica de un empleado
- public function updateToActiveStatus(Request $request, $id_employee)
- {
- try {
- $request['SAVED_BY_USER'] = $this->encrypt_controller->decrypt($request->SAVED_BY_USER);
- $validator = Validator::make($request->all(), [
- "SAVED_BY_USER" => ['required', 'digits:10']
- ]);
-
- if ($validator->fails()) {
- return $this->response_controller->makeResponse(
- TRUE,
- 'ERR_PERSONAL_REG001: Uno o más errores encontrados',
- $this->response_controller->makeErrors($validator->errors()->messages()),
- 400
- );
- }
-
- // Busca si el empleado existe
- $search_employee = DB::table("S002V01TPERS")
- ->select("PERS_IDPE")
- ->where("PERS_IDPE", "=", $id_employee)
- ->where('PERS_NULI', '=', $request->LINE_NUMBER)
- ->first();
-
- // Verifica si el objeto esta vacio
- if (!isset($search_employee) && empty($search_employee)) {
- return $this->response_controller
- ->makeResponse(TRUE, "ERR_PERSONAL_REG002: No se encontró al empleado", $search_employee, 500);
- }
-
- $user_register = DB::table('S002V01TUSUA')
- ->select('USUA_IDUS as ID_USER')
- ->where('USUA_IDUS', '=', $request->SAVED_BY_USER)
- ->where('USUA_NULI', '=', $request->LINE_NUMBER)
- ->first();
-
- // Verifica si el objeto esta vacio
- if (!isset($user_register) && empty($user_register)) {
- return $this->response_controller
- ->makeResponse(TRUE, "ERR_USUARIO_REG003: Tu usuario no es válido para activar empleados", [], 500);
- }
-
- $check_workteam = DB::table("S002V01TEQMA")
- ->select("S002V01TEQMA.EQMA_ESTA as STATUS")
- ->where("S002V01TPEEM.PEEM_IDPE", '=', $id_employee)
- ->join('S002V01TPEEM', 'S002V01TEQMA.EQMA_IDEQ', '=', 'S002V01TPEEM.PEEM_IDEM')
- ->first();
-
- if($check_workteam->STATUS == "Eliminado"){
- return $this->response_controller
- ->makeResponse(TRUE, "ERR_EQUIPO_TRABAJO_REG004: El equipo de trabajo no esta activo", [], 500);
- }
-
- DB::beginTransaction(); # Para impedir que las actualizaciones queden incompletas
-
- $UPDATE_DATE = Carbon::now()->timezone('America/Mexico_City')->toDateTimeString();
-
- $activate_employee = DB::table('S002V01TPERS')
- ->where('PERS_IDPE', $id_employee)
- ->where('PERS_NULI', '=', $request->LINE_NUMBER)
- ->update([
- "PERS_ESTA" => "Activo",
- "PERS_USMO" => trim($request->SAVED_BY_USER),
- "PERS_FEMO" => $UPDATE_DATE,
- "PERS_FEAR" => DB::raw('CURRENT_TIMESTAMP')
- ]);
-
- // Verifica que la actualización fuera exitosa
- if ($activate_employee < 1) {
- return $this->response_controller
- ->makeResponse(TRUE, 'ERR_PERSONAL_REG005: Algo salió mal, error activando al empleado', [], 500);
- }
-
- $activate_employee = DB::table('S002V01TPEEM')
- ->where('PEEM_IDPE', $id_employee)
- ->where('PEEM_NULI', '=', $request->LINE_NUMBER)
- ->update([
- "PEEM_ESTA" => "Activo",
- "PEEM_USMO" => trim($request->SAVED_BY_USER),
- "PEEM_FEMO" => $UPDATE_DATE,
- "PEEM_FEAR" => DB::raw('CURRENT_TIMESTAMP')
- ]);
-
- // Verifica que la actualización fuera exitosa
- if ($activate_employee < 1) {
- DB::rollBack(); # Si no se logra eliminar al empleado en el equipo, se revierten los cambios previos
- return $this->response_controller
- ->makeResponse(TRUE, 'ERR_PERSONAL_REG006: Algo salió mal, error activando al empleado del equipo', [], 500);
- }
-
- DB::commit(); # Para guardar los cambios en la base de datos
- return $this->response_controller->makeResponse(FALSE, "Activación exitosa");
-
- } catch (Throwable $th) {
- return $this->response_controller->
- makeResponse(TRUE, 'ERR_PERSONAL_REG007: Error inesperado', strtoupper($th->getMessage()), 500);
- }
- }
- // Metodo para obtener a los usuarios que no son empleados y el enviado por path
- public function getAvaibleUsers($id_employee, $line_number)
- {
- try {
- // Busca en la base si existe otro empleado con ese usuario
- $users = DB::table('S002V01TUSUA')
- ->select(
- DB::raw('TRIM(CONCAT(USUA_NOMB, " " , USUA_APPA, " ", COALESCE(USUA_APMA,""))) as NAME'),
- "USUA_IDUS as ID_USER"
- )
- ->orderBy('NAME', 'asc')
- ->where('USUA_NULI', '=', $line_number)
- ->where('USUA_ESTA', '=', "Activo")
- ->get();
- $employees = DB::table('S002V01TPERS')
- ->select("PERS_IDUS as ID_USER")
- ->where('PERS_NULI', '=', $line_number)
- ->get();
- $avaibleUsers = [];
- foreach ($users as $user) {
- foreach ($employees as $employee) {
- if ($user->ID_USER == $employee->ID_USER) {
- $user->ID_USER = "XXXX";
- }
- }
- if ($user->ID_USER != "XXXX") {
- $avaibleUsers[] = $user;
- }
- }
- // Busca en la base el empleado requerido
- if ($id_employee != "0") {
- $employeSelected = DB::table('S002V01TPERS')
- ->select(
- DB::raw('TRIM(CONCAT(S002V01TUSUA.USUA_NOMB, " " , S002V01TUSUA.USUA_APPA, " ", COALESCE(S002V01TUSUA.USUA_APMA,""))) as NAME'),
- "S002V01TUSUA.USUA_IDUS as ID_USER"
- )
- ->where('S002V01TUSUA.USUA_NULI', '=', $line_number)
- ->where('S002V01TPERS.PERS_NULI', '=', $line_number)
- ->where('S002V01TPERS.PERS_IDPE', '=', $id_employee)
- ->join('S002V01TUSUA', 'S002V01TPERS.PERS_IDUS', '=', 'S002V01TUSUA.USUA_IDUS')
- ->first();
- $avaibleUsers[] = $employeSelected;
- }
- // Verifica si el objeto contiene algo
- if (!isset($users) && empty($users)) {
- return $this->response_controller
- ->makeResponse(TRUE, 'ERR_USUARIO_REG001: No se encontraron datos', [], 500);
- }
- return $this->response_controller->makeResponse(FALSE, 'Usuarios obtenidos', $avaibleUsers, 200);
- } catch (Throwable $th) {
- return $this->response_controller
- ->makeResponse(TRUE, 'ERR_PERSONAL_REG004: Error inesperado', strtoupper($th), 500);
- }
- }
- // Metodo para guardar un nuevo empleado
- public function storeEmployee(Request $request)
- {
- try {
- $REGISTER_DATE = Carbon::now()->timezone('America/Mexico_City')->toDateTimeString();
- $request['SAVED_BY_USER'] = $this->encrypt_controller->decrypt($request->SAVED_BY_USER);
- $request['CONTACT_NAME'] = $this->encrypt_controller->decrypt($request->CONTACT_NAME);
- $request['CONTACT_TELEPHONE'] = $this->encrypt_controller->decrypt($request->CONTACT_TELEPHONE);
- $request['CONTACT_LADA'] = $this->encrypt_controller->decrypt($request->CONTACT_LADA);
- $request['CONTACT_ADDRESS'] = $this->encrypt_controller->decrypt($request->CONTACT_ADDRESS);
- $validator = Validator::make($request->all(), [
- "USER_ID" => ['required', 'digits:10'],
- "WORKTEAM_ID" => ['required', 'digits:10'],
- "CONTACT_NAME" => ['required', 'max:150'],
- "CONTACT_TELEPHONE" => ['required', 'max:11'],
- "CONTACT_LADA" => ['required', 'max:5'],
- "CONTACT_ADDRESS" => ['required', 'max:100'],
- "CONTRACT_TYPE" => ['required'],
- "SPECIALITY" => ['required', 'max:75'],
- "SUBCONTRATIST_ID" => ['max:10'],
- "SAVED_BY_USER" => ['required', 'digits:10'],
- "LINE_NUMBER" => ['required', 'digits:1']
- ]);
- if ($validator->fails()) {
- return $this->response_controller->makeResponse(
- TRUE,
- 'ERR_PERSONAL_REG001: Uno o más errores encontrados',
- $this->response_controller->makeErrors($validator->errors()->messages()),
- 400
- );
- }
- // Busca en la base si existe otro empleado con ese usuario
- $uniq_user = DB::table('S002V01TPERS')
- ->select("PERS_IDPE")
- ->where('PERS_IDUS', '=', $request->USER_ID)
- ->where('PERS_NULI', '=', $request->LINE_NUMBER)
- ->first();
- // Verifica si el objeto contiene algo
- if (isset($uniq_user) && !empty($uniq_user)) {
- return $this->response_controller
- ->makeResponse(TRUE, 'ERR_PERSONAL_REG002: El usuario ya está registrado como empleado', [], 500);
- }
- // Busca si el usuario existe
- $user_exist = DB::table('S002V01TUSUA')
- ->select("USUA_IDUS")
- ->where('USUA_IDUS', '=', $request->USER_ID)
- ->where('USUA_NULI', '=', $request->LINE_NUMBER)
- ->first();
- // Verifica si el objeto esta vacio
- if (!isset($user_exist) && empty($user_exist)) {
- return $this->response_controller
- ->makeResponse(TRUE, 'ERR_PERSONAL_REG003: No se encontró al usuario', [], 500);
- }
- // Busca si el equipo de trabajo existe
- $team_found = DB::table('S002V01TEQMA')
- ->select('EQMA_NOMB')
- ->where('EQMA_IDEQ', '=', $request->WORKTEAM_ID)
- ->where('EQMA_NULI', '=', $request->LINE_NUMBER)
- ->first();
- // Verifica si el objeto esta vacio
- if (!isset($team_found) && empty($team_found)) {
- return $this->response_controller
- ->makeResponse(TRUE, 'ERR_EQUIPO_TRABAJO_REG004: No se encontró al equipo de trabajo', [], 500);
- }
- $user_register = DB::table('S002V01TUSUA')
- ->select('USUA_IDUS as ID_USER')
- ->where('USUA_IDUS', '=', $request->SAVED_BY_USER)
- ->where('USUA_NULI', '=', $request->LINE_NUMBER)
- ->first();
- // Verifica si el objeto esta vacio
- if (!isset($user_register) && empty($user_register)) {
- return $this->response_controller
- ->makeResponse(TRUE, "ERR_USUARIO_REG005: Tu usuario no es válido para registrar empleados", [], 500);
- }
- DB::beginTransaction(); # Para impedir que las actualizaciones queden a incompletas
- $insert_employee = DB::table('S002V01TPERS')
- ->insert([
- "PERS_IDUS" => $request->USER_ID,
- "PERS_NOCE" => trim($request->CONTACT_NAME),
- "PERS_NUTC" => $request->CONTACT_TELEPHONE,
- "PERS_LATC" => $request->CONTACT_LADA,
- "PERS_DICE" => trim($request->CONTACT_ADDRESS),
- "PERS_TICO" => trim($request->CONTRACT_TYPE),
- "PERS_ESPE" => trim($request->SPECIALITY),
- "PERS_IDPS" => $request->SUBCONTRATIST_ID,
- "PERS_NULI" => $request->LINE_NUMBER,
- "PERS_ESTA" => "Activo",
- "PERS_USRE" => $request->SAVED_BY_USER,
- "PERS_FERE" => $REGISTER_DATE,
- "PERS_FEAR" => DB::raw('CURRENT_TIMESTAMP')
- ]);
- // Verifica que la inserción del empleado se haya hecho correctamente
- if (!$insert_employee) {
- return $this->response_controller
- ->makeResponse(TRUE, 'ERR_PERSONAL_REG006: Algo salió mal, error registrando al empleado', [], 500);
- }
- // Obtiene el ID del empleado registrado
- $employee_id = DB::table('S002V01TPERS')
- ->select('PERS_IDPE as EMPLOYEE_ID')
- ->where('PERS_IDUS', '=', $request->USER_ID)
- ->where('PERS_NULI', '=', $request->LINE_NUMBER)
- ->first();
- // Saca el ID del objeto
- $employee_id = $employee_id->EMPLOYEE_ID;
- $insert_employee_on_workteam = DB::table('S002V01TPEEM')
- ->insert([
- "PEEM_IDPE" => $employee_id,
- "PEEM_IDEM" => $request->WORKTEAM_ID,
- "PEEM_NULI" => $request->LINE_NUMBER,
- "PEEM_ESTA" => "Activo",
- "PEEM_USRE" => $request->SAVED_BY_USER,
- "PEEM_FERE" => $REGISTER_DATE,
- "PEEM_FEAR" => DB::raw('CURRENT_TIMESTAMP'),
- ]);
- // Verifica que la inserción del empleado en el equipo de trabajo se haya hecho correctamente
- if (!$insert_employee_on_workteam) {
- DB::rollBack(); # Si no se logra insertar al equipo, se revierten los cambios previos
- return $this->response_controller
- ->makeResponse(TRUE, 'ERR_EQUIPO_TRABAJO_REG007: Algo salió mal, error registrando al empleado en el equipo', [], 500);
- }
- // Verifica si el objeto esta vacio
- if (isset($request->DOCUMENTS_AUTHO) && !empty($request->DOCUMENTS_AUTHO)) {
- $doc = $request->DOCUMENTS_AUTHO;
- // Se obtiene el nombre del archivo con su extensión
- $completeFileName = $doc->getClientOriginalName();
- // Se obtiene únicamente el nombre
- $fileNameOnly = pathinfo($completeFileName, PATHINFO_FILENAME) . '-' . $employee_id;
- // Se obtiene la extensión del archivo
- $extension = $doc->getClientOriginalExtension();
- if ($extension != "pdf") {
- return $this->response_controller
- ->makeResponse(TRUE, 'ERR_DOCUMENTO_REG007: Solo se permiten archivos PDF', [], 500);
- }
- // Se quitan los espacios y se concatena datos para ser guardado
- $final_part_name_document = str_replace(' ', '_', $fileNameOnly) . '.' . $extension;
- $name_document = $this->documents_controller->createDocument(
- "GPRS",
- "IN",
- $final_part_name_document,
- $employee_id,
- 'pdf',
- $request->LINE_NUMBER,
- $request->SAVED_BY_USER
- );
- // El documento es guardado en el storage
- $doc->storeAs('public/pdf_documents', $name_document);
- }
- // Verifica si el objeto esta vacio
- if (isset($request->DOCUMENTS_AUTHO2) && !empty($request->DOCUMENTS_AUTHO2)) {
- $doc = $request->DOCUMENTS_AUTHO2;
- // Se obtiene el nombre del archivo con su extensión
- $completeFileName = $doc->getClientOriginalName();
- // Se obtiene únicamente el nombre
- $fileNameOnly = pathinfo($completeFileName, PATHINFO_FILENAME) . '-' . $employee_id;
- // Se obtiene la extensión del archivo
- $extension = $doc->getClientOriginalExtension();
- if ($extension != "pdf") {
- return $this->response_controller
- ->makeResponse(TRUE, 'ERR_DOCUMENTO_REG007: Solo se permiten archivos PDF', [], 500);
- }
- // Se quitan los espacios y se concatena datos para ser guardado
- $final_part_name_document = str_replace(' ', '_', $fileNameOnly) . '.' . $extension;
- $name_document = $this->documents_controller->createDocument(
- "GPRS",
- "IN",
- $final_part_name_document,
- $employee_id,
- 'pdf',
- $request->LINE_NUMBER,
- $request->SAVED_BY_USER
- );
- // El documento es guardado en el storage
- $doc->storeAs('public/pdf_documents', $name_document);
- }
- // Verifica si el objeto esta vacio
- if (isset($request->DOCUMENTS_CERT) && !empty($request->DOCUMENTS_CERT)) {
- $doc = $request->DOCUMENTS_CERT;
- // Se obtiene el nombre del archivo con su extensión
- $completeFileName = $doc->getClientOriginalName();
- // Se obtiene únicamente el nombre
- $fileNameOnly = pathinfo($completeFileName, PATHINFO_FILENAME) . '-' . $employee_id;
- // Se obtiene la extensión del archivo
- $extension = $doc->getClientOriginalExtension();
- if ($extension != "pdf") {
- return $this->response_controller
- ->makeResponse(TRUE, 'ERR_DOCUMENTO_REG007: Solo se permiten archivos PDF', [], 500);
- }
- // Se quitan los espacios y se concatena datos para ser guardado
- $final_part_name_document = str_replace(' ', '_', $fileNameOnly) . '.' . $extension;
- $name_document = $this->documents_controller->createDocument(
- "GPRS",
- "CE",
- $final_part_name_document,
- $employee_id,
- 'pdf',
- $request->LINE_NUMBER,
- $request->SAVED_BY_USER
- );
- // El documento es guardado en el storage
- $doc->storeAs('public/pdf_documents', $name_document);
- }
- // Verifica si el objeto esta vacio
- if (isset($request->DOCUMENTS_CERT2) && !empty($request->DOCUMENTS_CERT2)) {
- $doc = $request->DOCUMENTS_CERT2;
- // Se obtiene el nombre del archivo con su extensión
- $completeFileName = $doc->getClientOriginalName();
- // Se obtiene únicamente el nombre
- $fileNameOnly = pathinfo($completeFileName, PATHINFO_FILENAME) . '-' . $employee_id;
- // Se obtiene la extensión del archivo
- $extension = $doc->getClientOriginalExtension();
- if ($extension != "pdf") {
- return $this->response_controller
- ->makeResponse(TRUE, 'ERR_DOCUMENTO_REG007: Solo se permiten archivos PDF', [], 500);
- }
- // Se quitan los espacios y se concatena datos para ser guardado
- $final_part_name_document = str_replace(' ', '_', $fileNameOnly) . '.' . $extension;
- $name_document = $this->documents_controller->createDocument(
- "GPRS",
- "CE",
- $final_part_name_document,
- $employee_id,
- 'pdf',
- $request->LINE_NUMBER,
- $request->SAVED_BY_USER
- );
- // El documento es guardado en el storage
- $doc->storeAs('public/pdf_documents', $name_document);
- }
- // Verifica si el objeto esta vacio
- if (isset($request->DOCUMENT_OFFICE) && !empty($request->DOCUMENT_OFFICE)) {
- $doc = $request->DOCUMENT_OFFICE;
- // Se obtiene el nombre del archivo con su extensión
- $completeFileName = $doc->getClientOriginalName();
- // Se obtiene únicamente el nombre
- $fileNameOnly = pathinfo($completeFileName, PATHINFO_FILENAME) . '-' . $employee_id;
- // Se obtiene la extensión del archivo
- $extension = $doc->getClientOriginalExtension();
- if ($extension != "pdf") {
- return $this->response_controller
- ->makeResponse(TRUE, 'ERR_DOCUMENTO_REG007: Solo se permiten archivos PDF', [], 500);
- }
- // Se quitan los espacios y se concatena datos para ser guardado
- $final_part_name_document = str_replace(' ', '_', $fileNameOnly) . '.' . $extension;
- $name_document = $this->documents_controller->createDocument(
- "GPRS",
- "CO",
- $final_part_name_document,
- $employee_id,
- 'pdf',
- $request->LINE_NUMBER,
- $request->SAVED_BY_USER
- );
- // El documento es guardado en el storage
- $doc->storeAs('public/pdf_documents', $name_document);
- }
- DB::commit(); # Para guardar los cambios en la base de datos
- return $this->response_controller->makeResponse(FALSE, 'Creación exitosa', 200);
- } catch (Throwable $th) {
- return $this->response_controller
- ->makeResponse(TRUE, 'ERR_PERSONAL_REG008: Error inesperado', strtoupper($th), 500);
- }
- }
- // Metodo para obtener un empleado por id con sus documentos (Pensado: 1 empleado solo tiene un equipo de trabajo)
- public function getEmployeeById($id_employee, $line_number)
- {
- try {
- $employee = DB::table('S002V01TPERS')
- ->select(
- 'S002V01TPERS.PERS_IDPE as ID_EMPLOYEE',
- 'S002V01TPERS.PERS_IDUS as USER_ID',
- 'S002V01TEQMA.EQMA_IDEQ as WORKTEAM_ID',
- 'S002V01TPERS.PERS_IDPS as SUBCONTRATIST_ID',
- 'S002V01TEQMA.EQMA_NOMB as WORKTEAM_NAME',
- 'S002V01TPERS.PERS_NOCE as CONTACT_NAME',
- 'S002V01TPERS.PERS_NUTC as CONTACT_TELEPHONE',
- 'S002V01TPERS.PERS_LATC as CONTACT_LADA',
- 'S002V01TPERS.PERS_DICE as CONTACT_ADDRESS',
- 'S002V01TPERS.PERS_TICO as CONTRACT_TYPE',
- 'S002V01TPERS.PERS_ESPE as SPECIALITY',
- 'S002V01TPERS.PERS_NULI as LINE_NUMBER',
- DB::raw('TRIM(CONCAT(S002V01TUSUA.USUA_NOMB, " " , S002V01TUSUA.USUA_APPA, " ", COALESCE(S002V01TUSUA.USUA_APMA,""))) as EMPLOYEE_NAME')
- )
- ->where('S002V01TPERS.PERS_IDPE', '=', $id_employee)
- ->where('S002V01TPERS.PERS_NULI', '=', $line_number)
- ->where('s002v01TPEEM.PEEM_NULI', '=', $line_number)
- ->where('s002v01TEQMA.EQMA_NULI', '=', $line_number)
- ->where('s002v01TUSUA.USUA_NULI', '=', $line_number)
- ->join('S002V01TPEEM', 'S002V01TPERS.PERS_IDPE', '=', 'S002V01TPEEM.PEEM_IDPE')
- ->join('S002V01TEQMA', 'S002V01TPEEM.PEEM_IDEM', '=', 'S002V01TEQMA.EQMA_IDEQ')
- ->join('S002V01TUSUA', 'S002V01TPERS.PERS_IDUS', '=', 'S002V01TUSUA.USUA_IDUS')
- ->first();
- // Verifica si el objeto esta vacio
- if (!isset($employee) && empty($employee)) {
- return $this->response_controller
- ->makeResponse(TRUE, 'ERR_PERSONAL_REG001: No se encontró al empleado', [], 500);
- }
- $employee->CONTACT_NAME = $this->encrypt_controller->encrypt($employee->CONTACT_NAME);
- $employee->CONTACT_TELEPHONE = $this->encrypt_controller->encrypt($employee->CONTACT_TELEPHONE);
- $employee->CONTACT_LADA = $this->encrypt_controller->encrypt($employee->CONTACT_LADA);
- $employee->CONTACT_ADDRESS = $this->encrypt_controller->encrypt($employee->CONTACT_ADDRESS);
- $employee->DOCUMENTS = [];
- // Obtiene los documentos de un empleado
- $documents_of_employee = DB::table('S002V01TDOCU_P')
- ->select('DOCU_LIDO as DOCUMENT')
- ->where('DOCU_IDPE', '=', $id_employee)
- ->where('DOCU_NULI', '=', $line_number)
- ->get();
- // Verifica si el objeto contiene algo
- if (isset($documents_of_employee[0]) && !empty($documents_of_employee[0])) {
- foreach ($documents_of_employee as $doc) {
- $employee->DOCUMENTS[] = $this->encrypt_controller->encrypt($doc->DOCUMENT);
- }
- }
- return $this->response_controller
- ->makeResponse(FALSE, "Consulta exitosa", $employee);
- } catch (Throwable $th) {
- return $this->response_controller
- ->makeResponse(TRUE, 'ERR_PERSONAL_REG002: Error inesperado', strtoupper($th->getMessage()), 500);
- }
- }
- // Metodo para obtener todos los empleados con sus documentos (Pensado: 1 empleado solo tiene un equipo de trabajo)
- public function getAllEmployees($line_number)
- {
- try {
- $employees = DB::table('S002V01TPERS')
- ->select(
- 'S002V01TPERS.PERS_IDPE as EMPLOYEE_ID',
- 'S002V01TPERS.PERS_IDUS as USER_ID',
- 'S002V01TEQMA.EQMA_IDEQ as WORKTEAM_ID',
- 'S002V01TPERS.PERS_NOCE as CONTACT_NAME',
- 'S002V01TPERS.PERS_NUTC as CONTACT_TELEPHONE',
- 'S002V01TPERS.PERS_LATC as CONTACT_LADA',
- 'S002V01TPERS.PERS_DICE as CONTACT_ADDRESS',
- 'S002V01TPERS.PERS_TICO as CONTRACT_TYPE',
- 'S002V01TPERS.PERS_ESPE as SPECIALITY',
- )
- ->where('S002V01TPERS.PERS_NULI', '=', $line_number)
- ->where('S002V01TPEEM.PEEM_NULI', '=', $line_number)
- ->where('S002V01TEQMA.EQMA_NULI', '=', $line_number)
- ->join('S002V01TPEEM', 'S002V01TPERS.PERS_IDPE', '=', 'S002V01TPEEM.PEEM_IDPE')
- ->join('S002V01TEQMA', 'S002V01TPEEM.PEEM_IDEM', '=', 'S002V01TEQMA.EQMA_IDEQ')
- ->get();
- // Verifica si el objeto esta vacio
- if (!isset($employees[0]) && empty($employees[0])) {
- return $this->response_controller
- ->makeResponse(TRUE, 'ERR_PERSONAL_REG001: No se encontraron datos', [], 500);
- }
- foreach ($employees as $employee) {
- $employee->CONTACT_NAME = $this->encrypt_controller->encrypt($employee->CONTACT_NAME);
- $employee->CONTACT_TELEPHONE = $this->encrypt_controller->encrypt($employee->CONTACT_TELEPHONE);
- $employee->CONTACT_LADA = $this->encrypt_controller->encrypt($employee->CONTACT_LADA);
- $employee->CONTACT_ADDRESS = $this->encrypt_controller->encrypt($employee->CONTACT_ADDRESS);
- $employee->DOCUMENTS = [];
- }
- // Obtiene los documentos
- $documents_of_employees = DB::table('S002V01TDOCU_P')
- ->select('DOCU_LIDO as DOCUMENT', 'DOCU_IDPE as EMPLOYEE_ID')
- ->where('DOCU_NULI', '=', $line_number)
- ->get();
- // Verifica si el objeto esta vacio
- if (isset($documents_of_employees[0]) && !empty($documents_of_employees[0])) {
- // Asigna al empleado los documentos que le pertenezcan
- foreach ($employees as $employee) {
- foreach ($documents_of_employees as $doc) {
- if ($employee->EMPLOYEE_ID == $doc->EMPLOYEE_ID) {
- $employee->DOCUMENTS[] = $this->encrypt_controller->encrypt($doc->DOCUMENT);
- }
- }
- }
- }
- return $this->response_controller
- ->makeResponse(FALSE, "Consulta exitosa", $employees);
- } catch (Throwable $th) {
- return $this->response_controller
- ->makeResponse(TRUE, 'ERR_PERSONAL_REG002: Error inesperado', strtoupper($th->getMessage()), 500);
- }
- }
- // Metodo para actualizar un empleado
- public function updateEmployee(Request $request, $id_employee)
- {
- try {
- $save_option = $request->UPLOAD_NEW_DOCUMENTS != "N";
- $request['SAVED_BY_USER'] = $this->encrypt_controller->decrypt($request->SAVED_BY_USER);
- $UPDATE_DATE = Carbon::now()->timezone('America/Mexico_City')->toDateTimeString();
- $request['CONTACT_NAME'] = $this->encrypt_controller->decrypt($request->CONTACT_NAME);
- $request['CONTACT_TELEPHONE'] = $this->encrypt_controller->decrypt($request->CONTACT_TELEPHONE);
- $request['CONTACT_LADA'] = $this->encrypt_controller->decrypt($request->CONTACT_LADA);
- $request['CONTACT_ADDRESS'] = $this->encrypt_controller->decrypt($request->CONTACT_ADDRESS);
- $validator = Validator::make($request->all(), [
- "USER_ID" => ['required', 'digits:10'],
- "WORKTEAM_ID" => ['required', 'digits:10'],
- "CONTACT_NAME" => ['required', 'max:150'],
- "CONTACT_TELEPHONE" => ['required', 'max:11'],
- "CONTACT_LADA" => ['required', 'max:5'],
- "CONTACT_ADDRESS" => ['required', 'max:100'],
- "CONTRACT_TYPE" => ['required'],
- "SPECIALITY" => ['required', 'max:75'],
- "SUBCONTRATIST_ID" => ['max:10'],
- "SAVED_BY_USER" => ['required', 'digits:10'],
- "LINE_NUMBER" => ['required', 'digits:1']
- ]);
- if ($validator->fails()) {
- return $this->response_controller->makeResponse(
- TRUE,
- 'ERR_PERSONAL_REG001: Uno o más errores encontrados',
- $this->response_controller->makeErrors($validator->errors()->messages()),
- 400
- );
- }
- // Busca al empleado si existe
- $employee_exist = DB::table('S002V01TPERS')
- ->select('PERS_IDPE')
- ->where('PERS_IDPE', '=', $id_employee)
- ->where('PERS_NULI', '=', $request->LINE_NUMBER)
- ->first();
- // Verifica si el objeto esta vacio
- if (!isset($employee_exist) && empty($employee_exist)) {
- return $this->response_controller
- ->makeResponse(TRUE, 'ERR_PERSONAL_REG002: No se encontró al empleado', [], 500);
- }
- // Busca al equipo de trabajo si existe
- $team_found = DB::table('S002V01TEQMA')
- ->select('EQMA_NOMB')
- ->where('EQMA_IDEQ', '=', $request->WORKTEAM_ID)
- ->where('EQMA_NULI', '=', $request->LINE_NUMBER)
- ->first();
- // Verifica si el objeto esta vacio
- if (!isset($team_found) && empty($team_found)) {
- return $this->response_controller
- ->makeResponse(TRUE, 'ERR_EQUIPO_TRABAJO_REG003: No se encontró al equipo de trabajo', [], 500);
- }
- $user_register = DB::table('S002V01TUSUA')
- ->select('USUA_IDUS as ID_USER')
- ->where('USUA_IDUS', '=', $request->SAVED_BY_USER)
- ->where('USUA_NULI', '=', $request->LINE_NUMBER)
- ->first();
- // Verifica si el objeto esta vacio
- if (!isset($user_register) && empty($user_register)) {
- return $this->response_controller
- ->makeResponse(TRUE, "ERR_USUARIO_REG004: Tu usuario no es válido para actualizar empleados", [], 500);
- }
- DB::beginTransaction(); # Para impedir que las actualizaciones queden incompletas
- $update_employee = DB::table('S002V01TPERS')
- ->where('PERS_IDPE', '=', $id_employee)
- ->where('PERS_NULI', '=', $request->LINE_NUMBER)
- ->update([
- "PERS_IDUS" => $request->USER_ID,
- "PERS_NOCE" => trim($request->CONTACT_NAME),
- "PERS_NUTC" => $request->CONTACT_TELEPHONE,
- "PERS_LATC" => $request->CONTACT_LADA,
- "PERS_DICE" => trim($request->CONTACT_ADDRESS),
- "PERS_TICO" => trim($request->CONTRACT_TYPE),
- "PERS_ESPE" => trim($request->SPECIALITY),
- "PERS_IDPS" => $request->SUBCONTRATIST_ID,
- "PERS_ESTA" => "Activo",
- "PERS_USMO" => $request->SAVED_BY_USER,
- "PERS_FEMO" => $UPDATE_DATE,
- "PERS_FEAR" => DB::raw('CURRENT_TIMESTAMP')
- ]);
- // Verifica que la actualización del empleado haya sido satisfactoria
- if ($update_employee < 1) {
- return $this->response_controller
- ->makeResponse(TRUE, 'ERR_PERSONAL_REG005: Algo salió mal, error actualizando al empleado', [], 500);
- }
- $update_employee_on_workteam = DB::table('S002V01TPEEM')
- ->where('PEEM_IDPE', '=', $id_employee)
- ->where('PEEM_NULI', '=', $request->LINE_NUMBER)
- ->update([
- "PEEM_IDEM" => $request->WORKTEAM_ID,
- "PEEM_ESTA" => "Activo",
- "PEEM_USRE" => $request->SAVED_BY_USER,
- "PEEM_FERE" => $UPDATE_DATE,
- "PEEM_FEAR" => DB::raw('CURRENT_TIMESTAMP'),
- ]);
- // Verifica que la actualización del cambio de equipo del empleado haya sido satisfactoria
- if ($update_employee_on_workteam < 1) {
- DB::rollBack(); # Si no se logra actualizar el equipo, se revierten los cambios previos
- return $this->response_controller
- ->makeResponse(TRUE, 'ERR_EQUIPO_TRABAJO_REG006: Algo salió mal, error cambiando al empleado de equipo', [], 500);
- }
- // Verifica si el objeto esta vacio
- if (isset($request->DOCUMENTS_AUTHO) && !empty($request->DOCUMENTS_AUTHO)) {
- $doc = $request->DOCUMENTS_AUTHO;
- // Se obtiene el nombre del archivo con su extensión
- $completeFileName = $doc->getClientOriginalName();
- // Se obtiene únicamente el nombre
- $fileNameOnly = pathinfo($completeFileName, PATHINFO_FILENAME) . '-' . $id_employee;
- // Se obtiene la extensión del archivo
- $extension = $doc->getClientOriginalExtension();
- if ($extension != "pdf") {
- return $this->response_controller
- ->makeResponse(TRUE, 'ERR_DOCUMENTO_REG007: Solo se permiten archivos PDF', [], 500);
- }
- // Se quitan los espacios y se concatena datos para ser guardado
- $final_part_name_document = str_replace(' ', '_', $fileNameOnly) . '.' . $extension;
- $final_part_name_document = $this->documents_controller->deleteCodificationStructureName($final_part_name_document, "01", "GPRS");
- $name_document = $this->documents_controller->createDocument(
- "GPRS",
- "IN",
- $final_part_name_document,
- $id_employee,
- 'pdf',
- $request->LINE_NUMBER,
- $request->SAVED_BY_USER,
- $request->DOCUMENTS_AUTHO_UPDATE
- );
- // El documento es guardado en el storage
- $doc->storeAs('public/pdf_documents', $name_document);
- }
- // Verifica si el objeto esta vacio
- if (isset($request->DOCUMENTS_AUTHO2) && !empty($request->DOCUMENTS_AUTHO2)) {
- $doc = $request->DOCUMENTS_AUTHO2;
- // Se obtiene el nombre del archivo con su extensión
- $completeFileName = $doc->getClientOriginalName();
- // Se obtiene únicamente el nombre
- $fileNameOnly = pathinfo($completeFileName, PATHINFO_FILENAME) . '-' . $id_employee;
- // Se obtiene la extensión del archivo
- $extension = $doc->getClientOriginalExtension();
- if ($extension != "pdf") {
- return $this->response_controller
- ->makeResponse(TRUE, 'ERR_DOCUMENTO_REG007: Solo se permiten archivos PDF', [], 500);
- }
- // Se quitan los espacios y se concatena datos para ser guardado
- $final_part_name_document = str_replace(' ', '_', $fileNameOnly) . '.' . $extension;
- $final_part_name_document = $this->documents_controller->deleteCodificationStructureName($final_part_name_document, "01", "GPRS");
- $name_document = $this->documents_controller->createDocument(
- "GPRS",
- "IN",
- $final_part_name_document,
- $id_employee,
- 'pdf',
- $request->LINE_NUMBER,
- $request->SAVED_BY_USER,
- $request->DOCUMENTS_AUTHO2_UPDATE
- );
- // El documento es guardado en el storage
- $doc->storeAs('public/pdf_documents', $name_document);
- }
- // Verifica si el objeto esta vacio
- if (isset($request->DOCUMENTS_CERT) && !empty($request->DOCUMENTS_CERT)) {
- $doc = $request->DOCUMENTS_CERT;
- // Se obtiene el nombre del archivo con su extensión
- $completeFileName = $doc->getClientOriginalName();
- // Se obtiene únicamente el nombre
- $fileNameOnly = pathinfo($completeFileName, PATHINFO_FILENAME) . '-' . $id_employee;
- // Se obtiene la extensión del archivo
- $extension = $doc->getClientOriginalExtension();
- if ($extension != "pdf") {
- return $this->response_controller
- ->makeResponse(TRUE, 'ERR_DOCUMENTO_REG007: Solo se permiten archivos PDF', [], 500);
- }
- // Se quitan los espacios y se concatena datos para ser guardado
- $final_part_name_document = str_replace(' ', '_', $fileNameOnly) . '.' . $extension;
- $final_part_name_document = $this->documents_controller->deleteCodificationStructureName($final_part_name_document, "01", "GPRS");
- $name_document = $this->documents_controller->createDocument(
- "GPRS",
- "CE",
- $final_part_name_document,
- $id_employee,
- 'pdf',
- $request->LINE_NUMBER,
- $request->SAVED_BY_USER,
- $request->DOCUMENTS_CERT_UPDATE
- );
- // El documento es guardado en el storage
- $doc->storeAs('public/pdf_documents', $name_document);
- }
- // Verifica si el objeto esta vacio
- if (isset($request->DOCUMENTS_CERT2) && !empty($request->DOCUMENTS_CERT2)) {
- $doc = $request->DOCUMENTS_CERT2;
- // Se obtiene el nombre del archivo con su extensión
- $completeFileName = $doc->getClientOriginalName();
- // Se obtiene únicamente el nombre
- $fileNameOnly = pathinfo($completeFileName, PATHINFO_FILENAME) . '-' . $id_employee;
- // Se obtiene la extensión del archivo
- $extension = $doc->getClientOriginalExtension();
- if ($extension != "pdf") {
- return $this->response_controller
- ->makeResponse(TRUE, 'ERR_DOCUMENTO_REG007: Solo se permiten archivos PDF', [], 500);
- }
- // Se quitan los espacios y se concatena datos para ser guardado
- $final_part_name_document = str_replace(' ', '_', $fileNameOnly) . '.' . $extension;
- $final_part_name_document = $this->documents_controller->deleteCodificationStructureName($final_part_name_document, "01", "GPRS");
- $name_document = $this->documents_controller->createDocument(
- "GPRS",
- "CE",
- $final_part_name_document,
- $id_employee,
- 'pdf',
- $request->LINE_NUMBER,
- $request->SAVED_BY_USER,
- $request->DOCUMENTS_CERT2_UPDATE
- );
- // El documento es guardado en el storage
- $doc->storeAs('public/pdf_documents', $name_document);
- }
- // Verifica si el objeto esta vacio
- if (isset($request->DOCUMENT_OFFICE) && !empty($request->DOCUMENT_OFFICE)) {
- $doc = $request->DOCUMENT_OFFICE;
- // Se obtiene el nombre del archivo con su extensión
- $completeFileName = $doc->getClientOriginalName();
- // Se obtiene únicamente el nombre
- $fileNameOnly = pathinfo($completeFileName, PATHINFO_FILENAME) . '-' . $id_employee;
- // Se obtiene la extensión del archivo
- $extension = $doc->getClientOriginalExtension();
- if ($extension != "pdf") {
- return $this->response_controller
- ->makeResponse(TRUE, 'ERR_DOCUMENTO_REG007: Solo se permiten archivos PDF', [], 500);
- }
- // Se quitan los espacios y se concatena datos para ser guardado
- $final_part_name_document = str_replace(' ', '_', $fileNameOnly) . '.' . $extension;
- $final_part_name_document = $this->documents_controller->deleteCodificationStructureName($final_part_name_document, "01", "GPRS");
- $name_document = $this->documents_controller->createDocument(
- "GPRS",
- "CO",
- $final_part_name_document,
- $id_employee,
- 'pdf',
- $request->LINE_NUMBER,
- $request->SAVED_BY_USER,
- $request->DOCUMENT_OFFICE_UPDATE
- );
- // El documento es guardado en el storage
- $doc->storeAs('public/pdf_documents', $name_document);
- }
- DB::commit(); # Para guardar los cambios en la base de datos
- return $this->response_controller->makeResponse(FALSE, 'Actualización exitosa', 200);
- } catch (Throwable $th) {
- return $this->response_controller
- ->makeResponse(TRUE, 'ERR_PERSONAL_REG008: Error inesperado', strtoupper($th), 500);
- }
- }
- // Metodo para obtener la cantidad de contratos otorgados a cada empleado
- public function getContractsOfEveryEmployee($line_number)
- {
- try {
- // Obtiene la cantidad de contratos que tiene cada empleado
- $contracts_by_employee = DB::table('S002V01TPERS')
- ->select(
- 'S002V01TPERS.PERS_IDPE as ID_EMPLOYEE',
- DB::raw('TRIM(CONCAT(S002V01TUSUA.USUA_NOMB, " " , S002V01TUSUA.USUA_APPA, " ", COALESCE(S002V01TUSUA.USUA_APMA,""))) AS NAME'),
- DB::raw(
- 'COUNT(S002V01TPECO.PECO_IDPE) AS CONTRACTS_COUNT',
- )
- )
- ->where('S002V01TPERS.PERS_NULI', '=', $line_number)
- ->where('S002V01TUSUA.USUA_NULI', '=', $line_number)
- ->where('S002V01TPECO.PECO_NULI', '=', $line_number)
- ->where('S002V01TCONT.CONT_NULI', '=', $line_number)
- ->groupBy('S002V01TPERS.PERS_IDPE', 'NAME', 'S002V01TPECO.PECO_IDPE')
- ->join('S002V01TUSUA', 'S002V01TPERS.PERS_IDUS', '=', 'S002V01TUSUA.USUA_IDUS')
- ->join('S002V01TPECO', 'S002V01TPERS.PERS_IDPE', '=', 'S002V01TPECO.PECO_IDPE')
- ->join('S002V01TCONT', 'S002V01TPECO.PECO_IDCO', '=', 'S002V01TCONT.CONT_IDCO')
- ->get();
- // Verifica si el objeto esta vacio
- if (!isset($contracts_by_employee[0]) && empty($contracts_by_employee[0])) {
- return $this->response_controller
- ->makeResponse(TRUE, 'ERR_PERSONAL_CONTRATO_REG001: No se encontraron datos', [], 500);
- }
- return $this->response_controller
- ->makeResponse(FALSE, "Consulta exitosa", $contracts_by_employee);
- } catch (Throwable $th) {
- return $this->response_controller
- ->makeResponse(TRUE, 'ERR_PERSONAL_REG002: Error inesperado', strtoupper($th->getMessage()), 500);
- }
- }
- // Metodo para obtener detalles acerca de los contratos otorgados al empleado
- public function getDetailsOfContractsByEmployee($id_employee, $line_number)
- {
- try {
- // Busca al empleado si existe
- $employee_exist = DB::table('S002V01TPERS')
- ->select('PERS_IDPE')
- ->where('PERS_IDPE', '=', $id_employee)
- ->where('PERS_NULI', '=', $line_number)
- ->first();
- // Verifica si el objeto esta vacio
- if (!isset($employee_exist) && empty($employee_exist)) {
- return $this->response_controller
- ->makeResponse(TRUE, 'ERR_PERSONAL_REG001: No se encontró al empleado', [], 500);
- }
- //Obtiene los contratos pertenecientes al subcontratista deseado
- $contracts_by_employee = DB::table('S002V01TPERS')
- ->orderBy("S002V01TCONT.CONT_FEIN", 'desc')
- ->where('S002V01TPERS.PERS_IDPE', '=', $id_employee)
- ->where('S002V01TPERS.PERS_NULI', '=', $line_number)
- ->where('S002V01TPECO.PECO_NULI', '=', $line_number)
- ->where('S002V01TCONT.CONT_NULI', '=', $line_number)
- ->select('S002V01TCONT.CONT_FEIN as START_DATE', 'S002V01TCONT.CONT_FEFI as END_DATE', 'S002V01TCONT.CONT_COST as CONTRACT_COST')
- ->join('S002V01TPECO', 'S002V01TPERS.PERS_IDPE', '=', 'S002V01TPECO.PECO_IDPE')
- ->join('S002V01TCONT', 'S002V01TPECO.PECO_IDCO', '=', 'S002V01TCONT.CONT_IDCO')
- ->get();
- // Verifica si el objeto esta vacio
- if (!isset($contracts_by_employee[0]) && empty($contracts_by_employee[0])) {
- return $this->response_controller
- ->makeResponse(TRUE, 'ERR_PERSONAL_CONTRATO_REG002: Empleado sin contratos', $contracts_by_employee, 500);
- }
- foreach ($contracts_by_employee as $contract) {
- $contract->START_DATE = Carbon::create($contract->START_DATE)->format("d-m-Y h:i:s A");
- $contract->END_DATE = Carbon::create($contract->END_DATE)->format("d-m-Y h:i:s A");
- $contract->CONTRACT_COST = $this->encrypt_controller->encrypt($contract->CONTRACT_COST);
- }
- return $this->response_controller
- ->makeResponse(FALSE, "Consulta exitosa", $contracts_by_employee);
- } catch (Throwable $th) {
- return $this->response_controller
- ->makeResponse(TRUE, 'ERR_PERSONAL_REG003: Error inesperado', strtoupper($th->getMessage()), 500);
- }
- }
- // Metodo para la descarga de archivo excel con los detalles del empleado
- public function downoloadEmployeeInfoOnExcel(Request $request)
- {
- try {
- $request['SAVED_BY_USER'] = $this->encrypt_controller->decrypt($request->SAVED_BY_USER);
- $employee_id = $request->EMPLOYEE['ID_EMPLOYEE'];
- $final_part_name_document = "Details_Of_Employee_" . $employee_id . ".xlsx";
- // Crea el documento con los datos del request
- $document = $this->createDocument($request);
- // Busca la ultima versión del documento que se haya insertado
- $old_document_name = $this->documents_controller->getDocumentsWithSameName($final_part_name_document, 'excel');
- if ($old_document_name != null) {
- // Obtiene el nombre del documento que tiene el mismo contenido
- $old_document_name = $this->documents_controller->sameDocumentsExcel($document, $old_document_name);
- // Si no hay ningun cambio en el documento, se descarga la ultima versión
- if ($old_document_name != null) {
- return $this->response_controller
- ->makeResponse(False, 'Éxito', Storage::disk('excel')->url($old_document_name), 200);
- }
- }
- // Guarda el documento creado en la variable
- $writer = IOFactory::createWriter($document, 'Xlsx');
- $content = tmpfile();
- $writer->save($content);
- // Inserta la nueva version del documento en la base de datos y en el storage
- $name_document = $this->documents_controller->createDocument("GPRS", "IN", $final_part_name_document, $employee_id, "excel", $request->EMPLOYEE['LINE_NUMBER'], $request->SAVED_BY_USER);
- Storage::disk('excel')->put(
- $name_document,
- $content
- );
- return $this->response_controller
- ->makeResponse(False, 'Éxito', Storage::disk('excel')->url($name_document), 200);
- } catch (Throwable $th) {
- return $this->response_controller
- ->makeResponse(TRUE, 'ERR_EXCEL_REG001: Error inesperado', strtoupper($th), 500);
- }
- }
- // Metodo para la descarga de archivo pdf con los detalles del empleado
- public function downoloadEmployeeInfoOnPdf(Request $request)
- {
- try {
- $request['SAVED_BY_USER'] = $this->encrypt_controller->decrypt($request->SAVED_BY_USER);
- $employee_id = $request->EMPLOYEE['ID_EMPLOYEE'];
- $final_part_name_document = "Details_Of_Employee_" . $employee_id . ".pdf";
- // Crea el documento
- $document = $this->createDocument($request);
- $writer = IOFactory::createWriter($document, 'Mpdf');
- $content = tmpfile();
- // Busca la ultima versión del documento que se haya insertado
- $old_document_name = $this->documents_controller->getDocumentsWithSameName($final_part_name_document, 'pdf');
- $writer->save($content);
- if ($old_document_name != null) {
- // Obtiene el nombre del documento que tiene el mismo contenido
- $old_document_name = $this->documents_controller->sameDocumentsPdf($content, $old_document_name);
- // Si no hay ningun cambio en el documento, se descarga la ultima versión
- if ($old_document_name != null) {
- return $this->response_controller
- ->makeResponse(False, 'Éxito', Storage::disk('pdf')->url($old_document_name), 200);
- }
- }
- // Inserta la nueva version del documento en la base de datos y en el storage
- $name_document = $this->documents_controller->createDocument("GPRS", "IN", $final_part_name_document, $employee_id, "pdf", $request->EMPLOYEE['LINE_NUMBER'], $request->SAVED_BY_USER);
- Storage::disk('pdf')->put(
- $name_document,
- $content
- );
- return $this->response_controller
- ->makeResponse(False, 'Éxito', Storage::disk('pdf')->url($name_document), 200);
- } catch (Throwable $th) {
- return $this->response_controller
- ->makeResponse(TRUE, 'ERR_PDF_REG001: Error inesperado', strtoupper($th), 500);
- }
- }
- // Metodo para la creación de archivo
- public function createDocument(Request $request)
- {
- try {
- $employee = $request->EMPLOYEE;
- $document = new Spreadsheet();
- // Propiedades del documento
- $document->getProperties()
- ->setCreator("ITTEC")
- ->setTitle("Detalles del empleado")
- ->setDescription("Detalles de solo un empleado.")
- ->setKeywords("Empleado Detalles")
- ->setCategory("Empleado Detalles Pdf");
- // Cambia la hoja a horizontal par que se observen mejor los datos
- $document->getActiveSheet()->getPageSetup()->setOrientation("landscape");
- // Hace la escritura dentro del archivo
- $start_row = 2; # Indica desde que fila inicia la tabla
- $start_col = "B"; # Indica desde que columna inicia la tabla
- $col = $start_col;
- $row = $start_row;
- $col++;
- $second_col = $col;
- $col++;
- $third_col = $col;
- $col++;
- $fourth_col = $col;
- $col++;
- $fifth_col = $col;
- $col++;
- $sixth_col = $col;
- $col++;
- $seventh_col = $col;
- $col++;
- $eight_col = $col;
- $col = $start_col;
- $final_col = "";
- for ($i = 0; $i < 9; $i++) {
- $final_col = $col;
- $col++;
- }
- $col = $start_col;
- // Titulo del documento
- $document->getActiveSheet()->mergeCells($start_col . $row . ":" . $final_col . $row);
- $document->getActiveSheet()->setCellValue($start_col . $row, 'DETALLES DEL EMPLEADO')->getStyle($start_col . $row)->getFill()
- ->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)
- ->getStartColor()->setRGB('FFCC88');
- $document->getActiveSheet()->getStyle($start_col . $row)->getFont()->setBold(true);
- $row++;
- //Cuerpo del documento
- $document->getActiveSheet()->setCellValue($col . $row, 'ID EMPLEADO')->getStyle($col . $row)->getFill()
- ->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)
- ->getStartColor()->setRGB('38D9CE');
- $col++;
- $document->getActiveSheet()->setCellValue($col . $row, 'NOMBRE EMPLEADO')->getStyle($col . $row)->getFill()
- ->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)
- ->getStartColor()->setRGB('38D9CE');
- $col++;
- $document->getActiveSheet()->setCellValue($col . $row, 'NOMBRE EQUIPO')->getStyle($col . $row)->getFill()
- ->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)
- ->getStartColor()->setRGB('38D9CE');
- $col++;
- $document->getActiveSheet()->setCellValue($col . $row, 'NOMBRE CONTACTO DE EMERGENCIA')->getStyle($col . $row)->getFill()
- ->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)
- ->getStartColor()->setRGB('38D9CE');
- $col++;
- $document->getActiveSheet()->setCellValue($col . $row, 'TELEFONO CONTACTO DE EMERGENCIA')->getStyle($col . $row)->getFill()
- ->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)
- ->getStartColor()->setRGB('38D9CE');
- $col++;
- $document->getActiveSheet()->setCellValue($col . $row, 'DIRECCIÓN CONTACTO DE EMERGENCIA')->getStyle($col . $row)->getFill()
- ->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)
- ->getStartColor()->setRGB('38D9CE');
- $col++;
- $document->getActiveSheet()->setCellValue($col . $row, 'TIPO DE CONTRATO')->getStyle($col . $row)->getFill()
- ->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)
- ->getStartColor()->setRGB('38D9CE');
- $col++;
- $document->getActiveSheet()->setCellValue($col . $row, 'ESPECIALIDAD DEL EMPLEADO')->getStyle($col . $row)->getFill()
- ->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)
- ->getStartColor()->setRGB('38D9CE');
- $col++;
- $document->getActiveSheet()->setCellValue($col . $row, 'DOCUMENTOS')->getStyle($col . $row)->getFill()
- ->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)
- ->getStartColor()->setRGB('38D9CE');
- $row++;
- $col = $start_col;
- $document->getActiveSheet()->setCellValue($col . $row, "#" . $employee['ID_EMPLOYEE']);
- $col++;
- $document->getActiveSheet()->setCellValue($col . $row, $employee['EMPLOYEE_NAME']);
- $col++;
- $document->getActiveSheet()->setCellValue($col . $row, $employee['WORKTEAM_NAME']);
- $col++;
- $document->getActiveSheet()->setCellValue($col . $row, $this->encrypt_controller->decrypt($employee['CONTACT_NAME']));
- $col++;
- $document->getActiveSheet()->setCellValue($col . $row, $this->encrypt_controller->decrypt($employee['CONTACT_LADA']) . $this->encrypt_controller->decrypt($employee['CONTACT_TELEPHONE']));
- $col++;
- $document->getActiveSheet()->setCellValue($col . $row, $this->encrypt_controller->decrypt($employee['CONTACT_ADDRESS']));
- $col++;
- $document->getActiveSheet()->setCellValue($col . $row, $employee['CONTRACT_TYPE']);
- $col++;
- $document->getActiveSheet()->setCellValue($col . $row, $employee['SPECIALITY']);
- $col++;
- // Verifica si el empleado tiene documentos
- if (isset($employee['DOCUMENTS'][0]) && !empty($employee['DOCUMENTS'][0])) {
- foreach ($employee['DOCUMENTS'] as $doc) {
- $document->getActiveSheet()->setCellValue($col . $row, $this->encrypt_controller->decrypt($doc));
- $row++;
- }
- } else {
- $document->getActiveSheet()->setCellValue($col . $row, 'SIN DOCUMENTOS...');
- $document->getActiveSheet()->getStyle($col . $row)->getFont()->setBold(true);
- $row++;
- }
- //Ajusta las celdas a su contenido y da estilo
- $document->getActiveSheet()->mergeCells($start_col . $start_row + 2 . ":" . $start_col . $row - 1);
- $document->getActiveSheet()->mergeCells($second_col . $start_row + 2 . ":" . $second_col . $row - 1);
- $document->getActiveSheet()->mergeCells($third_col . $start_row + 2 . ":" . $third_col . $row - 1);
- $document->getActiveSheet()->mergeCells($fourth_col . $start_row + 2 . ":" . $fourth_col . $row - 1);
- $document->getActiveSheet()->mergeCells($fifth_col . $start_row + 2 . ":" . $fifth_col . $row - 1);
- $document->getActiveSheet()->mergeCells($sixth_col . $start_row + 2 . ":" . $sixth_col . $row - 1);
- $document->getActiveSheet()->mergeCells($seventh_col . $start_row + 2 . ":" . $seventh_col . $row - 1);
- $document->getActiveSheet()->mergeCells($eight_col . $start_row + 2 . ":" . $eight_col . $row - 1);
- $col = $start_col;
- for ($i = 0; $i < 9; $i++) {
- $document->getActiveSheet()->getColumnDimension($col)->setAutoSize(true);
- $col++;
- }
- $document->getActiveSheet()->getStyle($start_col . $start_row . ':' . $final_col . $row)->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER);
- $document->getActiveSheet()->getStyle($start_col . $start_row . ':' . $final_col . $row)->getAlignment()->setVertical(\PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER);
- $document->getActiveSheet()->getStyle($start_col . $start_row . ':' . $final_col . $row - 1)->getBorders()->getAllBorders()->setBorderStyle(\PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUM);
- return $document;
- } catch (Throwable $th) {
- return $this->response_controller
- ->makeResponse(TRUE, 'ERR_CREACIÓN_DOCUMENTO_REG001: Error inesperado', strtoupper($th->getMessage()), 500);
- }
- }
- }
|