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-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>
|
||||
@for (supplier of suppliers(); track supplier.id) {
|
||||
<nz-option [nzLabel]="supplier.name" [nzValue]="supplier.id"></nz-option>
|
||||
|
||||
@@ -46,10 +46,18 @@ export class CreatePurchaseorderForm {
|
||||
bestSupplier = x;
|
||||
}
|
||||
})
|
||||
|
||||
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({
|
||||
purchaseConditions: new FormControl<string | null>(null, Validators.required),
|
||||
lines: new FormArray([], Validators.required),
|
||||
@@ -61,19 +69,25 @@ export class CreatePurchaseorderForm {
|
||||
}
|
||||
|
||||
addProductToForm() {
|
||||
const supplierId = this.createPurchaseOrderForm.value.supplierId ?? this.getBestSupplier().id;
|
||||
this.createPurchaseOrderForm.patchValue({
|
||||
supplierId
|
||||
});
|
||||
|
||||
this.refresh();
|
||||
}
|
||||
|
||||
refresh(){
|
||||
this.lines.clear();
|
||||
this.products().forEach(x => {
|
||||
|
||||
this.getProductsOfSupplier().forEach(x => {
|
||||
this.lines.push(
|
||||
new FormGroup({
|
||||
productId: new FormControl(x.id),
|
||||
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