Fixed error with code to check product

This commit is contained in:
2026-05-26 18:57:41 +01:00
parent 961551e926
commit 14d3d25217
5 changed files with 34 additions and 38 deletions
@@ -28,7 +28,7 @@
<td class="text-center">
<nz-input-number
formControlName="price"
[nzMin]="1"
[nzMin]="0"
[nzStep]="1">
</nz-input-number>
</td>
@@ -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)])
})
);
});
@@ -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({
createPurchaseOrderForm: FormGroup = new FormGroup({
purchaseConditions: new FormControl<string | null>(null, Validators.required),
lines: this.fb.array([])
});
}
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)])
})
);
});
}
}
@@ -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({
createQuotationForm: FormGroup = new FormGroup({
message: new FormControl<string>(null, Validators.required),
purchaseConditions: new FormControl<string>(null, Validators.required),
lines: this.fb.array([])
});
}
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)])
})
);
});
}
}
+4 -2
View File
@@ -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éé');