src/Controller/Admin/DashboardController.php line 5404

  1. <?php
  2. namespace App\Controller\Admin;
  3. use EasyCorp\Bundle\EasyAdminBundle\Config\Dashboard;
  4. use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem;
  5. use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractDashboardController;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. use Aws\S3\S3Client;
  9. use Symfony\Component\Uid\Uuid;
  10. use Doctrine\Persistence\ManagerRegistry;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use App\Entity\Caixa;
  13. use App\Entity\Documento;
  14. use App\Entity\Tipo;
  15. use App\Entity\Classificacao;
  16. use App\Entity\Cliente;
  17. use App\Entity\User;
  18. use App\Entity\Cx;
  19. use App\Entity\ClienteAll;
  20. use App\Entity\Registro;
  21. use App\Entity\Fluxo;
  22. use App\Entity\Etapa;
  23. use App\Entity\MessengerMessages;
  24. use Doctrine\ORM\EntityManagerInterface;
  25. use setasign\Fpdi\Tcpdf\Fpdi;
  26. use setasign\Fpdi\PdfReader;
  27. use propa\tcpdi\tcpdi;
  28. use Symfony\Component\Dotenv\Dotenv;
  29. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  30. use Symfony\Component\String\Slugger\AsciiSlugger;
  31. use App\Form\UploadType;
  32. use PhpOffice\PhpSpreadsheet\IOFactory;
  33. use Symfony\Component\Mime\Email;
  34. use Symfony\Component\Mailer\MailerInterface;
  35. use Knp\Component\Pager\PaginatorInterface;
  36. use Dompdf\Dompdf;
  37. use Dompdf\Options;
  38. use Endroid\QrCode\Builder\Builder;
  39. use Endroid\QrCode\Encoding\Encoding;
  40. use Twig\Environment;
  41. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  42. use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
  43. use PhpOffice\PhpSpreadsheet\Shared\Date;
  44. use PhpOffice\PhpSpreadsheet\Style\Color;
  45. use PhpOffice\PhpSpreadsheet\Style\Fill;
  46. use Endroid\QrCode\ErrorCorrectionLevel\ErrorCorrectionLevelHigh;
  47. use Endroid\QrCode\Writer\PngWriter;
  48. use App\Message\UploadMultipartMessage;
  49. use Symfony\Component\Messenger\MessageBusInterface;
  50. use Symfony\Component\HttpFoundation\JsonResponse
  51. use DateTime;
  52. class DashboardController extends AbstractDashboardController
  53. {
  54.     
  55.     #[Route('/'name'inicial')]
  56.     public function home(): Response
  57.     {
  58.         
  59.         return $this->redirectToRoute('home');
  60.     }
  61.     
  62.     #[Route('/login_sucess'name'login_sucess')]
  63.     public function login_sucess(Request $request,ManagerRegistry $doctrineEntityManagerInterface $entityManager): Response
  64.     {
  65.         
  66.     
  67.         $user_logado $this->getUser();
  68.         $enabled $user_logado->getEnabled();
  69.         if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
  70.             $ip_cliente explode(','$_SERVER['HTTP_X_FORWARDED_FOR'])[0];
  71.         } else {
  72.             $ip_cliente $_SERVER['REMOTE_ADDR'];
  73.         }
  74.         
  75.           if($enabled == false){
  76.             $error ="Tentativa de login de usuário desativado";
  77.             $user_logado_nome=$user_logado->getNome();
  78.             $hoje = new \DateTimeImmutable('America/Sao_Paulo');
  79.             $registro = new Registro();
  80.             $registro->setOperacao($error);
  81.             $registro->setUser($user_logado_nome);
  82.             $registro->setData($hoje);
  83.             $registro->setIp($ip_cliente);
  84.             $entityManager->persist($registro);
  85.             $entityManager->flush();
  86.             return $this->redirectToRoute('app_logout');
  87.         }
  88.         
  89.         
  90.         
  91.         
  92.         $error ="Login Realizado";
  93.         $user_logado_nome=$user_logado->getNome();
  94.         $hoje = new \DateTimeImmutable('America/Sao_Paulo');
  95.         $registro = new Registro();
  96.         $registro->setOperacao($error);
  97.         $registro->setUser($user_logado_nome);
  98.         $registro->setData($hoje);
  99.         $registro->setIp($ip_cliente);
  100.         $entityManager->persist($registro);
  101.         $entityManager->flush();
  102.         
  103.       
  104.         
  105.         
  106.         
  107.         
  108.         
  109.         return $this->redirectToRoute('home');     
  110.     }
  111.     
  112.     #[Route('/index/home'name'home')]
  113.     public function inicial(PaginatorInterface $paginator,Request $request,ManagerRegistry $doctrineEntityManagerInterface $entityManagerSessionInterface $sessionMailerInterface $mailer): Response
  114.     {
  115.         $user_logado $this->getUser();
  116.         $user_logado_id $user_logado->getId();
  117.         $cliente =  $doctrine->getRepository(User::class)->findClientsByUserId($user_logado_id);
  118.         $erro '';
  119.         $pagina 'home';
  120.         $p ='';
  121.         
  122.         $etapas  null;
  123.         if(isset($_POST["btn_cliente"])){
  124.             
  125.             $session->set('cliente_id'$_POST["btn_cliente"]);
  126.             return $this->redirectToRoute('home');
  127.         }
  128.         
  129.         $clienteId $session->get('cliente_id');
  130.         
  131.         $etapas $doctrine->getRepository(Etapa::class)->findByUserAndUpdatedAt($user_logado);
  132.         
  133.        
  134.         return $this->render('index/index6.html.twig', [
  135.     
  136.             
  137.             'p'=>$p,
  138.             'erro'=>$erro,
  139.             'pagina' => $pagina,
  140.             'etapas'=>$etapas,
  141.             'cliente' => $cliente,
  142.             'clienteId' => $clienteId
  143.             
  144.             
  145.         ]);
  146.     } 
  147.     #[Route('/index/troca'name'troca')]
  148.     public function troca(SessionInterface $session): Response
  149.     {
  150.        
  151.         $session->remove('cliente_id');
  152.         $session->invalidate();
  153.         return $this->redirectToRoute('home');
  154.     }
  155.     #[Route('/index/export'name'export')]
  156.     public function export(Request $request,ManagerRegistry $doctrineEntityManagerInterface $entityManagerSessionInterface $session,MessageBusInterface $bus): Response
  157.     {
  158.         
  159.         
  160.         $pendingMessages $entityManager->getRepository(MessengerMessages::class)->countPendingMessages();
  161.         
  162.         #dd($pendingMessages);
  163.         
  164.         $user_logado $this->getUser();
  165.         $user_logado_id $user_logado->getId();
  166.         $userId $user_logado_id;
  167.         $cliente =  $doctrine->getRepository(User::class)->findClientsByUserId($user_logado_id);
  168.         $dotenv = new Dotenv();
  169.         $dotenv->load(__DIR__.'/.env');
  170.         $hoje = new \DateTimeImmutable('America/Sao_Paulo');
  171.         $hoje_formt=$hoje->format('Y-m-d') ;
  172.         $doc $entityManager->getRepository(Documento::class)->findByUserAndDate($user_logado_id$hoje_formt);
  173.         $dia_prod 'de hoje';
  174.         
  175.    
  176.         if(isset($_POST["date_perio"])){
  177.             
  178.             
  179.             $startDate $_POST["de"];
  180.             $endDate $_POST["ate"];
  181.        
  182.             $de = new \DateTimeImmutable($startDate);
  183.             $ate = new \DateTimeImmutable($endDate);
  184.             $de_formt=$de->format('d/m/Y') ;
  185.             $ate_formt=$ate->format('d/m/Y') ;
  186.             
  187.             if($endDate != ""){ 
  188.                 
  189.                 $doc $entityManager->getRepository(Documento::class)->findByUserAndDateRange($user_logado_id$startDate$endDate);
  190.                 $dia_prod 'de '$de_formt.' até '.$ate_formt
  191.             
  192.             }
  193.             if($endDate == ""){ 
  194.                 
  195.                 $doc $entityManager->getRepository(Documento::class)->findByUserAndDate($user_logado_id$startDate);
  196.                 $dia_prod 'de '$de_formt
  197.             }
  198.             
  199.             
  200.         }
  201.         
  202.         if(isset($_POST["btn_cliente"])){
  203.             
  204.             $session->set('cliente_id'$_POST["btn_cliente"]);
  205.             return $this->redirectToRoute('home');
  206.         }
  207.         $clienteId $session->get('cliente_id');
  208.         
  209.         
  210.         
  211.         if ($clienteId == null ) {
  212.             
  213.             $caixas =  "";
  214.             $index_all ="";
  215.             $documentos="";
  216.             $cliente_session "";
  217.             $cliente_alls "";
  218.        
  219.         } else {
  220.             $index_all =  $doctrine->getRepository(Tipo::class)->findBy(['cliente' => $clienteId]);
  221.             $caixas $entityManager->getRepository(Cliente::class)->findCaixasByClienteId($clienteId);
  222.             $documentos =  $doctrine->getRepository(Documento::class)->findBy(['tipo' => null ,'cliente' => $clienteId]);
  223.             $cliente_session =  $doctrine->getRepository(Cliente::class)->find($clienteId);
  224.             $cliente_alls $cliente_session->getClienteAll()->getId();
  225.         }
  226.         $erro '';
  227.         $ii=0;
  228.         $pagina 'export';
  229.         $p '';
  230.         $link '';
  231.         $mx 0;
  232.         $xy 
  233.         $yz 
  234.         $ay ;
  235.         $ky ;
  236.         $pdf ='';
  237.         $pagina_h4 ='Documento(s) para indexar';
  238.         $nome_menu_ '';
  239.         $index_tipo='';
  240.         
  241.         $user $this->getUser();
  242.         $user_nome$user->getEmail();
  243.         $user_nome_name$user->getNome();
  244.         $pasta_user=$user_nome.'/';
  245.         $arr = [];
  246.         $arrr=0;
  247.         $index_find null;
  248.         $dt '';
  249.         $clientS3 = new  S3Client([
  250.             'region'  => 'sa-east-1',
  251.             'version' => 'latest',
  252.             'credentials' => [ 
  253.                 'key'    => $_ENV['AWS_KEY'],
  254.                 'secret' => $_ENV['AWS_SECRET'],
  255.             ],
  256.         ]);
  257.         
  258.        if (isset($_POST["botao_export"])) {
  259.             $caixaId $_POST["caixas"];
  260.             $caixa_id $doctrine->getRepository(Caixa::class)->find($_POST["caixas"]);
  261.             $cliente_id $doctrine->getRepository(Cliente::class)->find($clienteId);
  262.             $clientes_status$cliente_id->getExtraFields();
  263.             if(!$clientes_status){
  264.                 $clientes_status="ged";
  265.             }
  266.             $cliente_nome $cliente_id->getNome();
  267.             $clientes $cliente_id->getId();
  268.             $conteiner $_POST["conteiner"];
  269.             $cont_file 0;
  270.             $umlautString $cliente_nome;
  271.             $slugger = new AsciiSlugger();
  272.             $teste $slugger->slug($umlautString$seperator '-')->toString();
  273.             $caminho strtolower($teste '/');
  274.             if ($clientes == 14) { $caminho 'cartorio-1deg-oficio-de-volta-redonda-rj/'; }
  275.             if ($clientes == 83) { $caminho 'casf-corretora-apolice-diversos/'; }
  276.             if ($clientes == 35) { $caminho 'pmecj-sp-saude/'; }
  277.             if ($clientes == 107) { $caminho 'pmecj-sp-execucao-fiscal/'; }
  278.             if ($clientes == 4) { $caminho 'cartorio-souza-reis-barra-mansa/'; }
  279.             if ($clientes == 112) { $caminho 'saae-cartao-de-ponto/'; }
  280.             if ($clientes == 15) { $caminho 'cbsi-dossies/'; }
  281.             if ($clientes == 55) { $caminho 'casf-gerep-contratos-de-prestadores-de-saude-pj/'; }
  282.             if ($clientes == 13) { $caminho 'casa-de-saude-santa-maria-c-s-s.M/'; }
  283.             if ($clientes == 40) { $caminho 'fasf-atas-e-diarios/'; }
  284.         
  285.             $filesTmp  $_FILES['file']['tmp_name'];
  286.             $filesName $_FILES['file']['name'];
  287.             
  288.             foreach ($filesTmp as $index => $file) {
  289.             
  290.                 $uuid Uuid::v4();
  291.                 $cont_file++;
  292.                 
  293.                 
  294.                 // nome original do arquivo
  295.                 $originalName pathinfo($filesName[$index], PATHINFO_FILENAME);
  296.                 
  297.                 // sanitiza o nome (remove acentos, espaços estranhos etc.)
  298.                 $slugger = new AsciiSlugger();
  299.                 $safeName strtolower($slugger->slug($originalName)->toString());
  300.                 
  301.                 // 🔹 Se cliente for local, usa nome original
  302.                 if ($clientes_status === 'local') {
  303.             
  304.             
  305.                     $filename $safeName '.pdf';
  306.             
  307.                 } else {
  308.                     if ($cliente_alls === 42) {
  309.                          $filename $originalName '.pdf';
  310.                     }else{
  311.                         $filename $uuid '.pdf';
  312.                     }
  313.                 }
  314.             
  315.                 $tempDir __DIR__ '/../../var/uploads/messenger';
  316.                 if (!is_dir($tempDir)) {
  317.                     mkdir($tempDir0777true);
  318.                 }
  319.             
  320.                 $tempFilePath $tempDir '/' $filename;
  321.             
  322.                 move_uploaded_file($file$tempFilePath);
  323.                 chmod($tempFilePath0644);
  324.                 if (!file_exists($tempFilePath) || filesize($tempFilePath) === 0) {
  325.                     throw new \RuntimeException(
  326.                         'Falha ao gravar PDF temporário: ' $tempFilePath
  327.                     );
  328.                 }
  329.                 
  330.                 // evita race condition de filesystem
  331.                 clearstatcache(true$tempFilePath);
  332.                 
  333.                 
  334.                 
  335.                 
  336.                 $bus->dispatch(new UploadMultipartMessage(
  337.                     $tempFilePath,
  338.                     $filename,
  339.                     $caminho,
  340.                     '',
  341.                     $caixaId,
  342.                     $clienteId,
  343.                     $userId,
  344.                     0,
  345.                     $conteiner,
  346.                     $clientes,
  347.                     $clientes_status,
  348.                     $safeName,
  349.                     $originalName,
  350.                     $cliente_alls
  351.                 ));
  352.             }
  353.         
  354.             $log = new Registro();
  355.             $log->setOperacao('EXPORTOU ' $cont_file ' DOCUMENTO(S)');
  356.             $log->setUser($user_nome_name);
  357.             $log->setCliente($cliente_nome);
  358.             $entityManager->persist($log);
  359.             $entityManager->flush();
  360.         
  361.             return $this->redirectToRoute('export');
  362.         }
  363.       
  364.         return $this->render('index/index.html.twig', [
  365.             'documentos' => $documentos,
  366.             'xy' => $xy,
  367.             'yz' => $yz,
  368.             'ay'=>$ay,
  369.             'link' => $link,
  370.             'pdf'=>$pdf,
  371.             'p'=>$p,
  372.             'erro'=>$erro,
  373.             'index_all'=>$index_all,
  374.             'index_tipo'=>$index_tipo,
  375.             'ky'=>$ky,
  376.             'pagina' => $pagina,
  377.             'pagina_h4' =>$pagina_h4,
  378.             'index_find'=>$index_find,
  379.             'mx'=>$mx,
  380.             'caixas' => $caixas,
  381.             'user_logado' => $user_logado,
  382.             'cliente' => $cliente,
  383.             'cliente_session' => $cliente_session,
  384.             'doc'=>$doc,
  385.             'dia_prod' => $dia_prod
  386.         ]);
  387.     }
  388.     
  389.     #[Route('/index/planilha'name'planilha')]
  390.     public function planilha(Request $request,ManagerRegistry $doctrineEntityManagerInterface $entityManagerSessionInterface $session): Response
  391.     {
  392.         
  393.       
  394.         $form $this->createForm(UploadType::class);
  395.         $user_logado$this->getUser();
  396.         $user_logado_id $user_logado->getId();
  397.         $user_nome_name$user_logado->getNome();
  398.         $cliente =  $doctrine->getRepository(User::class)->findClientsByUserId($user_logado_id);
  399.         $form->handleRequest($request);
  400.         $dotenv = new Dotenv();
  401.         $dotenv->load(__DIR__.'/.env');
  402.         $erro '';
  403.         $excel 0;
  404.         $pagina 'index';
  405.         $p '';
  406.         $clientS3 = new  S3Client([
  407.             'region'  => 'sa-east-1',
  408.             'version' => 'latest',
  409.             'credentials' => [ 
  410.                 'key'    => $_ENV['AWS_KEY'],
  411.                 'secret' => $_ENV['AWS_SECRET'],
  412.             ],
  413.         ]);
  414.    
  415.         
  416.         
  417.         if(isset($_POST["btn_cliente"])){
  418.             
  419.             $session->set('cliente_id'$_POST["btn_cliente"]);
  420.             return $this->redirectToRoute('home');
  421.         }
  422.         $clienteId $session->get('cliente_id');
  423.         
  424.         
  425.         
  426.         if ($clienteId == null ) {
  427.             
  428.             $caixas =  "";
  429.             $index_all ="";
  430.             $documentos="";
  431.             $cliente_session "";
  432.        
  433.         } else {
  434.             $index_all =  $doctrine->getRepository(Tipo::class)->findBy(['cliente' => $clienteId]);
  435.             $caixas $entityManager->getRepository(Cliente::class)->findCaixasByClienteId($clienteId);
  436.             $documentos =  $doctrine->getRepository(Documento::class)->findBy(['tipo' => null ,'cliente' => $clienteId]);
  437.             $cliente_session =  $doctrine->getRepository(Cliente::class)->find($clienteId);
  438.             $cliente_nome$cliente_session->getNome();
  439.             
  440.         }
  441.         
  442.         
  443.        
  444.         
  445.       
  446.         if ($form->isSubmitted() && $form->isValid()) {
  447.             $list =[];
  448.             $file $form['file']->getData();
  449.             $spreadsheet IOFactory::load($file->getPathname());
  450.             $sheetData $spreadsheet->getActiveSheet()->toArray();
  451.             foreach ($sheetData as $row) {
  452.                 $excel ++;
  453.                 $id_cx null ;
  454.                 $selections $_POST["selections"];
  455.                 $nome array_search('0'$selections);
  456.                 $caixa array_search('1'$selections);
  457.                 $assunto array_search('2'$selections);
  458.                 $keywod array_search('3'$selections);
  459.                 $data_documento array_search('4'$selections);
  460.                 $data_vecimento array_search('5'$selections);
  461.                 $descricao  array_search('6'$selections);
  462.                 
  463.                 if ($caixa != false ) {
  464.                         
  465.                     
  466.                     $numerosExcel preg_replace('/\D/'''$row[$caixa]);
  467.                     foreach ($caixas as $key) {
  468.                         $nome_cx $key->getNome();
  469.                         $numerosCaixa preg_replace('/\D/'''$nome_cx);
  470.                         if ($numerosCaixa == $numerosExcel ) {
  471.                             
  472.                                 $id_cx $key->getId();
  473.                         }
  474.                     }
  475.                     
  476.                     
  477.                     if ($id_cx == null) {
  478.                         echo '<script>alert("ERRO NA LINHA '.$excel.' NÃO EXISTE ESSA CAIXA CADASTRADA")</script>';
  479.                             return $this->render('index/index2.html.twig', [
  480.                             'documentos' => $documentos,
  481.                             'p'=>$p,
  482.                             'erro'=>$erro,
  483.                             'index_all'=>$index_all,
  484.                             'pagina' => $pagina,
  485.                             'caixas' => $caixas,
  486.                             'user_logado' => $user_logado,
  487.                             'cliente' => $cliente,
  488.                             'cliente_session' => $cliente_session,
  489.                             'form' => $form->createView(),
  490.                                             ]);
  491.                     }
  492.                 }
  493.                 
  494.                 
  495.                     $yourEntity = new Documento();
  496.                     // Ajuste conforme necessário
  497.                     $yourEntity->setUser($user_logado);
  498.                     $yourEntity->setCliente($cliente_session);
  499.                     $yourEntity->setClassificacao($doctrine->getRepository(Classificacao::class)->find(1));
  500.                     $yourEntity->setTipo($doctrine->getRepository(Tipo::class)->find($_POST["tipo"]));
  501.                     $yourEntity->setNome($row[$nome]); 
  502.                     if ($assunto != false ) {$yourEntity->setAssunto($row[$assunto]);}
  503.                     if ($caixa != false ) {$yourEntity->setCaixa($doctrine->getRepository(Caixa::class)->find($id_cx));}
  504.                     if ($keywod != false ) {$yourEntity->setKeywords($row[$keywod]);}
  505.                     if (!empty(trim($row[$data_documento])) && strtoupper(trim($row[$data_documento])) !== "NULL") {
  506.                         $yourEntity->setDataDocumento(new \DateTimeImmutable($row[$data_documento]));
  507.                     }
  508.                     
  509.                     #if (!empty(trim($row[$data_vecimento])) && strtoupper(trim($row[$data_vecimento])) !== "NULL") {
  510.                      #   $yourEntity->setVencimentoDocumento(new \DateTimeImmutable($row[$data_vecimento]));
  511.                     #}
  512.                     if ($descricao != false ) {$yourEntity->setExtraFields($row[$descricao]);}
  513.                     $entityManager->persist($yourEntity);
  514.                     $entityManager->flush();
  515.                     $erro "ok";
  516.                     
  517.                    
  518.                     
  519.             }
  520.                 
  521.                 $log = new Registro();
  522.                 $log->setOperacao('PLANILHA EXPORTADA, '.$excel .' CADASTROS INSERIDOS.' ); 
  523.                 $log->setUser($user_nome_name);
  524.                 $log->setCliente($cliente_nome);
  525.                 $entityManager->persist($log);
  526.                 $entityManager->flush();
  527.                 $erro "ok";
  528.                 if ($excel>1)  {$p =  'PLANILHA EXPORTADA COM SUCESSO, '.$excel .' CADASTROS INSERIDOS , .' ;}
  529.                 if ($excel==1) {$p =  'PLANILHA EXPORTADA COM SUCESSO, '.$excel .' CADASTRO INSERIDO ,' ;}
  530.             
  531.         }
  532.         
  533.         return $this->render('index/index2.html.twig', [
  534.                             'documentos' => $documentos,
  535.                             'p'=>$p,
  536.                             'erro'=>$erro,
  537.                             'index_all'=>$index_all,
  538.                             'pagina' => $pagina,
  539.                             'caixas' => $caixas,
  540.                             'user_logado' => $user_logado,
  541.                             'cliente' => $cliente,
  542.                             'cliente_session' => $cliente_session,
  543.                             'form' => $form->createView(),
  544.                                             ]);
  545.        
  546.     }
  547.     
  548.     #[Route('/index/planilha/classificacao'name'planilha_classificacao')]
  549.     public function planilha_classificacao(Request $request,ManagerRegistry $doctrineEntityManagerInterface $entityManagerSessionInterface $session): Response
  550.     {
  551.         
  552.       
  553.         $form $this->createForm(UploadType::class);
  554.         $user_logado$this->getUser();
  555.         $user_logado_id $user_logado->getId();
  556.         $user_nome_name$user_logado->getNome();
  557.         $cliente =  $doctrine->getRepository(User::class)->findClientsByUserId($user_logado_id);
  558.         $form->handleRequest($request);
  559.         $erro '';
  560.         $excel 0;
  561.         $pagina 'index';
  562.         $p '';
  563.         if(isset($_POST["btn_cliente"])){
  564.             
  565.             $session->set('cliente_id'$_POST["btn_cliente"]);
  566.             return $this->redirectToRoute('home');
  567.         }
  568.         $clienteId $session->get('cliente_id');
  569.         
  570.         
  571.         
  572.         if ($clienteId == null ) {
  573.             
  574.             $caixas =  "";
  575.             $cliente_session "";
  576.        
  577.         } else {
  578.             $cliente_session =  $doctrine->getRepository(Cliente::class)->find($clienteId);
  579.             $cliente_nome$cliente_session->getNome();  
  580.         }
  581.         
  582.         
  583.        
  584.         
  585.       
  586.         if ($form->isSubmitted() && $form->isValid()) {
  587.             $list =[];
  588.             $file $form['file']->getData();
  589.             $spreadsheet IOFactory::load($file->getPathname());
  590.             $sheetData $spreadsheet->getActiveSheet()->toArray();
  591.             foreach ($sheetData as $row) {
  592.                 $excel ++;
  593.                 $id_cx null ;
  594.                 $selections $_POST["selections"];
  595.                 $nome array_search('0'$selections);
  596.                 $fase_corrente array_search('1'$selections);
  597.                 $fase_intermediaria array_search('2'$selections);
  598.                 $destinacao_final array_search('3'$selections);
  599.                 $observacoes array_search('4'$selections);
  600.                 $descricao array_search('5'$selections);
  601.                 
  602.                 
  603.                 if($row[$nome] != null){
  604.                 
  605.                     $yourEntity = new Classificacao();
  606.                     $yourEntity->setNome($row[$nome]);
  607.                     $yourEntity->setFaseCorrente($row[$fase_corrente]);
  608.                     $yourEntity->setFaseIntermediaria($row[$fase_intermediaria]);
  609.                     $yourEntity->setDestinacaoFinal($row[$destinacao_final]);
  610.                     $yourEntity->setObservacoes($row[$observacoes]);
  611.                     $yourEntity->setExtraFields($row[$descricao]);
  612.                     $yourEntity->setCliente($cliente_session);
  613.                     $entityManager->persist($yourEntity);
  614.                     $entityManager->flush();
  615.                     $erro "ok";
  616.                 }
  617.                
  618.                     
  619.                    
  620.                     
  621.             }
  622.                 
  623.             $log = new Registro();
  624.             $log->setOperacao('PLANILHA EXPORTADA, '.$excel .' CADASTROS INSERIDOS.' ); 
  625.             $log->setUser($user_nome_name);
  626.             $log->setCliente($cliente_nome);
  627.             $entityManager->persist($log);
  628.             $entityManager->flush();
  629.             $erro "ok";
  630.             if ($excel>1)  {$p =  'PLANILHA EXPORTADA COM SUCESSO, '.$excel .' CADASTROS INSERIDOS , .' ;}
  631.             if ($excel==1) {$p =  'PLANILHA EXPORTADA COM SUCESSO, '.$excel .' CADASTRO INSERIDO ,' ;}
  632.             
  633.         }
  634.         
  635.         return $this->render('index/index_classificao.html.twig', [
  636.                             'p'=>$p,
  637.                             'erro'=>$erro,
  638.                             'pagina' => $pagina,
  639.                             'user_logado' => $user_logado,
  640.                             'cliente' => $cliente,
  641.                             'cliente_session' => $cliente_session,
  642.                             'form' => $form->createView(),
  643.                                             ]);
  644.        
  645.     }
  646.     #[Route('/index'name'index')]
  647.     public function indexar(Request $request,ManagerRegistry $doctrineEntityManagerInterface $entityManager SessionInterface $session): Response
  648.     {
  649.         $dotenv = new Dotenv();
  650.         $dotenv->load(__DIR__.'/.env');
  651.         $user_logado $this->getUser();
  652.         $form $this->createForm(UploadType::class);
  653.         $form->handleRequest($request);
  654.         $user_logado_tipoAcesso $user_logado->getTipoAcesso();
  655.         $user_logado_nome $user_logado->getNome();
  656.         $user_logado_id $user_logado->getId();
  657.         $cliente =  $doctrine->getRepository(User::class)->findClientsByUserId($user_logado_id);
  658.         $hoje = new \DateTimeImmutable('America/Sao_Paulo');
  659.         $hoje_formt=$hoje->format('Y-m-d');
  660.         $doc $entityManager->getRepository(Documento::class)->findByUserIndexAndDate($user_logado_nome$hoje_formt);
  661.         $dia_prod 'de hoje';
  662.         $permissao = [];
  663.         $list_indexador = [];
  664.          
  665.         if(isset($_POST["btn_cliente"])){
  666.             
  667.             $session->set('cliente_id'$_POST["btn_cliente"]);
  668.             return $this->redirectToRoute('home');
  669.         }
  670.         $clienteId $session->get('cliente_id');
  671.         if ($clienteId == null ) {
  672.             
  673.             $caixas =  "";
  674.             $index_all ="";
  675.             $documentos="";
  676.             $cliente_session "";
  677.        
  678.         } else {
  679.             
  680.             $index_all =  $doctrine->getRepository(Tipo::class)->findBy(['cliente' => $clienteId]);
  681.             $caixas $entityManager->getRepository(Cliente::class)->findCaixasByClienteId($clienteId);
  682.             $documentos =  $doctrine->getRepository(Documento::class)->findBy(['tipo' => null ,'cliente' => $clienteId]);
  683.             $cliente_session =  $doctrine->getRepository(Cliente::class)->find($clienteId);
  684.             
  685.             
  686.         }
  687.        
  688.         if(isset($_POST["date_perio"])){
  689.             
  690.             
  691.             $startDate $_POST["de"];
  692.             $endDate $_POST["ate"];
  693.        
  694.             $de = new \DateTimeImmutable($startDate);
  695.             $ate = new \DateTimeImmutable($endDate);
  696.             $de_formt=$de->format('d/m/Y') ;
  697.             $ate_formt=$ate->format('d/m/Y') ;
  698.             
  699.             if($endDate != ""){ 
  700.                 
  701.                 $doc $entityManager->getRepository(Documento::class)->findByUserAndDateIndexRange($user_logado_nome$startDate$endDate);
  702.                 $dia_prod 'de '$de_formt.' até '.$ate_formt
  703.             
  704.             }
  705.             if($endDate == ""){ 
  706.                 
  707.                 $doc $entityManager->getRepository(Documento::class)->findByUserIndexAndDate($user_logado_nome$startDate);
  708.                 $dia_prod 'de '$de_formt
  709.             }
  710.             
  711.             
  712.             
  713.         }
  714.        
  715.         
  716.         foreach ($user_logado_tipoAcesso["new"] as  $value) {
  717.             
  718.             foreach ($index_all as $key) {
  719.                 if ( $key->getId() ==  $value) {
  720.                     
  721.                     $permissao[] = $value;
  722.                     
  723.                 }
  724.                
  725.             }
  726.         }
  727.     
  728.         $documentos =  $doctrine->getRepository(Documento::class)->findBy(['tipo' => null 'cliente' => $clienteId]);
  729.         
  730.         $class =  $doctrine->getRepository(Classificacao::class)->findBy(['cliente' => $clienteId]);
  731.         $cliente_id $doctrine->getRepository(Cliente::class)->findBy(['id' => $clienteId]);
  732.         
  733.        
  734.         
  735.         
  736.         foreach ($cliente_id as $cliente_ids) {
  737.             
  738.             $cliente_nome$cliente_ids->getNome();
  739.             $clientes$cliente_ids->getId();
  740.             $umlautString =$cliente_nome;
  741.             $slugger = new AsciiSlugger();
  742.             $teste=$slugger->slug($umlautString$seperator '-')->toString();
  743.             $caminho strtolower ($teste.'/');
  744.                         
  745.             if($clientes == 14){$caminho='cartorio-1deg-oficio-de-volta-redonda-rj/';}
  746.             if($clientes == 83){$caminho='casf-corretora-apolice-diversos/';}
  747.             if($clientes == 35){$caminho='pmecj-sp-saude/';}
  748.             if($clientes == 107){$caminho='pmecj-sp-execucao-fiscal/';}
  749.             if($clientes ==  4){$caminho='cartorio-souza-reis-barra-mansa/';}
  750.             if($clientes ==  112){$caminho='saae-cartao-de-ponto/';}
  751.             if($clientes ==  15){$caminho='cbsi-dossies/';}
  752.             if($clientes ==  55){$caminho='casf-gerep-contratos-de-prestadores-de-saude-pj/';}
  753.             if($clientes ==  13){$caminho='casa-de-saude-santa-maria-c-s-s.M/';}
  754.         }
  755.         
  756.         
  757.         
  758.         if ($clienteId == null ) {
  759.             
  760.             $caixas =  "";
  761.        
  762.         } else {
  763.             
  764.             $caixas $entityManager->getRepository(Cliente::class)->findCaixasByClienteId($clienteId);
  765.         }   
  766.             
  767.            
  768.         $erro '';
  769.         $ii=0;
  770.         $pagina 'index';
  771.         $p '';
  772.         $link '';
  773.         $mx 0;
  774.         $xy 
  775.         $yz 
  776.         $ay ;
  777.         $ky ;
  778.         $pdf ='';
  779.         $pagina_h4 ='Documento(s) para indexar';
  780.         $nome_menu_ '';
  781.         $index_tipo='';
  782.         $uuid Uuid::v4();
  783.         $user $this->getUser();
  784.         $user_nome$user->getEmail();
  785.         $user_nome_name$user->getNome();
  786.         $pasta_user=$user_nome.'/';
  787.         $arr = [];
  788.         $arrr=0;
  789.         $index_find null;
  790.         $dt '';
  791.         $clientS3 = new  S3Client([
  792.                     'region'  => 'sa-east-1',
  793.                     'version' => 'latest',
  794.                     'credentials' => [ 
  795.                         'key'    => $_ENV['AWS_KEY'],
  796.                         'secret' => $_ENV['AWS_SECRET'],
  797.                     ],
  798.                 ]);
  799.         
  800.      
  801.             
  802.         if(isset($_POST["dt"]))
  803.         {   
  804.             $documentos =  $doctrine->getRepository(Documento::class)->findBy(['tipo' => $_POST["dt"]]);
  805.             $index_find =  $doctrine->getRepository(Tipo::class)->find($_POST["dt"]);
  806.             $pagina =$index_find->getNome();
  807.             $pagina_h4 ='Documento(s) do tipo ( '.$pagina.' )';
  808.             
  809.             
  810.         }
  811.        
  812.         if(isset($_POST["botao_index"])){
  813.             
  814.             $pdf =  $doctrine->getRepository(Documento::class)->find($_POST["id"]);
  815.             $link $pdf->getImage();
  816.             $xy ;
  817.             
  818.         }
  819.         if(isset($_POST["botao_doc"])){
  820.             
  821.             
  822.             $yz ;
  823.             $xy ;
  824.             $ay ;
  825.             $pdf =  $doctrine->getRepository(Documento::class)->find($_POST["id_pdf"]);
  826.             $index_tipo =  $doctrine->getRepository(Tipo::class)->find($_POST["id_index"]);
  827.            
  828.             $index_tipo =  $doctrine->getRepository(Tipo::class)->find($_POST["id_index"]);
  829.             $index_tipo_tipo =  $index_tipo->getNome();
  830.             $link $pdf->getImage();
  831.             $fase=$_POST["fase"];
  832.             $data $_POST["data"];
  833.             $cx $_POST["caixas"];
  834.             $classifica $_POST["classifica"];
  835.             $fase $_POST["fase"];
  836.             $desc $_POST["desc"];
  837.             $assunto $_POST["assunto"];
  838.             $chave $_POST["chave"];
  839.             $nome $_POST["nome"];
  840.             $conteiner $_POST["conteiner"];
  841.             
  842.           
  843.             
  844.             $caixa_id $doctrine->getRepository(Caixa::class)->find($cx);
  845.             
  846.             
  847.             
  848.             // Encontra todos os números na frase
  849.             preg_match_all('/\d+/'$fase$matches);
  850.             // $matches[0] agora contém todos os números encontrados na frase
  851.             $numeros array_map('intval'$matches[0]);
  852.             // Exibe os números encontrados
  853.             
  854.             if ($clientes != 7) {
  855.            
  856.                 if ($data != "") {
  857.                     
  858.                     if ($fase != "") {
  859.     
  860.                         // Número inteiro que você deseja somar ao ano
  861.                         $numeroParaSomar $numeros[0];
  862.     
  863.                         // Extrair o ano da data
  864.                         list($ano$mes$dia) = explode('-'$data);
  865.     
  866.                         // Converter o ano para um número inteiro
  867.                         $ano intval($ano);
  868.     
  869.                         // Somar o número ao ano
  870.                         $data_vecimento =  $ano $numeroParaSomar.'-'.$mes.'-'$dia;
  871.     
  872.                         $pdf->setVencimentoDocumento(new \DateTimeImmutable($data_vecimento));
  873.     
  874.                     }
  875.                 $pdf->setDataDocumento(new \DateTimeImmutable($data));
  876.                 }
  877.             }    
  878.             
  879.             if ($clientes == 7) {
  880.                   
  881.                   $pdf->setVencimentoDocumento(new \DateTimeImmutable($fase));
  882.                   $pdf->setDataDocumento(new \DateTimeImmutable($data));
  883.              }
  884.              
  885.             $pdf->setAssunto($assunto);
  886.             if ($classifica != "") {
  887.                 $classifica_id $doctrine->getRepository(Classificacao::class)->find($classifica);
  888.                 $pdf->setClassificacao($classifica_id);
  889.             }
  890.             $pdf->setCaixa($caixa_id);
  891.             $pdf->setExtraFields($desc);
  892.             $pdf->setNome($nome);
  893.             $pdf->setKeywords($chave);
  894.             $pdf->setUserIndex($user_nome_name);
  895.             $pdf->setConteiner($conteiner);
  896.             $pdf->setIndexAt(new \DateTimeImmutable('America/Sao_Paulo'));
  897.             $pdf->setTipo($index_tipo);
  898.             $entityManager->flush();
  899.             $id_pd $pdf->getId();    
  900.             $log = new Registro();
  901.             $log->setOperacao('Indexou o Documento com id '.$id_pd); 
  902.             $log->setUser($user_nome_name);
  903.             $log->setCliente($cliente_nome);
  904.             $entityManager->persist($log);
  905.             $entityManager->flush();
  906.             $erro 'ok';
  907.             $p =  $index_tipo_tipo.' indexado com sucesso';
  908.             
  909.            
  910.             
  911.            
  912.         }   
  913.         if(isset($_POST["botao_index_edit"])){
  914.             
  915.             $yz ;
  916.             $xy ;
  917.             $ay ;
  918.             $pdf =  $doctrine->getRepository(Documento::class)->find($_POST["id"]);
  919.             $index_tipo =  $doctrine->getRepository(Tipo::class)->find($_POST["id_index"]);
  920.             $link $pdf->getImage();
  921.         }
  922.         if(isset($_POST["botao_volta"])){
  923.             $xy ;
  924.             $yz ;
  925.         }
  926.         if(isset($_POST["index_button"])){
  927.             
  928.             
  929.             $yz ;
  930.             $xy ;
  931.             $ay ;
  932.             $pdf =  $doctrine->getRepository(Documento::class)->find($_POST["id_pdf"]);
  933.             $index_tipo =  $doctrine->getRepository(Tipo::class)->find($_POST["index_button"]);
  934.             $link $pdf->getImage();
  935.         }
  936.         if(isset($_POST["botao_cancel"])){
  937.             $yz ;
  938.             $xy ;
  939.             $ay ;
  940.             $pdf =  $doctrine->getRepository(Documento::class)->find($_POST["id_pdf"]);
  941.             $link $pdf->getImage();
  942.             
  943.         }
  944.         if(isset($_POST["delet"])){
  945.            
  946.             $ky ;
  947.             $pdf =  $doctrine->getRepository(Documento::class)->find($_POST["delet"]);
  948.             $documentos $doctrine->getRepository(Documento::class)->findBy(['id' => $_POST["delet"]]);
  949.             
  950.             if($pdf->getTipo()!= null){
  951.                 $index_find =  $doctrine->getRepository(Tipo::class)->find($pdf->getTipo());
  952.                 $pagina =$index_find->getTipo();
  953.                 $pagina_h4 ='Documento(s) do tipo ( '.$index_find->getTipo().' )';
  954.             }
  955.                         
  956.         }
  957.         if(isset($_POST["delet_cancel"])){
  958.             $ky ;
  959.         }
  960.         if(isset($_POST["delet_sim"])){
  961.             
  962.             $pdf =  $doctrine->getRepository(Documento::class)->find($_POST["id"]);
  963.             $id_pd $pdf->getId();
  964.             $entityManager->remove($pdf);
  965.             $entityManager->flush();
  966.           
  967.             $log = new Registro();
  968.             $log->setOperacao('Excluiu Documento com id '.$id_pd); 
  969.             $log->setUser($user_nome_name);
  970.             $log->setCliente($cliente_nome);
  971.             $entityManager->persist($log);
  972.             $entityManager->flush();
  973.             $erro 'ok';
  974.             $p 'Documento com id '.$id_pd.' excluido com sucesso '
  975.         }
  976.         if(isset($_POST["index_edit"])){
  977.             $yz ;
  978.             $xy ;
  979.             $ay ;
  980.             $pdf =  $doctrine->getRepository(Documento::class)->find($_POST["id_pdf"]);
  981.             $index_tipo =  $doctrine->getRepository(Tipo::class)->find($_POST["id_index"]);
  982.             $link $pdf->getImage();
  983.         }
  984.        
  985.        
  986.         $cmd $clientS3->getCommand('GetObject', [
  987.                 'Bucket' => 'arquivosdoc',
  988.                 'Key'    => $caminho$link
  989.             ]);
  990.             
  991.             $req $clientS3->createPresignedRequest($cmd'+30 minutes');
  992.             $all_Url = (string) $req->getUri();
  993.         return $this->render('index/index1.html.twig', [
  994.             'documentos' => $documentos,
  995.             'xy' => $xy,
  996.             'yz' => $yz,
  997.             'ay'=>$ay,
  998.             'link' => $link,
  999.             'pdf'=>$pdf,
  1000.             'p'=>$p,
  1001.             'erro'=>$erro,
  1002.             'index_all'=>$index_all,
  1003.             'index_tipo'=>$index_tipo,
  1004.             'ky'=>$ky,
  1005.             'pagina' => $pagina,
  1006.             'pagina_h4' =>$pagina_h4,
  1007.             'index_find'=>$index_find,
  1008.             'mx'=>$mx,
  1009.             'caixas' => $caixas,
  1010.             'class' => $class,
  1011.             'permissao'=>$permissao,
  1012.             'caminho' =>$caminho,
  1013.             'clientes' => $clientes,
  1014.             'doc'=>$doc,
  1015.             'dia_prod' => $dia_prod,
  1016.             'cliente_session' => $cliente_session,
  1017.             'all_Url'=>$all_Url
  1018.         ]);
  1019.     }
  1020.     
  1021.     
  1022.     #[Route('/index/corre'name'index_corre')]
  1023.     public function index_corre(Request $request,ManagerRegistry $doctrineEntityManagerInterface $entityManager SessionInterface $session): Response
  1024.     {
  1025.         $dotenv = new Dotenv();
  1026.         $dotenv->load(__DIR__.'/.env');
  1027.         $user_logado $this->getUser();
  1028.         $form $this->createForm(UploadType::class);
  1029.         $form->handleRequest($request);
  1030.         $user_logado_tipoAcesso $user_logado->getTipoAcesso();
  1031.         $user_logado_nome $user_logado->getNome();
  1032.         $user_logado_id $user_logado->getId();
  1033.         $cliente =  $doctrine->getRepository(User::class)->findClientsByUserId($user_logado_id);
  1034.         $hoje = new \DateTimeImmutable('America/Sao_Paulo');
  1035.         $hoje_formt=$hoje->format('Y-m-d');
  1036.         $doc $entityManager->getRepository(Documento::class)->findByUserIndexAndDate($user_logado_nome$hoje_formt);
  1037.         $dia_prod 'de hoje';
  1038.         $permissao = [];
  1039.         $list_indexador = [];
  1040.          
  1041.         if(isset($_POST["btn_cliente"])){
  1042.             
  1043.             $session->set('cliente_id'$_POST["btn_cliente"]);
  1044.             return $this->redirectToRoute('home');
  1045.         }
  1046.         $clienteId $session->get('cliente_id');
  1047.         if ($clienteId == null ) {
  1048.             
  1049.             $caixas =  "";
  1050.             $index_all ="";
  1051.             $documentos="";
  1052.             $cliente_session "";
  1053.        
  1054.         } else {
  1055.             
  1056.             $index_all =  $doctrine->getRepository(Tipo::class)->findBy(['cliente' => $clienteId]);
  1057.             $caixas $entityManager->getRepository(Cliente::class)->findCaixasByClienteId($clienteId);
  1058.             $documentos =  $doctrine->getRepository(Documento::class)->findBy(['tipo' => null ,'cliente' => $clienteId]);
  1059.             $cliente_session =  $doctrine->getRepository(Cliente::class)->find($clienteId);
  1060.             
  1061.             
  1062.         }
  1063.        
  1064.         if(isset($_POST["date_perio"])){
  1065.             
  1066.             
  1067.             $startDate $_POST["de"];
  1068.             $endDate $_POST["ate"];
  1069.        
  1070.             $de = new \DateTimeImmutable($startDate);
  1071.             $ate = new \DateTimeImmutable($endDate);
  1072.             $de_formt=$de->format('d/m/Y') ;
  1073.             $ate_formt=$ate->format('d/m/Y') ;
  1074.             
  1075.             if($endDate != ""){ 
  1076.                 
  1077.                 $doc $entityManager->getRepository(Documento::class)->findByUserAndDateIndexRange($user_logado_nome$startDate$endDate);
  1078.                 $dia_prod 'de '$de_formt.' até '.$ate_formt
  1079.             
  1080.             }
  1081.             if($endDate == ""){ 
  1082.                 
  1083.                 $doc $entityManager->getRepository(Documento::class)->findByUserIndexAndDate($user_logado_nome$startDate);
  1084.                 $dia_prod 'de '$de_formt
  1085.             }
  1086.             
  1087.             
  1088.             
  1089.         }
  1090.        
  1091.         
  1092.         foreach ($user_logado_tipoAcesso["new"] as  $value) {
  1093.             
  1094.             foreach ($index_all as $key) {
  1095.                 if ( $key->getId() ==  $value) {
  1096.                     
  1097.                     $permissao[] = $value;
  1098.                     
  1099.                 }
  1100.                
  1101.             }
  1102.         }
  1103.         $ids = [
  1104.             68723046818199686981668692526821222686981468668636852698,
  1105.             68182446872298682655068670346869774686832368232226868678,
  1106.             68627196826530681908068680116823849686844368231076858469,
  1107.             68190066872241687224368365086836538682323168410516862616,
  1108.             68364836836476682302468686906868662686789168365826868372,
  1109.             68364826823893687226868347586821087686701868365036872202,
  1110.             68364796818242686371868348306867256687225968685976834172,
  1111.             68364926869376681896568721686868595686031768599086868330,
  1112.             68399396872285686936668626596824620686984768182376834659,
  1113.             68349176866975686945468619376863512683474768199376834280,
  1114.             68324066862744681896368364806872203681883068238926831255,
  1115.             68165626872201683125668669996836481686842368165686862679,
  1116.             68683146866634683955768692436859933686951568325786836535,
  1117.             68238556823845682387668323976836478686371968599356871251,
  1118.             68695136869510683584868311566836517
  1119.         ];
  1120.             
  1121.         $qb $doctrine->getRepository(Documento::class)->createQueryBuilder('d');
  1122.         $documentos $qb
  1123.             ->where('d.id IN (:ids)')
  1124.             ->andWhere(
  1125.                 $qb->expr()->orX(
  1126.                     'd.extraFields IS NULL',
  1127.                     'd.dataDocumento IS NULL'
  1128.                 )
  1129.             )
  1130.             ->setParameter('ids'$ids)
  1131.             ->getQuery()
  1132.             ->getResult();
  1133.         
  1134.         $class =  $doctrine->getRepository(Classificacao::class)->findBy(['cliente' => $clienteId]);
  1135.         $cliente_id $doctrine->getRepository(Cliente::class)->findBy(['id' => $clienteId]);
  1136.         
  1137.        
  1138.         
  1139.         
  1140.         foreach ($cliente_id as $cliente_ids) {
  1141.             
  1142.             $cliente_nome$cliente_ids->getNome();
  1143.             $clientes$cliente_ids->getId();
  1144.             $umlautString =$cliente_nome;
  1145.             $slugger = new AsciiSlugger();
  1146.             $teste=$slugger->slug($umlautString$seperator '-')->toString();
  1147.             $caminho strtolower ($teste.'/');
  1148.                         
  1149.             if($clientes == 14){$caminho='cartorio-1deg-oficio-de-volta-redonda-rj/';}
  1150.             if($clientes == 83){$caminho='casf-corretora-apolice-diversos/';}
  1151.             if($clientes == 35){$caminho='pmecj-sp-saude/';}
  1152.             if($clientes == 107){$caminho='pmecj-sp-execucao-fiscal/';}
  1153.             if($clientes ==  4){$caminho='cartorio-souza-reis-barra-mansa/';}
  1154.             if($clientes ==  112){$caminho='saae-cartao-de-ponto/';}
  1155.             if($clientes ==  15){$caminho='cbsi-dossies/';}
  1156.             if($clientes ==  55){$caminho='casf-gerep-contratos-de-prestadores-de-saude-pj/';}
  1157.             if($clientes ==  13){$caminho='casa-de-saude-santa-maria-c-s-s.M/';}
  1158.         }
  1159.         
  1160.         
  1161.         
  1162.         if ($clienteId == null ) {
  1163.             
  1164.             $caixas =  "";
  1165.        
  1166.         } else {
  1167.             
  1168.             $caixas $entityManager->getRepository(Cliente::class)->findCaixasByClienteId($clienteId);
  1169.         }   
  1170.             
  1171.            
  1172.         $erro '';
  1173.         $ii=0;
  1174.         $pagina 'index';
  1175.         $p '';
  1176.         $link '';
  1177.         $mx 0;
  1178.         $xy 
  1179.         $yz 
  1180.         $ay ;
  1181.         $ky ;
  1182.         $pdf ='';
  1183.         $pagina_h4 ='Documento(s) para indexar';
  1184.         $nome_menu_ '';
  1185.         $index_tipo='';
  1186.         $uuid Uuid::v4();
  1187.         $user $this->getUser();
  1188.         $user_nome$user->getEmail();
  1189.         $user_nome_name$user->getNome();
  1190.         $pasta_user=$user_nome.'/';
  1191.         $arr = [];
  1192.         $arrr=0;
  1193.         $index_find null;
  1194.         $dt '';
  1195.         $clientS3 = new  S3Client([
  1196.                     'region'  => 'sa-east-1',
  1197.                     'version' => 'latest',
  1198.                     'credentials' => [ 
  1199.                         'key'    => $_ENV['AWS_KEY'],
  1200.                         'secret' => $_ENV['AWS_SECRET'],
  1201.                     ],
  1202.                 ]);
  1203.         
  1204.      
  1205.             
  1206.         if(isset($_POST["dt"]))
  1207.         {   
  1208.             $documentos =  $doctrine->getRepository(Documento::class)->findBy(['tipo' => $_POST["dt"]]);
  1209.             $index_find =  $doctrine->getRepository(Tipo::class)->find($_POST["dt"]);
  1210.             $pagina =$index_find->getNome();
  1211.             $pagina_h4 ='Documento(s) do tipo ( '.$pagina.' )';
  1212.             
  1213.             
  1214.         }
  1215.        
  1216.         if(isset($_POST["botao_index"])){
  1217.             
  1218.             $pdf =  $doctrine->getRepository(Documento::class)->find($_POST["id"]);
  1219.             $link $pdf->getImage();
  1220.             $xy ;
  1221.             
  1222.         }
  1223.         if(isset($_POST["botao_doc"])){
  1224.             
  1225.             
  1226.             $yz ;
  1227.             $xy ;
  1228.             $ay ;
  1229.             $pdf =  $doctrine->getRepository(Documento::class)->find($_POST["id_pdf"]);
  1230.             $index_tipo =  $doctrine->getRepository(Tipo::class)->find($_POST["id_index"]);
  1231.            
  1232.             $index_tipo =  $doctrine->getRepository(Tipo::class)->find($_POST["id_index"]);
  1233.             $index_tipo_tipo =  $index_tipo->getNome();
  1234.             $link $pdf->getImage();
  1235.             $fase=$_POST["fase"];
  1236.             $data $_POST["data"];
  1237.             $cx $_POST["caixas"];
  1238.             $classifica $_POST["classifica"];
  1239.             $fase $_POST["fase"];
  1240.             $desc $_POST["desc"];
  1241.             $assunto $_POST["assunto"];
  1242.             $chave $_POST["chave"];
  1243.             $nome $_POST["nome"];
  1244.             $conteiner $_POST["conteiner"];
  1245.             
  1246.           
  1247.             
  1248.             $caixa_id $doctrine->getRepository(Caixa::class)->find($cx);
  1249.             
  1250.             
  1251.             
  1252.             // Encontra todos os números na frase
  1253.             preg_match_all('/\d+/'$fase$matches);
  1254.             // $matches[0] agora contém todos os números encontrados na frase
  1255.             $numeros array_map('intval'$matches[0]);
  1256.             // Exibe os números encontrados
  1257.             
  1258.             if ($clientes != 7) {
  1259.            
  1260.                 if ($data != "") {
  1261.                     
  1262.                     if ($fase != "") {
  1263.     
  1264.                         // Número inteiro que você deseja somar ao ano
  1265.                         $numeroParaSomar $numeros[0];
  1266.     
  1267.                         // Extrair o ano da data
  1268.                         list($ano$mes$dia) = explode('-'$data);
  1269.     
  1270.                         // Converter o ano para um número inteiro
  1271.                         $ano intval($ano);
  1272.     
  1273.                         // Somar o número ao ano
  1274.                         $data_vecimento =  $ano $numeroParaSomar.'-'.$mes.'-'$dia;
  1275.     
  1276.                         $pdf->setVencimentoDocumento(new \DateTimeImmutable($data_vecimento));
  1277.     
  1278.                     }
  1279.                 $pdf->setDataDocumento(new \DateTimeImmutable($data));
  1280.                 }
  1281.             }    
  1282.             
  1283.             if ($clientes == 7) {
  1284.                   
  1285.                   $pdf->setVencimentoDocumento(new \DateTimeImmutable($fase));
  1286.                   $pdf->setDataDocumento(new \DateTimeImmutable($data));
  1287.              }
  1288.              
  1289.             $pdf->setAssunto($assunto);
  1290.             if ($classifica != "") {
  1291.                 $classifica_id $doctrine->getRepository(Classificacao::class)->find($classifica);
  1292.                 $pdf->setClassificacao($classifica_id);
  1293.             }
  1294.             $pdf->setExtraFields($desc);
  1295.             $pdf->setNome($nome);
  1296.             $pdf->setKeywords($chave);
  1297.             $pdf->setUserIndex($user_nome_name);
  1298.             $pdf->setConteiner($conteiner);
  1299.             $pdf->setIndexAt(new \DateTimeImmutable('America/Sao_Paulo'));
  1300.             $pdf->setTipo($index_tipo);
  1301.             $entityManager->flush();
  1302.             $id_pd $pdf->getId();    
  1303.             $log = new Registro();
  1304.             $log->setOperacao('Indexou o Documento com id '.$id_pd); 
  1305.             $log->setUser($user_nome_name);
  1306.             $log->setCliente($cliente_nome);
  1307.             $entityManager->persist($log);
  1308.             $entityManager->flush();
  1309.             $erro 'ok';
  1310.             $p =  $index_tipo_tipo.' indexado com sucesso';
  1311.             
  1312.            
  1313.             
  1314.            
  1315.         }   
  1316.         if(isset($_POST["botao_index_edit"])){
  1317.             
  1318.             $yz ;
  1319.             $xy ;
  1320.             $ay ;
  1321.             $pdf =  $doctrine->getRepository(Documento::class)->find($_POST["id"]);
  1322.             $index_tipo =  $doctrine->getRepository(Tipo::class)->find($_POST["id_index"]);
  1323.             $link $pdf->getImage();
  1324.         }
  1325.         if(isset($_POST["botao_volta"])){
  1326.             $xy ;
  1327.             $yz ;
  1328.         }
  1329.         if(isset($_POST["index_button"])){
  1330.             
  1331.             
  1332.             $yz ;
  1333.             $xy ;
  1334.             $ay ;
  1335.             $pdf =  $doctrine->getRepository(Documento::class)->find($_POST["id_pdf"]);
  1336.             $index_tipo =  $doctrine->getRepository(Tipo::class)->find($_POST["index_button"]);
  1337.             $link $pdf->getImage();
  1338.         }
  1339.         if(isset($_POST["botao_cancel"])){
  1340.             $yz ;
  1341.             $xy ;
  1342.             $ay ;
  1343.             $pdf =  $doctrine->getRepository(Documento::class)->find($_POST["id_pdf"]);
  1344.             $link $pdf->getImage();
  1345.             
  1346.         }
  1347.         if(isset($_POST["delet"])){
  1348.            
  1349.             $ky ;
  1350.             $pdf =  $doctrine->getRepository(Documento::class)->find($_POST["delet"]);
  1351.             $documentos $doctrine->getRepository(Documento::class)->findBy(['id' => $_POST["delet"]]);
  1352.             
  1353.             if($pdf->getTipo()!= null){
  1354.                 $index_find =  $doctrine->getRepository(Tipo::class)->find($pdf->getTipo());
  1355.                 $pagina =$index_find->getTipo();
  1356.                 $pagina_h4 ='Documento(s) do tipo ( '.$index_find->getTipo().' )';
  1357.             }
  1358.                         
  1359.         }
  1360.         if(isset($_POST["delet_cancel"])){
  1361.             $ky ;
  1362.         }
  1363.         if(isset($_POST["delet_sim"])){
  1364.             
  1365.             $pdf =  $doctrine->getRepository(Documento::class)->find($_POST["id"]);
  1366.             $id_pd $pdf->getId();
  1367.             $entityManager->remove($pdf);
  1368.             $entityManager->flush();
  1369.           
  1370.             $log = new Registro();
  1371.             $log->setOperacao('Excluiu Documento com id '.$id_pd); 
  1372.             $log->setUser($user_nome_name);
  1373.             $log->setCliente($cliente_nome);
  1374.             $entityManager->persist($log);
  1375.             $entityManager->flush();
  1376.             $erro 'ok';
  1377.             $p 'Documento com id '.$id_pd.' excluido com sucesso '
  1378.         }
  1379.         if(isset($_POST["index_edit"])){
  1380.             $yz ;
  1381.             $xy ;
  1382.             $ay ;
  1383.             $pdf =  $doctrine->getRepository(Documento::class)->find($_POST["id_pdf"]);
  1384.             $index_tipo =  $doctrine->getRepository(Tipo::class)->find($_POST["id_index"]);
  1385.             $link $pdf->getImage();
  1386.         }
  1387.        
  1388.        
  1389.         $cmd $clientS3->getCommand('GetObject', [
  1390.                 'Bucket' => 'arquivosdoc',
  1391.                 'Key'    => $caminho$link
  1392.             ]);
  1393.             
  1394.             $req $clientS3->createPresignedRequest($cmd'+30 minutes');
  1395.             $all_Url = (string) $req->getUri();
  1396.         return $this->render('index/index1.html.twig', [
  1397.             'documentos' => $documentos,
  1398.             'xy' => $xy,
  1399.             'yz' => $yz,
  1400.             'ay'=>$ay,
  1401.             'link' => $link,
  1402.             'pdf'=>$pdf,
  1403.             'p'=>$p,
  1404.             'erro'=>$erro,
  1405.             'index_all'=>$index_all,
  1406.             'index_tipo'=>$index_tipo,
  1407.             'ky'=>$ky,
  1408.             'pagina' => $pagina,
  1409.             'pagina_h4' =>$pagina_h4,
  1410.             'index_find'=>$index_find,
  1411.             'mx'=>$mx,
  1412.             'caixas' => $caixas,
  1413.             'class' => $class,
  1414.             'permissao'=>$permissao,
  1415.             'caminho' =>$caminho,
  1416.             'clientes' => $clientes,
  1417.             'doc'=>$doc,
  1418.             'dia_prod' => $dia_prod,
  1419.             'cliente_session' => $cliente_session,
  1420.             'all_Url'=>$all_Url
  1421.         ]);
  1422.     }
  1423.     
  1424.     #[Route('/index/novo/fluxo'name'fluxo_novo')]
  1425.     public function fluxoNovo(Request $request,ManagerRegistry $doctrineEntityManagerInterface $entityManagerSessionInterface $sessionMailerInterface $mailer): Response
  1426.     {
  1427.         $user_logado $this->getUser();
  1428.         $user_logado_nome $user_logado->getNome();
  1429.         $user_logado_id $user_logado->getId();
  1430.         $erro '';
  1431.         $pagina 'fluxo';
  1432.         $p ='';
  1433.         $cliente =  $doctrine->getRepository(User::class)->findClientsByUserId($user_logado_id);
  1434.         
  1435.         if(isset($_POST["btn_cliente"])){
  1436.             
  1437.             $session->set('cliente_id'$_POST["btn_cliente"]);
  1438.             return $this->redirectToRoute('home');
  1439.         }
  1440.         $clienteId $session->get('cliente_id');
  1441.         
  1442.       
  1443.         
  1444.         if ($clienteId == null ) {
  1445.             
  1446.             $cli =  "";
  1447.             return $this->redirectToRoute('home');
  1448.           
  1449.        
  1450.         } else {
  1451.             
  1452.          
  1453.             $cli $doctrine->getRepository(Cliente::class)->find($clienteId);
  1454.             
  1455.         }
  1456.         
  1457.         $query $doctrine->getManager()->createQuery('
  1458.             SELECT u
  1459.             FROM App\Entity\User u
  1460.             JOIN u.clientes c
  1461.             WHERE c.id = :clientId
  1462.             AND u.enabled = 1
  1463.         ')->setParameter('clientId'$clienteId);
  1464.         $usuarios $query->getArrayResult();
  1465.         if(isset($_POST["fluxo"])){
  1466.             
  1467.             $fluxo = new Fluxo();
  1468.             $nome $cli->getNome();
  1469.             $fluxo->setNome($nome);
  1470.             $fluxo->setUser($user_logado);
  1471.             $fluxo->setCliente($cli);
  1472.             $fluxo->setObs($_POST["obs"]);
  1473.             $entityManager->persist($fluxo);
  1474.             $entityManager->flush();
  1475.             $id_fluxo $fluxo->getId(); 
  1476.             
  1477.             $prazo $_POST["prazo"];
  1478.             $user_1 $_POST["user"];
  1479.             
  1480.             foreach ($user_1 as $users) {
  1481.                
  1482.                     $etapa = new Etapa();
  1483.                     $user $doctrine->getRepository(User::class)->find($users);
  1484.                     $mail $user->getEmail();
  1485.                     
  1486.                    
  1487.                     $etapa->setNome($_POST["etapa"]);
  1488.                     $etapa->setOrdem(1);
  1489.                     $etapa->setUser($user);
  1490.                     $etapa->setFluxo($doctrine->getRepository(Fluxo::class)->find($id_fluxo));
  1491.                     $etapa->setPrazo(new \DateTimeImmutable($prazo));
  1492.                     $entityManager->persist($etapa);
  1493.                     $entityManager->flush();
  1494.         
  1495.                     /*$email = (new Email())
  1496.                         ->from('arquivosdoc@arquivosdoc.com.br')
  1497.                         ->to($mail)
  1498.                         ->subject('Fluxo de Trabalho')
  1499.                         ->html('<div style="text-align: center;">
  1500.                             <h1 style="color:#1e4067;">Recebimento<br>
  1501.                             Cliente: '.$nome.'<br>
  1502.                             Prazo:'.$prazo.'<br>
  1503.                             Enviado por: '.$user_logado_nome.'<br>
  1504.                             Acesse sua pagina inicial no <a href="https://ged.arquivosdoc.com.br/login">ArquivosGED
  1505.                             </a></h1>
  1506.                             <img src="cid:logo"><div>')
  1507.                         ->embed(fopen('C:/xampp8/htdocs/gedemail/public/img/icon.png', 'r'), 'logo', 'image/png');
  1508.                     $mailer->send($email);*/
  1509.                     
  1510.                  
  1511.             }
  1512.             
  1513.             if(isset($_POST["user_2"])){
  1514.                 
  1515.                 
  1516.                 $prazo_2 $_POST["prazo_2"];
  1517.                 $user_2 $_POST["user_2"];
  1518.                 foreach ($user_2 as $users2) {
  1519.                     $etapa2 = new Etapa();
  1520.                     $etapa2->setNome($_POST["etapa2"]);
  1521.                     $etapa2->setOrdem(2);
  1522.                     $etapa2->setUser($doctrine->getRepository(User::class)->find($users2));
  1523.                     $etapa2->setFluxo($doctrine->getRepository(Fluxo::class)->find($id_fluxo));
  1524.                     $etapa2->setPrazo(new \DateTimeImmutable($prazo_2));
  1525.                     $entityManager->persist($etapa2);
  1526.                     $entityManager->flush();
  1527.                 }
  1528.             }
  1529.             if(isset($_POST["user_3"])){
  1530.                 
  1531.                 
  1532.                 $user_3 $_POST["user_3"];
  1533.                 $prazo_3 $_POST["prazo_3"];
  1534.                 foreach ($user_3 as $users3) {
  1535.                     $etapa3 = new Etapa();
  1536.                     $etapa3->setNome($_POST["etapa3"]);
  1537.                     $etapa3->setOrdem(3);
  1538.                     $etapa3->setUser($doctrine->getRepository(User::class)->find($users3));
  1539.                     $etapa3->setFluxo($doctrine->getRepository(Fluxo::class)->find($id_fluxo));
  1540.                     $etapa3->setPrazo(new \DateTimeImmutable($prazo_3));
  1541.                     $entityManager->persist($etapa3);
  1542.                     $entityManager->flush();
  1543.                 }    
  1544.             }
  1545.             if(isset($_POST["user_4"])){
  1546.                 
  1547.                 $user_4 $_POST["user_4"];
  1548.                 $prazo_4 $_POST["prazo_4"];
  1549.                 foreach ($user_4 as $users4) {
  1550.                     $etapa4 = new Etapa();
  1551.                     $etapa4->setNome($_POST["etapa4"]);
  1552.                     $etapa4->setOrdem(4);
  1553.                     $etapa4->setUser($doctrine->getRepository(User::class)->find($users4));
  1554.                     $etapa4->setFluxo($doctrine->getRepository(Fluxo::class)->find($id_fluxo));
  1555.                     $etapa4->setPrazo(new \DateTimeImmutable($prazo_4));
  1556.                     $entityManager->persist($etapa4);
  1557.                     $entityManager->flush();
  1558.                 }
  1559.             } 
  1560.             
  1561.             
  1562.             if(isset($_POST["user_5"])){
  1563.                 
  1564.                 $user_5 $_POST["user_5"];
  1565.                 $prazo_5 $_POST["prazo_5"];
  1566.                 foreach ($user_5 as $users5) {
  1567.                     $etapa5 = new Etapa();
  1568.                     $etapa5->setNome($_POST["etapa5"]);
  1569.                     $etapa5->setOrdem(5);
  1570.                     $etapa5->setUser($doctrine->getRepository(User::class)->find($users5));
  1571.                     $etapa5->setFluxo($doctrine->getRepository(Fluxo::class)->find($id_fluxo));
  1572.                     $etapa5->setPrazo(new \DateTimeImmutable($prazo_5));
  1573.                     $entityManager->persist($etapa5);
  1574.                     $entityManager->flush();
  1575.                 }
  1576.             } 
  1577.             $erro "ok";
  1578.             $p =  'FLUXO ENVIADO' ;
  1579.             
  1580.             
  1581.         }
  1582.         
  1583.     
  1584.        
  1585.         return $this->render('index/index4.html.twig', [
  1586.     
  1587.             
  1588.             'p'=>$p,
  1589.             'erro'=>$erro,
  1590.             'pagina' => $pagina,
  1591.             'usuarios' =>$usuarios,
  1592.             'cliente' => $cliente
  1593.             
  1594.         ]);
  1595.     }
  1596.     #[Route('/index/fluxo'name'fluxo')]
  1597.     public function fluxoPaginatorInterface $paginator,Request $request,ManagerRegistry $doctrineEntityManagerInterface $entityManagerSessionInterface $sessionMailerInterface $mailer): Response
  1598.     {
  1599.         $user_logado $this->getUser();
  1600.         $erro '';
  1601.         $pagina 'fluxo';
  1602.         $p ='';
  1603.         $registro $doctrine->getRepository(Registro::class)->findAll();
  1604.         $a 0;
  1605.         $clientS3 = new  S3Client([
  1606.             'region'  => 'sa-east-1',
  1607.             'version' => 'latest',
  1608.             'credentials' => [ 
  1609.                 'key'    => $_ENV['AWS_KEY'],
  1610.                 'secret' => $_ENV['AWS_SECRET'],
  1611.             ],
  1612.         
  1613.         ]);
  1614.         
  1615.     
  1616.         if(isset($_POST["btn_cliente"])){
  1617.             
  1618.             $session->set('cliente_id'$_POST["btn_cliente"]);
  1619.             return $this->redirectToRoute('home');
  1620.         }
  1621.         $clienteId $session->get('cliente_id');
  1622.         
  1623.         if($clienteId == null){
  1624.             
  1625.             return $this->redirectToRoute('home');
  1626.         }
  1627.         
  1628.         $cliente $doctrine->getRepository(Cliente::class)->find($clienteId);
  1629.         $fluxo $doctrine->getRepository(Fluxo::class)->findBy(['cliente' => $clienteId],['id'=> 'DESC']);
  1630.       
  1631.         
  1632.         // Paginar os fluxos
  1633.         $fluxos $paginator->paginate(
  1634.             $fluxo// O queryBuilder ou a query
  1635.             $request->query->getInt('page'1), // A página atual, padrão é 1
  1636.             // O número de itens por página
  1637.         );
  1638.         if (isset($_POST["excel"])) {
  1639.             
  1640.         
  1641.             $cx null;
  1642.             $id_fluxo $_POST["excel"];
  1643.             $fluxo_excel $doctrine->getRepository(Fluxo::class)->find($id_fluxo);
  1644.             $nome_fluxo $fluxo_excel->getNome();
  1645.             $fluxo_caixas $doctrine->getRepository(Caixa::class)->findByFluxoWithRelations($fluxo_excel->getId());
  1646.             
  1647.             
  1648.         
  1649.             // Cria uma nova planilha
  1650.             $spreadsheet = new Spreadsheet();
  1651.             $sheet $spreadsheet->getActiveSheet();
  1652.             $sheet->setTitle('CAIXA(S)');
  1653.             // Configura o cabeçalho
  1654.             $sheet->setCellValue('A1''ID');
  1655.             $sheet->setCellValue('B1''REPOSITOR');
  1656.             $sheet->setCellValue('C1''DATA DO ENVIO');
  1657.         
  1658.             // Estiliza o cabeçalho (fundo azul, texto branco e negrito)
  1659.             $headerStyle = [
  1660.                 'font' => [
  1661.                     'bold' => true,
  1662.                     'color' => ['rgb' => 'FFFFFF'], // Texto branco
  1663.                 ],
  1664.                 'fill' => [
  1665.                     'fillType' => Fill::FILL_SOLID,
  1666.                     'startColor' => ['rgb' => '095f99'], // Fundo azul
  1667.                 ],
  1668.             ];
  1669.             $sheet->getStyle('A1:C1')->applyFromArray($headerStyle);
  1670.         
  1671.             // Preenche os dados
  1672.             $rowCount 2;
  1673.             foreach ($fluxo_caixas as $caixas) {
  1674.                 
  1675.                     if($caixas->getCx() != null){
  1676.                     
  1677.                     $nome $caixas->getNome();
  1678.                     $cx $caixas->getCx()->getNome();
  1679.                     $data $caixas->getCreatedAt();
  1680.             
  1681.                     // Insere os valores
  1682.                     $sheet->setCellValue('A' $rowCount$cx);
  1683.                     $sheet->setCellValue('B' $rowCount$nome);
  1684.             
  1685.                     // Converte a data para o formato Excel
  1686.                     if ($data instanceof \DateTime) {
  1687.                         $sheet->setCellValue('C' $rowCountDate::PHPToExcel($data));
  1688.                     } else {
  1689.                         $sheet->setCellValue('C' $rowCount$data); // Evita erro se não for DateTime
  1690.                     }
  1691.             
  1692.                     $rowCount++;
  1693.                 }
  1694.             }
  1695.         
  1696.             // Formata a coluna C como data (exceto o cabeçalho)
  1697.             $sheet->getStyle('C2:C' . ($rowCount 1))
  1698.                 ->getNumberFormat()
  1699.                 ->setFormatCode('dd/mm/yyyy');
  1700.         
  1701.             // Define largura automática das colunas
  1702.             foreach (range('A''C') as $col) {
  1703.                 $sheet->getColumnDimension($col)->setAutoSize(true);
  1704.             }
  1705.              // Segunda aba - Outras informações (Exemplo)
  1706.             $sheet2 $spreadsheet->createSheet(); // Cria uma nova aba
  1707.             $sheet2->setTitle('DOCUMENTO(S)'); // Renomeia a aba
  1708.             $sheet2->setCellValue('A1' 'ID');
  1709.             $sheet2->setCellValue('B1' 'NOME');
  1710.             $sheet2->setCellValue('C1' 'REPOSITOR');
  1711.             $sheet2->setCellValue('D1' 'TIPO');
  1712.             $sheet2->setCellValue('E1' 'ASSUNTO');
  1713.             $sheet2->setCellValue('F1' 'PALAVRA-CHAVE');
  1714.             $sheet2->setCellValue('G1' 'DIGITALIZAÇÃO');
  1715.             $sheet2->setCellValue('H1' 'QUEM DIGITALIZOU?');
  1716.             $sheet2->setCellValue('I1' 'INDEXAÇÃO');
  1717.             $sheet2->setCellValue('J1' 'QUEM INDEXOU?');
  1718.             $sheet2->setCellValue('K1' 'IMAGEN(S)');
  1719.             $sheet2->getStyle('A1:K1')->applyFromArray($headerStyle);
  1720.             
  1721.             $rowCount 2;
  1722.             foreach ($fluxo_caixas as $caixas) {
  1723.                 $doc $caixas->getDocumentos();
  1724.                 
  1725.                 foreach ($doc as $docs) {
  1726.                     $tiponull;
  1727.                     $id $docs->getId();
  1728.                     $nome $docs->getNome();
  1729.                     $caixa $docs->getCaixa()->getNome();
  1730.                     if($docs->getTipo() != null){
  1731.                         $tipo $docs->getTipo()->getNome();
  1732.                     }
  1733.                     $qtd $docs->getQtd();
  1734.                     $assunto $docs->getAssunto();
  1735.                     $keywords $docs->getKeywords();
  1736.                     $user $docs->getUser()->getNome();
  1737.                     $data  $docs->getCreatedAt();
  1738.                     $index  $docs->getIndexAt();
  1739.                     $user_index  $docs->getUserIndex();
  1740.                     $sheet2->setCellValue('A' $rowCount,$id);
  1741.                     $sheet2->setCellValue('B' $rowCount,$nome);
  1742.                     $sheet2->setCellValue('C' $rowCount,$caixa);
  1743.                     $sheet2->setCellValue('D' $rowCount,$tipo);
  1744.                     $sheet2->setCellValue('E' $rowCount,$assunto);
  1745.                     $sheet2->setCellValue('F' $rowCount,$keywords);
  1746.                     $sheet2->setCellValue('G' $rowCount,$data);
  1747.                     $sheet2->setCellValue('H' $rowCount,$user);
  1748.                     $sheet2->setCellValue('I' $rowCount,$index);
  1749.                     $sheet2->setCellValue('J' $rowCount,$user_index);
  1750.                     $sheet2->setCellValue('K' $rowCount,$qtd);
  1751.                    
  1752.                     
  1753.                     if ($data instanceof \DateTime) {
  1754.                         $sheet2->setCellValue('G' $rowCountDate::PHPToExcel($data));
  1755.                     } else {
  1756.                         $sheet2->setCellValue('G' $rowCount$data); // Evita erro se não for DateTime
  1757.                     }
  1758.                     if ($data instanceof \DateTime) {
  1759.                         $sheet2->setCellValue('I' $rowCountDate::PHPToExcel($index));
  1760.                     } else {
  1761.                         $sheet2->setCellValue('I' $rowCount$index); // Evita erro se não for DateTime
  1762.                     }
  1763.             
  1764.             
  1765.                     $rowCount++;
  1766.                 
  1767.                 }
  1768.             }
  1769.             $sheet2->getStyle('I2:I' . ($rowCount 1))
  1770.                 ->getNumberFormat()
  1771.                 ->setFormatCode('dd/mm/yyyy');
  1772.             $sheet2->getStyle('G2:G' . ($rowCount 1))
  1773.                 ->getNumberFormat()
  1774.                 ->setFormatCode('dd/mm/yyyy');    
  1775.         
  1776.             foreach (range('A''K') as $col) {
  1777.                 $sheet2->getColumnDimension($col)->setAutoSize(true);
  1778.             }
  1779.         
  1780.             // Gera o arquivo para download
  1781.             $writer = new Xlsx($spreadsheet);
  1782.             header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  1783.             header('Content-Disposition: attachment; filename="' $nome_fluxo '-FLUXO-' $id_fluxo '.xlsx"');
  1784.             header('Cache-Control: max-age=0');
  1785.             $writer->save('php://output');
  1786.             exit;
  1787.         }
  1788.         if (isset($_POST["pdf"])) {
  1789.             
  1790.             $id_fluxo $_POST["pdf"];
  1791.             $fluxo_pdf $doctrine->getRepository(Fluxo::class)->findWithAllRelations($id_fluxo);
  1792.             $nome_fluxo $fluxo_pdf->getNome();
  1793.             
  1794.            
  1795.             $html $this->render('index/pdf.html.twig', [
  1796.                 'fluxo_pdf' => $fluxo_pdf,
  1797.                 'registro' => $registro
  1798.                 
  1799.             ]);
  1800.             $options = new Options();
  1801.             $options->set('isHtml5ParserEnabled'true);
  1802.             $options->set('isPhpEnabled'true);
  1803.             $options->set('isRemoteEnabled'true); 
  1804.             $dompdf = new Dompdf($options);
  1805.             $dompdf->loadHtml($html);
  1806.             $dompdf->setPaper('A4''portrait');
  1807.             // Renderiza o HTML para o PDF
  1808.             $dompdf->render();
  1809.             // Envia o PDF para o navegador para download
  1810.             $dompdf->stream("Relatório_Fluxo_".$id_fluxo."_".$nome_fluxo.".pdf", ["Attachment" => 0]); // 0 para exibir no navegador, 1 para download
  1811.         }
  1812.         if (isset($_POST["etiqueta"])) {
  1813.             try {
  1814.         
  1815.                 // reforça limites (pode ajustar conforme necessário)
  1816.                 ini_set('max_execution_time'500);
  1817.                 ini_set('memory_limit''3512M');
  1818.         
  1819.                 $id_fluxo $_POST["etiqueta"];
  1820.                 $fluxo_pdf $doctrine->getRepository(Fluxo::class)->findWithAllRelations($id_fluxo);
  1821.                 $cliente_id $fluxo_pdf->getCliente()->getId();
  1822.                 $cliente $doctrine->getRepository(Cliente::class)->findWithRelations($cliente_id);
  1823.                 $nome_fluxo $fluxo_pdf->getNome();
  1824.                 $clienteAll_fluxo $cliente->getClienteAll()->getLogo();
  1825.                 
  1826.                 $cmd $clientS3->getCommand('GetObject', [
  1827.                 'Bucket' => 'arquivosdoc',
  1828.                 'Key'    => 'LOGO_CLIENTES/'$clienteAll_fluxo
  1829.                 ]);
  1830.                 
  1831.                 $req $clientS3->createPresignedRequest($cmd'+30 minutes');
  1832.                 $cliente_all_Url = (string) $req->getUri();
  1833.                 
  1834.                 $clienteAll_fluxo_id $cliente->getClienteAll()->getId();
  1835.                 $fluxo_caixas $doctrine->getRepository(Caixa::class)->findByFluxoWithRelations($fluxo_pdf->getId());
  1836.                 if ($cliente_id == 139 or $cliente_id == 137){
  1837.                         $html '
  1838.                         <!DOCTYPE html>
  1839.                         <html lang="pt-BR">
  1840.                         <head>
  1841.                             <meta charset="UTF-8">
  1842.                             <meta name="viewport" content="width=device-width, initial-scale=1.0">
  1843.                             <title>FLUXO</title>
  1844.                             <style>
  1845.                                 * { margin: 0; padding: 0; font-family: Calibri, Arial, sans-serif; }
  1846.                                 body { text-transform: uppercase; }
  1847.                                 .filho { border: 2px solid black; width: 57.2mm; height: 100mm; display: inline-block; margin: 2px; position: relative;}
  1848.                                 h2 { text-align: center; font-size: 20px; padding: 5px; }
  1849.                                 h2 img{width: 250px; height: 250px;}
  1850.                                 h4 { text-align: center; font-size: 12px; padding: 10px; }
  1851.                                 h5 { text-align: center; font-size: 14px;}
  1852.                                 h6 { text-align: center; font-size: 14px; padding: 5px; }
  1853.                                 h5 img { text-align: center;max-height: 40px;width:auto;max-width: 40px}
  1854.                                 h6 img { text-align: center;margin:auto;  max-height: 130px;width:auto;max-width: 130px}
  1855.                                 p { text-align: center; font-size: 8px; font-weight: bold;}
  1856.                                 .pai { position: relative; top: 11%; }
  1857.                                 hr { color: black; }
  1858.                                 .lis2{
  1859.                                     
  1860.                                     font-weight: bold;
  1861.                                     margin:5px;
  1862.                                 }
  1863.                                 .lis3 {
  1864.                                     position: absolute;
  1865.                                     bottom: 0;
  1866.                                     width: 100%;
  1867.                                     font-weight: bold;
  1868.                                     text-align: center;
  1869.                                     margin-bottom:5px;
  1870.                                     margin-top:5px;
  1871.                                        
  1872.                                 }
  1873.                                 .lis{
  1874.                                     
  1875.                                     margin-left:10px;
  1876.                                     font-weight: bold;
  1877.                                 }
  1878.                                 li{
  1879.                                   margin:5px;
  1880.                                   font-size: 12px
  1881.                                 }
  1882.                                 
  1883.                             </style>
  1884.                         </head>
  1885.                         <body>
  1886.                         <div class="pai">';
  1887.                 
  1888.                         $count 0;
  1889.                 
  1890.                         foreach ($fluxo_caixas as $caixa) {
  1891.                             $count++;
  1892.                             $documento_fluxo $caixa->getDocumentos()->toArray();
  1893.                             
  1894.                 
  1895.                             $html .= '<div class="filho">
  1896.                                 
  1897.                                 
  1898.                                 <h6><img src="'.$cliente_all_Url.'" class="img"></h6>
  1899.                                 <hr>
  1900.                                 <h2>' htmlspecialchars($caixa->getNome()) . '</h2>
  1901.                                 <hr>
  1902.                                 ';
  1903.                 
  1904.                             $docs = [];
  1905.                             
  1906.                             if (!empty($documento_fluxo)) {
  1907.                                 foreach ($documento_fluxo as $doc) {
  1908.                                     if($doc->getTipo() != NULL ){
  1909.                                         if ($cliente_id != 122) {
  1910.                                             $docs[] = $doc->getTipo()->getNome();
  1911.                                         } else {
  1912.                                             $docs[] = $doc->getNome();
  1913.                                         }
  1914.                                     }
  1915.                                 }
  1916.                                 $docs array_unique($docs);
  1917.                             }
  1918.                             
  1919.                             
  1920.                             $docs_class = [];
  1921.                             
  1922.                             if (!empty($documento_fluxo)) {
  1923.                                 foreach ($documento_fluxo as $doc) {
  1924.                                     
  1925.                                     if($doc->getClassificacao() != NULL ){
  1926.                                        $clss =  $entityManager->getRepository(Classificacao::class)->findBy(['id' => $doc->getClassificacao()->getId()]);
  1927.                                        $class_nome =  $clss[0]->getNome();
  1928.                                        $docs_class[] = $class_nome;
  1929.                                         
  1930.                                     }
  1931.                                 }
  1932.                                 $docs_class array_unique($docs_class);
  1933.                             }
  1934.                 
  1935.                             $docs_data = [];
  1936.                             $docs_assunto=[];
  1937.                             if (!empty($documento_fluxo)) {
  1938.                                 foreach ($documento_fluxo as $data) {
  1939.                                     if ($data->getNome() !== null) {
  1940.                                         $docs_data[] = $data->getNome();
  1941.                                     }
  1942.                                     if ($data->getAssunto() !== null) {
  1943.                                         $docs_assunto[] = $data->getAssunto();
  1944.                                     }
  1945.                                 }
  1946.                                 $docs_data array_unique($docs_data);
  1947.                                 $docs_assunto array_unique($docs_assunto);
  1948.                             }
  1949.                             
  1950.                              if ($cliente_id == 139){
  1951.                        
  1952.                                 $pl_numeros = [];
  1953.                                 $req_numeros = [];
  1954.                                 $req_ano null;
  1955.                                 
  1956.                                 foreach ($docs_data as $doc) {
  1957.                                 
  1958.                                 
  1959.                                     if (preg_match('/^PL-(\d{1,3}(?:\.\d{3})*)$/'$doc$m)) {
  1960.                                 
  1961.                                         $numeroLimpo str_replace('.'''$m[1]);
  1962.                                         $pl_numeros[] = (int)$numeroLimpo;
  1963.                                     }
  1964.                                 
  1965.                            
  1966.                                     elseif (stripos($doc'REQUERIMENTO') !== false 
  1967.                                         && preg_match('/-(\d+)\.(\d{4})$/'$doc$m)) {
  1968.                                 
  1969.                                         $req_numeros[] = (int)$m[1];
  1970.                                         $req_ano $m[2];
  1971.                                     }
  1972.                                 }
  1973.                                 
  1974.                         
  1975.                                 
  1976.                                 $menorNome null;
  1977.                                 $maiorNome null;
  1978.                                 $docs_faltantes = [];
  1979.                                 $tipoAtual null;
  1980.                                 
  1981.                           
  1982.                                 
  1983.                                 if (!empty($pl_numeros)) {
  1984.                                 
  1985.                                     sort($pl_numeros);
  1986.                                 
  1987.                                     $menor min($pl_numeros);
  1988.                                     $maior max($pl_numeros);
  1989.                                 
  1990.                                     $menorNome 'PL ' number_format($menor0'''.');
  1991.                                     $maiorNome 'PL ' number_format($maior0'''.');
  1992.                                 
  1993.                                     $esperado range($menor$maior);
  1994.                                     $faltantes array_diff($esperado$pl_numeros);
  1995.                                 
  1996.                                     foreach ($faltantes as $f) {
  1997.                                         $docs_faltantes[] = 'PL ' number_format($f0'''.');
  1998.                                     }
  1999.                                 
  2000.                                     $tipoAtual 'PL';
  2001.                                 }
  2002.                                 
  2003.                           
  2004.                                 
  2005.                                 elseif (!empty($req_numeros)) {
  2006.                                 
  2007.                                     sort($req_numeros);
  2008.                                 
  2009.                                     $menor min($req_numeros);
  2010.                                     $maior max($req_numeros);
  2011.                                 
  2012.                                     $menorNome str_pad($menor2'0'STR_PAD_LEFT) . '.' $req_ano;
  2013.                                     $maiorNome str_pad($maior2'0'STR_PAD_LEFT) . '.' $req_ano;
  2014.                                 
  2015.                                     $esperado range($menor$maior);
  2016.                                     $faltantes array_diff($esperado$req_numeros);
  2017.                                 
  2018.                                     foreach ($faltantes as $f) {
  2019.                                         $docs_faltantes[] = str_pad($f2'0'STR_PAD_LEFT) . '.' $req_ano;
  2020.                                     }
  2021.                                 
  2022.                                     $tipoAtual 'REQUERIMENTO';
  2023.                                 }                                                                        
  2024.                                                                                                                             
  2025.                                                                 
  2026.                                     $html .= '<h6>' htmlspecialchars(implode(', '$docs)) . '</h6>
  2027.                                     <hr>';
  2028.                                    
  2029.     
  2030.     
  2031.                                     $html .= '<h6>Conteúdo:</h6>';
  2032.     
  2033.                                     $html .= '<div class="lis">';
  2034.                                     foreach ($docs_class as $classs_nome) {
  2035.                                     $html .= '
  2036.                                         <li>' $classs_nome'</li>';
  2037.                                     }
  2038.                                     $html .= '</div><br>';
  2039.                                     
  2040.                                     
  2041.                                     if ($menorNome !== null && $maiorNome !== null) {
  2042.                                         $html .= '<h6>'.$menorNome.' Até '.$maiorNome.'</h6>';
  2043.                                     }
  2044.         
  2045.                                     if($docs_faltantes != []){
  2046.                                         $html .= '
  2047.                                         <div class="lis2"><p>';
  2048.                                                 $html .= 'Faltantes*</br>';
  2049.                                                 $qtdFaltantes count($docs_faltantes);
  2050.     
  2051.                                                 if ($qtdFaltantes 40) {
  2052.                                                 
  2053.                                                     $html .= '<span style="color:red; font-weight:bold;font-size: 8px">
  2054.                                                         Existem ' $qtdFaltantes . ($tipoAtual === 'PL' ' projetos de lei ' ' requerimentos ') . 'faltantes.
  2055.                                                         Conferir no inventário.
  2056.                                                     </span>';
  2057.                                                 
  2058.                                                 } else {
  2059.                                                 
  2060.                                                 $html .= implode(' | '$docs_faltantes);
  2061.     
  2062.                                                 
  2063.                                                 }
  2064.                                             
  2065.                                         $html .= '</p></div>';
  2066.                                     }
  2067.                                 }
  2068.                                 else{
  2069.                                     
  2070.                                                                 // Remove duplicados
  2071.                                 $docs_assunto array_unique($docs_assunto);
  2072.                                 
  2073.                                 // Converte para DateTime
  2074.                                 $datasObj array_map(function ($data) {
  2075.                                     return DateTime::createFromFormat('m/Y'$data);
  2076.                                 }, $docs_assunto);
  2077.                                 
  2078.                                 // Remove possíveis datas inválidas
  2079.                                 $datasObj array_filter($datasObj);
  2080.                                 
  2081.                                 // Ordena por data
  2082.                                 usort($datasObj, function ($a$b) {
  2083.                                     return $a <=> $b;
  2084.                                 });
  2085.                                 
  2086.                                 $resultado = [];
  2087.                                 
  2088.                                 if (count($datasObj) > 0) {
  2089.                                 
  2090.                                     $inicio $datasObj[0];
  2091.                                     $anterior $datasObj[0];
  2092.                                 
  2093.                                     for ($i 1$i count($datasObj); $i++) {
  2094.                                 
  2095.                                         $atual $datasObj[$i];
  2096.                                 
  2097.                                         $proximoEsperado = clone $anterior;
  2098.                                         $proximoEsperado->modify('+1 month');
  2099.                                 
  2100.                                         if ($atual->format('m/Y') !== $proximoEsperado->format('m/Y')) {
  2101.                                 
  2102.                                             if ($inicio->format('m/Y') === $anterior->format('m/Y')) {
  2103.                                                 $resultado[] = $inicio->format('m/Y');
  2104.                                             } else {
  2105.                                                 $resultado[] = $inicio->format('m/Y') . ' até ' $anterior->format('m/Y');
  2106.                                             }
  2107.                                 
  2108.                                             $inicio $atual;
  2109.                                         }
  2110.                                 
  2111.                                         $anterior $atual;
  2112.                                     }
  2113.                                 
  2114.                                     // Fecha o último bloco
  2115.                                     if ($inicio->format('m/Y') === $anterior->format('m/Y')) {
  2116.                                         $resultado[] = $inicio->format('m/Y');
  2117.                                     } else {
  2118.                                         $resultado[] = $inicio->format('m/Y') . ' Até ' $anterior->format('m/Y');
  2119.                                     }
  2120.                                 }
  2121.                                 
  2122.                                     
  2123.                                     
  2124.                                     
  2125.                                     
  2126.                                     $html .= '<h6>Conteúdo:</h6>';
  2127.     
  2128.                                     $html .= '<div class="lis">';
  2129.                                     foreach ($docs_class as $classs_nome) {
  2130.                                     $html .= '
  2131.                                         <li>' $classs_nome'</li>';
  2132.                                     }
  2133.                                     $len count($resultado);
  2134.                                     if ($len <and $len >0) {
  2135.                                          
  2136.                                          $html .= '<br>';     
  2137.                                     }
  2138.                                     foreach ($docs_data as $classs_nome) {
  2139.                                     $html .= '
  2140.                                         <h6>' $classs_nome'</h6>';
  2141.                                     }
  2142.                                     
  2143.                                     
  2144.                                     
  2145.                                         
  2146.                                     foreach ($resultado as $classs_nome) {
  2147.                                         if ($len >= 9) {
  2148.                                             $fontSize 8;
  2149.                                         } 
  2150.                                         elseif ($len <10 and $len >5) {
  2151.                                             $fontSize 10;
  2152.                                         }
  2153.                                         
  2154.                                         elseif ($len <and $len >0) {
  2155.                                             $fontSize 12;
  2156.                                              
  2157.                                         }else{
  2158.                                             $fontSize 8;
  2159.                                         }
  2160.                                         
  2161.                                     $html .= '
  2162.                                         <p style="font-size: ' $fontSize 'px;">' $classs_nome'</p>';
  2163.                                     }
  2164.                                     
  2165.                                     $html .= '</div><br>';
  2166.                                 }
  2167.                                 $html .= 
  2168.                                 
  2169.                                 
  2170.                                 '<div class="lis3"><hr>
  2171.                                 
  2172.                                 <p>ARQUIVOS GESTÃO DOCUMENTAL</p>
  2173.                                 <h5><img src="https://index.arquivosdoc.com.br/img/logo_menu.png" class="img"></h5>
  2174.                                 </div>
  2175.                                 
  2176.                             </div>';
  2177.                 
  2178.                             if ($count %  10 == 0) {
  2179.                                 $html .= '<div style="page-break-after: always;"></div>';
  2180.                             }
  2181.                         }
  2182.                
  2183.                         $html .= '</div></body></html>';
  2184.                 }
  2185.         
  2186.                 if($clienteAll_fluxo_id != 17 and $clienteAll_fluxo_id != 40 and $cliente_id != 139 and $cliente_id != 137){
  2187.                         // Construção do HTML com os QR Codes
  2188.                         $html '
  2189.                         <!DOCTYPE html>
  2190.                         <html lang="pt-BR">
  2191.                         <head>
  2192.                             <meta charset="UTF-8">
  2193.                             <meta name="viewport" content="width=device-width, initial-scale=1.0">
  2194.                             <title>FLUXO</title>
  2195.                             <style>
  2196.                                 * { margin: 0; padding: 0; font-family: Calibri, Arial, sans-serif; }
  2197.                                 body { text-transform: uppercase; }
  2198.                                 .filho { border: 2px solid black; width: 120mm; height: 170mm; display: inline-block; margin-left: 45px; }
  2199.                                 h2 { text-align: center; font-size: 36px; padding: 5px; }
  2200.                                 h2 img{width: 200px; height: 200px;}
  2201.                                 h4 { text-align: center; font-size: 12px; padding: 10px; }
  2202.                                 h5 { text-align: center; font-size: 22px; padding: 10px; }
  2203.                                 h6 { text-align: justify; font-size: 26px; padding: 5px; }
  2204.                                 h6 img { float: right;  max-height: 70px;width:auto;max-width: 170px}
  2205.                                 p { text-align: justify; font-size: 14px; font-weight: bold; padding: 10px; }
  2206.                                 .pai { position: relative; top: 20%; }
  2207.                                 hr { color: black; }
  2208.                                 .lis{
  2209.                                 
  2210.                                  width:430px; height: 200px;
  2211.                                  margin:auto;
  2212.                                  font-weight: bold;
  2213.                                 }
  2214.                                 li{
  2215.                                   margin-left:10px;
  2216.                                 }
  2217.                                 
  2218.                             </style>
  2219.                         </head>
  2220.                         <body>
  2221.                         <div class="pai">';
  2222.         
  2223.                         $count 0;
  2224.         
  2225.                         foreach ($fluxo_caixas as $caixa) {
  2226.                             $count++;
  2227.                             $documento_fluxo $caixa->getDocumentos()->toArray();
  2228.         
  2229.                             // Gerar QR Code
  2230.                             $qrCode Builder::create()
  2231.                                 ->writer(new PngWriter())
  2232.                                 ->data("https://ged.arquivosdoc.com.br/info/caixa/" $caixa->getId())
  2233.                                 ->build();
  2234.                             $qrCodeBase64 base64_encode($qrCode->getString());
  2235.         
  2236.                             $html .= '<div class="filho">
  2237.                                 <h2>' htmlspecialchars($caixa->getNome()) . '</h2>
  2238.                                 <hr>
  2239.                                 <h6>Arquivos:<img src="'.$cliente_all_Url.'" class="img"></h6>
  2240.                                 <p>' htmlspecialchars($fluxo_pdf->getNome()) . '</p>
  2241.                                 <hr>
  2242.                                 <h6>Título:</h6>';
  2243.         
  2244.                             $docs = [];
  2245.                             
  2246.                             if (!empty($documento_fluxo)) {
  2247.                                 foreach ($documento_fluxo as $doc) {
  2248.                                     if($doc->getTipo() != NULL ){
  2249.                                         if ($cliente_id != 122) {
  2250.                                             $docs[] = $doc->getTipo()->getNome();
  2251.                                         } else {
  2252.                                             $docs[] = $doc->getNome();
  2253.                                         }
  2254.                                     }
  2255.                                 }
  2256.                                 $docs array_unique($docs);
  2257.                             }
  2258.                             
  2259.                             $docs_class = [];
  2260.                             
  2261.                             if (!empty($documento_fluxo)) {
  2262.                                 foreach ($documento_fluxo as $doc) {
  2263.                                     
  2264.                                     if($doc->getClassificacao() != NULL ){
  2265.                                        $clss =  $entityManager->getRepository(Classificacao::class)->findBy(['id' => $doc->getClassificacao()->getId()]);
  2266.                                        $class_nome =  $clss[0]->getNome();
  2267.                                        $docs_class[] = $class_nome;
  2268.                                        
  2269.                                         
  2270.                                     }
  2271.                                 }
  2272.                                 $docs_class array_unique($docs_class);
  2273.                             }
  2274.                             
  2275.         
  2276.                             $html .= '<p>' htmlspecialchars(implode(', '$docs)) . '</p>
  2277.                                 <hr>
  2278.                                 <h6>Conteúdo:</h6>';
  2279.                                 
  2280.                                 
  2281.                                 
  2282.                                   if($clienteAll_fluxo_id == 41){
  2283.                                       
  2284.                                         $html .= '<div class="lis">';
  2285.                                         $len count($docs_class);
  2286.                                      
  2287.                                         foreach ($docs_class as $classs_nome) {
  2288.                                         
  2289.                                         
  2290.                                             
  2291.                                             if ($len <= 9) {
  2292.                                                 $fontSize 16;
  2293.                                             } 
  2294.                                             elseif ($len <= 11) {
  2295.                                                 $fontSize 14;
  2296.                                             } 
  2297.                                             elseif ($len <= 13) {
  2298.                                                 $fontSize 12;
  2299.                                             } 
  2300.                                             elseif ($len <= 16) {
  2301.                                                 $fontSize 10;
  2302.                                             }
  2303.                                             elseif ($len <= 18) {
  2304.                                                 $fontSize 9;
  2305.                                             }
  2306.                                             elseif ($len <= 21) {
  2307.                                                 $fontSize =8;
  2308.                                             }
  2309.                                             elseif ($len <= 23) {
  2310.                                                 $fontSize 7;
  2311.                                             }
  2312.                                             else {
  2313.                                                 $fontSize 6;
  2314.                                             }
  2315.                                             $html .= '<li style="font-size: ' $fontSize 'px;">' $classs_nome '</li>';
  2316.                                         }
  2317.                                         
  2318.                                         $html .= '</div>';
  2319.                                         
  2320.                                       
  2321.                                   }else{
  2322.                                              $html .= '
  2323.                                                 <h2><img src="data:image/png;base64,' $qrCodeBase64 '" alt="QR Code"></h2>';
  2324.                                   }  
  2325.                                         
  2326.                                 
  2327.                                 
  2328.                                 $html .= '<hr>
  2329.                                 <h4>ARQUIVOS GESTÃO DOCUMENTAL</h4>
  2330.                                 <h5><img src="https://index.arquivosdoc.com.br/img/arquivos_mini.png" class="img"></h5>
  2331.                                 <hr>
  2332.                                 <h4>Etiqueta gerada automaticamente pelo ArquivosGED</h4>
  2333.                             </div>';
  2334.         
  2335.                             if ($count == 0) {
  2336.                                 $html .= '<div style="page-break-after: always;"></div>';
  2337.                             }
  2338.                         }
  2339.                
  2340.         
  2341.                         $html .= '</div></body></html>';
  2342.                 }
  2343.         
  2344.                 
  2345.                 if($clienteAll_fluxo_id == 17 ){
  2346.                     // Construção do HTML com os QR Codes
  2347.                     $html '
  2348.                     <!DOCTYPE html>
  2349.                     <html lang="pt-BR">
  2350.                     <head>
  2351.                         <meta charset="UTF-8">
  2352.                         <meta name="viewport" content="width=device-width, initial-scale=1.0">
  2353.                         <title>FLUXO</title>
  2354.                         <style>
  2355.                             * { margin: 0; padding: 0; font-family: Calibri, sans-serif; }
  2356.                             .filho { border: 2px solid black; width: 125mm; height: 170mm; display: inline-block; margin-left: 45px; }
  2357.                             h2 { font-size: 36px; padding: 5px; }
  2358.                             h2 img{width: 200px; height: 200px;}
  2359.                             .img_footer{width: 60px; height: 60px;position:relative;top:20px}
  2360.                             h4 { text-align: center; font-size: 12px; padding: 10px; }
  2361.                             h5 { text-align: center; font-size: 22px; padding: 10px; }
  2362.                             h6 { text-align: justify; font-size: 26px; padding: 5px; }
  2363.                             h6 img { float: right;  max-height: 77px;width:auto;max-width: 250px}
  2364.                             p { text-align: justify; font-size: 18px; font-weight: bold; padding: 10px; }
  2365.                             .pai { position: relative; top: 20%; }
  2366.                             hr { color: black; }
  2367.                             .rodape {
  2368.                                 position:relative;bottom:15px
  2369.                             }
  2370.         
  2371.                             
  2372.                         </style>
  2373.                     </head>
  2374.                     <body>
  2375.                     <div class="pai">';
  2376.             
  2377.                     $count 0;
  2378.         
  2379.                     $codigo "";
  2380.                     $info "";
  2381.                     $prazo "";
  2382.         
  2383.                     if($cliente_id == 113){
  2384.                         $codigo "23.182";
  2385.                         $info "PROCESSOS DIVERSOS";
  2386.                         $prazo "57 ANOS";
  2387.                     }
  2388.         
  2389.                     if($cliente_id == 114){                        
  2390.                         $codigo "23.11";
  2391.                         $info "PROCESSOS DE RECURSOS HUMANOS";
  2392.                         $prazo "100 ANOS";
  2393.                     }
  2394.             
  2395.                     foreach ($fluxo_caixas as $caixa) {
  2396.         
  2397.         
  2398.                         $texto $caixa->getNome();
  2399.         
  2400.                         preg_match_all('/\d+/'$texto$matches);
  2401.                         
  2402.                         if (count($matches[0]) >= 2) {
  2403.                              $numero str_pad($matches[0][0], 3'0'STR_PAD_LEFT); 
  2404.                             $ano substr($textostrpos($texto$matches[0][0]) + strlen($matches[0][0])); 
  2405.                             $ano trim(str_replace('-'''$ano)); 
  2406.                         } else {
  2407.                             echo "Formato inválido!";
  2408.                         }
  2409.         
  2410.         
  2411.         
  2412.                         $count++;
  2413.                         $documento_fluxo $caixa->getDocumentos()->toArray();
  2414.         
  2415.                         // Gerar QR Code
  2416.                         $qrCode Builder::create()
  2417.                             ->writer(new PngWriter())
  2418.                             ->data("https://ged.arquivosdoc.com.br/info/caixa/" $caixa->getId())
  2419.                             ->build();
  2420.                         $qrCodeBase64 base64_encode($qrCode->getString());
  2421.             
  2422.                         $html .= '<div class="filho">
  2423.                             <h2>&nbsp;Caixa nº&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'htmlspecialchars($numero) . '</h2>
  2424.                             <hr>
  2425.                             <h6>ARQUIVO:<img src="'.$cliente_all_Url'" class="img"></h6>
  2426.                             <p>SAAE VOLTA REDONDA-RJ</p>
  2427.                             <hr>
  2428.                             <h6>CÓDIGO TEMPORALIDADE:</h6>
  2429.                             <p>'.$codigo.'</p><hr>
  2430.                             <h6>TÍTULO:</h6>';
  2431.             
  2432.         
  2433.                         $html .= '<p>' htmlspecialchars('PROCESSOS ADMINISTRATIVOS') . '</p>
  2434.                             <hr>
  2435.                             <h6>INFORMAÇÕES:</h6>
  2436.                             <p>'.$info.'</p>
  2437.                             <hr>
  2438.                             <h6>PRAZO DE GUARDA:</h6>
  2439.                             <p>'.$prazo.'</p>
  2440.                             <hr>
  2441.                             <h6>DATA:</h6>
  2442.                             <p>'.$ano.'</p>
  2443.                             <hr>
  2444.                            
  2445.                                 <p class="rodape">&nbsp;ARQUIVOS GESTÃO DOCUMENTAL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2446.                                 <img src="https://index.arquivosdoc.com.br/img/arquivos_mini.png" class="img_footer"></p>
  2447.                            
  2448.                             </div>';
  2449.             
  2450.                         if ($count == 0) {
  2451.                             $html .= '<div style="page-break-after: always;"></div>';
  2452.                         }
  2453.                     }
  2454.            
  2455.         
  2456.                     $html .= '</div></body></html>';
  2457.                 }
  2458.                 
  2459.                 if($clienteAll_fluxo_id == 40  ){
  2460.                         $documento_all_sebrae $doctrine->getRepository(Documento::class)
  2461.                         ->findBy(
  2462.                             ['cliente' => $cliente_id], // filtros
  2463.                             ['id' => 'DESC'],            // ordenação (opcional)
  2464.                             100,                        // LIMIT
  2465.                             0                           // OFFSET
  2466.                         );
  2467.                         $html '
  2468.                         <!DOCTYPE html>
  2469.                         <html lang="pt-BR">
  2470.                         <head>
  2471.                             <meta charset="UTF-8">
  2472.                             <meta name="viewport" content="width=device-width, initial-scale=1.0">
  2473.                             <title>FLUXO</title>
  2474.                             <style>
  2475.                                 * { margin: 0; padding: 0; font-family: Calibri, Arial, sans-serif; }
  2476.                                 body { text-transform: uppercase; }
  2477.                                 .filho { border: 2px solid black; width: 120mm; height: 160mm; display: inline-block; margin-left: 20px;padding:10px;} 
  2478.                                 h2 { text-align: center; font-size: 36px; padding: 5px; }
  2479.                                 h2 img{width: 200px; height: 200px;}
  2480.                                 h4 { text-align: center; font-size: 12px; padding: 10px; }
  2481.                                 h5 { text-align: center; font-size: 22px; padding: 10px; }
  2482.                                 h6 { text-align: justify; font-size: 26px; padding: 5px; }}
  2483.                                 p { text-align: justify; font-size: 18px; font-weight: bold; padding: 10px; }
  2484.                                 .pai { position: relative; top: 20%;text-align:center; }
  2485.                                 hr { color: black; }
  2486.                                 
  2487.                                     .linha {
  2488.                                         margin-bottom: 1mm;
  2489.                                         font-size: 10pt;
  2490.                                     }
  2491.                                     .box-label {
  2492.                                         background: #f1f1f1;
  2493.                                         border: 1px solid black;
  2494.                                         padding: 1mm;
  2495.                                         font-size: 8pt;
  2496.                                         text-align: center;
  2497.                                         margin-top: 1mm;
  2498.                                     }
  2499.                                     .box-value {
  2500.                                         text-align: center;
  2501.                                         font-size: 10pt;
  2502.                                         margin: 2mm 0 2mm 0;
  2503.                                         
  2504.                                     }
  2505.                                    .box-value_conteudo {
  2506.                                         margin: 2mm 0 2mm 0;
  2507.                                         text-align: justify;
  2508.                                        
  2509.                                     }
  2510.                                     
  2511.                                     img{
  2512.                                         width: 120px;
  2513.                                         height:80px;
  2514.                                         margin: 2mm 0 2mm 0;
  2515.                                     }
  2516.                                     
  2517.                                     .titulo{
  2518.                                         margin: 2mm 0 2mm 0;
  2519.                                         font-size: 10pt;
  2520.                                     }
  2521.                                     
  2522.                                     .bloco-conteudo {
  2523.                                         position: relative;
  2524.                                         height: 100%;
  2525.                                     }
  2526.                                     
  2527.                                     .hr-fixo {
  2528.                                         position: absolute;
  2529.                                         bottom: 0;
  2530.                                         left: 0;
  2531.                                         width: 100%;
  2532.                                         margin: 0 0 0 0;
  2533.                                     }
  2534.                                     
  2535.                                 
  2536.                             </style>
  2537.                         </head>
  2538.                         <body>
  2539.                         <div class="pai">';
  2540.                 
  2541.                         $count 0;
  2542.                 
  2543.                         foreach ($documento_all_sebrae as $caixa) {
  2544.                             $count++;
  2545.                                 $conteudo htmlspecialchars(str_replace('?'''$caixa->getExtraFields()));
  2546.                                 $tamanho strlen($conteudo);
  2547.                                 $dates="";
  2548.                             
  2549.                                 if ($tamanho <= 300) {
  2550.                                     $fontSize '8pt';
  2551.                                 } elseif ($tamanho <= 600) {
  2552.                                     $fontSize '7pt';
  2553.                                 } elseif ($tamanho <= 900) {
  2554.                                     $fontSize '6pt';
  2555.                                 } else {
  2556.                                     $fontSize '4pt';
  2557.                                 }
  2558.                                 
  2559.                                 if($caixa->getDataDocumento()){
  2560.                                     $dates=$caixa->getDataDocumento()->format('d/m/Y');
  2561.                                 }
  2562.                             
  2563.                                 $html .= 
  2564.                                     '<div class="filho">
  2565.                                         <div class="bloco-conteudo">
  2566.                                         
  2567.                                             <img src="'.$cliente_all_Url.'" class="img"></h6>
  2568.                             
  2569.                                             <div class="titulo">ARQUIVO INATIVO</div><br>
  2570.                             
  2571.                                             <div class="linha">CAIXA Nº: _______________</div>
  2572.                             
  2573.                                             <div class="box-label">ÁREA/SIGLA:</div>
  2574.                                             <div class="box-value">'htmlspecialchars($caixa->getAssunto()) .'</div>
  2575.                             
  2576.                                             <div class="box-label">RESPONSÁVEL:</div>
  2577.                                             <div class="box-value">'htmlspecialchars($caixa->getConteiner()) .'</div>
  2578.                             
  2579.                                             <div class="box-label">DATA 1º ENVIO:</div>
  2580.                                             <div class="box-value">'htmlspecialchars($dates) .'</div>
  2581.                             
  2582.                                             <div class="box-label">Conteúdo</div>
  2583.                                             <div class="box-value_conteudo" style="font-size: '$fontSize .'">'$conteudo .'</div>
  2584.                                             
  2585.                                             <div class="hr-fixo">
  2586.                                                 <hr>
  2587.                                                 <div>CXRBM:'htmlspecialchars($caixa->getNome()) .'</div>
  2588.                                             </div>
  2589.                             
  2590.                                         </div>
  2591.         </div>';
  2592.                             $docs = [];
  2593.                             if ($count == 0) {
  2594.                                 $html .= '<div style="page-break-after: always;"></div>';
  2595.                             }
  2596.                         }
  2597.                
  2598.                         $html .= '</div></body></html>';
  2599.                 }
  2600.                         
  2601.                
  2602.                
  2603.                 // Configurar o Dompdf
  2604.                 $options = new Options();
  2605.                 $options->set('isHtml5ParserEnabled'true);
  2606.                 $options->set('isPhpEnabled'true);
  2607.                 $options->set('isRemoteEnabled'true);
  2608.                 $dompdf = new Dompdf($options);
  2609.                 $dompdf->loadHtml($html);
  2610.                 $dompdf->setPaper('A4''landscape');
  2611.         
  2612.                 // LIMPA TODOS OS BUFFERS ANTES DE RENDERIZAR
  2613.                 while (ob_get_level()) {
  2614.                     ob_end_clean();
  2615.                 }
  2616.         
  2617.                 // Tenta renderizar e, em vez de stream() direto, grava em arquivo temporário e envia
  2618.                 try {
  2619.                     $dompdf->render();
  2620.                 } catch (Throwable $e) {
  2621.                     // registra o erro e lança para cair no catch externo
  2622.                     error_log('Dompdf render failed: ' $e->getMessage());
  2623.                     throw $e;
  2624.                 }
  2625.         
  2626.                 // Gera arquivo temporário seguro
  2627.                 $tempFile sys_get_temp_dir() . DIRECTORY_SEPARATOR 'etiqueta_fluxo_' $id_fluxo '_' uniqid() . '.pdf';
  2628.                 $output $dompdf->output();
  2629.         
  2630.                 if (file_put_contents($tempFile$output) === false) {
  2631.                     throw new Exception('Falha ao escrever arquivo temporário do PDF.');
  2632.                 }
  2633.         
  2634.                 // Força headers corretos para download/visualização
  2635.                 header('Content-Type: application/pdf');
  2636.                 // Se quiser forçar download use attachment; se quiser abrir no browser use inline
  2637.                 header('Content-Disposition: inline; filename="Etiqueta_Fluxo_' preg_replace('/[^A-Za-z0-9_\-\.]/''_'$id_fluxo '_' $nome_fluxo) . '.pdf"');
  2638.                 header('Content-Length: ' filesize($tempFile));
  2639.                 header('Cache-Control: private, max-age=0, must-revalidate');
  2640.         
  2641.                 // Envia o arquivo binário ao navegador
  2642.                 readfile($tempFile);
  2643.         
  2644.                 // Remove o arquivo temporário com segurança
  2645.                 @unlink($tempFile);
  2646.         
  2647.                 // finaliza execução
  2648.                 exit;
  2649.         
  2650.                 
  2651.             } catch (Exception $e) {
  2652.                 // Loga para diagnóstico e mostra mensagem amigável
  2653.                 error_log('Erro ao gerar o PDF: ' $e->getMessage());
  2654.                 echo 'Erro ao gerar o PDF: ' htmlspecialchars($e->getMessage());
  2655.             }
  2656.         
  2657.         
  2658. }
  2659.         if (isset($_POST["qrcode"])) {
  2660.                 $id_fluxo $_POST["qrcode"];
  2661.                 $fluxo_qrcode $doctrine->getRepository(Fluxo::class)->findWithAllRelations($_POST["qrcode"]);
  2662.                 $nome_fluxo $fluxo_qrcode->getNome();
  2663.                 $fluxo_caixas_qrcode $doctrine->getRepository(Caixa::class)->findByFluxoWithRelations($fluxo_qrcode->getId());
  2664.                 $clienteAll_id $fluxo_qrcode->getCliente()->getId();
  2665.                 
  2666.                 if ($fluxo_caixas_qrcode != null ) {
  2667.                     $options = new Options();
  2668.                     $options->set('isHtml5ParserEnabled'true);
  2669.                     $options->set('isPhpEnabled'true);
  2670.                     $dompdf = new Dompdf($options);
  2671.                             
  2672.                     $html '
  2673.                         <html>
  2674.                             <head>
  2675.                                 <style>
  2676.                                     @page {
  2677.                                         margin: 35px 18.9px 0px 18.9px;
  2678.                                         size: 210mm 297mm; /* Ajuste de tamanho do papel */
  2679.                                     }
  2680.                                     body {
  2681.                                         margin: 0;
  2682.                                         padding: 0;
  2683.                                     }
  2684.                                     .qr-item {
  2685.                                         border: 2px dotted #000;
  2686.                                         text-align: center;
  2687.                                         width: 32.27mm;
  2688.                                         height: 34.9mm; 
  2689.                                         display: inline-block;
  2690.                                     }
  2691.                         
  2692.                                     .qr-item img {
  2693.                                         width: 115px; 
  2694.                                         height: 112px;
  2695.                                     }
  2696.                                     .qr-title {
  2697.                                         font-size: 16px;
  2698.                                         font-weight: bold;
  2699.                                     }
  2700.                                     .leo {
  2701.                                         display: flex;
  2702.                                         flex-wrap: wrap;
  2703.                                     }
  2704.                                 </style>
  2705.                             </head>
  2706.                             <body>';
  2707.             
  2708.                     $count 0// Contador de QR Codes
  2709.             
  2710.                     foreach ($fluxo_caixas_qrcode as $cx) {
  2711.                         $id_cx_ultimo $cx->getCx();
  2712.             
  2713.                         if ($id_cx_ultimo !== null) {
  2714.                             $nome $id_cx_ultimo->getNome();
  2715.             
  2716.                             // Gerar QR Code com imagem no centro
  2717.                             $result Builder::create()
  2718.                                 ->writer(new PngWriter())
  2719.                                 ->writerOptions([])
  2720.                                 ->data('https://logistica.arquivosdoc.com.br/'.$clienteAll_id.'/'.$nome)
  2721.                                 ->encoding(new Encoding('UTF-8'))
  2722.                                 ->size(500)
  2723.                                 ->margin(5)
  2724.                                 ->logoPath(__DIR__ '/logo.png'// Caminho do logo central
  2725.                                 ->build();
  2726.                             
  2727.                             // Salvar QR Code como arquivo temporário
  2728.                             $tempFile tempnam(sys_get_temp_dir(), 'qr_') . '.png';
  2729.                             $result->saveToFile($tempFile);
  2730.             
  2731.                             // Adicionar QR Code ao HTML
  2732.                             if ($count 48 == 0) {
  2733.                                 $html .= '<div class="leo">';
  2734.                             }
  2735.             
  2736.                             $html .= '<div class="qr-item">';
  2737.                             $html .= '<div class="qr-title">' $nome '</div>';
  2738.                             $html .= '<img src="data:image/png;base64,' base64_encode(file_get_contents($tempFile)) . '">';
  2739.                             $html .= '</div>';
  2740.             
  2741.                             $count++;
  2742.             
  2743.                             // Fechar a div e inserir quebra de página a cada 63 QR Codes
  2744.                             if ($count 48 == 0) {
  2745.                                 $html .= '</div><div style="page-break-after: always;"></div>';
  2746.                             }
  2747.                         }
  2748.                     }
  2749.             
  2750.                     // Fechar qualquer div aberta sem completar 63 itens
  2751.                     if ($count 48 != 0) {
  2752.                         $html .= '</div>';
  2753.                     }
  2754.             
  2755.                     $html .= '</body></html>';
  2756.             
  2757.                     // Carregar o HTML e gerar o PDF
  2758.                     $dompdf->loadHtml($html);
  2759.                     $dompdf->setPaper([00210297], 'portrait'); // Configurar o tamanho de página para A4
  2760.                     $dompdf->render();
  2761.                     $dompdf->stream("Qrcode_" $id_fluxo "_" $nome_fluxo ".pdf", ["Attachment" => ]);
  2762.                 } else {
  2763.                     echo "<script>alert('ERROR, ESSE FLUXO NÃO TEM SETOR DE GUARDA!');</script>";
  2764.                 }
  2765.             }
  2766.         
  2767.         if (isset($_POST["container"])) {
  2768.             $id_fluxo $_POST["container"];
  2769.             $fluxo_caixas $doctrine->getRepository(Caixa::class)->findByFluxoWithRelations($id_fluxo);
  2770.             $fluxo_container $doctrine->getRepository(Fluxo::class)->findWithAllRelations($id_fluxo);
  2771.             $clienteAll_id $fluxo_container->getCliente()->getId();
  2772.             $containers = [];
  2773.         
  2774.             foreach ($fluxo_caixas as $caixa) {
  2775.                 $documentos $caixa->getDocumentos();
  2776.         
  2777.                 foreach ($documentos as $documento) {
  2778.                     $container $documento->getConteiner(); 
  2779.                     $caixaId $documento->getCaixa()->getId(); 
  2780.                     
  2781.                     if ($container != null and $caixaId != null) {
  2782.                         
  2783.                         if (!isset($containers[$container])) {
  2784.                             $containers[$container] = [];
  2785.                         }
  2786.         
  2787.                         if (!in_array($caixaId$containers[$container])) {
  2788.                             $containers[$container][] = $caixaId;
  2789.                         }
  2790.                     }
  2791.                 }
  2792.             }
  2793.             
  2794.             $options = new Options();
  2795.             $options->set('isHtml5ParserEnabled'true);
  2796.             $options->set('isPhpEnabled'true);
  2797.             $dompdf = new Dompdf($options);
  2798.                     
  2799.             $html '
  2800.                 <html>
  2801.                     <head>
  2802.                         <style>
  2803.                             @page {
  2804.                                 margin: 35px 18.9px 0px 18.9px;
  2805.                                 size: 210mm 297mm; /* Ajuste de tamanho do papel */
  2806.                             }
  2807.                             body {
  2808.                                 margin: 0;
  2809.                                 padding: 0;
  2810.                             }
  2811.                             .qr-item {
  2812.                                 border: 2px dotted #000;
  2813.                                 width: 200mm;
  2814.                                 height: 80mm;
  2815.                                 margin-top:15px; 
  2816.                                 text-align: center;
  2817.                                
  2818.                                 
  2819.                             }
  2820.                              .img_qrcode h2{                           
  2821.                                position:relative;
  2822.                                top:25px;
  2823.                             }
  2824.                             .img_qrcode h3{                           
  2825.                                position:relative;
  2826.                                bottom:25px;
  2827.                                font-size: 20px;
  2828.                             }
  2829.                             .img_qrcode{
  2830.                                
  2831.                                 display: inline-block;
  2832.                                 margin: 5px  30px 5px 30px;
  2833.                                
  2834.                                
  2835.                             }
  2836.                 
  2837.                             .qr-item img {
  2838.                                 
  2839.                                 width: 170px; 
  2840.                                 height: 170px;
  2841.                                 
  2842.                             }
  2843.                             .qr-title {
  2844.                                 font-size: 70px;
  2845.                                 font-weight: bold;
  2846.                                
  2847.                             }
  2848.                             .leo {
  2849.                                 display: flex;
  2850.                                 flex-wrap: wrap;
  2851.                             }
  2852.                         </style>
  2853.                     </head>
  2854.                     <body>';
  2855.     
  2856.             $count 0// Contador de QR Codes
  2857.             // Exibir resultado
  2858.             foreach ($containers as $container => $caixas) {
  2859.                 #echo "Container $container => " . implode(", ", $caixas) . "<br>";
  2860.                 
  2861.                
  2862.                 if ($count == 0) {
  2863.                     $html .= '<div class="leo">';
  2864.                 }
  2865.                 $html .= '<div class="qr-item">';
  2866.                 $html .= '<div class="qr-title">' $container '</div><hr>';
  2867.                 foreach($caixas as $caixa ){
  2868.                     $caix $doctrine->getRepository(Caixa::class)->find($caixa);
  2869.                     $caix_nome =$caix->getNome();
  2870.                     $caix_cx =$caix->getCx()->getNome();
  2871.                     $result Builder::create()
  2872.                     ->writer(new PngWriter())
  2873.                     ->writerOptions([])
  2874.                     ->data('https://logistica.arquivosdoc.com.br/'.$clienteAll_id.'/'.$caix_cx)
  2875.                     ->encoding(new Encoding('UTF-8'))
  2876.                     ->size(350)
  2877.                     ->margin(5)
  2878.                     ->logoPath(__DIR__ '/logo.png'
  2879.                     ->build();
  2880.                 
  2881.                 
  2882.                     $tempFile tempnam(sys_get_temp_dir(), 'qr_') . '.png';
  2883.                     $result->saveToFile($tempFile);
  2884.                     
  2885.                     $html .= '
  2886.                         <div class="img_qrcode">    
  2887.                             <h2>'.$caix_cx.'</h2>
  2888.                             <img src="data:image/png;base64,' base64_encode(file_get_contents($tempFile)) . '">
  2889.                             <h3>'.$caix_nome.'</h3>
  2890.                         </div>
  2891.                     
  2892.                     ';
  2893.                 }
  2894.                 $html .= '</div>';
  2895.                 $count++;
  2896.                 
  2897.                 if ($count == 0) {
  2898.                     $html .= '</div><div style="page-break-after: always;"></div>';
  2899.                 }
  2900.             }
  2901.               // Fechar qualquer div aberta sem completar 63 itens
  2902.               if ($count != 0) {
  2903.                 $html .= '</div>';
  2904.             }
  2905.     
  2906.             $html .= '</body></html>';
  2907.     
  2908.             // Carregar o HTML e gerar o PDF
  2909.             $dompdf->loadHtml($html);
  2910.             $dompdf->setPaper([00210297], 'portrait'); // Configurar o tamanho de página para A4
  2911.             $dompdf->render();
  2912.             $dompdf->stream("Qrcode.pdf", ["Attachment" => ]);
  2913.             
  2914.         }
  2915.         
  2916.         if (isset($_POST["pasta"])) {
  2917.             
  2918.                 // reforça limites (pode ajustar conforme necessário)
  2919.                 ini_set('max_execution_time'500);
  2920.                 ini_set('memory_limit''3512M');
  2921.         
  2922.                 $id_fluxo $_POST["pasta"];
  2923.                 $fluxo_pdf $doctrine->getRepository(Fluxo::class)->findWithAllRelations($id_fluxo);
  2924.                 $cliente_id $fluxo_pdf->getCliente()->getId();
  2925.                 $cliente $doctrine->getRepository(Cliente::class)->findWithRelations($cliente_id);
  2926.                 $nome_fluxo $fluxo_pdf->getNome();
  2927.                 $clienteAll_fluxo $cliente->getClienteAll()->getLogo();
  2928.                 
  2929.                 $cmd $clientS3->getCommand('GetObject', [
  2930.                 'Bucket' => 'arquivosdoc',
  2931.                 'Key'    => 'LOGO_CLIENTES/'$clienteAll_fluxo
  2932.                 ]);
  2933.                 
  2934.                 $req $clientS3->createPresignedRequest($cmd'+30 minutes');
  2935.                 $cliente_all_Url = (string) $req->getUri();
  2936.                 
  2937.                 $clienteAll_fluxo_id $cliente->getClienteAll()->getId();
  2938.                 $fluxo_caixas $doctrine->getRepository(Caixa::class)->findByFluxoWithRelations($fluxo_pdf->getId());
  2939.                 if($clienteAll_fluxo_id == 39){
  2940.                     $html '
  2941.                     <!DOCTYPE html>
  2942.                     <html lang="pt-BR">
  2943.                     <head>
  2944.                         <meta charset="UTF-8">
  2945.                         <meta name="viewport" content="width=device-width, initial-scale=1.0">
  2946.                         <title>FLUXO</title>
  2947.                         <style>
  2948.                             * { margin: 0; padding: 0; font-family: Calibri, Arial, sans-serif; }
  2949.                             body { text-transform: uppercase; }
  2950.                             .filho { border: 2px solid black; width: 67.8mm; height: 145mm; display: inline-block; margin: 0px 2px 2px 2px; position: relative; }
  2951.                             h2 { text-align: center; font-size: 30px; padding: 5px; }
  2952.                             h2 img{width: 250px; height: 250px;}
  2953.                             h4 { text-align: center; font-size: 14px; padding: 10px; }
  2954.                             h5 { text-align: center; font-size: 16px;}
  2955.                             h6 { text-align: center; font-size: 18px; padding: 20px; }
  2956.                             h5 img { text-align: center;max-height: 40px;width:auto;max-width: 40px}
  2957.                             h6 img { text-align: center;margin:auto;  max-height: 200px;width:auto;max-width: 200px}
  2958.                             p { text-align: center; font-size: 12px; font-weight: bold;}
  2959.                             .pai { position: relative; top: 11%; }
  2960.                             hr { color: black; }
  2961.                             .lis2{
  2962.                                         
  2963.                                 font-weight: bold;
  2964.                                 margin:5px;
  2965.                             }
  2966.                             .lis3 {
  2967.                                 position: absolute;
  2968.                                 bottom: 0;
  2969.                                 width: 100%;
  2970.                                 font-weight: bold;
  2971.                                 text-align: center;
  2972.                                 margin-bottom:5px;
  2973.                                 margin-top:5px;
  2974.                             }
  2975.                             .lis{
  2976.                                 
  2977.                                 margin-left:10px;
  2978.                                 font-weight: bold;
  2979.                             }
  2980.                             li{
  2981.                                 margin:10px;
  2982.                                 font-size: 18px;
  2983.                             }
  2984.                             
  2985.                         </style>
  2986.                     </head>
  2987.                     <body>
  2988.                     <div class="pai">';
  2989.             
  2990.                     $count 0;
  2991.             
  2992.                     foreach ($fluxo_caixas as $caixa) {
  2993.                         $count++;
  2994.                         $documento_fluxo $caixa->getDocumentos()->toArray();
  2995.                         
  2996.                         
  2997.                         $html .= '<div class="filho">
  2998.                             
  2999.                             
  3000.                             <h6><img src="'.$cliente_all_Url.'" class="img"></h6>
  3001.                             <hr>
  3002.                             <h2>' htmlspecialchars($caixa->getNome()) . '</h2>
  3003.                             <hr>
  3004.                             ';
  3005.             
  3006.                         $docs = [];
  3007.                         
  3008.                         if (!empty($documento_fluxo)) {
  3009.                             foreach ($documento_fluxo as $doc) {
  3010.                                 if($doc->getTipo() != NULL ){
  3011.                                     if ($cliente_id != 122) {
  3012.                                         $docs[] = $doc->getTipo()->getNome();
  3013.                                     } else {
  3014.                                         $docs[] = $doc->getNome();
  3015.                                     }
  3016.                                 }
  3017.                             }
  3018.                             $docs array_unique($docs);
  3019.                         }
  3020.                         
  3021.                         $docs_class = [];
  3022.                         
  3023.                         if (!empty($documento_fluxo)) {
  3024.                             foreach ($documento_fluxo as $doc) {
  3025.                                 
  3026.                                 if($doc->getClassificacao() != NULL ){
  3027.                                     $clss =  $entityManager->getRepository(Classificacao::class)->findBy(['id' => $doc->getClassificacao()->getId()]);
  3028.                                     $class_nome =  $clss[0]->getNome();
  3029.                                     $docs_class[] = $class_nome;
  3030.                                     
  3031.                                 }
  3032.                             }
  3033.                             $docs_class array_unique($docs_class);
  3034.                         }
  3035.                         $docs_data = [];
  3036.                         $mapa = [];
  3037.                         if (!empty($documento_fluxo)) {
  3038.                             foreach ($documento_fluxo as $data) {
  3039.                                 if ($data->getNome() != null) {
  3040.                                     $docs_data[] = $data->getNome();
  3041.                                 }
  3042.                             }
  3043.                             $docs_data array_unique($docs_data);
  3044.                         }
  3045.                         $numeros = [];
  3046.                         foreach ($docs_data as $doc) {
  3047.                             if (preg_match('/PL-(\d+)/'$doc$matches)) {
  3048.                                 $numero = (int) $matches[1];
  3049.                                 $numeros[] = $numero;
  3050.                                 $mapa[$numero] = $doc// ✅ CORRETO
  3051.                             }
  3052.                         }
  3053.                         if (!empty($numeros)) {
  3054.                             $menor min($numeros);
  3055.                             $maior max($numeros);
  3056.                             $menorNome $mapa[$menor];
  3057.                             $maiorNome $mapa[$maior];
  3058.                         } else {
  3059.                             $menor null;
  3060.                             $maior null;
  3061.                             $menorNome null;
  3062.                             $maiorNome null;
  3063.                         }
  3064.                         /* Sequência completa e faltantes */
  3065.                         $sequenciaCompleta range($menor$maior);
  3066.                         $faltantes array_diff($sequenciaCompleta$numeros);
  3067.                         /* Nomes faltantes */
  3068.                         $docs_faltantes = [];
  3069.                         
  3070.                         if($docs_faltantes != []){
  3071.                             foreach ($faltantes as $num) {
  3072.                                 $docs_faltantes[] = 'PL_' str_pad($num3'0'STR_PAD_LEFT);
  3073.                             }
  3074.                         }
  3075.                         
  3076.                                                     
  3077.                         
  3078.                         
  3079.                         $html .= '<h6>' htmlspecialchars(implode(', '$docs)) . '</h6>
  3080.                             <hr>';
  3081.                             
  3082.                             $html .= '<h6>Conteúdo:</h6>';
  3083.                             $html .= '<div class="lis">';
  3084.                             foreach ($docs_class as $classs_nome) {
  3085.                             $html .= '
  3086.                                 <li>' $classs_nome'</li>';
  3087.                             }
  3088.                             $html .= '</div>';
  3089.                             $html .= '<h6>'.$menorNome.' Até '.$maiorNome.'</h6>';
  3090.                             if($docs_faltantes != []){
  3091.                                 $html .= '<div class="lis2"><p>';
  3092.                                     
  3093.                                         foreach ($docs_faltantes as $data) {
  3094.                                             $html .= 'Faltantes*: | ' $data' | ';
  3095.                                         }
  3096.                                     
  3097.                                 $html .= '</p></div>';
  3098.                             }
  3099.                             /*$html .= '
  3100.                                     <div class="lis3"><hr>
  3101.                                     
  3102.                                     <p>ARQUIVOS GESTÃO DOCUMENTAL</p>
  3103.                                     <h5><img src="https://index.arquivosdoc.com.br/img/logo_menu.png" class="img"></h5>
  3104.                                     </div>
  3105.                                     
  3106.                                 </div>';*/
  3107.                             
  3108.                             $html .= '</div>';
  3109.             
  3110.                         if ($count %  == 0) {
  3111.                             $html .= '<div style="page-break-after: always;"></div>';
  3112.                         }
  3113.                     }
  3114.             
  3115.                     $html .= '</div></body></html>';
  3116.                 }
  3117.                 
  3118.                 if($clienteAll_fluxo_id == 41){
  3119.                      $html '
  3120.                             <!DOCTYPE html>
  3121.                             <html lang="pt-BR">
  3122.                             <head>
  3123.                                 <meta charset="UTF-8">
  3124.                                 <meta name="viewport" content="width=device-width, initial-scale=1.0">
  3125.                                 <title>FLUXO</title>
  3126.                                 <style>
  3127.                                     * { margin: 0; padding: 0; font-family: Calibri, Arial, sans-serif; }
  3128.                                     body { text-transform: uppercase; }
  3129.                                     .filho { border: 2px solid black; width: 50mm; height: 144mm; display: inline-block; margin: 2px; position: relative;}
  3130.                                     h2 { text-align: center; font-size: 20px; padding: 5px; }
  3131.                                     h2 img{width: 250px; height: 250px;}
  3132.                                     h4 { text-align: center; font-size: 12px; padding: 10px; }
  3133.                                     h5 { text-align: center; font-size: 14px;}
  3134.                                     h6 { text-align: center; font-size: 14px; padding: 5px; }
  3135.                                     h5 img { text-align: center;max-height: 40px;width:auto;max-width: 40px}
  3136.                                     h6 img { text-align: center;margin:auto;  max-height: 130px;width:auto;max-width: 130px}
  3137.                                     p { text-align: center; font-size: 8px; font-weight: bold;}
  3138.                                     .pai { position: relative; top: 11%; }
  3139.                                     hr { color: black; }
  3140.                                     .lis2{
  3141.                                         
  3142.                                         font-weight: bold;
  3143.                                     }
  3144.                                     .lis3 {
  3145.                                         position: absolute;
  3146.                                         bottom: 0;
  3147.                                         width: 100%;
  3148.                                         font-weight: bold;
  3149.                                         text-align: center;
  3150.                                         margin-bottom:5px;
  3151.                                         margin-top:5px;
  3152.                                            
  3153.                                     }
  3154.                                     .lis{
  3155.                                         
  3156.                                         margin-left:10px;
  3157.                                         font-weight: bold;
  3158.                                     }
  3159.                                     li{
  3160.                                        font-size: 12px;
  3161.                                        margin-left:2px;
  3162.                                     }
  3163.                                     
  3164.                                 </style>
  3165.                             </head>
  3166.                             <body>
  3167.                             <div class="pai">';
  3168.             
  3169.                     $count 0;
  3170.             
  3171.                     
  3172.                             foreach ($fluxo_caixas as $caixa) {
  3173.                                 $count++;
  3174.                                 $documento_fluxo $caixa->getDocumentos()->toArray();
  3175.                                 
  3176.                     
  3177.                                 $html .= '<div class="filho">
  3178.                                     
  3179.                                     
  3180.                                     <h6><img src="'.$cliente_all_Url.'" class="img"></h6>
  3181.                                     <hr>
  3182.                                     <h2>' htmlspecialchars($caixa->getNome()) . '</h2>
  3183.                                     <hr>
  3184.                                     ';
  3185.                     
  3186.                                 $docs = [];
  3187.                                 
  3188.                                 if (!empty($documento_fluxo)) {
  3189.                                     foreach ($documento_fluxo as $doc) {
  3190.                                         if($doc->getTipo() != NULL ){
  3191.                                             if ($cliente_id != 122) {
  3192.                                                 $docs[] = $doc->getTipo()->getNome();
  3193.                                             } else {
  3194.                                                 $docs[] = $doc->getNome();
  3195.                                             }
  3196.                                         }
  3197.                                     }
  3198.                                     $docs array_unique($docs);
  3199.                                 }
  3200.                                 
  3201.                                 
  3202.     
  3203.     
  3204.                                 $docs_class = [];
  3205.                                 
  3206.                                 if (!empty($documento_fluxo)) {
  3207.                                     foreach ($documento_fluxo as $doc) {
  3208.                                         
  3209.                                         if($doc->getClassificacao() != NULL ){
  3210.                                            $clss =  $entityManager->getRepository(Classificacao::class)->findBy(['id' => $doc->getClassificacao()->getId()]);
  3211.                                            $class_nome =  $clss[0]->getNome();
  3212.                                            $docs_class[] = $class_nome;
  3213.                                             
  3214.                                         }
  3215.                                     }
  3216.                                     $docs_class array_unique($docs_class);
  3217.                                 }
  3218.                     
  3219.     
  3220.                                   $docs_data = [];
  3221.                                   if (!empty($documento_fluxo)) {
  3222.                                         foreach ($documento_fluxo as $data) {
  3223.                                             if ($data->getAssunto() !== null) {
  3224.                                                 $docs_data[] = $data->getAssunto();
  3225.                                             }
  3226.                                         }
  3227.                                         $docs_data array_unique($docs_data);
  3228.                                     }
  3229.                                 
  3230.                               
  3231.     
  3232.                                 
  3233.     
  3234.     
  3235.                                                             
  3236.                                 
  3237.                                 
  3238.                                 $html .= '<h6>' htmlspecialchars(implode(', '$docs)) . '</h6>
  3239.                                     <hr>';
  3240.                                    
  3241.     
  3242.     
  3243.                                     $html .= '<h6>Conteúdo:</h6>';
  3244.     
  3245.                                     $html .= '<div class="lis">';
  3246.                                     foreach ($docs_class as $classs_nome) {
  3247.                                     if($classs_nome == '028.11-COM ÔNUS'){
  3248.                                      $html .= '<li>SOLICITAÇÃO DE DIÁRIAS</li>';
  3249.                                     }
  3250.                                     $html .= '
  3251.                                         <li>' $classs_nome'</li>';
  3252.                                     }
  3253.                                     $html .= '</div><br>';
  3254.                                     $html .= '<h6>Descrição:</h6>';
  3255.                                     $html .= '<div class="lis">';
  3256.                                     $len count($docs_data);
  3257.                                     foreach ($docs_data as $assunto_nome) {
  3258.                                         
  3259.                                     $qtd_letra mb_strlen($assunto_nome'UTF-8');
  3260.                                      
  3261.                                     if ($len <= 20) {
  3262.                                         $fontSize 12;
  3263.                                     } 
  3264.                                     
  3265.                                     else{
  3266.                                         $fontSize 9;
  3267.                                     }
  3268.                                     if($qtd_letra 25 ){
  3269.                                         $fontSize 10;
  3270.                                     }
  3271.                                     $html .= '<li style="font-size: ' $fontSize 'px;">' $assunto_nome'</li>';
  3272.                                     }
  3273.                                     $html .= '</div><br>
  3274.                                     <div class="lis3"><hr>
  3275.                                     
  3276.                                     <p>ARQUIVOS GESTÃO DOCUMENTAL</p>
  3277.                                     <h5><img src="https://index.arquivosdoc.com.br/img/logo_menu.png" class="img"></h5>
  3278.                                     </div>
  3279.                                     
  3280.                                 </div>';
  3281.                     
  3282.                                 #if ($count == 4) {
  3283.                                  #   $html .= '<div style="page-break-after: always;"></div>';
  3284.                                 #}
  3285.                             }
  3286.                    
  3287.     
  3288.                     
  3289.                     
  3290.             
  3291.     
  3292.                     $html .= '</div></body></html>';
  3293.                 }
  3294.         
  3295.                 // Configurar o Dompdf
  3296.                 $options = new Options();
  3297.                 $options->set('isHtml5ParserEnabled'true);
  3298.                 $options->set('isPhpEnabled'true);
  3299.                 $options->set('isRemoteEnabled'true);
  3300.                 $dompdf = new Dompdf($options);
  3301.                 $dompdf->loadHtml($html);
  3302.                 $dompdf->setPaper('A4''portrait');
  3303.         
  3304.                 // LIMPA TODOS OS BUFFERS ANTES DE RENDERIZAR
  3305.                 while (ob_get_level()) {
  3306.                     ob_end_clean();
  3307.                 }
  3308.         
  3309.                 // Tenta renderizar e, em vez de stream() direto, grava em arquivo temporário e envia
  3310.                 try {
  3311.                     $dompdf->render();
  3312.                 } catch (Throwable $e) {
  3313.                     // registra o erro e lança para cair no catch externo
  3314.                     error_log('Dompdf render failed: ' $e->getMessage());
  3315.                     throw $e;
  3316.                 }
  3317.         
  3318.                 // Gera arquivo temporário seguro
  3319.                 $tempFile sys_get_temp_dir() . DIRECTORY_SEPARATOR 'etiqueta_fluxo_' $id_fluxo '_' uniqid() . '.pdf';
  3320.                 $output $dompdf->output();
  3321.         
  3322.                 if (file_put_contents($tempFile$output) === false) {
  3323.                     throw new Exception('Falha ao escrever arquivo temporário do PDF.');
  3324.                 }
  3325.         
  3326.                 // Força headers corretos para download/visualização
  3327.                 header('Content-Type: application/pdf');
  3328.                 // Se quiser forçar download use attachment; se quiser abrir no browser use inline
  3329.                 header('Content-Disposition: inline; filename="Etiqueta_Fluxo_' preg_replace('/[^A-Za-z0-9_\-\.]/''_'$id_fluxo '_' $nome_fluxo) . '.pdf"');
  3330.                 header('Content-Length: ' filesize($tempFile));
  3331.                 header('Cache-Control: private, max-age=0, must-revalidate');
  3332.         
  3333.                 // Envia o arquivo binário ao navegador
  3334.                 readfile($tempFile);
  3335.         
  3336.                 // Remove o arquivo temporário com segurança
  3337.                 @unlink($tempFile);
  3338.         
  3339.                 // finaliza execução
  3340.                 exit;
  3341.         
  3342.                 
  3343.        
  3344.         
  3345.         }
  3346.        
  3347.         
  3348.         return $this->render('index/index5.html.twig', [
  3349.             'clienteAll' => $cliente->getClienteAll()->getId(),
  3350.             'fluxos' => $fluxos,
  3351.             'p'=>$p,
  3352.             'erro'=>$erro,
  3353.             'pagina' => $pagina,
  3354.             'a' => $a,
  3355.              
  3356.         ]);
  3357.     }
  3358.     
  3359.     
  3360.     #[Route('/index/fluxo/diagrama/{id}'name'diagrama')]
  3361.     public function diagramaPaginatorInterface $paginator,Request $request,ManagerRegistry $doctrineEntityManagerInterface $entityManagerSessionInterface $sessionMailerInterface $mailer,$id): Response
  3362.     {
  3363.         $user_logado $this->getUser();
  3364.         $erro '';
  3365.         $pagina 'fluxo';
  3366.         $p ='';
  3367.         $clienteId $session->get('cliente_id');
  3368.         
  3369.         if($clienteId == null){
  3370.             
  3371.             return $this->redirectToRoute('home');
  3372.         }
  3373.         
  3374.         $fluxo_diagrama $doctrine->getRepository(Fluxo::class)->find($id);
  3375.         $fluxo_caixas_diagrama $doctrine->getRepository(Caixa::class)->findByFluxoWithRelations($fluxo_diagrama->getId());
  3376.             
  3377.  
  3378.     
  3379.         return $this->render('index/diagrama.html.twig', [
  3380.     
  3381.             'p'=>$p,
  3382.             'erro'=>$erro,
  3383.             'pagina' => $pagina,
  3384.             "fluxo_diagrama" => $fluxo_diagrama,
  3385.             "fluxo_caixas_diagrama" => $fluxo_caixas_diagrama
  3386.              
  3387.         ]);
  3388.     }
  3389.     #[Route('/index/recebimento/{id}'name'recebimento')]
  3390.     public function recebimentoPaginatorInterface $paginator,Request $request,ManagerRegistry $doctrineEntityManagerInterface $entityManagerSessionInterface $sessionMailerInterface $mailer,$id): Response
  3391.     {
  3392.         $user_logado $this->getUser();
  3393.         $user_nome $user_logado->getNome();
  3394.         $ip_cliente $_SERVER['REMOTE_ADDR'];
  3395.         $erro '';
  3396.         $pagina 'home';
  3397.         $p ='';
  3398.         $ged ""
  3399.         $log "";
  3400.         $caixa_manual "";
  3401.         $caixa_auto "";
  3402.         $cx_ultimo $doctrine->getRepository(Cx::class)->findUltimo();
  3403.         $etapa $doctrine->getRepository(Etapa::class)->findWithAllRelations($id);
  3404.         $fluxo $etapa->getFluxo();
  3405.         $cliente_fluxo $fluxo->getCliente()->getId();
  3406.         $clienteId $session->get('cliente_id');
  3407.         $cliente $doctrine->getRepository(Cliente::class)->findWithRelations($cliente_fluxo);
  3408.         $clienteAll =  $cliente->getClienteAll();
  3409.         $cliente_nome =  $cliente->getNome();
  3410.         $clienteAll_id =  $clienteAll->getId();
  3411.         $count 0// Contador de QR Codes
  3412.         $id_cx_ultimo 0;
  3413.         $date_hoje = new \DateTimeImmutable('America/Sao_Paulo');
  3414.         
  3415.         $caixas_setor $entityManager->getRepository(Cliente::class)->findCaixasByClienteId($cliente_fluxo);
  3416.         
  3417.         $query $entityManager->createQuery("
  3418.             SELECT c FROM App\Entity\Cx c
  3419.             LEFT JOIN c.caixas cx
  3420.             WHERE c.cliente = :clienteId
  3421.             AND cx.id IS NULL
  3422.         ");
  3423.         $query->setParameter('clienteId'$clienteAll_id);
  3424.         $cx_setor $query->getResult();
  3425.         foreach ($cx_ultimo as $key_id) {
  3426.             
  3427.             $id_cx_ultimo $key_id->getNome();
  3428.         }
  3429.         
  3430.         if(isset($_POST["btn_cliente"])){
  3431.             
  3432.             $session->set('cliente_id'$_POST["btn_cliente"]);
  3433.             return $this->redirectToRoute('home');
  3434.         }
  3435.         
  3436.         if($clienteId == null){
  3437.             
  3438.             return $this->redirectToRoute('home');
  3439.         }
  3440.         
  3441.         if ($request->isMethod('POST')) {
  3442.             
  3443.           
  3444.             
  3445.             if(isset($_POST["tipo"])){
  3446.                  $tp $_POST["tipo"];
  3447.                
  3448.                if($tp =='caixa'){
  3449.                    
  3450.                     if($_POST["qtd_caixa"] != ""){
  3451.     
  3452.     
  3453.                         if (isset($_POST["ged"]) || isset($_POST["log"])) {
  3454.     
  3455.                                 if (isset($_POST["ged"])) {
  3456.                                     
  3457.                                     $ged "ok";
  3458.     
  3459.                                     if (isset($_POST["caixa_manual"]) || isset($_POST["caixa_auto"])) {
  3460.     
  3461.                                         if (isset($_POST["caixa_manual"])) {
  3462.     
  3463.                                             $caixa_manual "ok";
  3464.             
  3465.                                         }
  3466.                                         if (isset($_POST["caixa_auto"])) {
  3467.     
  3468.                                             $caixa_auto "ok";
  3469.             
  3470.                                         }
  3471.     
  3472.                                     }else{
  3473.                                         echo "<script>alert('ERROR , Selecione o modo de Identificação do ArquivosGED (Manual ou Automático)!');</script>";
  3474.                                     }
  3475.             
  3476.                                 }
  3477.     
  3478.     
  3479.     
  3480.                                 if (isset($_POST["log"])) {
  3481.     
  3482.                                     $log "ok";
  3483.                                     
  3484.     
  3485.                                 }
  3486.     
  3487.                                 if ($ged == "ok" and $caixa_manual =="ok") {
  3488.     
  3489.                                     $caixa $_POST["caixa"];
  3490.                                     $qtd_caixas 0;
  3491.     
  3492.     
  3493.                                     $options = new Options();
  3494.                                     $options->set('isHtml5ParserEnabled'true);
  3495.                                     $options->set('isPhpEnabled'true);
  3496.                                     $dompdf = new Dompdf($options);
  3497.                         
  3498.                                     $html '
  3499.                                     <html>
  3500.                                         <head>
  3501.                                             <style>
  3502.                                                 @page {
  3503.                                                     margin: 35px 18.9px 0px 18.9px;
  3504.                                                     size: 210mm 297mm; /* Ajuste de tamanho do papel */
  3505.                                                 }
  3506.                         
  3507.                                                 body {
  3508.                                                     margin: 0;
  3509.                                                     padding: 0;
  3510.                                                 }
  3511.                                                 
  3512.                                                 .qr-item {
  3513.                                                     border: 2px dotted #000;
  3514.                                                     text-align: center;
  3515.                                                     width: 32.27mm;
  3516.                                                     height: 34.9mm; 
  3517.                                                     display: inline-block;
  3518.                                                 }
  3519.                                     
  3520.                                                 .qr-item img {
  3521.                                                     width: 115px; 
  3522.                                                     height: 112px;
  3523.                                                 }
  3524.                         
  3525.                                                 .qr-title {
  3526.                                                     font-size: 16px;
  3527.                                                     font-weight: bold;
  3528.                                                 }
  3529.                         
  3530.                                                 .leo {
  3531.                                                     display: flex;
  3532.                                                     flex-wrap: wrap;
  3533.                                                 }
  3534.                                             </style>
  3535.                                         </head>
  3536.                                         <body> 
  3537.                                       
  3538.                                     ';
  3539.                         
  3540.                         
  3541.                                     
  3542.                                     foreach ($caixa as $key) {
  3543.     
  3544.                                         if ($key != "" ) {
  3545.                                             $qtd_caixas ++ ;
  3546.                                             $caixas = new Caixa();
  3547.                                            
  3548.                                            
  3549.                                             if ($ged == "ok" and $log =="ok") {
  3550.                                                 
  3551.                                                 $cx = new Cx();
  3552.                                                 $id_cx_ultimo ++;
  3553.                                                 $cx->setNome($id_cx_ultimo);
  3554.                                                 $cx->setStatus(2);
  3555.                                                 $cx->setTexto($key);
  3556.                                                 $cx->setImage('ArquivosGED');
  3557.                                                 $cx->setCliente($clienteAll);
  3558.                                                 $entityManager->persist($cx);
  3559.                                                 $entityManager->flush();
  3560.     
  3561.                                                 $id_cx=$cx->getId();
  3562.                                                 $caixas->setCx($entityManager->getRepository(Cx::class)->find($id_cx));
  3563.     
  3564.                                                 // Gerar QR Code com imagem no centro
  3565.                                                 $result Builder::create()
  3566.                                                 ->writer(new PngWriter())
  3567.                                                 ->writerOptions([])
  3568.                                                 ->data('https://logistica.arquivosdoc.com.br/'.$clienteAll_id.'/'.$id_cx_ultimo)
  3569.                                                 ->encoding(new Encoding('UTF-8'))
  3570.                                                 ->size(500)
  3571.                                                 ->margin(5)
  3572.                                                 ->logoPath(__DIR__ '/logo.png'// Caminho do logo central
  3573.                                                 ->build();
  3574.                                                 // Salvar QR Code como arquivo temporário
  3575.                                                 $tempFile tempnam(sys_get_temp_dir(), 'qr_') . '.png';
  3576.                                                 $result->saveToFile($tempFile);
  3577.                                                 
  3578.                                                 // Adicionar QR Code ao HTML
  3579.                                                 if ($count 48 == 0) {
  3580.                                                     $html .= '<div class="leo">';
  3581.                                                 }
  3582.                                 
  3583.                                                 // Adicionar QR Code ao HTML
  3584.                                                 $html .= '<div class="qr-item">';
  3585.                                                 $html .= '<div class="qr-title">' $id_cx_ultimo '</div>';
  3586.                                                 $html .= '<img src="data:image/png;base64,' base64_encode(file_get_contents($tempFile)) . '">';
  3587.                                                 $html .= '</div>';
  3588.                                                 
  3589.                                                 
  3590.                                                  $count++;
  3591.     
  3592.                                                // Fechar a div e inserir quebra de página a cada 63 QR Codes
  3593.                                                if ($count 48 == 0) {
  3594.                                                    $html .= '</div><div style="page-break-after: always;"></div>';
  3595.                                                }
  3596.                                                 
  3597.                                             }
  3598.     
  3599.                                             
  3600.                                             $caixas->setNome($key);
  3601.                                             $caixas->addCliente($cliente);
  3602.                                             $caixas->setFluxo($fluxo);
  3603.                                             $entityManager->persist($caixas);
  3604.                                             $entityManager->flush();
  3605.                                             $id_caixa $caixas->getId();
  3606.                                             
  3607.                                                 
  3608.                                         }
  3609.                                     }
  3610.                                         if ($ged == "ok" and $log =="ok") {
  3611.                                             
  3612.                                               // Fechar qualquer div aberta sem completar 63 itens
  3613.                                              if ($count 48 != 0) {
  3614.                                                 $html .= '</div>';
  3615.                                             }
  3616.     
  3617.                                             $html .= '</div></body></html>';
  3618.                                 
  3619.                                             // Carregar o HTML e gerar o PDF
  3620.                                             $dompdf->loadHtml($html);
  3621.                                             $dompdf->setPaper([00210297], 'portrait'); // Configurar o tamanho de página para A4
  3622.                                             $dompdf->render();
  3623.                                             #file_put_contents('sample1.pdf', $dompdf->output());
  3624.                                             $dompdf->stream('dompdf', array('Attachment' => 0));
  3625.                                         }
  3626.     
  3627.                                             $registro = new Registro();
  3628.                                             $registro->setOperacao('RECEBIMENTO DE '.$qtd_caixas' CAIXA(S)'); 
  3629.                                             $registro->setUser($user_nome);
  3630.                                             $registro->setCliente($cliente_nome);
  3631.                                             $registro->setIp($ip_cliente);
  3632.                                             $entityManager->persist($registro);
  3633.                                             $entityManager->flush();
  3634.     
  3635.                                             $etapa->setRegistro($registro);
  3636.                                             $etapa->setObs($_POST["obs_caixa"]);
  3637.                                             $etapa->setUpdatedAt($date_hoje);
  3638.                                             $entityManager->flush();
  3639.                                             $erro 'ok';
  3640.                                             $p "Recbimento com sucesso";
  3641.                                     
  3642.     
  3643.                                 }
  3644.     
  3645.                                 if ($ged == "ok" and $caixa_auto =="ok") {
  3646.     
  3647.                                     
  3648.                                     if (isset($_POST["auto_ged"])) {
  3649.     
  3650.                                         $qtd_nome_caixa $_POST["qtd_caixa"];
  3651.                                         $nome_caixa_parti $_POST["auto_ged"];
  3652.                                         
  3653.     
  3654.     
  3655.     
  3656.                                         $options = new Options();
  3657.                                         $options->set('isHtml5ParserEnabled'true);
  3658.                                         $options->set('isPhpEnabled'true);
  3659.                                         $dompdf = new Dompdf($options);
  3660.                             
  3661.                                         $html '
  3662.                                         <html>
  3663.                                             <head>
  3664.                                                 <style>
  3665.                                                     @page {
  3666.                                                         margin: 35px 18.9px 0px 18.9px;
  3667.                                                         size: 210mm 297mm; /* Ajuste de tamanho do papel */
  3668.                                                     }
  3669.                             
  3670.                                                     body {
  3671.                                                         margin: 0;
  3672.                                                         padding: 0;
  3673.                                                     }
  3674.                                                     
  3675.                                                    .qr-item {
  3676.                                                     border: 2px dotted #000;
  3677.                                                     text-align: center;
  3678.                                                     width: 32.27mm;
  3679.                                                     height: 34.9mm; 
  3680.                                                     display: inline-block;
  3681.                                                 }
  3682.                                     
  3683.                                                 .qr-item img {
  3684.                                                     width: 115px; 
  3685.                                                     height: 112px;
  3686.                                                 }
  3687.                                     
  3688.                                                     .qr-title {
  3689.                                                         font-size: 16px;
  3690.                                                         font-weight: bold;
  3691.                                                     }
  3692.                             
  3693.                                                     .leo {
  3694.                                                         display: flex;
  3695.                                                         flex-wrap: wrap;
  3696.                                                     }
  3697.                                                 </style>
  3698.                                             </head>
  3699.                                             <body> 
  3700.                                               
  3701.                                         ';
  3702.                         
  3703.                         
  3704.     
  3705.     
  3706.                                         for ($i=0$i $qtd_nome_caixa$i++) { 
  3707.                                             
  3708.                                             $caixas = new Caixa();
  3709.     
  3710.                                             if ($ged == "ok" and $log =="ok") {
  3711.                                                 
  3712.                                                 $cx = new Cx();
  3713.                                                 $id_cx_ultimo ++;
  3714.                                                 $cx->setNome($id_cx_ultimo);
  3715.                                                 $cx->setStatus(2);
  3716.                                                 $cx->setTexto('Caixa '.$nome_caixa_parti);
  3717.                                                 $cx->setImage('ArquivosGED');
  3718.                                                 $cx->setCliente($clienteAll);
  3719.                                                 $entityManager->persist($cx);
  3720.                                                 $entityManager->flush();
  3721.     
  3722.                                                 $id_cx=$cx->getId();
  3723.                                                 $caixas->setCx($entityManager->getRepository(Cx::class)->find($id_cx));
  3724.     
  3725.                                                   // Gerar QR Code com imagem no centro
  3726.                                                 $result Builder::create()
  3727.                                                   ->writer(new PngWriter())
  3728.                                                   ->writerOptions([])
  3729.                                                   ->data('https://logistica.arquivosdoc.com.br/'.$clienteAll_id.'/'.$id_cx_ultimo)
  3730.                                                   ->encoding(new Encoding('UTF-8'))
  3731.                                                   ->size(500)
  3732.                                                   ->margin(5)
  3733.                                                   ->logoPath(__DIR__ '/logo.png'// Caminho do logo central
  3734.                                                   ->build();
  3735.                                                   // Salvar QR Code como arquivo temporário
  3736.                                                   $tempFile tempnam(sys_get_temp_dir(), 'qr_') . '.png';
  3737.                                                   $result->saveToFile($tempFile);
  3738.                                                     
  3739.                                                 // Adicionar QR Code ao HTML
  3740.                                                     if ($count 48 == 0) {
  3741.                                                         $html .= '<div class="leo">';
  3742.                                                     }    
  3743.                                                     
  3744.                                                   // Adicionar QR Code ao HTML
  3745.                                                   $html .= '<div class="qr-item">';
  3746.                                                   $html .= '<div class="qr-title">' $id_cx_ultimo '</div>';
  3747.                                                   $html .= '<img src="data:image/png;base64,' base64_encode(file_get_contents($tempFile)) . '">';
  3748.                                                   $html .= '</div>';
  3749.                                                   
  3750.                                                    $count++;
  3751.                                         
  3752.                                                    // Fechar a div e inserir quebra de página a cada 63 QR Codes
  3753.                                                    if ($count 48 == 0) {
  3754.                                                        $html .= '</div><div style="page-break-after: always;"></div>';
  3755.                                                    }
  3756.                                                 
  3757.                                             }
  3758.     
  3759.     
  3760.                                             $caixas->setNome('Caixa '.$nome_caixa_parti);
  3761.                                             $caixas->addCliente($cliente);
  3762.                                             $caixas->setFluxo($fluxo);
  3763.                                             $entityManager->persist($caixas);
  3764.                                             $entityManager->flush();
  3765.                                             $nome_caixa_parti++;
  3766.                                             
  3767.     
  3768.                                         }
  3769.     
  3770.                                         if ($ged == "ok" and $log =="ok") {
  3771.                                     
  3772.                                              // Fechar qualquer div aberta sem completar 63 itens
  3773.                                              if ($count 48 != 0) {
  3774.                                                 $html .= '</div>';
  3775.                                             }
  3776.                                             
  3777.                                             $html .= '</div></body></html>';
  3778.                                     
  3779.                                             // Carregar o HTML e gerar o PDF
  3780.                                             $dompdf->loadHtml($html);
  3781.                                             $dompdf->setPaper([00210297], 'portrait'); // Configurar o tamanho de página para A4
  3782.                                             $dompdf->render();
  3783.                                             #file_put_contents('sample1.pdf', $dompdf->output());
  3784.                                             $dompdf->stream('dompdf', array('Attachment' => 0));
  3785.                                         }    
  3786.     
  3787.                                         $registro = new Registro();
  3788.                                         $registro->setOperacao('RECEBIMENTO DE '.$qtd_nome_caixa' CAIXA(S)'); 
  3789.                                         $registro->setUser($user_nome);
  3790.                                         $registro->setCliente($cliente_nome);
  3791.                                         $registro->setIp($ip_cliente);
  3792.                                         $entityManager->persist($registro);
  3793.                                         $entityManager->flush();
  3794.                                         
  3795.                                         $etapa->setUpdatedAt($date_hoje);
  3796.                                         $etapa->setRegistro($registro);
  3797.                                         $entityManager->flush();
  3798.     
  3799.                                         $erro 'ok';
  3800.                                         $p "Recbimento com sucesso";
  3801.                                         
  3802.                                     }
  3803.     
  3804.                                 }
  3805.     
  3806.     
  3807.     
  3808.                                 if ($ged != "ok" and $log =="ok") {
  3809.                                     
  3810.                                     $qtd_caixa_ $_POST["qtd_caixa"];
  3811.                                     $options = new Options();
  3812.                                     $options->set('isHtml5ParserEnabled'true);
  3813.                                     $options->set('isPhpEnabled'true);
  3814.                                     $dompdf = new Dompdf($options);
  3815.                             
  3816.                                         $html '
  3817.                                         <html>
  3818.                                             <head>
  3819.                                                 <style>
  3820.                                                     @page {
  3821.                                                         margin: 35px 18.9px 0px 18.9px;
  3822.                                                         size: 210mm 297mm; /* Ajuste de tamanho do papel */
  3823.                                                     }
  3824.                             
  3825.                                                     body {
  3826.                                                         margin: 0;
  3827.                                                         padding: 0;
  3828.                                                     }
  3829.                                                     
  3830.                                                     .qr-item {
  3831.                                                         border: 2px dotted #000;
  3832.                                                         text-align: center;
  3833.                                                         width: 27.5mm;
  3834.                                                         height: 30.5mm; 
  3835.                                                         display: inline-block;
  3836.                                                     }
  3837.                             
  3838.                                                     .qr-item img {
  3839.                                                         width: 105px; 
  3840.                                                         height: 100px;
  3841.                                                     }
  3842.                             
  3843.                                                     .qr-title {
  3844.                                                         font-size: 16px;
  3845.                                                         font-weight: bold;
  3846.                                                     }
  3847.                             
  3848.                                                     .leo {
  3849.                                                         display: flex;
  3850.                                                         flex-wrap: wrap;
  3851.                                                     }
  3852.                                                 </style>
  3853.                                             </head>
  3854.                                             <body> 
  3855.                                                 <div class="leo">    
  3856.                                         ';
  3857.     
  3858.     
  3859.     
  3860.                                     for ($i=0$i $qtd_caixa_$i++) { 
  3861.                                             
  3862.                                                 $id_cx_ultimo ++;
  3863.                                                 // Gerar QR Code com imagem no centro
  3864.                                             $result Builder::create()
  3865.                                                 ->writer(new PngWriter())
  3866.                                                 ->writerOptions([])
  3867.                                                 ->data('https://logistica.arquivosdoc.com.br/'.$clienteAll_id.'/'.$id_cx_ultimo)
  3868.                                                 ->encoding(new Encoding('UTF-8'))
  3869.                                                 ->size(300)
  3870.                                                 ->margin(10)
  3871.                                                 ->logoPath(__DIR__ '/logo.png'// Caminho do logo central
  3872.                                                 ->build();
  3873.                                                 // Salvar QR Code como arquivo temporário
  3874.                                                 $tempFile tempnam(sys_get_temp_dir(), 'qr_') . '.png';
  3875.                                                 $result->saveToFile($tempFile);
  3876.                                 
  3877.                                                 // Adicionar QR Code ao HTML
  3878.                                                 $html .= '<div class="qr-item">';
  3879.                                                 $html .= '<div class="qr-title">' $id_cx_ultimo '</div>';
  3880.                                                 $html .= '<img src="data:image/png;base64,' base64_encode(file_get_contents($tempFile)) . '">';
  3881.                                                 $html .= '</div>';
  3882.                                     }
  3883.                                     
  3884.                                     $html .= '</div></body></html>';
  3885.                             
  3886.                                     // Carregar o HTML e gerar o PDF
  3887.                                     $dompdf->loadHtml($html);
  3888.                                     $dompdf->setPaper([00210297], 'portrait'); // Configurar o tamanho de página para A4
  3889.                                     $dompdf->render();
  3890.                                     file_put_contents('sample1.pdf'$dompdf->output());
  3891.                                     $dompdf->stream('dompdf', array('Attachment' => 1));
  3892.     
  3893.     
  3894.                                     $registro = new Registro();
  3895.                                     $registro->setOperacao('RECEBIMENTO DE '.$qtd_caixa_' CAIXA(S)'); 
  3896.                                     $registro->setUser($user_nome);
  3897.                                     $registro->setCliente($cliente_nome);
  3898.                                     $registro->setIp($ip_cliente);
  3899.                                     $entityManager->persist($registro);
  3900.                                     $entityManager->flush();
  3901.                                     
  3902.                                     $etapa->setUpdatedAt($date_hoje);
  3903.                                     $etapa->setRegistro($registro);
  3904.                                     $entityManager->flush();
  3905.     
  3906.                                     $erro 'ok';
  3907.                                     $p "Recbimento com sucesso";
  3908.     
  3909.     
  3910.                                 }
  3911.     
  3912.     
  3913.     
  3914.     
  3915.                             } else {
  3916.     
  3917.                             echo "<script>alert('ERROR , Selecione a Identificação!');</script>";
  3918.                         }
  3919.                          
  3920.                     }else {
  3921.                         echo "<script>alert('ERROR , Selecione a Quantidade!');</script>";
  3922.                     }
  3923.                }
  3924.                
  3925.                 if($tp =='doc'){
  3926.                     if(isset($_POST["check_cx_e"])){
  3927.                         $yz "yes";
  3928.                         $checkBoxes $request->request->all('inputs_cx_e');
  3929.                         $xy 0;
  3930.                         $qtd_caixas=0;
  3931.                         
  3932.       
  3933.                         foreach ($checkBoxes as $id => $nome) {
  3934.                             $cx_ $doctrine->getRepository(Cx::class)->find($id);
  3935.                             $_nome =  $cx_->getNome();
  3936.                            
  3937.                             if ($nome =="") {
  3938.                                
  3939.                                 echo "<script>alert('ERROR, Digite no campo gerado acima da tabela qual será repositorio do  ID: $_nome!');</script>";
  3940.                             }
  3941.                             if ($nome != "" ) {
  3942.                                 $id_cx_ultimo $_nome ;
  3943.                                 $qtd_caixas++;
  3944.                                 $xy 1;
  3945.                                 $caixas = new Caixa();
  3946.                                 $caixas->setNome($nome);
  3947.                                 $caixas->addCliente($cliente);
  3948.                                 $caixas->setFluxo($fluxo);
  3949.                                 $caixas->setCx($cx_);
  3950.                                 $entityManager->persist($caixas);
  3951.                                 $entityManager->flush();
  3952.                                 $registro = new Registro();
  3953.                                 $registro->setOperacao('RECEBIMENTO DA ID EXISTENTE '.$_nome); 
  3954.                                 $registro->setUser($user_nome);
  3955.                                 $registro->setCliente($cliente_nome);
  3956.                                 $registro->setIp($ip_cliente);
  3957.                                 $entityManager->persist($registro);
  3958.                                 $entityManager->flush();
  3959.                                 
  3960.                                 
  3961.                                 
  3962.                             }
  3963.                             
  3964.                         }
  3965.                        
  3966.                         if($xy==1){
  3967.                             $etapa->setRegistro($registro);
  3968.                             $etapa->setObs($_POST["obs_caixa"]);
  3969.                             $etapa->setUpdatedAt($date_hoje);
  3970.                             $entityManager->flush();
  3971.                             
  3972.                             $registro = new Registro();
  3973.                             $registro->setOperacao('RECEBIMENTO DE  '.$qtd_caixas' CAIXA(S) '); 
  3974.                             $registro->setUser($user_nome);
  3975.                             $registro->setCliente($cliente_nome);
  3976.                             $registro->setIp($ip_cliente);
  3977.                             $entityManager->persist($registro);
  3978.                             $entityManager->flush();
  3979.                             $erro 'ok';
  3980.                             $p "Recbimento com sucesso";
  3981.                         }
  3982.                       
  3983.                     }else{
  3984.                         $zy "not";
  3985.                     }
  3986.                     if(isset($_POST["check_caixa_e"])){
  3987.                         $zy "yes";
  3988.                         $options = new Options();
  3989.                         $options->set('isHtml5ParserEnabled'true);
  3990.                         $options->set('debugKeepTemp'true);
  3991.                         $options->set('isPhpEnabled'true);
  3992.                         $dompdf = new Dompdf($options);
  3993.                         
  3994.                         $html '
  3995.                                     <html>
  3996.                                         <head>
  3997.                                             <style>
  3998.                                                 @page {
  3999.                                                     margin: 35px 18.9px 0px 18.9px;
  4000.                                                     size: 210mm 297mm; /* Ajuste de tamanho do papel */
  4001.                                                 }
  4002.                         
  4003.                                                 body {
  4004.                                                     margin: 0;
  4005.                                                     padding: 0;
  4006.                                                 }
  4007.                                                 
  4008.                                                 .qr-item {
  4009.                                                     border: 2px dotted #000;
  4010.                                                     text-align: center;
  4011.                                                     width: 32.27mm;
  4012.                                                     height: 34.9mm; 
  4013.                                                     display: inline-block;
  4014.                                                 }
  4015.                                     
  4016.                                                 .qr-item img {
  4017.                                                     width: 115px; 
  4018.                                                     height: 112px;
  4019.                                                 }
  4020.                         
  4021.                                                 .qr-title {
  4022.                                                     font-size: 16px;
  4023.                                                     font-weight: bold;
  4024.                                                 }
  4025.                         
  4026.                                                 .leo {
  4027.                                                     display: flex;
  4028.                                                     flex-wrap: wrap;
  4029.                                                 }
  4030.                                             </style>
  4031.                                         </head>
  4032.                                         <body> 
  4033.                                     
  4034.                                     ';
  4035.                         
  4036.                         $ckeck $_POST["caixa_e"];
  4037.                         $xy 0;
  4038.                         $qtd_caixas=0;
  4039.                 
  4040.                         foreach ($ckeck as $key) {
  4041.                             $nome_k NULL;
  4042.                             $caixa_k $doctrine->getRepository(Caixa::class)->find($key);
  4043.                             if($caixa_k != NULL ){
  4044.                                 $nome_k $caixa_k->getNome();
  4045.                             }
  4046.                             
  4047.                             if ($clienteAll_id != 18) {
  4048.                             
  4049.                                 $cx = new Cx();
  4050.                                 $id_cx_ultimo ++;
  4051.                                 $cx->setNome($id_cx_ultimo);
  4052.                                 $cx->setStatus(2);
  4053.                                 $cx->setTexto($nome_k);
  4054.                                 $cx->setImage('ArquivosGED');
  4055.                                 $cx->setCliente($clienteAll);
  4056.                                 $entityManager->persist($cx);
  4057.                                 $entityManager->flush();
  4058.                                 $caixa_k->setCx($cx);
  4059.                                 
  4060.                             }
  4061.                             
  4062.                             $caixa_k->setFluxo($fluxo);
  4063.                             $entityManager->flush();
  4064.                             $registro = new Registro();
  4065.                             $registro->setOperacao('RECEBIMENTO DA CAIXA EXISTENTE '.$nome_k); 
  4066.                             $registro->setUser($user_nome);
  4067.                             $registro->setCliente($cliente_nome);
  4068.                             $registro->setIp($ip_cliente);
  4069.                             $entityManager->persist($registro);
  4070.                             $entityManager->flush();
  4071.                             // Gerar QR Code com imagem no centro
  4072.                             $result Builder::create()
  4073.                              ->writer(new PngWriter())
  4074.                              ->writerOptions([])
  4075.                              ->data('https://logistica.arquivosdoc.com.br/'.$clienteAll_id.'/'.$id_cx_ultimo)
  4076.                              ->encoding(new Encoding('UTF-8'))
  4077.                              ->size(500)
  4078.                              ->margin(5)
  4079.                              ->logoPath(__DIR__ '/logo.png'// Caminho do logo central
  4080.                              ->build();
  4081.                              // Salvar QR Code como arquivo temporário
  4082.                              $tempFile tempnam(sys_get_temp_dir(), 'qr_') . '.png';
  4083.                              $result->saveToFile($tempFile);
  4084.                              
  4085.                              // Adicionar QR Code ao HTML
  4086.                              if ($count 48 == 0) {
  4087.                                  $html .= '<div class="leo">';
  4088.                              }
  4089.              
  4090.                              // Adicionar QR Code ao HTML
  4091.                              $html .= '<div class="qr-item">';
  4092.                              $html .= '<div class="qr-title">' $id_cx_ultimo '</div>';
  4093.                              $html .= '<img src="data:image/png;base64,' base64_encode(file_get_contents($tempFile)) . '">';
  4094.                              $html .= '</div>';
  4095.                              
  4096.                              
  4097.                              $count++;
  4098.                             // Fechar a div e inserir quebra de página a cada 63 QR Codes
  4099.                             if ($count 48 == 0) {
  4100.                                 $html .= '</div><div style="page-break-after: always;"></div>';
  4101.                             }
  4102.                              
  4103.                             
  4104.                         }
  4105.                         // Fechar qualquer div aberta sem completar 63 itens
  4106.                         if ($count 48 != 0) {
  4107.                             $html .= '</div>';
  4108.                         }
  4109.                          
  4110.                         $html .= '</div></body></html>';
  4111.                         
  4112.                         if ($clienteAll_id != 18) {  
  4113.                             // Carregar o HTML e gerar o PDF
  4114.                             $dompdf->loadHtml($html);
  4115.                             $dompdf->setPaper([00210297], 'portrait'); // Configurar o tamanho de página para A4
  4116.                             $dompdf->render();
  4117.                             #file_put_contents('sample1.pdf', $dompdf->output());
  4118.                             $dompdf->stream('dompdf', array('Attachment' => 0));
  4119.                         }
  4120.                         if($xy==1){
  4121.                             $etapa->setRegistro($registro);
  4122.                             $etapa->setUpdatedAt($date_hoje);
  4123.                             $etapa->setObs($_POST["obs_caixa"]);
  4124.                             $entityManager->flush();
  4125.                             
  4126.                             $registro = new Registro();
  4127.                             $registro->setOperacao('RECEBIMENTO DE  '.$qtd_caixas' CAIXA(S) '); 
  4128.                             $registro->setUser($user_nome);
  4129.                             $registro->setCliente($cliente_nome);
  4130.                             $registro->setIp($ip_cliente);
  4131.                             $entityManager->persist($registro);
  4132.                             $entityManager->flush();
  4133.                             $erro 'ok';
  4134.                             $p "Recbimento com sucesso";
  4135.                         }
  4136.                       
  4137.                     }else{
  4138.                         $yz "not";
  4139.                     }
  4140.                     if ($yz == "not" and $zy="not") {
  4141.                         echo "<script>alert('ERROR , Preencha corretamente o formulario, está sem valor , selecione todas as opções necessaria!');</script>";
  4142.                     }
  4143.                    
  4144.                 }
  4145.                
  4146.                
  4147.                
  4148.                
  4149.             }else {
  4150.                 echo "<script>alert('ERROR , Selecione o tipo!');</script>";
  4151.             }
  4152.             
  4153.         }
  4154.         return $this->render('index/recebimento.html.twig', [
  4155.     
  4156.             
  4157.             'p'=>$p,
  4158.             'erro'=>$erro,
  4159.             'pagina' => $pagina,
  4160.             'etapa'=>$etapa,
  4161.             'caixas_setor' => $caixas_setor,
  4162.             'cx_setor' => $cx_setor
  4163.             
  4164.             
  4165.         ]);
  4166.     }
  4167.     #[Route('/index/higienizacao/{id}'name'higienizacao')]
  4168.     public function higienizacaoPaginatorInterface $paginator,Request $request,ManagerRegistry $doctrineEntityManagerInterface $entityManagerSessionInterface $sessionMailerInterface $mailer,$id): Response
  4169.     {
  4170.         $user_logado $this->getUser();
  4171.         $user_nome $user_logado->getNome();
  4172.         $date_hoje = new \DateTimeImmutable('America/Sao_Paulo');
  4173.         $ip_cliente $_SERVER['REMOTE_ADDR'];
  4174.         $erro '';
  4175.         $pagina 'home';
  4176.         $p ='';
  4177.         $a ;
  4178.         $clienteAll null;
  4179.         $cx null;
  4180.         $caixa null
  4181.         $etapa $doctrine->getRepository(Etapa::class)->findWithAllRelations($id);
  4182.         $fluxo $etapa->getFluxo();
  4183.         $etapa_caixas $etapa->getCaixa()->toArray();
  4184.         $fluxo_caixas $doctrine->getRepository(Caixa::class)->findByFluxoWithRelations($fluxo->getId());
  4185.        
  4186.         $e 0;
  4187.         $f 0;
  4188.         $clienteId $session->get('cliente_id');
  4189.         if($clienteId == null){
  4190.             
  4191.             return $this->redirectToRoute('home');
  4192.         }
  4193.         
  4194.         
  4195.         foreach ($etapa_caixas as $key) {
  4196.             $e++;
  4197.         }
  4198.         foreach ($fluxo_caixas as $key) {
  4199.             $f++;
  4200.         }
  4201.         if(isset($_POST["a"])){
  4202.             $a 2;
  4203.         }
  4204.         
  4205.         $qrCodeData $request->request->get('qrcode');
  4206.         if(isset($_POST["id_caixas"])){
  4207.             $a ;
  4208.             $caixa $doctrine->getRepository(Caixa::class)->findBy(['id' => $_POST["id_caixas"]]);
  4209.             
  4210.             foreach ($caixa as $key) { $caixa_cx_id $key->getClientes()->toArray();}
  4211.             
  4212.             $cx =  $caixa_cx_id ;
  4213.             
  4214.             foreach ($cx as $key) {$cliente_cx_id $key->getClienteAll()->getId();}
  4215.             
  4216.             $clienteAll $doctrine->getRepository(ClienteAll::class)->findClienteWithRelations($cliente_cx_id);
  4217.            
  4218.             
  4219.         }
  4220.         if($qrCodeData != null){
  4221.             
  4222.             $url $qrCodeData;
  4223.             preg_match('/(\d+)\/(\d+)$/'$url$matches);
  4224.             if (!empty($matches)) {
  4225.                 $numero1 $matches[1]; 
  4226.                 $numero2 $matches[2];
  4227.                 $clienteAll $doctrine->getRepository(ClienteAll::class)->find($numero1);
  4228.                 $cx $doctrine->getRepository(Cx::class)->findBy(['nome' => $numero2]);
  4229.                 
  4230.                 foreach ($cx as $key) {
  4231.                     $cx_id $key->getId();
  4232.                 }
  4233.                     
  4234.                 
  4235.                 $caixa $doctrine->getRepository(Caixa::class)->findBy(['cx' => $cx_id ]);
  4236.                 $a ;
  4237.                 
  4238.             } else {
  4239.                 
  4240.               
  4241.             }
  4242.             
  4243.         }
  4244.         if(isset($_POST["cx"])){
  4245.             $clienteAll $doctrine->getRepository(ClienteAll::class)->findClienteWithRelations($_POST["clienteAll"]);
  4246.             $clienteAll_nome $clienteAll->getNome();
  4247.             
  4248.             $cx $doctrine->getRepository(Cx::class)->find($_POST["cx"]);
  4249.             $caixa $doctrine->getRepository(Caixa::class)->find($_POST["caixas"]);
  4250.             $cliente $doctrine->getRepository(Cliente::class)->find($_POST["cliente"]);
  4251.             
  4252.             if ($cx != null) {
  4253.                 $cx_nome 'ID: '.$cx->getNome();
  4254.             }else{
  4255.                 $cx_nome 'GED: '.$caixa->getNome();
  4256.             }
  4257.         
  4258.             $cliente_nome $clienteAll_nome;
  4259.             if ($cliente_nome == NULL){
  4260.                 $cliente_nome $cliente->getNome();
  4261.             }
  4262.             
  4263.             
  4264.             $registro = new Registro();
  4265.             $registro->setOperacao('HIGIENIZAÇÃO '.$cx_nome); 
  4266.             $registro->setUser($user_nome);
  4267.             $registro->setCliente($cliente_nome);
  4268.             $registro->setIp($ip_cliente);
  4269.             $entityManager->persist($registro);
  4270.             $entityManager->flush();
  4271.             
  4272.             if($cx != null){
  4273.                 
  4274.                 $etapa->addCx($cx);
  4275.             }
  4276.             
  4277.             $etapa->addCaixa($caixa);
  4278.             $caixa->setHigienizaAt($date_hoje);
  4279.             $e++;
  4280.             if ($e == $f) {
  4281.                 
  4282.                 $registro = new Registro();
  4283.                 $registro->setOperacao('HIGIENIZAÇÃO DE '.$f' CAIXA(S)'); 
  4284.                 $registro->setUser('CONCLUIDO PELA EQUIPE');
  4285.                 $registro->setCliente($cliente_nome);
  4286.                 $registro->setIp($ip_cliente);
  4287.                 $entityManager->persist($registro);
  4288.                 $entityManager->flush();
  4289.                 $etapa->setRegistro($registro);
  4290.                 $etapa->setUpdatedAt($date_hoje);
  4291.                 $entityManager->flush();
  4292.             }
  4293.             
  4294.             $entityManager->flush();
  4295.             $erro 'ok';
  4296.             $p "Etapa concluída com sucesso";
  4297.         }
  4298.         
  4299.         return $this->render('index/higienizacao.html.twig', [
  4300.     
  4301.             'id'=>$id,
  4302.             'p'=>$p,
  4303.             'erro'=>$erro,
  4304.             'pagina' => $pagina,
  4305.             'a'=>$a,
  4306.             'clienteAll' => $clienteAll,
  4307.             'cx' =>$cx ,
  4308.             'caixa' => $caixa,
  4309.             'fluxo_caixas'=>$fluxo_caixas
  4310.             
  4311.             
  4312.             
  4313.         ]);
  4314.     }
  4315.    
  4316.     #[Route('/index/digitalizacao/{id}'name'digitalizacao')]
  4317.     public function digitalizacao(Request $request,ManagerRegistry $doctrineEntityManagerInterface $entityManagerSessionInterface $session,MessageBusInterface $bus,$id): Response
  4318.     {
  4319.         $ip_cliente $_SERVER['REMOTE_ADDR'];
  4320.         $etapa $doctrine->getRepository(Etapa::class)->findWithAllRelations($id);
  4321.         $fluxo $doctrine->getRepository(Fluxo::class)->findWithAllRelations($etapa->getFluxo()->getId());
  4322.         $cliente_nome $fluxo->getCliente()->getNome();
  4323.         $cliente_id $fluxo->getCliente();
  4324.         $fluxo_caixas $doctrine->getRepository(Caixa::class)->findByFluxoWithRelations($fluxo->getId());
  4325.         $form $this->createForm(UploadType::class);
  4326.         $user_logado $this->getUser();
  4327.         $user_logado_id $user_logado->getId();
  4328.         $userId $user_logado_id;
  4329.         $cliente =  $doctrine->getRepository(User::class)->findClientsByUserId($user_logado_id);
  4330.         $form->handleRequest($request);
  4331.         $dotenv = new Dotenv();
  4332.         $dotenv->load(__DIR__.'/.env');
  4333.         $hoje = new \DateTimeImmutable('America/Sao_Paulo');
  4334.         $hoje_formt=$hoje->format('Y-m-d') ;
  4335.         $dia_prod 'de hoje';
  4336.         $erro '';
  4337.         $ii=0;
  4338.         $pagina 'export';
  4339.         $p '';
  4340.         $uuid Uuid::v4();
  4341.         $user $this->getUser();
  4342.         $user_nome$user->getEmail();
  4343.         $user_nome_name$user->getNome();
  4344.         $pasta_user=$user_nome.'/';
  4345.         $cliente_alls "";
  4346.         $arr = [];
  4347.         $arrr=0;
  4348.         $f 0;
  4349.         $dt '';
  4350.         $clientS3 = new  S3Client([
  4351.             'region'  => 'sa-east-1',
  4352.             'version' => 'latest',
  4353.             'credentials' => [ 
  4354.                 'key'    => $_ENV['AWS_KEY'],
  4355.                 'secret' => $_ENV['AWS_SECRET'],
  4356.             ],
  4357.         
  4358.         ]);
  4359.         foreach ($fluxo_caixas as $key) {
  4360.             $f++;
  4361.         }
  4362.         if(isset($_POST["btn_cliente"])){
  4363.             
  4364.             $session->set('cliente_id'$_POST["btn_cliente"]);
  4365.             return $this->redirectToRoute('home');
  4366.         }
  4367.        
  4368.             
  4369.             
  4370.        
  4371.         $clienteId $session->get('cliente_id');
  4372.         
  4373.         if ($clienteId == null ) {
  4374.             
  4375.             $caixas =  "";
  4376.             $cliente_session "";
  4377.             return $this->redirectToRoute('home');
  4378.        
  4379.         } else {
  4380.             
  4381.             $caixas $fluxo_caixas;
  4382.             $cliente_session =  $doctrine->getRepository(Cliente::class)->find($clienteId);       
  4383.         }
  4384.         
  4385.         
  4386.         if(isset($_POST["botao_export"]))
  4387.         {
  4388.             
  4389.             $caixaId $_POST["caixas"];
  4390.             
  4391.             $caixa_id $doctrine->getRepository(Caixa::class)->find($_POST["caixas"]);
  4392.             $clientes$cliente_id->getId();
  4393.             $cliente_alls $cliente_id->getClienteAll()->getId();
  4394.             $clienteId=$clientes;
  4395.             $clientes_status$cliente_id->getExtraFields();
  4396.             if(!$clientes_status){
  4397.                 $clientes_status="ged";
  4398.             }
  4399.             $conteiner $_POST["conteiner"];
  4400.             $cont_file ;
  4401.             $umlautString =$cliente_nome;
  4402.             $slugger = new AsciiSlugger();
  4403.             $teste=$slugger->slug($umlautString$seperator '-')->toString();
  4404.             $caminho strtolower ($teste.'/');
  4405.                     
  4406.             if($clientes == 14){$caminho='cartorio-1deg-oficio-de-volta-redonda-rj/';}
  4407.             if($clientes == 83){$caminho='casf-corretora-apolice-diversos/';}
  4408.             if($clientes == 35){$caminho='pmecj-sp-saude/';}
  4409.             if($clientes == 107){$caminho='pmecj-sp-execucao-fiscal/';}
  4410.             if($clientes ==  4){$caminho='cartorio-souza-reis-barra-mansa/';}
  4411.             if($clientes ==  112){$caminho='saae-cartao-de-ponto/';}
  4412.             if($clientes ==  15){$caminho='cbsi-dossies/';}
  4413.             if($clientes ==  55){$caminho='casf-gerep-contratos-de-prestadores-de-saude-pj/';}
  4414.             if($clientes ==  13){$caminho='casa-de-saude-santa-maria-c-s-s.M/';}
  4415.             if($clientes ==  40){$caminho='fasf-atas-e-diario/';}
  4416.             if($clientes ==  127){$caminho='pmecj-s-a.A) - ALMOXARIFADO E PATRIMÔNIO/';}
  4417.            
  4418.             $filesTmp  $_FILES['file']['tmp_name'];
  4419.             $filesName $_FILES['file']['name'];
  4420.             
  4421.             foreach ($filesTmp as $index => $file) {
  4422.             
  4423.                 $uuid Uuid::v4();
  4424.                 $cont_file++;
  4425.                 // nome original do arquivo
  4426.                 $originalName pathinfo($filesName[$index], PATHINFO_FILENAME);
  4427.                 // sanitiza o nome (remove acentos, espaços estranhos etc.)
  4428.                 $slugger = new AsciiSlugger();
  4429.                 $safeName strtolower($slugger->slug($originalName)->toString());
  4430.             
  4431.                 // 🔹 Se cliente for local, usa nome original
  4432.                 if ($clientes_status === 'local') {
  4433.             
  4434.             
  4435.                     $filename $safeName '.pdf';
  4436.             
  4437.                 } else {
  4438.                     // padrão: UUID
  4439.                     $filename $uuid '.pdf';
  4440.                 }
  4441.             
  4442.                 $tempDir __DIR__ '/../../var/uploads/messenger';
  4443.                 if (!is_dir($tempDir)) {
  4444.                     mkdir($tempDir0777true);
  4445.                 }
  4446.             
  4447.                 $tempFilePath $tempDir '/' $filename;
  4448.             
  4449.                 move_uploaded_file($file$tempFilePath);
  4450.                 chmod($tempFilePath0644);
  4451.                 if (!file_exists($tempFilePath) || filesize($tempFilePath) === 0) {
  4452.                     throw new \RuntimeException(
  4453.                         'Falha ao gravar PDF temporário: ' $tempFilePath
  4454.                     );
  4455.                 }
  4456.                 
  4457.                 // evita race condition de filesystem
  4458.                 clearstatcache(true$tempFilePath);
  4459.             
  4460.                 $bus->dispatch(new UploadMultipartMessage(
  4461.                     $tempFilePath,
  4462.                     $filename,
  4463.                     $caminho,
  4464.                     '',
  4465.                     $caixaId,
  4466.                     $clienteId,
  4467.                     $userId,
  4468.                     0,
  4469.                     $conteiner,
  4470.                     $clientes,
  4471.                     $clientes_status,
  4472.                     $safeName,
  4473.                     $originalName,
  4474.                     $cliente_alls 
  4475.                 ));
  4476.             }
  4477.            
  4478.             $log = new Registro();
  4479.             $log->setOperacao('EXPORTOU '.$cont_file.' DOCUMENTO(S)'); 
  4480.             $log->setUser($user_nome_name);
  4481.             $log->setCliente($cliente_nome);
  4482.             $entityManager->persist($log);
  4483.             $entityManager->flush();
  4484.             
  4485.             return $this->redirectToRoute('digitalizacao', ['id' => $id]);
  4486.             
  4487.         
  4488.         }
  4489.         if(isset($_POST["caixa_total"])){
  4490.             $caixa_total $_POST["caixa_total"];
  4491.             $documento_total =$_POST["documento_total"];
  4492.             $qtd_total =$_POST["qtd_total"];
  4493.                 $registro = new Registro();
  4494.                 $registro->setOperacao('DIGITALIZAÇÃO:  '.$caixa_total' CAIXA(S) / '.$documento_total.' DOCUMENTO(S) / '.$qtd_total.' IMAGEN(S)'); 
  4495.                 $registro->setUser('CONCLUIDO PELA EQUIPE');
  4496.                 $registro->setCliente($cliente_nome);
  4497.                 $registro->setIp($ip_cliente);
  4498.                 $entityManager->persist($registro);
  4499.                 $entityManager->flush();
  4500.                 $etapa->setRegistro($registro);
  4501.                 $etapa->setUpdatedAt($hoje);
  4502.                 $entityManager->flush();
  4503.                 $erro 'ok';
  4504.                 $p "Etapa concluída com sucesso";
  4505.         }
  4506.        
  4507.         return $this->render('index/digitalizacao.html.twig', [
  4508.             'id'=>$id,
  4509.             'p'=>$p,
  4510.             'erro'=>$erro,
  4511.             'pagina' => $pagina,
  4512.             'caixas' => $caixas,
  4513.             'user_logado' => $user_logado,
  4514.             'cliente' => $cliente,
  4515.             'cliente_session' => $cliente_session,
  4516.             'form' => $form->createView(),
  4517.             'dia_prod' => $dia_prod,
  4518.             'fluxo' => $fluxo
  4519.         ]);
  4520.     }
  4521.     #[Route('/index/indexacao/{id}'name'indexacao')]
  4522.     public function indexacao(Request $request,ManagerRegistry $doctrineEntityManagerInterface $entityManager SessionInterface $session,$id): Response
  4523.     {   
  4524.         $ip_cliente $_SERVER['REMOTE_ADDR'];
  4525.         $etapa $doctrine->getRepository(Etapa::class)->findWithAllRelations($id);
  4526.         $fluxo $doctrine->getRepository(Fluxo::class)->findWithAllRelations($etapa->getFluxo()->getId());
  4527.         $cliente_nome $fluxo->getCliente()->getNome();
  4528.         $cliente_etapa $fluxo->getCliente();
  4529.         $fluxo_caixas $doctrine->getRepository(Caixa::class)->findByFluxoWithRelations($fluxo->getId());
  4530.         $caixaIds array_map(fn($caixa) => $caixa->getId(), $fluxo_caixas);
  4531.         $documentoRepository $entityManager->getRepository(Documento::class);
  4532.         $query $documentoRepository->createQueryBuilder('d')
  4533.             ->where('d.caixa IN (:caixaIds)')
  4534.             ->setParameter('caixaIds'$caixaIds)
  4535.             #->orderBy('d.qtd', 'ASC') // Ordenando pelo ID da caixa em ordem crescente
  4536.             ->getQuery();
  4537.         // Executa a query
  4538.         $documentos $query->getResult();
  4539.         $caixas $fluxo_caixas;
  4540.         $dotenv = new Dotenv();
  4541.         $dotenv->load(__DIR__.'/.env');
  4542.         $user_logado $this->getUser();
  4543.         $form $this->createForm(UploadType::class);
  4544.         $form->handleRequest($request);
  4545.         $user_logado_tipoAcesso $user_logado->getTipoAcesso();
  4546.         $user_logado_nome $user_logado->getNome();
  4547.         $user_logado_id $user_logado->getId();
  4548.         $cliente =  $doctrine->getRepository(User::class)->findClientsByUserId($user_logado_id);
  4549.         $hoje = new \DateTimeImmutable('America/Sao_Paulo');
  4550.         $hoje_formt=$hoje->format('Y-m-d');
  4551.         $doc $entityManager->getRepository(Documento::class)->findByUserIndexAndDate($user_logado_nome$hoje_formt);
  4552.         $dia_prod 'de hoje';
  4553.         $permissao = [];
  4554.         $list_indexador = [];
  4555.         $index_all =  $doctrine->getRepository(Tipo::class)->findBy(['cliente' => $cliente_etapa]);
  4556.         $class =  $doctrine->getRepository(Classificacao::class)->findBy(['cliente' => $cliente_etapa]);
  4557.         $cliente_ids =$cliente_etapa ;
  4558.         
  4559.        
  4560.             
  4561.         $cliente_nome$cliente_ids->getNome();
  4562.         $clientes$cliente_ids->getId();
  4563.         $umlautString =$cliente_nome;
  4564.         $slugger = new AsciiSlugger();
  4565.         $teste=$slugger->slug($umlautString$seperator '-')->toString();
  4566.         $caminho strtolower ($teste.'/');
  4567.                         
  4568.         if($clientes == 14){$caminho='cartorio-1deg-oficio-de-volta-redonda-rj/';}
  4569.         if($clientes == 83){$caminho='casf-corretora-apolice-diversos/';}
  4570.         if($clientes == 35){$caminho='pmecj-sp-saude/';}
  4571.         if($clientes == 107){$caminho='pmecj-sp-execucao-fiscal/';}
  4572.         if($clientes ==  4){$caminho='cartorio-souza-reis-barra-mansa/';}
  4573.         if($clientes ==  112){$caminho='saae-cartao-de-ponto/';}
  4574.         if($clientes ==  15){$caminho='cbsi-dossies/';}
  4575.         if($clientes ==  55){$caminho='casf-gerep-contratos-de-prestadores-de-saude-pj/';}
  4576.         if($clientes ==  13){$caminho='casa-de-saude-santa-maria-c-s-s.M/';}
  4577.         if($clientes ==  127){$caminho='pmecj-s-a.A) - ALMOXARIFADO E PATRIMÔNIO/';}
  4578.       
  4579.           
  4580.         if(isset($_POST["btn_cliente"])){
  4581.             
  4582.             $session->set('cliente_id'$_POST["btn_cliente"]);
  4583.             return $this->redirectToRoute('home');
  4584.         }
  4585.         $clienteId $session->get('cliente_id');
  4586.         
  4587.         
  4588.         if ($clienteId == null ) {
  4589.             
  4590.             $caixas =  "";
  4591.             $cliente_session "";
  4592.             return $this->redirectToRoute('home');
  4593.        
  4594.         }
  4595.            
  4596.         $erro '';
  4597.         $ii=0;
  4598.         $pagina 'index';
  4599.         $p '';
  4600.         $link '';
  4601.         $mx 0;
  4602.         $xy 
  4603.         $yz 
  4604.         $ay ;
  4605.         $ky ;
  4606.         $pdf ='';
  4607.         $pagina_h4 ='Documento(s) para indexar';
  4608.         $nome_menu_ '';
  4609.         $index_tipo='';
  4610.         $uuid Uuid::v4();
  4611.         $user $this->getUser();
  4612.         $user_nome$user->getEmail();
  4613.         $user_nome_name$user->getNome();
  4614.         $pasta_user=$user_nome.'/';
  4615.         $arr = [];
  4616.         $arrr=0;
  4617.         $index_find null;
  4618.         $dt '';
  4619.         $clientS3 = new  S3Client([
  4620.                     'region'  => 'sa-east-1',
  4621.                     'version' => 'latest',
  4622.                     'credentials' => [ 
  4623.                         'key'    => $_ENV['AWS_KEY'],
  4624.                         'secret' => $_ENV['AWS_SECRET'],
  4625.                     ],
  4626.                 ]);
  4627.         
  4628.      
  4629.             
  4630.        
  4631.         if(isset($_POST["botao_index"])){
  4632.             
  4633.             $pdf =  $doctrine->getRepository(Documento::class)->find($_POST["id"]);
  4634.             $link $pdf->getImage();
  4635.             $xy ;
  4636.             
  4637.         }
  4638.         if(isset($_POST["botao_doc"])){
  4639.             
  4640.             
  4641.             $yz ;
  4642.             $xy ;
  4643.             $ay ;
  4644.             $pdf =  $doctrine->getRepository(Documento::class)->find($_POST["id_pdf"]);
  4645.             $index_tipo =  $doctrine->getRepository(Tipo::class)->find($_POST["id_index"]);
  4646.            
  4647.             $index_tipo =  $doctrine->getRepository(Tipo::class)->find($_POST["id_index"]);
  4648.             $index_tipo_tipo =  $index_tipo->getNome();
  4649.             $link $pdf->getImage();
  4650.             $fase=$_POST["fase"];
  4651.             $data $_POST["data"];
  4652.             $cx $_POST["caixas"];
  4653.             $classifica $_POST["classifica"];
  4654.             $desc $_POST["desc"];
  4655.             $assunto $_POST["assunto"];
  4656.             $chave $_POST["chave"];
  4657.             $nome $_POST["nome"];
  4658.             $conteiner $_POST["conteiner"];
  4659.             
  4660.             
  4661.             $caixa_id $doctrine->getRepository(Caixa::class)->find($cx);
  4662.             
  4663.             
  4664.             
  4665.             
  4666.             // Exibe os números encontrados
  4667.             
  4668.             if ($clientes != 7) {
  4669.                 preg_match_all('/\d+/'$fase$matches);
  4670.                 $numeros array_map('intval'$matches[0]);
  4671.                 if ($data != "") {
  4672.                     if ($numeros != [] ) {
  4673.                         if ($fase != "") {
  4674.         
  4675.                             // Número inteiro que você deseja somar ao ano
  4676.                             $numeroParaSomar $numeros[0];
  4677.         
  4678.                             // Extrair o ano da data
  4679.                             list($ano$mes$dia) = explode('-'$data);
  4680.         
  4681.                             // Converter o ano para um número inteiro
  4682.                             $ano intval($ano);
  4683.         
  4684.                             // Somar o número ao ano
  4685.                             $data_vecimento =  $ano $numeroParaSomar.'-'.$mes.'-'$dia;
  4686.         
  4687.                             $pdf->setVencimentoDocumento(new \DateTimeImmutable($data_vecimento));
  4688.         
  4689.                         }
  4690.                 }
  4691.                 $pdf->setDataDocumento(new \DateTimeImmutable($data));
  4692.                 }
  4693.             }    
  4694.             
  4695.             if ($clientes == 7) {
  4696.                   $pdf->setVencimentoDocumento(new \DateTimeImmutable($fase));
  4697.                   $pdf->setDataDocumento(new \DateTimeImmutable($data));
  4698.              }
  4699.             
  4700.             
  4701.             $pdf->setAssunto($assunto);
  4702.             if ($classifica != "") {
  4703.                 $classifica_id $doctrine->getRepository(Classificacao::class)->find($classifica);
  4704.                 $pdf->setClassificacao($classifica_id);
  4705.             }
  4706.             $pdf->setCaixa($caixa_id);
  4707.             $pdf->setExtraFields($desc);
  4708.             $pdf->setNome($nome);
  4709.             $pdf->setKeywords($chave);
  4710.             $pdf->setUserIndex($user_nome_name);
  4711.             $pdf->setConteiner($conteiner);
  4712.             $pdf->setIndexAt(new \DateTimeImmutable('America/Sao_Paulo'));
  4713.             $pdf->setTipo($index_tipo);
  4714.             $entityManager->flush();
  4715.             $id_pd $pdf->getId();    
  4716.             $log = new Registro();
  4717.             $log->setOperacao('Indexou o Documento com id '.$id_pd); 
  4718.             $log->setUser($user_nome_name);
  4719.             $log->setCliente($cliente_nome);
  4720.             $entityManager->persist($log);
  4721.             $entityManager->flush();
  4722.             $erro 'ok';
  4723.             $p =  $index_tipo_tipo.' indexado com sucesso';
  4724.             
  4725.            
  4726.             
  4727.            
  4728.         }   
  4729.         if(isset($_POST["botao_index_edit"])){
  4730.             
  4731.             $yz ;
  4732.             $xy ;
  4733.             $ay ;
  4734.             $pdf =  $doctrine->getRepository(Documento::class)->find($_POST["id"]);
  4735.             $index_tipo =  $doctrine->getRepository(Tipo::class)->find($_POST["id_index"]);
  4736.             $link $pdf->getImage();
  4737.         }
  4738.         if(isset($_POST["botao_volta"])){
  4739.             $xy ;
  4740.             $yz ;
  4741.         }
  4742.         if(isset($_POST["index_button"])){
  4743.             
  4744.             
  4745.             $yz ;
  4746.             $xy ;
  4747.             $ay ;
  4748.             $pdf =  $doctrine->getRepository(Documento::class)->find($_POST["id_pdf"]);
  4749.             $index_tipo =  $doctrine->getRepository(Tipo::class)->find($_POST["index_button"]);
  4750.             $link $pdf->getImage();
  4751.         }
  4752.         if(isset($_POST["botao_cancel"])){
  4753.             $yz ;
  4754.             $xy ;
  4755.             $ay ;
  4756.             $pdf =  $doctrine->getRepository(Documento::class)->find($_POST["id_pdf"]);
  4757.             $link $pdf->getImage();
  4758.             
  4759.         }
  4760.         if(isset($_POST["delet"])){
  4761.            
  4762.             $ky ;
  4763.             $pdf =  $doctrine->getRepository(Documento::class)->find($_POST["delet"]);
  4764.             $documentos $doctrine->getRepository(Documento::class)->findBy(['id' => $_POST["delet"]]);
  4765.             
  4766.             if($pdf->getTipo()!= null){
  4767.                 $index_find =  $doctrine->getRepository(Tipo::class)->find($pdf->getTipo());
  4768.                 $pagina =$index_find->getTipo();
  4769.                 $pagina_h4 ='Documento(s) do tipo ( '.$index_find->getTipo().' )';
  4770.             }
  4771.                         
  4772.         }
  4773.         if(isset($_POST["delet_cancel"])){
  4774.             $ky ;
  4775.         }
  4776.         if(isset($_POST["delet_sim"])){
  4777.             
  4778.             $pdf =  $doctrine->getRepository(Documento::class)->find($_POST["id"]);
  4779.             $id_pd $pdf->getId();
  4780.             $entityManager->remove($pdf);
  4781.             $entityManager->flush();
  4782.           
  4783.             $log = new Registro();
  4784.             $log->setOperacao('Excluiu Documento com id '.$id_pd); 
  4785.             $log->setUser($user_nome_name);
  4786.             $log->setCliente($cliente_nome);
  4787.             $entityManager->persist($log);
  4788.             $entityManager->flush();
  4789.             $erro 'ok';
  4790.             $p 'Documento com id '.$id_pd.' excluido com sucesso '
  4791.         }
  4792.         if(isset($_POST["index_edit"])){
  4793.             $yz ;
  4794.             $xy ;
  4795.             $ay ;
  4796.             $pdf =  $doctrine->getRepository(Documento::class)->find($_POST["id_pdf"]);
  4797.             $index_tipo =  $doctrine->getRepository(Tipo::class)->find($_POST["id_index"]);
  4798.             $link $pdf->getImage();
  4799.         }
  4800.        
  4801.         if(isset($_POST["caixa_total"])){
  4802.             $caixa_total $_POST["caixa_total"];
  4803.             $documento_total =$_POST["documento_total"];
  4804.             $qtd_total =$_POST["qtd_total"];
  4805.                 $registro = new Registro();
  4806.                 $registro->setOperacao('INDEXADO:  '.$caixa_total' CAIXA(S) / '.$documento_total.' DOCUMENTO(S) / '); 
  4807.                 $registro->setUser('CONCLUIDO PELA EQUIPE');
  4808.                 $registro->setCliente($cliente_nome);
  4809.                 $registro->setIp($ip_cliente);
  4810.                 $entityManager->persist($registro);
  4811.                 $entityManager->flush();
  4812.                 $etapa->setRegistro($registro);
  4813.                 $etapa->setUpdatedAt($hoje);
  4814.                 $entityManager->flush();
  4815.                 $erro 'ok';
  4816.                 $p "Etapa concluída com sucesso";
  4817.         }
  4818.         
  4819.            $cmd $clientS3->getCommand('GetObject', [
  4820.                 'Bucket' => 'arquivosdoc',
  4821.                 'Key'    => $caminho$link
  4822.             ]);
  4823.             
  4824.             $req $clientS3->createPresignedRequest($cmd'+30 minutes');
  4825.             $all_Url = (string) $req->getUri();
  4826.         
  4827.         return $this->render('index/indexacao.html.twig', [
  4828.             'documentos' => $documentos,
  4829.             'xy' => $xy,
  4830.             'yz' => $yz,
  4831.             'ay'=>$ay,
  4832.             'link' => $link,
  4833.             'pdf'=>$pdf,
  4834.             'p'=>$p,
  4835.             'erro'=>$erro,
  4836.             'index_all'=>$index_all,
  4837.             'index_tipo'=>$index_tipo,
  4838.             'ky'=>$ky,
  4839.             'pagina' => $pagina,
  4840.             'pagina_h4' =>$pagina_h4,
  4841.             'index_find'=>$index_find,
  4842.             'mx'=>$mx,
  4843.             'class'=>$class,
  4844.             'caixas' => $caixas,
  4845.             'permissao'=>$permissao,
  4846.             'doc'=>$doc,
  4847.             'dia_prod' => $dia_prod,
  4848.             'fluxo' => $fluxo,
  4849.             'id' => $id,
  4850.             'caminho' =>$caminho,
  4851.             'clientes'=>$clientes,
  4852.             'all_Url'=>$all_Url
  4853.         ]);
  4854.     }
  4855.     
  4856.     #[Route('/kpis'name'kpis')]
  4857.     public function kpis(Request $request,ManagerRegistry $doctrineEntityManagerInterface $entityManager): Response
  4858.     {
  4859.         $hoje = new \DateTimeImmutable('America/Sao_Paulo');
  4860.         $hoje_formt=$hoje->format('Y-m-d') ;
  4861.         $pagina="kpis";
  4862.         $motivo ='';
  4863.         $error='';
  4864.         $user_logado $this->getUser();
  4865.         $de_="";
  4866.         $ate_"";
  4867.         $h4 ="TOTAL";
  4868.         if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
  4869.             $ip_cliente explode(','$_SERVER['HTTP_X_FORWARDED_FOR'])[0];
  4870.         } else {
  4871.             $ip_cliente $_SERVER['REMOTE_ADDR'];
  4872.         }
  4873.         
  4874.         $payload json_encode([
  4875.             
  4876.             'data_inicio' => null,
  4877.             'data_fim' => null
  4878.             
  4879.         ]);
  4880.         $options = [
  4881.             'http' => [
  4882.                 'header'  => "Content-Type: application/json\r\n",
  4883.                 'method'  => 'POST',
  4884.                 'content' => $payload,
  4885.             ],
  4886.         ];
  4887.         $context  stream_context_create($options);
  4888.         $response file_get_contents('https://produtive.arquivosdoc.com.br/api/tjrj'false$context);
  4889.         if ($response === false) {
  4890.             return new Response("Erro ao consumir API"500);
  4891.         }
  4892.         $data json_decode($responsetrue);
  4893.         
  4894.         $conn $entityManager->getConnection();
  4895.         $sql "
  4896.            SELECT 
  4897.                 c.nome AS cliente_nome,
  4898.                     (SELECT COUNT(cx.id) 
  4899.                      FROM cx cx 
  4900.                      WHERE cx.caminho IS NOT NULL 
  4901.                      AND cx.cliente_id = c.id) AS total_caixas,
  4902.                     (SELECT COUNT(d.id) 
  4903.                      FROM documento d 
  4904.                      JOIN cliente s ON s.id = d.cliente_id
  4905.                      WHERE s.cliente_all_id = c.id) AS total_documentos,
  4906.                     (SELECT SUM(d.qtd) 
  4907.                      FROM documento d 
  4908.                      JOIN cliente s ON s.id = d.cliente_id
  4909.                      WHERE s.cliente_all_id = c.id) AS imagens_total
  4910.                 FROM cliente_all c
  4911.                 ORDER BY c.nome ASC
  4912.         ";
  4913.         $stmt $conn->prepare($sql);
  4914.         $stmt->execute();
  4915.         $fed_cliente $stmt->executeQuery()->fetchAllAssociative();
  4916.         
  4917.          // 🔹 Adicionando TJRJ no array de clientes
  4918.         if (is_array($data)) {
  4919.             $fed_cliente[] = [
  4920.                 'cliente_nome'     => 'TRIBUNAL DE JUSTICA DO ESTADO DO RIO DE JANEIRO',
  4921.                  #'total_caixas'     => $data['total_caixas'] ?? 0,
  4922.                 'total_caixas'     => 0,
  4923.                 'total_documentos' => $data['total_documentos'] ?? 0,
  4924.                 'imagens_total'    => $data['imagens_total'] ?? 0
  4925.             ];
  4926.         }
  4927.         
  4928.        
  4929.        
  4930.         //IMAGENS
  4931.         $sql1 "SELECT SUM(d.qtd) AS total_imagens FROM documento d";
  4932.         $totalImagens $conn->fetchOne($sql1); 
  4933.         $totalImagens += $data['imagens_total'] ?? 0;
  4934.         
  4935.         //DOCUMENTOS
  4936.         $sql2 "SELECT COUNT(d.id) AS total_documentos FROM documento d";
  4937.         $documento $conn->fetchOne($sql2);
  4938.         $documento += $data['total_documentos'] ?? 0;
  4939.         
  4940.         //CX (com filtro de status != 0)
  4941.         $sql3 "SELECT COUNT(d.id) AS total_cx FROM cx d WHERE d.status != 0 AND d.caminho != ''";
  4942.         $cx $conn->fetchOne($sql3);
  4943.         
  4944.         
  4945.          if(isset($_POST["pesq"])){
  4946.         
  4947.             
  4948.             $de $_POST["de"];
  4949.             $ate $_POST["ate"]." 23:59:59";
  4950.             
  4951.             
  4952.             
  4953.             // IMAGENS
  4954.             $queryStr '
  4955.                 SELECT SUM(d.qtd) AS total_imagens
  4956.                 FROM App\Entity\Documento d
  4957.                 WHERE d.createdAt >= :de 
  4958.             ';
  4959.             if ($ate) {
  4960.                 $queryStr .= ' AND d.createdAt <= :ate';
  4961.             }
  4962.             $query $entityManager->createQuery($queryStr);
  4963.             $query->setParameter('de'$de);
  4964.             if ($ate) {$query->setParameter('ate'$ate);}
  4965.             $result $query->getSingleResult();
  4966.             $totalImagens $result['total_imagens'];
  4967.             //
  4968.         
  4969.             // DOCUMENTOS
  4970.             $queryStr '
  4971.                 SELECT COUNT(d.id) AS total_documentos
  4972.                 FROM App\Entity\Documento d
  4973.                 WHERE d.createdAt >= :de
  4974.             ';
  4975.             if ($ate) {
  4976.                 $queryStr .= ' AND d.createdAt <= :ate';
  4977.             }
  4978.             $query $entityManager->createQuery($queryStr);
  4979.             $query->setParameter('de'$de);
  4980.             if ($ate) {$query->setParameter('ate'$ate);}
  4981.             $result $query->getSingleResult();
  4982.             $documento $result['total_documentos'];
  4983.             //
  4984.         
  4985.             // CX
  4986.             $queryStr '
  4987.                 SELECT COUNT(d.id) AS total_cx
  4988.                 FROM App\Entity\Cx d
  4989.                 WHERE d.createdAt >= :de  AND d.caminho IS NOT NULL
  4990.             ';
  4991.             if ($ate) {
  4992.                 $queryStr .= ' AND d.createdAt <= :ate';
  4993.             } else {
  4994.                 $queryStr .= ' AND DATE(d.createdAt) = DATE(:de)';
  4995.             }
  4996.             $query $entityManager->createQuery($queryStr);
  4997.             $query->setParameter('de'$de);
  4998.             if ($ate) {$query->setParameter('ate'$ate);}
  4999.             $result $query->getSingleResult();
  5000.             $cx $result['total_cx'];
  5001.             //
  5002.             
  5003.             $queryStr "
  5004.                 SELECT 
  5005.                     c.nome AS cliente_nome,
  5006.                     (SELECT COUNT(cx.id) 
  5007.                      FROM App\Entity\Cx cx 
  5008.                      WHERE cx.status != 0 
  5009.                      AND cx.caminho != '' 
  5010.                      AND cx.cliente = c
  5011.                      AND cx.createdAt >= :de
  5012.             ";
  5013.             
  5014.             if ($ate) {
  5015.                 $queryStr .= " AND cx.createdAt <= :ate";
  5016.             } else {
  5017.                 $queryStr .= " AND DATE(cx.createdAt) = DATE(:de)";
  5018.             }
  5019.             
  5020.             $queryStr .= ") AS total_caixas,
  5021.         
  5022.                     (SELECT COUNT(d1.id) 
  5023.                      FROM App\Entity\Documento d1 
  5024.                      JOIN d1.cliente c1 
  5025.                      WHERE c1.clienteAll = c
  5026.                      AND d1.createdAt >= :de
  5027.             ";
  5028.             
  5029.             if ($ate) {
  5030.                 $queryStr .= " AND d1.createdAt <= :ate";
  5031.             } else {
  5032.                 $queryStr .= " AND DATE(d1.createdAt) = DATE(:de)";
  5033.             }
  5034.             
  5035.             $queryStr .= ") AS total_documentos,
  5036.         
  5037.                     (SELECT SUM(d2.qtd) 
  5038.                      FROM App\Entity\Documento d2 
  5039.                      JOIN d2.cliente c2 
  5040.                      WHERE c2.clienteAll = c
  5041.                      AND d2.createdAt >= :de
  5042.             ";
  5043.             
  5044.             if ($ate) {
  5045.                 $queryStr .= " AND d2.createdAt <= :ate";
  5046.             } else {
  5047.                 $queryStr .= " AND DATE(d2.createdAt) = DATE(:de)";
  5048.             }
  5049.             
  5050.             $queryStr .= ") AS imagens_total
  5051.             FROM App\Entity\ClienteAll c
  5052.             ORDER BY c.nome ASC
  5053.             ";
  5054.             
  5055.             // Preparar a consulta com os parâmetros de data
  5056.             $query $entityManager->createQuery($queryStr);
  5057.             $query->setParameter('de'$de);
  5058.             if ($ate) {
  5059.                 $query->setParameter('ate'$ate);
  5060.             }
  5061.             
  5062.             $result $query->getResult();
  5063.                     
  5064.             $fed_cliente $result;
  5065.             
  5066.             
  5067.             
  5068.             // 🔹 Chamada API TJRJ
  5069.             $payload json_encode([
  5070.                 'data_inicio' => $_POST["de"] ?? null,
  5071.                 'data_fim'    => $_POST["ate"] ?? null
  5072.             ]);
  5073.             
  5074.             $options = [
  5075.                 'http' => [
  5076.                     'header'  => "Content-Type: application/json\r\n",
  5077.                     'method'  => 'POST',
  5078.                     'content' => $payload,
  5079.                 ],
  5080.             ];
  5081.             
  5082.             $context  stream_context_create($options);
  5083.             $response file_get_contents('https://produtive.arquivosdoc.com.br/api/tjrj'false$context);
  5084.             
  5085.             $data $response json_decode($responsetrue) : [];
  5086.             
  5087.             // 🔹 Adiciona TJRJ na lista final (igual no geral)
  5088.             if (is_array($data)) {
  5089.                 $fed_cliente[] = [
  5090.                     'cliente_nome'     => 'TRIBUNAL DE JUSTICA DO ESTADO DO RIO DE JANEIRO',
  5091.                     'total_caixas'     => 0,
  5092.                     'total_documentos' => $data['total_documentos'] ?? 0,
  5093.                     'imagens_total'    => $data['imagens_total'] ?? 0
  5094.                 ];
  5095.             }
  5096.             
  5097.             
  5098.                     
  5099.                         
  5100.         } 
  5101.           
  5102.             
  5103.      
  5104.         
  5105.         return $this->render('index/kpis.html.twig',array(
  5106.             
  5107.             'error' =>$error,
  5108.             'motivo' => $motivo,
  5109.             'pagina'=>$pagina,
  5110.             'user_logado'=> $user_logado ,
  5111.             'cx' => $cx,
  5112.             'documento' => $documento,
  5113.             'de' =>$de_,
  5114.             'ate' =>$ate_,
  5115.             'h4' => $h4,
  5116.             //'documentosPorMes' => $documentosPorMes,
  5117.             //'cxPorMes'=>$cxPorMes,
  5118.             //'totalImagensPorMes' => $totalImagensPorMes,
  5119.             'totalImagens'=>$totalImagens,
  5120.             'fed_cliente'=> $fed_cliente
  5121.             
  5122.             
  5123.         ));
  5124.     }
  5125.     
  5126.     #[Route('/fila/count'name'fila_count'methods: ['GET'])]
  5127.     public function count(EntityManagerInterface $entityManager): JsonResponse
  5128.     {
  5129.         $user_logado $this->getUser();
  5130.         $user_logado_id $user_logado->getId();
  5131.         $count $entityManager->getRepository(MessengerMessages::class)->countPendingMessagesByUser($user_logado_id);
  5132.         
  5133.         return new JsonResponse(['count' => $count]);
  5134.     }
  5135.     
  5136.     #[Route('/index/qualidade'name'qualidade')]
  5137.     public function qualidade(Request $request,ManagerRegistry $doctrineEntityManagerInterface $entityManager SessionInterface $session): Response
  5138.     {   
  5139.         $clienteId $session->get('cliente_id');
  5140.         $ip_cliente $_SERVER['REMOTE_ADDR'];
  5141.         $caixaIds "LEONARDO DE SOUZA CRUZEIRO";
  5142.         $documentoRepository $entityManager->getRepository(Documento::class);
  5143.         $query $documentoRepository->createQueryBuilder('d')
  5144.             ->where('d.user_index IN (:caixaIds)')
  5145.             ->andWhere('d.cliente = :clienteId')
  5146.             ->andWhere('d.situacao = :situacao OR d.situacao IS NULL')
  5147.             ->setParameter('situacao''')
  5148.             ->setParameter('caixaIds'$caixaIds)
  5149.             ->setParameter('clienteId'$clienteId)
  5150.             ->orderBy('d.caixa''ASC'// Ordenando pelo ID da caixa em ordem crescente
  5151.             ->getQuery();
  5152.         // Executa a query
  5153.         $documentos $query->getResult();
  5154.         #dd($documentos);
  5155.         $dotenv = new Dotenv();
  5156.         $dotenv->load(__DIR__.'/.env');
  5157.         $user_logado $this->getUser();
  5158.         $form $this->createForm(UploadType::class);
  5159.         $form->handleRequest($request);
  5160.         $user_logado_tipoAcesso $user_logado->getTipoAcesso();
  5161.         $user_nome_name $user_logado->getNome();
  5162.         $user_logado_id $user_logado->getId();
  5163.         $hoje = new \DateTimeImmutable('America/Sao_Paulo');
  5164.         $hoje_formt=$hoje->format('Y-m-d');
  5165.         $dia_prod 'de hoje';
  5166.         $permissao = [];
  5167.         $list_indexador = [];
  5168.         $slugger = new AsciiSlugger();
  5169.         $erro '';
  5170.         $ii=0;
  5171.         $pagina 'qualidade';
  5172.         $p '';
  5173.         $link '';
  5174.         $xy 
  5175.         $pdf ='';
  5176.         $umlautString '';
  5177.         $clientes 0;
  5178.         $caminho ='';
  5179.         $class ="";
  5180.         $all_Url="";
  5181.         
  5182.         $clientS3 = new  S3Client([
  5183.                     'region'  => 'sa-east-1',
  5184.                     'version' => 'latest',
  5185.                     'credentials' => [ 
  5186.                         'key'    => $_ENV['AWS_KEY'],
  5187.                         'secret' => $_ENV['AWS_SECRET'],
  5188.                     ],
  5189.                 ]);
  5190.        
  5191.         if(isset($_POST["botao_index"])){
  5192.             
  5193.             $pdf =  $doctrine->getRepository(Documento::class)->find($_POST["id"]);
  5194.             $clientes $pdf->getCliente()->getId();
  5195.             $clienteRepository $entityManager->getRepository(Cliente::class);
  5196.             $class =  $doctrine->getRepository(Classificacao::class)->findBy(['cliente' => $clientes]);
  5197.             $query $clienteRepository->createQueryBuilder('c')
  5198.                 ->where('c.id = :caixaIds')
  5199.                 ->setParameter('caixaIds'$clientes)
  5200.                 ->getQuery();
  5201.             $cl $query->getSingleResult();
  5202.             $link $pdf->getImage();
  5203.             $xy ;
  5204.             $umlautString $cl->getNome();
  5205.             $teste=$slugger->slug($umlautString$seperator '-')->toString();
  5206.             $caminho strtolower ($teste.'/');
  5207.                     
  5208.             if($clientes == 14){$caminho='cartorio-1deg-oficio-de-volta-redonda-rj/';}
  5209.             if($clientes == 83){$caminho='casf-corretora-apolice-diversos/';}
  5210.             if($clientes == 35){$caminho='pmecj-sp-saude/';}
  5211.             if($clientes == 107){$caminho='pmecj-sp-execucao-fiscal/';}
  5212.             if($clientes ==  4){$caminho='cartorio-souza-reis-barra-mansa/';}
  5213.             if($clientes ==  112){$caminho='saae-cartao-de-ponto/';}
  5214.             if($clientes ==  15){$caminho='cbsi-dossies/';}
  5215.             if($clientes ==  55){$caminho='casf-gerep-contratos-de-prestadores-de-saude-pj/';}
  5216.             if($clientes ==  13){$caminho='casa-de-saude-santa-maria-c-s-s.M/';}
  5217.             if($clientes ==  127){$caminho='pmecj-s-a.A) - ALMOXARIFADO E PATRIMÔNIO/';}
  5218.             
  5219.             $cmd $clientS3->getCommand('GetObject', [
  5220.                 'Bucket' => 'arquivosdoc',
  5221.                 'Key'    => $caminho$link
  5222.                 ]);
  5223.                 
  5224.             $req $clientS3->createPresignedRequest($cmd'+30 minutes');
  5225.             $all_Url = (string) $req->getUri();
  5226.                 
  5227.         }
  5228.         if(isset($_POST["botao_doc"])){
  5229.             
  5230.             
  5231.             
  5232.             
  5233.             $yz ;
  5234.             $xy ;
  5235.             $ay ;
  5236.             
  5237.             $pdf =  $doctrine->getRepository(Documento::class)->find($_POST["id_pdf"]);
  5238.             $index_tipo =  $doctrine->getRepository(Tipo::class)->find($pdf->getTipo());
  5239.             $index_tipo_tipo =  $index_tipo->getNome();
  5240.             $link $pdf->getImage();
  5241.             $data $_POST["data"];
  5242.             $desc $_POST["desc"];
  5243.             $assunto $_POST["assunto"];
  5244.             $chave $_POST["chave"];
  5245.             $nome $_POST["nome"];
  5246.             $conteiner $_POST["conteiner"];
  5247.             $classifica $_POST["classifica"];
  5248.             $fase $_POST["fase"];
  5249.             
  5250.             preg_match_all('/\d+/'$fase$matches);
  5251.             $numeros array_map('intval'$matches[0]);
  5252.             if ($clientes != 7) {
  5253.                 if ($data != "") {
  5254.                     if ($fase != "") {
  5255.                         $numeroParaSomar $numeros[0];
  5256.                         list($ano$mes$dia) = explode('-'$data);
  5257.                         $ano intval($ano);
  5258.                         $data_vecimento =  $ano $numeroParaSomar.'-'.$mes.'-'$dia;
  5259.                         $pdf->setVencimentoDocumento(new \DateTimeImmutable($data_vecimento));
  5260.                     }
  5261.                 $pdf->setDataDocumento(new \DateTimeImmutable($data));
  5262.                 }
  5263.             }  
  5264.             if ($classifica != "") {
  5265.                 $classifica_id $doctrine->getRepository(Classificacao::class)->find($classifica);
  5266.                 $pdf->setClassificacao($classifica_id);
  5267.             }
  5268.             
  5269.             
  5270.             
  5271.             
  5272.             $pdf->setAssunto($assunto);
  5273.             $pdf->setExtraFields($desc);
  5274.             $pdf->setNome($nome);
  5275.             $pdf->setKeywords($chave);
  5276.             $pdf->setUserIndex($user_nome_name);
  5277.             $pdf->setConteiner($conteiner);
  5278.             $pdf->setIndexAt(new \DateTimeImmutable('America/Sao_Paulo'));
  5279.             $pdf->setSituacao('OK');
  5280.             $entityManager->flush();
  5281.             $id_pd $pdf->getId();    
  5282.             $log = new Registro();
  5283.             $log->setOperacao('Conferiu o Documento com id '.$id_pd); 
  5284.             $log->setUser($user_nome_name);
  5285.             $log->setCliente($umlautString);
  5286.             $entityManager->persist($log);
  5287.             $entityManager->flush();
  5288.             $erro 'ok';
  5289.             $p =  $index_tipo_tipo.' FOI CONFERIDO COM SUCESSO';
  5290.            
  5291.         }   
  5292.         if(isset($_POST["botao_volta"])){
  5293.             $xy ;
  5294.             $yz ;
  5295.         }
  5296.         
  5297.        
  5298.         
  5299.         return $this->render('index/qualidade.html.twig', [
  5300.             'documentos' => $documentos,
  5301.             'xy' => $xy,
  5302.             'link' => $link,
  5303.             'pdf'=>$pdf,
  5304.             'p'=>$p,
  5305.             'erro'=>$erro,
  5306.             'pagina' => $pagina,
  5307.             'caminho' =>$caminho,
  5308.             'class' => $class,
  5309.             'all_Url'=>$all_Url,
  5310.            
  5311.         ]);
  5312.     }
  5313.     
  5314.      #[Route('/metas'name'metas')]
  5315.     public function metasPaginatorInterface $paginator,Request $request,ManagerRegistry $doctrineEntityManagerInterface $entityManagerSessionInterface $sessionMailerInterface $mailer): Response
  5316.     {
  5317.         
  5318.         $fluxos_abertos $entityManager
  5319.             ->getRepository(Fluxo::class)
  5320.             ->fluxosAbertosComMaiorPrazo();
  5321.             
  5322.          $fluxos_mes $entityManager
  5323.         ->getRepository(Fluxo::class)
  5324.         ->findMes();
  5325.         $totalFluxos     0;
  5326.         $clientesUnicos  = [];
  5327.         $totalCaixas     0;
  5328.         $totalDocumentos 0;
  5329.         $totalImagens    0;
  5330.         foreach ($fluxos_mes as $fluxo) {
  5331.             $totalFluxos++;
  5332.             // 👇 garante cliente único
  5333.             if ($fluxo->getCliente()) {
  5334.                 $clienteId $fluxo->getCliente()->getId();
  5335.                 $clientesUnicos[$clienteId] = true;
  5336.             }
  5337.             foreach ($fluxo->getCaixas() as $caixa) {
  5338.                 $totalCaixas++;
  5339.                 foreach ($caixa->getDocumentos() as $documento) {
  5340.                     $totalDocumentos++;
  5341.                     $totalImagens += $documento->getQtd();
  5342.                 }
  5343.             }
  5344.         }
  5345.         $formatter = new \IntlDateFormatter(
  5346.             'pt_BR',
  5347.             \IntlDateFormatter::NONE,
  5348.             \IntlDateFormatter::NONE,
  5349.             'America/Sao_Paulo',
  5350.             \IntlDateFormatter::GREGORIAN,
  5351.             'MMMM'
  5352.         );
  5353.         $nomeMes ucfirst($formatter->format(new \DateTime()));
  5354.         $resumo = [
  5355.             'fluxos'     => $totalFluxos,
  5356.             'clientes'   => count($clientesUnicos), // ✅ não duplica
  5357.             'caixas'     => $totalCaixas,
  5358.             'documentos' => $totalDocumentos,
  5359.             'imagens'    => $totalImagens,
  5360.             'nomeMes'     => $nomeMes
  5361.         ];
  5362.         
  5363.         $a = [];
  5364.         foreach ($fluxos_abertos as $item) {
  5365.             $fluxo $item[0];
  5366.             $maiorData $item['prazo'];
  5367.             $cx 0;
  5368.             $doc 0;
  5369.             $img 0;
  5370.             $cliente_id $fluxo->getCliente()->getId();
  5371.             $cliente $doctrine->getRepository(Cliente::class)
  5372.             ->createQueryBuilder('c')
  5373.             ->where('c.id = :id')
  5374.             ->setParameter('id'$cliente_id)
  5375.             ->getQuery()
  5376.             ->getOneOrNullResult();
  5377.             foreach ($fluxo->getCaixas() as $caixas) {
  5378.                 $cx++;
  5379.                 foreach ($caixas->getDocumentos() as $docs) {
  5380.                     $doc++;
  5381.                     $img += $docs->getQtd();
  5382.                 }
  5383.             }
  5384.             $a[] = [
  5385.                 'fluxo'       => $fluxo->getId(),
  5386.                 'cliente'     => $cliente->getNome(),
  5387.                 'caixas'      => $cx,
  5388.                 'documentos'  => $doc,
  5389.                 'imagens'     => $img,
  5390.                 'prazo'       => $maiorData,
  5391.             ];
  5392.         }
  5393.                 
  5394.         return $this->render('index/metas_fluxos.html.twig', [
  5395.             'data'=>$a,
  5396.             'resumo'=>$resumo
  5397.     
  5398.         ]);
  5399.     }
  5400.     
  5401.     public function configureDashboard(): Dashboard
  5402.     {
  5403.         return Dashboard::new()
  5404.             ->setTitle('IndexDoc')
  5405.             ->setFaviconPath('./img/icon.png');   
  5406.     }
  5407.     
  5408.     public function configureMenuItems(): iterable
  5409.     {
  5410.         // yield MenuItem::linkToDashboard('Dashboard', 'fa fa-home');
  5411.         // yield MenuItem::linkToCrud('The Label', 'fas fa-list', EntityClass::class);
  5412.     }
  5413. }