added create quotation function and edit end delete product in quotation table
This commit is contained in:
@@ -5,10 +5,16 @@ 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 {GetQuotationDto, QuotationsService} from "../../services/api";
|
||||
import {
|
||||
GetQuotationDto,
|
||||
GetQuotationProductDto,
|
||||
QuotationproductsService,
|
||||
QuotationsService
|
||||
} from "../../services/api";
|
||||
import {NzNotificationService} from "ng-zorro-antd/notification";
|
||||
import {firstValueFrom} from "rxjs";
|
||||
import {FileService} from "../../services/file.service";
|
||||
import {QuantityForm} from "../quantity-form/quantity-form";
|
||||
|
||||
@Component({
|
||||
selector: 'app-quotation-table',
|
||||
@@ -19,6 +25,7 @@ import {FileService} from "../../services/file.service";
|
||||
NzIconDirective,
|
||||
NzTableComponent,
|
||||
QuotationForm,
|
||||
QuantityForm,
|
||||
],
|
||||
templateUrl: './quotation-table.html',
|
||||
styleUrl: './quotation-table.css',
|
||||
@@ -27,10 +34,12 @@ import {FileService} from "../../services/file.service";
|
||||
export class QuotationTable implements OnInit {
|
||||
private quotationsService = inject(QuotationsService);
|
||||
private notificationService = inject(NzNotificationService);
|
||||
private quotationProductsService = inject(QuotationproductsService)
|
||||
private fileService = inject(FileService);
|
||||
quotations = signal<GetQuotationDto[]>([]);
|
||||
quotationsLoading = signal<boolean>(false);
|
||||
modal = viewChild.required<ModalNav>('modalNav');
|
||||
modalQuantity = viewChild.required<ModalNav>('modalQuantity');
|
||||
|
||||
async ngOnInit() {
|
||||
await this.fetchQuotations();
|
||||
@@ -102,6 +111,43 @@ export class QuotationTable implements OnInit {
|
||||
}
|
||||
}
|
||||
|
||||
async deleteProduct(productId: number, quotationId: number) {
|
||||
this.quotationsLoading.set(true)
|
||||
try {
|
||||
await firstValueFrom(this.quotationProductsService.deleteQuotationProductEndpoint(productId, quotationId))
|
||||
this.notificationService.success(
|
||||
'Success',
|
||||
'Suppression effectuée'
|
||||
)
|
||||
} catch (e) {
|
||||
this.notificationService.error(
|
||||
'Erreur',
|
||||
'Impossible de supprimer la ligne'
|
||||
)
|
||||
}
|
||||
this.quotationsLoading.set(false)
|
||||
await this.fetchQuotations();
|
||||
}
|
||||
|
||||
async editQuantity(productId: number, quotationId: number, updateQuantityComponent: QuantityForm) {
|
||||
if (updateQuantityComponent.quantityForm.invalid) {
|
||||
this.notificationService.error(
|
||||
'Erreur',
|
||||
'Erreur d\'écriture dans le formulaire'
|
||||
)
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const quantity = updateQuantityComponent.quantityForm.getRawValue();
|
||||
await firstValueFrom(this.quotationProductsService.patchQuotationProductQuantityEndpoint(productId, quotationId, quantity))
|
||||
|
||||
this.notificationService.success('Success', 'Quantité modifiée')
|
||||
} catch (e) {
|
||||
this.notificationService.error('Erreur', 'Erreur lors de la modification')
|
||||
}
|
||||
}
|
||||
|
||||
selectedQuotation: GetQuotationDto | null = null;
|
||||
openEditModal(quotation: GetQuotationDto) {
|
||||
this.selectedQuotation = { ...quotation };
|
||||
@@ -120,5 +166,20 @@ export class QuotationTable implements OnInit {
|
||||
onModalCancel(modal: ModalNav) {
|
||||
modal.isVisible = false;
|
||||
}
|
||||
|
||||
selectedQuantity: GetQuotationProductDto | null = null;
|
||||
openEditQuantityModal(quantity: GetQuotationProductDto) {
|
||||
this.selectedQuantity = { ...quantity };
|
||||
this.modalQuantity().showModal();
|
||||
}
|
||||
|
||||
async onModalQuantityOk(productId: number, quotationId: number, updateQuantityComponent: QuantityForm, modal: ModalNav) {
|
||||
if (!this.selectedQuantity) return;
|
||||
|
||||
await this.editQuantity(productId, quotationId, updateQuantityComponent);
|
||||
updateQuantityComponent.quantityForm.reset();
|
||||
modal.isVisible = false;
|
||||
await this.fetchQuotations();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user