Added filter in creation of purchase order to see only stock of supplier among all checked products
This commit is contained in:
@@ -15,7 +15,9 @@
|
|||||||
</nz-form-label>
|
</nz-form-label>
|
||||||
|
|
||||||
<nz-form-control nzSpan="12" nzErrorTip="Ce champ est requis">
|
<nz-form-control nzSpan="12" nzErrorTip="Ce champ est requis">
|
||||||
<nz-select formControlName="supplierId" [nzPlaceHolder]="getBestSupplier().name ?? 'Choisir un fournisseur'"
|
<nz-select formControlName="supplierId"
|
||||||
|
(ngModelChange)="refresh()"
|
||||||
|
[nzPlaceHolder]="getBestSupplier().name ?? 'Choisir un fournisseur'"
|
||||||
nzShowSearch>
|
nzShowSearch>
|
||||||
@for (supplier of suppliers(); track supplier.id) {
|
@for (supplier of suppliers(); track supplier.id) {
|
||||||
<nz-option [nzLabel]="supplier.name" [nzValue]="supplier.id"></nz-option>
|
<nz-option [nzLabel]="supplier.name" [nzValue]="supplier.id"></nz-option>
|
||||||
|
|||||||
@@ -46,10 +46,18 @@ export class CreatePurchaseorderForm {
|
|||||||
bestSupplier = x;
|
bestSupplier = x;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
return bestSupplier;
|
return bestSupplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getProductsOfSupplier() {
|
||||||
|
const supplier = this.suppliers().find(x => x.id === this.createPurchaseOrderForm.value.supplierId);
|
||||||
|
if (!supplier) return [];
|
||||||
|
|
||||||
|
const supplierProductIds = supplier.prices.map(x => x.productId);
|
||||||
|
|
||||||
|
return this.products().filter(product => supplierProductIds.includes(product.id));
|
||||||
|
}
|
||||||
|
|
||||||
createPurchaseOrderForm: FormGroup = new FormGroup({
|
createPurchaseOrderForm: FormGroup = new FormGroup({
|
||||||
purchaseConditions: new FormControl<string | null>(null, Validators.required),
|
purchaseConditions: new FormControl<string | null>(null, Validators.required),
|
||||||
lines: new FormArray([], Validators.required),
|
lines: new FormArray([], Validators.required),
|
||||||
@@ -61,19 +69,25 @@ export class CreatePurchaseorderForm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
addProductToForm() {
|
addProductToForm() {
|
||||||
|
const supplierId = this.createPurchaseOrderForm.value.supplierId ?? this.getBestSupplier().id;
|
||||||
|
this.createPurchaseOrderForm.patchValue({
|
||||||
|
supplierId
|
||||||
|
});
|
||||||
|
|
||||||
|
this.refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
refresh(){
|
||||||
this.lines.clear();
|
this.lines.clear();
|
||||||
this.products().forEach(x => {
|
|
||||||
|
this.getProductsOfSupplier().forEach(x => {
|
||||||
this.lines.push(
|
this.lines.push(
|
||||||
new FormGroup({
|
new FormGroup({
|
||||||
productId: new FormControl(x.id),
|
productId: new FormControl(x.id),
|
||||||
name: new FormControl(x.name),
|
name: new FormControl(x.name),
|
||||||
quantity: new FormControl(1, [Validators.required, Validators.min(0)])
|
quantity: new FormControl(1, [Validators.required, Validators.min(1)])
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.createPurchaseOrderForm.patchValue({
|
|
||||||
supplierId: this.getBestSupplier().id,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user