print updates
This commit is contained in:
parent
b784d16902
commit
98acaa709b
@ -71,7 +71,9 @@ export class CarnetService {
|
||||
P_HEADERID: headerid,
|
||||
P_PRINTGL: 'N'
|
||||
}
|
||||
return this.http.post(`${this.apiUrl}/${this.apiDb}/PrintCarnet`, data);
|
||||
return this.http.post(`${this.apiUrl}/${this.apiDb}/PrintCarnet`, data, {
|
||||
responseType: 'blob', // Important: Set responseType to 'blob'
|
||||
});
|
||||
}
|
||||
|
||||
printGeneralList(headerid: number): Observable<any> {
|
||||
@ -89,9 +91,7 @@ export class CarnetService {
|
||||
P_USERID: this.userService.getUser(),
|
||||
P_CARNETNO: carnetNumber
|
||||
}
|
||||
return this.http.patch(`${this.apiUrl}/${this.apiDb}/DuplicateCarnet`, data, {
|
||||
responseType: 'blob', // Important: Set responseType to 'blob'
|
||||
});
|
||||
return this.http.patch(`${this.apiUrl}/${this.apiDb}/DuplicateCarnet`, data);
|
||||
}
|
||||
|
||||
extendCarnet(carnetNumber: string): Observable<any> {
|
||||
|
||||
@ -326,8 +326,12 @@ export class HomeComponent {
|
||||
printGeneralList(headerid: number): void {
|
||||
if (headerid) {
|
||||
this.carnetService.printGeneralList(headerid).subscribe({
|
||||
next: () => {
|
||||
next: (blob: Blob) => {
|
||||
|
||||
let filename = `${headerid}-GL.pdf`;
|
||||
|
||||
// Initiate download
|
||||
this.saveFile(blob, filename);
|
||||
},
|
||||
error: (error) => {
|
||||
let errorMessage = this.errorHandler.handleApiError(error, 'Failed to print general list');
|
||||
@ -402,4 +406,15 @@ export class HomeComponent {
|
||||
navigateTo(route: any[], extras?: any): void {
|
||||
this.navigationService.navigate(route, extras);
|
||||
}
|
||||
|
||||
private saveFile(blob: Blob, filename: string): void {
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = filename;
|
||||
document.body.appendChild(a); // Append to body to make it clickable in some browsers
|
||||
a.click();
|
||||
document.body.removeChild(a); // Clean up
|
||||
window.URL.revokeObjectURL(url);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user