+
    i{3                     \    ^ RI HtHtHtHtHtHt ^ RIHt ^ RI	H
t
 ^ RIHt ^ RItRR ltR# )    )jsonifyrender_templaterequest	send_filesessionafter_this_request)Mail)get_tasks_list)FormularioPDFServiceNc                n    V P                  RR.R7      R 4       pV P                  RR.R7      R 4       pR# )u   
Agrupa las rutas para el módulo de consulta de Tareas de Cotización.
(Se añade 'mail=None' para mantener consistencia con otros módulos
como AccessDistributors, aunque no se use aquí).
z)/Operaciones_Module/Ingenieria/Cotiz/listGET)methodsc                      \        4       p \        V 4      ^3#   \         d3   p\        RT 24       \        R\	        T4      R. /4      R3u Rp?# Rp?ii ; i)z
SIRVE LOS DATOS A JAVASCRIPT (JSON).
Esta es la ruta que el JavaScript llama (fetch) para llenar la tabla.
Debe coincidir exactamente con la ruta en CotizFormQueryIng.js.
z:[Error en ruta /Operaciones_Module/Ingenieria/Cotiz/list] errordata  N)r
   r   	Exceptionprintstr)taskses     xC:\Users\victor.barrera\Documents\proyectos\elepV3\Elep\src\App\Operaciones_Module\Ingenieria\Cotiz\CotizFormQueryIng.pylist_cotiz_tasks3funcion_CotizFormQueryIng.<locals>.list_cotiz_tasks   s]    		?"$E 5>3&& 	?NqcRSGSVVR893>>	?s    A'AAAz0/Operaciones_Module/Ingenieria/Cotiz/generar-pdfc            
       a \         P                  P                  R4      p V '       g   R+# \         P                  P                  RR4      P                  4       R8H  p\         P                  P                  RR4      P                  4       R8H  p\	        R,4       \	        R4       \	        R,4       \	        RV  24       \	        RV 24       \	        RV 24       \	        R	\
        P                  ! R
R4       24       \	        R,4        \        P                  ! V RVVR7      pV'       g   \	        RV  24       RV  R2R3# VR,          '       d   \        P                  P                  VR,          4      '       dY   VR,          p\        P                  P                  V4      p\        P                  P                  V4      oRp\	        RV 24       M8VR,          pVR,          oRV P                  RR4       R2pRp\	        RV 24       \        V3R l4       p\        VR4      ;_uu_ 4       pVP!                  4       p	RRR4       ^ RIHp
 V
! X	4      pVP'                  ^ 4       \)        VVRVR 7      #   + '       g   i     L>; i  \*         d   p^ RIpTP/                  4       p\	        4        \	        R,4       \	        R!4       \	        R,4       \	        R"T  24       \	        R#T 24       \	        4        \	        R$4       \	        T4       \	        R,4       R%T  R&\1        T4      P2                   R'\5        T4       R(T R)2	R*3u Rp?# Rp?ii ; i)-us  
Genera y descarga PDF de formulario con archivos adjuntos.

¿Por qué este endpoint?
- Centraliza la lógica de generación de PDFs
- Permite parámetros configurables (con/sin adjuntos, con/sin ZIP)
- Retorna el archivo directamente para descarga inmediata

Parámetros URL (query params):
    - form_id: ID del formulario (REQUERIDO) - Ejemplo: '1002-1-FormGral'
    - adjuntos: 'true'|'false' - Incluir archivos adjuntos (default: true)
    - zip: 'true'|'false' - Crear archivo ZIP (default: true)

Ejemplos de uso:
    GET /Operaciones_Module/Ingenieria/Cotiz/generar-pdf?form_id=1002-1-FormGral
    GET /Operaciones_Module/Ingenieria/Cotiz/generar-pdf?form_id=1002-1-FormGral&adjuntos=false
    GET /Operaciones_Module/Ingenieria/Cotiz/generar-pdf?form_id=1002-1-FormGral&zip=false

Returns:
    File: PDF o ZIP para descarga directa
    HTML: Página de error si algo falla
form_idadjuntostruezipu%   🚀 ENDPOINT: generar_pdf_formulariou   📋 FormID solicitado: u   📎 Incluir adjuntos: u   📦 Crear ZIP: u   👤 UserID: user_idzNo autenticadoN)r   nombre_archivoincluir_adjuntos	crear_zipu   ❌ FormID no encontrado: u  
                <html>
                    <body style="font-family: Arial; padding: 40px; text-align: center;">
                        <h1 style="color: #e74c3c;">❌ FormID No Encontrado</h1>
                        <p>No se encontró el FormID: <strong>u  </strong></p>
                        <p style="color: #666;">
                            El FormID no existe en la base de datos o no tiene datos asociados.
                        </p>
                        <hr style="margin: 30px 0;">
                        <h3>💡 Sugerencias:</h3>
                        <ul style="text-align: left; max-width: 600px; margin: 0 auto;">
                            <li>Verifica que el FormID sea correcto</li>
                            <li>Revisa la consola del servidor para más detalles</li>
                            <li>Contacta al administrador del sistema</li>
                        </ul>
                        <br>
                        <button onclick="history.back()" style="padding: 10px 20px; font-size: 16px;">
                            ← Regresar
                        </button>
                    </body>
                </html>
                i  zapplication/zipu   📦 Enviando ZIP: pdf
directorioformulario_-_z.pdfzapplication/pdfu   📄 Enviando PDF: c                   <  ^ RI p\        P                  P                  S4      '       d    VP	                  S4       \        RS 24       V #   \         d   p\        RT 24        Rp?T # Rp?ii ; i)uh   
Se ejecuta DESPUÉS de enviar el archivo al cliente
Elimina la carpeta temporal con todos los archivos
Nu   🗑️  Carpeta eliminada: u.   ⚠️  No se pudo eliminar carpeta temporal: )shutilospathexistsrmtreer   r   )responser*   r   directorio_eliminars   &  r   eliminar_archivos_temporales_funcion_CotizFormQueryIng.<locals>.generar_pdf_formulario.<locals>.eliminar_archivos_temporales   sr    P!ww~~&9::&9: <=P<QRS
   ! PJ1#NOOPs   (A A A1A,,A1rb)BytesIOT)mimetypeas_attachmentdownload_nameu   ❌ ERROR CRÍTICO EN ENDPOINTzFormID: zError: zStack trace completo:u  
            <html>
                <head>
                    <title>Error - Sistema IGSA</title>
                    <style>
                        body {
                            font-family: 'Courier New', monospace;
                            padding: 40px;
                            background: #1e1e1e;
                            color: #d4d4d4;
                        }
                        .error-box {
                            background: #252526;
                            padding: 20px;
                            border-radius: 5px;
                            border-left: 4px solid #f48771;
                            margin: 20px 0;
                        }
                        .error-title {
                            color: #f48771;
                            font-size: 24px;
                            margin-bottom: 20px;
                        }
                        .error-details {
                            background: #1e1e1e;
                            padding: 15px;
                            border-radius: 3px;
                            overflow-x: auto;
                            margin-top: 15px;
                        }
                        button {
                            background: #0e639c;
                            color: white;
                            border: none;
                            padding: 10px 20px;
                            font-size: 16px;
                            cursor: pointer;
                            border-radius: 3px;
                            margin-top: 20px;
                        }
                        button:hover {
                            background: #1177bb;
                        }
                    </style>
                </head>
                <body>
                    <div class="error-box">
                        <div class="error-title">❌ Error del Sistema</div>
                        <p><strong>FormID solicitado:</strong> z@</p>
                        <p><strong>Tipo de error:</strong> z:</p>
                        <p><strong>Mensaje:</strong> z</p>
                        
                        <div class="error-details">
                            <strong>Stack Trace:</strong>
                            <pre>u   </pre>
                        </div>
                        
                        <button onclick="history.back()">← Regresar</button>
                    </div>
                </body>
            </html>
            r   )u  
            <html>
                <body style="font-family: Arial; padding: 40px; text-align: center;">
                    <h1 style="color: #e74c3c;">⚠️ Parámetro Faltante</h1>
                    <p>Debe proporcionar el parámetro <code>form_id</code></p>
                    <p style="color: #666;">
                        Ejemplo: <code>/generar-pdf?form_id=1002-1-FormGral</code>
                    </p>
                    <hr style="margin: 30px 0;">
                    <button onclick="history.back()" style="padding: 10px 20px; font-size: 16px;">
                        ← Regresar
                    </button>
                </body>
            </html>
            i  zP================================================================================)r   argsgetlowerr   r   r   generar_pdf_con_adjuntosr+   r,   r-   basenamedirnamereplacer   openreadior4   seekr   r   	traceback
format_exctype__name__r   )r   r"   r#   	resultadoarchivo_enviarnombre_descargar5   r1   farchivo_bytesr4   archivo_bufferr   rC   error_detailr0   s                  @r   generar_pdf_formulario9funcion_CotizFormQueryIng.<locals>.generar_pdf_formulario+   s=   < ,,""9-  " #<<++J?EEG6QLL$$UF399;vE	 	h56h(	23'(8'9:; ,-gkk)5EFGHIhy	,EE#!1#	I 27)<=? @Gi H	* + : BGGNN9U3C$D$D!*5!1"$''"2"2>"B&(ggoon&E#,+O+<=> "+5!1&/&=#$/S0I/J$"O,+O+<=>      , nd++q ! , #$]3N"!"-	  ,+&  M	$//1LG(O23(OHWI&'GA3- G)*,(O0@` AHy I<<@G<L<L;M N669!fX >" #/ 0m=z {= =!M	sP   !J )J ?J +J :B3J -I4>5J 4J	?J MB2M
M
MN)route)appmailr   rN   s   &&  r   funcion_CotizFormQueryIngrS      sN     	YY:UGYL? M?, 	YYAE7YSA TA    )N)flaskr   r   r   r   r   r   
flask_mailr	   ?Consultas_SQL.Operaciones.Ingenieria.Cotiz.CotizFormQueryIngSQLr
   <App.Operaciones_Module.Ingenieria.Cotiz.FormularioPDFServicer   r+   rS    rT   r   <module>rZ      s     \ [  Z ] 	_rT   