From aad637c9c9767c03e7d0aa7425fe2cb7125d353c Mon Sep 17 00:00:00 2001 From: sanchezvem Date: Sun, 30 Nov 2025 12:32:27 +0100 Subject: [PATCH] add getall and delete function from purchase order page --- .../components/product-form/product-form.html | 2 +- .../components/product-form/product-form.ts | 11 - .../product-table/product-table.html | 1 - .../purchase-order-form.html | 2 +- .../purchase-order-form.ts | 11 - .../purchase-order-table.html | 38 ++-- .../purchase-order-table.ts | 202 ++++-------------- 7 files changed, 66 insertions(+), 201 deletions(-) diff --git a/src/app/components/product-form/product-form.html b/src/app/components/product-form/product-form.html index c4362c1..44e309a 100644 --- a/src/app/components/product-form/product-form.html +++ b/src/app/components/product-form/product-form.html @@ -1,4 +1,4 @@ -
+ Prix diff --git a/src/app/components/product-form/product-form.ts b/src/app/components/product-form/product-form.ts index f3fca0a..3efb4c9 100644 --- a/src/app/components/product-form/product-form.ts +++ b/src/app/components/product-form/product-form.ts @@ -26,15 +26,4 @@ export class ProductForm { price: new FormControl(null, [Validators.required]), quantity: new FormControl(null, [Validators.required]) }) - - submitForm() { - // Pour annuler si le formulaire est invalide - if (this.productForm.invalid) return; - - // Pour obtenir la valeur du formulaire - console.log(this.productForm.getRawValue()) - - // Pour vider le formulaire - this.productForm.reset() - } } diff --git a/src/app/components/product-table/product-table.html b/src/app/components/product-table/product-table.html index 78cb7a1..e69de29 100644 --- a/src/app/components/product-table/product-table.html +++ b/src/app/components/product-table/product-table.html @@ -1 +0,0 @@ -

product-table works!

diff --git a/src/app/components/purchase-order-form/purchase-order-form.html b/src/app/components/purchase-order-form/purchase-order-form.html index 9e8e9e4..096142e 100644 --- a/src/app/components/purchase-order-form/purchase-order-form.html +++ b/src/app/components/purchase-order-form/purchase-order-form.html @@ -1,4 +1,4 @@ - + Conditions générales de vente diff --git a/src/app/components/purchase-order-form/purchase-order-form.ts b/src/app/components/purchase-order-form/purchase-order-form.ts index f2e737c..f5175f8 100644 --- a/src/app/components/purchase-order-form/purchase-order-form.ts +++ b/src/app/components/purchase-order-form/purchase-order-form.ts @@ -25,15 +25,4 @@ export class PurchaseOrderForm { purchaseOrderForm: FormGroup = new FormGroup({ purchaseCondition: new FormControl(null,[Validators.required]) }) - - submitForm() { - // Pour annuler si le formulaire est invalide - if (this.purchaseOrderForm.invalid) return; - - // Pour obtenir la valeur du formulaire - console.log(this.purchaseOrderForm.getRawValue()) - - // Pour vider le formulaire - this.purchaseOrderForm.reset() - } } 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 27b75c5..72b31f4 100644 --- a/src/app/components/purchase-order-table/purchase-order-table.html +++ b/src/app/components/purchase-order-table/purchase-order-table.html @@ -1,4 +1,7 @@ - + Numéro @@ -9,37 +12,36 @@ - @for (data of basicTable.data; track data) { + @for (purchaseOrder of purchaseOrders(); track purchaseOrder.id) { - - - + {{ purchaseOrder.id }} + {{purchaseOrder.purchaseConditions}} + Fournisseur ???
- + Nom + Reférence Prix Quantité Action - @for (product of data.productOrder; track product) { + @for (product of purchaseOrder.getPurchaseProductDto; track product.productId) { - {{product.product.name}} - {{product.price}}€ + {{product.productName}} + {{product.productReferences}} + Prix €€€€ {{product.quantity}}
- - - -
- +
@@ -52,12 +54,16 @@
+
+ +
+
- +
@@ -65,7 +71,7 @@
- +
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 ee9c5a3..1c50fe0 100644 --- a/src/app/components/purchase-order-table/purchase-order-table.ts +++ b/src/app/components/purchase-order-table/purchase-order-table.ts @@ -1,12 +1,14 @@ -import { Component } from '@angular/core'; +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 {PurchaseOrderInfo} from "../../interfaces/purchase-order.interface"; import {PurchaseOrderForm} from "../purchase-order-form/purchase-order-form"; import {ModalButton} from "../modal-button/modal-button"; import {ProductForm} from "../product-form/product-form"; +import {GetPurchaseOrderDto, PurchaseordersService} from "../../services/api"; +import {NzNotificationService} from "ng-zorro-antd/notification"; +import {firstValueFrom} from "rxjs"; @Component({ selector: 'app-purchase-order-table', @@ -22,172 +24,52 @@ import {ProductForm} from "../product-form/product-form"; templateUrl: './purchase-order-table.html', styleUrl: './purchase-order-table.css', }) -export class PurchaseOrderTable { - purchaseOrders: PurchaseOrderInfo[] = [ - { - purchaseCondition: "Condition d'achat standard 1", - supplier: { - name: "Fournisseur 1", - email: "contact1@example.com", - phone: "0100000001", - address: "1 Rue de Paris", - zipCode: "75001", - city: "Paris", - deliveryDelay: 3, - products: [ - { - reference: "F1-P1", - name: "Produit 1A", - supplier: [], - duration: 0, - caliber: "", - approvalNumber: "", - weight: 1, - nec: 0, - image: "", - link: "", - minimalQuantity: 1 - }, - { - reference: "F1-P2", - name: "Produit 1B", - supplier: [], - duration: 0, - caliber: "", - approvalNumber: "", - weight: 2, - nec: 0, - image: "", - link: "", - minimalQuantity: 1 - } - ] - }, - productOrder: [ - { - product: { - reference: "F1-P1", - name: "Produit 1A", - supplier: [], - duration: 0, - caliber: "", - approvalNumber: "", - weight: 1, - nec: 0, - image: "", - link: "", - minimalQuantity: 1 - }, - quantity: 5, - price: 10 - }, - { - product: { - reference: "F1-P2", - name: "Produit 1B", - supplier: [], - duration: 0, - caliber: "", - approvalNumber: "", - weight: 2, - nec: 0, - image: "", - link: "", - minimalQuantity: 1 - }, - quantity: 3, - price: 15 - } - ] - }, +export class PurchaseOrderTable implements OnInit { + private purchaseOrdersService = inject(PurchaseordersService); + private notificationService = inject(NzNotificationService) + purchaseOrders = signal([]); + purchaseOrdersLoading = signal(false); - { - purchaseCondition: "Condition d'achat standard 2", - supplier: { - name: "Fournisseur 2", - email: "contact2@example.com", - phone: "0100000002", - address: "2 Rue de Lyon", - zipCode: "75002", - city: "Paris", - deliveryDelay: 4, - products: [ - { - reference: "F2-P1", - name: "Produit 2A", - supplier: [], - duration: 0, - caliber: "", - approvalNumber: "", - weight: 1.5, - nec: 0, - image: "", - link: "", - minimalQuantity: 1 - }, - { - reference: "F2-P2", - name: "Produit 2B", - supplier: [], - duration: 0, - caliber: "", - approvalNumber: "", - weight: 2.5, - nec: 0, - image: "", - link: "", - minimalQuantity: 1 - } - ] - }, - productOrder: [ - { - product: { - reference: "F2-P1", - name: "Produit 2A", - supplier: [], - duration: 0, - caliber: "", - approvalNumber: "", - weight: 1.5, - nec: 0, - image: "", - link: "", - minimalQuantity: 1 - }, - quantity: 6, - price: 11 - }, - { - product: { - reference: "F2-P2", - name: "Produit 2B", - supplier: [], - duration: 0, - caliber: "", - approvalNumber: "", - weight: 2.5, - nec: 0, - image: "", - link: "", - minimalQuantity: 1 - }, - quantity: 4, - price: 16 - } - ] - }, - ]; + async ngOnInit() { + await this.fetchPurchaseOrder(); + } - delete() { - return + 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) { + 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' + ) + } + await this.fetchPurchaseOrder(); } export(){ return } - transfert() { + transfer() { return } }