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"> <td class="text-center">
<nz-input-number <nz-input-number
formControlName="price" formControlName="price"
[nzMin]="1" [nzMin]="0"
[nzStep]="1"> [nzStep]="1">
</nz-input-number> </nz-input-number>
</td> </td>
@@ -55,12 +55,12 @@ export class AddProductSupplierForm implements OnInit {
addProductToForm(selectedProducts: GetProductDto[]) { addProductToForm(selectedProducts: GetProductDto[]) {
this.lines.clear(); this.lines.clear();
selectedProducts.forEach(p => { selectedProducts.forEach(x => {
this.lines.push( this.lines.push(
new FormGroup({ new FormGroup({
productId: new FormControl(p.id), productId: new FormControl(x.id),
name: new FormControl(p.name), name: new FormControl(x.name),
price: new FormControl(1, [Validators.required,Validators.min(0)]) price: new FormControl(0, [Validators.required,Validators.min(0)])
}) })
); );
}); });
@@ -25,28 +25,25 @@ import {NzInputDirective} from "ng-zorro-antd/input";
] ]
}) })
export class CreatePurchaseorderForm { export class CreatePurchaseorderForm {
createPurchaseOrderForm: FormGroup createPurchaseOrderForm: FormGroup = new FormGroup({
purchaseConditions: new FormControl<string | null>(null, Validators.required),
constructor(private fb: FormBuilder) { lines: new FormArray([], Validators.required),
this.createPurchaseOrderForm = this.fb.group({ })
purchaseConditions: new FormControl<string | null>(null, Validators.required),
lines: this.fb.array([])
});
}
get lines(): FormArray { get lines(): FormArray {
return this.createPurchaseOrderForm.get('lines') as FormArray; return this.createPurchaseOrderForm.get('lines') as FormArray;
} }
// Ajouter des produits sélectionnés dans le formulaire addProductToForm(selectedProducts: GetProductDto[]) {
syncSelectedProducts(selectedProducts: GetProductDto[]) {
this.lines.clear(); this.lines.clear();
selectedProducts.forEach(p => { selectedProducts.forEach(p => {
this.lines.push(this.fb.group({ this.lines.push(
productId: [p.id], new FormGroup({
name: [p.name], productId: new FormControl(p.id),
quantity: [1, [Validators.required, Validators.min(1)]] 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', styleUrl: './create-quotation-form.css',
}) })
export class CreateQuotationForm { export class CreateQuotationForm {
createQuotationForm: FormGroup createQuotationForm: FormGroup = new FormGroup({
message: new FormControl<string>(null, Validators.required),
constructor(private fb: FormBuilder) { purchaseConditions: new FormControl<string>(null, Validators.required),
this.createQuotationForm = this.fb.group({ lines: new FormArray([], Validators.required),
message: new FormControl<string>(null, Validators.required), })
purchaseConditions: new FormControl<string>(null, Validators.required),
lines: this.fb.array([])
});
}
get lines(): FormArray { get lines(): FormArray {
return this.createQuotationForm.get('lines') as FormArray; return this.createQuotationForm.get('lines') as FormArray;
} }
// Ajouter des produits sélectionnés dans le formulaire addProductToForm(selectedProducts: GetProductDto[]) {
syncSelectedProducts(selectedProducts: GetProductDto[]) {
this.lines.clear(); this.lines.clear();
selectedProducts.forEach(p => { selectedProducts.forEach(p => {
this.lines.push(this.fb.group({ this.lines.push(
productId: [p.id], new FormGroup({
name: [p.name], productId: new FormControl(p.id),
quantity: [1, [Validators.required, Validators.min(1)]] 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() { openPurchaseOrderForm() {
this.createPurchaseOrder().syncSelectedProducts(this.getSelectedProducts()); this.createPurchaseOrder().addProductToForm(this.getSelectedProducts());
} }
openQuotationForm() { openQuotationForm() {
this.createQuotation().syncSelectedProducts(this.getSelectedProducts()); this.createQuotation().addProductToForm(this.getSelectedProducts());
} }
openSupplierForm() { openSupplierForm() {
@@ -77,6 +77,8 @@ export class Stock {
products: orderLines products: orderLines
}; };
console.log(purchaseOrder);
try { try {
await firstValueFrom(this.purchaseOrdersService.createPurchaseOrder(purchaseOrder)); await firstValueFrom(this.purchaseOrdersService.createPurchaseOrder(purchaseOrder));
this.notificationService.success('Succès', 'Bon de commande créé'); this.notificationService.success('Succès', 'Bon de commande créé');