added generation function for generate pdf
This commit is contained in:
@@ -10,6 +10,8 @@ import {DeliverynotesService, GetDeliveryNoteDto} from "../../services/api";
|
|||||||
import {NzNotificationService} from "ng-zorro-antd/notification";
|
import {NzNotificationService} from "ng-zorro-antd/notification";
|
||||||
import {firstValueFrom} from "rxjs";
|
import {firstValueFrom} from "rxjs";
|
||||||
import {format} from "date-fns";
|
import {format} from "date-fns";
|
||||||
|
import {HttpResponse} from "@angular/common/http";
|
||||||
|
import {FileService} from "../../services/file.service";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-deliverery-note-table',
|
selector: 'app-deliverery-note-table',
|
||||||
@@ -27,7 +29,8 @@ import {format} from "date-fns";
|
|||||||
})
|
})
|
||||||
export class DelivereryNoteTable implements OnInit {
|
export class DelivereryNoteTable implements OnInit {
|
||||||
private deliveryNotesService = inject(DeliverynotesService);
|
private deliveryNotesService = inject(DeliverynotesService);
|
||||||
private notificationService = inject(NzNotificationService)
|
private notificationService = inject(NzNotificationService);
|
||||||
|
private fileService = inject(FileService);
|
||||||
deliveryNotes = signal<GetDeliveryNoteDto[]>([]);
|
deliveryNotes = signal<GetDeliveryNoteDto[]>([]);
|
||||||
deliveryNotesLoading = signal<boolean>(false);
|
deliveryNotesLoading = signal<boolean>(false);
|
||||||
|
|
||||||
@@ -95,7 +98,19 @@ export class DelivereryNoteTable implements OnInit {
|
|||||||
await this.fetchDeliveryNotes()
|
await this.fetchDeliveryNotes()
|
||||||
}
|
}
|
||||||
|
|
||||||
export(deliveryNote: number) {
|
async export(deliveryNoteId: number) {
|
||||||
return
|
try {
|
||||||
|
const pdf = await firstValueFrom(
|
||||||
|
this.deliveryNotesService.getDeliveryNotePdfEndpoint(deliveryNoteId, "response")
|
||||||
|
);
|
||||||
|
this.fileService.downloadBlob(pdf)
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
this.notificationService.error(
|
||||||
|
'Erreur',
|
||||||
|
'Impossible de générer un PDF'
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,7 +67,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<nz-divider nzType="vertical"></nz-divider>
|
<nz-divider nzType="vertical"></nz-divider>
|
||||||
<div>
|
<div>
|
||||||
<nz-icon nzType="export" nzTheme="outline" (click)="export()" class="cursor-pointer text-green-700"/>
|
<nz-icon nzType="export" nzTheme="outline" (click)="export(purchaseOrder.id)" class="cursor-pointer text-green-700"/>
|
||||||
</div>
|
</div>
|
||||||
<nz-divider nzType="vertical"></nz-divider>
|
<nz-divider nzType="vertical"></nz-divider>
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import {ModalButton} from "../modal-button/modal-button";
|
|||||||
import {GetPurchaseOrderDto, PurchaseordersService} from "../../services/api";
|
import {GetPurchaseOrderDto, PurchaseordersService} from "../../services/api";
|
||||||
import {NzNotificationService} from "ng-zorro-antd/notification";
|
import {NzNotificationService} from "ng-zorro-antd/notification";
|
||||||
import {firstValueFrom} from "rxjs";
|
import {firstValueFrom} from "rxjs";
|
||||||
|
import {FileService} from "../../services/file.service";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-purchase-order-table',
|
selector: 'app-purchase-order-table',
|
||||||
@@ -24,7 +25,8 @@ import {firstValueFrom} from "rxjs";
|
|||||||
})
|
})
|
||||||
export class PurchaseOrderTable implements OnInit {
|
export class PurchaseOrderTable implements OnInit {
|
||||||
private purchaseOrdersService = inject(PurchaseordersService);
|
private purchaseOrdersService = inject(PurchaseordersService);
|
||||||
private notificationService = inject(NzNotificationService)
|
private notificationService = inject(NzNotificationService);
|
||||||
|
private fileService = inject(FileService);
|
||||||
purchaseOrders = signal<GetPurchaseOrderDto[]>([]);
|
purchaseOrders = signal<GetPurchaseOrderDto[]>([]);
|
||||||
purchaseOrdersLoading = signal<boolean>(false);
|
purchaseOrdersLoading = signal<boolean>(false);
|
||||||
|
|
||||||
@@ -63,8 +65,19 @@ export class PurchaseOrderTable implements OnInit {
|
|||||||
await this.fetchPurchaseOrder();
|
await this.fetchPurchaseOrder();
|
||||||
}
|
}
|
||||||
|
|
||||||
export(){
|
async export(purchaseOrderId: number){
|
||||||
return
|
try {
|
||||||
|
const pdf = await firstValueFrom(
|
||||||
|
this.purchaseOrdersService.getPurchaseOrderPdfEndpoint(purchaseOrderId, "response")
|
||||||
|
);
|
||||||
|
this.fileService.downloadBlob(pdf)
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
this.notificationService.error(
|
||||||
|
'Erreur',
|
||||||
|
'Impossible de générer un PDF'
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
transfer() {
|
transfer() {
|
||||||
|
|||||||
@@ -65,7 +65,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<nz-divider nzType="vertical"></nz-divider>
|
<nz-divider nzType="vertical"></nz-divider>
|
||||||
<div>
|
<div>
|
||||||
<nz-icon nzType="export" nzTheme="outline" class="cursor-pointer text-green-700"/>
|
<nz-icon nzType="export" (click)="export(quotation.id)" nzTheme="outline" class="cursor-pointer text-green-700"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import {QuotationForm} from "../quotation-form/quotation-form";
|
|||||||
import {GetQuotationDto, QuotationsService} from "../../services/api";
|
import {GetQuotationDto, QuotationsService} from "../../services/api";
|
||||||
import {NzNotificationService} from "ng-zorro-antd/notification";
|
import {NzNotificationService} from "ng-zorro-antd/notification";
|
||||||
import {firstValueFrom} from "rxjs";
|
import {firstValueFrom} from "rxjs";
|
||||||
|
import {FileService} from "../../services/file.service";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-quotation-table',
|
selector: 'app-quotation-table',
|
||||||
@@ -25,7 +26,8 @@ import {firstValueFrom} from "rxjs";
|
|||||||
|
|
||||||
export class QuotationTable implements OnInit {
|
export class QuotationTable implements OnInit {
|
||||||
private quotationsService = inject(QuotationsService);
|
private quotationsService = inject(QuotationsService);
|
||||||
private notificationService = inject(NzNotificationService)
|
private notificationService = inject(NzNotificationService);
|
||||||
|
private fileService = inject(FileService);
|
||||||
quotations = signal<GetQuotationDto[]>([]);
|
quotations = signal<GetQuotationDto[]>([]);
|
||||||
quotationsLoading = signal<boolean>(false);
|
quotationsLoading = signal<boolean>(false);
|
||||||
|
|
||||||
@@ -63,5 +65,20 @@ export class QuotationTable implements OnInit {
|
|||||||
}
|
}
|
||||||
await this.fetchQuotations();
|
await this.fetchQuotations();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async export(quotationId: number){
|
||||||
|
try {
|
||||||
|
const pdf = await firstValueFrom(
|
||||||
|
this.quotationsService.getQuotationPdfEndpoint(quotationId, "response")
|
||||||
|
);
|
||||||
|
this.fileService.downloadBlob(pdf)
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
this.notificationService.error(
|
||||||
|
'Erreur',
|
||||||
|
'Impossible de générer un PDF'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -260,6 +260,49 @@ export class DeliverynotesService extends BaseService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @endpoint get /API/deliveryNotes/{id}/pdf
|
||||||
|
* @param id
|
||||||
|
* @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
|
||||||
|
* @param reportProgress flag to report request and response progress.
|
||||||
|
*/
|
||||||
|
public getDeliveryNotePdfEndpoint(id: number, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/pdf', context?: HttpContext, transferCache?: boolean}): Observable<Blob>;
|
||||||
|
public getDeliveryNotePdfEndpoint(id: number, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/pdf', context?: HttpContext, transferCache?: boolean}): Observable<HttpResponse<Blob>>;
|
||||||
|
public getDeliveryNotePdfEndpoint(id: number, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/pdf', context?: HttpContext, transferCache?: boolean}): Observable<HttpEvent<Blob>>;
|
||||||
|
public getDeliveryNotePdfEndpoint(id: number, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/pdf', context?: HttpContext, transferCache?: boolean}): Observable<any> {
|
||||||
|
if (id === null || id === undefined) {
|
||||||
|
throw new Error('Required parameter id was null or undefined when calling getDeliveryNotePdfEndpoint.');
|
||||||
|
}
|
||||||
|
|
||||||
|
let localVarHeaders = this.defaultHeaders;
|
||||||
|
|
||||||
|
const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([
|
||||||
|
'application/pdf'
|
||||||
|
]);
|
||||||
|
if (localVarHttpHeaderAcceptSelected !== undefined) {
|
||||||
|
localVarHeaders = localVarHeaders.set('Accept', localVarHttpHeaderAcceptSelected);
|
||||||
|
}
|
||||||
|
|
||||||
|
const localVarHttpContext: HttpContext = options?.context ?? new HttpContext();
|
||||||
|
|
||||||
|
const localVarTransferCache: boolean = options?.transferCache ?? true;
|
||||||
|
|
||||||
|
|
||||||
|
let localVarPath = `/API/deliveryNotes/${this.configuration.encodeParam({name: "id", value: id, in: "path", style: "simple", explode: false, dataType: "number", dataFormat: "int32"})}/pdf`;
|
||||||
|
const { basePath, withCredentials } = this.configuration;
|
||||||
|
return this.httpClient.request('get', `${basePath}${localVarPath}`,
|
||||||
|
{
|
||||||
|
context: localVarHttpContext,
|
||||||
|
responseType: "blob",
|
||||||
|
...(withCredentials ? { withCredentials } : {}),
|
||||||
|
headers: localVarHeaders,
|
||||||
|
observe: observe,
|
||||||
|
...(localVarTransferCache !== undefined ? { transferCache: localVarTransferCache } : {}),
|
||||||
|
reportProgress: reportProgress
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @endpoint patch /API/deliveryNotes/{id}
|
* @endpoint patch /API/deliveryNotes/{id}
|
||||||
* @param id
|
* @param id
|
||||||
|
|||||||
@@ -194,6 +194,49 @@ export class PurchaseordersService extends BaseService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @endpoint get /API/purchaseOrders/{id}/pdf
|
||||||
|
* @param id
|
||||||
|
* @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
|
||||||
|
* @param reportProgress flag to report request and response progress.
|
||||||
|
*/
|
||||||
|
public getPurchaseOrderPdfEndpoint(id: number, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/pdf', context?: HttpContext, transferCache?: boolean}): Observable<Blob>;
|
||||||
|
public getPurchaseOrderPdfEndpoint(id: number, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/pdf', context?: HttpContext, transferCache?: boolean}): Observable<HttpResponse<Blob>>;
|
||||||
|
public getPurchaseOrderPdfEndpoint(id: number, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/pdf', context?: HttpContext, transferCache?: boolean}): Observable<HttpEvent<Blob>>;
|
||||||
|
public getPurchaseOrderPdfEndpoint(id: number, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/pdf', context?: HttpContext, transferCache?: boolean}): Observable<any> {
|
||||||
|
if (id === null || id === undefined) {
|
||||||
|
throw new Error('Required parameter id was null or undefined when calling getPurchaseOrderPdfEndpoint.');
|
||||||
|
}
|
||||||
|
|
||||||
|
let localVarHeaders = this.defaultHeaders;
|
||||||
|
|
||||||
|
const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([
|
||||||
|
'application/pdf'
|
||||||
|
]);
|
||||||
|
if (localVarHttpHeaderAcceptSelected !== undefined) {
|
||||||
|
localVarHeaders = localVarHeaders.set('Accept', localVarHttpHeaderAcceptSelected);
|
||||||
|
}
|
||||||
|
|
||||||
|
const localVarHttpContext: HttpContext = options?.context ?? new HttpContext();
|
||||||
|
|
||||||
|
const localVarTransferCache: boolean = options?.transferCache ?? true;
|
||||||
|
|
||||||
|
|
||||||
|
let localVarPath = `/API/purchaseOrders/${this.configuration.encodeParam({name: "id", value: id, in: "path", style: "simple", explode: false, dataType: "number", dataFormat: "int32"})}/pdf`;
|
||||||
|
const { basePath, withCredentials } = this.configuration;
|
||||||
|
return this.httpClient.request('get', `${basePath}${localVarPath}`,
|
||||||
|
{
|
||||||
|
context: localVarHttpContext,
|
||||||
|
responseType: "blob",
|
||||||
|
...(withCredentials ? { withCredentials } : {}),
|
||||||
|
headers: localVarHeaders,
|
||||||
|
observe: observe,
|
||||||
|
...(localVarTransferCache !== undefined ? { transferCache: localVarTransferCache } : {}),
|
||||||
|
reportProgress: reportProgress
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @endpoint patch /API/purchaseOrders/{id}/PurchaseConditions
|
* @endpoint patch /API/purchaseOrders/{id}/PurchaseConditions
|
||||||
* @param id
|
* @param id
|
||||||
|
|||||||
@@ -194,6 +194,49 @@ export class QuotationsService extends BaseService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @endpoint get /API/quotations/{id}/pdf
|
||||||
|
* @param id
|
||||||
|
* @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
|
||||||
|
* @param reportProgress flag to report request and response progress.
|
||||||
|
*/
|
||||||
|
public getQuotationPdfEndpoint(id: number, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/pdf', context?: HttpContext, transferCache?: boolean}): Observable<Blob>;
|
||||||
|
public getQuotationPdfEndpoint(id: number, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/pdf', context?: HttpContext, transferCache?: boolean}): Observable<HttpResponse<Blob>>;
|
||||||
|
public getQuotationPdfEndpoint(id: number, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/pdf', context?: HttpContext, transferCache?: boolean}): Observable<HttpEvent<Blob>>;
|
||||||
|
public getQuotationPdfEndpoint(id: number, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/pdf', context?: HttpContext, transferCache?: boolean}): Observable<any> {
|
||||||
|
if (id === null || id === undefined) {
|
||||||
|
throw new Error('Required parameter id was null or undefined when calling getQuotationPdfEndpoint.');
|
||||||
|
}
|
||||||
|
|
||||||
|
let localVarHeaders = this.defaultHeaders;
|
||||||
|
|
||||||
|
const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([
|
||||||
|
'application/pdf'
|
||||||
|
]);
|
||||||
|
if (localVarHttpHeaderAcceptSelected !== undefined) {
|
||||||
|
localVarHeaders = localVarHeaders.set('Accept', localVarHttpHeaderAcceptSelected);
|
||||||
|
}
|
||||||
|
|
||||||
|
const localVarHttpContext: HttpContext = options?.context ?? new HttpContext();
|
||||||
|
|
||||||
|
const localVarTransferCache: boolean = options?.transferCache ?? true;
|
||||||
|
|
||||||
|
|
||||||
|
let localVarPath = `/API/quotations/${this.configuration.encodeParam({name: "id", value: id, in: "path", style: "simple", explode: false, dataType: "number", dataFormat: "int32"})}/pdf`;
|
||||||
|
const { basePath, withCredentials } = this.configuration;
|
||||||
|
return this.httpClient.request('get', `${basePath}${localVarPath}`,
|
||||||
|
{
|
||||||
|
context: localVarHttpContext,
|
||||||
|
responseType: "blob",
|
||||||
|
...(withCredentials ? { withCredentials } : {}),
|
||||||
|
headers: localVarHeaders,
|
||||||
|
observe: observe,
|
||||||
|
...(localVarTransferCache !== undefined ? { transferCache: localVarTransferCache } : {}),
|
||||||
|
reportProgress: reportProgress
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @endpoint patch /API/quotations/{id}/saleConditions
|
* @endpoint patch /API/quotations/{id}/saleConditions
|
||||||
* @param id
|
* @param id
|
||||||
|
|||||||
31
src/app/services/file.service.ts
Normal file
31
src/app/services/file.service.ts
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import {HttpResponse} from "@angular/common/http";
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root',
|
||||||
|
})
|
||||||
|
export class FileService {
|
||||||
|
getFilenameFromHttpResponse(httpResponse: HttpResponse<Blob>) {
|
||||||
|
const contentDispositionHeader = httpResponse.headers.get('Content-Disposition');
|
||||||
|
// console.log(contentDispositionHeader);
|
||||||
|
let result = contentDispositionHeader.split(';')[1].trim().split('=')[1];
|
||||||
|
// Removing the " from the after trim operation
|
||||||
|
result = result.replace(/"/g, '');
|
||||||
|
// Removing . from filename
|
||||||
|
// return result.replace(/./g, '_');
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
downloadBlob(data: HttpResponse<Blob>) {
|
||||||
|
const url = window.URL.createObjectURL(data.body);
|
||||||
|
const anchor = document.createElement('a');
|
||||||
|
|
||||||
|
anchor.download = this.getFilenameFromHttpResponse(data);
|
||||||
|
anchor.href = url;
|
||||||
|
anchor.click();
|
||||||
|
anchor.remove();
|
||||||
|
|
||||||
|
window.URL.revokeObjectURL(url);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user