function PlantillaCorrespondencia() { try { $this->objParam->addParametro('id_funcionario_usuario', $_SESSION["ss_id_funcionario"]); $this->objParam->defecto('ordenacion', 'id_correspondencia'); $this->objParam->defecto('dir_ordenacion', 'desc'); $this->objParam->addFiltro("cor.id_correspondencia = " . $this->objParam->getParametro('id_correspondencia')); $this->objFunc = $this->create('MODCorrespondencia'); $this->res = $this->objFunc->listarCorrespondencia(); if ($this->res->getTipo() == 'ERROR') { $this->res->imprimirRespuesta($this->res->generarJson()); exit; } $correspondencia = $this->res->getDatos(); //obtener detalle de envios $this->objParam->parametros_consulta['ordenacion'] = 'id_correspondencia'; $this->objParam->parametros_consulta['filtro'] = ' 0 = 0 '; $this->objParam->parametros_consulta['cantidad'] = '1000'; $this->objParam->addFiltro("cor.id_correspondencia_fk = " . $this->objParam->getParametro('id_correspondencia')); $this->objFunc = $this->create('MODCorrespondencia'); $this->res = $this->objFunc->listarCorrespondenciaDetalle($this->objParam); if ($this->res->getTipo() == 'ERROR') { $this->res->imprimirRespuesta($this->res->generarJson()); exit; } $correspondenciaDetalle = $this->res->getDatos(); //desc_funcionario -> es el funcionario que lo envia //desc_uo -> //numero numero de la correspondencia /*generamos una imagen qr para ingresar a la plantilla*/ $cadena_qr = '|' . $correspondencia[0]['numero'] . '|' . $correspondencia[0]['desc_uo'] . '|' . $correspondencia[0]['desc_funcionario'] . ''; $barcodeobj = new TCPDF2DBarcode($cadena_qr, 'QRCODE,M'); //todo cambiar ese nombre por algo randon $nombre_archivo = md5($_SESSION["ss_id_usuario_ai"] . $_SESSION["_SEMILLA"]); $png = $barcodeobj->getBarcodePngData($w = 8, $h = 8, $color = array(0, 0, 0)); $im = imagecreatefromstring($png); if ($im !== false) { header('Content-Type: image/png'); imagepng($im, dirname(__FILE__) . "/../../reportes_generados/" . $nombre_archivo . ".png"); imagedestroy($im); $img_qr = dirname(__FILE__) . "/../../reportes_generados/" . $nombre_archivo . ".png"; if ($correspondencia[0]['desc_ruta_plantilla_documento'] == NULL) { throw new Exception('no tiene plantilla o no esta en el formato correspondiente'); } /*agrego a la plantilla word los datos */ $templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor($correspondencia[0]['desc_ruta_plantilla_documento']); $templateProcessor->cloneRow('destinatario', count($correspondenciaDetalle)); for ($i = 0; $i < count($correspondenciaDetalle); $i++) { $xml_destinatario = htmlspecialchars($correspondenciaDetalle[$i]['desc_funcionario']) . '</w:t> </w:r> </w:p> <w:p w:rsidR="003D7875" w:rsidRDefault="006C602F" w:rsidP="006C602F"> <w:pPr> <w:pStyle w:val="Encabezado"/> <w:tabs> <w:tab w:val="clear" w:pos="4818"/> <w:tab w:val="left" w:pos="1276"/> <w:tab w:val="left" w:pos="2268"/> <w:tab w:val="left" w:pos="2552"/> </w:tabs> <w:jc w:val="both"/> <w:rPr> <w:b/> <w:bCs/> <w:iCs/> <w:color w:val="000000"/> <w:lang w:val="es-ES"/> </w:rPr> </w:pPr> <w:r> <w:rPr> <w:b/> <w:bCs/> <w:iCs/> <w:color w:val="000000"/> <w:lang w:val="es-ES"/> </w:rPr> <w:t>' . htmlspecialchars($correspondenciaDetalle[$i]["desc_cargo"]) . '</w:t> </w:r> </w:p>'; $numero_key = $i + 1; $key_name = '${destinatario#' . $numero_key . '}</w:t></w:r></w:p>'; $key_2 = '${destinatario#1}</w:t></w:r></w:p>'; $templateProcessor->setValueDestinatario($key_name, $xml_destinatario); //$templateProcessor->setValue($key_name, $correspondenciaDetalle[$i]['desc_funcionario'].'<br /> '.$correspondenciaDetalle[$i]['desc_cargo']); } setlocale(LC_ALL, "es_ES@euro", "es_ES", "esp"); $fecha_documento = strftime("%d/%m/%Y", strtotime($correspondencia[0]['fecha_documento'])); $templateProcessor->setImg('firma_digital', array('src' => $img_qr, 'swh' => '150')); $templateProcessor->setImgFooter('qr', array('src' => $img_qr, 'swh' => '250')); //$templateProcessor->setImgHeader('qrh',array('src' => $img_qr, 'swh'=>'250')); $templateProcessor->setValue('remitente', htmlspecialchars($correspondencia[0]['desc_funcionario'])); $templateProcessor->setValue('cargo_remitente', htmlspecialchars($correspondencia[0]['desc_cargo'])); $templateProcessor->setValue('referencia', htmlspecialchars($correspondencia[0]['referencia'])); $templateProcessor->setValue('fecha', htmlspecialchars($fecha_documento)); $templateProcessor->setValue('mensaje', htmlspecialchars($correspondencia[0]['mensaje'])); $templateProcessor->setValue('numero', htmlspecialchars($correspondencia[0]['numero'])); //$templateProcessor->setValue('uo', htmlspecialchars($correspondencia[0]['desc_uo'])); $templateProcessor->saveAs(dirname(__FILE__) . '/../../reportes_generados/' . $nombre_archivo . '.docx'); $temp['docx'] = $nombre_archivo . '.docx'; $this->res->setDatos($temp); $this->res->imprimirRespuesta($this->res->generarJson()); } else { echo 'ocurrio un error al guardar la imagen.'; } } catch (Exception $e) { throw new Exception($e->getMessage(), 2); } //fin catch }