From 14d3d25217f1ace03d328638b49b61aaee027d12 Mon Sep 17 00:00:00 2001 From: sanchezvem Date: Tue, 26 May 2026 18:57:41 +0100 Subject: [PATCH] Fixed error with code to check product --- .../add-product-supplier-form.html | 2 +- .../add-product-supplier-form.ts | 8 ++--- .../create-purchaseorder-form.ts | 27 ++++++++--------- .../create-quotation-form.ts | 29 +++++++++---------- src/app/pages/stock/stock.ts | 6 ++-- 5 files changed, 34 insertions(+), 38 deletions(-) diff --git a/src/app/components/add-product-supplier-form/add-product-supplier-form.html b/src/app/components/add-product-supplier-form/add-product-supplier-form.html index 66a94c5..756fa5a 100644 --- a/src/app/components/add-product-supplier-form/add-product-supplier-form.html +++ b/src/app/components/add-product-supplier-form/add-product-supplier-form.html @@ -28,7 +28,7 @@ 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 9060015..c22c773 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 @@ -55,12 +55,12 @@ export class AddProductSupplierForm implements OnInit { addProductToForm(selectedProducts: GetProductDto[]) { this.lines.clear(); - selectedProducts.forEach(p => { + selectedProducts.forEach(x => { this.lines.push( new FormGroup({ - productId: new FormControl(p.id), - name: new FormControl(p.name), - price: new FormControl(1, [Validators.required,Validators.min(0)]) + productId: new FormControl(x.id), + name: new FormControl(x.name), + price: new FormControl(0, [Validators.required,Validators.min(0)]) }) ); }); 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 2668f29..ecfea0e 100644 --- a/src/app/components/create-purchaseorder-form/create-purchaseorder-form.ts +++ b/src/app/components/create-purchaseorder-form/create-purchaseorder-form.ts @@ -25,28 +25,25 @@ import {NzInputDirective} from "ng-zorro-antd/input"; ] }) export class CreatePurchaseorderForm { - createPurchaseOrderForm: FormGroup - - constructor(private fb: FormBuilder) { - this.createPurchaseOrderForm = this.fb.group({ - purchaseConditions: new FormControl(null, Validators.required), - lines: this.fb.array([]) - }); - } + createPurchaseOrderForm: FormGroup = new FormGroup({ + purchaseConditions: new FormControl(null, Validators.required), + lines: new FormArray([], Validators.required), + }) get lines(): FormArray { return this.createPurchaseOrderForm.get('lines') as FormArray; } - // Ajouter des produits sélectionnés dans le formulaire - syncSelectedProducts(selectedProducts: GetProductDto[]) { + addProductToForm(selectedProducts: GetProductDto[]) { this.lines.clear(); selectedProducts.forEach(p => { - this.lines.push(this.fb.group({ - productId: [p.id], - name: [p.name], - quantity: [1, [Validators.required, Validators.min(1)]] - })); + this.lines.push( + new FormGroup({ + productId: new FormControl(p.id), + name: new FormControl(p.name), + quantity: new FormControl(1, [Validators.required,Validators.min(0)]) + }) + ); }); } } diff --git a/src/app/components/create-quotation-form/create-quotation-form.ts b/src/app/components/create-quotation-form/create-quotation-form.ts index e545f06..b5fafb5 100644 --- a/src/app/components/create-quotation-form/create-quotation-form.ts +++ b/src/app/components/create-quotation-form/create-quotation-form.ts @@ -34,29 +34,26 @@ import {GetProductDto} from "../../services/api"; styleUrl: './create-quotation-form.css', }) export class CreateQuotationForm { - createQuotationForm: FormGroup - - constructor(private fb: FormBuilder) { - this.createQuotationForm = this.fb.group({ - message: new FormControl(null, Validators.required), - purchaseConditions: new FormControl(null, Validators.required), - lines: this.fb.array([]) - }); - } + createQuotationForm: FormGroup = new FormGroup({ + message: new FormControl(null, Validators.required), + purchaseConditions: new FormControl(null, Validators.required), + lines: new FormArray([], Validators.required), + }) get lines(): FormArray { return this.createQuotationForm.get('lines') as FormArray; } - // Ajouter des produits sélectionnés dans le formulaire - syncSelectedProducts(selectedProducts: GetProductDto[]) { + addProductToForm(selectedProducts: GetProductDto[]) { this.lines.clear(); selectedProducts.forEach(p => { - this.lines.push(this.fb.group({ - productId: [p.id], - name: [p.name], - quantity: [1, [Validators.required, Validators.min(1)]] - })); + this.lines.push( + new FormGroup({ + productId: new FormControl(p.id), + name: new FormControl(p.name), + quantity: new FormControl(0, [Validators.required, Validators.min(0)]) + }) + ); }); } } diff --git a/src/app/pages/stock/stock.ts b/src/app/pages/stock/stock.ts index a12156e..b4779e1 100644 --- a/src/app/pages/stock/stock.ts +++ b/src/app/pages/stock/stock.ts @@ -43,11 +43,11 @@ export class Stock { } openPurchaseOrderForm() { - this.createPurchaseOrder().syncSelectedProducts(this.getSelectedProducts()); + this.createPurchaseOrder().addProductToForm(this.getSelectedProducts()); } openQuotationForm() { - this.createQuotation().syncSelectedProducts(this.getSelectedProducts()); + this.createQuotation().addProductToForm(this.getSelectedProducts()); } openSupplierForm() { @@ -77,6 +77,8 @@ export class Stock { products: orderLines }; + console.log(purchaseOrder); + try { await firstValueFrom(this.purchaseOrdersService.createPurchaseOrder(purchaseOrder)); this.notificationService.success('Succès', 'Bon de commande créé');