91 lines
3.0 KiB
TypeScript
91 lines
3.0 KiB
TypeScript
import {Component, inject, OnInit, signal} from '@angular/core';
|
|
import {ModalNav} from "../modal-nav/modal-nav";
|
|
import {NzDividerComponent} from "ng-zorro-antd/divider";
|
|
import {NzIconDirective} from "ng-zorro-antd/icon";
|
|
import {NzTableComponent} from "ng-zorro-antd/table";
|
|
import {PurchaseOrderForm} from "../purchase-order-form/purchase-order-form";
|
|
import {ModalButton} from "../modal-button/modal-button";
|
|
import {GetPurchaseOrderDto, PurchaseordersService} from "../../services/api";
|
|
import {NzNotificationService} from "ng-zorro-antd/notification";
|
|
import {firstValueFrom} from "rxjs";
|
|
import {FileService} from "../../services/file.service";
|
|
|
|
@Component({
|
|
selector: 'app-purchase-order-table',
|
|
imports: [
|
|
ModalNav,
|
|
NzDividerComponent,
|
|
NzIconDirective,
|
|
NzTableComponent,
|
|
PurchaseOrderForm,
|
|
ModalButton,
|
|
],
|
|
templateUrl: './purchase-order-table.html',
|
|
styleUrl: './purchase-order-table.css',
|
|
})
|
|
export class PurchaseOrderTable implements OnInit {
|
|
private purchaseOrdersService = inject(PurchaseordersService);
|
|
private notificationService = inject(NzNotificationService);
|
|
private fileService = inject(FileService);
|
|
purchaseOrders = signal<GetPurchaseOrderDto[]>([]);
|
|
purchaseOrdersLoading = signal<boolean>(false);
|
|
|
|
async ngOnInit() {
|
|
await this.fetchPurchaseOrder();
|
|
}
|
|
|
|
async fetchPurchaseOrder() {
|
|
this.purchaseOrdersLoading.set(true)
|
|
|
|
try {
|
|
const purchaseOrders = await firstValueFrom(this.purchaseOrdersService.getAllPurchaseOrderEndpoint())
|
|
this.purchaseOrders.set(purchaseOrders);
|
|
} catch (e) {
|
|
this.notificationService.error(
|
|
'Erreur',
|
|
'Erreur de communication avec l\'API'
|
|
)
|
|
}
|
|
this.purchaseOrdersLoading.set(false)
|
|
}
|
|
|
|
async delete(purchaseOrderId:number) {
|
|
this.purchaseOrdersLoading.set(true)
|
|
try {
|
|
await firstValueFrom(this.purchaseOrdersService.deletePurchaseOrderEndpoint(purchaseOrderId))
|
|
this.notificationService.success(
|
|
'Success',
|
|
'Suppression effectuée'
|
|
)
|
|
} catch (e) {
|
|
this.notificationService.error(
|
|
'Erreur',
|
|
'Impossible de supprimer la ligne'
|
|
)
|
|
}
|
|
this.purchaseOrdersLoading.set(false)
|
|
await this.fetchPurchaseOrder();
|
|
}
|
|
|
|
async export(purchaseOrderId: number){
|
|
this.purchaseOrdersLoading.set(true)
|
|
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'
|
|
);
|
|
}
|
|
this.purchaseOrdersLoading.set(false)
|
|
}
|
|
|
|
transfer() {
|
|
return
|
|
}
|
|
}
|