Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
51 / 51 |
|
100.00% |
1 / 1 |
CRAP | n/a |
0 / 0 |
|
| authorization_build_html | |
100.00% |
51 / 51 |
|
100.00% |
1 / 1 |
4 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * @file |
| 5 | * Shared HTML template builder for fiscal authorization PDFs. |
| 6 | */ |
| 7 | |
| 8 | declare(strict_types=1); |
| 9 | |
| 10 | /** |
| 11 | * Build authorization PDF HTML preserving legal contents from current template. |
| 12 | * |
| 13 | * @param array<string, mixed> $payload Request payload. |
| 14 | * @param array<string, string> $certificateSignatureData Visible signer certificate metadata. |
| 15 | * @return string HTML content. |
| 16 | */ |
| 17 | function authorization_build_html(array $payload, array $certificateSignatureData = []): string |
| 18 | { |
| 19 | $safe = static function (string $value): string { |
| 20 | return htmlspecialchars($value, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); |
| 21 | }; |
| 22 | |
| 23 | $isLegalRepresentative = ((string) ($payload['isLegalRepresentative'] ?? '0')) === '1'; |
| 24 | $signDate = date('Y-m-d'); |
| 25 | $authorizationStartDate = $signDate; |
| 26 | $authorizationEndDate = ''; |
| 27 | $yesNo = static function (bool $value): string { |
| 28 | return $value ? 'SI' : 'NO'; |
| 29 | }; |
| 30 | $certificateValue = static function (string $key) use ($certificateSignatureData): string { |
| 31 | $value = $certificateSignatureData[$key] ?? ''; |
| 32 | return trim((string) $value); |
| 33 | }; |
| 34 | $printableOrDash = static function (string $value): string { |
| 35 | return trim($value) !== '' ? $value : '-'; |
| 36 | }; |
| 37 | $isDigitallySigned = !empty($certificateSignatureData); |
| 38 | $authorizedRepresentativeName = (string) \AppConstants::SoftwareDeveloperName(); |
| 39 | $authorizedRepresentativeTaxId = (string) \AppConstants::SoftwareDeveloperTaxId(); |
| 40 | |
| 41 | return '<!DOCTYPE html> |
| 42 | <html> |
| 43 | <head> |
| 44 | <meta charset="utf-8"/> |
| 45 | <style> |
| 46 | body { font-family: DejaVu Sans, sans-serif; font-size: 10px; margin: 18px; color: #0f1720; } |
| 47 | h1 { font-size: 16px; margin: 0 0 4px 0; } |
| 48 | h2 { font-size: 12px; margin: 14px 0 6px 0; border-bottom: 1px solid #193c70; color: #193c70; } |
| 49 | h3 { font-size: 10px; margin: 10px 0 4px 0; color: #193c70; } |
| 50 | p { margin: 3px 0; line-height: 1.35; } |
| 51 | .meta { font-size: 9px; color: #475569; margin: 0 0 2px 0; } |
| 52 | .box { border: 1px solid #193c70; border-radius: 4px; padding: 6px; margin-top: 6px; background: #f8fbff; } |
| 53 | .page-break { page-break-after: always; } |
| 54 | .row { display: block; margin-bottom: 2px; } |
| 55 | .label { font-weight: bold; color: #193c70; } |
| 56 | .sig-line { margin-top: 30px; border-top: 1px solid #1f2937; width: 280px; padding-top: 4px; } |
| 57 | </style> |
| 58 | </head> |
| 59 | <body> |
| 60 | <h1>AUTORIZACION DE REPRESENTACION</h1> |
| 61 | <p class="meta">Emision de Registros de Facturacion · VeriFactu / TicketBAI · Factura Electronica (Factura-e)</p> |
| 62 | <p class="meta">RD 1007/2023 · Decreto 1/2023 · Ley 25/2013 · Ley 18/2022 · RD 1619/2012 · RGPD (UE) 2016/679</p> |
| 63 | |
| 64 | <h2>CERTIFICADO DE FIRMA UTILIZADO</h2> |
| 65 | <div class="box"> |
| 66 | <p class="row"><span class="label">Titular del certificado:</span> '.$safe($printableOrDash($certificateValue('subjectName'))).'</p> |
| 67 | <p class="row"><span class="label">NIF/CIF detectado:</span> '.$safe($printableOrDash($certificateValue('subjectTaxId'))).'</p> |
| 68 | <p class="row"><span class="label">Numero de serie:</span> '.$safe($printableOrDash($certificateValue('serialNumber'))).'</p> |
| 69 | <p class="row"><span class="label">Entidad emisora:</span> '.$safe($printableOrDash($certificateValue('issuerName'))).'</p> |
| 70 | <p class="row"><span class="label">Valido desde:</span> '.$safe($printableOrDash($certificateValue('validFrom'))).'</p> |
| 71 | <p class="row"><span class="label">Valido hasta:</span> '.$safe($printableOrDash($certificateValue('validTo'))).'</p> |
| 72 | <p class="row"><span class="label">Huella SHA-256:</span> '.$safe($printableOrDash($certificateValue('fingerprintSha256'))).'</p> |
| 73 | </div> |
| 74 | |
| 75 | <h2>1. DATOS DEL AUTORIZANTE (EMPRESA O PERSONA FISICA)</h2> |
| 76 | <div class="box"> |
| 77 | <p class="row"><span class="label">Razon social / Nombre completo:</span> '.$safe((string) ($payload['authorizerName'] ?? '')).'</p> |
| 78 | <p class="row"><span class="label">NIF / CIF:</span> '.$safe((string) ($payload['authorizerTaxId'] ?? '')).'</p> |
| 79 | <p class="row"><span class="label">Domicilio fiscal:</span> '.$safe((string) ($payload['authorizerAddress'] ?? '')).'</p> |
| 80 | <p class="row"><span class="label">Correo electronico:</span> '.$safe((string) ($payload['authorizerEmail'] ?? '')).'</p> |
| 81 | <p class="row"><span class="label">Telefono de contacto:</span> '.$safe((string) ($payload['authorizerPhone'] ?? '')).'</p> |
| 82 | </div> |
| 83 | |
| 84 | <h3>Representante legal del autorizante (si es persona juridica)</h3> |
| 85 | <div class="box"> |
| 86 | <p class="row"><span class="label">Indicado en formulario:</span> '.$yesNo($isLegalRepresentative).'</p> |
| 87 | <p class="row"><span class="label">Nombre y apellidos:</span> '.$safe((string) ($payload['legalRepresentativeName'] ?? '')).'</p> |
| 88 | <p class="row"><span class="label">NIF:</span> '.$safe((string) ($payload['legalRepresentativeTaxId'] ?? '')).'</p> |
| 89 | <p class="row"><span class="label">Cargo / Apoderamiento:</span> '.$safe((string) ($payload['legalRepresentativeRole'] ?? '')).'</p> |
| 90 | <p class="row"><span class="label">Num. escritura / poder notarial:</span> '.$safe((string) ($payload['legalRepresentativeDocument'] ?? '')).'</p> |
| 91 | </div> |
| 92 | |
| 93 | <h2>2. DATOS DEL REPRESENTANTE AUTORIZADO</h2> |
| 94 | <div class="box"> |
| 95 | <p class="row"><span class="label">Denominacion social:</span> '.$safe($authorizedRepresentativeName).'</p> |
| 96 | <p class="row"><span class="label">NIF / CIF:</span> '.$safe($authorizedRepresentativeTaxId).'</p> |
| 97 | <p class="row"><span class="label">Forma juridica:</span> Sociedad de Responsabilidad Limitada</p> |
| 98 | <p class="row"><span class="label">Actividad / Objeto social:</span> Desarrollo de soluciones informaticas para facturacion electronica</p> |
| 99 | <p class="row"><span class="label">CNAE principal:</span> 6201 - Actividades de programacion informatica</p> |
| 100 | </div> |
| 101 | |
| 102 | <div class="page-break"></div> |
| 103 | |
| 104 | <h1>AUTORIZACION DE REPRESENTACION</h1> |
| 105 | <p class="meta">Emision de Registros de Facturacion · VeriFactu / TicketBAI · Factura Electronica (Factura-e)</p> |
| 106 | <p class="meta">RD 1007/2023 · Decreto 1/2023 · Ley 25/2013 · Ley 18/2022 · RD 1619/2012 · RGPD (UE) 2016/679</p> |
| 107 | |
| 108 | <h2>3. OBJETO Y ALCANCE DE LA AUTORIZACION</h2> |
| 109 | <div class="box"> |
| 110 | <p class="row"><span class="label">Sistema(s) al que aplica:</span> VeriFactu, TicketBAI y Factura-e</p> |
| 111 | <p class="row"><span class="label">Facultades conferidas:</span> Generacion y firma electronica de registros y facturas, envio a AEAT/Haciendas Forales/FACe, conservacion y custodia, anulacion y rectificacion, consulta de estados.</p> |
| 112 | <p class="row"><span class="label">Fecha de inicio de la autorizacion:</span> '.$safe($authorizationStartDate).'</p> |
| 113 | <p class="row"><span class="label">Fecha de fin (vacio = indefinida):</span> '.$safe($authorizationEndDate).'</p> |
| 114 | </div> |
| 115 | |
| 116 | <h2>4. DECLARACIONES Y CLAUSULAS LEGALES</h2> |
| 117 | <div class="box"> |
| 118 | <p>1. El autorizante declara, bajo su responsabilidad, que la informacion proporcionada es veraz y completa, y que dispone de plenas facultades para otorgar la presente autorizacion.</p> |
| 119 | <p>2. En materia de registros de facturacion, '.$safe($authorizedRepresentativeName).' actuara conforme al articulo 4 del Real Decreto 1007/2023, de 5 de diciembre (VeriFactu), y a los Decretos Forales del Pais Vasco y normativa foral de Navarra que regulan el sistema TicketBAI.</p> |
| 120 | <p>3. En materia de factura electronica (Factura-e), la representacion se ampara en la Ley 25/2013, la Ley 18/2022, el RD 1619/2012 y el Reglamento (UE) 910/2014 (eIDAS).</p> |
| 121 | <p>4. El representante tratara los datos del autorizante unicamente para los fines indicados, conforme al RGPD y la LOPDGDD.</p> |
| 122 | <p>5. Esta autorizacion no transfiere al representante la titularidad de los derechos y obligaciones tributarias derivados de las facturas emitidas.</p> |
| 123 | <p>6. Para cualquier controversia derivada de este documento, las partes se someten a los Juzgados y Tribunales del domicilio del autorizante, con renuncia expresa a cualquier otro fuero.</p> |
| 124 | </div> |
| 125 | |
| 126 | <div class="page-break"></div> |
| 127 | |
| 128 | <h1>AUTORIZACION DE REPRESENTACION</h1> |
| 129 | <p class="meta">Emision de Registros de Facturacion · VeriFactu / TicketBAI · Factura Electronica (Factura-e)</p> |
| 130 | <p class="meta">RD 1007/2023 · Decreto 1/2023 · Ley 25/2013 · Ley 18/2022 · RD 1619/2012 · RGPD (UE) 2016/679</p> |
| 131 | |
| 132 | <h2>5. LUGAR, FECHA Y FIRMAS</h2> |
| 133 | <div class="box"> |
| 134 | <p class="row"><span class="label">Lugar de firma:</span> '.$safe((string) ($payload['signatureCity'] ?? '')).'</p> |
| 135 | <p class="row"><span class="label">Fecha de firma:</span> '.$safe($signDate).'</p> |
| 136 | </div> |
| 137 | '.($isDigitallySigned |
| 138 | ? '<p>Documento firmado digitalmente. La evidencia del certificado utilizado consta en la seccion "CERTIFICADO DE FIRMA UTILIZADO".</p>' |
| 139 | : '<p class="sig-line">Por el AUTORIZANTE</p> |
| 140 | <p>Firma y sello de la empresa / persona fisica</p>' |
| 141 | ).' |
| 142 | |
| 143 | </body> |
| 144 | </html>'; |
| 145 | } |
| 146 | ?> |