Added checkbox in stock page

This commit is contained in:
2026-05-26 18:35:44 +01:00
parent 4dd1d7e81d
commit 961551e926
8 changed files with 310 additions and 189 deletions
@@ -0,0 +1,68 @@
import {Component, inject, OnInit, signal} from '@angular/core';
import {FormArray, FormControl, FormGroup, ReactiveFormsModule, Validators} from "@angular/forms";
import {GetProductDto, GetSupplierDto, SuppliersService} from "../../services/api";
import {NzColDirective, NzRowDirective} from "ng-zorro-antd/grid";
import {NzFormControlComponent, NzFormLabelComponent} from "ng-zorro-antd/form";
import {NzFlexDirective} from "ng-zorro-antd/flex";
import {NzTableComponent} from "ng-zorro-antd/table";
import {NzInputNumberComponent} from "ng-zorro-antd/input-number";
import {NzOptionComponent, NzSelectComponent} from "ng-zorro-antd/select";
import {firstValueFrom} from "rxjs";
import {NzNotificationService} from "ng-zorro-antd/notification";
@Component({
selector: 'app-add-product-supplier-form',
imports: [
NzRowDirective,
NzFormControlComponent,
NzFormLabelComponent,
ReactiveFormsModule,
NzFlexDirective,
NzColDirective,
NzTableComponent,
NzInputNumberComponent,
NzOptionComponent,
NzSelectComponent
],
templateUrl: './add-product-supplier-form.html',
styleUrl: './add-product-supplier-form.css',
})
export class AddProductSupplierForm implements OnInit {
addProductForm: FormGroup = new FormGroup({
supplierId: new FormControl<number>(null, Validators.required),
lines: new FormArray([], Validators.required),
});
private suppliersServices = inject(SuppliersService);
private notificationService = inject(NzNotificationService);
suppliers = signal<GetSupplierDto[]>([]);
async ngOnInit() {
try {
const suppliers = await firstValueFrom(this.suppliersServices.getAllSuppliersEndpoint());
this.suppliers.set(suppliers);
}
catch {
this.notificationService.error('Erreur', 'Erreur de communication avec l\'API');
}
}
get lines(): FormArray {
return this.addProductForm.get('lines') as FormArray;
}
addProductToForm(selectedProducts: GetProductDto[]) {
this.lines.clear();
selectedProducts.forEach(p => {
this.lines.push(
new FormGroup({
productId: new FormControl(p.id),
name: new FormControl(p.name),
price: new FormControl(1, [Validators.required,Validators.min(0)])
})
);
});
}
}