<?php
namespace App\Controller;
use App\Entity\RFFUID;
use App\Entity\RFInventarioDocumentalComercial;
use App\Entity\RFInventarioDocumentalComex;
use App\Entity\RFInventarioDocumentalFinanzas;
use App\Entity\RFInventarioDocumentalGesHum;
use App\Entity\RFInventarioDocumentalSST;
use App\Entity\RFSolicitudDocumento;
use App\Form\RFFUIDType;
use App\Repository\RFFUIDRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Validator\Constraints\File;
#[Route('/rf/fuid')]
class RFFUIDController extends AbstractController
{
private $responseHandler;
private $documentHandler;
private $mailerCore;
private $code = 0;
private $msj = "";
private $url = "";
private $html = "";
public function __construct(\App\Services\ResponseHandler $responseHandler, \App\Services\DocumentHandler $documentHandler, \App\Services\MailerCore $mailerCore)
{
$this->responseHandler = $responseHandler;
$this->mailerCore = $mailerCore;
$this->documentHandler = $documentHandler;
}
#[Route('/', name: 'rf_fuid', methods: ['GET'])]
public function index(RFFUIDRepository $RFFUIDRepository): Response
{
$idProceso = $this->getUser()->getPersona()->getPerfilCargo()->getParProceso()->getId();
# dump($idProceso);
$entities = $RFFUIDRepository->getAll(null, [], $idProceso);
return $this->render('rf_fuid/index.html.twig', [
'entities' => $entities
]);
}
#[Route('/new', name: 'rf_fuid_new', methods: ['GET', 'POST'])]
public function new(Request $request, EntityManagerInterface $entityManager): Response
{
if ($this->getUser()->getPersona()->getSede() == null || $this->getUser()->getPersona()->getPerfilCargo() == null) {
$this->code = 'warning';
$this->msj = "Imposible continuar, aun no cuenta con la inforcion de sede y perfil cargo.";
return new Response(json_encode(['code' => $this->code, 'msj' => $this->msj, 'url' => $this->url, 'html' => $this->html]));
}
$RFFUID = new RFFUID();
$form = $this->createForm(RFFUIDType::class, $RFFUID, [
'idUsuarioElabora' => $this->getUser()->getPersona()->getId()
,
'idSede' => $this->getUser()->getPersona()->getSede()->getId()
,
'idProceso' => $this->getUser()->getPersona()->getPerfilCargo()->getParProceso()->getId()
,
'method' => 'POST',
'action' => $this->generateUrl($request->attributes->get('_route'))
]);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$RFFUID->setFechaEntrada(new \DateTime('now'));
$RFFUID->setObjeto("Transferencia Primaria");
$RFFUID->setUsuarioElabora($this->getUser()->getPersona());
$RFFUID->setSede($this->getUser()->getPersona()->getSede());
$RFFUID->setProceso($this->getUser()->getPersona()->getPerfilCargo()->getParProceso());
$RFFUID->setCreateAt(new \DateTime('now'));
$RFFUID->setCreateUser($this->getUser()->getUsername());
$RFFUID->setUpdateAt(new \DateTime('now'));
$RFFUID->setUpdateUser($this->getUser()->getUsername());
$entityManager->persist($RFFUID);
$entityManager->flush();
return $this->redirectToRoute('rf_fuid_edit', ['id' => $RFFUID->getId()]);
// $this->code = 'success';
// $this->msj = "Registro almacenado con exito.";
// return new Response(json_encode(['code' => $this->code, 'msj' => $this->msj, 'url' => $this->url, 'html' => $this->html]));
}
return $this->renderForm('rf_fuid/new.html.twig', [
'fuid' => $RFFUID,
'form' => $form,
]);
}
#[Route('/{id}/edit', name: 'rf_fuid_edit', methods: ['GET', 'POST'])]
public function edit(Request $request, RFFUID $RFFUID, EntityManagerInterface $entityManager): Response
{
if ($RFFUID->getEstado() != null) {
if ($RFFUID->getEstado()->getId() != 30) {
$this->code = 'info';
$this->msj = "Imposible continuar, el registro no se encuentra en el estado esperado.";
return new Response(json_encode(['code' => $this->code, 'msj' => $this->msj, 'url' => $this->url, 'html' => $this->html]));
}
}
$form = $this->createForm(RFFUIDType::class, $RFFUID, [
'idUsuarioElabora' => $this->getUser()->getPersona()->getId()
,
'idSede' => $this->getUser()->getPersona()->getSede()->getId()
,
'idProceso' => $this->getUser()->getPersona()->getPerfilCargo()->getParProceso()->getId()
,
'method' => 'POST',
'action' => $this->generateUrl($request->attributes->get('_route'), ['id' => $RFFUID->getId()])
]);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$RFFUID->setUpdateAt(new \DateTime('now'));
$RFFUID->setUpdateUser($this->getUser()->getUsername());
$this->code = 'success';
$this->msj = "Registro almacenado con exito.";
return new Response(json_encode(['code' => $this->code, 'msj' => $this->msj, 'url' => $this->url, 'html' => $this->html]));
}
$res = $this->getEntitiesFUID($entityManager, $RFFUID, true);
return $this->renderForm('rf_fuid/edit.html.twig', [
'keys' => $res['encabezado'],
'fuid' => $RFFUID,
'form' => $form,
'entities' => $res['entities']
]);
}
#[Route('/{id}/registrar_inventario', name: 'rf_fuid_registrar_inventario', methods: ['GET', 'POST'])]
public function registrarInventario(Request $request, RFFUID $RFFUID, EntityManagerInterface $entityManager): Response
{
if ($RFFUID->getEstado() != null) {
if ($RFFUID->getEstado()->getId() != 30) {
$this->code = 'info';
$this->msj = "Imposible continuar, el registro no se encuentra en el estado esperado.";
return new Response(json_encode(['code' => $this->code, 'msj' => $this->msj, 'url' => $this->url, 'html' => $this->html]));
}
}
$proceso = $this->getUser()->getPersona()->getPerfilCargo()->getParProceso();
$df = $proceso->getFuenteDatosRFFUID();
$formObj = null;
$obj = null;
$formName = "";
$tituloFuid = "";
// Si el proceso es Recurso FÃsico, se usa el formulario Comex por defecto
// ya que este proceso gestiona documentación de múltiples áreas.
if (str_contains(strtolower($proceso->getNombre()), 'recurso')) {
$df = 'App\Entity\RFInventarioDocumentalComex';
}
// Si el proceso no tiene configurado un tipo de documento FUID,
// se retorna un mensaje amigable en lugar de generar un error 500.
if (!$df) {
$this->code = 'warning';
$this->msj = "Su proceso no tiene un FUID configurado. Contacte al administrador del sistema.";
return new Response(json_encode(['code' => $this->code, 'msj' => $this->msj, 'url' => $this->url, 'html' => $this->html]));
}
switch ($df) {
case 'App\Entity\RFInventarioDocumentalComercial':
$obj = new \App\Entity\RFInventarioDocumentalComercial();
$formObj = \App\Form\RFInventarioDocumentalComercialType::class;
$formName = "formComercial";
$tituloFuid = "Registar Documento Comercial";
break;
case 'App\Entity\RFInventarioDocumentalComex':
$obj = new \App\Entity\RFInventarioDocumentalComex();
$formObj = \App\Form\RFInventarioDocumentalComexType::class;
$formName = "formComex";
$tituloFuid = "Registar Documento Comex";
break;
case 'App\Entity\RFInventarioDocumentalFinanzas':
$obj = new \App\Entity\RFInventarioDocumentalFinanzas();
$formObj = \App\Form\RFInventarioDocumentalFinanzasType::class;
$formName = "formFinanzas";
$tituloFuid = "Registar Documento Finanzas";
break;
case 'App\Entity\RFInventarioDocumentalGesHum':
$obj = new \App\Entity\RFInventarioDocumentalGesHum();
$formObj = \App\Form\RFInventarioDocumentalGesHumType::class;
$formName = "formGesHum";
$tituloFuid = "Registar Documento Gestion Humana";
break;
case 'App\Entity\RFInventarioDocumentalSST':
$obj = new \App\Entity\RFInventarioDocumentalSST();
$formObj = \App\Form\RFInventarioDocumentalSSTType::class;
$formName = "formSST";
$tituloFuid = "Registar Documento SST";
break;
}
$form = $this->createForm($formObj, $obj, ['method' => 'POST', 'action' => $this->generateUrl($request->attributes->get('_route'), ['id' => $RFFUID->getId()])]);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$obj->setFUID($RFFUID);
$obj->setPersona($this->getUser()->getPersona());
$obj->setEstado($entityManager->getRepository(\App\Entity\ParEstado::class)->find(30));
$obj->setDisponibilidad($entityManager->getRepository(\App\Entity\ParEstado::class)->find(38));
$obj->setCreateAt(new \DateTime('now'));
$obj->setCreateUser($this->getUser()->getUsername());
$obj->setUpdateAt(new \DateTime('now'));
$obj->setUpdateUser($this->getUser()->getUsername());
dump($obj->getFolio());
$entityManager->persist($obj);
$entityManager->flush();
$this->mailerCore->FUID('notificacion', [$RFFUID]);
$this->code = 'success';
$this->msj = "Registro cargado exitosamente";
$this->url = $this->generateUrl('rf_fuid_edit', [
'id' => $RFFUID->getId()
]);
return new Response(json_encode(['code' => $this->code, 'msj' => $this->msj, 'url' => $this->url, 'html' => $this->html]));
}
return $this->render("rf_fuid/formArchivo.html.twig", [
'btnEditar' => true,
'tituloFUID' => $tituloFuid,
$formName => $form->createView(),
'fuid' => $RFFUID,
]);
}
#[Route('/{id}/editar_inventario/{fuid}', name: 'rf_fuid_editar_inventario', methods: ['GET', 'POST'])]
public function editarInventario(EntityManagerInterface $entityManager, Request $request, $id, $fuid): Response
{
$RFFUID = $entityManager->getRepository(RFFUID::class)->find($fuid);
$inf = $this->getEntitiFUID($entityManager, $RFFUID, $id);
$obj = $inf['obj'];
$formObj = $inf['formObj'];
$formName = $inf['formName'];
$form = $this->createForm(
$formObj,
$obj,
[
'method' => 'POST',
'action' => $this->generateUrl(
'rf_fuid_editar_inventario',
[
'id' => $id,
'fuid' => $RFFUID->getId()
]
)
]
);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
if ($RFFUID->getEstado() != null) {
$this->code = 'info';
$this->msj = "Imposible continuar, el registro no se encuentra en el estado esperado.";
return new Response(json_encode(['code' => $this->code, 'msj' => $this->msj, 'url' => $this->url, 'html' => $this->html]));
}
$obj->setUpdateAt(new \DateTime('now'));
$obj->setUpdateUser($this->getUser()->getUsername());
$entityManager->persist($obj);
$entityManager->flush();
$this->code = 'success';
$this->msj = "Registro almacenado con exito.";
return new Response(json_encode(['code' => $this->code, 'msj' => $this->msj, 'url' => $this->url]));
}
return $this->render("rf_fuid/formArchivo.html.twig", [
'btnEditar' => true,
'tituloFUID' => $inf['titulo'],
$formName => $form->createView(),
'fuid' => $RFFUID,
]);
}
#[Route('/{id}/ver_inventario/{fuid}', name: 'rf_fuid_ver_inventario', methods: ['GET', 'POST'])]
public function verInventario(EntityManagerInterface $entityManager, Request $request, $id, $fuid): Response
{
//Obtenemos le fuid que nos pasa el formulario
$RFFUID = $entityManager->getRepository(RFFUID::class)->find($fuid);
$inf = $this->getEntitiFUID($entityManager, $RFFUID, $id);
$obj = $inf['obj'];
$formObj = $inf['formObj'];
$formName = $inf['formName'];
$form = $this->createForm(
$formObj,
$obj,
[
'method' => 'POST',
'disabled_fields' => true,
'action' => $this->generateUrl(
'rf_fuid_editar_inventario',
[
'id' => $id,
'fuid' => $RFFUID->getId()
]
)
]
);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
if ($RFFUID->getEstado() != null) {
$this->code = 'info';
$this->msj = "Imposible continuar, el registro no se encuentra en el estado esperado.";
return new Response(json_encode(['code' => $this->code, 'msj' => $this->msj, 'url' => $this->url, 'html' => $this->html]));
}
$obj->setUpdateAt(new \DateTime('now'));
$obj->setUpdateUser($this->getUser()->getUsername());
$entityManager->persist($obj);
$entityManager->flush();
$this->code = 'success';
$this->msj = "Registro almacenado con exito.";
return new Response(json_encode(['code' => $this->code, 'msj' => $this->msj, 'url' => $this->url]));
}
return $this->render("rf_fuid/formArchivo.html.twig", [
'btnEditar' => false,
'tituloFUID' => $inf['titulo'],
$formName => $form->createView(),
'fuid' => $RFFUID,
]);
}
#[Route('/{id}/cargar_archivo_inventario/{fuid}/{idNotificacion}', name: 'rf_fuid_cargar_archivo_inventario', methods: ['GET', 'POST'])]
public function cargarArchivoInventario(EntityManagerInterface $entityManager, Request $request, $id, $fuid, $idNotificacion = 0): Response
{
$RFFUID = $entityManager->getRepository(RFFUID::class)->find($fuid);
$inf = $this->getEntitiFUID($entityManager, $RFFUID, $id);
$obj = $inf['obj'];
$formObj = $inf['formObj'];
if ($obj->getArchivo() != null && $idNotificacion != 0) {
$this->code = 'warning';
$this->msj = "Imposible continuar, el registro ya cuenta con un documento.";
return new Response(json_encode(['code' => $this->code, 'msj' => $this->msj, 'url' => $this->url, 'html' => $this->html]));
//$contrato->setEstado($this->entityManager->getRepository(\App\Entity\ParEstado::class)->find(1));
}
$form = $this->createForm($formObj, $obj, ['disabled_fields' => true, 'method' => 'POST', 'action' => $this->generateUrl($request->attributes->get('_route'), ['id' => $id, 'fuid' => $fuid])]);
$form->add('file', \Symfony\Component\Form\Extension\Core\Type\FileType::class, ['label' => 'Documentos', 'mapped' => false, 'required' => true, 'multiple' => true]);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
// if (!$RFFUID || $RFFUID?->getEstado()?->getId() != 30 && $RFFUID?->getEstado()?->getId() != 40) {
// $this->code = 'info';
// $this->msj = "Imposible continuar, el registro no se encuentra en el estado esperado.";
// return new Response(json_encode(['code' => $this->code, 'msj' => $this->msj, 'url' => $this->url, 'html' => $this->html]));
// }
$files = $form->get('file')->getData();
if (!$files || count($files) == 0) {
$this->code = 'warning';
$this->msj = "Imposible continuar, valide los documentos adjuntos.";
return new Response(json_encode(['code' => $this->code, 'msj' => $this->msj, 'url' => $this->url, 'html' => $this->html]));
}
foreach ($files as $file) {
$rutaArchivo = $this->documentHandler->cargarArchivo($file, $inf['df'], "", $obj->getArchivo());
if ($rutaArchivo['code'] != 'success') {
$this->code = 'warning';
$this->msj = "Imposible cargar el registro, {$rutaArchivo['msj']}";
return new Response(json_encode(['code' => $this->code, 'msj' => $this->msj, 'url' => $this->url, 'html' => $this->html]));
//$contrato->setEstado($this->entityManager->getRepository(\App\Entity\ParEstado::class)->find(1));
}
$inventarioDocumentalArchivo = new \App\Entity\RFInventarioDocumentalArchivos();
$inventarioDocumentalArchivo->setDF($inf['df']);
$inventarioDocumentalArchivo->setIdEntidad($obj->getId());
$inventarioDocumentalArchivo->setArchivo($rutaArchivo['msj']);
$entityManager->persist($inventarioDocumentalArchivo);
}
$obj->setEstado($entityManager->getRepository(\App\Entity\ParEstado::class)->find(40));
$obj->setDisponibilidad($entityManager->getRepository(\App\Entity\ParEstado::class)->find(41));
$obj->setUpdateAt(new \DateTime('now'));
$obj->setUpdateUser($this->getUser()->getUsername());
$entityManager->persist($obj);
$entityManager->flush();
$this->code = 'success';
$this->msj = "Registro almacenado con exito.";
//adicion notificación edicion.
// $this->addFlash('success', "Registro almacenado con exito.");
if ($idNotificacion != 0) {
$estadoInactivo = $entityManager->getRepository(\App\Entity\ParEstado::class)->find(2);
$estadoGestionado = $entityManager->getRepository(\App\Entity\ParEstado::class)->find(63); //nuevo estado solicitado por ajuste
foreach ($entityManager->getRepository(\App\Entity\RFSolicitudDocumento::class)->findBy(['idEntidad' => $obj->getId(), 'estado' => 1]) as $solpen) {
// if ($solpen->getTipoSolicitud()->getId() == 1) {
// $solpen->setEstado($estadoGestionado);
// } else {
// $solpen->setEstado($estadoInactivo);
// }
$solpen->setEstado($estadoGestionado); # Quedar siempre en estado GESTIONADO
$solpen->setUsuarioAtiende($this->getUser()->getPersona());
$solpen->setUpdateUser($this->getUser()->getUsername());
$solpen->setUpdateAt(new \DateTime('now'));
$entityManager->persist($solpen);
$this->mailerCore->solicitudDocumento('gestionar', [$solpen]);
}
$entityManager->flush();
return $this->redirectToRoute('rf_solicitud_documento');
}
return new Response(json_encode(['code' => $this->code, 'msj' => $this->msj, 'url' => $this->url, 'html' => $this->html]));
// return $this->redirectToRoute('rf_fuid_cargar_ubicar', ['id' => $RFFUID->getId()], Response::HTTP_SEE_OTHER);
}
$cantArchivos = $entityManager->getRepository(\App\Entity\RFInventarioDocumentalArchivos::class)->findBy(['DF' => $inf['df'], 'idEntidad' => $obj->getId()]);
return $this->render("rf_fuid/formArchivo.html.twig", [
'tituloFUID' => $inf['titulo'],
$inf['formName'] => $form->createView(),
'fuid' => $RFFUID,
'dirAsset' => $inf['dirAsset'],
'obj' => $obj,
'cantArchivos' => $cantArchivos
]);
}
#[Route('/{id}/notificar_archivo_fisico/{fuid}/{idNotificacion}', name: 'rf_fuid_notificar_archivo_fisico', methods: ['GET', 'POST'])]
public function notificarFisico(Request $request, EntityManagerInterface $entityManager, $id, $fuid, $idNotificacion): Response
{
$RFFUID = $entityManager->getRepository(RFFUID::class)->find($fuid);
$inf = $this->getEntitiFUID($entityManager, $RFFUID, $id);
$obj = $inf['obj'];
$formObj = $inf['formObj'];
$solicitud = $entityManager->getRepository(\App\Entity\RFSolicitudDocumento::class)->find($idNotificacion);
if ($solicitud->getEstado()->getId() != 1) {
$this->code = 'info';
$this->msj = "Imposible continuar, el registro no se encuentra en el estado esperado.";
return new Response(json_encode(['code' => $this->code, 'msj' => $this->msj, 'url' => $this->url, 'html' => $this->html]));
}
$estadoNotificado = $entityManager->getRepository(\App\Entity\ParEstado::class)->find(43);
$solicitud->setFechaNotificacion(new \DateTime('now'));
$solicitud->setEstado($estadoNotificado);
$solicitud->setUsuarioAtiende($this->getUser()->getPersona());
$solicitud->setUpdateUser($this->getUser()->getUsername());
$solicitud->setUpdateAt(new \DateTime('now'));
$entityManager->persist($solicitud);
$entityManager->flush();
$this->code = 'success';
$this->msj = "Registro almacenado con exito.";
$this->mailerCore->solicitudDocumento('gestionar', [$solicitud]);
return new Response(json_encode(['code' => $this->code, 'msj' => $this->msj, 'url' => $this->url, 'html' => $this->html]));
//$this->addFlash('success', "Registro almacenado con exito.");
// return $this->redirectToRoute('rf_solicitud_documento');
}
#[Route('/{id}/eliminar_archivo_inventario/{fuid}/{idArchivo}', name: 'rf_fuid_eliminar_archivo_inventario', methods: ['GET'])]
public function eliminarArchivoInventario(EntityManagerInterface $entityManager, Request $request, $id, $fuid, $idArchivo): Response
{
$RFFUID = $entityManager->getRepository(RFFUID::class)->find($fuid);
$inf = $this->getEntitiFUID($entityManager, $RFFUID, $id);
$obj = $inf['obj'];
$formObj = $inf['formObj'];
$archivo = $entityManager->getRepository(\App\Entity\RFInventarioDocumentalArchivos::class)->find($idArchivo);
#Eliminar archivo para ser recursivo con el servidor
$this->documentHandler->eliminarArchivo(get_class($obj), $archivo->getArchivo());
# $archivo->setIdEntidad(null);
// dump(get_class($obj));
$entityManager->remove($archivo);
$obj->setArchivo(null);
$entityManager->flush();
//$limpiarArhivo = $this->documentHandler->eliminarArchivo($inf['df'], $obj->getArchivo());
$this->code = 'success';
$this->msj = "Registro retirado con exito.";
$this->url = $this->generateUrl('rf_fuid_cargar_archivo_inventario', [
'id' => $id,
'fuid' => $fuid,
]);
return new JsonResponse(['code' => $this->code, 'msj' => $this->msj, 'url' => $this->url, 'html' => $this->html]);
}
#[Route('/{id}/eliminar_inventario/{fuid}', name: 'rf_fuid_eliminar_inventario', methods: ['POST'])]
public function eliminarInventario(Request $request, EntityManagerInterface $entityManager, $id, $fuid): Response
{
$RFFUID = $entityManager->getRepository(RFFUID::class)->find($fuid);
$inf = $this->getEntitiFUID($entityManager, $RFFUID, $id);
$obj = $inf['obj'];
$formObj = $inf['formObj'];
if ($obj->getFUID()->getEstado() != null) {
$this->code = 'info';
$this->msj = "Imposible continuar, el registro no se encuentra en el estado esperado.";
return new Response(json_encode(['code' => $this->code, 'msj' => $this->msj, 'url' => $this->url, 'html' => $this->html]));
}
$limpiarArhivo = $this->documentHandler->eliminarArchivo($inf['df'], $obj->getArchivo());
$entityManager->remove($obj);
$entityManager->flush();
$url = $this->generateUrl('rf_fuid_edit', [
'id' => $RFFUID->getId(),
]);
return new JsonResponse([
'code' => 'success',
'msj' => 'Registro eliminado exitosamente',
'url' => $url,
'html' => ''
]);
}
#[Route('/{id}/finalizar', name: 'rf_fuid_finalizar', methods: ['GET'])]
public function finalizar(Request $request, RFFUID $RFFUID, EntityManagerInterface $entityManager): Response
{
if ($RFFUID->getEstado() != null) {
$this->code = 'info';
$this->msj = "Imposible continuar, el registro no se encuentra en el estado esperado.";
return new Response(json_encode(['code' => $this->code, 'msj' => $this->msj, 'url' => $this->url, 'html' => $this->html]));
}
$RFFUID->setEstado($entityManager->getRepository(\App\Entity\ParEstado::class)->find(30));
//$RFFUID->setEstadoDisponibilidad($entityManager->getRepository(\App\Entity\ParEstado::class)->find(38));
$RFFUID->setUpdateAt(new \DateTime('now'));
$RFFUID->setUpdateUser($this->getUser()->getUsername());
$entityManager->persist($RFFUID);
$entityManager->flush();
//$this->mailerCore->FUID('notificacion', [$RFFUID]);
$this->code = 'success';
$this->msj = "Registro almacenado con exito.";
return new Response(json_encode(['code' => $this->code, 'msj' => $this->msj, 'url' => $this->url, 'html' => $this->html]));
}
#[Route('/{id}/registrar_recepcion', name: 'rf_fuid_registrar_recepcion', methods: ['GET', 'POST'])]
public function registrarRecepcion(Request $request, RFFUID $RFFUID, EntityManagerInterface $entityManager): Response
{
if (!$RFFUID->getEstado() || $RFFUID?->getEstado()?->getId() != 30) {
$this->code = 'info';
$this->msj = "Imposible continuar, el registro no se encuentra en el estado esperado.";
return new Response(json_encode(['code' => $this->code, 'msj' => $this->msj, 'url' => $this->url, 'html' => $this->html]));
}
$form = $this->createForm(RFFUIDType::class, $RFFUID, [
'disabled_fields' => true,
'idUsuarioElabora' => $RFFUID->getUsuarioElabora()->getId()
,
'idSede' => $RFFUID->getSede()->getId()
,
'idProceso' => $RFFUID->getProceso()->getId()
,
'method' => 'POST',
'action' => $this->generateUrl($request->attributes->get('_route'), ['id' => $RFFUID->getId()])
]);
$form
->add('resultadoRevision', null, [
'label' => 'Resultado Revisión',
'placeholder' => 'seleccione una opcion',
'required' => true
])
->add('motivo', null, [
'placeholder' => 'seleccione una opcion',
'required' => true
])
->add('observacionRecepcion', null, [
'label' => 'Observación Recepción',
'attr' => [
'placeholder' => 'seleccione una opcion'
],
'required' => false
]);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$RFFUID->setUsuarioRecibe($this->getUser()->getPersona());
$RFFUID->setFechaRecepcion(new \DateTime('now'));
if ($RFFUID->getMotivo()) {
$RFFUID->setEstado(null);
//$RFFUID->setEstadoDisponibilidad(null);
$this->mailerCore->FUID('rechazo', [$RFFUID]);
} else {
$res = $this->getEntitiesFUID($entityManager, $RFFUID);
$estadoArchivo = $entityManager->getRepository(\App\Entity\ParEstado::class)->find(30);
$estadoDisponible = $entityManager->getRepository(\App\Entity\ParEstado::class)->find(39);
foreach ($res['entities'] as $ent) {
$ent->setEstado($estadoArchivo);
$ent->setDisponibilidad($estadoDisponible);
$ent->setUpdateAt(new \DateTime('now'));
$ent->setUpdateUser($this->getUser()->getUsername());
$entityManager->persist($ent);
}
}
$RFFUID->setUpdateAt(new \DateTime('now'));
$RFFUID->setUpdateUser($this->getUser()->getUsername());
$entityManager->persist($RFFUID);
$entityManager->flush();
$this->code = 'success';
$this->msj = "Registro almacenado con exito.";
return new Response(json_encode(['code' => $this->code, 'msj' => $this->msj, 'url' => $this->url, 'html' => $this->html]));
}
$res = $this->getEntitiesFUID($entityManager, $RFFUID, true);
return $this->renderForm('rf_fuid/recepcion.html.twig', [
'keys' => $res['encabezado'],
'fuid' => $RFFUID,
'form' => $form,
'entities' => $res['entities']
]);
}
#[Route('/{id}/cargar_ubicar', name: 'rf_fuid_cargar_ubicar', methods: ['GET', 'POST'])]
public function cargarUbicar(Request $request, RFFUID $RFFUID, EntityManagerInterface $entityManager): Response
{
if ($RFFUID->getEstado() == null || ($RFFUID->getEstado()->getId() != 30 && $RFFUID->getEstado()->getId() != 40)) {
$this->code = 'warning';
$this->msj = "Imposible continuar, el registro no se encuentra en el estado esperado.";
return new Response(json_encode(['code' => $this->code, 'msj' => $this->msj, 'url' => $this->url, 'html' => $this->html]));
}
$form = $this->createForm(RFFUIDType::class, $RFFUID, [
'disabled_fields' => true,
'idUsuarioElabora' => $RFFUID->getUsuarioElabora()->getId()
,
'idSede' => $RFFUID->getSede()->getId()
,
'idProceso' => $RFFUID->getProceso()->getId()
,
'method' => 'POST',
'action' => $this->generateUrl($request->attributes->get('_route'), ['id' => $RFFUID->getId()])
]);
$form
->add('resultadoRevision', null, [
'placeholder' => 'seleccione una opcion',
'disabled' => true
])
->add('motivo', null, [
'placeholder' => 'seleccione una opcion',
'disabled' => true
])
->add('observacionRecepcion', null, [
'attr' => [
'placeholder' => 'seleccione una opcion'
],
'disabled' => true
])
->add('ubicacion', null, [
'placeholder' => 'seleccione una opcion'
])
->add('numeroPosicion', null, [
'label' => 'Número de Posición',
]);
$form
->remove('caja')
->remove('entidadProductora')
->remove('usuarioResponsable')
->remove('resultadoRevision')
->remove('motivo')
->remove('observacionRecepcion');
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
//control de subida archivos.
$RFFUID->setEstado($entityManager->getRepository(\App\Entity\ParEstado::class)->find(40));
// $RFFUID->setEstadoDisponibilidad($entityManager->getRepository(\App\Entity\ParEstado::class)->find(41));
$RFFUID->setUpdateAt(new \DateTime('now'));
$RFFUID->setUpdateUser($this->getUser()->getUsername());
$entityManager->persist($RFFUID);
$entityManager->flush();
$this->code = 'success';
$this->msj = "Registro almacenado con exito.";
return new Response(json_encode(['code' => $this->code, 'msj' => $this->msj, 'url' => $this->url, 'html' => $this->html]));
}
$res = $this->getEntitiesFUID($entityManager, $RFFUID, true);
return $this->renderForm('rf_fuid/cargarUbicar.html.twig', [
'keys' => $res['encabezado'],
'fuid' => $RFFUID,
'form' => $form,
'entities' => $res['entities']
]);
}
public function getEntitiesFUID(EntityManagerInterface $entityManager, RFFUID $RFFUID, $isArray = false): array
{
$entities = [];
$keys = [];
$tituloFuid = "";
if ($isArray) {
if (count($RFFUID->getInventarioDocumentalComercial()) > 0) {
$entities = $entityManager->getRepository(\App\Entity\RFInventarioDocumentalComercial::class)->getAll([$RFFUID->getId()]);
$tituloFuid = "Documento Comercial";
} else if (count($RFFUID->getInventarioDocumentalComex()) > 0) {
$entities = $entityManager->getRepository(\App\Entity\RFInventarioDocumentalComex::class)->getAll([$RFFUID->getId()]);
$tituloFuid = "Documento Comex";
} else if (count($RFFUID->getInventarioDocumentalFinanzas()) > 0) {
$entities = $entityManager->getRepository(\App\Entity\RFInventarioDocumentalFinanzas::class)->getAll([$RFFUID->getId()]);
$tituloFuid = "Documento Finanzas";
} else if (count($RFFUID->getInventarioDocumentalGesHum()) > 0) {
$entities = $entityManager->getRepository(\App\Entity\RFInventarioDocumentalGesHum::class)->getAll([$RFFUID->getId()]);
$tituloFuid = "Documento Gestion Humana";
} else if (count($RFFUID->getInventarioDocumentalSST()) > 0) {
$entities = $entityManager->getRepository(\App\Entity\RFInventarioDocumentalSST::class)->getAll([$RFFUID->getId()]);
$tituloFuid = "Documento SST";
}
if (isset($entities) && !empty($entities)) {
$keys = array_keys($entities[0]);
}
} else {
if (count($RFFUID->getInventarioDocumentalComercial()) > 0) {
$entities = $RFFUID->getInventarioDocumentalComercial();
$tituloFuid = "Documento Comercial";
} else if (count($RFFUID->getInventarioDocumentalComex()) > 0) {
$entities = $RFFUID->getInventarioDocumentalComex();
$tituloFuid = "Documento Comex";
} else if (count($RFFUID->getInventarioDocumentalFinanzas()) > 0) {
$entities = $RFFUID->getInventarioDocumentalFinanzas();
$tituloFuid = "Documento Finanzas";
} else if (count($RFFUID->getInventarioDocumentalGesHum()) > 0) {
$entities = $RFFUID->getInventarioDocumentalGesHum();
$tituloFuid = "Documento Gestion Humana";
} else if (count($RFFUID->getInventarioDocumentalSST()) > 0) {
$entities = $RFFUID->getInventarioDocumentalSST();
$tituloFuid = "Documento SST";
}
}
return ['encabezado' => $keys, 'entities' => $entities, 'titulo' => $tituloFuid];
}
public function getEntitiFUID(
EntityManagerInterface $entityManager,
RFFUID $RFFUID,
$id
): array {
$map = [
\App\Entity\RFInventarioDocumentalComercial::class => [
'relation' => 'getInventarioDocumentalComercial',
'form' => \App\Form\RFInventarioDocumentalComercialType::class,
'name' => 'formComercial',
'titulo' => 'Editar Documento Comercial',
],
\App\Entity\RFInventarioDocumentalComex::class => [
'relation' => 'getInventarioDocumentalComex',
'form' => \App\Form\RFInventarioDocumentalComexType::class,
'name' => 'formComex',
'titulo' => 'Editar Documento Comex',
],
\App\Entity\RFInventarioDocumentalFinanzas::class => [
'relation' => 'getInventarioDocumentalFinanzas',
'form' => \App\Form\RFInventarioDocumentalFinanzasType::class,
'name' => 'formFinanzas',
'titulo' => 'Editar Documento Finanzas',
],
\App\Entity\RFInventarioDocumentalGesHum::class => [
'relation' => 'getInventarioDocumentalGesHum',
'form' => \App\Form\RFInventarioDocumentalGesHumType::class,
'name' => 'formGesHum',
'titulo' => 'Editar Documento Gestión Humana',
],
\App\Entity\RFInventarioDocumentalSST::class => [
'relation' => 'getInventarioDocumentalSST',
'form' => \App\Form\RFInventarioDocumentalSSTType::class,
'name' => 'formSST',
'titulo' => 'Editar Documento SST',
],
];
foreach ($map as $entityClass => $config) {
// Intentamos buscar el ID en esa entidad
$obj = $entityManager->getRepository($entityClass)->find($id);
if ($obj) {
return [
'df' => $entityClass,
'obj' => $obj,
'formObj' => $config['form'],
'formName' => $config['name'],
'titulo' => $config['titulo'],
'dirAsset' => (new \ReflectionClass($obj))->getShortName(),
];
}
}
throw new \Exception('No se encontró el documento con ID: ' . $id);
}
#[Route('/consulta_archivo', name: 'rf_fuid_consulta_archivo', methods: ['GET'])]
public function consultaArchivo(Request $request, EntityManagerInterface $entityManager): Response
{
$proceso = $this->getUser()->getPersona()->getPerfilCargo()->getParProceso();
$df = $proceso->getFuenteDatosRFFUID();
if ($df) {
$entities = $entityManager->getRepository($df)->consultaArchivo();
} else {
$entities = [];
}
return $this->render('rf_fuid/index.html.twig', [
'entities' => $entities
]);
}
#[Route('/consulta_archivo_comercial', name: 'rf_fuid_consulta_archivo_comercial', methods: ['GET'])]
public function consultaArchivoComercial(Request $request, EntityManagerInterface $entityManager): Response
{
$proceso = $this->getUser()->getPersona()->getPerfilCargo()->getParProceso();
$df = 'App\Entity\RFInventarioDocumentalComercial';
return $this->render('rf_fuid/index.html.twig', [
'entities' => $entityManager->getRepository($df)->consultaArchivo()
]);
}
#[Route('/consulta_archivo_comex', name: 'rf_fuid_consulta_archivo_comex', methods: ['GET'])]
public function consultaArchivoComex(Request $request, EntityManagerInterface $entityManager): Response
{
$proceso = $this->getUser()->getPersona()->getPerfilCargo()->getParProceso();
$df = 'App\Entity\RFInventarioDocumentalComex';
return $this->render('rf_fuid/index.html.twig', [
'entities' => $entityManager->getRepository($df)->consultaArchivo()
]);
}
#[Route('/consulta_archivo_finanzas', name: 'rf_fuid_consulta_archivo_finanzas', methods: ['GET'])]
public function consultaArchivoFinanzas(Request $request, EntityManagerInterface $entityManager): Response
{
$proceso = $this->getUser()->getPersona()->getPerfilCargo()->getParProceso();
$df = 'App\Entity\RFInventarioDocumentalFinanzas';
return $this->render('rf_fuid/index.html.twig', [
'entities' => $entityManager->getRepository($df)->consultaArchivo()
]);
}
#[Route('/consulta_archivo_gestion_humana', name: 'rf_fuid_consulta_archivo_gestion_humana', methods: ['GET'])]
public function consultaArchivoGestionHumana(Request $request, EntityManagerInterface $entityManager): Response
{
$proceso = $this->getUser()->getPersona()->getPerfilCargo()->getParProceso();
$df = 'App\Entity\RFInventarioDocumentalGesHum';
return $this->render('rf_fuid/index.html.twig', [
'entities' => $entityManager->getRepository($df)->consultaArchivo()
]);
}
#[Route('/consulta_archivo_sst', name: 'rf_fuid_consulta_archivo_sst', methods: ['GET'])]
public function consultaArchivoSST(Request $request, EntityManagerInterface $entityManager): Response
{
$proceso = $this->getUser()->getPersona()->getPerfilCargo()->getParProceso();
$df = 'App\Entity\RFInventarioDocumentalSST';
return $this->render('rf_fuid/index.html.twig', [
'entities' => $entityManager->getRepository($df)->consultaArchivo()
]);
}
#[Route('/{id}/solicitar_archivo', name: 'rf_fuid_solicitar_archivo', methods: ['GET', 'POST'])]
public function solicitarArchivo(Request $request, EntityManagerInterface $entityManager, $id): Response
{
if ($this->getUser()->getPersona()->getSede() == null || $this->getUser()->getPersona()->getPerfilCargo() == null) {
$this->code = 'warning';
$this->msj = "Imposible continuar, aun no cuenta con la inforcion de sede y perfil cargo.";
return new Response(json_encode(['code' => $this->code, 'msj' => $this->msj, 'url' => $this->url, 'html' => $this->html]));
}
$proceso = $this->getUser()->getPersona()->getPerfilCargo()->getParProceso();
$df = $proceso->getFuenteDatosRFFUID();
$obj = $entityManager->getRepository($df)->find($id);
if (!$obj && !$obj?->getEstado()) {
$this->code = 'warning';
$this->msj = "Imposible continuar, el registro aun no esta en el estado esperado.";
return new Response(json_encode(['code' => $this->code, 'msj' => $this->msj, 'url' => $this->url, 'html' => $this->html]));
}
$inf = $this->getEntitiFUID($obj);
# dump($inf);
# evaluar si es viene algun mensaje de alerta
if (isset($inf['code'])) {
$this->code = 'error';
$this->msj = "Imposible continuar, el registro aun no esta en el estado esperado.";
return new Response(json_encode(['code' => $this->code, 'msj' => $this->msj, 'url' => $this->url, 'html' => $this->html]));
}
$formObj = $inf['formObj'];
$formName = $inf['formName'];
$form = $this->createForm($formObj, $obj, ['disabled' => true]);
$RFSolicitudDocumento = new \App\Entity\RFSolicitudDocumento();
$tipoSolicitud = [];
$cantArchivos = $entityManager->getRepository(\App\Entity\RFInventarioDocumentalArchivos::class)->findBy(['DF' => $inf['df'], 'idEntidad' => $obj->getId()]);
# Validar si es un objeto valido
if ($obj?->getDisponibilidad()?->getId() == 45 && $obj?->getEstado()?->getId() == 42 && count($cantArchivos) == 0) {
$tipoSolicitud = [1];
} else if ($obj?->getDisponibilidad()?->getId() == 39 && ($obj?->getEstado()?->getId() == 40 || $obj?->getEstado()?->getId() == 30)) {
$tipoSolicitud = [2];
}
$formSolicitud = $this->createForm(
\App\Form\RFSolicitudDocumentoType::class,
$RFSolicitudDocumento,
['tipoSolicitud' => $tipoSolicitud, 'method' => 'POST', 'action' => $this->generateUrl($request->attributes->get('_route'), ['id' => $id])]
);
$formSolicitud->handleRequest($request);
if ($formSolicitud->isSubmitted() && $formSolicitud->isValid()) {
$repetido = $entityManager->getRepository(\App\Entity\RFSolicitudDocumento::class)->findOneBy(['FUID' => $obj->getFUID()->getId(), 'idEntidad' => $obj->getId(), 'usuarioSolicita' => $this->getUser()->getId(), 'estado' => 1]);
if (!$repetido) {
$RFSolicitudDocumento->setFUID($obj->getFUID());
$RFSolicitudDocumento->setDF($df);
$RFSolicitudDocumento->setIdEntidad($obj->getId());
$RFSolicitudDocumento->setUsuarioSolicita($this->getUser()->getPersona());
$RFSolicitudDocumento->setCreateAt(new \DateTime('now'));
$RFSolicitudDocumento->setCreateUser($this->getUser()->getUsername());
$RFSolicitudDocumento->setUpdateAt(new \DateTime('now'));
$RFSolicitudDocumento->setUpdateUser($this->getUser()->getUsername());
$RFSolicitudDocumento->setEstado($entityManager->getRepository(\App\Entity\ParEstado::class)->find(1));
$entityManager->persist($RFSolicitudDocumento);
$entityManager->flush();
}
//if ($RFSolicitudDocumento->getTipoSolicitud()->getId() == 1) {
$this->mailerCore->solicitudDocumento('notificacion', [$RFSolicitudDocumento], [], $obj);
$this->code = 'success';
$this->msj = "Registro almacenado con exito.";
return new Response(json_encode(['code' => $this->code, 'msj' => $this->msj, 'url' => $this->url, 'html' => $this->html]));
}
return $this->render('rf_fuid/solicitarArchivo.html.twig', [
'fuid' => $obj->getFUID(),
'form' => $formSolicitud->createView(),
'tituloFUID' => "",
$formName => $form->createView(),
'dirAsset' => $inf['dirAsset'],
'obj' => $obj
]);
}
# Funcion para ver documentos
#[Route('/{id}/ver_documentos', name: 'rf_fuid_ver_documentos', methods: ['GET', 'POST'])]
public function verDocumentos(Request $request, EntityManagerInterface $entityManager, $id)
{
$proceso = $this->getUser()->getPersona()->getPerfilCargo()->getParProceso();
$df = $proceso->getFuenteDatosRFFUID();
#dump($df);
$obj = $entityManager->getRepository($df)->find($id);
if (!$obj && !$obj?->getEstado()) {
$this->code = 'warning';
$this->msj = "Imposible continuar, el registro aun no esta en el estado esperado.";
return new Response(json_encode(['code' => $this->code, 'msj' => $this->msj, 'url' => $this->url, 'html' => $this->html]));
}
#dump($obj);
$nombreClase = (new \ReflectionClass($obj))->getShortName();
dump($nombreClase);
return $this->render('rf_fuid/verDocumentos.html.twig', [
'entidad' => $obj, # forzar la clase
'claseCarpeta' => $nombreClase,
]);
}
#[Route('/{id}/tracking_archivo', name: 'rf_fuid_tracking_archivo', methods: ['GET', 'POST'])]
public function trackingArchivo(Request $request, EntityManagerInterface $entityManager, $id): Response
{
// if ($this->getUser()->getPersona()->getSede() == null || $this->getUser()->getPersona()->getPerfilCargo() == null) {
// $this->code = 'warning';
// $this->msj = "Imposible continuar, aun no cuenta con la inforcion de sede y perfil cargo.";
// return new Response(json_encode(['code' => $this->code, 'msj' => $this->msj, 'url' => $this->url, 'html' => $this->html]));
// }
$proceso = $this->getUser()->getPersona()->getPerfilCargo()->getParProceso();
$df = $proceso->getFuenteDatosRFFUID();
$obj = $entityManager->getRepository($df)->find($id);
// dump($obj);
if (!$obj && !$obj?->getEstado()) {
$this->code = 'warning';
$this->msj = "Imposible continuar, el registro aun no esta en el estado esperado.";
return new Response(json_encode(['code' => $this->code, 'msj' => $this->msj, 'url' => $this->url, 'html' => $this->html]));
}
$inf = $this->getEntitiFUID($entityManager, $obj->getFUID(), $id);
$formObj = $inf['formObj'];
$formName = $inf['formName'];
$form = $this->createForm($formObj, $obj, ['disabled' => true]);
$solicitudes = $entityManager->getRepository(\App\Entity\RFSolicitudDocumento::class)->findBy(['DF' => $inf['df'], 'idEntidad' => $obj->getId()], ['createAt' => 'DESC']);
return $this->render('rf_fuid/trackingArchivo.html.twig', [
'fuid' => $obj->getFUID(),
'tituloFUID' => "",
$formName => $form->createView(),
'dirAsset' => $inf['dirAsset'],
'obj' => $obj,
'solicitudes' => $solicitudes,
]);
}
#[Route('/buscar_cedula_usuario', name: 'rf_fuid_buscar_cedula_usuario', methods: ['GET', 'POST'])]
public function buscarCedula(Request $request, EntityManagerInterface $entityManager): Response
{
$numDoc = $request->request->get('numDoc');
$persona = $entityManager->getRepository(\App\Entity\TerPersona::class)->findOneBy(['numeroDocumento' => $numDoc]);
$res = [];
if ($persona) {
$res = ['idPer' => $persona->getId()];
}
return new Response(json_encode($res));
}
}