();
+ constructor() {
+ effect(() => {
+ if (this.purchaseOrder()) {
+ this.purchaseOrderForm.patchValue({
+ purchaseConditions: this.purchaseOrder().purchaseConditions,
+ });
+ }
+ });
+ }
}
diff --git a/src/app/components/purchase-order-table/purchase-order-table.html b/src/app/components/purchase-order-table/purchase-order-table.html
index 2779a74..7887718 100644
--- a/src/app/components/purchase-order-table/purchase-order-table.html
+++ b/src/app/components/purchase-order-table/purchase-order-table.html
@@ -54,28 +54,24 @@
-
-
-
+
-
-
-
+
-
-
-
+
-
-
-
+
-
-
-
+
|
}
+
+
\ No newline at end of file
diff --git a/src/app/components/purchase-order-table/purchase-order-table.ts b/src/app/components/purchase-order-table/purchase-order-table.ts
index b3eac7f..4e48c21 100644
--- a/src/app/components/purchase-order-table/purchase-order-table.ts
+++ b/src/app/components/purchase-order-table/purchase-order-table.ts
@@ -1,14 +1,16 @@
-import {Component, inject, OnInit, signal} from '@angular/core';
+import {Component, inject, OnInit, signal, viewChild} 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 {GetPurchaseOrderDto, GetQuotationDto, PurchaseordersService} from "../../services/api";
import {NzNotificationService} from "ng-zorro-antd/notification";
import {firstValueFrom} from "rxjs";
import {FileService} from "../../services/file.service";
+import {QuotationForm} from "../quotation-form/quotation-form";
+import {DelivererForm} from "../deliverer-form/deliverer-form";
@Component({
selector: 'app-purchase-order-table',
@@ -19,6 +21,7 @@ import {FileService} from "../../services/file.service";
NzTableComponent,
PurchaseOrderForm,
ModalButton,
+ DelivererForm,
],
templateUrl: './purchase-order-table.html',
styleUrl: './purchase-order-table.css',
@@ -29,6 +32,7 @@ export class PurchaseOrderTable implements OnInit {
private fileService = inject(FileService);
purchaseOrders = signal([]);
purchaseOrdersLoading = signal(false);
+ modal = viewChild.required('modalNav');
async ngOnInit() {
await this.fetchPurchaseOrder();
@@ -87,4 +91,44 @@ export class PurchaseOrderTable implements OnInit {
transfer() {
return
}
+
+ async edit(id: number, updatePurchaseOrderComponent: PurchaseOrderForm) {
+ if (updatePurchaseOrderComponent.purchaseOrderForm.invalid) {
+ this.notificationService.error(
+ 'Erreur',
+ 'Erreur d\'écriture dans le formulaire'
+ )
+ return;
+ }
+
+ try {
+ const purchaseOrders = updatePurchaseOrderComponent.purchaseOrderForm.getRawValue();
+ await firstValueFrom(this.purchaseOrdersService.patchPurchaseOrderPurchaseConditionsEndpoint(id, purchaseOrders))
+
+ this.notificationService.success('Success', 'Bon de commande modifié')
+ } catch (e) {
+ this.notificationService.error('Erreur', 'Erreur lors de la modification')
+ }
+ }
+
+ selectedPurchaseOrder: GetPurchaseOrderDto | null = null;
+ openEditModal(purchaseOrder: GetPurchaseOrderDto) {
+ this.selectedPurchaseOrder = { ...purchaseOrder };
+ this.modal().showModal();
+ }
+
+ async onModalOk(id: number, updatePurchaseOrderComponent: PurchaseOrderForm, modal: ModalNav) {
+ if (!this.selectedPurchaseOrder) return;
+
+ await this.edit(id, updatePurchaseOrderComponent);
+ updatePurchaseOrderComponent.purchaseOrderForm.reset();
+ modal.isVisible = false;
+ await this.fetchPurchaseOrder();
+ }
+
+ onModalCancel(modal: ModalNav) {
+ modal.isVisible = false;
+ }
+
+ protected readonly PurchaseOrderForm = PurchaseOrderForm;
}
diff --git a/src/app/components/quotation-table/quotation-table.ts b/src/app/components/quotation-table/quotation-table.ts
index 229ef9f..5c63d21 100644
--- a/src/app/components/quotation-table/quotation-table.ts
+++ b/src/app/components/quotation-table/quotation-table.ts
@@ -9,7 +9,6 @@ import {GetQuotationDto, QuotationsService} from "../../services/api";
import {NzNotificationService} from "ng-zorro-antd/notification";
import {firstValueFrom} from "rxjs";
import {FileService} from "../../services/file.service";
-import {DelivereryNoteForm} from "../deliverery-note-form/deliverery-note-form";
@Component({
selector: 'app-quotation-table',
@@ -20,7 +19,6 @@ import {DelivereryNoteForm} from "../deliverery-note-form/deliverery-note-form";
NzIconDirective,
NzTableComponent,
QuotationForm,
- DelivereryNoteForm,
],
templateUrl: './quotation-table.html',
styleUrl: './quotation-table.css',