add getall and delete function from quotation page
This commit is contained in:
@@ -1,27 +1,13 @@
|
||||
import { Component } from '@angular/core';
|
||||
import {Component, inject, OnInit, signal} from '@angular/core';
|
||||
import {NzTableComponent} from "ng-zorro-antd/table";
|
||||
import {ModalButton} from "../modal-button/modal-button";
|
||||
import {ModalNav} from "../modal-nav/modal-nav";
|
||||
import {NzDividerComponent} from "ng-zorro-antd/divider";
|
||||
import {NzIconDirective} from "ng-zorro-antd/icon";
|
||||
import {QuotationForm} from "../quotation-form/quotation-form";
|
||||
import {ProductTable} from "../product-table/product-table";
|
||||
import {ProductForm} from "../product-form/product-form";
|
||||
|
||||
interface QuotationInfo {
|
||||
quotationId: number;
|
||||
quotationMessage?: string;
|
||||
quotationConditionsSale?: string;
|
||||
quotationProduct: [
|
||||
{ quotationProductReference: string; },
|
||||
{ quotationProductName: string; },
|
||||
{ quotationProductQuantity?: number; },
|
||||
],
|
||||
quotationProductReference: string;
|
||||
quotationProductName: string;
|
||||
quotationProductQuantity?: number;
|
||||
Supplier?: string;
|
||||
}
|
||||
import {GetQuotationDto, QuotationsService} from "../../services/api";
|
||||
import {NzNotificationService} from "ng-zorro-antd/notification";
|
||||
import {firstValueFrom} from "rxjs";
|
||||
|
||||
@Component({
|
||||
selector: 'app-quotation-table',
|
||||
@@ -32,56 +18,50 @@ interface QuotationInfo {
|
||||
NzIconDirective,
|
||||
NzTableComponent,
|
||||
QuotationForm,
|
||||
ProductForm
|
||||
],
|
||||
templateUrl: './quotation-table.html',
|
||||
styleUrl: './quotation-table.css',
|
||||
})
|
||||
|
||||
export class QuotationTable {
|
||||
quotations: QuotationInfo[] = [
|
||||
{
|
||||
quotationId: 101,
|
||||
quotationMessage: 'Livraison urgente demandée',
|
||||
quotationConditionsSale: 'Paiement à 30 jours',
|
||||
quotationProduct: [
|
||||
{ quotationProductReference: 'DLV-1000' },
|
||||
{ quotationProductName: 'Produit1'},
|
||||
{ quotationProductQuantity: 5 },
|
||||
],
|
||||
quotationProductReference: 'DLV-1000',
|
||||
quotationProductName: 'Produit1',
|
||||
quotationProductQuantity: 5,
|
||||
Supplier: 'Fireworkssupplier&Co'
|
||||
},
|
||||
{
|
||||
quotationId: 102,
|
||||
quotationMessage: 'Livraison standard',
|
||||
quotationConditionsSale: 'Payé d\'avance',
|
||||
quotationProduct: [
|
||||
{ quotationProductReference: 'DLV-1001' },
|
||||
{ quotationProductName: 'Produit2'},
|
||||
{ quotationProductQuantity: 6 },
|
||||
],
|
||||
quotationProductReference: 'DLV-1001',
|
||||
quotationProductName: 'Produit2',
|
||||
quotationProductQuantity: 6,
|
||||
Supplier: 'Fireworkssupplier&Co'
|
||||
},
|
||||
{
|
||||
quotationId: 103,
|
||||
quotationMessage: 'Livraison rapide',
|
||||
quotationConditionsSale: 'Paiement à 15 jours',
|
||||
quotationProduct: [
|
||||
{ quotationProductReference: 'DLV-1003' },
|
||||
{ quotationProductName: 'Produit3'},
|
||||
{ quotationProductQuantity: 7 },
|
||||
],
|
||||
quotationProductReference: 'DLV-1002',
|
||||
quotationProductName: 'Produit3',
|
||||
quotationProductQuantity: 7,
|
||||
Supplier: 'Fireworkssupplier&Co'
|
||||
export class QuotationTable implements OnInit {
|
||||
private quotationsService = inject(QuotationsService);
|
||||
private notificationService = inject(NzNotificationService)
|
||||
quotations = signal<GetQuotationDto[]>([]);
|
||||
quotationsLoading = signal<boolean>(false);
|
||||
|
||||
async ngOnInit() {
|
||||
await this.fetchQuotations();
|
||||
}
|
||||
|
||||
async fetchQuotations() {
|
||||
this.quotationsLoading.set(true)
|
||||
|
||||
try {
|
||||
const quotations = await firstValueFrom(this.quotationsService.getAllQuotationEndpoint())
|
||||
this.quotations.set(quotations);
|
||||
} catch (e) {
|
||||
this.notificationService.error(
|
||||
'Erreur',
|
||||
'Erreur de communication avec l\'API'
|
||||
)
|
||||
}
|
||||
];
|
||||
this.quotationsLoading.set(false)
|
||||
}
|
||||
|
||||
async delete(quotation:number) {
|
||||
try {
|
||||
await firstValueFrom(this.quotationsService.deleteQuotationEndpoint(quotation))
|
||||
this.notificationService.success(
|
||||
'Success',
|
||||
'Suppression effectuée'
|
||||
)
|
||||
} catch (e) {
|
||||
this.notificationService.error(
|
||||
'Erreur',
|
||||
'Impossible de supprimer la ligne'
|
||||
)
|
||||
}
|
||||
await this.fetchQuotations();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user