-
-
-
-
\ No newline at end of file
+
+
+
+ Enviando...
+
+
+
+
\ No newline at end of file
diff --git a/src/app/components/visor-pdf/visor-pdf.component.ts b/src/app/components/visor-pdf/visor-pdf.component.ts
index fab43a1..538f82b 100644
--- a/src/app/components/visor-pdf/visor-pdf.component.ts
+++ b/src/app/components/visor-pdf/visor-pdf.component.ts
@@ -2,21 +2,26 @@ import { Component, OnInit, inject } from '@angular/core';
import { CommonModule } from '@angular/common';
import { DynamicDialogRef, DynamicDialogConfig } from 'primeng/dynamicdialog';
import { SafePipe } from '../../../pipes/safe.pipe';
-
-import pdfMake from 'pdfmake/build/pdfmake';
-import pdfFonts from 'pdfmake/build/vfs_fonts';
-import { TDocumentDefinitions } from 'pdfmake/interfaces';
+import { ButtonModule } from 'primeng/button';
+import { ToastModule } from 'primeng/toast';
+import { ProgressSpinnerModule } from 'primeng/progressspinner';
import { MessageService } from 'primeng/api';
-pdfMake.vfs = pdfFonts.vfs;
+import { PdfService } from '../../services/pdf.service';
+import { AlertService } from '../../services/alert.service';
@Component({
selector: 'app-visor-pdf',
standalone: true,
- imports: [CommonModule, SafePipe],
+ imports: [
+ CommonModule,
+ SafePipe,
+ ButtonModule,
+ ToastModule,
+ ProgressSpinnerModule
+ ],
templateUrl: './visor-pdf.component.html',
- styleUrls: ['./visor-pdf.component.scss'],
- providers: [MessageService]
+ styleUrls: ['./visor-pdf.component.scss']
})
export class VisorPdfComponent implements OnInit {
product: any;
@@ -27,165 +32,8 @@ export class VisorPdfComponent implements OnInit {
private dialogRef = inject(DynamicDialogRef);
private config = inject(DynamicDialogConfig);
private messageService = inject(MessageService);
-
- docDefinition: TDocumentDefinitions = {
- content: [
- // Encabezado con información de empresa y cronograma
- {
- columns: [
- {
- width: '50%',
- text: 'Empresa: Constructora Los Andes S.A.',
- margin: [0, 0, 0, 5]
- },
- {
- width: '50%',
- text: [
- { text: 'Cronograma: SC-23-45\n' },
- { text: 'Nombre sistema: Terminal Portuario Norte' }
- ],
- alignment: 'right',
- margin: [0, 0, 0, 5]
- }
- ]
- },
-
- // Título y subtítulo
- {
- text: 'CRONOGRAMA BASE DE OBRAS E INVERSIONES',
- alignment: 'center',
- bold: true,
- fontSize: 12,
- margin: [0, 10, 0, 0]
- },
- {
- text: 'ACTUALIZACIÓN PLAN DE DESARROLLO O NUEVA CONCESIÓN',
- alignment: 'center',
- bold: true,
- fontSize: 11,
- margin: [0, 0, 0, 10]
- },
-
- // Tabla principal
- {
- table: {
- headerRows: 1,
- widths: ['10%', '12%', '23%', '12%', '10%', '10%', '10%', '13%'],
- body: [
- [
- { text: 'ETAPA', style: 'tableHeader', alignment: 'center' },
- { text: 'CÓDIGO GLOSA', style: 'tableHeader', alignment: 'center' },
- { text: 'DESCRIPCIÓN GLOSA', style: 'tableHeader', alignment: 'center' },
- { text: 'MONTO INVERSIÓN UF', style: 'tableHeader', alignment: 'center' },
- { text: 'AÑO INICIO', style: 'tableHeader', alignment: 'center' },
- { text: 'AÑO TERMINO', style: 'tableHeader', alignment: 'center' },
- { text: 'MES TERMINO', style: 'tableHeader', alignment: 'center' },
- { text: 'NOTA', style: 'tableHeader', alignment: 'center' }
- ],
- [
- { text: '1', alignment: 'center' },
- { text: 'INF-001', alignment: 'center' },
- { text: 'Estudios preliminares', alignment: 'left' },
- { text: '2,500', alignment: 'right' },
- { text: '2025', alignment: 'center' },
- { text: '2025', alignment: 'center' },
- { text: 'Julio', alignment: 'center' },
- { text: 'Fase inicial', alignment: 'left' }
- ],
- [
- { text: '2', alignment: 'center' },
- { text: 'MOV-102', alignment: 'center' },
- { text: 'Movimiento de tierras', alignment: 'left' },
- { text: '15,750', alignment: 'right' },
- { text: '2025', alignment: 'center' },
- { text: '2026', alignment: 'center' },
- { text: 'Enero', alignment: 'center' },
- { text: 'En terreno', alignment: 'left' }
- ],
- [
- { text: '3', alignment: 'center' },
- { text: 'CIM-203', alignment: 'center' },
- { text: 'Construcción de cimientos', alignment: 'left' },
- { text: '32,800', alignment: 'right' },
- { text: '2026', alignment: 'center' },
- { text: '2026', alignment: 'center' },
- { text: 'Mayo', alignment: 'center' },
- { text: 'Crítico', alignment: 'left' }
- ],
- [
- { text: '4', alignment: 'center' },
- { text: 'EST-304', alignment: 'center' },
- { text: 'Estructura principal', alignment: 'left' },
- { text: '65,420', alignment: 'right' },
- { text: '2026', alignment: 'center' },
- { text: '2027', alignment: 'center' },
- { text: 'Febrero', alignment: 'center' },
- { text: 'Alta inversión', alignment: 'left' }
- ],
- [
- { text: '5', alignment: 'center' },
- { text: 'TER-405', alignment: 'center' },
- { text: 'Terminaciones y acabados', alignment: 'left' },
- { text: '18,300', alignment: 'right' },
- { text: '2027', alignment: 'center' },
- { text: '2027', alignment: 'center' },
- { text: 'Octubre', alignment: 'center' },
- { text: 'Etapa final', alignment: 'left' }
- ]
- ]
- }
- },
-
- // Total
- {
- columns: [
- {
- width: '80%',
- text: 'TOTAL:',
- alignment: 'right',
- bold: true,
- margin: [0, 15, 10, 20]
- },
- {
- width: '20%',
- text: '134,770 UF',
- alignment: 'left',
- bold: true,
- margin: [0, 15, 0, 20]
- }
- ]
- },
-
- // Firma
- {
- text: 'X',
- alignment: 'center',
- bold: true,
- fontSize: 14,
- margin: [0, 15, 0, 0]
- },
- {
- text: 'Firma SSS',
- alignment: 'center',
- fontSize: 10,
- margin: [0, 0, 0, 10]
- }
- ],
-
- // Estilos
- styles: {
- tableHeader: {
- bold: true,
- fontSize: 10,
- fillColor: '#f2f2f2'
- }
- },
-
- // Definiciones de página
- pageSize: 'A4',
- pageOrientation: 'portrait',
- pageMargins: [40, 40, 40, 40]
- };
+ private pdfService = inject(PdfService);
+ private alertService = inject(AlertService);
ngOnInit() {
// Obtener el producto pasado a través del servicio de diálogo
@@ -196,33 +44,29 @@ export class VisorPdfComponent implements OnInit {
}
generarPDF() {
- const pdfDocGenerator = pdfMake.createPdf(this.docDefinition);
- pdfDocGenerator.getDataUrl((dataUrl) => {
+ this.pdfService.generateCronogramaPdf(this.product).then(dataUrl => {
this.pdfSrc = dataUrl;
});
}
descargarPDF() {
- pdfMake.createPdf(this.docDefinition).download('cronogramaspdf');
+ this.pdfService.downloadCronogramaPdf('cronograma', this.product);
}
+
enviarPDF() {
this.enviando = true;
console.log('Enviando PDF...');
-
+
setTimeout(() => {
this.enviando = false;
console.log('Mostrando mensaje de envio...')
-
- this.messageService.add({
- severity: 'success',
- summary: '¡Enviado con éxito!',
- detail: 'El cronograma ha sido enviado correctamente',
- life: 30000,
- });
+ this.alertService.success(
+ 'El cronograma ha sido enviado correctamente a la plataforma.',
+ '¡Enviado con éxito!'
+ );
}, 2000);
}
-
cerrar() {
this.dialogRef.close();
}
diff --git a/src/app/services/alert.service.ts b/src/app/services/alert.service.ts
new file mode 100644
index 0000000..da895db
--- /dev/null
+++ b/src/app/services/alert.service.ts
@@ -0,0 +1,128 @@
+import { Injectable, ComponentRef, createComponent, EnvironmentInjector, ApplicationRef } from '@angular/core';
+import { AlertDialogComponent, AlertDialogOptions } from '../components/alert-dialog/alert-dialog.component';
+
+@Injectable({
+ providedIn: 'root'
+})
+export class AlertService {
+ private alertRef: ComponentRef