53 lines
1.8 KiB
TypeScript
53 lines
1.8 KiB
TypeScript
import { Component } from '@angular/core';
|
|
import {FormBuilder, FormGroup, FormArray, Validators, ReactiveFormsModule, FormControl} from '@angular/forms';
|
|
import { GetProductDto } from '../../services/api';
|
|
import {NzTableComponent} from "ng-zorro-antd/table";
|
|
import {NzInputNumberComponent} from "ng-zorro-antd/input-number";
|
|
import {NzColDirective} from "ng-zorro-antd/grid";
|
|
import {NzFlexDirective} from "ng-zorro-antd/flex";
|
|
import {NzFormControlComponent, NzFormItemComponent, NzFormLabelComponent} from "ng-zorro-antd/form";
|
|
import {NzInputDirective} from "ng-zorro-antd/input";
|
|
|
|
@Component({
|
|
selector: 'app-create-purchaseorder-form',
|
|
templateUrl: './create-purchaseorder-form.html',
|
|
styleUrl: './create-purchaseorder-form.css',
|
|
imports: [
|
|
ReactiveFormsModule,
|
|
NzTableComponent,
|
|
NzInputNumberComponent,
|
|
NzColDirective,
|
|
NzFlexDirective,
|
|
NzFormControlComponent,
|
|
NzFormItemComponent,
|
|
NzFormLabelComponent,
|
|
NzInputDirective,
|
|
]
|
|
})
|
|
export class CreatePurchaseorderForm {
|
|
createPurchaseOrderForm: FormGroup
|
|
|
|
constructor(private fb: FormBuilder) {
|
|
this.createPurchaseOrderForm = this.fb.group({
|
|
purchaseConditions: new FormControl<string | null>(null, Validators.required),
|
|
lines: this.fb.array([])
|
|
});
|
|
}
|
|
|
|
get lines(): FormArray {
|
|
return this.createPurchaseOrderForm.get('lines') as FormArray;
|
|
}
|
|
|
|
// Ajouter des produits sélectionnés dans le formulaire
|
|
syncSelectedProducts(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)]]
|
|
}));
|
|
});
|
|
}
|
|
}
|