Skip to content

Commit

Permalink
Adds dowload file button to recibo-venta-actions-bar component.
Browse files Browse the repository at this point in the history
  • Loading branch information
facundososalopez committed Mar 24, 2023
1 parent e5a73ad commit 73a7241
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
<fa-icon [icon]="['far', 'eye']"></fa-icon>
</button>
</li>
<li class="list-inline-item" *ngIf="recibo.idCliente && !hiddenButtonsValues['download']">
<button class="btn btn-primary" (click)="downloadReciboPdf()" placement="left" ngbPopover="Descargar Archivo" triggers="mouseenter:mouseleave" *ngIf="recibo.idCliente">
<fa-icon [icon]="['fas', 'file-download']"></fa-icon>
</button>
</li>
<li class="list-inline-item" *ngIf="hasRoleToCrearNota && !hiddenButtonsValues['create-nota-debito']">
<button class="btn btn-primary" (click)="crearNotaDeDebitoRecibo()"
ngbPopover="Crear Nota de Débito" placement="left" triggers="mouseenter:mouseleave">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,19 @@ export class ReciboVentaActionsBarComponent extends ReciboActionsBarDirective {
error: err => this.mensajeService.msg(err.error, MensajeModalType.ERROR),
});
}

downloadReciboPdf() {
this.loadingOverlayService.activate();
this.recibosService.getReporteRecibo(this.recibo.idRecibo)
.pipe(finalize(() => this.loadingOverlayService.deactivate()))
.subscribe({
next: res => {
const file = new Blob([res], {type: 'application/pdf'});
const fileURL = URL.createObjectURL(file);
window.open(fileURL, '_blank');
},
error: () => this.mensajeService.msg('Error al generar el reporte', MensajeModalType.ERROR),
})
;
}
}
3 changes: 0 additions & 3 deletions src/app/components/ver-recibo/ver-recibo.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ <h1 class="h3 flex-fill text-truncate">
[recibo]="recibo"
(afterDelete)="volverAlListado()">
</app-recibo-venta-actions-bar>
<button class="btn btn-primary" (click)="downloadReciboPdf()" placement="left" ngbPopover="Descargar Archivo" triggers="mouseenter:mouseleave" *ngIf="recibo.idCliente">
<fa-icon [icon]="['fas', 'file-download']"></fa-icon>
</button>
</div>
</div>
<table class="table table-bordered table-sm">
Expand Down
15 changes: 0 additions & 15 deletions src/app/components/ver-recibo/ver-recibo.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,4 @@ export class VerReciboComponent implements OnInit {
volverAlListado() {
this.location.back();
}

downloadReciboPdf() {
this.loadingOverlayService.activate();
this.recibosService.getReporteRecibo(this.recibo.idRecibo)
.pipe(finalize(() => this.loadingOverlayService.deactivate()))
.subscribe({
next: res => {
const file = new Blob([res], {type: 'application/pdf'});
const fileURL = URL.createObjectURL(file);
window.open(fileURL, '_blank');
},
error: () => this.mensajeService.msg('Error al generar el reporte', MensajeModalType.ERROR),
})
;
}
}
3 changes: 2 additions & 1 deletion src/app/directives/recibo-actions-bar.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Router } from '@angular/router';
import { Recibo } from './../models/recibo';
import { Directive, Input, Output, EventEmitter, OnInit } from '@angular/core';

type ReciboActionButtonName = 'show'|'create-nota-debito'|'delete';
type ReciboActionButtonName = 'show'|'create-nota-debito'|'delete'|'download';

@Directive()
export abstract class ReciboActionsBarDirective implements OnInit {
Expand Down Expand Up @@ -44,6 +44,7 @@ export abstract class ReciboActionsBarDirective implements OnInit {
'show': false,
'delete': false,
'create-nota-debito': false,
'download': false,
};

protected constructor(protected router: Router,
Expand Down

0 comments on commit 73a7241

Please sign in to comment.