From 56d3d1bea71bf85fb98db9aa25e865ca2a5aa66b Mon Sep 17 00:00:00 2001 From: sanchezvem Date: Tue, 26 May 2026 19:17:40 +0100 Subject: [PATCH] Added supplier in purchase order form --- .../add-product-supplier-form.ts | 23 ++++-------------- .../create-purchaseorder-form.html | 16 ++++++++++++- .../create-purchaseorder-form.ts | 10 ++++++-- .../create-quotation-form.html | 2 +- src/app/pages/stock/stock.html | 4 ++-- src/app/pages/stock/stock.ts | 24 +++++++++++++++---- 6 files changed, 49 insertions(+), 30 deletions(-) diff --git a/src/app/components/add-product-supplier-form/add-product-supplier-form.ts b/src/app/components/add-product-supplier-form/add-product-supplier-form.ts index c22c773..00f9533 100644 --- a/src/app/components/add-product-supplier-form/add-product-supplier-form.ts +++ b/src/app/components/add-product-supplier-form/add-product-supplier-form.ts @@ -1,14 +1,12 @@ -import {Component, inject, OnInit, signal} from '@angular/core'; +import {Component, input} from '@angular/core'; import {FormArray, FormControl, FormGroup, ReactiveFormsModule, Validators} from "@angular/forms"; -import {GetProductDto, GetSupplierDto, SuppliersService} from "../../services/api"; +import {GetProductDto, GetSupplierDto} from "../../services/api"; import {NzColDirective, NzRowDirective} from "ng-zorro-antd/grid"; import {NzFormControlComponent, NzFormLabelComponent} from "ng-zorro-antd/form"; import {NzFlexDirective} from "ng-zorro-antd/flex"; import {NzTableComponent} from "ng-zorro-antd/table"; import {NzInputNumberComponent} from "ng-zorro-antd/input-number"; import {NzOptionComponent, NzSelectComponent} from "ng-zorro-antd/select"; -import {firstValueFrom} from "rxjs"; -import {NzNotificationService} from "ng-zorro-antd/notification"; @Component({ selector: 'app-add-product-supplier-form', @@ -27,26 +25,13 @@ import {NzNotificationService} from "ng-zorro-antd/notification"; templateUrl: './add-product-supplier-form.html', styleUrl: './add-product-supplier-form.css', }) -export class AddProductSupplierForm implements OnInit { +export class AddProductSupplierForm { addProductForm: FormGroup = new FormGroup({ supplierId: new FormControl(null, Validators.required), lines: new FormArray([], Validators.required), }); - private suppliersServices = inject(SuppliersService); - private notificationService = inject(NzNotificationService); - - suppliers = signal([]); - - async ngOnInit() { - try { - const suppliers = await firstValueFrom(this.suppliersServices.getAllSuppliersEndpoint()); - this.suppliers.set(suppliers); - } - catch { - this.notificationService.error('Erreur', 'Erreur de communication avec l\'API'); - } - } + suppliers = input.required(); get lines(): FormArray { return this.addProductForm.get('lines') as FormArray; diff --git a/src/app/components/create-purchaseorder-form/create-purchaseorder-form.html b/src/app/components/create-purchaseorder-form/create-purchaseorder-form.html index b90a5be..e0afa79 100644 --- a/src/app/components/create-purchaseorder-form/create-purchaseorder-form.html +++ b/src/app/components/create-purchaseorder-form/create-purchaseorder-form.html @@ -9,6 +9,20 @@ + + + Fournisseur + + + + + @for (supplier of suppliers(); track supplier.id){ + + } + + + +
@@ -18,7 +32,7 @@ - @for (line of lines.controls.slice(); let i = $index; track i) { + @for (line of lines.controls; let i = $index; track i) { {{ line.value.name }} diff --git a/src/app/components/create-purchaseorder-form/create-purchaseorder-form.ts b/src/app/components/create-purchaseorder-form/create-purchaseorder-form.ts index ecfea0e..147f96e 100644 --- a/src/app/components/create-purchaseorder-form/create-purchaseorder-form.ts +++ b/src/app/components/create-purchaseorder-form/create-purchaseorder-form.ts @@ -1,12 +1,13 @@ -import {Component} from '@angular/core'; +import {Component, input} from '@angular/core'; import {FormBuilder, FormGroup, FormArray, Validators, ReactiveFormsModule, FormControl} from '@angular/forms'; -import {GetProductDto} from '../../services/api'; +import {GetProductDto, GetSupplierDto} from '../../services/api'; import {NzTableComponent} from "ng-zorro-antd/table"; import {NzInputNumberComponent} from "ng-zorro-antd/input-number"; import {NzColDirective} from "ng-zorro-antd/grid"; import {NzFlexDirective} from "ng-zorro-antd/flex"; import {NzFormControlComponent, NzFormItemComponent, NzFormLabelComponent} from "ng-zorro-antd/form"; import {NzInputDirective} from "ng-zorro-antd/input"; +import {NzOptionComponent, NzSelectComponent} from "ng-zorro-antd/select"; @Component({ selector: 'app-create-purchaseorder-form', @@ -22,12 +23,17 @@ import {NzInputDirective} from "ng-zorro-antd/input"; NzFormItemComponent, NzFormLabelComponent, NzInputDirective, + NzOptionComponent, + NzSelectComponent, ] }) export class CreatePurchaseorderForm { + suppliers = input.required(); + createPurchaseOrderForm: FormGroup = new FormGroup({ purchaseConditions: new FormControl(null, Validators.required), lines: new FormArray([], Validators.required), + supplierId: new FormControl(null, Validators.required), }) get lines(): FormArray { diff --git a/src/app/components/create-quotation-form/create-quotation-form.html b/src/app/components/create-quotation-form/create-quotation-form.html index 74e0fdb..a749284 100644 --- a/src/app/components/create-quotation-form/create-quotation-form.html +++ b/src/app/components/create-quotation-form/create-quotation-form.html @@ -28,7 +28,7 @@ - @for (line of lines.controls.slice(); let i = $index; track i) { + @for (line of lines.controls; let i = $index; track i) { {{ line.value.name }} diff --git a/src/app/pages/stock/stock.html b/src/app/pages/stock/stock.html index f1f29bd..e8c7b40 100644 --- a/src/app/pages/stock/stock.html +++ b/src/app/pages/stock/stock.html @@ -8,7 +8,7 @@ name="Créer un bon de commande" size="35%" class="ml-4"> - + - + }
diff --git a/src/app/pages/stock/stock.ts b/src/app/pages/stock/stock.ts index b4779e1..edca83c 100644 --- a/src/app/pages/stock/stock.ts +++ b/src/app/pages/stock/stock.ts @@ -1,9 +1,14 @@ -import {Component, inject, signal, viewChild} from '@angular/core'; +import {Component, inject, OnInit, signal, viewChild} from '@angular/core'; import {StockTable} from "../../components/stock-table/stock-table"; import {ModalButton} from "../../components/modal-button/modal-button"; import {CreatePurchaseorderForm} from "../../components/create-purchaseorder-form/create-purchaseorder-form"; import {NzNotificationService} from "ng-zorro-antd/notification"; -import {CreatePriceDto, PurchaseordersService, QuotationsService, SuppliersService} from "../../services/api"; +import { + GetSupplierDto, + PurchaseordersService, + QuotationsService, + SuppliersService +} from "../../services/api"; import {firstValueFrom} from "rxjs"; import {CreateQuotationForm} from "../../components/create-quotation-form/create-quotation-form"; import {AddProductSupplierForm} from "../../components/add-product-supplier-form/add-product-supplier-form"; @@ -21,7 +26,7 @@ import {AddProductSupplierForm} from "../../components/add-product-supplier-form styleUrl: './stock.css', }) -export class Stock { +export class Stock implements OnInit { createPurchaseOrder = viewChild.required('purchaseOrderForm'); createQuotation = viewChild.required('quotationForm'); addProduct = viewChild.required('supplierForm'); @@ -35,9 +40,20 @@ export class Stock { private notificationService = inject(NzNotificationService); products = signal([]); + suppliers = signal([]); productIds = []; + async ngOnInit() { + try { + const suppliers = await firstValueFrom(this.suppliersService.getAllSuppliersEndpoint()); + this.suppliers.set(suppliers); + } + catch { + this.notificationService.error('Erreur', 'Erreur de communication avec l\'API'); + } + } + getSelectedProducts() { return this.products().filter(x => this.productIds.includes(x.id)); } @@ -77,8 +93,6 @@ export class Stock { products: orderLines }; - console.log(purchaseOrder); - try { await firstValueFrom(this.purchaseOrdersService.createPurchaseOrder(purchaseOrder)); this.notificationService.success('Succès', 'Bon de commande créé');